User's Manual

66
Chapter 5: Building a Scene Graph
This chapter includes the following sections:
•“Creating Scene Graphs on page 66.
•“Diagramming Scene Graphs on page 69.
•“Altering Scene Graphs on page 73.
•“Loading a VRML Scene Graph on page 74.
•“Saving Scene Graphs on page 75.
•“Troubleshooting Scene Graph Construction on page 75.
Creating Scene Graphs
The top node in a scene graph is called the root node; it must be a group-type node.
Actions applied to the root node visit all of the children nodes of the root node.
To create a scene graph, you start with the root node and add children to it using the
csGroup::addChild() method, as follows:
root->addChild(myLight);
root->addChild(myShape);
In this simple example, the myLight node is added rst to the scene graph whose root
node is called root; the myShape node is added second. When a draw action is applied to
the root node, either of these nodes may be evaluated rst.
To complete the scene graph, you add children to any child nodes of the root node that
are a group-type. You continue adding children to group-type nodes until the complete
scene is encapsulated in the scene graph.
Root Node
Most scene graphs have a root node of type csGroup. If you have a one-node scene
graph, for example, a csShape node, which is a leaf node, then the root node, the only
node, is a leaf node.
It is also possible to have multiple root nodes for a scene graph, as shown in Figure 5-2.