|
1. Scene graph
The main type of structure used by X3DToolKit is the scene graph. Any 3D scene should
be represented by a scene graph.
a) Scene graph definition
fig 1: A typical example of a scene graph.
The scene graph is used to organize the objects of a scene into a hierarchy. Thus the
coordinates of the object A are transformed by the transformation T, whereas the
coordinates of the object C remain unchanged.
b) Nodes: graph elements divided into components
A scene graph is a set of nodes, which can have children.
Each node has a unique type (ex: Transform). Using an object-oriented conception,
a node is the instance of a class.
fig 2: A typical example of conception. The class D inherits the class C.
Besides the set of types is partitioned into components. In this example, the type D belongs to the com3
component.
2. Traversing and processing the scene graph
The main action in X3DToolKit is the traversal and the process of the scene graph. The
object which realizes the action is called a processor.
processor = walker + visitor
Traversal and visit are separated into distinct objects.
a) Walker
It is the traversal algorithm which is generally a DFS (depth first search) algorithm.
It calls the visitor for processing the nodes.
b) Visitor
This implementation of the visitor design pattern acts exclusively on the nodes.
The 3 different actions of the visitor are enter , leave and walkOn . walkOn indicates whether the
children have to be explored or not.
fig 3: An example illustrating the order of calls during a DFS traversal.
Recall that the set of nodes is partitioned into components. Each component is related
with a component visitor (different from a visitor!). The union of the different
component visitors creates the visitor (using a proxy design pattern) which groups
the visiting functions associated with the nodes of the component.
fig 4: the visitor holds the component visitors of the com1 and com3 component.
For example, we want to count the number of C in a scene graph. We only have to define the com1Visitor,
visitor of the com1 component with an enterC function that increases the number
of nodes.
When enter of the visitor is called by the walker, the visitor calls the appropriate
function of its component visitors. .
c) Double dispatching
The visiting functions can be defined for any node.
The schema shows which functions are actually applied when only some of them are
defined.
fig 6: The functions enter are defined for the nodes A, C and D. The type E inherits the function enter of the type C, whereas D redefines its
function enter.
The rule is simple: For a given processor, each node inherits the functions of the
node from which it derives.
d) State variables
During a traversal, it is possible to need to memorize informations (for example the
node stack) in order to use them in the visiting functions. The mechanism of state
variables ensures the unicity of the informations per processor.
3. X3D scene graph.
Naturally, the X3D scene graph is provided.
a) Loading an X3D scene graph from an x3d file
The loader is almost a processor, the walker is replaced by an xml parser and the
visitor is replaced by a creator which is very close.
4. Provided functionalities
The following scene graphs are provided:
a) GL
The GL scene graph is an image of the X3D scene graph, by including the nodes for which
a draw method can be defined in an openGL context. A processor called
GLBuilder converts the X3D scene graph to the GL scene graph.
b) MESH
The MESH scene graph is a simpler scene graph than the X3D one and contains lesser types
of nodes - Mesh and VertexSet are the principal nodes - thanks
to templates providing a fully customizable mesh structure. The processor MeshBuilder
converts an X3D scene graph to a MESH scene graph.
c) List of the existing processors
-
on the X3D scene graph:
-
BBoxUpdater : updates the bounding boxes of the X3D scene graph.
-
WorldCoordTranslator : translates all the coordinates of the objects of the X3D scene
graph to the world coordinates.
-
SceneSaver : saves the X3D scene graph to an x3d file.
-
GLBuilder : converts the X3D scene graph to the GL scene graph.
-
MeshBuilder : builds the template Mesh structure. Must be instantiated.
-
on the GL scene graph:
-
Updater : updates the content of the nodes of the GL scene graph.
-
Renderer : renders the GL scene graph.
-
on the MESH scene graph:
-
NormalsUpdater : updates the normals.
-
X3DBuilder : builds the X3D scene graph from a MESH scene graph. Must be instantiated.
|