File: CSG.mesa
Author: Eric Bier in the summer of 1982
Last edited by Bier on August 18, 1983 11:28 am
Contents: The csg Solids Interface. Essentially maintains a database of csg trees each of which contains one or more combined primitives. Maintaining a tree involves creating primitives and adding them to trees with the csg operations, intersection, union, and difference.
DIRECTORY
CoordSys,
GraphicsColor,
Matrix3d,
Rope,
Shading,
SVBoundBox,
SV2d,
SVArtwork,
SVVector3d;
CSG: DEFINITIONS =
BEGIN
Artwork: TYPE = REF ArtworkObj;
ArtworkObj: TYPE = SVArtwork.ArtworkObj;
BoundBox: TYPE = SVBoundBox.BoundBox;
BoundHedron: TYPE = SVBoundBox.BoundHedron;
Color: TYPE = GraphicsColor.Color;
CoordSystem: TYPE = CoordSys.CoordSystem;
Matrix4by4: TYPE = Matrix3d.Matrix4by4;
Point2d: TYPE = SV2d.Point2d;
Point3d: TYPE = Matrix3d.Point3d;
Vector: TYPE = SVVector3d.Vector;
Surface: TYPE = REF ANY;-- may be RectSurface, TubeSurface, DiskSurface, ShellSurface...
LightSourceList: TYPE = Shading.LightSourceList;
RayCastProc: TYPE = PROC [cameraPoint: Point2d, localRay: Ray, masterObject: REF ANY, prim: Primitive] RETURNS [class: Classification];
RayCastNoBBoxesProc: TYPE = PROC [localRay: Ray, masterObject: REF ANY, prim: Primitive] RETURNS [class: Classification];
Classification: TYPE = REF ClassificationObj;
ClassificationObj: TYPE = RECORD [
count: NAT,
params: ParameterArray,
surfaces: SurfaceArray,
primitives: PrimitiveArray,-- the primitive from which each surface came
classifs: InOutArray,
normals: NormalArray];
maxSceneDepth: NAT = 40;
ParameterArray: TYPE = ARRAY [1..maxSceneDepth] OF REAL;
InOutArray: TYPE = ARRAY [1..maxSceneDepth] OF BOOL;
NormalArray: TYPE = ARRAY [1..maxSceneDepth] OF Vector;
SurfaceArray: TYPE = REF SurfaceArrayObj;
SurfaceArrayObj: TYPE = ARRAY [1..maxSceneDepth] OF Surface;
PrimitiveArray: TYPE = ARRAY [1..maxSceneDepth] OF Primitive;
Primitive: TYPE = REF PrimitiveObj;
PrimitiveObj: TYPE = RECORD [
name: Rope.ROPE,
artwork: Artwork,
assembly: REF ANY, -- a DisplayList3d.Assembly. REF ANY avoids compilation dependencies.
mo: REF ANY, -- should be MasterObject but oh the compilation dependencies!
rayCast: RayCastProc,
rayCastNoBBoxes: RayCastNoBBoxesProc,
primWRTAssembly: CoordSystem,
scalars: Vector,
worldWRTPrim: Matrix4by4,
primWRTWorld: Matrix4by4,
hints: REF ANY, -- each object type may wish to store helpful information here
boundBox: BoundBox,
boundHedron: BoundHedron,
inverted: BOOL, -- is this shape to be subtracted?
currentRay: Ray,
rayStepX: Ray];
Ray: TYPE = REF RayObj;
RayObj: TYPE = RECORD [
basePt: Point3d,
direction: Vector];
In my current plan, all of the instances of each surface type will refer to the same underlying csg surface expressed in the instance (unit dimensions) coordinate system. Hence, I will build these primitve shapes into the code (this more or less must be done anyway because the formulas - x^2 + y^2 = R^2; z = constant, etc. - are hard to enter symbolically in Mesa).
However, for rapid rendering, I will have a line-drawing approximation to each world surface. These will involve a sweep-based representation with a finite mesh (translational sweep for blocks, rotational for cylinders and spheres). I will create one such representation for each of the primitive solid types in the same instance coordinate system in which the exact csg reps are defined. Rendering line-drawings with the sweep reps will then involve, using the same matrix transforms as are used to place the csg shapes, followed by a perspective transform and a call to 2d graphics routines.
PointSetOp: TYPE = {union, intersection, difference};
Composite: TYPE = REF CompositeObj;
CompositeObj: TYPE = RECORD [
name: Rope.ROPE,
operation: PointSetOp,
leftSolid: REF ANY,
rightSolid: REF ANY,
boundBox: BoundBox];
CSGTree: TYPE = REF CSGTreeObj;
CSGTreeObj: TYPE = RECORD [
name: Rope.ROPE,
son: REF ANY,
backgroundColor: Color,
shadows: BOOL];
CopyClass: PROC [class: Classification] RETURNS [copy: Classification];
MakeCompositeCell: PROC [name: Rope.ROPE, operation: PointSetOp, LeftSolidPtr: REF ANY, RightSolidPtr: REF ANY] RETURNS [c: Composite];
MakeCSGTree: PROC [son: REF ANY, backgroundColor: Color, shadows: BOOL] RETURNS [tree: CSGTree];
CombineBoundBoxes: PROC [bb1, bb2: BoundBox, op: PointSetOp] RETURNS [newBB: BoundBox];
END.