Click or drag to resize
DigitalRuneSceneNode Class
Represents an object in a 3D scene.
Inheritance Hierarchy
SystemObject
  DigitalRune.Graphics.SceneGraphSceneNode
    More...

Namespace: DigitalRune.Graphics.SceneGraph
Assembly: DigitalRune.Graphics (in DigitalRune.Graphics.dll) Version: 1.2.0.0 (1.2.1.14562)
Syntax
public class SceneNode : IGeometricObject, INamedObject, 
	IDisposable

The SceneNode type exposes the following members.

Constructors
  NameDescription
Public methodSceneNode
Initializes a new instance of the SceneNode class.
Top
Methods
  NameDescription
Public methodClone
Creates a new SceneNode that is a clone of the current instance (incl. all children).
Protected methodCloneCore
Makes the instance a clone (deep copy) of the specified SceneNode.
Protected methodCreateInstanceCore
When implemented in a derived class, creates a new instance of the SceneNode derived class.
Public methodDispose(Boolean)
Releases all resources used by the scene node and all descendant nodes.
Protected methodDispose(Boolean, Boolean)
Releases the unmanaged resources used by an instance of the SceneNode class and optionally releases the managed resources.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInvalidate
Invalidates this scene node and all children.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnParentChanged
Called when Parent was changed.
Protected methodOnPoseChanged
Raises the PoseChanged event.
Protected methodOnSceneChanged
Raises the SceneChanged event.
Protected methodOnShapeChanged
Raises the ShapeChanged event.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodClearLastPose
Clears the LastPoseWorld property of the current scene node (and its descendants).
(Defined by SceneHelper.)
Public Extension MethodClearLastScale
Clears the LastScaleWorld property of the current scene node (and its descendants).
(Defined by SceneHelper.)
Public Extension MethodContains
Determines whether whether a scene node contains another scene node in its subtree.
(Defined by SceneHelper.)
Public Extension MethodGetAncestors
Gets the ancestors of the given scene node.
(Defined by SceneHelper.)
Public Extension MethodGetChildren
Gets the children of the given scene node.
(Defined by SceneHelper.)
Public Extension MethodGetDescendantsOverloaded.
Gets the descendants of the given scene node using a depth-first search.
(Defined by SceneHelper.)
Public Extension MethodGetDescendants(Boolean)Overloaded.
Gets the descendants of the given scene node using a depth-first or a breadth-first search.
(Defined by SceneHelper.)
Public Extension MethodGetLeaves
Gets the leaves of the scene node.
(Defined by SceneHelper.)
Public Extension MethodGetRoot
Gets the root node.
(Defined by SceneHelper.)
Public Extension MethodGetSceneNode
Gets a scene node by name from the subtree of the specified scene node.
(Defined by SceneHelper.)
Public Extension MethodGetSelfAndAncestors
Gets the scene node and its ancestors scene.
(Defined by SceneHelper.)
Public Extension MethodGetSubtreeOverloaded.
Gets the subtree (the given scene node and all of its descendants) using a depth-first search.
(Defined by SceneHelper.)
Public Extension MethodGetSubtree(Boolean)Overloaded.
Gets the subtree (the given scene node and all of its descendants) using a depth-first or a breadth-first search.
(Defined by SceneHelper.)
Public Extension MethodGetSubtreeAabb
Gets the AABB of the current subtree.
(Defined by SceneHelper.)
Public Extension MethodLookAt(Vector3F, Vector3F)Overloaded.
Rotates the scene node so that it faces a certain direction (in world space).
(Defined by SceneHelper.)
Public Extension MethodLookAt(Vector3F, Vector3F, Vector3F)Overloaded.
Moves and rotates the scene node so that it faces a certain direction (in world space).
(Defined by SceneHelper.)
Public Extension MethodSetInstanceAlpha
Sets the opacity (alpha) of a scene node - see remarks.
(Defined by SceneHelper.)
Public Extension MethodSetLastPose
Sets LastPoseWorld to the current PoseWorld.
(Defined by SceneHelper.)
Public Extension MethodSetLastScale
Sets LastScaleWorld to the current ScaleWorld.
(Defined by SceneHelper.)
Public Extension MethodSupportsInstanceAlpha
Determines whether the opacity of the scene node can be changed using SetInstanceAlpha(SceneNode, Single).
(Defined by SceneHelper.)
Top
Properties
  NameDescription
