DIRECTORY ColorMap, ColorPackagePrivate, CSG, DisplayMap, Preprocess3d, Real, Rope, SV3d, SVArtwork, SVBoundBox, SVBoundSphere, SVModelTypes, SVRayTypes, SVSceneTypes; Preprocess3dImpl: PROGRAM IMPORTS ColorMap, ColorPackagePrivate, CSG, DisplayMap, SVArtwork, SVBoundBox, SVBoundSphere EXPORTS Preprocess3d = BEGIN BoundBox: TYPE = SVModelTypes.BoundBox; BoundSphere: TYPE = SVModelTypes.BoundSphere; Camera: TYPE = SVModelTypes.Camera; Composite: TYPE = SVRayTypes.Composite; CoordSystem: TYPE = SVModelTypes.CoordSystem; CSGTree: TYPE = SVRayTypes.CSGTree; LightSourceList: TYPE = SVModelTypes.LightSourceList; MasterObject: TYPE = SVSceneTypes.MasterObject; PointSetOp: TYPE = SVRayTypes.PointSetOp; Primitive: TYPE = SVRayTypes.Primitive; SurfaceArray: TYPE = SVRayTypes.SurfaceArray; Surface: TYPE = REF ANY; Vector: TYPE = SV3d.Vector; PreprocessForImage: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bb: BoundBox, bs: BoundSphere] = { IF tree.son = NIL THEN RETURN[ NIL, NIL ]; OpenArtworksInNode[tree.son]; bb _ FindBoundingBoxesInNode[tree.son, camera]; bs _ FindBoundingSpheresInNode[tree.son, camera]; }; PreprocessForSlice: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bs: BoundSphere] = { IF tree.son = NIL THEN RETURN[ NIL ]; bs _ FindBoundingSpheresInNode[tree.son, camera]; }; PreprocessForInteraction: PUBLIC PROC [tree: CSGTree, camera: Camera] RETURNS [bb: BoundBox] = { IF tree.son = NIL THEN RETURN[ NIL ]; bb _ FindBoundingBoxesInNode[tree.son, camera]; }; OpenArtworksInNode: PRIVATE PROC [node: REF ANY] = { WITH node SELECT FROM comp: Composite => { OpenArtworksInNode[comp.leftSolid]; OpenArtworksInNode[comp.rightSolid]; }; prim: Primitive => { SVArtwork.OpenArtwork[prim.artwork]; RETURN; }; ENDCASE => ERROR; }; -- end of OpenArtworksInNode FindBoundingBoxesInNode: PRIVATE PROC [node: REF ANY, camera: Camera] RETURNS [BoundBox] = { WITH node SELECT FROM comp: Composite => {-- bounding box is the combination of the bounding boxes of the children. comp.boundBox _ CSG.CombineBoundBoxes[ FindBoundingBoxesInNode[comp.leftSolid, camera], FindBoundingBoxesInNode[comp.rightSolid, camera], comp.operation]; RETURN[comp.boundBox]; }; prim: Primitive => {-- bounding box is found from the bounding poly hedron mo: MasterObject; prim.boundBox _ SVBoundBox.BoundBoxFromBoundHedron[prim.boundHedron, camera, prim.primWRTAssembly]; mo _ NARROW[prim.mo]; mo.class.preprocess[prim, camera]; -- compute the sub-boxes RETURN[prim.boundBox]; }; ENDCASE => ERROR; }; -- end of FindBoundingBoxesInNode FindBoundingSpheresInNode: PRIVATE PROC [node: REF ANY, camera: Camera] RETURNS [BoundSphere] = { worldCS: CoordSystem _ camera.coordSys.parent; WITH node SELECT FROM comp: Composite => { comp.boundSphere _ CSG.CombineBoundSpheres[ FindBoundingSpheresInNode[comp.leftSolid, camera], FindBoundingSpheresInNode[comp.rightSolid, camera], comp.operation]; RETURN[comp.boundSphere]; }; prim: Primitive => {-- bounding sphere is found from the bounding poly hedron mo: MasterObject; prim.boundSphere _ SVBoundSphere.BoundSphereFromBoundHedron[prim.boundHedron, worldCS, prim.primWRTAssembly]; mo _ NARROW[prim.mo]; mo.class.preprocess[prim, camera]; -- compute the sub-spheres RETURN[prim.boundSphere]; }; ENDCASE => ERROR; }; -- end of FindBoundingSpheresInNode FindRayStepXInPrimitives: PUBLIC PROC [node: REF ANY] = { WITH node SELECT FROM comp: Composite => { -- keep walking we only care about primitives FindRayStepXInPrimitives[comp.leftSolid]; FindRayStepXInPrimitives[comp.rightSolid]; }; prim: Primitive => {-- here }; ENDCASE => ERROR; }; -- end of FindRayStepXInPrimitives globalTable: DisplayMap.ColorTable; globalPalette: DisplayMap.PalTable; GetGlobalTable: PUBLIC PROC RETURNS [DisplayMap.ColorTable] = { RETURN[globalTable]; }; SetUpColorMap: PUBLIC PROC [tableName: Rope.ROPE] = { [globalTable, globalPalette] _ DisplayMap.Restore[tableName]; -- get the standard color map from this file ColorPackagePrivate.SetNewColorMapProc[PaletteMapper]; FOR palix: CARDINAL IN[0..globalPalette.size) DO ColorMap.SetRGBColor[palix, globalPalette[palix].r, globalPalette[palix].g, globalPalette[palix].b]; ENDLOOP; }; PaletteMapper: ColorPackagePrivate.ColorMapProc = TRUSTED { RETURN[DisplayMap.GetIndex[r,g,b, globalTable]]; }; Init: PROC = { }; Init[]; END. μFile: Preprocess3dImpl.mesa Last edited by Bier on August 10, 1984 1:41:58 am PDT Copyright c 1984 by Xerox Corporation. All rights reserved. Contents: File CSGImpl.mesa overflowed storage so I will put the preprocessing phases of ray casting in this interface. Preprocessing may include calculation transforms and their inverses, bounding boxes, unit rays in each instance coordinate system, and so forth. Before doing anything with a CSG tree, do this. Computes bounding spheres and bounding boxes as needed. Opens AIS files for use with texture mapping. Computes bounding spheres, but not bounding boxes. Opens no AIS files. Computes bounding boxes, but no bounding spheres. Opens no AIS files. Tree walk through to the leaves and find the position of each primitive. Tree walk find the bound box of each primitive and composite. primWRTWorld and worldWRTPrim should be available. ie FindTransformsInNode must be done first. Tree walk find the bound sphere of each primitive and composite. primWRTWorld and worldWRTPrim should be available. ie FindTransformsInNode must be done first. The bounding sphere is the combination of the bounding spheres of the children. Do this before casting any rays so that we only have to do it once. finds Κ΅– "cedar" style˜Ihead1šœ™Iprocšœ5™5Jšœ Οmœ1™