Class Spatial

java.lang.Object
com.ardor3d.scenegraph.Spatial
All Implemented Interfaces:
Hintable, Savable
Direct Known Subclasses:
Mesh, Node

public abstract class Spatial extends Object implements Savable, Hintable
Base class for all scenegraph objects.
  • Field Details

    • _name

      protected String _name
      This spatial's name.
    • _localTransform

      protected final Transform _localTransform
      Spatial's transform relative to its parent.
    • _worldTransform

      protected final Transform _worldTransform
      Spatial's absolute transform.
    • _worldBound

      protected BoundingVolume _worldBound
      Spatial's world bounding volume.
    • _parent

      protected Node _parent
      Spatial's parent, or null if it has none.
    • _controllers

      protected List<SpatialController<?>> _controllers
      ArrayList of controllers for this spatial.
    • _renderStateList

      protected EnumMap<RenderState.StateType,RenderState> _renderStateList
      The render states of this spatial.
    • _listener

      protected DirtyEventListener _listener
      Listener for dirty events.
    • _dirtyMark

      protected EnumSet<DirtyType> _dirtyMark
      Field for accumulating dirty marks.
    • _userData

      protected Object _userData
      Field for user data. Note: If this object is not explicitly of type Savable, it will be ignored during save.
    • _frustumIntersects

      protected Camera.FrustumIntersect _frustumIntersects
      Keeps track of the current frustum intersection state of this Spatial.
    • _sceneHints

      protected SceneHints _sceneHints
      The hints for Ardor3D's use when evaluating and rendering this spatial.
    • _delegateMap

      protected transient Map<Object,RenderDelegate> _delegateMap
      The render delegates to use for this Spatial, mapped by glContext reference.
    • _queueDistance

      public transient double _queueDistance
    • ON_DIRTY_TRANSFORM_ONLY

      protected static final EnumSet<DirtyType> ON_DIRTY_TRANSFORM_ONLY
    • ON_DIRTY_TRANSFORM

      protected static final EnumSet<DirtyType> ON_DIRTY_TRANSFORM
    • ON_DIRTY_RENDERSTATE

      protected static final EnumSet<DirtyType> ON_DIRTY_RENDERSTATE
    • ON_DIRTY_BOUNDING

      protected static final EnumSet<DirtyType> ON_DIRTY_BOUNDING
    • ON_DIRTY_ATTACHED

      protected static final EnumSet<DirtyType> ON_DIRTY_ATTACHED
  • Constructor Details

    • Spatial

      public Spatial()
      Constructs a new Spatial. Initializes the transform fields.
    • Spatial

      public Spatial(String name)
      Constructs a new Spatial with a given name.
      Parameters:
      name - the name of the spatial. This is required for identification purposes.
  • Method Details

    • getName

      public String getName()
      Returns the name of this spatial.
      Returns:
      This spatial's name.
    • setName

      public void setName(String name)
      Sets the name of this Spatial.
      Parameters:
      name - new name
    • setRenderDelegate

      public void setRenderDelegate(RenderDelegate delegate, Object glContextRef)
      Sets the render delegate.
      Parameters:
      delegate - the new delegate, or null for default behavior
      glContextRef - 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

      public RenderDelegate getRenderDelegate(Object glContextRef)
      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

      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

      protected void setParent(Node parent)
      Called by Node.attachChild(Spatial) and Node.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

      public boolean hasAncestor(Node ancestor)
      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

      public Hintable getParentHintable()
      Specified by:
      getParentHintable in interface Hintable
      Returns:
      a hierarchical parent to be used for determining inheritance of certain SceneHint fields.
      See Also:
    • getSceneHints

      public SceneHints getSceneHints()
      Gets the scene hints.
      Specified by:
      getSceneHints in interface Hintable
      Returns:
      the scene hints set on this Spatial
    • getListener

      public DirtyEventListener getListener()
      Returns the listener for dirty events on this node, if set.
      Returns:
      the listener
    • setListener

      public void setListener(DirtyEventListener listener)
      Sets the listener for dirty events on this node.
      Parameters:
      listener - listener to use.
    • markDirty

      public void markDirty(DirtyType dirtyType)
      Mark this node as dirty. Can be marked as Transform, Bounding, Attached, Detached, Destroyed or RenderState
      Parameters:
      dirtyType - the dirty type
    • markDirty

      protected void markDirty(Spatial caller, DirtyType dirtyType)
      Mark this node as dirty. Can be marked as Transform, Bounding, Attached, Detached, Destroyed or RenderState
      Parameters:
      caller - the spatial where the marking was initiated
      dirtyType - the dirty type
    • isDirty

      public boolean isDirty(DirtyType dirtyType)
      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

      public void clearDirty(DirtyType dirtyType)
      Clears the dirty flag set at this spatial for the supplied dirty type.
      Parameters:
      dirtyType - dirty type to clear flag for
    • clearDirty

      public void clearDirty(Spatial caller, DirtyType dirtyType)
      Clears the dirty flag set at this spatial for the supplied dirty type.
      Parameters:
      caller - the spatial where the clearing was initiated
      dirtyType - dirty type to clear flag for
    • propagateDirtyUp

      protected void propagateDirtyUp(EnumSet<DirtyType> dirtyTypes)
      Propagate the dirty mark up the tree hierarchy.
      Parameters:
      dirtyTypes - the dirty types
    • propagateDirtyDown

      protected void propagateDirtyDown(EnumSet<DirtyType> dirtyTypes)
      Propagate the dirty mark down the tree hierarchy.
      Parameters:
      dirtyTypes - the dirty types
    • propageEventUp

      protected void propageEventUp(Spatial spatial, DirtyType dirtyType, boolean dirty)
      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 spatial
      dirtyType - the dirty type
      dirty - if true, propogate a dirty event, else propogate a clean event
    • getRotation

      public ReadOnlyMatrix3 getRotation()
      Gets the local rotation matrix.
      Returns:
      the rotation
    • getScale

      public ReadOnlyVector3 getScale()
      Gets the local scale vector.
      Returns:
      the scale
    • getTranslation

      public ReadOnlyVector3 getTranslation()
      Gets the local translation vector.
      Returns:
      the translation
    • getTransform

      public ReadOnlyTransform getTransform()
      Gets the local transform.
      Returns:
      the transform
    • setTransform

      public void setTransform(ReadOnlyTransform transform)
      Sets the local transform.
      Parameters:
      transform - the new transform
    • setWorldRotation

      public void setWorldRotation(ReadOnlyMatrix3 rotation)
      Sets the world rotation matrix.
      Parameters:
      rotation - the new world rotation
    • setWorldRotation

      public void setWorldRotation(ReadOnlyQuaternion rotation)
      Sets the world rotation quaternion.
      Parameters:
      rotation - the new world rotation
    • setWorldScale

      public void setWorldScale(ReadOnlyVector3 scale)
      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 coordinate
      y - the y coordinate
      z - the z coordinate
    • setWorldScale

      public void setWorldScale(double scale)
      Sets the world scale.
      Parameters:
      scale - the new world scale
    • setWorldTranslation

      public void setWorldTranslation(ReadOnlyVector3 translation)
      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 coordinate
      y - the y coordinate
      z - the z coordinate
    • setWorldTransform

      public void setWorldTransform(ReadOnlyTransform transform)
      Sets the world transform.
      Parameters:
      transform - the new world transform
    • setRotation

      public void setRotation(ReadOnlyMatrix3 rotation)
      Sets the rotation of this spatial. This marks the spatial as DirtyType.Transform.
      Parameters:
      rotation - the new rotation of this spatial
    • setRotation

      public void setRotation(ReadOnlyQuaternion rotation)
      Sets the rotation of this spatial. This marks the spatial as DirtyType.Transform.
      Parameters:
      rotation - the new rotation of this spatial
    • setScale

      public void setScale(ReadOnlyVector3 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 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 factor
      y - the y scale factor
      z - the z scale factor
    • setTranslation

      public void setTranslation(ReadOnlyVector3 translation)
      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 coordinate
      y - the y coordinate
      z - the z coordinate
    • addTranslation

      public void addTranslation(ReadOnlyVector3 translation)
      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 amount
      y - the y amount
      z - the z amount
    • getWorldRotation

      public ReadOnlyMatrix3 getWorldRotation()
      Gets the world rotation matrix.
      Returns:
      the world rotation
    • getWorldScale

      public ReadOnlyVector3 getWorldScale()
      Gets the world scale vector.
      Returns:
      the world scale
    • getWorldTranslation

      public ReadOnlyVector3 getWorldTranslation()
      Gets the world translation vector.
      Returns:
      the world translation
    • getWorldTransform

      public ReadOnlyTransform getWorldTransform()
      Gets the world transform.
      Returns:
      the world transform
    • getWorldBound

      public BoundingVolume getWorldBound()
      getWorldBound retrieves the world bound at this level.
      Returns:
      the world bound at this level.
    • onDraw

      public void onDraw(Renderer r)
      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

      public abstract void draw(Renderer renderer)
      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

      protected RenderDelegate 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). See ReadOnlyTimer.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). See ReadOnlyTimer.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). See ReadOnlyTimer.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). See ReadOnlyTimer.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

      public Vector3 localToWorld(ReadOnlyVector3 in, Vector3 store)
      Convert a vector (in) from this spatial's local coordinate space to world coordinate space.
      Parameters:
      in - vector to read from
      store - where to write the result (null to create a new vector, may be same as in)
      Returns:
      the result (store)
    • worldToLocal

      public Vector3 worldToLocal(ReadOnlyVector3 in, Vector3 store)
      Convert a vector (in) from world coordinate space to this spatial's local coordinate space.
      Parameters:
      in - vector to read from
      store - 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

      protected void updateWorldRenderStates(boolean recurse, RenderState.StateStack stateStack)
      Called internally. Updates the render states of this Spatial. The stack contains parent render states.
      Parameters:
      recurse - true to recurse down the scenegraph tree
      stateStack - The parent render states, or null if we are starting at this point in the scenegraph.
    • applyWorldRenderStates

      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. By default, this function does nothing.
      Parameters:
      recurse - true to recurse down the scenegraph tree
      stack - The stack for each state
    • sortLights

      public void sortLights()
      Sort the ligts on this spatial.
    • getLocalRenderStates

      public EnumMap<RenderState.StateType,RenderState> getLocalRenderStates()
      Retrieves the complete renderstate list.
      Returns:
      the list of renderstates
    • 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 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

      public RenderState getLocalRenderState(RenderState.StateType type)
      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

      public void clearRenderState(RenderState.StateType type)
      Clears a given render state index by setting it to null.
      Parameters:
      type - The type of RenderState to clear
    • propagateStatesFromRoot

      public void propagateStatesFromRoot(RenderState.StateStack stack)
      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

      public Object getUserData()
      Gets the Spatial specific user data.
      Returns:
      the user data
    • setUserData

      public void setUserData(Object userData)
      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

      public void addController(SpatialController<?> controller)
      Adds a SpatialController to this Spatial's list of controllers.
      Parameters:
      controller - The SpatialController to add
      See Also:
    • removeController

      public boolean removeController(SpatialController<?> controller)
      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

      public SpatialController<?> removeController(int index)
      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

      public SpatialController<?> 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:
    • getControllers

      public List<SpatialController<?>> 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

      public Camera.FrustumIntersect 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

      public Camera.FrustumIntersect 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

      public void setLastFrustumIntersection(Camera.FrustumIntersect frustumIntersects)
      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

      public void acceptVisitor(Visitor visitor, boolean preexecute)
      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

      public String toString()
      Returns the Spatial's name followed by the class of the spatial
      Example: "MyNode (com.ardor3d.scene.Spatial)
      Overrides:
      toString in class Object
      Returns:
      Spatial's name followed by the class of the Spatial
    • makeCopy

      public Spatial makeCopy(boolean shareGeometricData)
      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

      public Spatial 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

      public Class<? extends Spatial> getClassTag()
      Specified by:
      getClassTag in interface Savable
      See Also:
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Parameters:
      capsule - the input capsule
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also:
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Parameters:
      capsule - the capsule
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also: