<> <> <> <> DIRECTORY Rope USING [ ROPE ], Atom USING [ PropList ], Terminal USING [ Virtual ], ViewerClasses USING [ Viewer ], Imager USING [ Context, Rectangle ], ImagerPixel USING [ PixelMap ], ImagerSample USING [ Box ], ImagerColor USING [ RGB ], G3dBasic, G3dMatrix; ThreeDBasics: CEDAR DEFINITIONS ~ BEGIN <> Error: SIGNAL [reason: ErrorDesc]; ErrorDesc: TYPE ~ RECORD [code: ATOM, explanation: Rope.ROPE]; RGB: TYPE ~ ImagerColor.RGB; RGBSequence: TYPE ~ RECORD [ length: NAT _ 0, s: SEQUENCE maxLength: NAT OF RGB]; NatRGB: TYPE ~ RECORD [r, g, b: NAT]; NatRGBSequence: TYPE ~ RECORD [ length: NAT _ 0, s: SEQUENCE maxLength: NAT OF NatRGB]; PixelPart: TYPE ~ { r, g, b, a, z }; -- addressing within Pixels Pixel: TYPE ~ ARRAY PixelPart OF CARDINAL; -- r, g, b, alpha, z (depth) RealSequence: TYPE ~ G3dBasic.RealSequenceRep; IntegerSequence: TYPE ~ G3dBasic.IntegerSequenceRep; IntSequence: TYPE ~ G3dBasic.IntSequenceRep; NatSequence: TYPE ~ G3dBasic.NatSequenceRep; NatTable: TYPE ~ G3dBasic.NatTableRep; Pair: TYPE ~ G3dBasic.Pair; -- RECORD [x, y: REAL]; PairSequence: TYPE ~ G3dBasic.PairSequenceRep; IntegerPair: TYPE ~ G3dBasic.IntegerPair; -- RECORD [x, y: INTEGER]; IntegerPairSequence: TYPE ~ G3dBasic.IntegerPairSequenceRep; Triple: TYPE ~ G3dBasic.Triple; -- RECORD [x, y, z: REAL]; TripleSequence: TYPE ~ G3dBasic.TripleSequenceRep; Quad: TYPE ~ G3dBasic.Quad; -- RECORD [x, y, z, w: REAL]; QuadSequence: TYPE ~ G3dBasic.QuadSequenceRep; Box: TYPE ~ ImagerSample.Box; -- [min, max: [s, f: INTEGER] _ zeroVec] Rectangle: TYPE ~ Imager.Rectangle; -- RECORD [x, y, w, h: REAL] Xfm3D: TYPE ~ G3dMatrix.Matrix; -- REF 4 by 4 ARRAY OF REAL Xfm3DRep: TYPE ~ G3dMatrix.MatrixRep; ScaleAndAddXfm: TYPE ~ RECORD[scaleX, scaleY, scaleZ, addX, addY, addZ: REAL]; 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]; <> Spot: TYPE ~ RECORD[ coverage: REAL _ 1.0, -- percentage of pixel area covered by surface mask: BYTE _ 255, -- coding for covered area (default, all covered) partShiny: REAL _ 1.0, -- how much of shiny surface shows (1.0 = all) val: REF RealSequence _ NIL, -- interpolated values for shading yIncr: REF RealSequence _ NIL, -- vertical increments for interpolated values xIncr: REF RealSequence _ NIL, -- horizontal increments for interpolated values xySwapped: BOOLEAN, -- if TRUE, xincr and yincr are swapped props: Atom.PropList _ NIL -- catchall ]; SpotProc: TYPE ~ PROC[ context: REF Context, shading: REF ShadingClass, spot: REF Spot, data: REF ANY _ NIL ]; <> TextureFunction: TYPE ~ RECORD[name: ATOM, proc: SpotProc, props: Atom.PropList]; TextureMap: TYPE ~ RECORD[type: ATOM, pixels: REF ANY, props: Atom.PropList]; SummedTexture: TYPE ~ RECORD[SEQUENCE length: NAT OF REF SumSequence]; SumSequence: TYPE ~ RECORD[SEQUENCE length: NAT OF REF IntSequence]; <<>> <> 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[ length: CARDINAL _ 0, entry: SEQUENCE maxLength: CARDINAL OF REF Vertex ]; ShadingValue: TYPE ~ RECORD[ xn,yn,zn: REAL _ 0.0, -- normal vector to surface exn,eyn,ezn: REAL _ 0.0, -- normal in eyespace r,g,b: REAL _ 1.0, -- vertex color (default white) scaled by object color t: REAL _ 1.0, -- original transmittance er,eg,eb,et: REAL _ 0.0 -- computed color and transmittance (for current lights, view, etc.) ]; ShadingSequence: TYPE ~ RECORD[ length: CARDINAL _ 0, entry: SEQUENCE maxLength: CARDINAL OF REF ShadingValue ]; VertexInfo: TYPE ~ RECORD[coord: Vertex, shade: ShadingValue, props: Atom.PropList, aux: REF ANY]; VertexInfoSequence: TYPE ~ RECORD [ length: CARDINAL _ 0, entry: SEQUENCE maxLength: CARDINAL OF REF VertexInfo ]; VertexInfoProc: TYPE ~ PROC[ context: REF Context, vtx: VertexInfo, data: REF ANY _ NIL ] RETURNS[VertexInfo]; VtxToRealSeqProc: TYPE ~ PROC[ dest: REF RealSequence, source: VertexInfo, data: REF ANY _ NIL ] RETURNS[REF RealSequence]; <> FacingDir: TYPE ~ { front, back, undetermined }; Patch: TYPE ~ RECORD[type: ATOM _ NIL, oneSided: BOOLEAN _ TRUE, nVtces: NAT _ 0, clipState: ClipState _ undetermined, dir: FacingDir _ undetermined, props: Atom.PropList _ NIL, vtx: SEQUENCE maxLength: NAT OF VertexInfo]; <> <> PatchSequence: TYPE ~ RECORD [ length: CARDINAL _ 0, entry: SEQUENCE maxLength: CARDINAL OF REF Patch ]; PtrPatch: TYPE ~ RECORD[type: ATOM _ NIL, oneSided: BOOLEAN _ TRUE, nVtces: NAT _ 0, clipState: ClipState _ undetermined, dir: FacingDir _ undetermined, props: Atom.PropList _ NIL, vtxPtr: REF NatSequence]; PtrPatchSequence: TYPE ~ RECORD[ length: CARDINAL _ 0, entry: SEQUENCE maxLength: CARDINAL OF REF PtrPatch ]; PatchProc: TYPE ~ PROC[ context: REF Context, patch: REF Patch, data: REF ANY _ NIL ] RETURNS[REF Patch]; PtrPatchProc: TYPE ~ PROC[ context: REF Context, patch: REF PtrPatch, data: REF ANY _ NIL ] RETURNS[REF PtrPatch]; <> ClipState: TYPE ~ { in, out, clipped, undetermined }; ShapeInstance: TYPE ~ RECORD[ class: REF ShapeClass _ NIL, -- surface type, reloadable display procedures shadingClass: REF ShadingClass _ NIL, -- shading parameters and procedures name: Rope.ROPE _ NIL, -- local name for Shape (allows instancing) fileName: Rope.ROPE _ NIL, -- file name (should be on a server) fixedProps: Atom.PropList _ NIL, -- fixed attributes props: Atom.PropList _ NIL, -- catchall ($LinesList, $Hidden) <> 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: BOOLEAN _ TRUE, -- location, orientation, or rotation changed <> insideVisible: BOOLEAN _ FALSE, -- closed (or open) surface clipState: ClipState _ undetermined, -- { in, out, clipped } shadingInValid: BOOLEAN _ TRUE, -- true if light or object changed vtcesInValid: BOOLEAN _ TRUE, -- 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 ANY _ NIL, -- surface definition using defining points shadingProps: Atom.PropList _ NIL -- shading status and parameters ]; <> <<- $Closed, $PatchColors, $PatchColorsInFile, $PatchInfo, $PatchNormalsInFile, $PatchTransmittancesInFile, $VertexColorsInFile, $VertexNormalsInFile, $VertexTextureInFile, $VertexTransmittanceInFile>> <<>> <> <<- $ClippedPatches, $ClippedVertices, $Hidden, $LinesList, >> <<>> <> <<- $AuxiliaryVtxData, $PolygonInfoComputed, $Scale, $ShapeLerp, $TextureScale, $TxtrCoordParams, $TxtrCoordRange, $TxtrCoordType, $TxtrTranslation, $VtxInfoComputed>> <<>> ShapeClass: TYPE ~ RECORD[ type: ATOM _ NIL, -- eg. $ConvexPolygon, $Bezier, $Light, etc. validate: ShapeProc _ NIL, -- update vtces and shading after changes display: ShapeProc _ NIL, -- display whole shape (speed optimized?) displayPatch: PatchProc _ NIL, -- display patch (for priority display algorithms) doBeforeFrame: LIST OF ShapeProc _ NIL -- to do before display (for animation, etc.) ]; ShadingClass: TYPE ~ RECORD[ type: ATOM _ NIL, -- eg. $Default, $MappedAndSolidTexture shadingType: ATOM _ NIL, -- $Faceted or $Smooth, $Lines, or supplied ShapeProc color: RGB _ [0.7, 0.7, 0.7], -- whole object color, may be mixed with vtx color shininess: REAL _ 0.0, -- highlight power, typically 30.0-300.0, 0 means none transmittance: REAL _ 0.0, -- surface transmittance of object patchShade: REF ShadingSequence _ NIL, -- shading per patch texture: LIST OF REF ANY _ NIL, -- TextureMap, Solid texture function, etc. cnvrtVtx: VtxToRealSeqProc _ NIL, -- converts vertex to sequence of reals getColor: SpotProc _ NIL, -- calculates shade at pixel loadShapeAux: ShapeProc _ NIL, -- loads extra shading info for shape loadVtxAux: VertexInfoProc _ NIL, -- loads extra info per vertex lerpVtxAux: VertexInfoProc _ NIL, -- interpolates extra info per vertex shadeVtx: VertexInfoProc _ NIL -- calculates shade from vertex info ]; ShapeSequence: TYPE ~ RECORD[ length: CARDINAL _ 0, entry: SEQUENCE maxLength: CARDINAL OF REF ShapeInstance ]; ShapeProc: TYPE ~ PROC[context: REF Context, shape: REF ShapeInstance, data: REF ANY _ NIL] RETURNS[REF ShapeInstance]; <> Context: TYPE ~ RECORD [ class: REF ContextClass _ NIL, stopMe: REF BOOLEAN _ NIL, -- stop flag for bailing out (ref for inheritance) imageReady: BOOLEAN _ FALSE, -- flag for useable image in display <> frameNumber: NAT _ 0, -- current frame for animation routines shapes: REF ShapeSequence _ NIL, -- current collection of shapes and lights visibleShapes: REF ShapeSequence _ NIL, -- computed by SurfaceRender.ValidateContext lightSources: REF ShapeSequence _ NIL, -- computed by SurfaceRender.ValidateContext environment: Atom.PropList _ NIL, -- for reflection map, ambient light proc, etc. <> viewInValid: BOOLEAN _ TRUE, -- true whenever view parameter updated 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: REF Rectangle _ NIL, -- 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 ndcToPixels: ScaleAndAddXfm _ [1.,1.,1., 0.,0.,0.], -- to screen coords <> viewer: ViewerClasses.Viewer, -- viewer record if in Viewer ELSE NIL terminal: Terminal.Virtual _ NIL, -- virtual terminal for this context, if displayed displayInValid: BOOLEAN _ TRUE, -- true whenever display parameter updated pixels: ImagerPixel.PixelMap _ NIL, -- where the bits are pixelAspectRatio: REAL _ 1.0, -- physical width/height of displayed pixel viewPort: REF Rectangle _ NIL, -- viewport in floating pt. display coordinates preferredViewPort: Rectangle _ [0.,0.,65536.,65536.], -- maximum viewport size extentCovered: Box _ [[0, 0], [0, 0]], -- bounds area used (while building image) preferredRenderMode: ATOM _ NIL, -- $Pixels, $Imager (fancy vs. device independent) displayProps: Atom.PropList _ NIL, -- $Depth, $Alpha (Pixel posn), -- $FullDisplayMemory, $ViewerAdjusted <> autoRedraw: BOOLEAN _ FALSE, -- quick image hint, redraw if viewer changes delayClear: BOOLEAN _ FALSE, -- delay clearing buffer when rendering doVisibly: BOOLEAN _ TRUE, -- build image on display antiAliasing: BOOLEAN _ FALSE, -- flag for antialiasing and alpha buffer depthBuffering: BOOLEAN _ FALSE, -- buffer for cheap hidden-surface removal depthResolution: NAT _ 8192, -- number of buckets for depth sorting sortSequence: REF _ NIL, -- shapes or surfaces sorted for display props: Atom.PropList _ NIL -- catchall <> ]; ContextClass: TYPE ~ RECORD[ displayType: ATOM _ NIL, -- { $PseudoColor, $Gray, $FullColor, << $ImagerGray, $ImagerDithered, $ImagerFullClr,>> << $Bitmap, $Interpress } >> setUpDisplayType: ContextProc, -- makes sure there are bits to write, sets up colors validateDisplay: ContextProc, -- makes sure viewPort changes, etc. take effect render: ContextProc, -- call this to display the scene loadBackground: ContextProc, -- clear to background << 2d drawing primitives use normalized display coordinates (-1.0 < x < 1.0, -.75 < y < .75)>> draw2DLine: PROC[context: REF Context, p1, p2: Pair, color: Pixel], -- display a line draw2DPolygon: PROC[context: REF Context, poly: REF PairSequence, color: Pixel], draw2DRope: PROC[context: REF Context, rope: Rope.ROPE, position: Pair, color: Pixel _ [255,255,128,0,0], size: REAL _ 20, font: Rope.ROPE _ NIL], displayPolygon: PatchProc, -- 3 dimensional shading drawInViewer: PROC[ context: REF Context, procRec: REF ImagerProcRec ], updateViewer: ContextProc ]; ContextProc: TYPE ~ PROC[ context: REF Context, data: REF ANY _ NIL ]; ImagerProc: TYPE ~ PROC[ context: REF Context, imagerCtx: Imager.Context, data: REF ANY _ NIL ]; ImagerProcRec: TYPE ~ RECORD[ proc: ImagerProc, data: REF ANY _ NIL ]; <> RectangleFromBox: PROC[ Box ] RETURNS[ Rectangle ]; BoxFromRectangle: PROC[ Rectangle ] RETURNS[ Box ]; IntersectRectangles: PROC[ Rectangle, Rectangle ] RETURNS[ Rectangle ]; <> RegisterDisplayType: PROC[ class: ContextClass, type: ATOM ]; <> GetDisplayType: PROC[ type: ATOM ] RETURNS[ class: ContextClass ]; <> LoadDisplayType: PROC[ context: REF Context, type: ATOM ]; <> RegisterSurfaceType: PROC[ class: ShapeClass, type: ATOM ]; <> GetSurfaceType: PROC[ type: ATOM ] RETURNS[ class: ShapeClass ]; <> LoadSurfaceType: PROC[ shape: REF ShapeInstance, type: ATOM _ $ConvexPolygon ]; <> RegisterShadingClass: PROC[ class: ShadingClass, type: ATOM ]; <> GetShadingClass: PROC[ type: ATOM ] RETURNS[ class: ShadingClass ]; <> LoadShadingClass: PUBLIC PROC[ shape: REF ShapeInstance, type: ATOM _ $Default ]; <> <> Create: PROC[] RETURNS [REF Context]; <> SetView: PUBLIC 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]; SetPosition: PROC[ shape: REF ShapeInstance, concat: BOOLEAN _ FALSE ]; <> CloseDisplay: PROC[context: REF Context]; <> <<>> END.