Package com.ardor3d.scenegraph
Class Spatial
java.lang.Object
com.ardor3d.scenegraph.Spatial
Base class for all scenegraph objects.
-
Field Summary
Modifier and TypeFieldDescriptionprotected List
<SpatialController<?>> ArrayList of controllers for this spatial.protected Map
<Object, RenderDelegate> The render delegates to use for this Spatial, mapped by glContext reference.Field for accumulating dirty marks.protected Camera.FrustumIntersect
Keeps track of the current frustum intersection state of this Spatial.protected DirtyEventListener
Listener for dirty events.protected final Transform
Spatial's transform relative to its parent.protected String
This spatial's name.protected Node
Spatial's parent, or null if it has none.double
protected EnumMap
<RenderState.StateType, RenderState> The render states of this spatial.protected SceneHints
The hints for Ardor3D's use when evaluating and rendering this spatial.protected Object
Field for user data.protected BoundingVolume
Spatial's world bounding volume.protected final Transform
Spatial's absolute transform. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptVisitor
(Visitor visitor, boolean preexecute) Execute the given Visitor on this Spatial, and any Spatials managed by this Spatial as appropriate.void
addController
(SpatialController<?> controller) Adds a SpatialController to this Spatial's list of controllers.void
addTranslation
(double x, double y, double z) adds to the current translation of this spatial.void
addTranslation
(ReadOnlyVector3 translation) addTranslation
adds the given translation to the translation of this spatial.protected void
applyWorldRenderStates
(boolean recurse, RenderState.StateStack stack) The method actually implements how the render states are applied to this spatial and (if recurse is true) any children it may have.void
Removes all Controllers from this Spatial's list of controllers.void
clearDirty
(DirtyType dirtyType) Clears the dirty flag set at this spatial for the supplied dirty type.void
clearDirty
(Spatial caller, DirtyType dirtyType) Clears the dirty flag set at this spatial for the supplied dirty type.void
Clears a given render state index by setting it to null.abstract void
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.getController
(int i) Returns the controller in this list of controllers at index i.int
Gets the controller count.Returns the ArrayList that contains this spatial's SpatialControllers.protected RenderDelegate
Grab the render delegate for this spatial based on the currently set RenderContext.Tries to find the most accurate last frustum intersection for this spatial by checking the parent for possible Outside value.Returns the listener for dirty events on this node, if set.Returns this spatial's last frustum intersection result.Returns the requested RenderState that this Spatial currently has set or null if none is set.Retrieves the complete renderstate list.getName()
Returns the name of this spatial.getParent
retrieve's this node's parent.getRenderDelegate
(Object glContextRef) Gets the render delegate.Gets the local rotation matrix.getScale()
Gets the local scale vector.Gets the scene hints.Gets the local transform.Gets the local translation vector.Gets the Spatial specific user data.getWorldBound
retrieves the world bound at this level.Gets the world rotation matrix.Gets the world scale vector.Gets the world transform.Gets the world translation vector.boolean
hasAncestor
(Node ancestor) determines if the provided Node is the parent, or parent's parent, etc. of this Spatial.boolean
Test if this spatial is marked as dirty in respect to the supplied DirtyType.localToWorld
(ReadOnlyVector3 in, Vector3 store) Convert a vector (in) from this spatial's local coordinate space to world coordinate space.makeCopy
(boolean shareGeometricData) Create a copy of this spatial.Creates and returns a new instance of this spatial.void
Mark this node as dirty.protected void
Mark this node as dirty.void
onDraw
checks the spatial with the camera to see if it should be culled, if not, the node's draw method is called.void
passes the new world bound up the tree to the root.protected void
propagateDirtyDown
(EnumSet<DirtyType> dirtyTypes) Propagate the dirty mark down the tree hierarchy.protected void
propagateDirtyUp
(EnumSet<DirtyType> dirtyTypes) Propagate the dirty mark up the tree hierarchy.void
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.protected void
propageEventUp
(Spatial spatial, DirtyType dirtyType, boolean dirty) Propagate the dirty event up the hierarchy.void
read
(InputCapsule capsule) removeController
(int index) Removes a SpatialController from this Spatial's list of controllers by index.boolean
removeController
(SpatialController<?> controller) Removes a SpatialController from this Spatial's list of controllers, if it exist.boolean
removeFromParent
removes this Spatial from it's parent.void
setLastFrustumIntersection
(Camera.FrustumIntersect frustumIntersects) Overrides the last intersection result.void
setListener
(DirtyEventListener listener) Sets the listener for dirty events on this node.void
Sets the name of this Spatial.protected void
Called byNode.attachChild(Spatial)
andNode.detachChild(Spatial)
- don't call directly.void
setRenderDelegate
(RenderDelegate delegate, Object glContextRef) Sets the render delegate.setRenderState
sets a render state for this node.void
setRotation
(ReadOnlyMatrix3 rotation) Sets the rotation of this spatial.void
setRotation
(ReadOnlyQuaternion rotation) Sets the rotation of this spatial.void
setScale
(double scale) setScale
sets the scale of this spatial.void
setScale
(double x, double y, double z) sets the scale of this spatial.void
setScale
(ReadOnlyVector3 scale) setScale
sets the scale of this spatial.void
setTransform
(ReadOnlyTransform transform) Sets the local transform.void
setTranslation
(double x, double y, double z) sets the translation of this spatial.void
setTranslation
(ReadOnlyVector3 translation) setTranslation
sets the translation of this spatial.void
setUserData
(Object userData) Sets the Spatial specific user data.void
setWorldRotation
(ReadOnlyMatrix3 rotation) Sets the world rotation matrix.void
setWorldRotation
(ReadOnlyQuaternion rotation) Sets the world rotation quaternion.void
setWorldScale
(double scale) Sets the world scale.void
setWorldScale
(double x, double y, double z) Sets the world scale.void
setWorldScale
(ReadOnlyVector3 scale) Sets the world scale.void
setWorldTransform
(ReadOnlyTransform transform) Sets the world transform.void
setWorldTranslation
(double x, double y, double z) Sets the world translation.void
setWorldTranslation
(ReadOnlyVector3 translation) Sets the world translation vector.void
Sort the ligts on this spatial.toString()
Returns the Spatial's name followed by the class of the spatial
Example: "MyNode (com.ardor3d.scene.Spatial)protected void
updateChildren
(double time) Override to allow objects like Node to update their children.void
updateControllers
(double time) Update all controllers set on this spatial.void
updateGeometricState
(double time) Update geometric state.void
updateGeometricState
(double time, boolean initiator) updateGeometricState
updates all the geometry information for the node.abstract void
updateWorldBound
(boolean recurse) updates the bounding volume of the world.void
updateWorldRenderStates
(boolean recurse) Updates the render state values of this Spatial and and children it has.protected void
updateWorldRenderStates
(boolean recurse, RenderState.StateStack stateStack) Called internally.void
updateWorldTransform
(boolean recurse) Updates the worldTransform.worldToLocal
(ReadOnlyVector3 in, Vector3 store) Convert a vector (in) from world coordinate space to this spatial's local coordinate space.void
write
(OutputCapsule capsule)
-
Field Details
-
_name
This spatial's name. -
_localTransform
Spatial's transform relative to its parent. -
_worldTransform
Spatial's absolute transform. -
_worldBound
Spatial's world bounding volume. -
_parent
Spatial's parent, or null if it has none. -
_controllers
ArrayList of controllers for this spatial. -
_renderStateList
The render states of this spatial. -
_listener
Listener for dirty events. -
_dirtyMark
Field for accumulating dirty marks. -
_userData
Field for user data. Note: If this object is not explicitly of type Savable, it will be ignored during save. -
_frustumIntersects
Keeps track of the current frustum intersection state of this Spatial. -
_sceneHints
The hints for Ardor3D's use when evaluating and rendering this spatial. -
_delegateMap
The render delegates to use for this Spatial, mapped by glContext reference. -
_queueDistance
public transient double _queueDistance -
ON_DIRTY_TRANSFORM_ONLY
-
ON_DIRTY_TRANSFORM
-
ON_DIRTY_RENDERSTATE
-
ON_DIRTY_BOUNDING
-
ON_DIRTY_ATTACHED
-
-
Constructor Details
-
Spatial
public Spatial()Constructs a new Spatial. Initializes the transform fields. -
Spatial
Constructs a newSpatial
with a given name.- Parameters:
name
- the name of the spatial. This is required for identification purposes.
-
-
Method Details
-
getName
Returns the name of this spatial.- Returns:
- This spatial's name.
-
setName
Sets the name of this Spatial.- Parameters:
name
- new name
-
setRenderDelegate
Sets the render delegate.- Parameters:
delegate
- the new delegate, or null for default behaviorglContextRef
- if null, the delegate is set as the default render delegate for this spatial. Otherwise, the delegate is used when this Spatial is rendered in a RenderContext tied to the given glContextRef.
-
getRenderDelegate
Gets the render delegate.- Parameters:
glContextRef
- if null, retrieve the default render delegate for this spatial. Otherwise, retrieve the delegate used when this Spatial is rendered in a RenderContext tied to the given glContextRef.- Returns:
- delegate as described.
-
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
Called byNode.attachChild(Spatial)
andNode.detachChild(Spatial)
- don't call directly.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.
-
hasAncestor
determines if the provided Node is the parent, or parent's parent, etc. of this Spatial.- Parameters:
ancestor
- the ancestor object to look for.- Returns:
- true if the ancestor is found, false otherwise.
-
getParentHintable
- Specified by:
getParentHintable
in interfaceHintable
- Returns:
- a hierarchical parent to be used for determining inheritance of certain SceneHint fields.
- See Also:
-
getSceneHints
Gets the scene hints.- Specified by:
getSceneHints
in interfaceHintable
- Returns:
- the scene hints set on this Spatial
-
getListener
Returns the listener for dirty events on this node, if set.- Returns:
- the listener
-
setListener
Sets the listener for dirty events on this node.- Parameters:
listener
- listener to use.
-
markDirty
Mark this node as dirty. Can be marked as Transform, Bounding, Attached, Detached, Destroyed or RenderState- Parameters:
dirtyType
- the dirty type
-
markDirty
Mark this node as dirty. Can be marked as Transform, Bounding, Attached, Detached, Destroyed or RenderState- Parameters:
caller
- the spatial where the marking was initiateddirtyType
- the dirty type
-
isDirty
Test if this spatial is marked as dirty in respect to the supplied DirtyType.- Parameters:
dirtyType
- dirty type to test against- Returns:
- true if spatial marked dirty against the supplied dirty type
-
clearDirty
Clears the dirty flag set at this spatial for the supplied dirty type.- Parameters:
dirtyType
- dirty type to clear flag for
-
clearDirty
Clears the dirty flag set at this spatial for the supplied dirty type.- Parameters:
caller
- the spatial where the clearing was initiateddirtyType
- dirty type to clear flag for
-
propagateDirtyUp
Propagate the dirty mark up the tree hierarchy.- Parameters:
dirtyTypes
- the dirty types
-
propagateDirtyDown
Propagate the dirty mark down the tree hierarchy.- Parameters:
dirtyTypes
- the dirty types
-
propageEventUp
Propagate the dirty event up the hierarchy. If a listener is found on the spatial the event is fired and the propagation is stopped.- Parameters:
spatial
- the spatialdirtyType
- the dirty typedirty
- if true, propogate a dirty event, else propogate a clean event
-
getRotation
Gets the local rotation matrix.- Returns:
- the rotation
-
getScale
Gets the local scale vector.- Returns:
- the scale
-
getTranslation
Gets the local translation vector.- Returns:
- the translation
-
getTransform
Gets the local transform.- Returns:
- the transform
-
setTransform
Sets the local transform.- Parameters:
transform
- the new transform
-
setWorldRotation
Sets the world rotation matrix.- Parameters:
rotation
- the new world rotation
-
setWorldRotation
Sets the world rotation quaternion.- Parameters:
rotation
- the new world rotation
-
setWorldScale
Sets the world scale.- Parameters:
scale
- the new world scale vector
-
setWorldScale
public void setWorldScale(double x, double y, double z) Sets the world scale.- Parameters:
x
- the x coordinatey
- the y coordinatez
- the z coordinate
-
setWorldScale
public void setWorldScale(double scale) Sets the world scale.- Parameters:
scale
- the new world scale
-
setWorldTranslation
Sets the world translation vector.- Parameters:
translation
- the new world translation
-
setWorldTranslation
public void setWorldTranslation(double x, double y, double z) Sets the world translation.- Parameters:
x
- the x coordinatey
- the y coordinatez
- the z coordinate
-
setWorldTransform
Sets the world transform.- Parameters:
transform
- the new world transform
-
setRotation
Sets the rotation of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
rotation
- the new rotation of this spatial
-
setRotation
Sets the rotation of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
rotation
- the new rotation of this spatial
-
setScale
setScale
sets the scale of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
scale
- the new scale of this spatial
-
setScale
public void setScale(double scale) setScale
sets the scale of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
scale
- the new scale of this spatial
-
setScale
public void setScale(double x, double y, double z) sets the scale of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
x
- the x scale factory
- the y scale factorz
- the z scale factor
-
setTranslation
setTranslation
sets the translation of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
translation
- the new translation of this spatial
-
setTranslation
public void setTranslation(double x, double y, double z) sets the translation of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
x
- the x coordinatey
- the y coordinatez
- the z coordinate
-
addTranslation
addTranslation
adds the given translation to the translation of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
translation
- the translation vector
-
addTranslation
public void addTranslation(double x, double y, double z) adds to the current translation of this spatial. This marks the spatial as DirtyType.Transform.- Parameters:
x
- the x amounty
- the y amountz
- the z amount
-
getWorldRotation
Gets the world rotation matrix.- Returns:
- the world rotation
-
getWorldScale
Gets the world scale vector.- Returns:
- the world scale
-
getWorldTranslation
Gets the world translation vector.- Returns:
- the world translation
-
getWorldTransform
Gets the world transform.- Returns:
- the world transform
-
getWorldBound
getWorldBound
retrieves the world bound at this level.- Returns:
- the world bound at this level.
-
onDraw
onDraw
checks the spatial with the camera to see if it should be culled, if not, the node's draw method is called.This method is called by the renderer. Usually it should not be called directly.
- Parameters:
r
- the renderer used for display.
-
draw
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:
renderer
- the renderer used for display.
-
getCurrentRenderDelegate
Grab the render delegate for this spatial based on the currently set RenderContext.- Returns:
- the delegate or null if a delegate was not found.
-
updateGeometricState
public void updateGeometricState(double time) Update geometric state.- Parameters:
time
- The time in seconds between the last two consecutive frames (time per frame). SeeReadOnlyTimer.getTimePerFrame()
- See Also:
-
updateGeometricState
public void updateGeometricState(double time, boolean initiator) updateGeometricState
updates all the geometry information for the node.- Parameters:
time
- The time in seconds between the last two consecutive frames (time per frame). SeeReadOnlyTimer.getTimePerFrame()
initiator
- true if this node started the update process.
-
updateChildren
protected void updateChildren(double time) Override to allow objects like Node to update their children.- Parameters:
time
- The time in seconds between the last two consecutive frames (time per frame). SeeReadOnlyTimer.getTimePerFrame()
-
updateControllers
public void updateControllers(double time) Update all controllers set on this spatial.- Parameters:
time
- The time in seconds between the last two consecutive frames (time per frame). SeeReadOnlyTimer.getTimePerFrame()
-
updateWorldTransform
public void updateWorldTransform(boolean recurse) Updates the worldTransform.- 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.
-
localToWorld
Convert a vector (in) from this spatial's local coordinate space to world coordinate space.- Parameters:
in
- vector to read fromstore
- where to write the result (null to create a new vector, may be same as in)- Returns:
- the result (store)
-
worldToLocal
Convert a vector (in) from world coordinate space to this spatial's local coordinate space.- Parameters:
in
- vector to read fromstore
- where to write the result (null to create a new vector, may be same as in)- Returns:
- the result (store)
-
updateWorldRenderStates
public void updateWorldRenderStates(boolean recurse) Updates the render state values of this Spatial and and children it has. Should be called whenever render states change.- Parameters:
recurse
- true to recurse down the scenegraph tree
-
updateWorldRenderStates
Called internally. Updates the render states of this Spatial. The stack contains parent render states.- Parameters:
recurse
- true to recurse down the scenegraph treestateStack
- The parent render states, or null if we are starting at this point in the scenegraph.
-
applyWorldRenderStates
The method actually implements how the render states are applied to this spatial and (if recurse is true) any children it may have. By default, this function does nothing.- Parameters:
recurse
- true to recurse down the scenegraph treestack
- The stack for each state
-
sortLights
public void sortLights()Sort the ligts on this spatial. -
getLocalRenderStates
Retrieves the complete renderstate list.- Returns:
- the list of renderstates
-
setRenderState
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 BlendState 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.
-
getLocalRenderState
Returns the requested RenderState that this Spatial currently has set or null if none is set.- Parameters:
type
- the state type to retrieve- Returns:
- a render state at the given position or null
-
clearRenderState
Clears a given render state index by setting it to null.- Parameters:
type
- The type of RenderState to clear
-
propagateStatesFromRoot
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:
stack
- The stack to push any parent states onto.
-
updateWorldBound
public abstract void updateWorldBound(boolean recurse) 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().- Parameters:
recurse
- true to recurse down the scenegraph tree
-
propagateBoundToRoot
public void propagateBoundToRoot()passes the new world bound up the tree to the root. -
getUserData
Gets the Spatial specific user data.- Returns:
- the user data
-
setUserData
Sets the Spatial specific user data.- Parameters:
userData
- Some Spatial specific user data. Note: If this object is not explicitly of type Savable, it will be ignored during read/write.
-
addController
Adds a SpatialController to this Spatial's list of controllers.- Parameters:
controller
- The SpatialController to add- See Also:
-
removeController
Removes a SpatialController from this Spatial's list of controllers, if it exist.- Parameters:
controller
- The SpatialController to remove- Returns:
- True if the SpatialController was in the list to remove.
- See Also:
-
removeController
Removes a SpatialController from this Spatial's list of controllers by index.- Parameters:
index
- The index of the controller to remove- Returns:
- The SpatialController removed or null if nothing was removed.
- See Also:
-
clearControllers
public void clearControllers()Removes all Controllers from this Spatial's list of controllers.- See Also:
-
getController
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:
-
getControllers
Returns the ArrayList that contains this spatial's SpatialControllers.- Returns:
- This spatial's _controllers.
-
getControllerCount
public int getControllerCount()Gets the controller count.- Returns:
- the number of controllers set on this Spatial.
-
getLocalLastFrustumIntersection
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.- Returns:
- The spatial's last frustum intersection result.
-
getLastFrustumIntersection
Tries to find the most accurate last frustum intersection for this spatial by checking the parent for possible Outside value.- Returns:
- Outside, if this, or any ancestor was Outside, otherwise the local intersect value.
-
setLastFrustumIntersection
Overrides the last intersection result. This is useful for operations that want to start rendering at the middle of a scene tree and don't want the parent of that node to influence culling. (See texture renderer code for example.)- Parameters:
frustumIntersects
- the new frustum intersection value
-
acceptVisitor
Execute the given Visitor on this Spatial, and any Spatials managed by this Spatial as appropriate.- Parameters:
visitor
- the Visitor object to use.preexecute
- if true, we will visit this Spatial before any Spatials we manage (such as children of a Node.) If false, we will visit them first, then ourselves.
-
toString
Returns the Spatial's name followed by the class of the spatial
Example: "MyNode (com.ardor3d.scene.Spatial) -
makeCopy
Create a copy of this spatial.- Parameters:
shareGeometricData
- if true, reuse any data fields describing the geometric shape of the spatial, as applicable.- Returns:
- the copy as described.
-
makeInstanced
Creates and returns a new instance of this spatial. Used for instanced rendering. All instances visible on the screen will be drawn in one draw call. The new instance will share all data (meshData and renderStates) with the current mesh and all other instances created from this spatial.- Returns:
- an instanced copy of this node
-
getClassTag
- Specified by:
getClassTag
in interfaceSavable
- See Also:
-
read
- Specified by:
read
in interfaceSavable
- Parameters:
capsule
- the input capsule- Throws:
IOException
- Signals that an I/O exception has occurred.- See Also:
-
write
- Specified by:
write
in interfaceSavable
- Parameters:
capsule
- the capsule- Throws:
IOException
- Signals that an I/O exception has occurred.- See Also:
-