Class AnimationManager

java.lang.Object
com.ardor3d.extension.animation.skeletal.AnimationManager

public class AnimationManager extends Object

AnimationManager describes and maintains an animation system. It tracks one or more layered animation state machines (AnimationLayer) and uses their combined result to update one or more poses (via a set AnimationApplier.) AnimationClips used in these layers are instanced and tracked specifically for this manager.

By default, an animation manager has a single base animation layer. Other layers may be added to this. It is important that the base layer (the layer at index 0) always has a full set of data to put a skeleton pose into a valid state.

  • Field Details

    • _globalTimer

      protected ReadOnlyTimer _globalTimer
      A timer to use as our "global" time keeper. All animation sources under this manager will use this timer as their time reference.
    • _applyToPoses

      protected List<SkeletonPose> _applyToPoses
      The pose(s) this manager manipulates on update.
    • _sceneRoot

      protected final Spatial _sceneRoot
      The root of a scenegraph we can look for transform animation targets under.
    • _clipInstances

      protected final Map<AnimationClip,AnimationClipInstance> _clipInstances
      Local instance information for any clips referenced by the layers/blend trees in this manager.
    • _applier

      protected AnimationApplier _applier
      A logic object responsible for taking animation data and applying it to skeleton poses.
    • _layers

      protected final List<AnimationLayer> _layers
      Our animation layers.
    • _valuesStore

      protected final LoggingMap<String,Double> _valuesStore
      A map of key / Double values, allowing control over elements under this manager without needing precise knowledge of the layout of those layers, blend trees, etc. Missing keys will return 0.0 and log a warning.
    • _updateRate

      protected double _updateRate
      The throttle rate of animation. Default is 60fps (1/60.0). Set to 0 to disable throttling.
    • _lastUpdate

      protected double _lastUpdate
      The global time we last processed an animation. (To use when checking our throttle.)
    • _currentAnimationState

      protected AnimationManager.AnimationUpdateState _currentAnimationState
      Sets the current animationState used to control if animation is playing, pausing or stopped.
    • _canSetStopState

      protected boolean _canSetStopState
      boolean flag to allow stop state to be updated one last time.
    • _resetClipsOnStop

      protected boolean _resetClipsOnStop
      boolean flag to reset Clips automatically once they are stopped.
    • _updateStateListeners

      protected final List<AnimationUpdateStateListener> _updateStateListeners
      Listeners for changes to this manager's AnimationUpdateState.
  • Constructor Details

    • AnimationManager

      public AnimationManager(ReadOnlyTimer globalTimer, SkeletonPose pose)
      Construct a new AnimationManager.
      Parameters:
      globalTimer - the timer to use for global time keeping.
      pose - a pose to update. Optional if we won't be animating a SkinnedMesh.
    • AnimationManager

      public AnimationManager(ReadOnlyTimer globalTimer, SkeletonPose pose, Spatial sceneRoot)
      Construct a new AnimationManager.
      Parameters:
      globalTimer - the timer to use for global time keeping.
      pose - a pose to update. Optional if we won't be animating a SkinnedMesh.
      sceneRoot - a root we will use to search for spatials when doing transform animations.
  • Method Details

    • getCurrentGlobalTime

      public double getCurrentGlobalTime()
      Returns:
      the "local time", in seconds reported by our global timer.
    • getGlobalTimer

      public ReadOnlyTimer getGlobalTimer()
      Returns:
      the timer used by this manager for global time keeping.
    • setGlobalTimer

      public void setGlobalTimer(Timer timer)
      Parameters:
      timer - the timer to be used by this manager for global time keeping.
    • isResetClipsOnStop

      public boolean isResetClipsOnStop()
      Returns:
      True if clips will reset if the currentUpdateState is Stop.
    • setResetClipsOnStop

      public void setResetClipsOnStop(boolean resetClipsOnStop)
      Parameters:
      resetClipsOnStop - True if clips are to be reset when currentUpdateState is Stop, false otherwise.
    • play

      public void play()
    • pause

      public void pause()
    • stop

      public void stop()
    • isPlaying

      public boolean isPlaying()
    • isPaused

      public boolean isPaused()
    • isStopped

      public boolean isStopped()
    • setAnimationUpdateState

      public void setAnimationUpdateState(AnimationManager.AnimationUpdateState newAnimationState)
      Parameters:
      newAnimationState - the new animation state in the animation Manager.
    • fireAnimationUpdateStateChange

      protected void fireAnimationUpdateStateChange(AnimationManager.AnimationUpdateState oldState)
      Notify any listeners of the state change
      Parameters:
      oldState - previous state
    • addAnimationUpdateStateListener

      public void addAnimationUpdateStateListener(AnimationUpdateStateListener listener)
      Add an AnimationUpdateStateListener to this manager.
      Parameters:
      listener - the listener to add.
    • removeAnimationUpdateStateListener

      public boolean removeAnimationUpdateStateListener(AnimationUpdateStateListener listener)
      Remove an AnimationUpdateStateListener from this manager.
      Parameters:
      listener - the listener to remove.
      Returns:
      true if the listener was found
    • clearAnimationUpdateStateListeners

      public void clearAnimationUpdateStateListeners()
      Remove any AnimationUpdateStateListeners registered with this manager.
    • getAnimationUpdateState

      public AnimationManager.AnimationUpdateState getAnimationUpdateState()
      Returns:
      the currentAnimationState.
    • addPose

      public void addPose(SkeletonPose pose)
      Parameters:
      pose - a pose to add to be updated by this manager.
    • removePose

      public boolean removePose(SkeletonPose pose)
      Parameters:
      pose - the pose to remove from this manager.
      Returns:
      true if the pose was found to be removed.
    • containsPose

      public boolean containsPose(SkeletonPose pose)
      Parameters:
      pose - a pose to look for
      Returns:
      true if the pose was found in this manager.
    • getPoseCount

      public int getPoseCount()
      Returns:
      the number of poses managed by this manager.
    • getSkeletonPose

      public SkeletonPose getSkeletonPose(int index)
      Parameters:
      index - the index to pull the pose from.
      Returns:
      pose at the given index
    • getApplier

      public AnimationApplier getApplier()
      Returns:
      the logic object responsible for taking animation data and applying it to skeleton poses.
    • setApplier

      public void setApplier(AnimationApplier applier)
      Parameters:
      applier - a logic object to be responsible for taking animation data and applying it to skeleton poses.
    • update

      public void update()
      Move associated layers forward to the current global time and then apply the associated animation data to any SkeletonPoses set on the manager.
    • getClipInstance

      public AnimationClipInstance getClipInstance(AnimationClip clip)
      Retrieve and track an instance of an animation clip to be used with this manager.
      Parameters:
      clip - the clip to instance.
      Returns:
      our new clip instance.
    • findClipInstance

      public AnimationClipInstance findClipInstance(String clipName)
      Retrieve an existing clip instance being tracked by this manager.
      Parameters:
      clipName - the name of the clip to find an existing instance of. Case sensitive.
      Returns:
      our existing clip instance, or null if we were not tracking a clip of the given name.
    • findAnimationClip

      public AnimationClip findAnimationClip(String clipName)
      Retrieve an existing clip tracked by this manager.
      Parameters:
      clipName - the name of the clip to find. Case sensitive.
      Returns:
      our existing clip, or null if we were not tracking a clip of the given name.
    • resetClipInstance

      public void resetClipInstance(AnimationClip clip, double globalStartTime)
      Rewind and reactivate the clip instance associated with the given clip.
      Parameters:
      clip - the clip to pull the instance for.
      globalStartTime - the time to set the clip instance's start as.
    • getAnimationLayer

      public AnimationLayer getAnimationLayer(int index)
      Parameters:
      index - the index of the layer to retrieve.
      Returns:
      the animation layer at that index, or null of index is outside the bounds of our list of layers.
    • findAnimationLayer

      public AnimationLayer findAnimationLayer(String layerName)
      Parameters:
      layerName - the name of the layer to find.
      Returns:
      the first animation layer with a matching name, or null of none are found.
    • addAnimationLayer

      public int addAnimationLayer(AnimationLayer layer)
      Add a new layer to our list of animation layers.
      Parameters:
      layer - the layer to add.
      Returns:
      the index of our added layer in our list of animation layers.
    • insertAnimationLayer

      public void insertAnimationLayer(AnimationLayer layer, int index)
      Insert a given animation layer into our list of layers.
      Parameters:
      layer - the layer to insert.
      index - the index to insert at. Moves any layers at that index over by one before inserting.
    • removeAnimationLayer

      public boolean removeAnimationLayer(AnimationLayer layer)
      Parameters:
      layer - a layer to remove.
      Returns:
      true if the layer is found to remove.
    • getBaseAnimationLayer

      public AnimationLayer getBaseAnimationLayer()
      Returns:
      our bottom most layer. This layer should always consist of a full skeletal pose data.
    • getUpdateRate

      public double getUpdateRate()
      Returns:
      the amount of time in seconds between frame rate updates. (throttle) default is 60fps (1.0/60.0).
    • setUpdateRate

      public void setUpdateRate(double updateRate)
      Parameters:
      updateRate - the new throttle rate. Default is 60fps (1.0/60.0). Set to 0 to disable throttling.
    • getCurrentSourceData

      public Map<String,? extends Object> getCurrentSourceData()
      Returns:
      the current source data from the layers of this manager.
    • getValuesStore

      public LoggingMap<String,Double> getValuesStore()
    • getClipInstancesStore

      public Map<AnimationClip,AnimationClipInstance> getClipInstancesStore()
      Returns:
      the Map containing the AnimationClips and their respective AnimationClipInstances.