FCurve.Resample

Introduced

v3.0

Description

Resamples the fcurve, adding keys from startframe to endframe at the interval defined by the step.

A valid range is defined as:

startframe < endframe and step < 0.25 * ( endframe - startframe )

Note: If the fcurve is locked or if any keys in the interval are locked then the method raises an 'Access Denied' (E_ACCESSDENIED) error.

You can override the key locks by using the OverrideKeyLock argument.

C# Syntax

FCurve.Resample( Object in_StartFrame, Object in_EndFrame, Double in_Step, Boolean in_KeepExistingKeys, Boolean in_OverrideKeyLock );

Scripting Syntax

FCurve.Resample( [StartFrame], [EndFrame], [Step], [KeepExistingKeys], [OverrideKeyLock] );

Parameters

Parameter Type Description
StartFrame Variant The time in frames at which to start resampling.

Default Value: The first key frame on the fcurve or, if there are no keys, the playcontrol In frame value.

EndFrame Variant The time in frames at which to end resampling.

Default Value: The last key frame or, if there are no keys, the playcontrol Out frame value.

Step Double The interval in frames between each key.

Default Value: 1

KeepExistingKeys Boolean Do not remove keys in resampled range.

Default Value: false

OverrideKeyLock Boolean Override the FCurveKey.Locked value for existing keys in range and remove these keys if the KeepExistingKeys argument is set to false.

Default Value: false

Examples

JScript Example

/*
	This JScript examples illustrates how to the FCurve.Resample method
	to add a predetermined number of keys to an fcurve.
*/
// Create a null
Application.NewScene("", false);
var nullobj = ActiveSceneRoot.AddNull();
// Create an fcurve on the posx parameter from the null
var fc = nullobj.posx.AddFCurve();
// Define a number of keys
var nbkeys = 100;
var arraysize = nbkeys * 2;
var keys = new Array( 2 * nbkeys );
var i = 0, offset = -50;
// Generate some key data with a random distribution
for ( i=0; i<arraysize; i+=2 )
{
	v = Math.round( offset + Math.random() * 100 );
	keys[i] = v;
	keys[i+1] = v;
}
keys.sort();
for ( i=0; i<arraysize; i+=2 )
{
	keys[i+1] = Math.cos( (i+1) / 10 ) * 100;
}
// Set the keys onto the fcurve
fc.SetKeys( keys );
// Add the same keys to posy for comparision
nullobj.posy.AddFCurve().SetKeys( keys );
var empty;
// Resample the entire fcurve on posx and disregard the
// existing keys
fc.Resample( empty, empty, 5 );
LogMessage( "original curve : " + nullobj.posy.Source.GetNumKeys() 
	+ " resampled curve : " + nullobj.posx.Source.GetNumKeys() );
// The resampling method can also be used to add keys 
// to a empty fcurve
nullobj.posz.AddFCurve().Resample( -50,50 );
// Outputs:
//INFO : original curve : 64 resampled curve : 21

See Also

FCurve.AddKey FCurve.RemoveKeys FCurve.GetNumKeys FCurve.Smooth FCurve.Fit