G3dModel.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, July 21, 1992 10:42 am PDT
DIRECTORY Atom, Draw2d, G2dBasic, G3dBasic, G3dIO, G3dMatrix, G3dPlane, G3dPolygon, G3dShape, G3dSpline, IO, Rope;
Imported Types
ROPE: TYPE ~ Rope.ROPE;
Context: TYPE ~ Draw2d.Context;
DrawType: TYPE ~ Draw2d.DrawType;
SplineSequence: TYPE ~ G3dSpline.SplineSequence;
SurfaceSequence: TYPE ~ G3dBasic.SurfaceSequence;
Pair: TYPE ~ G3dBasic.Pair;
PairSequence: TYPE ~ G3dBasic.PairSequence;
Ray: TYPE ~ G3dBasic.Ray;
Segment: TYPE ~ G3dBasic.Segment;
Triple: TYPE ~ G3dBasic.Triple;
TripleSequence: TYPE ~ G3dBasic.TripleSequence;
Matrix: TYPE ~ G3dMatrix.Matrix;
Viewport: TYPE ~ G3dMatrix.Viewport;
Plane: TYPE ~ G3dPlane.Plane;
PolygonProc: TYPE ~ G3dPolygon.PolygonProc;
PolygonSequence: TYPE ~ G3dPolygon.PolygonSequence;
EdgeSequence: TYPE ~ G3dShape.EdgeSequence;
ScreenSequence: TYPE ~ G3dShape.ScreenSequence;
Shape: TYPE ~ G3dShape.Shape;
ShapeSequence: TYPE ~ G3dShape.ShapeSequence;
SurfaceProc: TYPE ~ G3dShape.SurfaceProc;
STREAM: TYPE ~ IO.STREAM;
Shape Definitions
Vertex: TYPE ~ G3dShape.Vertex;
VertexSequence:
TYPE ~ G3dShape.VertexSequence;
Model: TYPE ~ REF ModelRep; -- stored on shape as modelData
ModelRep:
TYPE ~
RECORD [
points: TripleSequence ← NIL, -- sequence of 3d points
polygons: PolygonSequence ← NIL, -- complex polygons
curves: SplineSequence ← NIL -- for curved edges
];
NearModel:
TYPE ~
RECORD [
point: Triple ← [], -- intersection point or nearest point
noIntersection: BOOL ← TRUE, -- true iff point inside segment
nPolygon: NAT ← 0 -- polygon index for nearest inter. pt.
];
Record returned for closest point to a model or intersection of a model with a ray.
If intersecting with ray, point is closest point to ray and noIntersection iff ray misses model.
File IO
ShapeFromFile:
PROC [
fileName: ROPE, -- shape file name
points: BOOL ← TRUE, -- set points sequence
polygons: BOOL ← FALSE, -- set elaborate polygons
faceCenters: BOOL ← TRUE, -- set shape.faceCenters
faceNormals: BOOL ← TRUE, -- set shape.faceNormals
edges: BOOL ← TRUE, -- set shape.edges
curves: BOOL ← FALSE, -- set shape.curves
normal: BOOL ← FALSE, -- set polygon normals (only if polygons is true)
center: BOOL ← FALSE, -- set polygon centers (only if polygons is true)
lines: BOOL ← FALSE, -- set polygon lines (only if polygons is true)
accs: BOOL ← FALSE, -- set polygon accs (only if polygons is true)
area: BOOL ← FALSE] -- set polygon area (only if polygons is true)
RETURNS [Shape];
Return the shape given in the file, setting those fields as specified.
Shape Specification
GetModel:
PROC [shape: Shape]
RETURNS [Model];
Return shape.modelData, if non-NIL, otherwise allocate and return Model.
SetShape:
PROC [
shape: Shape, -- original shape
points: BOOL ← TRUE, -- set points sequence
polygons: BOOL ← FALSE, -- set elaborate polygons
faceCenters: BOOL ← TRUE, -- set shape.faceCenters
faceNormals: BOOL ← TRUE, -- set shape.faceNormals
edges: BOOL ← TRUE, -- set shape.edges
curves: BOOL ← FALSE, -- set shape.curves
normal: BOOL ← FALSE, -- set polygon normals (only if polygons is true)
center: BOOL ← FALSE, -- set polygon centers (only if polygons is true)
lines: BOOL ← FALSE, -- set polygon lines (only if polygons is true)
accs: BOOL ← FALSE, -- set polygon accs (only if polygons is true)
area: BOOL ← FALSE]; -- set polygon area (only if polygons is true)
Set the specified shape attributes.
Vertex Procedures
SetPoints:
PROC [shape: Shape];
Set shape.modelData.points.
IsolateVertices:
PROC [shape: Shape];
For each polygon in shape, allocate each of its vertices independently,
so that a polygon vertex is no longer shared with its neighbors.
DeleteVertices:
PROC [shape: Shape, vId0, vId1:
NAT];
Delete vertices numbered vId0 through vId1; renumber polygon vertex numbers accordingly;
delete all polygons referencing these vertices.
Polygon Procedures
SetPolygons:
PROC [
shape: Shape,
normal, center, area, accs, lines: BOOL,
complyWithVertices: BOOL ← TRUE];
Set polygon.indices from shape.polys.
Set various fields in the polygon record, depending on which of the following are true:
normal: compute polygon.normal, the polygon's normal
center: compute polygon.center, the polygon's center
area: compute polygon.area, the polygon's area
accs: compute polygon.accs, the accelerators for nearness testing
lines: compute polygon.lines, the 2d line equations for edges in the majorPlane
polygon.plane and polygon.majorPlane are always set.
If complyWithVertices, ensure that polygon.normal and polygon.plane do not conflict
with the surface normals. If complyWithVertices and shape.faces # NIL,
shape.faces[n].normal is assumed to comply with shape.vertices[n].normal.
CullBadPolygons:
PROC [polygons: SurfaceSequence, maxNVertices:
NAT];
Remove any polygons referring to vertices beyond maxNVertices.
Creation
ShapeFromRevolvedCurve:
PROC [
curve: PairSequence,
axis: Ray,
res: NAT,
start: NAT ← 0,
stop: NAT ← LAST[NAT]]
RETURNS [Shape];
Return a shape consisting of a polygonal mesh created from revolving curve about axis.
axialRes is the number of instances of the curve about the axis.
ShapeFromPointsPolys:
PROC [name:
ROPE, points: TripleSequence, polys: SurfaceSequence]
RETURNS [Shape];
Return a shape given the location of its vertices and polygon information.
ShapeFrom2dCurve:
PROC [name:
ROPE, curve: PairSequence]
RETURNS [Shape];
Create a shape from the curve, setting the curve in the z = 0 plane.
ShapeFrom3dCurve:
PROC [name:
ROPE, curve: TripleSequence]
RETURNS [Shape];
Create a shape from the curve.
ShapeFromSegments:
PROC [name:
ROPE, segments:
LIST
OF Segment]
RETURNS [Shape];
Create a shape from a list of line segments.
ShapeFromPoints:
PROC [name:
ROPE, points: TripleSequence]
RETURNS [Shape];
Polygonize a set of points, minimizing the resulting volume.
Processing
SkipNPolys:
PROC [shape: Shape, nPolys:
NAT];
Eliminate the first nPolys polygons from the shape.
Cleave:
PROC [shape: Shape, plane: Plane, cap:
BOOL ←
FALSE]
RETURNS [neg, pos: Shape];
Return those parts of shape on the negative and positive sides of plane.
shape is presumed to contain only convex polygons.
If cap, an additional polygon is caps the object at the slicing plane.
Curve Procedures
DrawCurves:
PROC [
context: Context,
shape: Shape,
view: Matrix,
viewport: Viewport ← [],
type: DrawType ← solid,
backFaces: BOOL ← TRUE,
screens: ScreenSequence ← NIL,
forceTransform: BOOL ← FALSE,
forInterpress: BOOL ← FALSE]
RETURNS [ScreenSequence];
Draw the shape in the given context, according to shape.model.curves.
If screens = NIL, it is allocated; screens is returned.
If screens.valid or NOT forceTransform then screens are used directly to display;
otherwise they are first computed according to the view matrix.
SetCurves:
PROC [shape: Shape];
Make curves connecting the polygon edges.
MakeCurves:
PROC [
vertices, normals: TripleSequence,
edges: EdgeSequence,
curves: SplineSequence ← NIL]
RETURNS [SplineSequence];
Make curves connecting the polygon edges.
NormalsFromCurve:
PUBLIC
PROC
[curve:
PairSequence]
RETURNS
[PairSequence];
Unit normals are created by rotating estimated tangents left 90° as we follow curve.
If data is specified in the opposite order, the normals may be 180° out of phase.