com.jme.scene
Class SwitchNode

java.lang.Object
  extended by com.jme.scene.Spatial
      extended by com.jme.scene.Node
          extended by com.jme.scene.SwitchNode
All Implemented Interfaces:
Savable, java.io.Serializable
Direct Known Subclasses:
DiscreteLodNode

public class SwitchNode
extends Node

SwitchNode defines a node that maintains a single active child at a time. This allows the instantanious switching of children depending on any number of factors. For example, multiple levels of detail models can be loaded into the switch node and the active model can be set depending on the distance from the camera.

Version:
$Id: SwitchNode.java 4131 2009-03-19 20:15:28Z blaine.dev $
Author:
Mark Powell
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
static int SN_INVALID_CHILD
          defines an inactive or invalid child.
 
Fields inherited from class com.jme.scene.Node
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
SwitchNode()
           
SwitchNode(java.lang.String name)
          Constructor instantiates a new SwitchNode object.
 
Method Summary
 int attachChild(Spatial child)
          Attaches a child to this SwitchNode.
 int attachChildAt(Spatial child, int index)
          Attaches a child to this SwitchNode at a specified index.
 void disableAllChildren()
          Marks the node to render nothing on a draw.
 void draw(Renderer r)
          If a valid active child is set, that child is rendered and none others.
 void findCollisions(Spatial scene, CollisionResults results)
          collisions are checked for the currently active child.
 void findPick(Ray toTest, PickResults results)
          Tests a ray against this spatial, and stores the results in the result object.
 int getActiveChild()
          Returns the index of the currently rendered child for this Node.
 boolean hasCollision(Spatial scene, boolean checkTriangles)
          collisions are checked for the currently active child.
 void read(JMEImporter e)
           
 void setActiveChild(int child)
          Sets the index of the child of this Node that will be rendered.
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.Node
applyRenderState, childChange, detachAllChildren, detachChild, detachChildAt, detachChildNamed, getChild, getChild, getChildIndex, getChildren, getQuantity, getTriangleCount, getVertexCount, hasChild, lockBounds, lockMeshes, lockShadows, lockTransforms, setModelBound, sortLights, swapChildren, unlockBounds, unlockMeshes, unlockShadows, unlockTransforms, updateModelBound, updateWorldBound, updateWorldData, updateWorldVectors
 
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

SN_INVALID_CHILD

public static final int SN_INVALID_CHILD
defines an inactive or invalid child.

See Also:
Constant Field Values
Constructor Detail

SwitchNode

public SwitchNode()

SwitchNode

public SwitchNode(java.lang.String name)
Constructor instantiates a new SwitchNode object. The name of the node is provided during construction.

Parameters:
name - the name of the node.
Method Detail

getActiveChild

public int getActiveChild()
Returns the index of the currently rendered child for this Node.

Returns:
The currently active child.

setActiveChild

public void setActiveChild(int child)
Sets the index of the child of this Node that will be rendered. If the index is <0 or >getQuantity then nothing is rendered.

Parameters:
child - The child index of this node it should render.

disableAllChildren

public void disableAllChildren()
Marks the node to render nothing on a draw.


attachChild

public int attachChild(Spatial child)
Attaches a child to this SwitchNode. This child will not be visible unless it is set to the active child. It should be noted that the attachment of the child will set it to be non-collidable. Only active child are collidable using a SwitchNode.

Overrides:
attachChild in class Node
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)
Attaches a child to this SwitchNode at a specified index. This child will not be visible unless it is set to the active child. It should be noted that the attachment of the child will set it to be non-collidable. Only active child are collidable using a SwitchNode.

Overrides:
attachChildAt in class Node
Parameters:
child - the child to attach to this node.
Returns:
the number of children maintained by this node.

draw

public void draw(Renderer r)
If a valid active child is set, that child is rendered and none others. This function should be called internally only.

Overrides:
draw in class Node
Parameters:
r - The render system to draw the child.
See Also:
Spatial.draw(com.jme.renderer.Renderer)

findCollisions

public void findCollisions(Spatial scene,
                           CollisionResults results)
collisions are checked for the currently active child.

Overrides:
findCollisions in class Node
Parameters:
scene - the scene to test against.
results - the results of the collisions.

hasCollision

public boolean hasCollision(Spatial scene,
                            boolean checkTriangles)
collisions are checked for the currently active child.

Overrides:
hasCollision in class Node
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.

Overrides:
findPick in class Node
Parameters:
toTest - ray to test picking against
results - the results of the picking

write

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

read

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