/*
This example illustrates how to create an fcurve with
the SI3D style for constraining tangents.
*/
// Create a null
Application.NewScene( "", false );
var nullobj = ActiveSceneRoot.AddNull();
// Get the posx, posy parameters from the null
var posx = nullobj.posx;
var posy = nullobj.posy;
// Create an fcurve on posx, posy
var fc1 = posx.AddFCurve();
var fc2 = posy.AddFCurve();
// Define the number of keys
var nbkeys = 100;
// Start editing the fcurves
fc1.BeginEdit();
fc2.BeginEdit();
// Set the style of fc1 to SI3D style
fc1.SI3DStyle = true;
var tangents = new Array( nbkeys * 4 );
// Add keys to the fcurve
for ( i=0, j=0; i<nbkeys; i++, j+=4 )
{
val = (Math.cos( (i+1)/10 ) * 100);
fc1.AddKey( i, val );
fc2.AddKey( i, val );
tangents[j] = 0;
tangents[j+1] = 0;
tangents[j+2] = 0;
tangents[j+3] = 0;
}
// Set the tangent to zero to illustrate the difference
// between the Softimage & SI|3D styles
fc1.SetKeyTangents(tangents);
fc2.SetKeyTangents(tangents);
// End editing the fcurve and put undo event onto the
// undo/redo stack
fc1.EndEdit();
fc2.EndEdit();
// Print the key tangents from both curves to compare
var key1;
var key2;
for ( i=0; i<nbkeys; i++ )
{
key1 = fc1.GetKeyAtIndex(i);
key2 = fc2.GetKeyAtIndex(i);
str = "fc1: " + key1.lefttanx + ","+ key1.lefttany + ","+ key1.righttanx + ","+ key1.righttany;
str += " fc2: " + key2.lefttanx + ","+ key2.lefttany + ","+ key2.righttanx + ","+ key2.righttany;
LogMessage(str);
}
// Outputs:
//INFO : fc1: 0,0,0.3333333333333333,0 fc2: 0,0,0,0
//INFO : fc1: -0.33333333333333326,0,0.33333333333333326,0 fc2: 0,0,0,0
//INFO : fc1: -0.33333333333333326,0,0.3333333333333335,0 fc2: 0,0,0,0
// etc.
//INFO : fc1: -0.3333333333333343,0,0.3333333333333343,0 fc2: 0,0,0,0
//INFO : fc1: -0.3333333333333343,0,0.3333333333333343,0 fc2: 0,0,0,0
//INFO : fc1: -0.3333333333333343,0,0,0 fc2: 0,0,0,0 |