com.jme.scene
Class Spatial

java.lang.Object
  extended bycom.jme.scene.Spatial
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Geometry, Node, WidgetAbstractImpl

public abstract class Spatial
extends java.lang.Object
implements java.io.Serializable

Spatial defines the base class for scene graph nodes. It maintains a link to a parent, it's local transforms and the world's transforms. All other nodes, such as Node and Geometry are subclasses of Spatial.

Version:
$Id: Spatial.java,v 1.63 2005/03/01 00:21:39 renanse Exp $
Author:
Mark Powell
See Also:
Serialized Form

Field Summary
protected static RenderState[] currentStates
          RenderStates a Spatial contains during rendering.
static RenderState[] defaultStateList
          List of default states all spatials take if none is set.
protected  boolean forceCull
          If true, spatial and all children are culled from the scene graph.
protected  boolean forceView
          If true, spatial and all children are always rendered in the scene graph.
protected  int frustrumIntersects
           
protected  java.util.ArrayList geometricalControllers
          ArrayList of controllers for this spatial.
protected  int lightCombineMode
          Flag signaling how lights are combined for this node.
protected  Quaternion localRotation
          Spatial's rotation relative to its parent.
protected  Vector3f localScale
          Spatial's scale relative to its parent.
protected  Vector3f localTranslation
          Spatial's translation relative to its parent.
protected  java.lang.String name
          This spatial's name.
protected  Node parent
          Spatial's parent, or null if it has none.
 float queueDistance
           
protected  int renderQueueMode
           
protected  RenderState[] renderStateList
          The render states of this spatial.
protected  int textureCombineMode
          Flag signaling how textures are combined for this node.
protected  BoundingVolume worldBound
          Spatial's bounding volume relative to the world.
protected  Quaternion worldRotation
          Spatial's world absolute rotation.
protected  Vector3f worldScale
          Spatial's world absolute scale.
protected  Vector3f worldTranslation
          Spatial's world absolute translation.
protected  int zOrder
           
 
Constructor Summary
Spatial()
          Empty Constructor to be used internally only.
Spatial(java.lang.String name)
          Constructor instantiates a new Spatial object setting the rotation, translation and scale value to defaults.
 
Method Summary
 void addController(Controller controller)
          Adds a Controller to this Spatial's list of controllers.
static void applyDefaultStates()
          All non null default states are applied to the renderer.
protected  void applyRenderState(java.util.Stack[] states)
          Called during updateRenderState(Stack[]), this function determines how the render states are actually applied to the spatial and any children it may have.
 void calculateCollisions(Spatial scene, CollisionResults results)
          calculateCollisions calls findCollisions to populate the CollisionResults object then processes the collision results.
 void calculatePick(Ray ray, PickResults results)
           
static void clearCurrentState(int state)
          clears the specified state.
static void clearCurrentStates()
          sets all current states to null, and therefore forces the use of the default states.
 void clearRenderState(int renderStateType)
          Clears a given render state index by setting it to 0.
abstract  void draw(Renderer r)
          draw abstract method that handles drawing data to the renderer if it is geometry and passing the call to it's children if it is a node.
abstract  void drawBounds(Renderer r)
          drawBounds abstract method that handles drawing bounds data to the renderer if it is geometry and passing the call to it's children if it is a node.
abstract  void findCollisions(Spatial scene, CollisionResults results)
          checks this spatial against a second spatial, any collisions are stored in the results object.
abstract  void findPick(Ray toTest, PickResults results)
           
 Controller getController(int i)
          Returns the controller in this list of controllers at index i.
 java.util.ArrayList getControllers()
          Returns the ArrayList that contains this spatial's Controllers.
