Each BranchGroup object also has a compile method for converting the subgraph un-
der the object to an internal Java 3D format for faster rendering. As an example, several
successive transformation matrices under the subgraph may be combined for rendering
In the code segment of Figure 6 where a multicolor cube is created, line 14 first creates
an empty BranchGroup node BG_c. Line 17 then creates a TransformGroup TG_c , which
will be discussed in the next section, in Figure 6, and attaches it as a child node to BG_c.
In line 27, the BranchGroup is compiled. A BranchGroup can be detached by invoking
the detach() function.
In line 24, bounds are declared to specify a volume of space for a certain region of
influence for appropriate objects and scene group nodes. This is essential for rendering
and other purposes such as determining the influence of, for example, lightning and fog.
In general, the volume specified may be within a box, a sphere or between sets of planes.
In the RotatingCube example, an imaginary sphere within which the cube is to rotate is
In addition to BranchGroup, TransformGroup is another commonly encountered object in a
scene graph. Technically, a TransformGroup object serves as a container for Transform3D
objects, through which translational, rotational and other transforms can be specified. All the
child nodes under a certain TransformGroup node will be subject to the specified transforms
so that the objects rendered will be appropriately translated, rotated and transformed.
In the RotatingCube example, a TransformGroup node TG_c, as depicted in Figure 6,
is created for the behavior B1, Geometry and Appearance S1, of the multicolor cube object.
Details on these nodes have been discussed earlier in Section 1.7.
As mentioned in previous section, the view branch defines how a viewer sees the virtual
world. In the code fragment in Figure 5, specific parameters on the viewing position, ori-
entation, screen size and so on are provided so that Java3D can render a certain desirable
view of this 3D world on, for example, a 2D monitor.
A detailed discussion of various nodes and components under the view branch is given in
the chapter on multiple views. However, in simpler applications where a single view is enough,
it is not necessary to understand the full mechanism involved in the view branch.
Instead, by using a convenience utility class provided by Java3D, a simple universe
comprising the structure within the boxed region in Figure 7 can be readily constructed
Search WWH ::