DisplayList3d.mesa
Last edited by Bier on December 18, 1982 1:17 am
Author: Eric Bier on August 12, 1983 11:25 am
DIRECTORY
CSG,
CSGGraphics,
CoordSys,
Graphics,
GraphicsColor,
IO,
Matrix3d,
Rope,
Shading,
SV2d,
SVArtwork,
SVBoundBox,
SVPolygon3d,
SVVector3d;
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 = REF ArtworkObj;
ArtworkObj: TYPE = SVArtwork.ArtworkObj;
BoundHedron: TYPE = SVBoundBox.BoundHedron;
Classification: TYPE = REF ClassificationObj;
ClassificationObj: TYPE = CSG.ClassificationObj;
Color: TYPE = GraphicsColor.Color;
CoordSysList: TYPE = CoordSys.CoordSysList;
CoordSysObj: TYPE = CoordSys.CoordSysObj;
CoordSystem: TYPE = REF CoordSysObj;
CSGTree: TYPE = REF CSGTreeObj;
CSGTreeObj: TYPE = CSG.CSGTreeObj;
Camera: TYPE = REF CameraObj;
CameraObj: TYPE = CSGGraphics.CameraObj;
DrawStyle: TYPE = CSGGraphics.DrawStyle; -- {wire, shaded, rayCast, normals}
FrameBox: TYPE = CSGGraphics.FrameBox;
Matrix4by4: TYPE = Matrix3d.Matrix4by4;
Plane: TYPE = SVPolygon3d.Plane;
Point2d: TYPE = SV2d.Point2d;
Point3d: TYPE = Matrix3d.Point3d;
PointSetOp: TYPE = CSG.PointSetOp; -- {union, intersection, difference}
Poly3d: TYPE = SVPolygon3d.Poly3d;
Primitive: TYPE = REF PrimitiveObj;
PrimitiveObj: TYPE = CSG.PrimitiveObj;
Ray: TYPE = REF RayObj;
RayObj: TYPE = CSG.RayObj;
Vector: TYPE = SVVector3d.Vector;
DisplayList Types
Databases, Scenes, Assemblies, and Lightsources
Database: TYPE = REF DatabaseObj;
DatabaseObj: TYPE = RECORD [scenes: LIST OF Scene];
Scene: TYPE = REF SceneObj;
SceneObj: TYPE = RECORD [
name: Rope.ROPE,
worldCS: CoordSystem, -- a name for the identity matrix
coordSystems: CoordSysList,
lightSources: LightSourceList,
masterObjects: MasterObjectList,
assembly: Assembly,
cameras: FileCameraList,
cameraOrder: LIST OF Rope.ROPE,
backgroundColor: Color,
shadows: BOOL,
dirty: BOOL];
The assembly mentioned above is known throughout the system as "sceneAssembly". Translation, scaling and rotation of this assembly effects the entire scene.
Assembly: TYPE = REF AssemblyObj;
AssemblyObj: TYPE = RECORD [
 name: Rope.ROPE,
 coordSys: CoordSystem,
 artwork: Artwork,
 scalars: Vector,
 visible: BOOL,
 isTool: BOOL,
 object: REF ANY -- a MasterObject or an assembly list
 ];
AssemblyList: TYPE = REF AssemblyListObj;
AssemblyListObj: TYPE = RECORD [
 list: LIST OF Assembly,
 pointSetOp: PointSetOp];