static RenderState getCurrentState(int state)
           
 int getLastFrustumIntersection()
          Returns this spatial's last frustum intersection result.
 int getLightCombineMode()
          Returns this spatial's light combine mode.
 Quaternion getLocalRotation()
          getLocalRotation retrieves the local rotation of this node.
 Vector3f getLocalScale()
          getLocalScale retrieves the local scale of this node.
 Vector3f getLocalTranslation()
          getLocalTranslation retrieves the local translation of this node.
 java.lang.String getName()
          Returns the name of this spatial.
 Node getParent()
          getParent retrieve's this node's parent.
 int getRenderQueueMode()
           
 RenderState[] getRenderStateList()
          Returns the array of RenerState that this Spatial currently has.
 int getTextureCombineMode()
          Returns this spatial's texture combine mode.
 BoundingVolume getWorldBound()
          getWorldBound retrieves the world bound at this node level.
 Quaternion getWorldRotation()
          getWorldRotation retrieves the absolute rotation of the Spatial.
 Vector3f getWorldScale()
          getWorldScale retrieves the absolute scale factor of the spatial.
 Vector3f getWorldTranslation()
          getWorldTranslation retrieves the absolute translation of the spatial.
 int getZOrder()
           
abstract  boolean hasCollision(Spatial scene, boolean checkTriangles)
           
 boolean isForceCulled()
          isForceCulled reports if this node should always be culled or not.
 boolean isForceView()
          isForceView returns true if the node will be rendered whether it's in the camera frustum or not.
 void onDraw(Renderer r)
          onDraw checks the node with the camera to see if it should be culled, if not, the node's draw method is called.
 void onDrawBounds(Renderer r)
          onDrawBounds checks the node with the camera to see if it should be culled, if not, the node's draw method is called.
 void propagateBoundToRoot()
          propagateBoundToRoot passes the new world bound up the tree to the root.
protected  void propagateStatesFromRoot(java.util.Stack[] states)
          Called during updateRenderState(Stack[]), this function goes up the scene graph tree until the parent is null and pushes RenderStates onto the states Stack array.
 Spatial putClone(Spatial store, CloneCreator properties)
           
 boolean removeController(Controller controller)
          Removes a Controller to this Spatial's list of controllers, if it exist.
 boolean removeFromParent()
          removeFromParent removes this Spatial from it's parent.
 void setForceCull(boolean forceCull)
          setForceCull sets if this node should always be culled or not.
abstract  void setForceView(boolean value)
          setForceView will force the node to be rendered whether it's in the camera frustum or not.
 void setLightCombineMode(int lightCombineMode)
          Sets how lights from parents should be combined for this spatial.
 void setLocalRotation(Matrix3f rotation)
          setLocalRotation sets the local rotation of this node.
 void setLocalRotation(Quaternion quaternion)
          setLocalRotation sets the local rotation of this node, using a quaterion to build the matrix.
 void setLocalScale(float localScale)
          setLocalScale sets the local scale of this node.
 void setLocalScale(Vector3f localScale)
          setLocalScale sets the local scale of this node.
 void setLocalTranslation(Vector3f localTranslation)
          setLocalTranslation sets the local translation of this node.
 void setName(java.lang.String name)
          Sets the name of this spatial.
 void setParent(Node parent)
          setParent sets the parent of this node.
 void setRenderQueueMode(int renderQueueMode)
           
 RenderState setRenderState(RenderState rs)
          setRenderState sets a render state for this node.
 void setTextureCombineMode(int textureCombineMode)
          Sets how textures from parents should be combined for this Spatial.
 void setWorldBound(BoundingVolume worldBound)
          setWorldBound sets the world bound for this node level.
 void setZOrder(int zOrder)
           
 java.lang.String toString()
          Returns the Spatial's name followed by the class of the spatial
Example: "MyNode (com.jme.scene.Spatial)
 void updateCollisionTree()
          This method updates the exact bounding tree of any this Spatial.
 void updateGeometricState(float time, boolean initiator)
          updateGeometricState updates all the geometry information for the node.
 void updateRenderState()
          Updates the render state values of this Spatial and and children it has.
protected  void updateRenderState(java.util.Stack[] parentStates)
          Called internally.
abstract  void updateWorldBound()
          updateWorldBound updates the bounding volume of the world.
protected  void updateWorldData(float time)
          updateWorldData updates the world transforms from the parent down to the leaf.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

localRotation

protected Quaternion localRotation
Spatial's rotation relative to its parent.


worldRotation

protected Quaternion worldRotation
Spatial's world absolute rotation.


localTranslation

protected Vector3f localTranslation
Spatial's translation relative to its parent.


worldTranslation

protected Vector3f worldTranslation
Spatial's world absolute translation.


localScale

