Examining a Model's Scene Graph
After loading the model, WrapLoaderInfo3D's next main task is to traverse the model's scene graph and report on its structure. Walking over the graph is easy due to the parent-child relationship between the nodes and that all the nodes are subclasses of a single superclass, SceneGraphObject
. A simplified inheritance hierarchy is shown in Figure 16-8.
As mentioned in Chapter 14, Leaf nodes are subclassed in various ways to obtain Shape3D and environment nodes for lighting, backgrounds, sound, and so on. The subclasses of Group include BranchGroup and TransformGroup, which may have their own children (Group and/or Leaf nodes). NodeComponent objects are used to store information in nodes, such as Geometry and Appearance attributes, and may be shared between nodes.

Figure 16-8. Some subclasses of SceneGraphObject
A simple algorithm for traversing a scene graph is shown here:
examineNode(node) {
if the node is a Group {
print Group info;
for each child of the node
examineNode(child); // recursive call
}
else if the node is a Leaf
if the node is a Shape3D {
examine its appearance;
examine its geometry;
}
else print Leaf info
}
else print general node info;
}This pseudocode is the heart of the examineNode() and examineShape3D() methods in WrapLoaderInfo3D. The algorithm is simplified by concentrating on a few node types, principally Shape3D, and by considering ...