com.jme3.animation
Class AnimationFactory

java.lang.Object
  extended by com.jme3.animation.AnimationFactory

public class AnimationFactory
extends java.lang.Object

A convenience class to easily setup a spatial keyframed animation you can add some keyFrames for a given time or a given keyFrameIndex, for translation rotation and scale. The animationHelper will then generate an appropriate SpatialAnimation by interpolating values between the keyFrames.

Usage is :
- Create the AnimationHelper
- add some keyFrames
- call the buildAnimation() method that will retruna new Animation
- add the generated Animation to any existing AnimationControl


Note that the first keyFrame (index 0) is defaulted with the identy transforms. If you want to change that you have to replace this keyFrame with any transform you want.


Nested Class Summary
protected  class AnimationFactory.Rotation
          Inner Rotation type class to kep track on a rotation Euler angle
 
Field Summary
protected  float duration
          Animation duration in seconds
protected  int fps
          frames per seconds
protected  AnimationFactory.Rotation[] keyFramesRotation
           
protected  Vector3f[] keyFramesScale
           
protected  Vector3f[] keyFramesTranslation
          The map of keyFrames to compute the animation.
protected  java.lang.String name
          Name of the animation
protected  Quaternion[] rotations
          rotation array for this animation
protected  Vector3f[] scales
          scales array for this animation
protected  float[] times
          Time array for this animation
protected  int totalFrames
          total number of frames
protected  float tpf
          time per frame
protected  Vector3f[] translations
          Translation array for this animation
 
Constructor Summary
AnimationFactory(float duration, java.lang.String name)
          Creates and AnimationHelper
AnimationFactory(float duration, java.lang.String name, int fps)
          Creates and AnimationHelper
 
Method Summary
 void addKeyFrameRotation(int keyFrameIndex, Quaternion rotation)
          Adds a key frame for the given rotation at the given keyFrame index
This can't be used if the interpolated angle is higher than PI (180°)
Use addKeyFrameRotationAngles(int keyFrameIndex, float x, float y, float z) instead that uses Euler angles rotations.
 void addKeyFrameRotationAngles(int keyFrameIndex, float x, float y, float z)
          Adds a key frame for the given rotation at the given key frame index.
Rotation is expressed by Euler angles values in radians.
Note that the generated rotation will be stored as a quaternion and interpolated using a spherical linear interpolation (slerp)
Hence, this method may create intermediate keyFrames if the interpolation angle is higher than PI to ensure continuity in animation
 void addKeyFrameScale(int keyFrameIndex, Vector3f scale)
          Adds a key frame for the given scale at the given keyFrame index
 void addKeyFrameTransform(int keyFrameIndex, Transform transform)
          Adds a key frame for the given Transform at the given keyFrame index
 void addKeyFrameTranslation(int keyFrameIndex, Vector3f translation)
          Adds a key frame for the given translation at the given keyFrame index
 void addTimeRotation(float time, Quaternion rotation)
          Adds a key frame for the given rotation at the given time
This can't be used if the interpolated angle is higher than PI (180°)
Use addTimeRotationAngles(float time, float x, float y, float z) instead that uses Euler angles rotations.
*
 void addTimeRotationAngles(float time, float x, float y, float z)
          Adds a key frame for the given rotation at the given time.
Rotation is expressed by Euler angles values in radians.
Note that the generated rotation will be stored as a quaternion and interpolated using a spherical linear interpolation (slerp)
Hence, this method may create intermediate keyFrames if the interpolation angle is higher than PI to ensure continuity in animation
 void addTimeScale(float time, Vector3f scale)
          Adds a key frame for the given scale at the given time
 void addTimeTransform(float time, Transform transform)
          Adds a key frame for the given Transform at the given time
 void addTimeTranslation(float time, Vector3f translation)
          Adds a key frame for the given translation at the given time
 Animation buildAnimation()
          Creates an Animation based on the keyFrames previously added to the helper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Name of the animation


fps

protected int fps
frames per seconds


duration

protected float duration
Animation duration in seconds


totalFrames

protected int totalFrames
total number of frames


tpf

protected float tpf
time per frame


times

protected float[] times
Time array for this animation


translations

protected Vector3f[] translations
Translation array for this animation


rotations

protected Quaternion[] rotations
rotation array for this animation


scales

protected Vector3f[] scales
scales array for this animation


keyFramesTranslation

protected Vector3f[] keyFramesTranslation
The map of keyFrames to compute the animation. The key is the index of the frame


keyFramesScale

protected Vector3f[] keyFramesScale

keyFramesRotation

protected AnimationFactory.Rotation[] keyFramesRotation
Constructor Detail