LightSourceList: TYPE = Shading.LightSourceList; -- LIST OF LightSource;
LightSource: TYPE = REF LightSourceObj;
LightSourceObj: TYPE = Shading.LightSourceObj;
FileCamera: TYPE = REF FileCameraObj;
FileCameraObj: TYPE = RECORD [
name: Rope.ROPE,
origin: Point3d,
focusPoint: Point3d,
slant: REAL, -- the slant of the camera counter-clockwise from horizontal in degrees.
resolution: REAL,
focalLength: REAL,
frame: FrameBox,
clippingPlanes: LIST OF Plane,
visibleAssemblies: LIST OF Rope.ROPE];
FileCameraList: TYPE = LIST OF FileCamera;
Master Object Class Types
MasterObjectClass: TYPE = REF MasterObjectClassObj;
MasterObjectClassObj: TYPE = RECORD [
name: Rope.ROPE,
filein: FileinProc,
fileout: FileoutProc,
rayCast: RayCastProc,
rayCastNoBBoxes: RayCastNoBBoxesProc,
getHedron: BoundHedronProc,
preprocess: PreprocessProc,
lineDraw: LineDrawProc,
normalsDraw: NormalsDrawProc,
countSurf: CountPlanarSurfacesProc,
getSurf: GetPlanarSurfacesProc,
drawSurf: DrawPlanarSurfaceProc,
drawSubBoxes: DrawSubBoxesProc];
MasterObjectClassList: TYPE = LIST OF MasterObjectClass;
Master Object Types
MasterObject: TYPE = REF MasterObjectRec;
MasterObjectRec: TYPE = RECORD [
name: Rope.ROPE,
class: MasterObjectClass,
mainBody: REF ANYNIL, -- information independent of imaging style
lineBody: REF ANY,
shadeBody: REF ANY,
rayCastBody: REF ANY
];
MasterObjectList: TYPE = LIST OF MasterObject;
FileoutProc: TYPE = PROC [f: IO.STREAM, mo: MasterObject];
FileinProc: TYPE = PROC [f: IO.STREAM, name: Rope.ROPE] RETURNS [mo: MasterObject];
RayCastProc: TYPE = CSG.RayCastProc;
RayCastNoBBoxesProc: TYPE = CSG.RayCastNoBBoxesProc;
BoundHedronProc: TYPE = PROC [mo: MasterObject] RETURNS [hedron: BoundHedron];
PreprocessProc: TYPE = PROC [prim: Primitive, camera: Camera];
LineDrawProc: TYPE = PROC[dc: Graphics.Context, data: REF ANY, camera: Camera, localCS: CoordSystem];
NormalsDrawProc: TYPE = PROC[dc: Graphics.Context, data: REF ANY, camera: Camera, localCS: CoordSystem];
CountPlanarSurfacesProc: TYPE = PROC [masterObject: MasterObject] RETURNS [len: NAT];
GetPlanarSurfacesProc: TYPE = PROC [assembly: Assembly, camera: CoordSystem] RETURNS [PlanarSurfaceList];
PlanarSurface: TYPE = REF PlanarSurfaceObj;
PlanarSurfaceObj: TYPE = RECORD [
whichSurface: REF ANY,
each object type will have its own way of describing its surfaces
assembly: Assembly,
mo: MasterObject,
normal: Vector,
depth: REAL]; -- in camera coords which the master object calculates (for now)
The normal is a surface normal given in local coordinates by each assembly. It is converted to camera coordinates before it is passed back to master object class code for drawing.
PlanarSurfaceList: TYPE = LIST OF PlanarSurface;
DrawPlanarSurfaceProc: TYPE = PROC [dc: Graphics.Context, ps: PlanarSurface, lightSources: LightSourceList, camera: Camera];
DrawSubBoxesProc: TYPE = PROC [dc: Graphics.Context, prim: Primitive, screenCS: CoordSystem];
Noop Procedures
A master object can use these entries if it doesn't implement one of these procedures
NoOpRayCast: RayCastProc;
NoOpRayCastNoBBoxes: RayCastNoBBoxesProc;
NoOpPreprocess: PreprocessProc;
NoOpLineDraw: LineDrawProc;
NoOpNormalsDraw: NormalsDrawProc;
NoOpCountPlanarSurfaces: CountPlanarSurfacesProc;
NoOpGetPlanarSurfaces: GetPlanarSurfacesProc;
NoOpDrawPlanarSurface: DrawPlanarSurfaceProc;
NoOpDrawSubBoxes: DrawSubBoxesProc;
Set Up the System
RegisterMasterObjectClass: PROC [
name: Rope.ROPE,
filein: FileinProc,
fileout: FileoutProc,
rayCast: RayCastProc,
rayCastNoBBoxes: RayCastNoBBoxesProc,
getHedron: BoundHedronProc,
preprocess: PreprocessProc,
lineDraw: LineDrawProc,
normalsDraw: NormalsDrawProc,
countSurf: CountPlanarSurfacesProc,
getSurf: GetPlanarSurfacesProc,
drawSurf: DrawPlanarSurfaceProc,
drawSubBoxes: DrawSubBoxesProc]
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
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 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];
CreatePrimitiveAssembly: PROC [name: Rope.ROPE, object: Rope.ROPE, size: Vector, scene: Scene, artwork: Artwork ← NIL, isTool: BOOLFALSE]
RETURNS [assembly: Assembly, masterObjectFound: BOOL];
Object must be on the master object list of scene. Use AddMasterObjectToScene below.
CreateClusterAssembly: PROC [name: Rope.ROPE, pointSetOp: PointSetOp, isTool: BOOLFALSE]
RETURNS [assembly: Assembly];
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, clippingPlanes: LIST OF Plane, visibleAssemblies: LIST OF Rope.ROPE] RETURNS [fileCamera: FileCamera];
CameraFromFileCamera: PROC [fileCamera: FileCamera, worldCS: CoordSystem, screenCS: CoordSystem, style: DrawStyle] RETURNS [camera: Camera];
A conversion from the viewer-independent to the viewer-dependent type of camera.
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
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.
AddCoordSysToScene: PROC [cs: CoordSystem, scene: Scene];
AddAssemblyToScene: PROC [assembly: Assembly, scene: Scene, mat: Matrix4by4];
Add assembly to the top level list of assemblies in the scene.
AddSubassemblyToAssembly: PROC [subassembly: Assembly, assembly: Assembly, scene: Scene, mat: Matrix4by4];
Automatically makes coordsys of subassembly refer to coordsys of super assembly, and adds coordsys to scene.
AttemptToAddSubassemblyToPrimitive: SIGNAL;
Restructure the Tree
RenameAssembly: PROC [assem: Assembly, newName: Rope.ROPE, scene: Scene];
CopyAssemblyAndSons: PROC [assembly: Assembly, scene: Scene, prefix: Rope.ROPE]
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.
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 [newAssembly: 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
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.
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.
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];
UniqueNameFrom: PROC [name: Rope.ROPE, scene: Scene]
RETURNS [unique: Rope.ROPE];
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
DeleteMasterObjectNamed: PROC [moName: Rope.ROPE, scene: Scene]
RETURNS [found: BOOL];
DeleteMasterObjectIfUnused: PROC [mo: MasterObject, scene: Scene]
RETURNS [found: BOOL];
DeleteCoordSysNamed: PROC [csName: Rope.ROPE, 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
Draw Parts of the Scene Tree
DrawScene: PROC [dc: Graphics.Context, scene: Scene, camera: Camera];
Draw given scene.
DrawAssembly: PROC [dc: Graphics.Context, assembly: Assembly, scene: Scene, camera: Camera];
Draw an assembly and all of its children.
Convert a Scene Tree to a Ray Tracing Tree
SceneToTree: PROC [scene: Scene, camera: Camera] RETURNS [tree: CSGTree];
ListTree: PROC [outHandle: IO.STREAM, tree: CSGTree];

END.