Public propertyAabb
Gets the axis-aligned bounding box (AABB) in world space.
Public propertyActualIsEnabled
Gets a value indicating whether this scene node is actually enabled. (The method checks the current scene node and its ancestors.)
Public propertyCastsShadows
Gets or sets a value indicating whether this scene node blocks the light and casts shadows.
Public propertyChildren
Gets or sets the children of this scene node.
Public propertyIsDisposed
Gets a value indicating whether this scene node has been disposed of.
Public propertyIsEnabled
Gets or sets a value indicating whether this scene node is enabled. (May override children - see remarks.)
Public propertyIsRenderable
Gets or sets a value indicating whether this scene node can be rendered with a SceneNodeRenderer.
Public propertyIsShadowCasterCulled
Gets or sets a value indicating whether the occlusion culling determined that this scene node does not need to be rendered into the shadow map of the directional light.
Public propertyIsStatic
Gets or sets a value indicating whether this scene node is static (immobile).
Public propertyLastFrame
Gets or sets the number of the last frame in which the scene node was rendered.
Public propertyLastPoseWorld
Gets or sets the PoseWorld of the last frame.
Public propertyLastScaleWorld
Gets or sets the ScaleWorld of the last frame.
Public propertyMaxDistance
Gets or sets the maximum distance up to which the scene node is rendered. (Needs to be normalized - see remarks.)
Public propertyName
Gets or sets the name of this scene node.
Public propertyParent
Gets the parent scene node.
Public propertyPoseLocal
Gets or sets the pose (position and orientation) relative to the parent scene node.
Public propertyPoseWorld
Gets or sets the pose (position and orientation) in world space.
Public propertyProxy
Gets or sets the proxy node.
Public propertyRenderData
Gets or sets the cached renderer data.
Public propertyScaleLocal
Gets or sets the scale relative to the parent scene node.
Public propertyScaleWorld
Gets the total effective scale (which incorporates the scale factors of parent scene nodes).
Public propertySceneData
Gets or sets scene data.
Public propertyShape
Gets (or sets) the bounding shape of this scene node.
Public propertySortTag
Gets or sets the sort tag.
Public propertyUserData
Gets or sets user-defined data.
Public propertyUserFlags
Gets or sets a 16-bit value which can be used to store user-defined information or flags.
Top
Events
  NameDescription
Public eventSceneChanged
Occurs when the local subtree changed.
Public eventShapeChanged
Occurs when the Shape or ScaleWorld was changed.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate methodIDisposableDispose
Releases all resources used by the scene node and all descendant nodes.
Explicit interface implementationPrivate methodIGeometricObjectClone
Creates a new IGeometricObject that is a clone (deep copy) of the current instance.
Explicit interface implementationPrivate propertyIGeometricObjectPose
Gets the pose (position and orientation) in world space.
Explicit interface implementationPrivate eventIGeometricObjectPoseChanged
Occurs when the pose was changed.
Explicit interface implementationPrivate propertyIGeometricObjectScale
Gets the total effective scale (which incorporates the scale factors of parent scene nodes).
Top
Remarks

A SceneNode usually represents an instance of a graphics object in a 3D scene. See derived classes such as MeshNode, CameraNode, LightNode, etc.

A scene node can have a transformation (see ScaleLocal/PoseLocal, ScaleWorld/PoseWorld), a bounding shape (see Shape), a parent and children (see Parent, Children).

Scene Graph:
The scene node hierarchy, defined by the properties Parent and Children, is a tree (a graph without cycles). A scene node can only have zero or one parent - it cannot be the child of multiple other nodes. Scene nodes are attached to their parent: When the parent node is transformed (rotated or translated) in a scene, all descendant nodes move together with the parent node.

Local Transformation vs. World Transformation:
ScaleLocal and PoseLocal describe the local transformation of a node relative to its parent node. ScaleWorld and PoseWorld describe the absolute transformation of a node in world space.

The transformation can be set either in local space (using ScaleLocal and PoseLocal) or in world space (using PoseWorld). The other properties will be updated automatically. (Note: ScaleWorld cannot be set directly - the property is read-only.)

The local transformation is the dominant transformation: When a scene node is detached from its parent and attached to another scene node, it will be placed relative to the new parent. The local transformation will remain the same, but the world transformation will change - except when the parent's transformation is the identity transform.

Non-uniform Scaling:
Non-uniform scaling of scene nodes or subtrees is supported, but it should be used with care. Non-uniform scalings can be expensive because they require special treatment. (Imagine a scene node which has a bounding sphere. When the node is scaled non-uniformly, the sphere becomes an ellipsoid. An ellipsoid requires a different collision algorithm than a simple sphere...)

No Shearing:
Certain combinations of non-uniform scalings and rotations can create shear transformations. Shearing complicates the scene management and prevents certain optimizations. Shearing is therefore not supported! The scene graph automatically eliminates any shearing.

Transformation of Previous Frame:
A scene node additionally has two optional properties: LastScaleWorld and LastPoseWorld. These properties define the scene node's transformation of the last frame that was rendered. This information is required by certain effects, such as object motion blur or camera motion blur. Important: These properties are not set automatically! LastScaleWorld and LastPoseWorld need to be updated by the application logic whenever the transformation of the scene node is changed.

