com.jme.scene
Class Node

java.lang.Object
  extended by com.jme.scene.Spatial
      extended by com.jme.scene.Node
All Implemented Interfaces:
Savable, java.io.Serializable
Direct Known Subclasses:
Arrow, AxisRods, BillboardNode, Bone, CameraNode, ConnectionPoint, ImposterNode, LensFlare, LightNode, OgreEntityNode, ParticleSystem, PassNode, SharedNode, SimpleLightNode, SkinNode, Skybox, SwitchNode, TerrainPage, Transient

public class Node
extends Spatial
implements java.io.Serializable, Savable

Node defines an internal node of a scene graph. The internal node maintains a collection of children and handles merging said children into a single bound to allow for very fast culling of multiple nodes. Node allows for any number of children to be attached.

Author:
Mark Powell, Gregg Patton, Joshua Slack
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.scene.Spatial
Spatial.CullHint, Spatial.LightCombineMode, Spatial.NormalsMode, Spatial.TextureCombineMode
 
Field Summary
protected  java.util.List<Spatial> children
          This node's children.
 
Fields inherited from class com.jme.scene.Spatial
cullHint, frustrumIntersects, geometricalControllers, isCollidable, lightCombineMode, localRotation, localScale, localTranslation, LOCKED_BOUNDS, LOCKED_BRANCH, LOCKED_MESH_DATA, LOCKED_NONE, LOCKED_SHADOWS, LOCKED_TRANSFORMS, lockedMode, name, normalsMode, parent, queueDistance, renderQueueMode, renderStateList, textureCombineMode, worldBound, worldRotation, worldScale, worldTranslation, zOrder
 
Constructor Summary
Node()
          Default constructor.
Node(java.lang.String name)
          Constructor instantiates a new Node with a default empty list for containing children.
 
