< Zurück | Inhalt | Weiter >

5.6 BranchGroup

java.lang.Object

|

+−−javax.media.j3d.SceneGraphObject

|

+−−javax.media.j3d.Node

|

+−−javax.media.j3d.Group

|

+−−javax.media.j3d.BranchGroup


BranchGroup defines a Group Node that can be dynamically inserted or removed from a parent Group at runtime. In addition the root parent Group of the scenegraph must be a BranchGroup since only BranchGroups can be inserted into a Locale.


To allow a BranchGroup to be dynamically removed from its parent, the BranchGroup must have the BranchGroup.ALLOW_DETACH capability set. To allow a BranchGroup to be dynamically inserted (or attached) into a parent Group the Group must have the capability Group.ALLOW_CHILDREN_EXTEND. Why these capabilities have been divided between the Group and BranchGroup classes is not quite clear.


BranchGroups are typically used as return values by the methods that build the various components of an application scenegraph. For example, an F1 racing application might define the following abstract class:


abstract class F1Object extends Object

{

BranchGroup m_BranchGroup = null;


public F1Object();

protected BranchGroup createBranchGroup();


public getBranchGroup()

{

if( m_BranchGroup == null ) m_BranchGroup = createBranchGroup();


return m_BranchGroup;

}

}


The F1Object abstract class forces the application developer to define the createBranchGroup virtual method in a derived class. The createBranchGroup method is responsible for creating a BranchGroup containing the child Nodes required to define the Geometry and Behaviors for the F1Object being created. This very simple OO design allows an F1Object Manager class to be defined that maintains a Vector (or List or Map) of generic F1Objects and is responsible for their creation and removal from the applications scenegraph. The objects derived from F1Object are themselves easily reusable because their geometry generation and management routines are all packages with the class itself. The setUserData method (defined in the section on Group Nodes) can be used to track F1Object instances once they have been inserted into the scenegraph.