/*
This example demonstrates how to set up and populate an fcurve
using the z-position values from an animation fcurve created
by setting keys on a null. The newly created z-position fcurve
is then applied to a sphere's z-position.
*/
NewScene(null, false);
// Get a null and animate it.
var oRoot = Application.ActiveProject.ActiveScene.Root;
var oNull = oRoot.AddPrimitive("Null");
SaveKey(oNull + ".kine.local.posx", 1);
SaveKey(oNull + ".kine.local.posy", 1);
SaveKey(oNull + ".kine.local.posz", 1);
SetValue("PlayControl.Current", 50);
Translate(oNull, -14, 0.5, -12, siRelative, siView, siObj, siXYZ);
SaveKey(oNull + ".kine.local.posx", 50);
SaveKey(oNull + ".kine.local.posy", 50);
SaveKey(oNull + ".kine.local.posz", 50);
// Loop through the animation and store the z values into a key array for AddFCurve2 (aZKeys).
var oPosVector = XSIMath.CreateVector3();
var aZKeys = new Array(50 * 2+1);
for ( i=0; i<=50; i++ )
{
var oCurrentTransform = oNull.Kinematics.Global.Transform(i);
oCurrentTransform.GetTranslation(oPosVector);
aZKeys[i*2] = i;
aZKeys[i*2+1] = oPosVector.z;
}
// Now get a sphere and place the FCurves on it.
var oSphere = oRoot.AddGeometry("Sphere", "MeshSurface");
oSphere.Kinematics.Global.Parameters("posz").AddFCurve2(aZKeys); |