Method Summary
protected  void applyRenderState(java.util.Stack<? extends RenderState>[] states)
          Applies the stack of render states to each child by calling updateRenderState(states) on each child.
 int attachChild(Spatial child)
          attachChild attaches a child to this node.
 int attachChildAt(Spatial child, int index)
          attachChildAt attaches a child to this node at an index.
 void childChange(Geometry geometry, int index1, int index2)
           
 void detachAllChildren()
          detachAllChildren removes all children attached to this node.
 int detachChild(Spatial child)
          detachChild removes a given child from the node's list.
 Spatial detachChildAt(int index)
          detachChildAt removes a child at a given index.
 int detachChildNamed(java.lang.String childName)
          detachChild removes a given child from the node's list.
 void draw(Renderer r)
          draw calls the onDraw method for each child maintained by this node.
 void findCollisions(Spatial scene, CollisionResults results)
          checks this spatial against a second spatial, any collisions are stored in the results object.
 void findPick(Ray toTest, PickResults results)
          Tests a ray against this spatial, and stores the results in the result object.
 Spatial getChild(int i)
          getChild returns a child at a given index.
 Spatial getChild(java.lang.String name)
          getChild returns the first child found with exactly the given name (case sensitive.)
 int getChildIndex(Spatial sp)
           
 java.util.List<Spatial> getChildren()
          Returns all children to this node.
 int getQuantity()
          getQuantity returns the number of children this node maintains.
 int getTriangleCount()
          getTriangleCount returns the number of triangles contained in all sub-branches of this node that contain geometry.
 int getVertexCount()
          getVertexCount returns the number of vertices contained in all sub-branches of this node that contain geometry.
 boolean hasChild(Spatial spat)
          determines if the provided Spatial is contained in the children list of this node.
 boolean hasCollision(Spatial scene, boolean checkTriangles)
          Checks this spatial against a second spatial for collisions.
 void lockBounds()
          Calling this method tells the scenegraph that it is not necessary to update bounds from this point in the scenegraph on down to the leaves.
 void lockMeshes(Renderer r)
          Flags this spatial and those below it that any meshes in the specified scenegraph location or lower will not have changes in vertex, texcoord, normal or color data.
 void lockShadows()
          Calling this method tells the scenegraph that it is not necessary to update Shadow volumes that may be associated with this Spatial.
 void lockTransforms()
          Flags this spatial and those below it in the scenegraph to not recalculate world transforms such as translation, rotation and scale on every update.
 void read(JMEImporter e)
           
 void setModelBound(BoundingVolume modelBound)
          setModelBound sets the bounding object for this Spatial.
 void sortLights()
           
 void swapChildren(int index1, int index2)
           
 void unlockBounds()
          Flags this spatial and those below it to allow for bounds updating (the default).
 void unlockMeshes(Renderer r)
          Flags this spatial and those below it to allow for mesh updating (the default).
 void unlockShadows()
          Flags this spatial and those below it to allow for shadow volume updates (the default).
 void unlockTransforms()
          Flags this spatial and those below it to allow for transform updating (the default).
 void updateModelBound()
          updateBound recalculates the bounding object for this Spatial.
 void updateWorldBound()
          updateWorldBound merges the bounds of all the children maintained by this node.
 void updateWorldData(float time)
          updateWorldData updates all the children maintained by this node.
 void updateWorldVectors(boolean recurse)
          If not locked, updates worldscale, worldrotation and worldtranslation
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.Spatial
addController, calculateCollisions, calculatePick, clearControllers, clearRenderState, clearRenderState, getClassTag, getController, getControllerCount, getControllers, getCullHint, getLastFrustumIntersection, getLightCombineMode, getLocalCullHint, getLocalLightCombineMode, getLocalNormalsMode, getLocalRenderQueueMode, getLocalRotation, getLocalScale, getLocalTextureCombineMode, getLocalToWorldMatrix, getLocalTranslation, getLocks, getName, getNormalsMode, getParent, getRenderQueueMode, getRenderState, getRenderState, getTextureCombineMode, getUserData, getWorldBound, getWorldRotation, getWorldScale, getWorldTranslation, getZOrder, hasAncestor, isCollidable, localToWorld, lock, lock, lockBranch, lockMeshes, lookAt, onDraw, propagateBoundToRoot, propagateStatesFromRoot, removeController, removeController, removeFromParent, removeUserData, rotateUpTo, setCullHint, setIsCollidable, setLastFrustumIntersection, setLightCombineMode, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setLocalTranslation, setLocks, setLocks, setName, setNormalsMode, setParent, setRenderQueueMode, setRenderState, setTextureCombineMode, setUserData, setZOrder, setZOrder, toString, unlock, unlock, unlockBranch, unlockMeshes, updateGeometricState, updateRenderState, updateRenderState, updateWorldRotation, updateWorldScale, updateWorldTranslation, updateWorldVectors, worldToLocal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jme.util.export.Savable
getClassTag
 

Field Detail

children

protected java.util.List<Spatial> children
This node's children.

Constructor Detail

Node

public Node()
Default constructor.


Node

public Node(java.lang.String name)
Constructor instantiates a new Node with a default empty list for containing children.

Parameters:
name - the name of the scene element. This is required for identification and comparision purposes.
Method Detail

getQuantity

public int getQuantity()
getQuantity returns the number of children this node maintains.

Returns:
the number of children this node maintains.

getTriangleCount

public int getTriangleCount()
getTriangleCount returns the number of triangles contained in all sub-branches of this node that contain geometry.

Specified by:
getTriangleCount in class Spatial
Returns:
the triangle count of this branch.

getVertexCount

public int getVertexCount()
getVertexCount returns the number of vertices contained in all sub-branches of this node that contain geometry.

Specified by:
getVertexCount in class Spatial
Returns:
the vertex count of this branch.

attachChild

public int attachChild(Spatial child)
attachChild attaches a child to this node. This node becomes the child's parent. The current number of children maintained is returned.
If the child already had a parent it is detached from that former parent.

