DisplayList3d.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last edited by Bier on July 31, 1985 11:41:53 pm PDT
DIRECTORY
Imager,
IO,
Rope,
SV2d,
SV3d,
SVModelTypes,
SVRayTypes,
SVSceneTypes;
DisplayList3d: DEFINITIONS =
BEGIN
versionRope: Rope.
ROPE;
Used for version stamps and initial greeting. Exported by DisplayList3dImplA.
Introduction
Contents: The Solidviews System is involved with the creation and manipulation of three dimensional scenes. A scene is a list of lightsources, a list of cameras, and a tree of assemblies. Intermediate nodes in this tree are cluster assemblies. The leaves of this tree are primitive assemblies. Each cluster assembly specifies a point set operation describing how its children should be combined. Each primitive assembly refers to a master object (a shape) and a triplet of scalars describing how this master object should be scaled before being displayed. All assemblies (cluster or primitive) refer to a coordinate system which describes how the object should be positioned and oriented with respect to its parent coordinate system (from which we can derive how it will be positioned in the scene's master coordinate system known as WORLD). Each master object is an instance of a class of shapes called a master object class.
This interface provides procedures which:
Set Up the System
The set of master object classes is established at load time. It is independent of scene, since it is assumed that each artist will want to have all available classes at his disposal for all scenes. Thus, each program which implements a master object class must register it at load time. Those classes which have only one instance (such as spheres, cylinders, blocks, and cones) should register these at load time as well.
Create Entities
Scenes, Master Objects, Primitive Assemblies, Cluster Assemblies, Light Sources.
Build the Scene Tree
Add Master Objects, Light Sources, Coordinate Systems, and Assemblies to the scene.
Add assemblies as children of other assemblies.
Restructure the Tree
Rename assemblies. Copy assemblies. Move assemblies to other nodes. Change the order of assemblies within nodes. Add assemblies from other scenes. Add entire other scenes. Change the surface appearance of a Primitive Assembly.
Delete Parts of the Scene Tree
Delete Master Objects, Coordinate Systems, and Light Sources from the scene.
Delete Assemblies from their parents. Delete all assemblies from the scene. Delete all Coordinate Systems from the scene.
Find Scene Entities from their Names
Find scenes from the global scene database. In scenes find: Assemblies, Master Objects, Master Object Classes, Light Sources from their names. Also some facilities for generate a unique assembly name by adding a number to a given assembly name.
Get Generators of Scene Entities
GetGenerator and Next procedures for Scenes, Coordinate Systems, Assemblies, Light Sources, Master Object Classes, Master Objects. Also a procedure which returns a list of primitive assemblies.
Draw Parts of the Scene Tree
Draw the entire scene. Draw an assembly and all of its children.
Convert a Scene Tree to a Ray Tracing Tree
Given a camera postion we can produce a view dependent tree representing the givne scene. Also provides a procedure for printing a text form of the resulting tree.
Imported Types
Artwork: TYPE = SVModelTypes.Artwork;
BoundHedron: TYPE = SVModelTypes.BoundHedron;
Classification: TYPE = SVRayTypes.Classification;
Color: TYPE = Imager.Color;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
CSGTree: TYPE = SVRayTypes.CSGTree;
Camera: TYPE = SVModelTypes.Camera;
DrawStyle: TYPE = SVModelTypes.DrawStyle; -- {wire, shaded, rayCast, normals}
FrameBox: TYPE = SVModelTypes.FrameBox;
LightSource: TYPE = SVModelTypes.LightSource;
Matrix4by4: TYPE = SV3d.Matrix4by4;
Plane: TYPE = SV3d.Plane;
Point2d: TYPE = SV2d.Point2d;
Point3d: TYPE = SV3d.Point3d;
PointSetOp: TYPE = SVRayTypes.PointSetOp; -- {union, intersection, difference}
Poly3d: TYPE = SV3d.Poly3d;
Primitive: TYPE = SVRayTypes.Primitive;
Projection: TYPE = SVModelTypes.Projection;
Ray: TYPE = SVRayTypes.Ray;
Vector: TYPE = SV3d.Vector;
DisplayList Types
Databases, Scenes, Assemblies, and Lightsources
Database: TYPE = SVSceneTypes.Database;
Scene: TYPE = SVSceneTypes.Scene;
Assembly: TYPE = SVSceneTypes.Assembly;
ShowAsType: TYPE = SVSceneTypes.ShowAsType;
Shape: TYPE = SVSceneTypes.Shape;
ToolData: TYPE = SVSceneTypes.ToolData;
FrameBlock: TYPE = SVSceneTypes.FrameBlock;
AssemblyList: TYPE = SVSceneTypes.AssemblyList;
LightSourceList: TYPE = SVSceneTypes.LightSourceList;
FileCamera: TYPE = SVSceneTypes.FileCamera;
FileCameraList: TYPE = SVSceneTypes.FileCameraList;
Master Object Class Types
MasterObjectClass: TYPE = SVSceneTypes.MasterObjectClass;
MasterObjectClassList: TYPE = SVSceneTypes.MasterObjectClassList;
MasterObject: TYPE = SVSceneTypes.MasterObject;
MasterObjectList: TYPE = SVSceneTypes.MasterObjectList;
FileoutProc: TYPE = SVSceneTypes.FileoutProc;
FileinProc: TYPE = SVSceneTypes.FileinProc;
FileoutPolyProc: TYPE = SVSceneTypes.FileoutPolyProc;
RayCastProc: TYPE = SVSceneTypes.RayCastProc;
RayCastNoBBoxesProc: TYPE = SVSceneTypes.RayCastNoBBoxesProc;
RayCastBoundingSpheresProc: TYPE = SVSceneTypes.RayCastBoundingSpheresProc;
BoundHedronProc: TYPE = SVSceneTypes.BoundHedronProc;
PreprocessProc: TYPE = SVSceneTypes.PreprocessProc;
LineDrawProc: TYPE = SVSceneTypes.LineDrawProc;
NormalsDrawProc: TYPE = SVSceneTypes.NormalsDrawProc;
CountPlanarSurfacesProc: TYPE = SVSceneTypes.CountPlanarSurfacesProc;
GetPlanarSurfacesProc: TYPE = SVSceneTypes.GetPlanarSurfacesProc;
PlanarSurface: TYPE = SVSceneTypes.PlanarSurface;
PlanarSurfaceList: TYPE = SVSceneTypes.PlanarSurfaceList;
DrawPlanarSurfaceProc: TYPE = SVSceneTypes.DrawPlanarSurfaceProc;
DrawSubBoxesProc: TYPE = SVSceneTypes.DrawSubBoxesProc;
DrawSubSpheresProc: TYPE = SVSceneTypes.DrawSubSpheresProc;
Noop Procedures
A master object can use these entries if it doesn't implement one of these procedures.
Null Bodies In DisplayList3dImplB.
NoOpFilein: FileinProc;
NoOpFileout: FileoutProc;
NoOpFileoutPoly: FileoutPolyProc;
NoOpRayCast: RayCastProc;
NoOpRayCastNoBBoxes: RayCastNoBBoxesProc;
NoOpRayCastBoundingSpheres: RayCastBoundingSpheresProc;
NoOpBoundHedron: BoundHedronProc;
NoOpPreprocess: PreprocessProc;
NoOpLineDraw: LineDrawProc;
NoOpNormalsDraw: NormalsDrawProc;
NoOpCountPlanarSurfaces: CountPlanarSurfacesProc;
NoOpGetPlanarSurfaces: GetPlanarSurfacesProc;
NoOpDrawPlanarSurface: DrawPlanarSurfaceProc;
NoOpDrawSubBoxes: DrawSubBoxesProc;
NoOpDrawSubSpheres: DrawSubSpheresProc;
Set Up the System
In DisplayList3dImplA
RegisterMasterObjectClass:
PROC [
name: Rope.ROPE,
filein: FileinProc,
fileout: FileoutProc,
fileoutPoly: FileoutPolyProc,
rayCast: RayCastProc,
rayCastNoBBoxes: RayCastNoBBoxesProc,
rayCastBoundingSpheres: RayCastBoundingSpheresProc,
getHedron: BoundHedronProc,
preprocess: PreprocessProc,
lineDraw: LineDrawProc,
normalsDraw: NormalsDrawProc,
countSurf: CountPlanarSurfacesProc,
getSurf: GetPlanarSurfacesProc,
drawSurf: DrawPlanarSurfaceProc,
drawSubBoxes: DrawSubBoxesProc,
drawSubSpheres: DrawSubSpheresProc]
RETURNS [moClass: MasterObjectClass];
Creates a MasterObjectClass and adds it to a global list at load time.
RegisterMasterObject:
PROC [mo: MasterObject];
Adds a MasterObject to a global list at load time. It is later added to the default scene at viewer startup (CreateScene) time.
Create Entities
In DisplayList3dImplA
CreateScene:
PROC [name: Rope.
ROPE]
RETURNS [scene: Scene];
Creates scene and adds scene to database. Includes default coordinate systems (WORLD, CAMERA, and SCENE), one default point light source, one ambient light source, five default master objects (cube, sphere, cone, cylinder, and torus) and seven default cameras (Top, Bottom, Left, Right, Front, UpLeft, and UpRight).
CreateEmptyScene:
PROC [name: Rope.
ROPE]
RETURNS [scene: Scene];
Like create scene, but includes only the 3 default coordinate systems. No light sources, master objects or cameras.
CreateMasterObject:
PROC [
name: Rope.ROPE,
class: MasterObjectClass,
mainBody: REF ANY,
lineBody: REF ANY,
shadeBody: REF ANY,
rayCastBody: REF ANY]
RETURNS [mo: MasterObject];
CopyMasterObject: PROC [mo: MasterObject] RETURNS [copy: MasterObject];
CreateSceneAssembly:
PROC [name: Rope.
ROPE, pointSetOp: PointSetOp, coordSys: CoordSystem, isTool:
BOOL ←
FALSE, toolData: ToolData ←
NIL]
RETURNS [assembly: Assembly];
The scene assembly is the only assembly which has no parent. This procedure creates an assembly and doesn't try to wire it up to a parent.
CreateAndAddPrimitiveAssembly:
PROC [name: Rope.
ROPE, object: Rope.
ROPE, size: Vector, scene: Scene, parent: Assembly, mat: Matrix4by4, artwork: Artwork ←
NIL, isTool:
BOOL ←
FALSE, toolData: ToolData ←
NIL]
RETURNS [assembly: Assembly, masterObjectFound:
BOOL, success:
BOOL];
Add a primitive assembly, based on the master object named object, scaled by size, in scene. Add it as a child of parent, so that assemblyparent will be mat. Its surface looks are described by artwork. It will look normal to start with (as opposed to as a "Tool" or invisible). If toolData is not provided, a close-fitting tool will be computed when needed.
Object must be on the master object list of scene. Use AddMasterObjectToScene below.
If success is FALSE, a message is written to the message window and nothing is done (NameAlreadyPresent and AttemptToAddSubassemblyToPrimitive are failure reasons).
CreateAndAddClusterAssembly:
PROC [name: Rope.
ROPE, pointSetOp: PointSetOp ← union, scene: Scene, parent: Assembly, mat: Matrix4by4, isTool:
BOOL ←
FALSE, toolData: ToolData ←
NIL]
RETURNS [assembly: Assembly, success:
BOOL];
Like CreateAndAddPrimitiveAssembly but adds an assembly which can have children (can be passed as "parent" later.
AttemptToAddSubassemblyToPrimitive: SIGNAL;
ConnectAssemblyToParent:
PROC [assembly: Assembly, parent: Assembly];
Not for general use. Used in conjunction with Create*AtExistingCoordSys to wire up children to parents. Text filing uses this.
CreatePrimitiveAtExistingCoordSys:
PROC [name: Rope.
ROPE, object: Rope.
ROPE, size: Vector, scene: Scene, coordSys: CoordSystem, artwork: Artwork ←
NIL, isTool:
BOOL ←
FALSE, toolData: ToolData ←
NIL]
RETURNS [assembly: Assembly, masterObjectFound:
BOOL];
Text filing creation.
CreateClusterAssemblyAtExistingCoordSys:
PROC [name: Rope.
ROPE, pointSetOp: PointSetOp, scene: Scene, coordSys: CoordSystem, isTool:
BOOL ←
FALSE, toolData: ToolData ←
NIL]
RETURNS [assembly: Assembly];
Text filing creation.
CreateToolData:
PROC [loX, hiX, loY, hiY, loZ, hiZ:
REAL, plane:
NAT, infinite:
BOOL ←
FALSE, clientData:
REF
ANY ←
NIL]
RETURNS [toolData: ToolData];
plane = 1, 2, 3 corresponds to the x=0, y=0, and z=0 planes respectively. plane = 4 means all three of them. ToolDatas are needed by CreatePrimitiveAssembly and CreateClusterAssembly above if the assembly is to be a tool.
CreateAmbientLightSource: PROC [name: Rope.ROPE, color: Color]
RETURNS [ls: LightSource];
CreateLightSource: PROC [name: Rope.ROPE, position: Point3d, color: Color]
RETURNS [ls: LightSource];
CreateFileCamera:
PROC [
name: Rope.ROPE,
origin: Point3d,
focusPoint: Point3d,
slant: REAL,
resolution: REAL,
focalLength: REAL,
projection: Projection,
frame: FrameBox,
clippingPlanes: LIST OF Plane,
visibleAssemblies: LIST OF Rope.ROPE] RETURNS [fileCamera: FileCamera];
CreateCamera:
PROC [worldCS: CoordSystem, screenCS: CoordSystem]
RETURNS [camera: Camera];
Must be done whenever a new scene is to be viewed (including whenever a solidviewer is created. Adding the camera to the scene tree is probably one of the first acts after creating a new coordinate system tree.
StuffCameraFromFileCamera:
PROC [camera: Camera, fileCamera: FileCamera, style: DrawStyle];
A conversion from the viewer-independent to the viewer-dependent type of camera. Must be done whenever camera name (Front, Top, etc) or changes (and thus whenever the scene changes).
InitialCameraList:
PROC []
RETURNS [cameras: FileCameraList];
An initial list of cameras provided with a new scene (or an old scene which was made before named file cameras were introduced).
Build the Scene Tree
In DisplayList3dImplA
Any of the procedures below may signal NameAlreadyPresent.
NameAlreadyPresent: SAFE SIGNAL;
AddMasterObjectToScene:
PROC [mo: MasterObject, scene: Scene];
Adds the named object to the scene's master object list.
AddLightSourceToScene:
PROC [ls: LightSource, scene: Scene];
Add LightSource "ls" to the given scene.
AddCameraToScene:
PROC [fileCamera: FileCamera, scene: Scene];
Add FileCamera "fileCamera" to the given scene.
AddCameraOrderNameToScene:
PROC [name: Rope.
ROPE, scene: Scene];
The names of those cameras which should open automatically with the pic file is loaded are added to the scene in order.
AddOrResizeToolToAssembly: PROC [assembly: Assembly, scene: Scene];
Restructure the Tree
In DisplayList3dImplA
UniqueAssemblyNameFrom:
PROC [name: Rope.
ROPE, scene: Scene]
RETURNS [unique: Rope.
ROPE];
Takes name, breaks it up into 3 parts: the base rope, a ".", and a trailing number. Increments the number to make the name unique, and reconcatenates the three parts.
RenameAssembly: PROC [assem: Assembly, newName: Rope.ROPE, scene: Scene];
In DisplayList3dImplB
CopyAssemblyAndSonsRename: PROC [assembly: Assembly, scene: Scene, prefix: Rope.ROPE, parent: Assembly]
RETURNS [copy: Assembly];
Creates a new assembly tree with copied master objects at the leaves
May SIGNAL NameAlreadyPresent or AttemptToAddSubassemblyToPrimitive if there is a failure for either of these reasons. Soon to be obsolete. Use CopyAssemblyAndSonsUniqueNames.
CopyAssemblyAndSonsNoRename:
PROC [assembly: Assembly, newScene: Scene, parent: Assembly]
RETURNS [copy: Assembly];
Not used anymore.
CopyAssemblyAndSonsUniqueNames:
PROC [assembly: Assembly, oldScene: Scene, newScene: Scene, parent: Assembly]
RETURNS [copy: Assembly];
An attempt to do it right. For assembly and all of its successors, we find an integer a just high enough so that if name.# becomes name.a then all names will be unique. We copy the assembly and its successors and rename them this way.
MoveSubassembly: PROC [assem: Assembly, to: Assembly, scene: Scene];
MoveToFrontOfAssembly:
PROC [subassembly: Assembly, assembly: Assembly, scene: Scene];
Moves subassembly to the first position of assembly's assemblylist.
MergeAssemblyIntoScene:
PROC [originalAssembly: Assembly, fromScene: Scene, parentAssembly: Assembly, toScene: Scene]
RETURNS [copyAssembly: Assembly];
Makes a list of all of the masterobjects needed. Compares this list to the list of masterobjects available in the new scene, subtracting any that are available. Copies those that are still needed and adds them to the new scene. Makes a copy of the newAssembly tree (without changing names) but refering to master objects in the new scene. Wires up the new assembly to its parent.
MergeSceneIntoScene: PROC [fromScene: Scene, toScene: Scene]
RETURNS [success:
BOOL];
Takes all of the assemblies from fromScene which are directly under sceneAssembly and adds them to the sceneAssembly of toScene. Makes sure that all assemblies in fromScene have names unique in toScene first.
SetArtworkAssembly: PROC [assembly: Assembly, artwork: Artwork, scene: Scene];
Find Scene Entities from their Names
In DisplayList3dImplA
FindSceneFromName:
PROC [name: Rope.
ROPE]
RETURNS [scene: Scene];
Looks for named scene in the global database
DatabaseEmpty: SIGNAL;
SceneNotFound: SIGNAL;
FindAssemblyFromName: PROC [name: Rope.ROPE, scene: Scene]
RETURNS [assembly: Assembly, superAssembly: Assembly];
Finds the named assembly and its immediate superior in current scene. superAssembly is NIL if assembly is top level
AssemblyNotFound: SIGNAL;
AssemblyNameIsPresent:
PROC [name: Rope.
ROPE, scene: Scene]
RETURNS [
BOOL];
Is an assembly with this name present in current scene?
AnyNamesAlreadyPresent:
PROC [assembly: Assembly, scene: Scene]
RETURNS [
BOOL];
Returns TRUE iff one or more of: assembly's name or the names of all of assembly's children is currently found in scene.
In DisplayList3dImplB
NewNamesAlreadyPresent:
PROC [assembly: Assembly, scene: Scene, prefix: Rope.
ROPE]
RETURNS [
BOOL];
Like AnyNamesAlreadyPresent except that assembly's name and the name of each of assembly's children is concatenated with prefix before being tested for presence in the scene.
In DisplayList3dImplA
FindClassFromName: PROC [name: Rope.ROPE]
RETURNS [moClass: MasterObjectClass, success: BOOL];
FindObjectFromName: PROC [name: Rope.ROPE, scene: Scene]
RETURNS [object: MasterObject, success: BOOL];
ObjectNameIsPresent: PROC [name: Rope.ROPE, scene: Scene] RETURNS [BOOL];
CoordSysNameIsPresent: PROC [name: Rope.ROPE, scene: Scene] RETURNS [BOOL];
FindLightFromName: PROC [name: Rope.ROPE, scene: Scene]
RETURNS [light: LightSource, success: BOOL];
LightSourceNameIsPresent: PROC [name: Rope.ROPE, scene: Scene] RETURNS [BOOL];
FindFileCameraFromName: PROC [name: Rope.ROPE, scene: Scene] RETURNS [fileCamera: FileCamera, success: BOOL];
FileCameraNameIsPresent: PROC [name: Rope.ROPE, scene: Scene] RETURNS [BOOL];
UniqueObjectNameFrom:
PROC [name: Rope.
ROPE, scene: Scene]
RETURNS [unique: Rope.
ROPE];
Takes name and appends an integer which is greater than the integer for any other master object in the scene.
Get Generators of Scene Entities
Scene Generator
GetSceneGenerator: PROC RETURNS [g: SceneGenerator];
gets a generator of the scenes in the database
SceneGenerator: TYPE = REF SceneGeneratorObj;
SceneGeneratorObj: TYPE = RECORD [currentPtr: LIST OF Scene];
NextScene: PROC [g: SceneGenerator] RETURNS [scene: Scene];
CoordSystem Generator
GetCoordSysGenerator: PROC [scene: Scene] RETURNS [g: CoordSysGenerator];
gets a generator of the assemblies in the current scene
CoordSysGenerator: TYPE = REF CoordSysGeneratorObj;
CoordSysGeneratorObj: TYPE = RECORD[currentPtr: LIST OF CoordSystem];
NextCoordSys: PROC [g: CoordSysGenerator] RETURNS [cs: CoordSystem];
Assembly Generator
GetAssemblyGenerator: PROC [scene: Scene] RETURNS [g: AssemblyGenerator];
gets a generator of the assemblies in the current scene
AssemblyGenerator: TYPE = REF AssemblyGeneratorObj;
AssemblyGeneratorObj: TYPE = RECORD[currentPtr: LIST OF Assembly];
NextAssembly: PROC [g: AssemblyGenerator] RETURNS [a: Assembly];
LightSource Generator
GetLightSourceGenerator: PROC [scene: Scene] RETURNS [g: LightSourceGenerator];
gets a generator of the lightsources in the current scene.
LightSourceGenerator: TYPE = REF LightSourceGeneratorObj;
LightSourceGeneratorObj: TYPE = RECORD [currentPtr: LightSourceList];
NextLight: PROC [g: LightSourceGenerator] RETURNS [ls: LightSource];
MasterObjectClass Generator
GetMasterObjectClassGenerator: PROC [scene: Scene] RETURNS
[g: MasterObjectClassGenerator];
MasterObjectClassGenerator: TYPE = REF MasterObjectClassGeneratorObj;
MasterObjectClassGeneratorObj:
TYPE =
RECORD [
currentPtr: MasterObjectClassList];
NextClass: PROC [g: MasterObjectClassGenerator]
RETURNS [moClass: MasterObjectClass];
MasterObject Generator
MasterObjectsOfScene: PROC [scene: Scene]
RETURNS [l: MasterObjectList];
MasterObjectsOfAssembly: PROC [assembly: Assembly, scene: Scene] RETURNS [l: MasterObjectList];
List of Primitive Assemblies
ListOfPrimAssemblies:
PROC [assembly: Assembly, scene: Scene]
RETURNS [primList:
LIST
OF Assembly];
Returns a list of the leaves of the tree whose root is the given assembly. A good start for any function interested in modifying all of the primitive assemblies of a given subassembly of the scene (including the whole scene, of course).
Delete Parts of the Scene Tree
In DisplayList3dImplB
DeleteMasterObjectNamed: PROC [moName: Rope.ROPE, scene: Scene]
RETURNS [found: BOOL];
DeleteMasterObjectIfUnused: PROC [mo: MasterObject, scene: Scene]
RETURNS [found: BOOL];
DeleteCoordSysAndChildren: PROC [cs: CoordSystem, scene: Scene];
DeleteLightSourceNamed: PROC [lsName: Rope.ROPE, scene: Scene];
ClearScene:
PROC [scene: Scene];
Removes all assemblies from scene. Leaves light sources for now.
ClearCoordSystems:
PROC [scene: Scene];
Removes all but WORLD, and SCREEN from current scene.
ClearMasterObjects:
PUBLIC
PROC [scene: Scene];
Removes all but "block", "sphere", "cone", and "cylinder" from current scene.
DeleteSubassemblyFromAssembly:
PROC [subassembly: Assembly, assembly: Assembly, scene: Scene ←
NIL]
RETURNS [success:
BOOL];
Deletes subAssembly from assembly. If subassembly is not a son of assembly, returns FALSE and does nothing
DeleteAllPrimitivesOfClass:
PROC [className: Rope.
ROPE, scene: Scene];
className must be a master object class, e.g. "sphere" or "jack". All primitive (leaf) assemblies refering to shapes of this class will be deleted.
DeleteAllAssembliesSittingOn:
PROC [chair: Assembly, scene: Scene];
All assemblies A such that A.sittingOn = chair.name will be deleted along with their children.
Draw Parts of the Scene Tree
In DisplayList3dImplB.mesa
DrawScene:
PROC [dc: Imager.Context, scene: Scene, camera: Camera];
Draw given scene.
DrawAssembly:
PROC [dc: Imager.Context, assembly: Assembly, scene: Scene, camera: Camera];
Draw an assembly and all of its children.
END.