protected Vector3f localScale
Spatial's scale relative to its parent.


worldScale

protected Vector3f worldScale
Spatial's world absolute scale.


forceCull

protected boolean forceCull
If true, spatial and all children are culled from the scene graph.


forceView

protected boolean forceView
If true, spatial and all children are always rendered in the scene graph.


worldBound

protected BoundingVolume worldBound
Spatial's bounding volume relative to the world.


parent

protected transient Node parent
Spatial's parent, or null if it has none.


defaultStateList

public static RenderState[] defaultStateList
List of default states all spatials take if none is set.


currentStates

protected static RenderState[] currentStates
RenderStates a Spatial contains during rendering.


renderStateList

protected RenderState[] renderStateList
The render states of this spatial.


renderQueueMode

protected int renderQueueMode

zOrder

protected int zOrder

queueDistance

public transient float queueDistance

lightCombineMode

protected int lightCombineMode
Flag signaling how lights are combined for this node. By default set to INHERIT.


textureCombineMode

protected int textureCombineMode
Flag signaling how textures are combined for this node. By default set to INHERIT.


geometricalControllers

protected java.util.ArrayList geometricalControllers
ArrayList of controllers for this spatial.


name

protected java.lang.String name
This spatial's name.


frustrumIntersects

protected int frustrumIntersects
Constructor Detail

Spatial

public Spatial()
Empty Constructor to be used internally only.


Spatial

public Spatial(java.lang.String name)
Constructor instantiates a new Spatial object setting the rotation, translation and scale value to defaults.

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

setName

public void setName(java.lang.String name)
Sets the name of this spatial.

Parameters:
name - The spatial's new name.

getName

public java.lang.String getName()
Returns the name of this spatial.

Returns:
This spatial's name.

addController

public void addController(Controller controller)
Adds a Controller to this Spatial's list of controllers.

Parameters:
controller - The Controller to add
See Also:
Controller

removeController

public boolean removeController(Controller controller)
Removes a Controller to this Spatial's list of controllers, if it exist.

Parameters:
controller - The Controller to remove
Returns:
True if the Controller was in the list to remove.
See Also:
Controller

getController

public Controller getController(int i)
Returns the controller in this list of controllers at index i.

Parameters:
i - The index to get a controller from.
Returns:
The controller at index i.
See Also:
Controller

getControllers

public java.util.ArrayList getControllers()
Returns the ArrayList that contains this spatial's Controllers.

Returns:
This spatial's geometricalControllers.

getWorldBound

public BoundingVolume getWorldBound()
getWorldBound retrieves the world bound at this node level.

Returns:
the world bound at this level.

setWorldBound

public void setWorldBound(BoundingVolume worldBound)
setWorldBound sets the world bound for this node level. This function should only be used in rare situations. In most cases, users will let jME's engine set the world bound and will instead call setModelBound on the leaf nodes.

Parameters:
worldBound - the world bound at this level.
See Also:
Geometry.setModelBound(com.jme.bounding.BoundingVolume)

onDraw

public void onDraw(Renderer r)
onDraw checks the node with the camera to see if it should be culled, if not, the node's draw method is called.

Parameters:
r - the renderer used for display.

onDrawBounds

public void onDrawBounds(Renderer r)
onDrawBounds checks the node with the camera to see if it should be culled, if not, the node's draw method is called.

Parameters:
r - the renderer used for display.

draw

public abstract void draw(Renderer r)
draw abstract method that handles drawing data to the renderer if it is geometry and passing the call to it's children if it is a node.

Parameters:
r - the renderer used for display.

drawBounds

public abstract void drawBounds(Renderer r)
drawBounds abstract method that handles drawing bounds data to the renderer if it is geometry and passing the call to it's children if it is a node.

Parameters:
r - the renderer used for display.

getWorldRotation

public Quaternion getWorldRotation()
getWorldRotation retrieves the absolute rotation of the Spatial.

Returns:
the Spatial's world rotation matrix.

getWorldTranslation

public Vector3f getWorldTranslation()
getWorldTranslation retrieves the absolute translation of the spatial.

Returns:
the world's tranlsation vector.

getWorldScale

public Vector3f getWorldScale()
getWorldScale retrieves the absolute scale factor of the spatial.

