SVScene.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last edited by Bier on May 25, 1987 4:51:34 pm PDT
DIRECTORY
AtomButtonsTypes, Imager, IO, Rope, SV2d, SV3d, SVBasicTypes, SVModelTypes, SVRayTypes, SVSceneTypes, ViewerClasses;
SVScene: CEDAR DEFINITIONS =
BEGIN
versionRope: Rope.
ROPE;
Used for version stamps and initial greeting. Exported by SVSceneImplA.
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 Slice.
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.
Imported Types
Artwork: TYPE = SVModelTypes.Artwork;
Slice: TYPE = SVSceneTypes.Slice;
SliceList: TYPE = SVSceneTypes.SliceList;
BoundBox: TYPE = SVBasicTypes.BoundBox;
BoundHedron: TYPE = SVBasicTypes.BoundHedron;
Camera: TYPE = SVModelTypes.Camera;
Classification: TYPE = SVRayTypes.Classification;
Color: TYPE = Imager.Color;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
CSGTree: TYPE = SVRayTypes.CSGTree;
Database: TYPE = SVSceneTypes.Database;
DrawStyle: TYPE = SVModelTypes.DrawStyle; -- {wire, shaded, rayCast, normals}
FeedbackData: TYPE = AtomButtonsTypes.FeedbackData;
FileCamera: TYPE = SVSceneTypes.FileCamera;
FileCameraList: TYPE = SVSceneTypes.FileCameraList;
FrameBlock: TYPE = SVSceneTypes.FrameBlock;
FrameBox: TYPE = SVModelTypes.FrameBox;
LightSource: TYPE = SVModelTypes.LightSource;
LightSourceList: TYPE = SVSceneTypes.LightSourceList;
MasterObject: TYPE = SVSceneTypes.MasterObject;
MasterObjectClass: TYPE = SVSceneTypes.MasterObjectClass;
MasterObjectClassList: TYPE = SVSceneTypes.MasterObjectClassList;
MasterObjectList: TYPE = SVSceneTypes.MasterObjectList;
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;
Scene: TYPE = SVSceneTypes.Scene;
Shape: TYPE = SVSceneTypes.Shape;
ShowAsType: TYPE = SVSceneTypes.ShowAsType;
ToolData: TYPE = SVSceneTypes.ToolData;
Vector3d: TYPE = SV3d.Vector3d;
Viewer: TYPE = ViewerClasses.Viewer;
Create Entities
In SVSceneImplA
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: Slice];
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.
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, style: DrawStyle]
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, scene: Scene];
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).
GetEyepoint: PROC [camera: Camera] RETURNS [eyePointWORLD: Point3d];
Build the Scene Tree
In SVSceneImplA
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: Slice, scene: Scene];
Restructure the Tree
In SVSceneImplA
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: Slice, newName: Rope.ROPE, scene: Scene];
In SVSceneImplB
CopyAssemblyAndSonsRename: PROC [assembly: Slice, scene: Scene, prefix: Rope.ROPE, parent: Slice, feedback: FeedbackData]
RETURNS [copy: Slice];
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: Slice, newScene: Scene, parent: Slice, feedback: FeedbackData]
RETURNS [copy: Slice];
Not used anymore.
CopyAssemblyAndSonsUniqueNames:
PROC [assembly: Slice, oldScene: Scene, newScene: Scene, parent: Slice, feedback: FeedbackData]
RETURNS [copy: Slice];
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: Slice, to: Slice, scene: Scene];
MoveToFrontOfAssembly:
PROC [subassembly: Slice, assembly: Slice, scene: Scene];
Moves subassembly to the first position of assembly's assemblylist.
MergeAssemblyIntoScene:
PROC [originalAssembly: Slice, fromScene: Scene, parentAssembly: Slice, toScene: Scene, feedback: FeedbackData]
RETURNS [copyAssembly: Slice];
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, feedback: FeedbackData]
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: Slice, artwork: Artwork, scene: Scene];
Find Scene Entities from their Names
In SVSceneImplA
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: Slice, superAssembly: Slice, success:
BOOL];
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: Slice, 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 SVSceneImplB
NewNamesAlreadyPresent:
PROC [assembly: Slice, 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 SVSceneImplA
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.
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];
Slice Generator
GetAssemblyGenerator: PROC [scene: Scene] RETURNS [g: AssemblyGenerator];
PrimAssembliesInScene: PROC [scene: Scene] RETURNS [g: AssemblyGenerator];
AssemblyGenerator: TYPE = REF AssemblyGeneratorObj;
AssemblyGeneratorObj: TYPE = RECORD[currentPtr: LIST OF Slice];
NextAssembly: PROC [g: AssemblyGenerator] RETURNS [a: Slice];
ListOfPrimAssemblies:
PROC [assembly: Slice, scene: Scene]
RETURNS [primList:
LIST
OF Slice];
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).
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: Slice, scene: Scene] RETURNS [l: MasterObjectList];
Delete Parts of the Scene Tree
In SVSceneImplB
DeleteMasterObjectNamed: PROC [moName: Rope.ROPE, scene: Scene] RETURNS [found: BOOL];
MasterObjectIsUsed: PROC [mo: MasterObject, scene: Scene] RETURNS [used: 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: Slice, assembly: Slice, 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, feedback: FeedbackData];
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: Slice, scene: Scene];
All assemblies A such that A.sittingOn = chair.name will be deleted along with their children.
DeleteAllSelected: PROC [scene: Scene, camera: Camera] RETURNS [bBox: BoundBox];
Draw Parts of the Scene Tree
In SVSceneImplB.mesa
DrawScene:
PROC [dc: Imager.Context, scene: Scene, camera: Camera, except: Slice ←
NIL];
Draw given scene.
Selections
SaveSelections: PROC [scene: Scene];
RestoreSelections: PROC [scene: Scene];
END.