SceneUtilities.mesa
Copyright © 1984, 1986 by Xerox Corporation. All rights reserved.
Last Edited by: Crow, April 9, 1988 3:24:29 pm PDT
Bloomenthal, September 6, 1988 5:06:07 pm PDT
DIRECTORY
Rope     USING [ ROPE ],
IO      USING [ STREAM ],
Imager    USING [ Rectangle ],
ThreeDBasics  USING [ Context, NatTable, PairSequence, Patch, RealSequence, RGB,
         RGBSequence, ShapeInstance, ShapeSequence, Triple,
         TripleSequence ];
SceneUtilities: CEDAR DEFINITIONS
~ BEGIN
Basic Types
RGB: TYPE ~ ThreeDBasics.RGB;
RGBSequence: TYPE ~ ThreeDBasics.RGBSequence;
RealSequence: TYPE ~ ThreeDBasics.RealSequence;
PairSequence: TYPE ~ ThreeDBasics.PairSequence;
TripleSequence: TYPE ~ ThreeDBasics.TripleSequence;
Triple: TYPE ~ ThreeDBasics.Triple;        -- RECORD [ x, y, z: REAL];
NatTable: TYPE ~ ThreeDBasics.NatTable;
Patch: TYPE ~ ThreeDBasics.Patch;
ShapeInstance: TYPE ~ ThreeDBasics.ShapeInstance;
ShapeSequence: TYPE ~ ThreeDBasics.ShapeSequence;
Context: TYPE ~ ThreeDBasics.Context;
Utility Procedures
GetRope: PROC[input: IO.STREAM] RETURNS[Rope.ROPE];
Procedures for Setting up and using Contexts
CreateDefaultContext: PROC[] RETURNS [REF Context];
sets up context with blue background, white light source over left shoulder, view from 12 units or so, rendering through fancy renderer
PrependWorkingDirectory: PROC[context: REF Context, file: Rope.ROPE] RETURNS[Rope.ROPE];
adds working directory from context to name
TackOnExtension: PUBLIC PROC[file, extension: Rope.ROPE] RETURNS[Rope.ROPE];
adds extension ".interpress" to end of name if there is no existing extension
GetTmpContext: PROC [srcCtx: REF Context] RETURNS[dstCtx: REF Context];
copies context so temporary modifications can be made
CopyContextData: PROC [dstCtx, srcCtx: REF Context];
copies all but display
CopyContextShapes: PROC [dstCtx, srcCtx: REF Context];
copies all shapes so that they can be modified without affecting the original descriptions
StartLog: PROC [context: REF Context] RETURNS[IO.STREAM];
open typescript log
FlushLog: PROC [context: REF Context];
for safety from potential disasters    
CloseLog: PROC [context: REF Context];
close when done to flush
Procedures for Defining and Altering Environments
ForcePrioritySort: PROC[context: REF Context, on: BOOLEANTRUE];
Set up to do priority sort on polygons to get intersecting surfaces
SetWindow: PROC[context: REF Context, size: Imager.Rectangle];
Set window (for viewing subimage). Window is bounded by -1.0 <= x, y <= 1.0. Context.aspectRatio (default 4/3) further bounds window so longest side runs from -1.0 to 1.0. Any subimage within the bounded region may be displayed by setting a smaller window. The window aspect ratio must match the viewport aspect ratio to get a non-distorted image.
SetViewPort: PROC[context: REF Context, size: Imager.Rectangle];
Changes position and size of area affected on display. Viewport is defined in terms of pixels. Non-square pixels must be compensated for here.
View and Lighting control
SetAmbientLight: PROC [context: REF Context, color: Rope.ROPE];
Set ambient light color
SetBackgroundColor: PROC [context: REF Context, color: RGB];
Set background color
GetBackgroundColor: PROC [context: REF Context] RETURNS [color: RGB];
NameBackgroundColor: PROC [context: REF Context, color: Rope.ROPE];
SetBackgroundImage: PROC [context: REF Context, aisFile: Rope.ROPE];
SetBackgroundContext: PROC [context, bkGrdCtx: REF Context ];
SetLight: PROC[context: REF Context, name: Rope.ROPE, position: Triple, color: RGB ← [1, 1, 1] ];
Install a new light source in the scene, or change a previously named one
DeleteLight: PROC[context: REF Context, name: Rope.ROPE];
Install a new light source in the scene, or change a previously named one
Scene Input/Output
SaveOnFile: PROC[context: REF Context, fileName: Rope.ROPE];
Write out a whole scene to a named file
RestoreFromFile: PROC[context: REF Context, fileName: Rope.ROPE];
Read in a whole scene from a named file
MakeFrameFromFile: PROC[context: REF Context, fileName: Rope.ROPE];
Display a scene stored in a file, leave context unchanged
ReadScene: PROC[context: REF Context, input: IO.STREAM];
Read in a whole scene in a format produced below
WriteScene: PROC[context: REF Context, output: IO.STREAM];
Write out a whole scene in a simple format
Procedures for Reading and Writing Shape Descriptions
SetTexture: PROC [shape: REF ShapeInstance, textures: REF PairSequence];
Assign the texture coordinates for the given shape.
SetVertexProps: PROC [
shape: REF ShapeInstance,
normals, colors, textures, transmittance: BOOL];
Indicate the validity of vertex normals, colors, textures, and transmittance for the shape.
ReadShape: PROC[shape: REF ShapeInstance, fileName: Rope.ROPE];
full format shape read from file
CloneShape: PROC[newshape, oldShape: REF ShapeInstance];
copy shape data, used where new instance of previously read file is desired
AddShapeAt: PROC[ context: REF Context, shapeName: Rope.ROPE, fileName: Rope.ROPE,
      position: Triple ← [0.,0.,0.] ];