Returns:
the world's scale factor.

isForceCulled

public boolean isForceCulled()
isForceCulled reports if this node should always be culled or not. If true, this node will not be displayed.

Returns:
true if this node should never be displayed, false otherwise.

isForceView

public boolean isForceView()
isForceView returns true if the node will be rendered whether it's in the camera frustum or not.

Returns:
true if viewing is forced, false otherwise.

setForceCull

public void setForceCull(boolean forceCull)
setForceCull sets if this node should always be culled or not. True will always cull the node, false will allow proper culling to take place. NOTE: You must set this AFTER attaching to a parent or it will be reset with the parent's forceCull value.

Parameters:
forceCull - the value for forcing a culling.

setForceView

public abstract void setForceView(boolean value)
setForceView will force the node to be rendered whether it's in the camera frustum or not.

Parameters:
value - true to force viewing, false otherwise.

updateGeometricState

public void updateGeometricState(float time,
                                 boolean initiator)
updateGeometricState updates all the geometry information for the node.

Parameters:
time - the frame time.
initiator - true if this node started the update process.

updateWorldData

protected void updateWorldData(float time)
updateWorldData updates the world transforms from the parent down to the leaf.

Parameters:
time - the frame time.

updateWorldBound

public abstract void updateWorldBound()
updateWorldBound updates the bounding volume of the world. Abstract, geometry transforms the bound while node merges the children's bound. In most cases, users will want to call updateModelBound() and let this function be called automatically during updateGeometricState().


updateRenderState

public void updateRenderState()
Updates the render state values of this Spatial and and children it has. Should be called whenever render states change.


updateRenderState

protected void updateRenderState(java.util.Stack[] parentStates)
Called internally. Updates the render states of this Spatial. The stack contains parent render states.

Parameters:
parentStates - The list of parent renderstates.

applyRenderState

protected void applyRenderState(java.util.Stack[] states)
Called during updateRenderState(Stack[]), this function determines how the render states are actually applied to the spatial and any children it may have. By default, this function does nothing.

Parameters:
states - An array of stacks for each state.

propagateStatesFromRoot

protected void propagateStatesFromRoot(java.util.Stack[] states)
Called during updateRenderState(Stack[]), this function goes up the scene graph tree until the parent is null and pushes RenderStates onto the states Stack array.

Parameters:
states - The Stack[] to push states onto.

propagateBoundToRoot

public void propagateBoundToRoot()
propagateBoundToRoot passes the new world bound up the tree to the root.


getParent

public Node getParent()
getParent retrieve's this node's parent. If the parent is null this is the root node.

Returns:
the parent of this node.

setParent

public void setParent(Node parent)
setParent sets the parent of this node.

Parameters:
parent - the parent of this node.

removeFromParent

public boolean removeFromParent()
removeFromParent removes this Spatial from it's parent.

Returns:
true if it has a parent and performed the remove.

getLocalRotation

public Quaternion getLocalRotation()
getLocalRotation retrieves the local rotation of this node.

Returns:
the local rotation of this node.

setLocalRotation

public void setLocalRotation(Matrix3f rotation)
setLocalRotation sets the local rotation of this node.

Parameters:
rotation - the new local rotation.

setLocalRotation

public void setLocalRotation(Quaternion quaternion)
setLocalRotation sets the local rotation of this node, using a quaterion to build the matrix.

Parameters:
quaternion - the quaternion that defines the matrix.

getLocalScale

public Vector3f getLocalScale()
getLocalScale retrieves the local scale of this node.

Returns:
the local scale of this node.

setLocalScale

public void setLocalScale(float localScale)
setLocalScale sets the local scale of this node.

Parameters:
localScale - the new local scale, applied to x, y and z

setLocalScale

public void setLocalScale(Vector3f localScale)
setLocalScale sets the local scale of this node.

Parameters:
localScale - the new local scale.

getLocalTranslation

public Vector3f getLocalTranslation()
getLocalTranslation retrieves the local translation of this node.

Returns:
the local translation of this node.

setLocalTranslation

public void setLocalTranslation(Vector3f localTranslation)
setLocalTranslation sets the local translation of this node.

Parameters:
localTranslation - the local translation of this node.

setRenderState