Parameters:
child - the child to attach to this node.
Returns:
the number of children maintained by this node.

attachChildAt

public int attachChildAt(Spatial child,
                         int index)
attachChildAt attaches a child to this node at an index. This node becomes the child's parent. The current number of children maintained is returned.
If the child already had a parent it is detached from that former parent.

Parameters:
child - the child to attach to this node.
Returns:
the number of children maintained by this node.

detachChild

public int detachChild(Spatial child)
detachChild removes a given child from the node's list. This child will no longe be maintained.

Parameters:
child - the child to remove.
Returns:
the index the child was at. -1 if the child was not in the list.

detachChildNamed

public int detachChildNamed(java.lang.String childName)
detachChild removes a given child from the node's list. This child will no longe be maintained. Only the first child with a matching name is removed.

Parameters:
childName - the child to remove.
Returns:
the index the child was at. -1 if the child was not in the list.

detachChildAt

public Spatial detachChildAt(int index)
detachChildAt removes a child at a given index. That child is returned for saving purposes.

Parameters:
index - the index of the child to be removed.
Returns:
the child at the supplied index.

detachAllChildren

public void detachAllChildren()
detachAllChildren removes all children attached to this node.


getChildIndex

public int getChildIndex(Spatial sp)

swapChildren

public void swapChildren(int index1,
                         int index2)

getChild

public Spatial getChild(int i)
getChild returns a child at a given index.

Parameters:
i - the index to retrieve the child from.
Returns:
the child at a specified index.

getChild

public Spatial getChild(java.lang.String name)
getChild returns the first child found with exactly the given name (case sensitive.)

Parameters:
name - the name of the child to retrieve. If null, we'll return null.
Returns:
the child if found, or null.

hasChild

public boolean hasChild(Spatial spat)
determines if the provided Spatial is contained in the children list of this node.

Parameters:
spat - the child object to look for.
Returns:
true if the object is contained, false otherwise.

updateWorldData

public void updateWorldData(float time)
updateWorldData updates all the children maintained by this node.

Overrides:
updateWorldData in class Spatial
Parameters:
time - the frame time.

updateWorldVectors

public void updateWorldVectors(boolean recurse)
Description copied from class: Spatial
If not locked, updates worldscale, worldrotation and worldtranslation

Overrides:
updateWorldVectors in class Spatial
Parameters:
recurse - usually false when updating the tree. Set to true when you just want to update the world transforms for a branch without updating geometric state.

lockBounds

public void lockBounds()
Description copied from class: Spatial
Calling this method tells the scenegraph that it is not necessary to update bounds from this point in the scenegraph on down to the leaves. This is useful for performance gains where you have scene items that do not move (at all) or change shape and thus do not need constant re-calculation of boundaries. When you call lock, the bounds are first updated to ensure current bounds are accurate.

Overrides:
lockBounds in class Spatial
See Also:
Spatial.unlockBounds()

lockShadows

public void lockShadows()
Description copied from class: Spatial
Calling this method tells the scenegraph that it is not necessary to update Shadow volumes that may be associated with this Spatial. This is useful for skipping various checks for spatial transformation when deciding whether or not to recalc a shadow volume for a Spatial.

Overrides:
lockShadows in class Spatial
See Also:
Spatial.unlockShadows()

lockTransforms

public void lockTransforms()
Description copied from class: Spatial
Flags this spatial and those below it in the scenegraph to not recalculate world transforms such as translation, rotation and scale on every update. This is useful for efficiency when you have scene items that stay in one place all the time as it avoids needless recalculation of transforms.

Overrides:
lockTransforms in class Spatial
See Also:
Spatial.unlockTransforms()

lockMeshes

