The following subsections cover in detail the format of each node's specification in a scene file, as well as its response and precise effect on the traversal state, when encountered. The traversal state consists of
Group Beginand
Group Endeach delimiter occupying a line of its own. A Group node may have no children, in which case it effectively becomes a leaf node.
Also, right before the first child appears, i.e. immediately after the Group Begin delimiter, the node's name (or lack thereof) is specified on a separate line. This line must start with the Name keyword, followed by a mandatory colon and a single space, and end with an arbitrary string which becomes the node's name. The keyword <None> may be used in place of a name, in which case the node remains nameless.
When a Group node is encountered during traversal, it first saves the current traversal state, then it traverses its children, and concludes by restoring the traversal state to its saved configuration.
A Primitive node requires a single additional line (besides the node type), which specifies the shape of the primitive. All the valid shape names are listed in the table below, in the first column.
When traversed, a Primitive node renders itself, using the current traversal state to determine the rendering parameters and the modeling transformation. The second column of the table describes the rendered object in detail, assuming an identity modeling transformation.
All objects except lines and discs are rendered by invoking some routine in the general purpose library for graphics applications, possibly after some elementary transformations are pushed on the modeling stack to provide consistent orientation between primitives. By contrast, lines and discs are always rendered using direct OpenGL calls, for efficiency. The user may specify whether all primitives but lines are rendered as lit solids or wireframes.
The third column in the table states where a shape appears in the above figure.
Shape name | Rendered object | Location in figure |
---|---|---|
Sphere | A unit sphere centered at the origin. | Center. |
Cube | An axis-aligned cube with unit side length, and centered at the origin. | Middle row, right column. |
Cylinder | An un-capped cylinder of unit radius, wrapped around the y axis and extending from y=-0.5 to y=0.5. | Top row, right column. |
Line | A line segment lying on the y axis, and extending from y=-0.5 to y=0.5. | Top row, third column. |
Icosahedron | An icosahedron whose vertices lie on a unit sphere centered at the origin. | Top row, second column. |
Octahedron | An octahedron whose vertices lie on a unit sphere centered at the origin. | Top row, left column. |
Tetrahedron | A tetrahedron whose vertices lie on a unit sphere centered at the origin. | Middle row, left column. |
Dodecahedron | A dodecahedron whose vertices lie on a unit sphere centered at the origin. | Bottom row, left column. |
Cone | An un-capped cone whose base has unit radius, whose axis is aligned with the y axis, and extending from y=-0.5 to y=0.5. | Bottom row, middle column. |
Disc | A flat disc of unit radius lying on the xz plane. | Bottom row, right column. Shown rotated about the x axis by 90 degrees, for clarity's sake. |
The scene file which was used to generate the above figure is
/usr/class/cs248/assignments/assignment3/examples/primitives.sc
Each property name is followed by a mandatory colon, a sequence of tabs and/or spaces, and some space- and/or tab-separated real numbers. Each of these numbers is called an argument, and all the arguments together comprise the value of the property; the number of arguments for each property is listed in the second column of the table.
The effect of a Material node on the traversal state is twofold:
The interpretation of properties and their values adheres to OpenGL's lighting model; for more information, consult chapter 6 of the The OpenGL Programming Guide and/or the on-line manual pages for glMaterial*().
Property name | Number of arguments |
---|---|
Ambient | 4 |
Diffuse | 4 |
Specular | 4 |
Emission | 4 |
Shininess | 1 |
Each property name is followed by a mandatory colon, a sequence of tabs and/or spaces, and then some space- and/or tab-separated arguments; the number and type of arguments for each property are listed in the second and third columns of the table.
When a Light node is encountered during traversal,
The interpretation of the light emission properties and the light position adheres to OpenGL's lighting model; for more information, consult chapter 6 of the The OpenGL Programming Guide and/or the on-line manual pages for glLight*().
Property name | Number of arguments | Argument type |
---|---|---|
ID | 1 | Integer between 0 to 7 (both ends included) |
Ambient | 4 | All reals |
Diffuse | 4 | All reals |
Specular | 4 | All reals |
Position | 4 | All reals |
Caution: By default, no OpenGL lights are enabled, and thus all scene objects except lines are invisible. At least one light needs to be specified to make objects visible. For example, to simulate the effect of the sun shining from directly behind the camera, the following light specification can be used:
Light ID: 0 Ambient: 1 1 1 1 Diffuse: 1 1 1 1 Specular: 1 1 1 1 Position: 0 0 1 0
The first property of a camera is its name. It is specified in a line by itself, using the Name keyword, followed by a mandatory colon and a single space, and then its argument, which is an arbitrary string. Unlike other nodes with a name property, a Camera node must always be named; that is, the argument <None> does not make the camera nameless.
The second property of a camera is its type. Its specification commences with a line starting with the Type keyword, followed by a mandatory colon and a single space. The first argument of the property follows. This can be either
On the next line, all the remaining arguments, some space- and/or tab-separated real numbers, appear. The number of the remaining arguments depends on the first argument:
When a Camera node is encountered during traversal,
The only property of a static transformation is its type. Its specification commences with a line starting with the Type keyword, followed by a mandatory colon and a single space. The first argument of the property follows. Valid values for this first argument appear in the first column of the table below.
On the next line, all the remaining arguments, some space- and/or tab-separated real numbers, appear. The number and interpretation of the remaining arguments depend on the first one; these are tabulated below, in the second and third columns respectively.
First argument | Number of remaining arguments | Interpretation |
---|---|---|
Translation | 3 | X, Y, and Z displacements. |
Scale | 3 | X, Y, and Z scale factors. |
Rotation | 4 | Angle of rotation, in degrees, followed by the X, Y, and Z components of the rotation axis. |
When a Static Transformation node is encountered during traversal, it post-multiplies the current modeling matrix by a matrix effecting the transformation encoded in the node. To this end, the OpenGL calls glTranslate*(), glScale*(), or glRotate*() are used, depending on the first argument; for more information on these transformations and their parameters, see the pertinent manual pages.
The first property of a joint transformation is its name (or lack thereof). It is specified in a line by itself, using the Name keyword, followed by a mandatory colon and a single space, and then its argument, namely an arbitrary string which becomes the node's name. The keyword <None> may be used in place of a name, in which case the node remains nameless.
The second property of a joint transformation is its type. Its specification commences with a line starting with the Type keyword, followed by a mandatory colon and a single space. The first argument of the property follows. Valid values for this first argument appear in the first column of the table above.
The remaining arguments of the type property appear between the delimiters
Keyframes Beginand
Keyframes Endeach delimiter occupying a line of its own. Between these delimiters, two or more lines appear, each containing some space- and/or tab-separated real numbers.
The two required lines should correspond to the first and last keyframe.
When a Joint Transformation node is encountered during traversal, it behaves in almost the same way as a Static Transformation node. The only difference is that Joint Transformation nodes take into account the user-specified
when modifying the current modeling transformation. Thus, each of the parameters of a Joint Transformation node (e.g. the X, Y, and Z displacements for a translation) areCaution: Interpolating the axis of rotation can produce unintuitive, albeit semantically correct, results.