public RenderState setRenderState(RenderState rs)
setRenderState sets a render state for this node. Note, there can only be one render state per type per node. That is, there can only be a single AlphaState a single TextureState, etc. If there is already a render state for a type set the old render state will be returned. Otherwise, null is returned.

Parameters:
rs - the render state to add.
Returns:
the old render state.

getRenderStateList

public RenderState[] getRenderStateList()
Returns the array of RenerState that this Spatial currently has.

Returns:
This spatial's state array.

clearRenderState

public void clearRenderState(int renderStateType)
Clears a given render state index by setting it to 0.

Parameters:
renderStateType - The index of a RenderState to clear
See Also:
RenderState.getType()

setRenderQueueMode

public void setRenderQueueMode(int renderQueueMode)

getRenderQueueMode

public int getRenderQueueMode()

setZOrder

public void setZOrder(int zOrder)

getZOrder

public int getZOrder()

setLightCombineMode

public void setLightCombineMode(int lightCombineMode)
Sets how lights from parents should be combined for this spatial.

Parameters:
lightCombineMode - The light combine mode for this spatial
See Also:
LightState.COMBINE_CLOSEST, LightState.COMBINE_FIRST, LightState.COMBINE_RECENT_ENABLED, LightState.INHERIT, LightState.OFF, LightState.REPLACE

getLightCombineMode

public int getLightCombineMode()
Returns this spatial's light combine mode. If the mode is set to inherit, then the spatial gets its combine mode from its parent.

Returns:
The spatial's light current combine mode.

setTextureCombineMode

public void setTextureCombineMode(int textureCombineMode)
Sets how textures from parents should be combined for this Spatial.

Parameters:
textureCombineMode - The new texture combine mode for this spatial.
See Also:
TextureState.COMBINE_CLOSEST, TextureState.COMBINE_FIRST, TextureState.COMBINE_RECENT_ENABLED, TextureState.INHERIT, TextureState.OFF, TextureState.REPLACE

getTextureCombineMode

public int getTextureCombineMode()
Returns this spatial's texture combine mode. If the mode is set to inherit, then the spatial gets its combine mode from its parent.

Returns:
The spatial's texture current combine mode.

getLastFrustumIntersection

public int getLastFrustumIntersection()
Returns this spatial's last frustum intersection result. This int is set when a check is made to determine if the bounds of the object fall inside a camera's frustum. If a parent is found to fall outside the frustum, the value for this spatial will not be updated. Possible values include: Camera.OUTSIDE_FRUSTUM, Camera.INTERSECTS_FRUSTUM, and Camera.INSIDE_FRUSTUM

Returns:
The spatial's last frustum intersection result.

clearCurrentStates

public static void clearCurrentStates()
sets all current states to null, and therefore forces the use of the default states.


clearCurrentState

public static void clearCurrentState(int state)
clears the specified state. The state is referenced by it's int value, and therefore should be called via RenderState's constant list. For example, RenderState.RS_ALPHA.

Parameters:
state - the state to clear.

getCurrentState

public static RenderState getCurrentState(int state)

applyDefaultStates

public static void applyDefaultStates()
All non null default states are applied to the renderer.


calculateCollisions

public void calculateCollisions(Spatial scene,
                                CollisionResults results)
calculateCollisions calls findCollisions to populate the CollisionResults object then processes the collision results.

Parameters:
scene - the scene to test against.
results - the results object.

findCollisions

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

Parameters:
scene - the scene to test against.
results - the results of the collisions.

hasCollision

public abstract boolean hasCollision(Spatial scene,
                                     boolean checkTriangles)

calculatePick

public void calculatePick(Ray ray,
                          PickResults results)

findPick

public abstract void findPick(Ray toTest,
                              PickResults results)

updateCollisionTree

public void updateCollisionTree()
This method updates the exact bounding tree of any this Spatial. If this spatial has children, the function is called recursivly on its children. Spatial objects, such as text, which don't make sense to have an exact bounds are ignored.


toString

public java.lang.String toString()
Returns the Spatial's name followed by the class of the spatial
Example: "MyNode (com.jme.scene.Spatial)

Returns:
Spatial's name followed by the class of the Spatial

putClone

public Spatial putClone(Spatial store,
                        CloneCreator properties)