ThreeDScenes.mesa
Copyright © 1984, 1986 by Xerox Corporation. All rights reserved.
Last Edited by: Crow, May 24, 1986 1:36:49 pm PDT
DIRECTORY
Rope     USING [ROPE],
Atom     USING [PropList],
IO      USING [STREAM],
Imager    USING [Rectangle, Context],
ImagerColor   USING [RGB],
Vector2    USING [VEC],
Pixels     USING [Extent, PixelBuffer],
ScanConvert   USING [RealSequence, GetColorProc],
Vector3d    USING [Triple, Quad],
Matrix3d    USING [Matrix];
ThreeDScenes: CEDAR DEFINITIONS
~ BEGIN
Basic Types
Error: SIGNAL [reason: ErrorDesc];
ErrorDesc: TYPE ~ RECORD [code: ATOM, explanation: Rope.ROPE];
RGB: TYPE ~ ImagerColor.RGB;
Pair: TYPE ~ Vector2.VEC;           -- RECORD [ x, y: REAL];
Triple: TYPE ~ Vector3d.Triple;        -- RECORD [ x, y, z: REAL];
Quad: TYPE ~ Vector3d.Quad;         -- RECORD [ x, y, z, w: REAL];
Rectangle: TYPE ~ Pixels.Extent;
RealSequence: TYPE ~ ScanConvert.RealSequence;
Xfm3D: TYPE ~ Matrix3d.Matrix; -- REF ARRAY [0..4) OF ARRAY [0..4) OF REAL
ScaleAndAddXfm: TYPE ~ RECORD[scaleX, scaleY, scaleZ, addX, addY, addZ: REAL];
Box: TYPE ~ RECORD[left, right, bottom, top: NAT];    -- bounding box for limit tests
SixSides: TYPE ~ {Left, Right, Bottom, Top, Near, Far};
OutCode: TYPE ~ RECORD[left, right, bottom, top, near, far: BOOLEAN];
NoneOut: OutCode ~ [FALSE, FALSE, FALSE, FALSE, FALSE, FALSE];
AllOut: OutCode ~ [TRUE, TRUE, TRUE, TRUE, TRUE, TRUE];
Vertex Definitions
Vertex: TYPE ~ RECORD[
x,y,z: REAL ← 0.0,     -- object coordinates
ex, ey, ez: REAL ← 0.0,   -- eyespace coordinates
sx, sy, sz: REAL ← 0.0,    -- screen coordinates
clip: OutCode ← NoneOut -- clip code
];
VertexSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF Vertex];
ShadingValue: TYPE ~ RECORD[
xn,yn,zn: REAL ← 0.0,   -- normal vector to surface
r,g,b: REAL ← 0.7,     -- original color (default grey)
t: REAL ← 0.0,     -- original transmittance
txtrX,txtrY,txtrZ: REAL ← 0.0,  -- texture coordinates
exn,eyn,ezn: REAL ← 0.0,   -- normal in eyespace
ir,ig,ib,it: CARDINAL ← 0 -- computed color and transmittance (for current lights, view, etc.)
];
ShadingSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF ShadingValue];
VertexInfo: TYPE ~ RECORD[coord: Vertex, shade: ShadingValue, props: Atom.PropList];
VertexInfoSequence: TYPE ~ RECORD [SEQUENCE length: CARDINAL OF REF VertexInfo];
VtxToRealSeqProc: TYPE ~ PROC[dest: REF RealSequence, source: VertexInfo]
        RETURNS
