Keyframe (struct)

A sequence of keyframes defining animation over time.

The keyframe represents a single control key on an keyframetrack, which is essentially an animation curve. A keyframe provide various interpolation methods from keyframe to the next.

When interpolating Bezier keyframes, the tangent values are defined as a gradient and fraction pair. The tangent x value is the fraction between this key and the next. A value of 0.333 generates a handle that stretches one third the distance from this key to the next. The tangent y value is the gradient of the handle. A value of 0.0 creates a flat handle, and a value of 1.0 generates a handle whose slope is 45 degrees.

Storing keyframe handles as fractions and gradients is consistent with the major DCCs, and ensures that the curve shape is maintained as the keys are edited in the curve editor.

参考

KeyframeTrack

/*
** Example: keyframe.kl
*/

require Animation, Util;

operator entry(){

    // create two keys using Bezier Interpolation
    Keyframe keyA(0.0, 0.0, Vec2(-0.333, 0.0), Vec2(-0.333, 0.0));
    Keyframe keyB(100.0, 4.0);

    // interpolate the keys for a given time
    report("Bezier Interpolation : value:" + unitTestPrint(keyA.interpolate(keyB, 2.0)));

    keyA.interpolation = Keyframe_Interpolation_Linear;
    keyB.interpolation = Keyframe_Interpolation_Linear;
    report("Linear Interpolation : value:" + unitTestPrint(keyA.interpolate(keyB, 2.0)));

 	keyA.interpolation = Keyframe_Interpolation_Constant;
    keyB.interpolation = Keyframe_Interpolation_Constant;
    report("Constant Interpolation : value:" + unitTestPrint(keyA.interpolate(keyB, 2.0)));

    keyA.interpolation = Keyframe_Interpolation_Constant_Next;
    keyB.interpolation = Keyframe_Interpolation_Constant_Next;
    report("Constant_Next Interpolation : value:" + unitTestPrint(keyA.interpolate(keyB, 2.0)));
}

/*
** Output:

Bezier Interpolation : value:+0.117782
Linear Interpolation : value:+0.080001
Constant Interpolation : value:+0.0
Constant_Next Interpolation : value:+4.0

*/

Keyframe Keyframe Keyframe

Members

Scalar time  
Scalar value  
Integer interpolation  
Vec2 inTangent  
Vec2 outTangent  

Methods

  Keyframe ( in Keyframe other )
  Keyframe ( in Scalar time, in Scalar value )
  Keyframe ( in Scalar time, in Scalar value, in Vec2 inTangent, in Vec2 outTangent )
  Keyframe ( in Scalar time, in Scalar value, in Vec2 inTangent, in Vec2 outTangent, in Integer interpolation )
  Keyframe ()
Keyframe clone ? ()
String getDesc ? ( in String indent )
String getDesc ? ()
Scalar interpolate ? ( in Keyframe key2, in Scalar t )
Scalar linearInterpolate ? ( in Keyframe key2, in Scalar b )

Methods in detail

Keyframe ( in Keyframe other )

copy constructor


Keyframe ( in Scalar time, in Scalar value )

constructor providing time and value. tangents are zero length, interpolation is set to linear.


Keyframe ( in Scalar time, in Scalar value, in Vec2 inTangent, in Vec2 outTangent )

constructor providing time, value and both tangents. interpolation is set to bezier.


Keyframe ( in Scalar time, in Scalar value, in Vec2 inTangent, in Vec2 outTangent, in Integer interpolation )

constructor providing time, value, both tangent and the interpolation type


Keyframe ()

default constructor, time, value, tangents are zeroed. interpolation is linear.


Keyframe Keyframe.clone? ()

clone method


String Keyframe.getDesc? ( in String indent )

Generates a Description string of this keyframe.

indent The indentation to use when generating the string.


String Keyframe.getDesc? ()

Generates a Description string of this keyframe.


Scalar Keyframe.interpolate? ( in Keyframe key2, in Scalar t )

interpolates this key with another one provided a (absolute) time value


Scalar Keyframe.linearInterpolate? ( in Keyframe key2, in Scalar b )

interpolates this key with another one provided linear blend value (0.0 to 1.0)