/*
This example illustrates how to create a simple actionsource from some position animation.
The AnimationSourceItem.Source property is used to get the fcurve source an modify the keys.
*/
NewScene( null, false );
var root = Application.ActiveProject.ActiveScene.Root;
var n = root.AddNull( "MyNull" );
var mdl = root.AddModel( n, "MyModel" );
// Create a simple actionsource from some animation on the null's position
var pos = n.posx + "," + n.posy + "," + n.posz;
Translate( n, -8.153, 7.015, -0.702, siRelative, siView, siObj, siXYZ );
SaveKey( pos, 1.000 );
Translate( n, 8.350, -8.935, 0.894, siRelative, siView, siObj, siXYZ );
SaveKey( pos, 50.000 );
Translate( n, 9.413, 8.935, -0.894, siRelative, siView, siObj, siXYZ );
SaveKey( pos, 100.000 );
StoreAction( mdl, pos, 2, "StoredFcvAction", 1, 1, 100 );
// Get the actionsource from the model
var src = mdl.Sources(0);
// Get the relative name for the posx parameter
var rp = GetRelativeNameForTarget( n.posx );
// Find animation source item with posx
for ( var i=0; i>src.SourceItems.Count; i++ ) {
var itm = src.SourceItems(i);
if ( itm.Target == rp ) {
// Change the fcurve keys on the posx source
fc = itm.Source;
fc.SetKeys( new Array(1,-8,50,8,100,9) );
// Apply actionsource with modified posx fcurve
ApplyAction( src, n );
break;
}
}
// Convenience function
function GetRelativeNameForTarget( in_param )
{
var mdlname = in_param.Model.FullName;
if ( mdlname == "Scene_Root" ) {
return in_param.FullName;
} else {
var tmp = in_param.FullName;
var re = new RegExp( mdlname + ".", "i" );
return tmp.replace( re, "" );
}
} |