com.jme.animation
Class KeyframeController

java.lang.Object
  extended bycom.jme.scene.Controller
      extended bycom.jme.animation.KeyframeController
All Implemented Interfaces:
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,v 1.11 2005/03/27 18:58:08 Mojomonkey Exp $
Author:
Jack Lindamood Parts by kevglass
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 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
 boolean getModelUpdate()
          Returns true if the model's bounding volume is being updated every frame.
 TriMesh getMorphMesh()
           
 Controller putClone(Controller store, CloneCreator properties)
          This function should be overridden by any Spatial objects that want their Controller cloned by a CloneCreator.
 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
 
Methods inherited from class com.jme.scene.Controller
getMaxTime, getMinTime, getRepeatType, getSpeed, isActive, setActive, 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 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

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.

getMorphMesh

public TriMesh getMorphMesh()

putClone

public Controller putClone(Controller store,
                           CloneCreator properties)
This function should be overridden by any Spatial objects that want their Controller cloned by a CloneCreator. It stores into "store" the properties of this Controller.

Overrides:
putClone in class Controller
Parameters:
store - The Controller to store properties into. If null, null is returned.
properties - The CloneCreator controlling how things should be copied into the store Controller.
Returns:
The store controller, after a copy.