Convenience function for reading in a shape from a file and positioning it in a scene, clones previously read shape if file has been used before
WriteShape: PROC[context: REF Context, shapeName: Rope.ROPE, fileName: Rope.ROPE,
      transformed: BOOLFALSE, xyz: BOOLTRUE,
      normal, color, trans, texture, polyClr: BOOLFALSE];
write shape to file, fields set to TRUE will be written, coordinates will be transformed to world space (shape.position applied) if "transformed" is TRUE
Procedures for Manipulating Shapes
NewShape: PROC[ name: Rope.ROPE, type: ATOM ← $ConvexPolygon ]
   RETURNS[REF ShapeInstance];
Returns a new, empty shape data structure, loads name into proper field, loads class
ShapeFromData: PROC[ name: Rope.ROPENIL, surface: REF NatTable,
       vertices, normals: REF TripleSequence ← NIL,
       colors: REF RGBSequence ← NIL, trnsmttnce: REF RealSequence ← NIL,
       txtrCoord: REF PairSequence ← NIL,
       insideVisible, faceted: BOOLFALSE,
       type: ATOM ← $ConvexPolygon ]
     RETURNS[REF ShapeInstance];
builds a shape data structure using the supplied data, NIL parameters are ignored except for "vertices" and "surface" which must be supplied, "faceted" = TRUE assumes that colors are to be applied to facets rather than vertices
ShapeFromRope: PROC[ name: Rope.ROPENIL, message: Rope.ROPE, color: Rope.ROPENIL,
        size: REAL ← 0.5, font: Rope.ROPENIL ]
     RETURNS[REF ShapeInstance];
builds a shape data structure for displaying a message or label in the scene. Shape is two-dimensional, always facing the eyepoint, but changes in size with perspective.
ChangeRopeMessage: PUBLIC PROC[ context: REF Context, shapeName: Rope.ROPE,
           newMessage: Rope.ROPE ];
Changes the message displayed for a rope shape
FindShape: PROC[ context: REF Context, shapeName: Rope.ROPE ]
    RETURNS
[REF ShapeInstance];
Finds shape data, given its name
AddShape: PROC[ context: REF Context, shape: REF ShapeInstance ];
Adds a shape to a context
DeleteShape: PROC[ context: REF Context, shapeName: Rope.ROPE ];
Removes a shape from a context
CopyShape: PROC[ context: REF Context, shapeName, newName: Rope.ROPENIL ]
    RETURNS[REF ShapeInstance];
Makes a copy of a shape, using name to find it in context
CopyShapeDirect: PROC[ shape: REF ShapeInstance, newName: Rope.ROPENIL ]
    RETURNS[REF ShapeInstance];
Makes a copy of a shape
PlaceShape: PROC[ context: REF Context, shapeName: Rope.ROPE, location: Triple];
Places local origin of shape at absolute position in world space
MoveShape: PROC[ context: REF Context, shapeName: Rope.ROPE, delta: Triple];
Moves local origin of shape by given amount in world space
RotateShapeLocal: PROC[ context: REF Context, shapeName: Rope.ROPE, theta: REAL];
Rotation about vertical axis in local shape coordinates or axis last defined by RotateShape
RotateShape: PROC[ context: REF Context, shapeName: Rope.ROPE,
      axisBase, axisEnd: Triple, theta: REAL ];
Rotation about arbitrary axis in local shape coordinates
OrientShape: PROC[ context: REF Context, shapeName: Rope.ROPE, axis: Triple];
Tilts vertical axis of shape into given axis, done after above rotation
Hide: PROC[context: REF Context, shapeName: Rope.ROPE];
Maintain data but don't display
Reveal: PROC[context: REF Context, shapeName: Rope.ROPE];
Undo Hide
Procedures for Shading Surfaces
SetColor: PROC[context: REF Context, shapeName: Rope.ROPE, color: RGB];
SetFaceted: PROC[context: REF Context, shapeName: Rope.ROPE];
Set up shape for Faceted display, set colors and normals for all patches
SetSmooth: PROC[context: REF Context, shapeName: Rope.ROPE];
Set up shape for Smooth (Gouraud Shaded) display
SetHiddenLines: PROC[context: REF Context, shapeName: Rope.ROPE];
Set up shape for Hidden Line drawing display
SetNormaledLines: PROC[context: REF Context, shapeName: Rope.ROPE];
Set up shape for Hidden Line with normals display
SetLines: PROC[context: REF Context, shapeName: Rope.ROPE];
Set up shape for Line drawing display
SetShadedLines: PROC[context: REF Context, shapeName: Rope.ROPE];
SetShiny: PROC[context: REF Context, shapeName: Rope.ROPE, shininess: REAL ← 50.0];
Sets glossiness (size of highlight) for surface, higher shininess means smaller, crisper highlight
SetDull: PROC[context: REF Context, shapeName: Rope.ROPE];
SetTransparent: PROC[context: REF Context, shapeName: Rope.ROPE, t: REAL ← 0.8];
Sets transparency for surface, t ranges from 0.0 (opaque) to 1.0 (clear)
SetOpaque: PROC[context: REF Context, shapeName: Rope.ROPE];
IncludeBackFaces: PROC[context: REF Context, shapeName: Rope.ROPE];
Sets one sided flag on each patch false (if surface uses standard PtrPatch type)
RemoveBackFaces: PROC[context: REF Context, shapeName: Rope.ROPE];
Sets one sided flag on each patch true (if surface uses standard PtrPatch type)
END.