Graphics3dDoc.tioga
This document is maintained by members of the 3d Imaging Group
Bloomenthal, February 22, 1993 7:17 pm PST
Crow, May 27, 1989 6:34:54 pm PDT
Glassner, November 23, 1989 5:31:44 pm PST
PCEDAR 2.0 —
Graphics3d: Software for Three-Dimensional Graphics
Jules Bloomenthal
© Copyright 1988, 1990 Xerox Corporation. All rights reserved.
Created by: Jules Bloomenthal
Maintained by: Jules Bloomenthal <Bloomenthal.pa>
DF File: /PCedar/Top/Graphics3d-Suite.df
Keywords: geometry, three-dimensional, 3d, models, images, animation
Abstract: Cedar Three-Dimensional Graphics Software supports geometric modellng and rendering functions for the creation of individual and animated images. This document presents a conceptual overview, documentation of user tools, and descriptions of interfaces and their implementations.
XEROX  Xerox Corporation
   Palo Alto Research Center
   3333 Coyote Hill Road
   Palo Alto, California 94304

General Notes
Organization of this Document
This document consists of two sections, a User's Guide and a Programmer's Guide. Second level Tioga viewing provides a reasonable outline for this document.
Additional Documentation
The various interfaces in Graphics3d provide additional, specific documentation.
Concepts
Objects, Shapes, Models
The reader will find the words object, shape, and model used frequently and somewhat interchangeably, in this document. These words are used in the intuitive sense: things that exist in three-dimensional space and may be manipulated and imaged by our 3d system. Objects are usually represented by their bounding surfaces, which are collections of geometric primitives such as patches or, more commonly, polygons.
The most common computer representation for an object used by our our system is the Shape. This representation is described in detail in the G3dShape interface.
The external computer representation of an object is the shape file, described in the following section.
Shape Files
In General
An object may be defined by a shape file, which explicitly specifies the collection of geometric primitives that constitute the boundary, or surface, of the object. Typically the primitives are described by a set of vertices (points on the surface) and a set of surfaces (connections of the vertices). A number of programs generate shape files, and some of these are discussed in the User's Guide. Typically, a surface is a simple, convex polygon, or a bi-parametric patch.
Generally, a shape file is required as input to those programs that create line drawings or shaded images of object(s).
File Format
The format of the shape file follows that defined in the G3DIO interface:
Data is preceded by a keyLine that specifies the data format. The keyLine is a keyWord followed by a `~' and an arbitrary number of field descriptions. The field descriptions, optionally separated by commas, consist of a colon-terminated identifier and a case-insensitive fieldType. Whitespace may appear before any of the punctuations ('~', ':', or ',').
Here's a sample keyLine:
Vertices~ xyzCoords: Triple, transmittance: Real
 where Triple indicates an <x y z> triplet of numbers.
Data following a keyLine is terminated by another keyLine or by the end of file. Any line that is not a keyLine, is not blank, and doesn't begin with "--" is a dataLine and is assumed to contain valid data whose format agrees with that defined by the previous keyLine.
Comments begin with "--"; they may be a separate line within the file or may terminate a dataLine or keyLine.
Keylines common in a shape file are:
DataSize~ <data descriptor>
This information is optional; it contains ``hints'' that optimize file reading by specifying the number of data lines, if known. Current descriptors include:
Vertices: <cardinal> the number of vertices to be read 
Surfaces: <cardinal> the number of surfaces (polygons, patches, etc.) to be read 
Other descriptors may be used as desired for special purposes.
SurfaceType~ <surface descriptor>
Current descriptors include:
ConvexPolygon the following data describe a surface formed of convex polygons
Polygons  the following data describe a surface formed of convex polygons
Bezier  the following data describe a surface formed of Bezier patches
Patches  the following data describe a surface formed of Bezier patches
InsideVisible the shape has holes or is not closed and thus the inside may be visible
CountFromOne vertex indices assume first vertex is 1 (backward compatibility)
Triangulated all polygons have three vertices; indicating this will speed file input
The default surface type is convex polygons, counting from zero with no insides visible. This keyline is not followed by any data. Unrecognized keywords will be stored on the "fixedProps" property list of the ShapeInstance (see G3dShape.mesa).
Vertices~ <vertex descriptor> . . . <vertex descriptor>
Vertex descriptors include:
index:  Integer a single whole number serves as a vertex index
xyzCoords: Triple three real numbers define the location of the surface vertex
normalVec: Triple three real numbers define the vertex surface normal
rgbColor:  Triple three real numbers define the color of the vertex
textureCoords: Pair two real numbers define the vertex texture coordinates
transmittance: Real a real number indicates the transmittance of the vertex
The "Vertices" keyline is followed by vertex data. Vertex locations are defined in a right-handed coordinate system, as discussed below. Descriptor identifiers other than the above will cause the corresponding data to be stored on the objects's "fixedProps" property list, where it may later be used. However the allowable number types are restricted to {Integer, Real, Pair, Triple, Quad}.
Surfaces~ <surface descriptor> . . . <surface descriptor>
Surface descriptors (polygons, patches, etc.) include:
index:  Integer a single whole number serves as a surface index
nSides:  Integer the number of sides of the polygon
normalVec: Triple three real numbers indicate the surface normal
rgbColor:  Triple three real numbers indicate the color of the surface
transmittance: Real a real number indicates the transmittance of the surface 
vertices:  Nats a sequence of integers indicate the connection of vertices for
   polygons, a list of control points for patches, or other vertex
   pointers for other kinds of surfaces. Since the vertex
   sequence is arbitrarily long, this must be the last descriptor
Descriptor identifiers other than the above will cause the corresponding data to be stored on the objects's "fixedProps" property list, as with vertices.
This keyline is followed by surface data.
Sample Shape File
The following shape file describes a box with the top removed:
OpenBox.shape: a box with the top removed
-- "OpenBox" isn't a keyword, so the above line is interpreted as a comment
DataSize~ Vertices: 8, Surfaces: 5  -- optimize file input by giving counts
SurfaceType~ ConvexPolygon, InsideVisible -- inside surface can be seen
Vertices~ xyzCoords: triple
1.0 -1.0 -1.0
-1.0 -1.0 -1.0
-1.0  1.0 -1.0
1.0  1.0 -1.0
1.0 -1.0  1.0
-1.0 -1.0  1.0
-1.0  1.0  1.0
1.0  1.0  1.0
Surfaces~ vertices: nats
3 2 1 0  -- bottom
1 5 4 0  -- front (as seen from negative y-axis)
1 2 6 5  -- left side
3 0 4 7  -- right side
3 7 6 2  -- back
Notes on surface normals and vertex ordering
In 3dGraphics, polygons are rendered according to the normal of the polygon or its constituent vertices. In general, the normal should face towards the outside of a surface; for a convex solid, for example, all visible polygons will have normals which face towards the viewer.
The vertices of a polygon are assumed to be taken in clockwise order as seen from the outside. "Outside" may be meaningless in the case of some surfaces (using "insideVisible ") forming a sheet rather than a closed surface. In such cases, neigboring polygons (sharing an edge) should be ordered consistently.
Patches defined by rows of control points are assumed to be taken with rows running from left to right and each succeeding row above the preceding one as seen from the outside of the surface.
Polygons taken clockwise Patches taken row-wise, left to right
[Artwork node; type 'Artwork on' to command tool]
Surface normals may be included as a part of the vertex description; it is important that the normals adhere to the following convention:
[Artwork node; type 'Artwork on' to command tool]
The coordinate system shown is right-handed. The triangle shown lies in the XY plane, with its normals facing in the +Z direction, the "outside" of the triangle; normals should face to the outside of a shape.
The proper order of vertices is clockwise when the polygon normal faces the viewer.
If a shape file does not obey these conventions, the subsequent shaded image will probably evidence various errors.
Scene Files
Coordinate Systems
In 3dGraphics, as well as ThreeDWorld, the world (or object) coordinate system is right-handed, with the x-axis pointing East, the y-axis pointing North, and the z-axis pointing up (assuming no previous transformations of the axes).
The screen space is left-handed, with the x-axis pointing to the right, the y-axis pointing up, and the z-axis pointing into the screen.
Rotations are, as is tradition, right-handed. This means that when rotating around, say, the x-axis, positive rotation is in the direction of curl of the fingers if the right hand's thumb is pointed in the direction of the x-axis. Similarly for any axis of rotation.
Collection of Objects
A typical scene consists of one or more objects positioned and oriented according to a user's specification. Usually the positioning and orientation is accomplished interactively, but it can also be accomplished manually (by typing into a file) or programmatically (by executing a program).
Scene Descriptions
A scene may be described by a scene description file. This file may be generated by 3dView or created/edited by hand. It may be executed by the programs 3dView or 3dScene. Here is a sample scene file:
A sample scene description (Tioga-formatted comments are ignored)
Color 1.0 0.0 1.0
ReadShape ///Shapes/Sphere.shape
Render
Each line in the file is considered to be a separate command, which must observe the following syntax:
Command-name <dataName mandatoryData> [dataName optionalData]
Many of the names supported by the scene language have variants. The variants defined here are separated from each other by a vertical bar |. If the variants are synonyms for each other, they are enclosed by parentheses. If the variants form an enumerated type, they are enclosed by curly braces. For example, the translation command, (Translate | T), indicates that "T" and "Translate" are equivalent. However, the argument to DisplayMode is given as {gray | dither | fullColor}, indicating that one of the three options is a valid specification for that argument.
A dataName is listed here only to indicate the function of the data; the dataName itself should not appear in the scene description file. An exception is a dataName beginning with a hyphen, which indicates a named argument to a command. Named arguments must include the dataName (with hyphen!) in the scene description file. Named arguments may appear in any order within the command; unnamed arguments must follow the order given in this document.
An expression in angle brackets, <>, indicates the specified data is required by the command; an expression in square brackets, [], indicates the specified data is optional. For example, in the RotateAxis command,
RotateAxis <-axis TRIPLE> <-angle REAL> [-base TRIPLE] [-radians]
the -axis and -angle arguments must be given, but -base and -radians are optional. Note that the -radians argument takes no data. Here are some legal and illegal calls to this command:
RotateAxis -axis 3 5 3 -angle 5   -- simple and legal
RotateAxis -radians -angle 1.5 -axis 2.2 1.1 0.2 -- more complex and legal
RotateAxis -base 1 2 3 -angle 110 -axis 1 2 3 -- different options and legal
RotateAxis -angle 30 -radians   -- illegal (the mandatory -axis is missing)
Acceptable data types are:
REAL  a real valued number
INT  a integer valued number
BOOL  a boolean (i.e. TRUE or FALSE)
ROPE  a string
TRIPLE  three REALS separated by white space (fields named X, Y, Z)
COLOR  a TRIPLE, but in the range [0..1] (fields named R, G, B)
{a | b | c}  an unnamed enumerated type
Expressions (e.g., "5+7") are not allowed.
The commands supported by the scene description language are explained below.
Miscellaneous Commands:
--
Ignore this line. Commented nodes are also ignored.
ReadScene <fileName ROPE>
Read and execute a new scene file in the midst of the present one.
Echo <message ROPE>
Write the message to the scene log.
Command <command ROPE>
Execute the given command.
Rendering:
Draw
Draw the scene onto the line drawing display (no op if scene file is parsed by 3dScene).
Render
Render the scene onto the color display.
DisplayMode <mode {gray | dither | fullColor}>
Set the display mode to gray (8 bits), dither (8 bits using a custom 3d dither, not Imager dither), or full color (24 bits).
DisplayRegion <x REAL> <y REAL> <w REAL> <h REAL>
Set the display region for the color display; normally defaulting to full screen. Values are in pixel units. This is a window (or clipping region) into the camera's viewport.
Viewport <x REAL> <y REAL> <w REAL> <h REAL>
Set the camera's viewport for subsequent image rendering. Values are in pixel units.
BackgroundColor <color COLOR>
Set the background color. Values must be in the range [0..1].
BackgroundImage <aisFileName ROPE>
Set the background to be the named image, pre-empting the flat background color.
EnableBackground <mode BOOL>
Enable or disable the background.
AntiAliasing <mode BOOL>
Render subsequent images with or without anti-aliasing.
DepthBuffering <mode BOOL>
Render subsequent images with or without depth buffering.
NormalCoding <mode BOOL>
Render subsequent images with or without normal coding.
AddProperty <key ROPE> <property ROPE>
Property is placed on the property list of the 3d context, under the given key.
Camera Operations:
FieldOfView <fov REAL>
Set the field of view, in degrees.
EyePoint <point TRIPLE>
Set the origin of the camera (similar to Move)
LookAt <point TRIPLE>
Set the direction of view of the camera.
Up <direction TRIPLE>
Set the "up" direction relative to the camera's view direction.
Roll <angle REAL>
Roll the camera by the given degrees about the camera's view direction.
Object Hierarchy:
To create an animaton, you will usually create a hierarchy of objects. This hierarchy is set up like an inverted tree: the root is at the top, and the branches go out and down. Each node in the tree inherits the transformations of its parent node. For example, you might make an arm with a node at the root, and working down, a node at the shoulder, elbow, and wrist. Rotating at the elbow will rotate the wrist as well, but leave the shoulder unaffected.
To start a new branch issue the commnd StartBranch. EndBranch will return you to the node you were at when you last issued StartBranch. For details on model hierarchies, see any good computer graphics text (such as 3D Computer Graphics for Artists and Designers, by Glassner, Design Press).
Identity
The current coordinate system (CCS) is reset to identity (no transformation). This is particularly useful when specifying several keys at different times, and you want to start each key description anew.
StartBranch
Create a new branch in the hierarchy. Everything in this branch is defined with respect to the coordinate system in effect when the branch is created. Note that this system may be defined by keys, so it may move over time. Thus the branch may move rigidly over time.
EndBranch
Conclude definition of a branch. You are returned to the point in the hierarchy as of the last StartBranch.
Animation:
StartKeys
This command changes the mode of the system. The current transformation is saved (as with the StartBranch command). You may then issue any command from the sections Coordinate System Transformations and Material Specification. Transformation commands will accumulate, and material commands will over-write previous values, as usual. However, typically you will eventually specify a Time command (see below). This "locks in" the current transformation and material specifications at the indicated time. You may then provide new material specifications and new transformations, followed by another Time command; this will lock in the values at the new time. Each of these sets of time and data is called a "Key"; the commands leading up to a Time command contribute to the key that describes the world at that moment.
At the moment you specify the StartKeys command, the current transformation is saved. Any keys that are now created are interpreted with respect to the coordinate system in effect when the StartKeys is given.
There are two common situations encountered when specifying keys for motion - successive keys are either cumulative or distinct. An example of the former is a sequence like
"t x 20 ; time 0 ; t x 10 ; time 1"
The result of this command sequence is that the transformation "t x 20" is the specified key at time 0, and "t x 30" is the value at time 1. In effect, the transformations accumulate as though the time command had not been given.
If you wish each key to "start over", as though the previous key had not existed, then you must issue the Identity command after the Time command. This sets the transformation to identity (or no effect), as always with respect to the coordinate system in effect when you issued StartKeys. An example of this approach is a sequence like
"t x 20 ; time 0 ; identity ; t x 10 ; time 1"
The result of this sequence is that the transformation "t x 20" is specificed at time 0 (as before), but the transformation "t x 10" is the key at time 1.
N.B.: You may not issue StartBranch and EndBranch commands while defining keys (i.e. after a StartKeys but before an EndKeys). Those commands affect the structure of your hierarchical model, which cannot change over time. You may not nest key definitions; thus, after a StartKeys command you may not issue another StartKeys until you have issued an EndKeys.
EndKeys
End the definition of a sequence of keys.
Time <time REAL>
Specify that the current transformation and material specifications are to be associated with a key at the specified time. This command is only legal after a StartKeys and before an EndKeys.
StrobeScene <time REAL>
This command transforms all objects and their materials to their values at the specified time. Typically in an animation (using 3dinterp, described below) you will read your scene file describing your objects and their associated keys, and then enter a loop where you issue the StrobeScene command for a particular time, and then the Render command. When the rendering is complete, you save the frame (e.g. to videotape or disk), and then you issue a new StrobeScene command one frame-time later, followed by another render command, and so on.
DiffuseInterpolation {constant | linear | smooth }
Set the interpolation type for diffuse reflectivity for this node.
SpecularInterpolation {constant | linear | smooth }
Set the interpolation type for specular reflectivity for this node.
MetallicityInterpolation {constant | linear | smooth }
Set the interpolation type for metallicity for this node.
ShininessInterpolation {constant | linear | smooth }
Set the interpolation type for shininess for this node.
TransmittanceInterpolation {constant | linear | smooth }
Set the interpolation type for transmittance for this node.
ColorInterpolation {constant | linear | smooth }
Set the interpolation type for color for this node.
TransformInterpolation {constant | linear | smooth }
Set the interpolation type for transformations for this node.
Coordinate System Transformations:
(Translate | T) <X | Y | Z > <distance REAL>
The CCS is translated the specified distance in the specified direction.
(Translate | T) <XYZ> <distances TRIPLE>
This convenience command is a shorthand for the sequence
 Translate X distances.X
 Translate Y distances.Y
 Translate Z distances.Z
Since translation is commutative, there is no ambiguity in specifying all three translations at one time.
(Scale | S) <X | Y | Z > <factor REAL>
The CCS is scaled by the specified factor in the specified direction.
(Scale | S) <XYZ> <factors TRIPLE>
This convenience command is a shorthand for the sequence
 Scale X factors.X
 Scale Y factors.Y
 Scale Z factors.Z
Since scaling is commutative, there is no ambiguity in specifying all three scales at one time.
Shear <X | Y | Z > <X | Y | Z> <factor REAL>
The CCS is sheared along the first axis relative to the second axis by the specified amount.
(Rotate | R) <X | Y | Z > <angle REAL> [-radians]
The CCS is rotated by the specified angle around the specified axis. The angle is interpreted in degrees, unless -radians is specified.
RotateAxis <-axis TRIPLE> <-angle REAL> [-base TRIPLE] [-radians]
default base: (0.0 0.0 0.0)
The CCS is rotated by the specified angle around the specified axis. If desired, a base for the axis may be given. The angle is interpreted in degrees, unless -radians is specified.
ExplicitMatrix
<m00 m01 m02 m03 m10 m11 m12 m13 m20 m21 m22 m23 m30 m31 m32 m33: REAL> [-absolute]
This command is for experts, and is provided as a shorthand for those who write programs that make scene files. If the -absolute flag is not provided, then the specified four-by-four transformation matrix is appended to the CCS. If -absolute is provided, then the specified matrix replaces the current transformation matrix (the transformation on top of the stack), irrelevant of all preceding matrix commands. Matrices below the current transformation on the stack are unaffected. The matrix components are given left-to-right, top-to-bottom, like reading a book.
Lighting:
AmbientLight <color COLOR>
The ambient light of the scene is set to the specified color.
AddLight <-position TRIPLE> [-color COLOR] [-name ROPE]
default name: AutoLight#
default color: (1.0 1.0 1.0)
Add a new light to the scene description. The position of the light must be specified. The name and color of the light may also be specified.
Shape I/O:
ReadShape <shapeFileName ROPE> [instanceName ROPE]
Read the shape from a file and (optionally) name it.
If no instance name is supplied, the local file name is used.
The transformation associated with this shape is that of the CCS.
WriteShape <shapeName ROPE> [shapeFileName ROPE] [-transform]
Write the named shape to a file.
If a filename is not specified, one is built by appending ".shape." to the shape name.
Experts: if the -transform option is given, the shape is transformed by its matrix before writing.
WriteAllShapes
All shapes in the scene are written to files, as per WriteShape.
DeleteShape <shapeName ROPE>
The named shape is deleted from the scene description.
DeleteAllShapes
All shapes in the scene are deleted.
Shape Modification:
InvertNormals
Reverse the normals of the most recently input shape.
Triangulate
Triangulate the most recently input shape.
ReversePolygons
Reverse the polygons of the most recently input shape.
OpenContours
All polygons in the active shape are marked as open (i.e. the first vertex is not assumed to be joined to the last).
AddAxes [-origin TRIPLE] [-size REAL] [-scale TRIPLE] [-nReticles INT]
Add symbolic axes to the image.
Material Specification:
SaveMaterial <materialName ROPE>
Save the current material with the specified name.
UseMaterial <materialName ROPE>
Replace the current material with the material previously saved with the specified name.
BackFacesVisible <visible BOOL>
If TRUE, back faces are visible, otherwise they are ignored.
RenderStyle <style
{faceted | smooth | lines | shadedLines | hiddenLines | linesWnormals | controlPoints}>
Set the rendering style for objects with this material.
Visible <visible BOOL>
If TRUE, surfaces with this material are visible; otherwise they are invisible. This differs from transparency in that invisible objects are entirely ignored, thus speeding rendering.
Color <color COLOR> [-scale]
Set the color of this material. If the scale option is provided, the current color is scaled by the supplied color.
Diffuse <factor REAL> [-scale]
Set the diffuse reflectivity coefficient for the current material. If the scale option is provided, the current diffuse reflectivity is scaled by the supplied diffuse reflectivity.
Specular <factor REAL> [-scale]
Set the specular reflectivity coefficient for the current material. If the scale option is provided, the current specular reflectivity is scaled by the supplied specular reflectivity.
Metallicity <factor REAL> [-scale]
Set the metallicity coefficient for the current material.. If the scale option is provided, the current metallicity is scaled by the supplied metallicity. The factor is assumed to lie in the range [0, 1], where 0=plastic appearance, and 1=metallic appearance. This controls color-shifting on highlights (unimplemented).
Shininess <factor REAL> [-scale]
Set the shininess of the current material; 0 for dull, 50 or so for highly shiny. If the scale option is provided, the current shininess is scaled by the supplied shininess.
Transmittance <factor REAL> [-scale]
Set the transmittance of the current material; 0 for opaque, 1 for transparent. If the scale option is provided, the current transmittance is scaled by the supplied transmittance.
Texture:
OffsetTexture <offset PAIR>
Offset any textures for this material by the specified amounts.
ScaleTexture <scale PAIR>
Scale any textures for this material by the specified amounts.
ScaleBumps <height REAL>
Scale any bump map for this material by the specified amount.
FilterTexture <filtering BOOL>
If TRUE, then any textures associated with this material will be filtered, otherwise they will be point sampled.
SetTexture <textureType {intensity | color | bump}> <fileName ROPE>
Attach the specified type of texture from the specified file to the current material.
DisableTexture <textureType {intensity | color | bump}>
Detach the specified type of texture from the current material.
Variables:
Set <variableName ROPE> <value ROPE>
The first two words ("Set" and the variableName) are parsed. The rest of the line is assigned as the value of the variable. Henceforth, every line will be examined on a word-by-word basis (a "word" is a sequence of characters delineated by a start-of-line, end-of-line, tab, or blank). Only the first word of the line (presumably a command) is left free of substitution. If any other word matches a variable name, then the value of the variable is substituted for that word, before the command arguments are interpreted.
Any sequence of characters may be used for the variable name; it begins with the first non-blank-or-tab after the word "Set" and concludes with the first blank or tab. Anything remaining on the line becomes its value.
Typical uses of Set are for symbolic names ("set yellow 1 1 0", followed later by "color yellow"; and "set pi 3.14159") and shorthand for files and complex commands ("set myile ///reprisal/cedar/users/glassner.pa/pix/texturefile", followed later by "settexture bump myfile").
This technique is powerful enough to hurt you. For example, imagine the results of Set 3 0, which will then set any instance of 3 (seperated by blanks or tabs) to the value 0. Be careful!
The only exceptions to the replacement rule are the first word on each line, and the variableName argument to Set.
Unset <variableName ROPE>
The specified variableName is removed from the list of variables; it will not be substituted for until Set again.
Pseudo-Variables:
Pseudo-variables are commands and keywords that are interpreted like variables, but they do not have a one-to-one correspondence to a particular value. The notion of pseudo-variable is currently only implemented in a random-number facility. Anywhere that numeric arguments are required (be they real, integer, or triple) you may specify instead that you wish the system to use a random number within a specified range (the syntax is given below). You may also re-seed the random number generator at any time. If you do not seed before first use, a constant seed will be used by default; thus you will get the same sequence of random numbers each time the scene file is parsed (if the file is nested, and other random number calls precede the file, then the file under consideration will naturally get different values than if it was the first file called. Nevertheless, the overall sequence for all random calls in any complete scene will remain unchanged).
Example: To create three stacked cylinders of differing radii and length:
Cylinder -r randomreal 0.0 1.0 -zlo randomreal -10 -5 -zhi randomreal -5 0
Cylinder -r randomreal 0.0 1.0 -zlo randomreal -5 0 -zhi randomreal 0 5
Cylinder -r randomreal 0.0 1.0 -zlo randomreal 0 5 -zhi randomreal 5 10
RandomSeed <seed INT>
Seed the random number generator with the specified value. If seed=0, a default value is used. If seed>0, seed is scaled if necessary and then used. If seed<0, a random seed is created by consulting the system clock.
RandomInt <low INT> <high INT>
This sequence of word and two integers is replaced with an integer in the range [low .. high].
RandomReal <low REAL> <high REAL>
This sequence of word and two reals is replaced with a real in the range [low .. high].
RandomTriple <low INT> <high INT>
This sequence of word and two reals is replaced with a triple. The three elements of the triple are chosen at random, and the resulting triple (interpreted as a vector) is scaled to have a length in the range [low .. high]. To get unit vectors, use the range [1.0 .. 1.0].
Primitive Shapes:
Shapes are all approximated polygonally. You can think of this operation as sampling an ideal, smooth shape. Some shapes sample in more than one dimension; e.g. a sphere is sampled in both latitude and longitude. The default sampling density in all dimensions for all shapes is 10. You may control the resolution of the sampling for all shapes.
All shapes may be given a name with the -name option. If you do not supply a name then one will be created for you, to identify the object. Typically the name is a combination of the shape's type and a number; this number is the number of the shape in the scene description at the time it is read. For example, if the first object is a sphere and the second object is a cylinder, they will receive names "AutoSphere0" and "AutoCylinder1". The "Auto" indicates that the name was created automatically, to easily distinguish it from your own names.
When angles are specified, you may use radians or degrees, though you must be consistent across a single line. Degrees are assumed for the default; if you supply the -radians option your angles will be interpreted (for that shape) in radians.
Sphere [-r REAL] [-uRes INT] [-vRes INT]
[-minTheta REAL] [-maxTheta REAL] [-minPsi REAL] [-maxPsi REAL] [-radians]
[-name ROPE]
Create a sphere, centered at the origin. The radius is specified with the -r option; default is 1.0. uRes controls the longitudinal sampling (around the equator), vRes controls latitudinal sampling (north-south). The range of theta determines the range of the equator in the patch; theta begins at 0 at the point [radius, 0, 0], it is 90 degrees at [0, radius, 0], and finally makes it back to 360 at [radius, 0, 0]. Psi is the north-south control; it is 0 degrees at the south pole [0, 0, -radius], 90 degrees at the equator, and 180 degrees at the north pole.
Thus, 0dthetad360, 0dpsid180.
Cylinder [-r REAL] [-zlo REAL] [-zhi REAL] [-steps INT] [-lcap] [-ucap]
[-minTheta REAL] [-maxTheta REAL] [-radians]
[-name ROPE]
Create a cylinder whose axis is the Z axis. The cylinder extends from zlo to zhi (defaults -1.0 and 1.0), with a radius of r (default 1). The cylinder is approximated as a polyhedral tube with a number of sides specified by steps. If -lcap is specifed, a cap is placed on the bottom of the cylinder; similar actions results with -ucap. The cylinder is normally closed in cross-section; you may specify that the cross-section should only extend between the angular limits given with -minTheta and -maxTheta. Theta is 0 degrees on the X axis at [radius, 0, 0], 90 degrees on the Y axis at [0, radius, 0], and eventually wraps back to 360.
Thus, 0dthetad360.
Cone [-rlo REAL] [-rhi REAL] [-zlo REAL] [-zhi REAL] [-steps INT] [-lcap] [-ucap]
[-minTheta REAL] [-maxTheta REAL] [-radians]
[-name ROPE]
Create a cone whose axis is the Z axis. The cylinder extends from zlo to zhi (defaults -1.0 and 1.0). The radius at zlo is given by rlo, the radius at zhi is given by rhi (both radii default to 1.0). The cylinder is approximated as a polyhedral tube with a number of sides specified by steps. If -lcap is specifed, a cap is placed on the bottom of the cylinder; similar actions results with -ucap. The cylinder is normally closed in cross-section; you may specify that the cross-section should only extend between the angular limits given with -minTheta and -maxTheta. Theta is 0 degrees on the X axis at [radius, 0, 0], 90 degrees on the Y axis at [0, radius, 0], and eventually wraps back to 360.
Thus, 0dthetad360.
Torus [-minorR REAL] [-majorR REAL] [-uRes INT] [-vRes INT]
[-minTheta REAL] [-maxTheta REAL] [-minPsi REAL] [-maxPsi REAL] [-radians]
[-name ROPE]
Create a torus (donut). The torus straddles the XY plane, with the Z axis going up the center of the hole. The distance from the origin to the center of the tube is given by majorR, the radius of the tube itself is minorR. The steps taken around the tube in the XY plane is controlled by uRes, the number of steps taken around the circumference of the cross-section is controlled by vRes. Theta travels around the Z axis; theta is 0 degrees on the X axis at [majorR, 0, 0], 90 degrees on the Y axis at [0, majorR, 0], and eventually wraps back to 360. Psi wraps around the cross-section. It is zero at the bottom of the donut [majorR, 0, -minorR], 90 degrees at the outside [majorR+minorR, 0, 0], and wraps around back to 360.
Thus, 0dtheta, psid360.
Box <xExtent REAL> <yExtent REAL> <zExtent REAL> [-name ROPE]
Create a rectangular prism (box). Boxes may be created many ways (sweep, surface of revolution, prism, etc.). This command is provided for two reasons: as a convenience, and as another form of parameterization. The 2d texture coordinates on a box created with this command run from (0,0) to (1,1) independently on each face.
Ngon <sides> [-r REAL] [-z REAL]
[-minTheta REAL] [-maxTheta REAL] [-radians]
[-name ROPE]
Create a polygon with the specified number of sides. The first vertex lies on the X axis [radius, 0, 0]. By default theta travels from 0 (on the X axis) to 90 (on the Y axis), back to 360. By specifying a smaller range of theta you get a piece of the polygon, but that piece still has the given number of sides. The polygon will lie in the z=0 plane by default, though you may specify the z value explicitly.
Thus, 0dthetad360.
Annulus [-minorR REAL] [-majorR REAL] [-steps INT] [-z REAL]
[-minTheta REAL] [-maxTheta REAL] [-radians]
[-name ROPE]
Create an annulus (a ring with a smaller ring extracted from the center). minorR is the distance to the inner ring (the radius of the hole), majorR is the distance to the outer ring. The steps, z, and theta arguments are similar to those for the ngon command above.
Swept Shapes:
You may use basic shapes to produce more complex shapes. The general idea is that of a ``sweep,'' or a path along which the basic shape is moved. As the shape moves along the path, you may transform it in a variety of ways.
There are two simple shape transformations: extrude and revolve. These both modify the input shape. Note what this means for transformations: when you specify an object, its place in the transformation tree is determined by the structure of the tree when you originally read in the object. Thus, if you want to apply a transformation to an extruded or revolved shape, specify the transformation before the creation of the shape that you subsequently modify. For example, "t x 10 ; readshape foo.shape ; revolve" will move your revolved shape 10 units along x; the sequence "readshape foo.shape ; t x 10 ; revolve" will cause the "t x 10" to be ignored as far as the revolved shape is concerned, since it was not applied to the original object.
Extrude [-distance REAL] [-axis REAL REAL REAL] [-name ROPE]
The active shape in the scene is taken as the basic object. It is swept along the specified distance (default 1.0) along the specified axis (default Z axis = 0 0 1). This is a useful mechanism for making prisms and "flying logos".
Revolve [-contour] [-steps INT] [-axis REAL REAL REAL]
[-minTheta REAL] [-maxTheta REAL] [-radians]
The active shape is revolved around the specified axis (default Z axis = 0 0 1). The number of steps tells how many steps to take from the lo value of theta to the high value (default steps = 10, default range of theta = 0 to 2pi). Theta=0 is the X axis, theta is 90 at the Y axis. If you specify -contour, then the input shape is assumed to be just a curve, and is not interpreted as a polygon (thus there is no final edge connecting first and last vertices).
More sophisticated actions are available though the commands below. These are much more powerful, but also more complex. The general idea is that you may specify a sweep path, along which the object is moved, and then a variety of operations that may occur along that path. These commands are intended for modeling experts, who need the extra power they provide. All of the power below, and some additional operations not described here, are available to the programmer through the client interface to G3dSweep.
At each instancing of the object along the path, it may be consecutively scaled, rotated, and translated. The first operation takes place with respect to the local coordinate system of the object as it is swept along the path. The object tries to maintain some sense of local orientation. For example, if the object is a 2d curve, then the cross-section normal to the path will be close to constant, and the curve will not spin haphazardly as it sweeps. More details of this technique may be found in [Bloomenthal, "Modeling The Mighty Maple", Siggraph '85 Proceedings]. Successive operations occur with respect to the coordinate system left after the preceding operation. Any operations you do not specify default to identity transformations (i.e. unspecified operations cause no change).
You specify these transformations with small text files containing sequences of quadruples. Each quadruple is in the order: length x y z. The "length" parameter specifies the normalized length along the sweeping path at which the following three arguments apply; the length is 0.0 at the start of the path and 1.0 at the end.
Parameters may be interpolated as stright, smooth, or cyclic. Straight interpolation uses linear interpolation of all parameters from one specification to the next. Smooth and cylic both use an interpolating cubic spline between specified knots. The difference is that cyclic interpolation assumes that the end wraps smoothly to the begining, which is useful when the path is closed.
The path itself is also a sequence of tuples, but the length field is not included.
Here are the commands for setting and changing the sweep information, and actually sweeping an object. Note that you get more power and options through the client interface; these commands are just pre-packaged versions of common techniques.
Incidentally, lest this all seem overly complex and impractical, it is the case in many commercial systems that the generalized swept object is the only primitive in the system. Indeed, that is also the case in our scene language (with the exception of explicit .shape files). All of the objects described above (sphere, cylinder, torus, etc.) are all generated through calls on the generalized sweep package - in effect, they are just special-purpose versions of the Sweep command below. Similarly, the commands Extrude and Revolve above are again just specialized versions of Sweep with most parameters pre-set.
ClearSweepPaths
The sweep paths are all cleared to an empty state. There is no sweeping path defined, and no transformations upon it.
ChangeSweepPaths
 [-shape FILENAME] [-shapeBlend BLENDTYPE]
 [-scale FILENAME] [-scaleBlend BLENDTYPE]
 [-path FILENAME] [-pathBlend BLENDTYPE]
 [-translate FILENAME] [-translate BLENDTYPE]
 [-rotate FILENAME] [-rotateBlend BLENDTYPE]
The sweep paths are updated to the specified files and interpolation types. Any combination of the above arguments may be given; unspecified arguments are unchanged. The FILENAME type is simply a rope with the name of the file holding the parameters. The BLENDTYPE type is one of the three strings straight, smooth, or cyclic. Nothing happens as a result of this command; this sets up for a Sweep.
Sweep
 <[-activeShape] [-onlyShape ROPE]> [-steps INT]
 [-anchor BOOL] [-connect BOOL] [-instance BOOL]
 [-localFrames BOOL] [-tubeTexture BOOL] [-close BOOL]
 [-tlo REAL] [-thi REAL]
 [-name ROPE]
The Sweep command is the real workhorse for sweeping objects. You must specify either the -onlyShape option, and give the name of a shape in the current scene decription, or -activeShape, which will use the currently active shape. You may then specify any combination of the other options.
The operation is that the path is broken up into a number of equal-length intervals (the number of intervals is controlled by the argument to -steps). At the start of the path, between each pair of intervals, and at the end, the current frame is computed. If -localFrames is set to FALSE, then the object is not rotated into the local orientation, it is just translated into position. Other wise the object is translated and rotated, and the object placed. The appropriate transformations as given by ChangeSweepPaths are computed and applied.
The vertices of the object are recorded at that point in space. The object may then be actually instantiated at that point (if -instance is set to TRUE) - this means that the polygons that connect the vertices are actually built. If -instances is FALSE, then these polygons are not built; this is the default.
When all of the steps have been taken, the individually placed copies of the object are connected together into a tube. This operation is suppressed if -connect is set to FALSE.
If the option -anchor is set to TRUE, then the initial transformation is ignored; in effect, the path is anchored to the original orientation of the shape. If the option -close is set to TRUE, then the path is interpreted as a closed path, and the interpolation attempts to make the start and end of the path connect smoothly.
The values of tlo and thi determine the limits of the path that are actually interpolated; these are normalized length parameters. They default to 0.0 and 1.0. If you specify a smaller range, then the object is only swept along the specified piece of the path.
The -name option lets you name the newly swept object.
Shape Filters:
The following procedures take as input the current shape. This shape is deleted from the scene description, and replaced with a new shape, based on the old, but with changed polygons. The actions of each parameter are shown graphically on a triangle, though the processes work on polygons of any number of sides.
A common idea in many of these operations is the "center" of a polygon; this is the average of the vertex coordinates.
Note that because these commands work with the active object, they must follow an object definition.
PolyStellate <a REAL>
Build a prism above the polygon. a controls the height, as a percentage of the length of the longest side of the polygon.
[Artwork node; type 'Artwork on' to command tool]
PolyFrame <a REAL>
Replace the polygon with a "picture frame" around it; i.e. cut a hole in the polygon. a controls the size of the hole.
[Artwork node; type 'Artwork on' to command tool]
PolyDilate <a REAL>
Replace the polygon with a version scaled around the center. a controls the scaling.
[Artwork node; type 'Artwork on' to command tool]
PolyRotate <a REAL>
Rotate the polygon in place about its center, in its own plane, by an angle given by a.
[Artwork node; type 'Artwork on' to command tool]
PolyInscribe <a REAL>
Replace the polygon with a new polygon inscribed within. a determines what point on the sides is used for the inscribing.
[Artwork node; type 'Artwork on' to command tool]
PolyCorners <a REAL>
Replace the polygon with its corners. a determines how large the corners should be as a function of the lengths of the sides of the polygon. Values of a above 0.5 are not guaranteed to produce sensible results.
[Artwork node; type 'Artwork on' to command tool]
PolyCutCorners <a REAL>
Replace the polygon with its corners cut away. a determines how large the corners should be as a function of the lengths of the sides of the polygon. Values of a above 0.5 are not guaranteed to produce sensible results.
[Artwork node; type 'Artwork on' to command tool]
PolyFan <a REAL>
Replace the polygon with a "fan" shaped series of polygons joining the center and the edges. a determines how far along the edges the fans extend.
[Artwork node; type 'Artwork on' to command tool]
PolyStar <a REAL>
Replace the polygon with a "star" shaped series of polygons joining the center and the edges. a determines how far twoards the edges the blades reach.
[Artwork node; type 'Artwork on' to command tool]
Imaging
Graphics3d provides a tool for the display, or imaging, of various three-dimensional objects described by a scene.
Animation
An animation is a sequence of images intended to be displayed at 30 frames per second (for video) or 24 frames per second (for film). The sequence of images is generated from a corresponding sequence of image descriptions; these descriptions may be in the form of a mesa file or a scene file, both described elsewhere in this document.
User Guide
In General
In many of the interactive tools a scrollable, one or two line viewer displays certain information, such as the number of points and polygons written to a file. It also queries the user for information, such as a filename. A carriage-return in response to most queries will abort the current operation.
The software described in this document has numerous relations to other Cedar software. We present here a (possibly outdated) graph of the more prominent relationships:
[Artwork node; type 'Artwork on' to command tool]
User Profile Options
3dView.ArcBalls: TRUE | FALSE (defaults to FALSE)
Interactive Control
Interactive Control using ArcBalls
Note: All the interactive controls suppress graphics redraw if the left mouse button is used. In the descriptions that follow, this will be referred to as the blind button, or dragging blind.
Most interactive tools now support an unusual form of controls called ArcBalls. There is a ball for rotation and one for translation; each behaves a little differently, but both take arcs drawn on a sphere as input.
We discuss the rotation controller first:
An input arc is defined by clicking down at the start of the arc with the mouse inside the rim of the sphere, dragging with the mouse button still down, and releasing at the end of the desired arc. You will see the arc drawn on the sphere, providing feedback as you drag; unless you are dragging blind you will also see the graphics redrawn using the new rotation. The arc is used to specify an incremental change; a zero-length arc--obtained by clicking down and up without dragging--leaves the rotation unaltered. In general, an arc of q degrees will give a rotation of 2q degrees around the axis of the arc (the normal to the plane in which the arc lies). Thus a sideways drag along the equator will rotate around the vertical, a vertical drag will rotate around the horizontal, and a drag along the rim will rotate around the direction of gaze. (This is easier to do than to describe!)
In this unconstrained mode, any axis and any angle is possible, depending on where you start and how far you drag. If, however, you hold down either of the CTRL or SHIFT keys, the possible axes are restricted to the coordinate axes, of either the body (well, really the world for now) or the camera. Thus holding down SHIFT and clicking near the center of the ball limits you to either the horizontal or vertical camera axis. Note that the particular choice of axis still depends (to a more limited extent) on where you click down and where you drag.
You have another important option, represented by a "B" or "C" in the upper left corner of the ball. Clicking on it cycles the choice of rotation center from body to camera and back. Thus when "C" is displayed, the world will seem to rotate, while with "B" only the body will. Depending on your choice of center, the translation may also be affected.
Finally, you can resort to absolute numeric input. The numbers above the ball represent the current rotation as a quaternion. If you type in four new numbers (or just edit the values displayed) and a RETURN, you will replace (not increment) the current rotation. This will be a blind change; click the ball to redraw the graphics.
Here's how to use the translation controller:
A translation plane is specified by clicking anywhere on the ball, whereupon the mouse will drop a marker and move to the center of the circle. As the mouse is dragged with the button still held down, you will move about in the selected plane. Thus to move in the plane of the screen, click down in the center and drag; to move in depth, click on the rim. Unless you are dragging blind you will also see the graphics redrawn using the new translation. Again, the effect is incremental, so clicking and releasing without dragging does not change the translation. The rim of the circle now represents infinity, and you move faster as you approach it.
Constraints are still available, when desired, by holding down either of the CTRL or SHIFT keys. If you like, you can release a constraint key after selecting an initial plane, leaving you free to drag anywhere in that plane. Thus if you want to be sure you're not changing depth, hold down SHIFT, click down at the center of the ball, release SHIFT, and drag. (This is also possible, though less useful, with the rotation controller.) Note that if you rotate the body the constraint axes selected by CTRL are rotated with it.
Choice of origin is irrelevant for incremental translations, so the corner is empty. However you can still use absolute numeric input. Again, this will be a blind change; click either ball to redraw the graphics. Note that these controls order the camera transformation as rotate first, then translate; other controls may differ.
Hazards: When dragging blind it's easy to get lost. You can find the origin of the world again by typing in a rotation of "0 0 0 1" and a translation of, say, "0 10 0". When programs update the internal camera values, they probably won't tell the ArcBalls, so the displayed values may be stale. Click each ball to bring the numbers up to date if you suspect this has happened. Lights and objects are defined in world space; thus the position of a light is always fixed with respect to objects when the camera controls are manipulated.
Interactive Control Using Sliders and Dials
Most interactive tools will provide a set of controls that adjust the viewing parameters. These parameters may be adjusted in one of three ways:
1. direct manipulation of the viewing parameters
2. incremental adjustment of the world space (space within which objects are defined)
3. incremental adjustment of the eye space (space relative to the current eye position)
Generally, the latter two are the more intuitively useful. Adjusting in world space performs transformations on the objects relative to the object's coordinate system. Adjusting in eye space performs transformations relative to the current camera's coordinate system. Although this distinction is sometimes confusing, these two modes often are considered the most natural for scene interaction.
In eye or wor mode, the interactive camera controls reset themselves to zero after each release.
Most tools provide one set of controls for all three types of adjustments; the type of adjustment is determined by a mode control, which can be set to "par" (for direct manipulation), "wor" (for world space adjustment), and "eye" (for eye space adjustment).
Lights and objects are defined in world space; thus the position of a light is always fixed with respect to objects when the camera controls are manipulated.
Multiple Viewports
Some interactive tools may provide the user with multiple viewports. The camera controls will affect only the active viewport, which is denoted by a small black box in its lower left corner. To change the active viewport, simply click the mouse in the desired window.
The Sprite
Some interactive tools may provide the user with a ``sprite.'' This is a 3d point the user can position by CONTROL-mousing in a viewport.
Vertex Selection
Some interactive tools may provide the user the ability to select a vertex from a set of shapes. This is done by SHIFT-mousing in a viewport.
3dView
The principal interactive graphics tool for creating line drawing or shaded images.
Description
A tool to create line drawings or shaded images of a polygon model, as defined in <ShapeFile>. The shape file format, essentially a "points-polygon" file, is described above. A sample shape file, 3dTest.shape, is provided.
The program allows the user to interact with a number of display parameters. Most controls (sliders, dials, and pop-up menu selections) cause an immediate redraw of the viewer only if the right mouse button is pressed; this permits several parameters to be adjusted using the left mouse button before (a possibly very time consuming) redraw is performed.
3dView will read unusually ordered points-polygon files; that is, a file whose vertices are preceeded with an index and whose polygons reference vertices according to their index number, not their position in the file.
The reading of a file may be accelerated if the number of vertices and polygons is declared in a statement prior to the data, for example:
DataSize~ Vertices: 20, Surfaces: 36
Line drawing in the viewer may be aborted if the LEFT-SHIFT and SWAT keys are depressed while the mouse is in the viewer. The shaded image rendering may be aborted with the Abort-Render button.
Line drawings made on the LF display and shaded images made on the color display should match exactly. The LF-Ops function, "Show Render Window" places a dashed rectangle in the line drawing viewer to indicate the portion that will be shaded on the color display (they aren't necessarily equal since the LF viewer can change shape).
If an animation file is specified, 3dView obtains its display information from the animation file.
Options
3dView [Shape-file] [-interpret <interp file>] [-scene <scene file>] [-useArcBall]
Shape-file, if given, causes the named shape to be read as the initally displayed object.
An interp-file, if given, causes the named file to be interpreted (see 3dInterpret), with line drawings displaying the progress of the interpretation.
A scene-file, if given, causes the named file to be parsed for scene commands (see 3dScene), with line drawings displaying the progress of the parsing. The Draw scene command is functional.
If useArcBall is specified, an experimental method for orienting and positioning objects is used instead of the standard set of interactive controls.
An alternate version of 3dView, called 3dLine, provides the same functions, but for line drawing only.
Functions
Render Ops
Shaded Image | Hidden Lines
Grey Display | Full Color Display
AntiAliasing on | off
Texture Filtering (anti-aliasing) on | off
Read Texture from a File
Read Bumps from a File
Remove Texture and Bumps from a Shape
Auto Rendering on | off
Render an Arbitrarily Sized Image to a File
Annotation (parameter labeling of an image) on | off
LF Ops
LF Display on | off
Vertex Normals Display on | off
Face Normals Display on | off
Vertices Only Display on | off
Vertex Labeling on | off
Polygon Labeling on | off
Sprite on | off
Pendant on | off
Client Display on | off
Show Render Window on | off
Silhouettes on | off
Timing on | off
Curve Display on | off
Vertex Querying on / off
Line Drawing Mode solid | dashed | dotted
Shape Ops
Backing-Facing Polygon Display on | off
Invert Normals
If a shape file does not observe the conventions described in the section on shape files, then various rendering errors may occur. Inverting the surface normals is one method to compensate for the shape file error. One may need to experiment with these operations in order to correct any problems observed when rendering a shaded image.
Invert Polygons
If a shape file does not observe the conventions described in the section on shape files, then various rendering errors may occur. Inverting the polygon ordering is one method to compensate for the shape file error. One may need to experiment with these operations in order to correct any problems observed when rendering a shaded image.
Set Light Style
Set Render Style
Patches From Normals Display
Set Shininess of Shape
Scale texture coordinates of Shape
Change Bump Scale Factor
Set Color of Shape
List Current Shapes
Delete a Shape
Read New Shape
Light Ops
List Current Lights
Add a New Light
Adjust ambient lighting
Delete a Light
Animation Ops
Set Time
Show Frames
3dAnimateMaster
Description
This command defines the machine upon which it is run to be the master synchronizer for an animation:
3dAnimateMaster <animation name> <# frames> <estMinutesPerFrame>
Once the named animation is registered, remote machine may request a frame number from the master machine (see G3dAnimate.mesa). If any remote machine takes more than twice the estimated number of minutes per frame (estMinutesPerFrame), that frame may be given to another remote machine.
3dInterpret
Description
This tool interprets an animation file in order to render one or more images. The animation file is interpreted by the StatementInterpreter and, therefore, may include most Mesa language constructs. A sample mesa file, 3dTest.mesa may be interpreted by typing to the CommandTool:
3dInterpret 3dTest.interp
Options include:
-noLog don't create a log
-fork fork the animation
In addition to procedures in standard libraries (Rope, Convert, etc.), the animation file may define and use its own variables and procedures.
Interp files also may contain calls on the following procedures:
Command: PROC [rope: ROPE];
Execute the given command from within the mesa file.
ReadScriptFile: PROC [fileName: ROPE];
Read the named animation file; this permits a nesting of animation files.
MessageToLog: PROC [message: ROPE];
Write the given message to the 3dInterpret log.
Open: PROC [interface: ROPE];
Make the named interface available to the animation file. This is effectively equivalent in Mesa to a DIRECTORY, IMPORTS, and OPEN statement. As in Mesa, a procedure within the interface may be called with or without the interface name (e.g., either "Foo.Proc" or "Proc"). And as in Mesa, should two interfaces be opened, each of which exports a procedure by the same name, the desired procedure is obtained by using the interface name (otherwise the procedure obtained is from the last interface to be opened).
3dInterpret also provides access to the procedure:
Op: PROC [operation: ROPE];
Perform the given operation on the 3d scene.
An operation consists of keywords and anticipated data.
See the list of scene description commands, above.
3dLighting
Description
This is an interactive tool to facilitate designing the lighting for a 3d scene. The tool also provides the ability to choose surface parameters for the objects within a scene.
The tool only runs on the color display; if you don't have a color display, you cannot run this program. When you first invoke the tool, the color display must be in viewers-enabled, 24 bpp mode; if it is not, you will get a message (in the command tool) asking you to set the color display. Perhaps the easiest way to get the display into this mode is to type ColorDisplayModeFullColor to a command tool (see ColorDisplayDoc for this and other color display commands).
The real estate of the screen is divided into four logical areas: the image, the controls, the buttons, and the typescript. Using the controls and buttons you change the appearance of the image; the typescript mediates the textual I/O needed at times.
When you have created, positioned, and colored all of your lights, you may save them to a file for later use as input to the rendering and modeling programs. When you have created and described all your surfaces, they too may be saved to a file for later use as input.
All adjustments take place on a distinguished light, called the Active Light, and a distinguished material, called the Active Material. You may select any light or material to be active at any time, but only the active light or material may be modified by the controls.
There is one light with a distinguished name: Ambient. You may treat a light with this name like any other. However, this light has only color, so setting of its position or spread (see below) is ignored. The color of this light is added to every point in the scene. When you use the output of 3dLighting as input to the rendering system, the values of the light named Ambient are used as the ambient lighting values in the renderer.
Invocation
With the color display on, viewers enabled, 24 bpp, type
3dLighting
and you're in business. If you wish to use an image you have already created as your interactive image, then type
3dLighting AISFileName.AIS
and that image will appear in the image area of the tool.
The Controls
On the right side of the screen appear two sets of controls: one for controlling the lighting, and one for controlling surface descriptions.
Lighting Controls
The upper set of controls is for lighting design.
Light Color
At the top of this set are three horizontal sliders, marked H, S, and L. Immediately below them is a function viewer. To the left of these four controls is a colored box. Together, these controls help you design the color of the active light. The three sliders select the Hue, Saturation, and Value of the light's color, which is displayed in the vertical box just to the left of the sliders. The function viewer is for designing a spectral power distribution of the light's emittance (ihe contents of this function viewer are ignored for now).
Light Position
Beneath the color controls are two controls marked Psi and Theta. These represent the polar angles of the placement of the light. Psi is in the range [p/2 .. -p/2], where p/2 corresponds to the north pole, -p/2 is the south pole. Theta is in the range [0 .. 2p]; an angle of 0 maps to head-on from the viewer; larger values travel to the left, then left-to-right behind the object, and then again from right-to-left on the front.
Light Spread
To the left of the position controls is a horizontal slider marked S; this adjusts the spread of a light source. When S is less than 1, it is diffused more than normally, so that the light falls off less slowly as the surface turns away from the light source. When S is 1.0, then the geometry of a simple point source is used. When S is increased above 1.0, the light is narrowed, like a spotlight. (This parameter is not currently implemented in the renderer.)
Material Controls
Just beneath the S, Psi, and Theta controls for the lights appear the material controls.
Material Color
The H, S, L sliders, function viewer, and color box for the active material are used exactly as the corresponding lighting controls are used. At the top of this set are three horizontal sliders, marked H, S, and L. Immediately below them is a function viewer. To the left of these four controls is a colored box. Together, these controls help you design the color of the active light. The three sliders select the Hue, Saturation, and Value of the light's color, which is displayed in the vertical box just to the left of the sliders. The function viewer is for designing a spectral power distribution of the light's emittance (the contents of this function viewer are ignored for now).
Material Parameters
The material is described by seven parameters that are components of a slightly enhanced Phong shading model.
kd
This is the diffuse reflectivity coefficient, a control how "matte" the surface is.
ks
This is the speciular reflectivity coefficient, a control of the "shinyness" of the material.
ke
This is the specular highlight coefficient. Larger numbers give sharper highlights. Highlights are only an issue when ks > 0.0.
km
This is the metallicity coefficient. When 0, the material is considered "non-metallic", i.e. a plastic. When 1, the material is considered "fully metallic". This distinction affects a subtlety of shading called color shifting, which can modulate the color of a highlight on a metallic material, based on the angle of incidence and the wavelength. A small amount of color shifting is visible in the previewing image when the effect is extreme, but usually not otherwise due to the rather coarse quantization involved. (This parameter is not currently implemented in the renderer.)
kr
This is the reflectivity coefficient; 0 means "not reflective at all", 1 means "completely reflective". The effects of this control are not visible in the tool; only in the renderer.
kt
This is the transparency coefficient; 0 means "not transparent at all", 1 means "completely transparent". The effects of this control are not visible in the tool; only in the renderer.
Note that there are physical restrictions on some of these parameters that neither the lighting tool nor the renderer check to impose on you. You may wish to take these with a grain of salt, since the whole lighting model used in the tool and the renderer is more of a hack than a real simulation of radiation (though it is a time-honored hack in the field!). Nevertheless, your materials will be most sensible if you obey the conservation of energy:
kd + ks = 1.0
If kd + ks > 1, then the surface will reflect more light than it receives! Sometimes this is a useful effect in an image designed for artistic effect rather than physical simulation, so it remains possible. Do be careful, though.
The Buttons
The top row of the tool contains six buttons. Each button, when held down, causes a pop-up menu to appear.
Place Light
You may indicate the direction of the active light by clicking directly in the image area of the screen. This menu allows you to indicate how you want such a mouse click to be interpreted. Choosing one of these options specifies how the system will interpret future clicks of the mouse in the image area. The options will be discussed in terms of how mouse clicks are interpreted when that option is the one most recently selected. The default interpretation of mouse clicks when the program first begins is in the Place Direction mode.
Recall that lights are simple points, uniformly radiating in space. Mouse clicks in the image area specify the location of the light source. Thus, clicking in the image area is exactly equivalent to changing the Psi and Theta lighting controls.
Place Direction
The active light is positioned so that the indicated point is the most brightly lit.
Place Highlight
The active light is positioned so that the indicated point is the center of the highlight from the active light.
Point Towards
Subsequent mouse clicks are assumed to be on the (invisible) back of the surface, rather than the (visible) front. This is often helpful for setting up back-lighting.
Lighting Ops
This menu allows you to control the number of lights in your scene, and which is to be considered active.
Add Light
A new light is created and added to the set of lights. You are prompted for a name in the typescript. The light is originally created as an exact duplicate of the currently active light. The new light is made the active light.
Delete Light
You will be presented with a new menu of the current lights. The top entry reads "All Lights". Selecting any entry will remove the selected light from the scene; selecting "All Lights" will remove all lights from the scene. If the active light is deleted, some other light will become active if any lights remain.
Activate Light
You will be presented with a new menu of the current lights. Selecting one will make it the active light.
Material Ops
This menu allows you to control the number of materials in your scene, and which is to be considered active. All options work exactly the same way as for materials.
Add Material
A new material is created and added to the set of materials. You are prompted for a name in the typescript. The material is originally created as an exact duplicate of the currently active material. The new material is made the active material.
Delete Material
You will be presented with a new menu of the current materials. The top entry reads "All Materials". Selecting any entry will remove the selected material from the scene; selecting "All Materials" will remove all materials from the scene. If the active material is deleted, some other material will become active if any materials remain.
Activate Material
You will be presented with a new menu of the current materials. Selecting one will make it the active material.
IO
This menu allows you to read, write, and merge light and material descriptions to and from scene files. Each of the options prompts you for a file name in the typescript window. Any text in the indicated file that is not appropriate input to the chosen command is ignored; thus you may read in complete scene files, and only the germane commands are acted upon. Files created by the Write commands below are in scene file format, appropriate either for reading back into the program, or as input to any program that interprets scene files.
Write Lights
A complete description of all current lights is written to a file.
Read Lights
The current set of lights is replaced with the description in the specified file.
Merge Lights
The light descriptions in the specified file are added in to the set of lights in the current scene.
Write Materials
A complete description of all current materials is written to a file.
Read Materials
The current set of materials is replaced with the description in the specified file.
Merge Materials
The material descriptions in the specified file are added in to the set of materials in the current scene.
Write Lights and Materials
Write all lights and materials to a single file.
Read Lights and Materials
Shorthand for Read Lights and then Read Materials from the same file.
Merge Lights and Materials
Shorthand for Merge Lights and then Merge Materials from the same file.
Read Image File
Replace the image with the specifed AIS file. If you want the results to be useful, be sure that the file is a normal-encoded file, produced (for example) with the techniques below, under Preparing An Image for Use with 3dLighting.
Sphere
Sometimes it is helpful to see a high-resolution example of the current lighting situation. The active material is assumed to coat the surface of a sphere, and the current set of lights is used to illuminate that sphere. The rendered sphere appears in the image window. It cannot be interactively manipulated. To change anything, you must click in a control; this will cause the sphere to be replaced by the preview image, which you may then continue to manipulate interactively. You may then choose to see the sphere again later, when you have redesigned your scene. Large spheres can take a long time to draw!
Enter Radius
You are prompted for the radius of the sphere, in pixels.
Full Size
The largest sphere that can fit in the preview window is drawn. Warning: this can be slow!
150
The preview sphere is drawn with a radius of 150 pixels.
100
The preview sphere is drawn with a radius of 100 pixels.
50
The preview sphere is drawn with a radius of 50 pixels.
25
The preview sphere is drawn with a radius of 25 pixels.
Debug
Implementor's toolkit. No user-servicable parts inside. Refer service to qualified personnel. All warranties void upon breakage of seal. Guaranteed sterile until opened. You may already have won!
The Image
The image area of the tool is where you actually see the results of your interactive design. It is a large square in the lower-left corner of the screen.
The image is actually the upper-left 405 by 405 pixels of an AIS file. The default AIS file that appears when you first start the tool is called "3dNormalSphere.ais" and is found in the directory in which you did your Bringover to get 3dlighting. You may use another image of your own design using the IO button (described above).
Clicking in the image will cause the currently active light to change its position, based on the most recent selection from the Place Light button (described above). Until some selection is made from that button, mouse clicks in the image area are ignored.
The Typescript
A small viewer where prompts appear for file names, material and light names, and so on. Some output (such as short lists of lights) also appear in this viewer.
Preparing An Image for Use with 3dLighting
The 3dLighting image is actually an encoded form of the geometry of a rendered image. The idea is that when you want to use 3dLighting to design lighting and surface characteristics for a scene, you first render that scene using the rendering tools, but you enable "normal buffering". The easiest way to do this is to use 3dview to set up your viewing before you render; under the Rendering button select the option Normal Encoding is Off; this will toggle the normal buffering mode (the next time you look at this menu you'll see Normal Encoding Is On). Then select Render; the image will not look like typical rendered images; what's being created is an encoded form of the surface geometry of the visible surfaces. When your image is complete, save it as an AIS file (e.g. Ct Save MyImage.ais). This file is now appropriate for use with 3dLighting.
3dScene
Description
Usage: 3dScene <Scene Filename>.
This program parses a scene description file (described above); the Draw command is a no op.
3dTube
Description
Generalized cylinders have been used to advantage in representing three-dimensional synthetic and natural forms. The interest here is to provide the software support required to model the three-dimensional objects described in Bloomenthal: Modeling the Mighty Maple, Siggraph 1985.
The individual interfaces are self-documenting, and their use is typified in TubeCommandsImpl.mesa, which implements the program "Tube."
TubeCommandsImpl.mesa implements a program, called "Tube," which permits interactive specification of a tube.
Generalized cylinders, or tubes, consist of a cross-sections which follow along a central axis. The central axis consists of a sequence of spline sections which interpolate user specified knots. A surface is created by triangulating between the cross-sections.
Tube permits the interactive specification of a tube.
The tube viewer is divided into four horizontal sections. The upper section contains a menu of functions, the next lower section contains a typescript for querying the user, the next lower section contains the graphic representation of the tube, and the lowest section contains a number of controls for manipulating the tube.
Initially the tube is represented only by its central axis. This begins as a single spline section, but may be manipulated into an indefinite number of sections, forming a continuous spline sequence. Any individual section may be selected for special modification; the selection is performed with the middle mouse button (to mark the beginning of the selection) and the right mouse button (to mark the end of the selection). The left mouse button selects an individual point along the sequence.
The Menu
Any mouse button may be used to activate a menu button; no distinction is made between mouse buttons. The individual menu buttons are:
Help:  prints a short summary of mouse use onto the commander viewer.
Auto-On/Off: auto-on automatically eliminates details (such as contours) during display
  if the tube is being rotated; only the central spline and/or the tube
  skeleton are displayed. Auto-off defeats this feature, thus lengthening the
  drawing time, especialy if the tube has significant detail.
Label-On/Off: some details are labelled or not, depending on the state of this button.
Max-Out:  write the tube to a file in a points/polygon format especially designed for
  Nelson Max. The user is queried for a filename; a <CR> will abort the
  operation.
Poly-Out:  write the tube to a file in the shape file format used at PARC. The user
  is queried for a filename; a <CR> will abort the operation.
Skel-On/Off: if on, display the skeleton of the tube as a series of straight lines
  connecting the central knots.
Pick-On/Off: if on, display the tangent vector of the central axis where selected by the
  left mouse button.
Splines-On/Off: if on, display the central axis as a spline sequence; the selected sections
  are drawn solid, others dotted.
Circles-On/Off: if on, display the circular cross-sections of the tube.
Lines-On/Off: if on, display lines connecting the circular cross-sections of the tube.
Frames-On/Off: if on, display the reference frames used along the central axis of the tube.
Normals-On/Off: if on, display the normals to the tube surface.
Curv-On/Off: if on, display curvature vectors along the central axis of the tube.
Vel-On/Off: if on, display velocity vectors along the central axis of the tube.
Acc-On/Off: if on, display acceleration vectors along the central axis of the tube.
The Controls
The controls are in three rows. The upper row controls camera/object orientation; the middle row controls various surface parameters; the bottom row controls the shape of the central axis.
tw0: twists the beginning of the selected splines.
tw1: twists the end of the selected splines.
r0: changes the radius at the beginning of the selected splines.
r1: changes the radius at the end of the selected splines.
scal: scales the radius of the entire tube.
eps: this adjusts the epsilon which is used to determine the number of linear segments to
 represent the continuously curving central axis. The smaller eps, the greater the
 number of segments.
cres: this adjusts the circular resolution of the cross-sections.
lim: if the number of vectors to be drawn is less than lim,
 then the image is double-buffered; it is single-buffered otherwise.
ptx: move the horizontal position of the selected point on the central axis.
pty: move the vertical position of the selected point.
ptz: move the depth position of the selected point.
lng: change the longitude of the tangent to the central axis at the selected point.
lat: change the lattitude of the tangent.
mag: change the magnitude of the tangent.
Other Interactive Tools
3dCleave <Shape-File>
Cleave a shape with an interactively specified plane.
3dNavigate <Shape-File>
Crawl along the surface of a model according to an interactively drawn curve.
3dPatch
Simple interactive manipulation of Bezier control points to display a bicubic surface patch. The control point is selected by mousing down in the graphics viewer; once selected, the control point is indicated by an asterisk.
3dPlotHeight
Display of height fields (elevation data). This may be performed with hidden lines removed. Interactive scaling and centering available to the user. Cf: PlotGraphDoc.tioga.
3dPolygonModel
Interactively create a polygon model [NOT IMPLEMENTED].
3dPolygonProx
Interactively detects points on a model closest to a given point or intersected by a given ray.
3dProject
A test bed for different 3d to 2d projection techniques.
3dTexture
Interactively adjust the texture of a model [NOT IMPLEMENTED].
3dVolumeAddDel
Interactively modify an octree.
3dVolumeNeighbors
Interactively explore neighbors of cubes.
3dVolumeRead
Display an octree, according to the following octree file format:
A keyline must precede the octree data and be of the form:
Octree~ size: <REAL> center: <x, y, z: REAL>,
where size is the width of the root octree.
Subsequent data lines should be of the form:
Cube: <BBBBBBBB>
where B is either a 0 or a 1, and the position of B corresponds to an octant of the cube
 where the octants are ordered: lbn, lbf, ltn, ltf, rbn, rbf, rtn, rtf,
 l standing for left, r for right, b for bottom, t for top, n for near, and f for far.
A 0 represents no subdivision of the corresponding octant; a 1 does.
For example, an octree whose root cube is subdivided only in the left-bottom-far octant, would be encoded as:
Cube: 01000000
Cube: 00000000
Non-interactive Commands
3dGraph <Function> [-option]
functions are:
 Bump:  a second order curve
 Gauss:  the normal distribution curve
 Poisson:  the poisson curve, with a the scalar
 Power:  a power curve, with a the exponent
 Sin:  a sin curve raised to the a power
 Ln:  natural logarithm
 Log:  logarithm to the base a
 Perlin:  Ken's curve, with a the scalar
 Wyvill:  Wyvill's soft function
 SlowInOut:  Slow in and out curve
options are:
 -scale  <REAL> (default = 1)
 -xMin   <REAL> (default = 0)
 -xMax   <REAL> (default = 1)
 -a  <REAL> (default = 1)
3dModelOps
Perform simple operations on a shape file.
3dModelStats
Print statistics given a shape file.
Guide to the Programmer
The Release Process
In order to assure users and clients a stable CedarChest version, this release process is proposed:
1. Notify users/clients that the CedarChest versions will be inconsistent for a short period.
2. Ask the CedarChest coordinator not to Delver or KillExcessVersions on the pertinent directories.
3. Bringover /CedarChest7.0/Top/Graphics3d.df.
4. Edit/Debug/Test
5. Check packages with Unbound program. MakeVerify, and SModel when consistent.
6. Announce the new release.
7. Wait a sufficient time (two or three working days?) for users/clients to Bringover.
8. Ask the CedarChest coordinator to KillExcessVersions on the pertinent directories.
The Interfaces
Graphics3d.df is an umbrella for other DF files. A summary, presented by DF file, follows. Most details are provided in the individual interfaces.
G3dBasic.df
This package comprises several interfaces for geometric functions: vector arithmetic for operating on vectors and points, planar arithmetic for operating on planes, matrix arithmetic for representing geometric transformations, and an interface for three dimensional splines. The interfaces are exported by G3dBasicPackage.bcd.
G3dBasic
Basic geometric definitions of geometric primitives and sequences. Basic procedures for geometric computation as well as sequence copying and lengthening.
G3dClip
Three dimensional clipping functions when displaying via a perspective transformation.
G3dCurve
Procedures to define and evaluate contiguous spline segments.
G3dDraw
Procedures to draw 3d primitives into Imager contexts.
G3dFunction
Includes a (hopefully expanding) collection of functions that have use in three-dimensional modeling, rendering, or animating.
G3dHierarchy
Procedures to create, manipulate, and evaluate a tree of 3d primitives and/or attributes.
G3dIO
IO functions for 3d primitives.
G3dMatrix
Operations on four by four matrices, useful for homogeneous transformations. This collection of procedures allows the creation and concatenation of transformation matrices which represent fundamental three-dimensional geometric transformations such as scale, translation, rotation, and perspective.
G3dPatch
Procedures to create, manipulate, and evaluate bi-cubic patches.
G3dPlane
Operations on three-dimensional planes. This collection of procedures allows fundamental planar arithmetic to be performed on simple geometric primitives such as lines and points.
G3dPolygon
Operations on three-dimensional polygons.
G3dQuaternion
Operations on quaternions. This collection of procedures provides quaternion algebra, construction and extraction, conversion to and from rotation matrices, and splining. Quaternions are considered by many to be a superior representation for the storage and splining of body and camera orientations.
G3dShape
Definition of three-dimensional shapes, their creation, manipulation, input and output.
G3dSpectrum
Definition and evaluation of color spectrums.
G3dSpline
Interpolation, conversion, evaluation, size, search, subdivision, and miscellaneous functions of three-dimensional curves.
Some thoughts about Geometry3dSpline.CoeffsFromPointsAndNormals[]: this is related to the more general problem of surface fitting; although consideration of the differential geometry of the surface may lead to a less ad hoc approach, the problem as given to CoeffsFromPointsAndNormals is underconstrained; therefore, the ad hoc heuristic chosen doesn't seem unreasonable.
G3dVector
Operations on three-dimensional points and vectors. This collection of procedures allows fundamental vector arithmetic to be performed on simple geometric primitives such as vectors and points.
G3dView
Procedures for setting the view transformations for subsequent shaded images or line drawings.
G3dModel.df
This comprises several interfaces for creating and manipulating three-dimensional models; the interfaces are exported by G3dModelPackage.bcd.
G3dAssembly
Procedures for assembly components into more complex models.
G3dNavigate
Procedures for movement along the surface of a model.
G3dModel
Includes a definition of a three-dimensional model that includes points, polygons, normals, colors, textures, and accelerators for line-drawing. Also includes procedures for the reading, writing, drawing, and manipulating of such models.
G3dSweep
Procedures defining swept surfaces.
G3dTexture
Procedures for assigning texture to models.
G3dTube
Procedures for defining, manipulating, and evaluating tubular objects.
G3dWingedEdge
Procedures for defining, manipulating, and evaluating windged-edge objects.
G3dRender.df
This package comprises several interfaces for the rendering of three-dimensional primitives and models; the interfaces are exported by G3dRenderPackage.bcd.
G3dColorDisplaySupport
Procedures to support drawing into the color display.
G3dClipXfmShade
Procedures for clipping, transforming, and shading.
G3dDisplay
Procedures for controlling the color display.
G3dEdgeBlt
??.
G3dLight
Procedures for lighting models.
G3dMappedAndSolidTexture
Procedures to support rastered or procedural texture or bump mapping.
G3dNormalCoding
Procedures to compute normal codes from a z-buffer.
G3dRender
The principal interface for clients wishing to render scenes as described by a 3d context.
G3dRenderWithImager
Low level procedures for rendering to an Imager context.
G3dRenderWithPixels
Low level procedures for rendering to to a color display.
G3dScanConvert
Scan conversion procedures for the rendering of shaded images.
G3dShade
Shading techniques for three-dimensional objects.
G3dSortandDisplay
Low level procedures for depth sorting of polygons.
G3dViewer
Procedures for interacting with the Viewers mechanism.
G3dScene.df
This package comprises several interfaces for the specification and rendering of three-dimensional scenes; the interfaces are exported by G3dScenePackage.bcd.
G3dAnimate
This interface provides for the synchronization of remote computation of frames within an animation.
G3dBuild
Proecedures for creating various canonical shapes.
G3dScene
Procedures for placing models within a scene.
G3dUser.df
G3dUser.df consists of implementations and load files for command line commands and interactive tools that create, manipulate and render three dimensional objects. The commands are described in detail in the User's Guide, above.
This df file also contains the G3dUserPackage, which exports interfaces for the interactive control of position and orientation of objects and camera. These interfaces are briefly described:
G3dArcBall
Procedures to create and respond to controls for position and orientation of an object and a camera.
G3dControl
Procedures providing three-dimensional control for positioning and orienting objects and the camera. See the section, Interactive Control, below.
G3dInterpret
Procedures for specifying and applying motion to models.
G3dLighting
Procedures to support the 3dLightingTool.
G3dLineTool
Procedures to support line drawing tools.
G3dPlot
Procedures to support height field plotting.
G3dRayTrace
A number of procedures to support ray tracing, including a tool that displays the ray-trace image area, eye point and direction; the client must register a ray-tracing procedure (one that returns an rgb value given a unit length ray). The image screen width and height is set by the client or by the user, as is the field-of-view; the vertical screen size is clipped so that the aspect ratio agrees with the image size and field-of-view.
G3dRayTraceTool
Procedures to support a ray tracing tool.
G3dRenderTool
Procedures to support rendering tools.
G3dVolume.df
This package comprises several interfaces for defining, manipulating, and rendering two forms of spatial representations: the octree and the voxel array. The interface is exported by G3dVolumePackage.bcd.
G3dCube
Operations on cubes and octrees.
G3dCubeDraw
Drawing operations for cubes and octrees.
G3dOctree
Definition and operations on octrees.
G3dRayCube
Ray-cube intersection operations.
G3dVoxel
Procedures for the creation of voxel arrays, and the storage and retrieval of voxels.
Notes on Theory and Implementation
G3dControl Camera Model
The ``camera transformation,'' as defined in G3dView.WorldToViewMatrix, is
[x y z 1] [Wi] [S] [T] [R] [X] [Ei] [P]
where
Wi is the incremental world transform, if any,
S is scale,
T is translate,
R is rotate,
X swaps y and z (world space is right-handed, eye and view spaces are left-handed),
Ei is incremental eye transform, if any,
P is perspective.
[Artwork node; type 'Artwork on' to command tool]
The standard parameters are in G3dControl.Camera.par, namely:
1 scale (no differential scale)
3 mov (x, y, z translates)
3 rot (x, y, z); R = Rx.Ry.Rz, in that order
1 field of view
For a more intuitive interaction, incremental controls are provided that insert, one at a time, simple translation or rotation transformations into the transformation pipeline in world space or eye space. These are camera.wor and camera.eye.
In order to maintain a unique, nonredundant, repeatable camera representation, these incremental controls are ``absorbed'' or merged back into the standard parameters.
Incremental World Space Transforms
Note: Mi means M incremental.
World Space Translate
Given Wi = Ti = a translation,
find T', R' such that TiSTR = ST'R'
where | | is the matrix symbol
  | |
and t and ti are 1X3 = [x y z] matrices,
and s and r are 3X3 matrices
TiSTR = |1 0| |s 0| |1 0| |r 0|
   |ti 1| |0 1| |t 1| |0 1|
combining the first two terms:
=   |s 0| |1 0| |r 0|
   |sti 1| |t 1| |0 1|
expanding the first term:
=   |s 0| |1 0| |1 0| |r 0|
   |0 1| |sti 1| |t 1| |0 1|
combining the second and third term:
=   |s 0| |1  0| |r 0|
   |0 1| |t+sti 1| |0 1|
=   S T' R'; thus, T is modified, R is unmodified
World Space Rotate
Given Wi = Ri = a rotation,
find T', R' such that RiSTR = ST'R'
RiSTR = |ri 0| |s 0| |1 0| |r 0|
   |0 1| |0 1| |t 1 ||0 1|
combining the first two terms:
=   |ris 0| |1 0| |r 0|
   |0  1| |t 1| |0 1|
manipulating the first two terms:
=   |s 0| |ri 0| |r 0|
   |0 1| |t 1| |0 1|
manipulating the second and third terms:
=   |s 0| |1  0| |rir 0|, (because tr = tri-1rir)
   |0 1| |tri-1 1| |0 1|
=   S T' R'; where R'=RiR; thus, T is modified, R is modified
A new rotation matrix R' is computed, then its rotation parameters are extracted.
Incremental Eye Space Transforms
Eye Space Translate (dolly: left/right, up/down, in/out)
Given Ei = Ti = a translation,
we want to find T', R' such that TRXTi = T'R'X
where X = swap matrix: |1 0 0 0|
       |0 0 1 0|
       |0 1 0 0|
       |0 0 0 1|
TRXTi = |1 0| |r 0| |x 0| |1 0| |x 0| |x 0|, (two swaps okay, since XX = I)
   |t 1| |0 1| |t 1| |ti 1| |0 1| |0 1|
combining the third, fourth, and fifth terms:
=   |1 0| |r 0| |1 0| |x 0|, where tx = (a, c, b) if ti = (a, b, c),
   |t 1| |0 1| |tx 1| |0 0|, since Tx = XTiX = |1  0|, and x = |1 0 0|
                 |tix 1|,    |0 0 1|
                       |0 1 0|
manipulating the second and third terms:
=   |1 0| |1  0| |r 0| |x 0|
   |t 1| |txr-1 1| |0 1| |0 1|
combining the first two terms:
=   |1   0| |r 0| |x 0|
   |t+txr-1 1| |0 1| |0 1|
=   T' R' X; thus, T is modified, R is unmodified
Eye Space Rotate (Gimbal: picthc, yaw, roll)
Given Ei = Ri = a rotation,
find T', R' such that TRXRi = T'R'X
TRXRi = |1 0| |r 0| |x 0| |ri 0| |x 0| |x 0|, (two swaps okay, since XX = I)
   |t 1| |0 1| |0 1| |0 1| |0 1| |0 1|
combining third, fourth, and fifth terms:
=   |1 0| |r 0| |rx 0| |x 0|
   |t 1| |0 1| |0 1| |0 1|, where Rx = XRiX,
           rx = xrix = |1 0 0| |a b c| |1 0 0| = |a c b|
               |0 0 1| |d e f| |0 0 1|  |d e f|
               |0 1 0| |g h i| |0 1 0|  |g h i|
combining the second and third terms:
=   |1 0| |rrx 0| |x 0|
   |t 1| |0 1| |0 1|
=   T' R' X; where R'=RRx= RXRiX; thus, T is unmodified, R is modified
An extraction is needed.
 — Paul Heckbert
G3dQuaternion
In the code, both the incremental rotation and the aggregate rotation are represented as unit quaternions, qInc and qAgg. Just to remind you, a unit quaternion has four components, [x, y, z, w], naturally grouped as a vector v=[x, y, z] and a scalar w, with x2+y2+z2+w2=1. The mapping from unit quaternions to rotations is such that [v, w]=[u sin q/2, cos q/2], where u is a unit vector along the axis of rotation and q is the angle of rotation. Quaternion multiplication maps to rotation composition. To end these preliminaries, note that since sine is an odd function, the inverse of unit q=[v, w] is its conjugate, q*=[—v, w].
The quaternion for the rotation determined by the arc from p0 to p1 on the unit sphere is given by p1p0*, where the product is the quaternion product, here equal to [p0 p1, p0 . p1]. It's pretty easy to see that this gives a rotation about the axis perpendicular to the plane of the arc, by an angle equal to twice the arc length. (The dot product gives cosine of the arc length, and the cross product gives a vector perpendicular to the plane of p0 and p1 with magnitude the sine of the arc length.)
The angle doubling is important for two reasons. First, it allows all possible rotations, from 0° to 360°, about any axis, to be indicated by an arc on the visible hemisphere. Second—and more subtle—it works out so that the rotation for p1 from p0 followed by the rotation for p2 from p1 is equal to the rotation for p2 from p0. (This is trivial to show using quaternions. Let q10=p1p0*, q21=p2p1*, and q20=p2p0*. Then q20=q21q10=p2p1*p1p0*=p2p0*, since p1*=p1-1.) This has the important implication that as one drags the end of an arc, the change in orientation is natural, since a dragging motion acts like an incremental arc with the same effect as a final arc, and the spherical "vector addition" works. Also, the present orientation is not affected by the path I took to bring the end to its present location; not so for an ordinary trackball.
This whole idea grew out of the fact that there is an isomorphism between rotations and arcs on a sphere, (see D. S. Richardson's paper "Quaternion Algebra for Three-Dimensional Computer Graphics and Modelling", Australian Comp. Sci. Communications, 5(1), 109—120, February 1983; Richardson makes the error, throughout his paper, of omitting angle doubling.) While I had known of this for quite some time, I never saw any particular use for it, until inspiration hit a week ago.
Note that the isomorphism does allow us to plot a rotation/orientation in a graphically meaningful way, not just an input one.
If the increment is left multiplied times the aggregate, qIncqAgg, the axes will remain fixed with respect to the viewer; this seems the least confusing way to do it. However, if we right multiply, qAggqInc, the axes will remain fixed with respect to the object, which is sometimes handy.
The arcs should increment, not just set, the current orientation, because they would always start as zero length; a non-incremental effect would be too jarring. And so that the user could get an idea of the axis by looking at the feedback on the ball, we draw the projected arcs, rather than the simpler chords.
In summary, a few simple algebraic ideas:
 (1) Stick to unit quaternions: x2+y2+z2+w2 = 1
 (2) Quaternions have four real components: [x, y, z, w],
  which can be treated as [vector, scalar]: [[x, y, z], w]
 (3) Quaternions are almost an axis-angle description:
  [v, w] = [UnitAxis*sin Angle/2, cos Angle/2]
 (4) The composition of rotation q1 followed by q2 is the non-commutative product: q2 q1
And a few geometric ideas for unit quaternions:
 (5) They form a unit sphere in x-y-z-w 4D space
 (6) Diametrically opposite points are the same rotation
 (7) Travel along a great arc gives rotation about a fixed axis
 (8) Arc length is half the rotation angle
Lastly, a meta-rule:
 (*) Quaternions are like complex numbers, but multiplication doesn't commute.
 — Ken Shoemake
G3dNormalCoding
The rationale behind G3dNormalCoding
G3dNormalCoding allows the conversion of normalized vectors to or from 8-bit integers. This is useful for interactive tools that perform shading via the colormap; each entry in the colormap corresponding to a particular normal. Once each colormap entry is filled with the shade for its associated normal, the frame buffer image will appear shaded.
The rationale behind the design
This approach has its drawbacks. First, Dorado frame buffers, as do most frame buffers, allow only 256 entries in the colormap. Thus, each picture may display only 256 different normals. Second, there is a necessary loss of precision when converting from an encoded (8-bit) normal to a full floating-point normal.
The impact of the first problem is reduced by dithering the normals before encoding; each normal has a small amount of noise added to it before it is quantized into one of the 256 buckets. There's not much to be done about the second problem. When reading a normal back from the frame buffer, you may wish to read pixels from a region centered around the pixel of interest, and then average. This compensates for the noise added during encoding, and also provides some interpolation between the quantized normals.
There are two colormap entries that should not be used in such a scheme: colors 0 and 255, corresponding to foreground and background (usually black and white, respectively). Users expect black text on a white background, and that should be the default. If a tool decides to change these colors that's fine, but the normal encoding process should leave them alone.
There are many ways to convert a normal into an 8-bit quantity. A number of schemes were tested, including: encode just the x and y componenets, four bits each (z is determined by z = 1-x-y); encode polar co-ordinates r and q, four bits each (r = SqRt[x2+y2], q = ArcCos[y, x]), and a single value representing arc-length around an equal-area spiral. These all required special tests to avoid the foreground and background colors. Some also had wasted entries (for example, using four bits for each of x and y means that there will be an entry for [1, 1], which is clearly unrealizable by unit-length vectors).
The encoding technique
The solution finally adopted is the use of a pair of tables, one associating normals with indices, and the other associating indices with normals. To encode a normal, one looks it up in the table, and receives an index number giving the colormap entry for that normal. To decode, one looks up the index number in the other table.
The correlation between indices and the geometry of the normals is not trivial, as it is with the cases above. Consider a 17-by-17 grid of squares, exactly enclosing a circle; the circle's center is at (8.5, 8.5) with a radius of 8.5. There are 249 squares with at least some of their area within the circle. For each of these squares, one finds the (x, y) co-ordinates at the center, and treats those as the first two co-ordinates of an associated normal.
The approach is to scan the grid from left to right, top to bottom, finding those squares within the circle and filling up the tables with normals for those squares.
For example, consider the following 5-by-5 grid, centered within the larger 17-by-17 grid:
[Artwork node; type 'Artwork on' to command tool]
The grid under consideration is (10, 7); its center is (10.5, 7.5). Its normalized (x,y) coordinates are ((10.5-8.5)/8.5, (7.5-8.5)/8.5) = (0.2352941, -0.1176471). Since z = SqRt[1.0 - (x2+y2)], the normal at this square is (0.2352941, -0.1176471, 0.9647776).
Assume that squares [0 .. s] have been filled so far, so this is the s+1'st normal to be encoded. So now GtoNTable[s+1] ← (0.2352941, -0.1176471, 0.9647776), which associates Grayvalue s+1 with this normal (hence GtoN for "Grey to Normal").
The other table, NtoGTable, associates the colormap entry s+1 with a quantized version of this normal. Clearly it's easiest to use the values in the grid for the x and y components, so NtoGTable[10][7] ← s+1.
On a 17-by-17 grid, 249 entries, [6 .. 254] ,will be filled this way . Entries 0 and 255 are reserved for foreground and background colors (usually black and white, respectively). Entries [1..5] are available for use by the program. In the lighting-and-surface tool, color 1 is for the light source color display and color 2 is for the surface color display.
 — Andrew Glassner