G3dScene.mesa
Copyright Ó 1988, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 15, 1992 11:31 pm PDT
Glassner, June 25, 1990 4:00:32 pm PDT
DIRECTORY Args, Atom, Commander, G3dBasic, G3dMatrix, G3dQuaternion, G3dRender, G3dShape, G3dSpline, G3dTimeTrees, IO, Random, Rope, ViewerClasses, ViewerTools;
G3dScene: CEDAR DEFINITIONS
~ BEGIN
Type Declarations
Arg:    TYPE ~ Args.Arg;
PropList:   TYPE ~ Atom.PropList;
Handle:   TYPE ~ Commander.Handle;
Pair:    TYPE ~ G3dBasic.Pair;
Triple:   TYPE ~ G3dBasic.Triple;
Matrix:   TYPE ~ G3dMatrix.Matrix;
MatrixSequence: TYPE ~ G3dMatrix.MatrixSequence;
SplineSequence: TYPE ~ G3dSpline.SplineSequence;
Quaternion:  TYPE ~ G3dQuaternion.Quaternion;
Context3d:  TYPE ~ G3dRender.Context3d;
RenderStyle:  TYPE ~ G3dRender.RenderStyle;
Shape:   TYPE ~ G3dShape.Shape;
ShapeSequence: TYPE ~ G3dShape.ShapeSequence;
TimeTree:  TYPE ~ G3dTimeTrees.TimeTree;
STREAM:   TYPE ~ IO.STREAM;
RandomStream: TYPE ~ Random.RandomStream;
ROPE:    TYPE ~ Rope.ROPE;
Viewer:   TYPE ~ ViewerClasses.Viewer;
Write Scene Descriptions to a File or Viewer
WriteCameraParameters: PROC [context3d: Context3d];
Write the camera parameters to the primary selection.
WriteParameters: PROC [context3d: Context3d, fileName: ROPE ¬ NIL];
Write all the relevant parameters of the context3d to the specified file.
If fileName = NIL, obtain it from the current mouse selection.
If fileName = NIL and no fileName selected by the mouse, write to the primary selection.
WriteParametersToStream: PROC [context3d: Context3d, out: STREAM];
Write all the relevant parameters of the context3d to the output stream.
Read Scene Descriptions from a File or Viewer
MakeFrameFromFile: PROC [context3d: Context3d, fileName: ROPE];
Display a scene described in fileName, without altering context3d.
ReadParameters: PROC [context3d: Context3d, fileName: ROPE ¬ NIL, cmdOut: STREAM ¬ NIL]
RETURNS [shouldRepaint: BOOL];
Set context3d parameters based on the scene description.
If fileName = NIL, obtain it from the current mouse selection. If fileName = NIL and no
name selected with the mouse, read parameters from the primary selection.
Parsing a Scene Description
LogProc: TYPE ~ PROC [rope: ROPE, clientData: REF ANY];
WriteLog: PROC [ps: ParseState, msg: ROPE];
Send the message to the log, if a logProc has been assigned to ps.
Parse: PROC [
context3d: Context3d,
operation: ROPE,
cmdOut: STREAM ¬ NIL,
logProc: LogProc ¬ NIL,
logErrors: BOOL ¬ TRUE,
fileName: ROPE ¬ NIL,
clientData: REF ANY ¬ NIL,
parseState: ParseState ¬ NIL]
RETURNS [ParseState];
Perform the specified operation on the context3d.
operation consists of an arbitrary number of operations:
each operation is a keyword followed by arguments, if required.
Only registered operations (see below) and a short number of internally defined operations
are supported; see the graphics 3d documentation for the standard list of operations.
If logProc # NIL, a message is written for each operation parsed.
If logErrors, any errors encountered are printed in an error viewer.
If fileName # NIL, it is used when printing errors.
a parseState may be given for continuity between calls on Parse; otherwise one is allocated.
Support for Shape Creation
InheritMaterial: PROC [ps: ParseState];
Assign the material information in ps.currentMaterial to the shape in ps.currentShape
SaveCurrentShapeInTree: PROC [ps: ParseState];
Save the active shape in the TimeTree associated with ps.
Registering Procedures Callable from a Scene File
SceneProc:  TYPE ~ PROC [ps: ParseState, args: ROPE, data: REF ANY];
Registry:   TYPE ~ LIST OF RECORD [key: ROPE, proc: SceneProc, data: REF ANY];
SourceText:  TYPE ~ REF SourceTextRep;
SourceTextRep: TYPE ~ RECORD [
fileName:     ROPE ¬ NIL,
position:     INT ¬ 0
];
ParseState:  TYPE ~ REF ParseStateRep;
ParseStateRep: TYPE ~ RECORD [
book-keeping:
fileName:    ROPE ¬ NIL,     -- originating scene file (if any)
index:     INT ¬ 0,      -- character position within scene file
errorMessage:  ROPE ¬ NIL,     -- if any errors encountered
errorViewer:   Viewer ¬ NIL,    -- viewer for displaying parse errors
cmdHandle:   Handle ¬ NIL,    -- for Cedar command execution
nesting:    NAT ¬ 0,      -- nesting of parse calls
directory:    ROPE ¬ NIL,     -- working directory
shouldRepaint:  BOOL ¬ FALSE,    -- operations necessitated a repaint?
logProc:    LogProc ¬ NIL,    -- for logging operations
clientData:   REF ANY ¬ NIL,    -- passed to registered procs
3d context3d:
context3d:    Context3d ¬ NIL,    -- rendering information
current attributes:
command:   ROPE ¬ NIL,     -- currently executing command (key)
currentShape:  Shape ¬ NIL,     -- currently active shape
currentMaterial:  Material ¬ [],    -- currently active surface attributes
ctm:     Matrix ¬ NIL,    -- current transformation matrix
build state:
buildData:   REF ANY ¬ NIL,    -- state data for G3dBuild routines
animation support:
timeTree:    TimeTree ¬ NIL,    -- hiearchy with animation info
changes:    PropList ¬ NIL,    -- what's changed in this key
inKey:    BOOL ¬ FALSE,    -- TRUE when we're creating keys
accumulated state:
matrixStack:   LIST OF Matrix ¬ NIL,  -- matrix stack for pusing/popping
randomStream:  RandomStream ¬ NIL,  -- for pseudo-variables
materials:    MaterialSequence ¬ NIL, -- accumulated surface attributes
variables:    VariableSequence ¬ NIL-- accumulated key-substitute pairs
];
Material:     TYPE ~ RECORD [
name:        ROPE ¬ NIL,
backFaces:      BOOL ¬ FALSE,
renderStyle:      RenderStyle ¬ smooth,
color:        Triple ¬ [0.7, 0.7, 0.7],
diffuseReflectivity:    REAL ¬ 1.0,
specularReflectivity:   REAL ¬ 1.0,
metallicity:      REAL ¬ 1.0,
shininess:      REAL ¬ 50.0,
transmittance:     REAL ¬ 0.0,
visible:       BOOL ¬ TRUE,
textureOffset:     Pair ¬ [0.0, 0.0],
textureScale:      Pair ¬ [1.0, 1.0],
bumpScale:      REAL ¬ 1.0,
textureFiltering:     BOOL ¬ FALSE,
textureIntensityName:   ROPE ¬ NIL,
textureColorName:    ROPE ¬ NIL,
textureBumpName:    ROPE ¬ NIL
];
MaterialSequence:  TYPE ~ REF MaterialSequenceRep;
MaterialSequenceRep: TYPE ~ RECORD [
length:       CARDINAL ¬ 0,
element:       SEQUENCE maxLength: CARDINAL OF Material
];
Variable:     TYPE ~ RECORD [name, value: ROPE ¬ NIL];
VariableSequence:  TYPE ~ REF VariableSequenceRep;
VariableSequenceRep: TYPE ~ RECORD [
length:       CARDINAL ¬ 0,
element:       SEQUENCE maxLength: CARDINAL OF Variable
];
ParseError: ERROR [explanation: ROPE];
Procedures registered with the global registry may raise this error, output to a log file results.
RegisterProc: PROC [key: ROPE, proc: SceneProc, data: REF ANY ¬ NIL];
Register the proc as callable from a scene file under the name "key;"
arguments following key (up to a carriage-return) are passed to proc, as is data.
Proc must be a top level procedure and, naturally, must be registered before it is called.
UnregisterProc: PROC [key: ROPE];
Remove the registered proc from the registry.
GetRegistry: PROC RETURNS [Registry];
Return the global registry.
ResetRegistry: PROC;
Set the global registry to NIL.
TimeTree Node Construction
MakeTransformNode: PROC [ps: ParseState];
Create a transform node in ps.timeTree if needed
MakeKeysNode: PROC [ps: ParseState];
Create a keys node in ps.timeTree if needed
MakeShapeNode: PROC [ps: ParseState];
Create a shape node in ps.timeTree if needed
Utility Procs for Registered SceneProcs
AssignCtmToShape: PROC [ps: ParseState, shape: Shape];
Assign the matrix at the top of the stack to the shape.
GetArgs: PROC [ps: ParseState, input, format: ROPE] RETURNS
[Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg,Arg];
Like Args.ArgsGetFromRope, but replaces all variable names in the input
with their values before evaluation.
SubstituteVariables: PROC [
variables: VariableSequence,
input: ROPE,
rs: RandomStream ¬ NIL]
RETURNS [out: ROPE];
In the specified rope replace all variable names with their values.
LookupVariable: PROC [variables: VariableSequence, name: ROPE] RETURNS [ROPE];
Return the value of the variable with the given name. If no such variable exists,
return the name itself as the value.
END.