Class KeyframeController<T extends Spatial>

java.lang.Object
com.ardor3d.scenegraph.controller.ComplexSpatialController<T>
com.ardor3d.extension.model.util.KeyframeController<T>
All Implemented Interfaces:
SpatialController<T>, Savable, Serializable

public class KeyframeController<T extends Spatial> extends ComplexSpatialController<T>
TODO: Revisit for better Ardor3D integration. Started Date: Jun 12, 2004
Class can do linear interpolation of a Mesh between units of time. Similar to VertexKeyframeController but interpolates float units of time instead of integer key frames. setSpeed(float) sets a speed relative to the defined speed. For example, the default is 1. A speed of 2 would run twice as fast and a speed of .5 would run half as fast setMinTime(float) and setMaxTime(float) both define the bounds that KeyframeController should follow. It is the programmer's responsibility to make sure that the MinTime and MaxTime are within the span of the defined setKeyframe Controller functions RepeatType and isActive are both defined in their default way for KeyframeController When this controller is saved/loaded to XML format, it assumes that the mesh it morphs is the Mesh it belongs to, so it is recommended to only attach this controller to the Mesh it animates. (Based on work by Jack Lindamood, kevglass (parts), hevee (blend time), Julien Gouesse (port to Ardor3D))
See Also:
  • Field Details

  • Constructor Details

    • KeyframeController

      public KeyframeController()
      Default constructor. Speed is 1, MinTime is 0 MaxTime is 0. Both MinTime and MaxTime are automatically adjusted by setKeyframe if the setKeyframe time is less than MinTime or greater than MaxTime. Default RepeatType is WRAP.
  • Method Details

    • getCurrentTime

      public double getCurrentTime()
    • getCurrentFrame

      public int getCurrentFrame()
    • getCurTime

      public double getCurTime()
      Gets the current time in the animation
      Returns:
      the current time in the animation
    • setCurTime

      public void setCurTime(double time)
      Sets the current time in the animation
      Parameters:
      time - The time this Controller should continue at
    • setMorphingMesh

      public void setMorphingMesh(Mesh morph)
      Sets the Mesh that will be physically changed by this KeyframeController
      Parameters:
      morph - The new mesh to morph
    • shallowSetMorphMesh

      public void shallowSetMorphMesh(Mesh morph)
    • setKeyframe

      public void setKeyframe(double time, Mesh shape)
      Tells the controller to change its morphMesh to shape at time seconds. Time must be >=0 and shape must be non-null and shape must have the same number of vertexes as the current shape. If not, then nothing happens. It is also required that setMorphingMesh(Mesh) is called before setKeyframe. It is assumed that shape.indices == morphMesh.indices, otherwise morphing may look funny
      Parameters:
      time - The time for the change
      shape - The new shape at that time
    • setSmoothTranslation

      public void setSmoothTranslation(float newTimeToReach, float translationLen, float newBeginTime, float newEndTime)
      This function will do a smooth translation between a keframe's current look, to the look directly at newTimeToReach. It takes translationLen time (in seconds) to do that translation, and once translated will animate like normal between newBeginTime and newEndTime

      This would be useful for example when a figure stops running and tries to raise an arm. Instead of "teleporting" to the raise-arm animation beginning, a smooth translation can occur.
      Parameters:
      newTimeToReach - The time to reach.
      translationLen - How long it takes
      newBeginTime - The new cycle beginning time
      newEndTime - The new cycle ending time.
    • setNewAnimationTimes

      public void setNewAnimationTimes(double newBeginTime, double newEndTime)
      Sets the new animation boundaries for this controller. This will start at newBeginTime and proceed in the direction of newEndTime (either forwards or backwards). If both are the same, then the animation is set to their time and turned off, otherwise the animation is turned on to start the animation acording to the repeat type. If either BeginTime or EndTime are invalid times (less than 0 or greater than the maximum set keyframe time) then a warning is set and nothing happens.
      It is suggested that this function be called if new animation boundaries need to be set, instead of setMinTime and setMaxTime directly.
      Parameters:
      newBeginTime - The starting time
      newEndTime - The ending time
    • update

      public void update(double time, T caller)
      As defined in Controller
      Specified by:
      update in interface SpatialController<T extends Spatial>
      Specified by:
      update in class ComplexSpatialController<T extends Spatial>
      Parameters:
      time - as defined in Controller
      caller - The spatial currently executing this controller.
    • updateBounding

      protected void updateBounding()
      Updates the bounding volume of the morph mesh
    • setUpdateBounding

      public void setUpdateBounding(boolean update)
      If true, the model's bounding volume will be updated every frame. If false, it will not.
      Parameters:
      update - The new update model volume per frame value.
    • isUpdateBounding

      public boolean isUpdateBounding()
      Returns true if the model's bounding volume is being updated every frame.
      Returns:
      True if bounding volume is updating.
    • setInterpTex

      public void setInterpTex(boolean interpTex)
    • isInterpTex

      public boolean isInterpTex()
    • setBlendTime

      public void setBlendTime(float blendTime)
      If repeat type RT_WRAP is set, after reaching the last frame of the currently set animation maxTime (see Controller.setMaxTime), there will be an additional blendTime seconds long phase inserted, morphing from the last frame to the first.
      Parameters:
      blendTime - The blend time to set
    • getBlendTime

      public float getBlendTime()
      Gets the currently set blending time for smooth animation transitions
      Returns:
      The current blend time
      See Also:
    • getMorphMesh

      public Mesh getMorphMesh()
    • getClassTag

      public Class<? extends KeyframeController> getClassTag()
      Specified by:
      getClassTag in interface Savable
      Overrides:
      getClassTag in class ComplexSpatialController<T extends Spatial>
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class ComplexSpatialController<T extends Spatial>
      Throws:
      IOException
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class ComplexSpatialController<T extends Spatial>
      Throws:
      IOException