public void lockMeshes(Renderer r)
Description copied from class: Spatial
Flags this spatial and those below it that any meshes in the specified scenegraph location or lower will not have changes in vertex, texcoord, normal or color data. This allows optimizations by the engine such as creating display lists from the data. Calling this method does not provide a guarentee that data changes will not be allowed or will/won't show up in the scene. It is merely a hint to the engine.

Overrides:
lockMeshes in class Spatial
Parameters:
r - A renderer to lock against.
See Also:
Spatial.unlockMeshes(Renderer)

unlockBounds

public void unlockBounds()
Description copied from class: Spatial
Flags this spatial and those below it to allow for bounds updating (the default).

Overrides:
unlockBounds in class Spatial
See Also:
Spatial.lockBounds()

unlockShadows

public void unlockShadows()
Description copied from class: Spatial
Flags this spatial and those below it to allow for shadow volume updates (the default).

Overrides:
unlockShadows in class Spatial
See Also:
Spatial.lockShadows()

unlockTransforms

public void unlockTransforms()
Description copied from class: Spatial
Flags this spatial and those below it to allow for transform updating (the default).

Overrides:
unlockTransforms in class Spatial
See Also:
Spatial.lockTransforms()

unlockMeshes

public void unlockMeshes(Renderer r)
Description copied from class: Spatial
Flags this spatial and those below it to allow for mesh updating (the default). Generally this means that any display lists setup will be erased and released.

Overrides:
unlockMeshes in class Spatial
Parameters:
r - The renderer used to lock against.
See Also:
Spatial.lockMeshes(Renderer)

draw

public void draw(Renderer r)
draw calls the onDraw method for each child maintained by this node.

Specified by:
draw in class Spatial
Parameters:
r - the renderer to draw to.
See Also:
Spatial.draw(com.jme.renderer.Renderer)

applyRenderState

protected void applyRenderState(java.util.Stack<? extends RenderState>[] states)
Applies the stack of render states to each child by calling updateRenderState(states) on each child.

Overrides:
applyRenderState in class Spatial
Parameters:
states - The Stack[] of render states to apply to each child.

sortLights

public void sortLights()
Overrides:
sortLights in class Spatial

updateWorldBound

public void updateWorldBound()
updateWorldBound merges the bounds of all the children maintained by this node. This will allow for faster culling operations.

Specified by:
updateWorldBound in class Spatial
See Also:
Spatial.updateWorldBound()

findCollisions

public void findCollisions(Spatial scene,
                           CollisionResults results)
Description copied from class: Spatial
checks this spatial against a second spatial, any collisions are stored in the results object.

Specified by:
findCollisions in class Spatial
Parameters:
scene - the scene to test against.
results - the results of the collisions.

hasCollision

public boolean hasCollision(Spatial scene,
                            boolean checkTriangles)
Description copied from class: Spatial
Checks this spatial against a second spatial for collisions.

Specified by:
hasCollision in class Spatial
Parameters:
scene - the scene to test against.
checkTriangles - check for collisions on triangle accuracy level
Returns:
true if any collision were found

findPick

public void findPick(Ray toTest,
                     PickResults results)
Description copied from class: Spatial
Tests a ray against this spatial, and stores the results in the result object.

Specified by:
findPick in class Spatial
Parameters:
toTest - ray to test picking against
results - the results of the picking

getChildren

public java.util.List<Spatial> getChildren()
Returns all children to this node.

Returns:
a list containing all children to this node

childChange

public void childChange(Geometry geometry,
                        int index1,
                        int index2)

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class Spatial
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class Spatial
Throws:
java.io.IOException

setModelBound

public void setModelBound(BoundingVolume modelBound)
Description copied from class: Spatial
setModelBound sets the bounding object for this Spatial.

Specified by:
setModelBound in class Spatial
Parameters:
modelBound - the bounding object for this spatial.

updateModelBound

public void updateModelBound()
Description copied from class: Spatial
updateBound recalculates the bounding object for this Spatial.

Specified by:
updateModelBound in class Spatial