AnimationFactory

public AnimationFactory(float duration,
                        java.lang.String name)
Creates and AnimationHelper

Parameters:
duration - the desired duration for the resulting animation
name - the name of the resulting animation

AnimationFactory

public AnimationFactory(float duration,
                        java.lang.String name,
                        int fps)
Creates and AnimationHelper

Parameters:
duration - the desired duration for the resulting animation
name - the name of the resulting animation
fps - the number of frames per second for this animation (default is 30)
Method Detail

addTimeTransform

public void addTimeTransform(float time,
                             Transform transform)
Adds a key frame for the given Transform at the given time

Parameters:
time - the time at which the keyFrame must be inserted
transform - the transforms to use for this keyFrame

addKeyFrameTransform

public void addKeyFrameTransform(int keyFrameIndex,
                                 Transform transform)
Adds a key frame for the given Transform at the given keyFrame index

Parameters:
keyFrameIndex - the index at which the keyFrame must be inserted
transform - the transforms to use for this keyFrame

addTimeTranslation

public void addTimeTranslation(float time,
                               Vector3f translation)
Adds a key frame for the given translation at the given time

Parameters:
time - the time at which the keyFrame must be inserted
translation - the translation to use for this keyFrame

addKeyFrameTranslation

public void addKeyFrameTranslation(int keyFrameIndex,
                                   Vector3f translation)
Adds a key frame for the given translation at the given keyFrame index

Parameters:
keyFrameIndex - the index at which the keyFrame must be inserted
translation - the translation to use for this keyFrame

addTimeRotation

public void addTimeRotation(float time,
                            Quaternion rotation)
Adds a key frame for the given rotation at the given time
This can't be used if the interpolated angle is higher than PI (180°)
Use addTimeRotationAngles(float time, float x, float y, float z) instead that uses Euler angles rotations.
*

Parameters:
time - the time at which the keyFrame must be inserted
rotation - the rotation Quaternion to use for this keyFrame
See Also:
addTimeRotationAngles(float time, float x, float y, float z)

addKeyFrameRotation

public void addKeyFrameRotation(int keyFrameIndex,
                                Quaternion rotation)
Adds a key frame for the given rotation at the given keyFrame index
This can't be used if the interpolated angle is higher than PI (180°)
Use addKeyFrameRotationAngles(int keyFrameIndex, float x, float y, float z) instead that uses Euler angles rotations.

Parameters:
keyFrameIndex - the index at which the keyFrame must be inserted
rotation - the rotation Quaternion to use for this keyFrame
See Also:
addKeyFrameRotationAngles(int keyFrameIndex, float x, float y, float z)

addTimeRotationAngles

public void addTimeRotationAngles(float time,
                                  float x,
                                  float y,
                                  float z)
Adds a key frame for the given rotation at the given time.
Rotation is expressed by Euler angles values in radians.
Note that the generated rotation will be stored as a quaternion and interpolated using a spherical linear interpolation (slerp)
Hence, this method may create intermediate keyFrames if the interpolation angle is higher than PI to ensure continuity in animation

Parameters:
time - the time at which the keyFrame must be inserted
x - the rotation around the x axis (aka yaw) in radians
y - the rotation around the y axis (aka roll) in radians
z - the rotation around the z axis (aka pitch) in radians

addKeyFrameRotationAngles

public void addKeyFrameRotationAngles(int keyFrameIndex,
                                      float x,
                                      float y,
                                      float z)
Adds a key frame for the given rotation at the given key frame index.
Rotation is expressed by Euler angles values in radians.
Note that the generated rotation will be stored as a quaternion and interpolated using a spherical linear interpolation (slerp)
Hence, this method may create intermediate keyFrames if the interpolation angle is higher than PI to ensure continuity in animation

Parameters:
keyFrameIndex - the index at which the keyFrame must be inserted
x - the rotation around the x axis (aka yaw) in radians
y - the rotation around the y axis (aka roll) in radians
z - the rotation around the z axis (aka pitch) in radians

addTimeScale

public void addTimeScale(float time,
                         Vector3f scale)
Adds a key frame for the given scale at the given time

Parameters:
time - the time at which the keyFrame must be inserted
scale - the scale to use for this keyFrame

addKeyFrameScale

public void addKeyFrameScale(int keyFrameIndex,
                             Vector3f scale)
Adds a key frame for the given scale at the given keyFrame index

Parameters:
keyFrameIndex - the index at which the keyFrame must be inserted
scale - the scale to use for this keyFrame

buildAnimation

public Animation buildAnimation()
Creates an Animation based on the keyFrames previously added to the helper.

Returns:
the generated animation