v3.0
指定されたインデックスでのキーの時間(フレーム)および値を設定します。
注:該当の新しいフレーム値に別のキーがすでに存在する場合は、'Cannot set key'(E_FAIL)エラーが発生します。
インデックスが範囲外の場合は、'Invalid argument'(E_INVALIDARG)エラーが発生します。
F カーブがロックされている場合は、'Access Denied'(E_ACCESSDENIED)エラーが発生します。
FCurve.SetKey( Int32 in_Index, Object in_Frame, Object in_Value, Boolean in_OverrideKeyLock ); |
FCurve.SetKey( Index, Frame, Value, [OverrideKeyLock] ); |
| パラメータ | タイプ | 説明 |
|---|---|---|
| Index | Long | キーのインデックス。0~(キーの数から1を引いた数)の間の数字である必要があります。 |
| Frame | Variant | 新しいキーの時間(フレーム) |
| Value | Variant |
新しいキーの値。次のように、値の種類を使用します。 標準およびロー F カーブには、Double 値(VT_R8)を使用します 整数 F カーブには、LONG (VT_I4)を使用します。ブール F カーブには、Variant Bool 値(VT_BOOL,VARIANT_TRUE,V RIANT_FALSE)を使用します。 |
| OverrideKeyLock | Boolean |
FCurveKey.Locked 値を上書きして、強制的にキーを削除します。 デフォルト値: false |
/*
This JScript example illustrates how to use the FCurve.SetKey method
to translate keys.
*/
// 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()
// Create a custom property set on the null
var cpset = nullobj.AddCustomProperty( "CustomPSet" );
var empty;
var x = cpset.AddParameter( "X", siDouble, empty, siAnimatable, "X", "X", empty, 5, 0, 5 );
var y = cpset.AddParameter( "Y", siInt4, empty, siAnimatable, "Y", "Y", empty, 5, 0, 5 );
var fc1 = x.AddFCurve();
var fc2 = y.AddFCurve();
// Start editing the fcurves
fc1.BeginEdit();
fc2.BeginEdit();
// Add keys to the fcurves
fc1.Resample();
fc2.Resample();
// Assign some values to keys
var val, X;
for ( i=0; i<fc1.GetNumKeys(); i++ )
{
X = ( (i+1) - 10 )/10;
fc1.GetKeyAtIndex(i).Value = Math.atan( X / Sqr( -X * X + 1 ) );
// Copy the value to fc2 for comparison
fc2.GetKeyAtIndex(i).Value = fc1.GetKeyValue(i);
}
var ckeys = fc1.GetNumKeys();
var tangents = new Array( ckeys * 4 );
var itan = 0;
// Save tangents
for ( i=0; i<ckeys; i++ )
{
var key = fc1.GetKeyAtIndex(i);
// Save the tangents
tangents[itan++] = key.LeftTanX;
tangents[itan++] = key.LeftTanY;
tangents[itan++] = key.RightTanX;
tangents[itan++] = key.RightTanY;
}
// Translate the keys
for ( i=0; i<ckeys; i++ )
{
frame = fc1.GetKeyFrame(i);
val = fc1.GetKeyValue(i);
key = fc1.GetKey(frame);
fc1.SetKey( i, frame-100, val * 1.25 );
}
// Reset the tangents
fc1.SetKeyTangents(tangents);
// End editing the fcurves
fc1.EndEdit();
fc2.EndEdit();
// Utility function
function Sqr( x )
{
return x * x;
} |