KeyframeTrack (object)

A sequence of keyframes defining animation over time.

The KeyframeTrack represents an animation curve storing a list of keyframe. A KeyframeTrack can be evaluated using a time parameter, generating a Scalar value. The keys in the keyframe track are always stored in chronological order.

参考

Keyframe

/*
** Example: keyframeTrack.kl
*/

require Animation;

operator entry(){

    KeyframeTrack track = KeyframeTrack('track', Color(1.0, 0.0, 0.0));

    track.addKey(Keyframe(0.0, 0.0, Vec2(0.0, 0.0), Vec2(0.333, 0.0)));
    track.addKey(Keyframe(2.0, 50.0, Vec2(-0.5, 25.0), Vec2(0.5, 25.0)));
    track.addKey(Keyframe(4.0, 0.0, Vec2(-0.333, 0.0), Vec2(0.333, 0.0)));

    Integer keyIndex;
    for(Integer i=0; i<=20; i++){
        Scalar time = Math_linearInterpolate(0.0, 4.0, Scalar(i)/20.0);
        Scalar value = track.evaluate(time, keyIndex);
        report("time:" + time + " value:" + value);
    }
}

/*
** Output:

time:+0.0 value:+0.0
time:+0.2 value:+0.798225
time:+0.4 value:+3.329768
time:+0.6 value:+7.601063
time:+0.8 value:+13.26752
time:+1.0 value:+19.73493
time:+1.2 value:+26.42404
time:+1.4 value:+32.94145
time:+1.6 value:+39.08389
time:+1.8 value:+44.77364
time:+2.0 value:+50.0
time:+2.2 value:+53.83283
time:+2.4 value:+55.0989
time:+2.6 value:+53.45285
time:+2.8 value:+48.63787
time:+3.0 value:+40.68987
time:+3.2 value:+30.27007
time:+3.4 value:+18.94325
time:+3.6 value:+8.941275
time:+3.8 value:+2.278844
time:+4.0 value:+0.0

*/

One way to generate keyframes on a KeyframeTrack, is to call setValue on the keyframe track passing in a value to store. This value is used to either update an existing key if one exists at the specified time, or add a new key at the specified time in the track.

/*
** Example: keyframeTrack_setValue.kl
*/

require Animation;

operator entry(){

    KeyframeTrack track = KeyframeTrack('track', Color(1.0, 0.0, 0.0));

    track.setValue(0.0, 0.0);
    track.setValue(2.0, 50.0);
    track.setValue(4.0, 0.0);
    track.setValue(2.0, 20.0); // Update an existing key

    report(track.getDesc());

    Integer keyIndex;
    for(Integer i=0; i<=10; i++){
        Scalar time = Math_linearInterpolate(0.0, 4.0, Scalar(i)/10.0);
        Scalar value = track.evaluate(time, keyIndex);
        report("time:" + time + " value:" + value);
    }
}

/*
** Output:

KeyframeTrack { 
  name: "track",
  color: {r:+1.0,g:+0.0,b:+0.0,a:+1.0},
  defaultValue: +0.0,
  numKeys:3,
  keys:[ 
    Keyframe { 
      time: +0.0
      value: +0.0
      interpolation: Bezier
      inTangent: {x:-0.333,y:+0.0}
      outTangent: {x:+0.333,y:+0.0}
    },
    Keyframe { 
      time: +2.0
      value: +20.0
      interpolation: Bezier
      inTangent: {x:-0.333,y:+0.0}
      outTangent: {x:+0.333,y:+0.0}
    },
    Keyframe { 
      time: +4.0
      value: +0.0
      interpolation: Bezier
      inTangent: {x:-0.333,y:+0.0}
      outTangent: {x:+0.333,y:+0.0}
    },
  ]
}
time:+0.0 value:+0.0
time:+0.4 value:+2.081786
time:+0.8 value:+7.041295
time:+1.2 value:+12.95853
time:+1.6 value:+17.91809
time:+2.0 value:+20.0
time:+2.4 value:+17.91821
time:+2.8 value:+12.9587
time:+3.2 value:+7.041466
time:+3.6 value:+2.0819
time:+4.0 value:+0.0

*/