[REF RealSequence];
ShadingProcs: TYPE ~ RECORD [VtxToRealSeqProc, ScanConvert.GetColorProc];
Shape Definitions (also used for lights)
ClipState: TYPE ~ { in, out, clipped };
ShapeInstance: TYPE ~ RECORD[
type: ATOMNIL,        -- eg. $ConvexPolygon, $Bezier, $Light, etc.
insideVisible: BOOLEANFALSE,    -- closed (or open) surface
name: Rope.ROPE ← NIL,       -- local name for Shape (allows instancing)
fileName: Rope.ROPENIL,      -- file name (should be on a server)
location: Triple ← [0.,0.,0.],      -- position in scene space (last transform)
orientation: Triple ← [0.,0.,1.],     -- vector defining orientation (second transform)
rotation: REAL ← 0.,        -- rotation about rotation axis (first transform)
axisBase: Triple ← [0.,0.,0.],      -- rotation axis: direction = End - Base
axisEnd: Triple ← [0.,0.,1.],      --     rotation is about base point
position: Xfm3D ← NIL,      -- transform from definition space to world space
positionInValid: BOOLEANTRUE,    -- location, orientation, or rotation changed
clipState: ClipState ← in,       -- { in, out, clipped }
shadingInValid: BOOLEANTRUE,    -- true if light or object changed
vtcesInValid: BOOLEANTRUE,    -- true if object or view changed
centroid: Vertex,         -- bounding sphere
boundingRadius: REAL ← 0.0,
screenExtent: Box ← [0, 0, 0, 0],    -- extent on screen (when position valid)
vertex: REF VertexSequence ← NIL,   -- location and clip codes for defining points
shade: REF ShadingSequence ← NIL,    -- shading at defining points
numSurfaces: NAT ← 0,       -- number of surface elements
surface: REF ANYNIL,      -- surface definition using defining points
shadingProps: Atom.PropList ← NIL,   -- shading definition
props: Atom.PropList ← NIL      -- catchall
];
ShapeSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF ShapeInstance];
Uses for ShapeInstance.shadingProps:
- $Type - {$Faceted, $Smooth, $Lines}
- $Color - {REF RGB}
- $Transmittance - {REF REAL}
- $Shininess - {REF REAL}
- $PatchColors - {ShadingValue for each Patch}
Context Definition
Context: TYPE ~ RECORD [
shapes: REF ShapeSequence ← NIL,   -- current collection of shapes in environment
lights: REF ShapeSequence ← NIL,    -- current light sources
environment: Atom.PropList ← NIL,   -- for reflection map, ambient light proc, etc.
eyePoint: Triple ← [1.0, -5.0, 2.0],  -- defines point from which view is seen
ptOfInterest: Triple ← [0.,0.,0.],    -- defines center of image and focus
rollAngle: REAL ← 0.,       -- rotational angle about direction of view
upDirection: Triple ← [0.,0.,1.],    -- defines "heads-up" direction (redundant)
fieldOfView: REAL ← 40.,      -- horizontal angle included in field of view
window: Imager.Rectangle ← [-1.,-1., 2., 2.], -- window clips field of view in eyespace
hitherLimit: REAL ← 1.,       -- anything closer to eyepoint is clipped
yonLimit: REAL ← 1000.,      -- anything further from eyepoint is clipped
clippingPlanes: ARRAY SixSides OF Quad,  -- computed clip planes
eyeSpaceXfm: Xfm3D ← NIL,    -- world space to eyespace
eyeToNDC: ScaleAndAddXfm ← [1.,1.,1., 0.,0.,0.], -- eyespace to normalized display coords
display: Pixels.PixelBuffer,  -- display-specific info
viewPort: Imager.Rectangle,     -- viewport in floating pt. display coordinates
extentCovered: Box ← [0, 0, 0, 0],    -- bounds area used (while building image)
renderMode: ATOMNIL,   -- {$Dithered, $PseudoClr, $Grey, $Dorado24, $FullClr }
alphaBuffer: BOOLEANFALSE,    -- buffer for matting and antialiasing
depthBuffer: BOOLEANFALSE,    -- buffer for cheap hidden-surface removal
lineDrawing: BOOLEANFALSE,    -- vector or shaded representation
depthResolution: NAT ← 8192,  -- number of buckets for depth sorting
sortSequence: REFNIL,      -- shapes or surfaces sorted for display
props: Atom.PropList ← NIL-- catchall
];
Procedures for Setting up Contexts
GetFromImagerContext: PROC[ imagerCtx: Imager.Context,
          alpha, depth, grey: BOOLEANFALSE ]
        RETURNS [REF Context];
Sets up context using imager context where possible, options: alpha, depth buffer & greyscale
Create: PROC[ width, height: NAT, renderMode: ATOM, alpha, depth: BOOLEANFALSE ]
   RETURNS [REF Context];