Bounding Shape:
The property Shape contains the bounding shape of the scene node. The bounding shape is used by the Scene for frustum culling and other optimizations. Be aware that the bounding shape of a scene node is not a hierarchical bounding shape. It defines only the bounds of the current node. The bounding shape does not include the bounds of the children!

The Shape can be set to Infinite. In this case the scene node is never culled during frustum culling and is always visible.

Some scene nodes have an Empty bounding shape. These scene nodes are ignored in scene queries. I.e. they do not show up in the query results! Newly created scene nodes have an Empty bounding shape. The Scene and ModelNode also have an Empty shape. (These types of nodes are just used to group other nodes in the scene graph. They can be ignored during rendering.)

The root of a scene hierarchy is usually the Scene. However, SceneNode objects can also be used independently from a Scene object. For example, when a ModelNode is loaded the model hierarchy is also defined as a tree of scene nodes. ModelNodes can be placed inside a Scene, but they can also be used and rendered independently from a Scene object.

Tree Traversal:
SceneHelper provides various helper methods to traverse the scene tree using LINQ: See GetRoot(SceneNode), GetAncestors(SceneNode), GetSelfAndAncestors(SceneNode), GetChildren(SceneNode), GetDescendants(SceneNode), GetSubtree(SceneNode), GetLeaves(SceneNode)

Cloning:
Scene nodes are cloneable. Clone makes a copy of the current scene node and recursively clones all children. The purpose of Clone is to replicate a single scene node or an entire tree of scene nodes in a scene. For example, by repeatedly calling Clone on a MeshNode multiple copies ("instances") of a Mesh object can be placed within a scene.

A scene node contains instance data, which is specific to a certain scene node object and shared data, which can be shared by multiple scene nodes. For example, a MeshNode contains MaterialInstances, which are unique for each mesh node, and a Mesh, which can be shared by multiple mesh nodes. By cloning a scene node all instance data is duplicated (deep copy), but the shared data is only copied by reference (shallow copy). So, when a MeshNode is cloned, the original and the cloned mesh node will have a unique set of material instances (MaterialInstances), but both will share the same Mesh.

Any object stored in UserData is copied per reference (shallow copy). SceneData and RenderData are never copied when the scene node is cloned.

Scene Node Sorting:
In many cases scene nodes need to be sorted. For example:

  • When rendering opaque objects the scene nodes need to be sorted front-to-back for efficient rendering.
  • When rendering transparent objects the scene nodes need to be sorted back-to-front for correct alpha transparency.
  • When multiple light shine on an object, it can be helpful to sort the lights by their light contribution in order to identify the lights that should be rendered.
  • Etc.
The property SortTag can be used for sorting scene nodes. For example, when sorting scene nodes by distance, the distance can be computed and stored in SortTag.

Scene Node Disposal (Potential Memory Leaks!)
Scene nodes implement IDisposable. The Dispose(Boolean) method should be called when the scene node is no longer needed. This is necessary in order to prevent potential memory leaks. Once the method has been called, the scene node is no longer usable. Reusing a previously disposed scene node may result in undefined behavior!

When calling Dispose(Boolean), the parameter determines whether data objects (such as vertex buffers, index buffers, etc.) are disposed or preserved. Disposing scene nodes including data objects can be dangerous because resources might be shared and still used by other scene nodes. It is therefore recommended to pass as parameter - unless it is certain that the resources are no longer needed.

Any data stored in RenderData, SceneData, or UserData is disposed together with the scene node.

See Also
Inheritance Hierarchy
SystemObject
  DigitalRune.Graphics.SceneGraphSceneNode
    DigitalRune.Graphics.SceneGraphBillboardNode
    DigitalRune.Graphics.SceneGraphCameraNode
    DigitalRune.Graphics.SceneGraphDecalNode
    DigitalRune.Graphics.SceneGraphFigureNode
    DigitalRune.Graphics.SceneGraphFogNode
    DigitalRune.Graphics.SceneGraphLensFlareNode
    DigitalRune.Graphics.SceneGraphLightNode
    DigitalRune.Graphics.SceneGraphLodGroupNode
    DigitalRune.Graphics.SceneGraphMeshNode
    DigitalRune.Graphics.SceneGraphModelNode
    DigitalRune.Graphics.SceneGraphOccluderNode
    DigitalRune.Graphics.SceneGraphParticleSystemNode
    DigitalRune.Graphics.SceneGraphRenderToTextureNode
    DigitalRune.Graphics.SceneGraphScene
    DigitalRune.Graphics.SceneGraphSkyNode
    DigitalRune.Graphics.SceneGraphSpriteNode
    DigitalRune.Graphics.SceneGraphTerrainNode
    DigitalRune.Graphics.SceneGraphWaterNode