KeyframeTrack.kl

Types

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

*/

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 )