< Zurück | Inhalt | Weiter >

5.4 Group

java.lang.Object

|

+−−javax.media.j3d.SceneGraphObject

|

+−−javax.media.j3d.Node

|

+−−javax.media.j3d.Group


Group defines a scenegraph Node that contains a collection of child Nodes. It defines the following child

Node management methods:


void addChild(Node child) java.util.Enumeration getAllChildren() Node getChild(int index)

void insertChild(Node child, int index) void moveTo(BranchGroup branchGroup) int numChildren()

void removeChild(int index)

void setChild(Node child, int index)


These methods essentially delegate, in obvious ways, to the internal collection that manages the child Nodes within the Group. Table 5.2 shows the capabilities defined by Group.


Table 5.2 Capabilities defined by Group


Capability bit

Description

ALLOW_CHILDREN_EXTEND

Allows child Nodes to be added to the Group

ALLOW_CHILDREN_READ

Allows reading of child Nodes (e.g., getChild method)

ALLOW_CHILDREN_WRITE

Allows writing of child Nodes (e.g., setChild method)

ALLOW_COLLISION_BOUNDS_READ

Allows reading of collision Bounds

ALLOW_COLLISION_BOUNDS_WRITE

Allows writing of collision Bounds

Group is an important base class for the Java 3D Node management classes, and it can also be instantiated in its own right. For increased flexibility, however, I recommend BranchGroup Nodes because they can be dynamically added or removed from the scenegraph. The classes derived from Group are shown in table 5.3.


Table 5.3 Classes derived from Group


Class

Description

BranchGroup

A dynamically insertable and removable Group

OrderedGroup

A Group that renders its children in a defined order, irrespective of location

Primitive

A geometric Group used to manage geometry in the utils package

SharedGroup

A Group that can be reused across the scenegraph and can be attached to multiple parents

Switch

A Group that can conditionally display its child Nodes


TransformGroup

A Group that has an associated geometric transformation containing rotation, translation, and scale information that is applied to its child Nodes before rendering

Note that an instance of any of the Group−derived classes, including SharedGroup, can only be added to a single location within the scenegraph. Attempting to add a scenegraph node to a scenegraph that already has an assigned parent (i.e., a node that has already been added to the scenegraph) will result in a run−time exception. I discuss reusing scenegraph branches using a SharedGroup and a Link later in this chapter.


 

5.4.1 Remove a child Node by reference