Skip to main content.
  1. Composing scenegraph with Blender
    1. What is scenegraph?
    2. OSG fileformat
      1. Transform node
      2. Level of Detail node
      3. Proxy node
      4. Polygon offset node

Composing scenegraph with Blender

Here is the situation: There are 50 separate 3d-models that forms a city. Now we want to view them all at once with osgviewer. How to do it? We could make one huge file that includes all the houses: just append all models to a one file in Blender and export that. That will do if models were very simple but what if we also wanted to model some interiors? And how about scalability? If we needed other 50 buildings? So, it is obvious that there must be a better solution.

top

What is scenegraph?

There is a good introduction to scenegraph: http://www.realityprime.com/scenegraph.php

One definition could be this: Scenegraph is a computer (performance) friendly description of the 3D-world. This means that virtual world is formulated such way that it is possible to computer to make an optimal presentation of it from the current point of view.

With Blender and OSGExport you can produce simple scenegraphs. Simple here means the structure of the scenegraph, not the complexity of geometry. For example, you can not use LOD nodes or group nodes. Using those requires hand-editing and in order to do that one must know something about osg-fileformat.

top

OSG fileformat

Here is a simple osg-file (just a plane):

Geode {
UniqueID Cube_geode DataVariance DYNAMIC name "Cube_geode" cullingActive TRUE num_drawables 1 Geometry { StateSet { UniqueID Cube_stateset DataVariance STATIC rendering_hint OPAQUE_BIN GL_BLEND OFF Material { DataVariance STATIC ColorMode OFF diffuseColor 0.800000011921 0.800000011921 0.800000011921 1.0 specularColor 1.0 1.0 1.0 1.0 emissionColor 0.0 0.0 0.0 1.0 shininess 24.5960784314 } } VertexArray 4 { -1 0 1 -1 0 -1 1 0 -1 1 0 1 } NormalBinding PER_VERTEX NormalArray 4 { 0 -1 0 0 -1 0 0 -1 0 0 -1 0 } PrimitiveSets 1 { DrawElementsUInt QUADS 1 { 0 1 2 3 } } } }
top

Transform node

With transforms node it is possible to define location, rotation and scale of an object or objects. The last line in the following example defines transform in xyz-space (1, -3, 2).

MatrixTransform {
  StateSet { 0xba1 ON }
  Matrix {
    DataVariance DYNAMIC
    1.0 0.0 0.0 0.0
    0.0 1.0 0.0 0.0
    0.0 0.0 1.0 0.0
    1.0 -3.0 2.0 1.0
  }
  ... transformed objects ...
}

top

Level of Detail node

Maybe one of the most important nodes is the LOD-node. It makes possible very large and complex scenes that can be displayed in normal pc-environment.

This is how it looks:


LOD {
    UniqueID LOD_2
    DataVariance DYNAMIC
    name "lod2"
    nodeMask 0xffffffff
    cullingActive TRUE
    Radius -1
    RangeMode DISTANCE_FROM_EYE_POINT
    RangeList 2 {
      100 1000
      0 100
      0 40
    }
    num_children 3
    ... child objects ...
}

LOD-node is simple: values in the rangelist defines when child objects are displayed.

The first child of lod is displayed when distance from the viewer to lod is between 100 and 1000. Note that these values can overlap. The second and third child are both displayed when distance is less than 40. This is handy for example for buildings. You can have a separate stonebase that is displayed all the time and the body of the house is changed to more detailed one when user get near.

top

Proxy node

With proxy-node one can make a composition of separate files. It is like include statement in programming languages.

    ProxyNode {

        UniqueID ProxyNode_0
        DataVariance DYNAMIC
        nodeMask 0xffffffff
        cullingActive TRUE
        description "SizeNode1"
        Radius -1
        FileNameList 1 {
            house.osg
        }
        num_children 0
    } 
top

Polygon offset node