KeyframeTrack KeyframeTrack KeyframeTrack IKeyframeTrack IKeyframeTrack KeyframeTrack->IKeyframeTrack

Members

String name  
Color color  
Scalar defaultValue  
UInt32 defaultInterpolation  
Keyframe[] keys  

Methods

  KeyframeTrack ( in KeyframeTrack other )
  KeyframeTrack ( in String name, in Color color )
  KeyframeTrack ( in String name, in Color color, in Scalar defaultValue )
  KeyframeTrack ( in String name, in Color color, in Scalar defaultValue, in UInt32 defaultInterpolation )
  KeyframeTrack ()
  addKey ! ( in Keyframe key )
  addKey ! ( in Scalar time, in Scalar value )
  clear ! ()
KeyframeTrack clone ? ()
Scalar evaluate ? ( in Scalar time )
Scalar evaluate ? ( in Scalar time, out Integer keyIndex )
String getDesc ? ( in String indent, in Boolean includeKeys )
String getDesc ? ()
String getName ? ()
UInt32 setValue ! ( in Scalar time, in Scalar value )

Methods in detail

KeyframeTrack ( in KeyframeTrack other )

copy constructor


KeyframeTrack ( in String name, in Color color )

constructor taking a track name, a color. 0.0 is used as the default value along with bezier interpolation.


KeyframeTrack ( in String name, in Color color, in Scalar defaultValue )

constructor taking a track name, a color, the default value. bezier interpolation is used

name The name of the KeyframeTrack.
name The color of the KeyframeTrack. Used when displaying the track in a curve editor.
name The value of the curve to use when it contains zero keyframes.
name The default interpollation method to assign new keys when they are generated.


KeyframeTrack ( in String name, in Color color, in Scalar defaultValue, in UInt32 defaultInterpolation )

constructor taking a track name, a color, the default value and the default key frame interpolation

name The name of the KeyframeTrack.
name The color of the KeyframeTrack. Used when displaying the track in a curve editor.
name The value of the curve to use when it contains zero keyframes.
name The default interpollation method to assign new keys when they are generated.


KeyframeTrack ()

default constructor


KeyframeTrack.addKey! ( in Keyframe key )

Adds a key frame to the track. The key is pushed to the end or injected depending on its time value, maintinging the chronological order of the keys.


KeyframeTrack.addKey! ( in Scalar time, in Scalar value )

Adds a new key to the track at the given time and value.


KeyframeTrack.clear! ()

clears the content of the KeyframeTrack, removing all keyframes. The KeyframeTrack will return the default value if evaluated.


KeyframeTrack KeyframeTrack.clone? ()

clone method


Scalar KeyframeTrack.evaluate? ( in Scalar time )

Evaluate the curve at a given time without passing the cached keyindex. This method is slower because the keys array must be searched every update for the pair of keys to be interpolated. Provide a keyIndex cache to speed up evaluations

time The time to evaluate the track.


Scalar KeyframeTrack.evaluate? ( in Scalar time, out Integer keyIndex )

Evaluate the curve at a given time returning the value of the track. speeds up subsequent evaluations by enabling incremental searching of the track for the next key in the sequence.

time The time to evaluate the track.


String KeyframeTrack.getDesc? ( in String indent, in Boolean includeKeys )

Generates a Description string of this KeyframeTrack.

indent The indentation to use when generating the string.


String KeyframeTrack.getDesc? ()

Generates a Description string of this KeyframeTrack.


String KeyframeTrack.getName? ()

Returns the name of the KeyframeTrack.


UInt32 KeyframeTrack.setValue! ( in Scalar time, in Scalar value )

Set the value of the curve at a given time, potentially generating new keys, if a key does not exist at the given time, or

time The time to set the value of the track.
value The value to store in the track.