com.jmex.model.animation
Class KeyframeController

java.lang.Object
  extended by com.jme.scene.Controller
      extended by com.jmex.model.animation.KeyframeController
All Implemented Interfaces:
Savable, java.io.Serializable

public class KeyframeController
extends Controller

Started Date: Jun 12, 2004

Class can do linear interpolation of a TriMesh between units of time. Similar to VertexKeyframeController but interpolates float units of time instead of integer keyframes.

Controller.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

Controller.setMinTime(float) and Controller.setMaxTime(float) both define the bounds that KeyframeController should follow. It is the programmer's responsiblity 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 TriMesh it belongs to, so it is recomended to only attach this controller to the TriMesh it animates.

Version:
$Id: KeyframeController.java 4132 2009-03-19 20:34:56Z blaine.dev $
Author:
Jack Lindamood, kevglass (parts), hevee (blend time)
See Also:
Serialized Form

Nested Class Summary
static class KeyframeController.PointInTime
          This class defines a point in time that states morphShape should look like newShape at time seconds
 
Field Summary
 java.util.ArrayList<KeyframeController.PointInTime> keyframes
          An array of PointInTime s that defines the animation
 
Fields inherited from class com.jme.scene.Controller
RT_CLAMP, RT_CYCLE, RT_WRAP
 
Constructor Summary
KeyframeController()
          Default constructor.
 
Method Summary
 float getBlendTime()
          Gets the currently set blending time for smooth animation transitions
 int getCurrentFrame()
           
 float getCurrentTime()
           
 float getCurTime()
          Gets the current time in the animation
 boolean getModelUpdate()
          Returns true if the model's bounding volume is being updated every frame.
 TriMesh getMorphMesh()
           
 void read(JMEImporter im)
           
 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.
 void setCurTime(float time)
          Sets the current time in the animation
 void setKeyframe(float time, TriMesh shape)
          Tells the controller to change its morphMesh to shape at time seconds.
 void setModelUpdate(boolean update)
          If true, the model's bounding volume will be updated every frame.
 void setMorphingMesh(TriMesh morph)
          Sets the Mesh that will be physically changed by this KeyframeController
 void setNewAnimationTimes(float newBeginTime, float newEndTime)
          Sets the new animation boundaries for this controller.
 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.
 void shallowSetMorphMesh(TriMesh morph)
           
 void update(float time)
          As defined in Controller
 void write(JMEExporter ex)
           
 
Methods inherited from class com.jme.scene.Controller
getClassTag, getControllerValues, getMaxTime, getMinTime, getRepeatType, getSpeed, isActive, setActive, setControllerValues, setMaxTime, setMinTime, setRepeatType, setSpeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyframes

public transient java.util.ArrayList<KeyframeController.PointInTime> keyframes
An array of PointInTime s that defines the animation

Constructor Detail

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 RT_WRAP.

Method Detail

getCurrentTime

public float getCurrentTime()

getCurrentFrame

public int getCurrentFrame()

getCurTime

public float getCurTime()
Gets the current time in the animation


setCurTime

public void setCurTime(float time)
Sets the current time in the animation

Parameters:
time - The time this Controller should continue at

setMorphingMesh

public void setMorphingMesh(TriMesh morph)
Sets the Mesh that will be physically changed by this KeyframeController

Parameters:
morph - The new mesh to morph

shallowSetMorphMesh

public void shallowSetMorphMesh(TriMesh morph)

setKeyframe

public void setKeyframe(float time,
                        TriMesh 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(TriMesh) 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 sec) to do that translation, and once translated will animate like normal between newBeginTime and newEndTime

This would be usefull for example when a figure stops running and tries to raise an arm. Instead of "teleporting" to the raise-arm animation begining, a smooth translation can occur.

Parameters:
newTimeToReach - The time to reach.
translationLen - How long it takes
newBeginTime - The new cycle begining time
newEndTime - The new cycle ending time.

setNewAnimationTimes

public void setNewAnimationTimes(float newBeginTime,
                                 float 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(float time)
As defined in Controller

Specified by:
update in class Controller
Parameters:
time - as defined in Controller

setModelUpdate

public void setModelUpdate(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.

getModelUpdate

public boolean getModelUpdate()
Returns true if the model's bounding volume is being updated every frame.

Returns:
True if bounding volume is updating.

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:
setBlendTime(float blendTime)

getMorphMesh

public TriMesh getMorphMesh()

write

public void write(JMEExporter ex)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class Controller
Throws:
java.io.IOException

read

public void read(JMEImporter im)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class Controller
Throws:
java.io.IOException