Nodes in a scene graph can be categorized into three basic types: Content nodes, state nodes, and procedural nodes. Today's topic is the content category, which consists essentially of geometry nodes. There are three basic methods for adding geometry nodes to a scene graph: load the geometry from a file, build the geometry on the fly, or "instance" (reference) an existing geometry.Loading Geometry From a File
WorldToolKit can load geometry information from files using three primary functions:
- WTnode_load
- WTmovnode_load
- WTgeometrynode_load
All three take the same type of arguments, read the same types of files, and return the same type of result. All three add a geometry node to the scene graph, ( unless the parent is specified as NULL. )
The distinction is that WTgeometry node_load always creates a single non-movable geometry node regardless of the data in the file; WTnode_load creates one or more non-movable geometry nodes, depending upon the data in the file, and WTmovnode_load creates a movable node, consisting of a separator node, a transform node, and a geometry node. See pages 6-2 and following for information regarding the file types supported by WorldToolKit, and the limitations thereof.
Building Geometry on the Fly
WorldToolKit can build geometry on the fly using two different methods. Note, however, that neither method adds a node to the scene graph. These methods only produce a geometry, which must then be added to the scene graph with WTgeometrynode_new.
The easiest and most straightforward method is the set of routines for creating standard shapes ( aka predefined geometries ). See pages 6-14 to 6-21 for more information.
- WTgeometry_newblock
- WTgeometry_newcylinder
- WTgeometry_newcone
- WTgeometry_newsphere
- WTgeometry_newhemisphere
- WTgeometry_newrectangle
- WTgeometry_newtruncone
- WTgeometry_newextrusion
- WTgeometry_newtext3d
The other method for creating geometries on the fly is to create custom geometries, as described on page 6-21 and following. We will not concern ourselves with this method at this time.
Instancing ( Referencing ) an Existing Movable Node
There are many cases in which it is desirable to have multiple copies of a single geometry - trees in a forest, books on a bookshelf, wheels on a car. In each of these cases the original geometry may be large and complex, and there is no good reason to store multiple copies in memory. However it is important that each instance of the object have its own transformation information, since the objects must be in different locations. WorldToolKit therefore has a mechanism whereby multiple movable nodes can share pointers to a common geometry. This is arranged using the function
- WTmovnode_instance
This function will effectively "copy" a movable node, creating new separator and transform nodes. However instead of creating a copy of the geometry, the new node will contain a link (pointer) to the existing geometry from the original source node.