# Palomino - Graph Module

©2004,2009 Jim E. Brooks http://www.palomino3d.org

- Index
- Overview
- SceneGraph
- Graph
- Subgraph
- State-Sorting (NodeSort)
- Visitors
- ModelCache

## Overview

[2008/02]

There are 3 levels of graph classes: SceneGraph, Graph, Subgraph.
These are Facade classes that abstract the exact arrangement of nodes.

## SceneGraph

[2009/01]

                         +------------+
                         | root node  |
                     +---+------------+--+
                     |        |          |
                     |        |          |
              +--------+  +--------+  +--------+
              | branch |  | branch |  | branch |
              |  node  |  |  node  |  |  node  |
              | default|  |  [1]   |  |  [2]   |
              +--------+  +--------+  +--------+

This arrangement circumvents OSG's rule of allowing child nodes to override similar state of its parent which wouldn't be restored after traversal crosses over to a sibling node.

The SceneGraph should be partitioned into branches. Branch nodes are group nodes with different graphical states. Most 3D Objects can be attached using `SceneGraph::AttachNode()` which attach under the branch node having a default state. Optionally, new special branch nodes can be attached using code>SceneGraph::AttachBranchNode(GroupNode) and the client can attach nodes directly to that special branch node.

### C++ Classes

SceneGraph is a singleton that provides the public interface.
SceneGraph _is_ a BaseSceneGraph and _has_ a ShadowSceneGraph.
Some base methods are overridden to fork operations to both.

## Graph

[2008/02]

The Graph class represents a per-Object graph (ObjectGraph would be its long name). A Graph is passed as an arg to Object ctor. Graph is a Facade over the implemented arrangement of OSG nodes.

### Graph May Have Two Transform Nodes

Graph ctor may be passed a transform node as the root node. However, the Graph class isn't aware of that fact, Graph ctor always proceeds to create a transform node and places under it the incoming root node. This allows, transparently to Graph, correcting the orientation of a 3D model prior to encapsulating it as a Graph object.

## Subgraph

[2008/02]

Subgraph defines a partition of a Graph. Subgraph is typically used to define parts of an aircraft's 3D model. Optionally, Subgraph can model a part that has a limited range of movement such as landing gear.

3D model files (.ac) typically name a part of a mesh. A Visitor is created to searche for a named node in a Graph, which becomes the root node of a Subgraph. A transform node is spliced in order to rotate the part.

## State-Sorting (NodeSort)

[2009/03]

To keep the scene-graph optimally sorted by state, the SceneGraph class has a set of branch nodes. Branch nodes are mapped a NodeSort value that defines specific graphical states (shader, no fog, etc). Object classes can override Object::GetNodeSort() to cause SceneGraph::AttachObject() to place them under the appropriate branch node.

## Visitors

[2007/12]

The Visitor design pattern is ideal for graphs. Extended Graph functionality is provided in the form of Visitor classes. This Visitor pattern keeps Graph class minimal. Graph can be extended by adding new Visitor classes (rather than adding new Graph methods or Graph derivatives).

## ModelCache

[2008/02]

ModelCache caches the results of osgDB::readNodeFile(). Sharing the same node saves enormous amounts of memory. A shared node has multiple parent nodes. The reason a 3D model can exist in multiple locations is because its shared node is placed under separate transform nodes.

Last modified: Sat Nov 7 14:50:04 CST 2009