/*
This JScript example illustrates how to use the FCurve.KeyExists method
to find keys on an fcurve.
*/
// Create a null
Application.NewScene( null, false );
var nullobj = ActiveSceneRoot.AddNull();
// Create an fcurve on the posx parameter from the null
var fc = nullobj.posx.AddFCurve();
// Define some random keys
var nbkeys = 10;
var arraysize = nbkeys * 2;
var keys = new Array( 2 * nbkeys );
var i = 0, empty;
offset = -50;
for ( i=0; i<arraysize; i+=2 )
{
keys[i] = offset + Math.random() * 100 ;
keys[i+1] = Math.cos( Math.random() ) * 10;
}
keys.sort();
// Set the keys on the fcurve
fc.SetKeys( keys );
// Find the random keys
for ( i=-50; i<50; i++ )
{
if ( fc.KeyExists(i) )
{
LogMessage( "found key near frame " + i );
}
var ckeys = fc.GetNumKeys( i - 0.5, i + 0.5 )
if ( ckeys > 1 )
{
LogMessage( "found "+ ckeys + " keys around frame " + i );
}
}
// Outputs:
//INFO : found key near frame -21
//INFO : found key near frame -20
//INFO : found key near frame -7
//INFO : found key near frame -6
//INFO : found key near frame -5
//INFO : found key near frame -4
//INFO : found 2 keys around frame -4
//INFO : found key near frame -3
//INFO : found key near frame -2
//INFO : found key near frame 5
//INFO : found key near frame 6
//INFO : found key near frame 7
//INFO : found key near frame 8
//INFO : found key near frame 9
//INFO : found key near frame 10 |