ThreeDSurfaces.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last Edited by: Crow, May 19, 1986 12:26:46 pm PDT
DIRECTORY
Atom     USING [PropList],
Rope     USING [ROPE],
IO      USING [STREAM],
Vector2    USING [VEC],
ScanConvert   USING [RealSequence],
Vector3d    USING [Triple, Quad],
ThreeDScenes  USING [AllOut, ClipState, Context, NoneOut, OutCode, ShapeInstance,
        ShapeSequence, Vertex, VertexInfo, VertexInfoSequence];
ThreeDSurfaces: CEDAR DEFINITIONS
~ BEGIN
Basic Types
Context: TYPE ~ ThreeDScenes.Context;
Pair: TYPE ~ Vector2.VEC;           -- [ x, y: REAL];
Triple: TYPE ~ Vector3d.Triple;       -- [ x, y, z: REAL];
Quad: TYPE ~ Vector3d.Quad;        -- [ x, y, z, w: REAL];
RealSequence: TYPE ~ ScanConvert.RealSequence;
OutCode: TYPE ~ ThreeDScenes.OutCode;
NoneOut: OutCode ~ ThreeDScenes.NoneOut;
AllOut: OutCode ~ ThreeDScenes.AllOut;
Vertex Definitions
Vertex: TYPE ~ ThreeDScenes.Vertex;
VertexInfo: TYPE ~ ThreeDScenes.VertexInfo;
VertexInfoSequence: TYPE ~ ThreeDScenes.VertexInfoSequence;
Patch Definitions
Patch: TYPE ~ RECORD[type: ATOMNIL, oneSided: BOOLEANTRUE, nVtces: NAT ← 0,
       clipState: ClipState ← in, props: Atom.PropList ← NIL,
       vtx: SEQUENCE length: NAT OF VertexInfo];
ImplementedPatch types: $ConvexPolygon, $Bezier
PatchProcs: TYPE ~ RECORD[
expand: PatchExpandProc,
subdivide: PatchExpandProc,
display: PatchDisplayProc,
displayLines: PatchDisplayProc
];
PatchSequence: TYPE ~ RECORD [SEQUENCE length: CARDINAL OF REF Patch];
PtrPatch: TYPE ~ RECORD[type: ATOMNIL, oneSided: BOOLEANTRUE, nVtces: NAT ← 0,
        clipState: ClipState ← in, props: Atom.PropList ← NIL,
        vtxPtr: SEQUENCE length: NAT OF NAT];
PtrPatchSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF PtrPatch];
ShapePatch: TYPE ~ RECORD[shape: REF ShapeInstance, patch, next: NAT];
SortSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF ShapePatch];
Shape Definitions
ClipState: TYPE ~ ThreeDScenes.ClipState;
ShapeInstance: TYPE ~ ThreeDScenes.ShapeInstance;
Utility Procedures
EnableDisplay: PROC [];
StopDisplay: PROC [];
ShapePatchToPatch: PROC[ context: REF Context, sPatch: REF ThreeDSurfaces.ShapePatch ]
       RETURNS
[patch: REF Patch];
Procedures for Reading in Shape Descriptions
LoadShape: PROC[shape: REF ShapeInstance, fileName: Rope.ROPE,
      type: ATOM ← $ConvexPolygon, insideVisible: BOOLEANFALSE];
ReadPatches: PROC[ shape: REF ShapeInstance, in: IO.STREAM, nPatches: NAT,
      type: ATOM, insideVisible: BOOLEANFALSE ];
GetPatchColors: PROC[shape: REF ShapeInstance, fileName: Rope.ROPE];
Procedures for Transformations and Clipping
ClipPoly: PROC[ context: REF Context, poly: REF Patch] RETURNS [REF Patch];
GetPatchClipState: PROC[ patch: REF Patch];
Procedures for expansion of/to polygons
PatchExpandProc: TYPE ~ PROC[ shape: REF ShapeInstance, patch: REF PtrPatch,
          limitType: ATOM, limit: REAL]
        RETURNS[ v: REF VertexInfoSequence, p: REF PtrPatchSequence ];
Expands a patch in one step to displayable polygons
PatchDisplayProc: TYPE ~ PROC[ context: REF Context, patch: REF Patch,
          limitType: ATOM, limit: REAL,
          
action: PROC[context: REF Context, patch: REF Patch] ];
Expands and displays the patch in whatever way it chooses, using the supplied action proc
ShapeExpand: PROC[ context: REF Context, shape: REF ShapeInstance,
       limitType: ATOMNIL, limit: REAL ← 0.0]
     RETURNS [REF ShapeInstance];
Expands a whole shape, calling procedures supplied by the surface type
ShapeSubdivide: PROC[ context: REF Context, shape: REF ShapeInstance,
        limitType: ATOMNIL, limit: REAL ← 0.0]
     RETURNS [REF ShapeInstance];
Subdivide a whole shape once, calling procedures supplied by the surface type
RegisterSurfaceType: PROC[ context: REF Context, type: ATOM, procs: REF PatchProcs ];
Mechanism for a surface type to register its expansion, subdivision, and display procedures
Procedures for Shading Surfaces
BackFacing: PROC[ poly: REF Patch, useEyeSpace: BOOLEANFALSE] RETURNS [BOOLEAN];
ShadePoly: PROC[ context: REF Context, poly: REF Patch];
GetShades: PROC[context: REF Context, shape: REF ShapeInstance];
GetPolyNormals: PROC[shape: REF ShapeInstance];
GetVtxNormals: PROC[shape: REF ShapeInstance];
Procedures for Sorting and Display
LoadSortSequence: PROC[context: REF Context, buckets: REF SortSequence ← NIL]
      RETURNS[REF SortSequence];
 This builds a back-to-front ordered sequence of patch references
These call a procedure for each polygon in a set of objects
DoBackToFront: PROC[ context: REF Context, sortSeq: REF SortSequence,
       action: PROC[REF ShapePatch]];
DoFrontToBack: PROC[ context: REF Context, sortSeq: REF SortSequence,
       action: PROC[REF ShapePatch]];
DoForPatches: PROC[context: REF Context, set: REF ThreeDScenes.ShapeSequence,
       patchAction: PROC[REF ShapePatch],
       shapeAction: PROC[REF ThreeDScenes.ShapeInstance]];
These render entire scenes
ShowObjects: PROC[ context: REF Context, frontToBack: BOOLEANFALSE ];
ShowWireFrameObjects: PROC[context: REF Context];

These scan convert an individual patch
OutputPatchEdges: PROC[context: REF Context, patch: REF Patch];
OutputPatch: PROC[context: REF Context, patch: REF Patch];
END.