Procedures for Defining and Altering Environments
SetEyeSpace: PROC[ context: REF Context ];    -- get worldspace to eyespace matrix
SetWindow: PROC[context: REF Context, size: Imager.Rectangle];
WindowFromViewPort: PROC[viewPort: Imager.Rectangle] RETURNS[Imager.Rectangle];
SetViewPort: PROC[context: REF Context, size: Imager.Rectangle, clear: BOOLEANFALSE];
FillViewPort: PROC[context: REF Context, clr: RGB]; -- clears for new image
FillInBackGround: PROC[context: REF Context]; -- loads background behind current image
SetView: PROC[context: REF Context, eyePoint, ptOfInterest: Triple, fieldOfView: REAL ← 40.0,
     rollAngle: REAL ← 0.0, upDirection: Triple ← [ 0., 0., 1.],
     hitherLimit: REAL ← .01, yonLimit: REAL ← 1000.0];
SetLight: PROC[context: REF Context, name: Rope.ROPE, position: Triple, color: RGB ← [1., 1., 1.]]
   RETURNS
[REF ShapeInstance];
DeleteLight: PROC[context: REF Context, name: Rope.ROPE];
GetAmbientLight: PROC[context: REF Context, normal: Triple] RETURNS[RGB];
ReadScene: PROC[context: REF Context, input: IO.STREAM];
WriteScene: PROC[context: REF Context, output: IO.STREAM];
Procedures for Manipulating Shapes
NewShape: PROC[ name: Rope.ROPE ] RETURNS[REF ShapeInstance];
FindShape: PROC[ set: REF ShapeSequence, name: Rope.ROPE ] RETURNS[REF ShapeInstance];
AddShape: PROC[ set: REF ShapeSequence, shape: REF ShapeInstance ]
    RETURNS
[REF ShapeSequence];
DeleteShape: PROC[ set: REF ShapeSequence, name: Rope.ROPE ] RETURNS[REF ShapeSequence];
CopyShape: PROC[ shape: REF ShapeInstance, newName: Rope.ROPE ]
    RETURNS
[REF ShapeInstance];
PlaceShape: PROC[ shape: REF ShapeInstance, location: Triple]; -- absolute position
MoveShape: PROC[ shape: REF ShapeInstance, delta: Triple];    -- relative position
OrientShape: PROC[ shape: REF ShapeInstance, axis: Triple];    -- tilt from vertical
RotateShape: PUBLIC PROC[ shape: REF ShapeInstance, axisBase, axisEnd: Triple, theta: REAL ];
Rotation about arbitrary axis
SetPosition: PROC[shape: REF ShapeInstance, concat: BOOLEANFALSE];
Get new position matrix or concatenate to previous matrix
PutShading: PROC[ shape: REF ShapeInstance, key: ATOM, value: REF ANY];
GetShading: PROC[ shape: REF ShapeInstance, key: ATOM ] RETURNS [value: REF ANY];
Procedures for Manipulating Vertices
InitShades: PROC[ shape: REF ShapeInstance ] RETURNS[shade: REF ShadingSequence];
SetUpStandardFile: PROC[file: Rope.ROPE] RETURNS [stream: IO.STREAM, numEntries: NAT];
ReadVertexCoords: PROC[vtx: REF VertexSequence, in: IO.STREAM, nVtces: NAT];
ReadTextureCoords: PROC[shade: REF ShadingSequence, in: IO.STREAM, nVtces: NAT];
ReadColors: PROC[shade: REF ShadingSequence, in: IO.STREAM, length: NAT];
ReadNormals: PROC[shade: REF ShadingSequence, in: IO.STREAM, length: NAT];
GetClipCodeForPt: PROC[context: REF Context, pt: Triple] RETURNS[clip: OutCode];
XfmPtToEyeSpace: PROC[context: REF Context, pt: Triple] RETURNS[Triple, OutCode];
XfmPtToDisplay: PROC[context: REF Context, pt: Triple] RETURNS[Triple];
ShadePt: PROC [context: REF Context, pt: VertexInfo, shininess: REAL]
   RETURNS [RGB, REAL];
XfmToEyeSpace: PROC[context: REF Context, shape: REF ShapeInstance] RETURNS[ClipState];
XfmToDisplay: PROC[context: REF Context, shape: REF ShapeInstance];
GetVtxShades: PROC[ context: REF Context, shape: REF ShapeInstance ];
END.