AnimationSourceItem

Object Hierarchy | Related C++ Class: AnimationSourceItem

Inheritance

SIObject

AnimationSourceItem

Introduced

v1.5

Description

An ActionSource contains a collection of animation source items (AnimationSourceItemCollection) which is accessible via the ActionSource.SourceItems property.

The AnimationSourceItem provides access to the animation DataSource (for example, an FCurve) and its target (the parameter which the animation source drives).

One way to create action animation is to create an empty ActionSource and then populate it afterwards using the ActionSource.AddSourceItem method. In that case, you can add an FCurve or a StaticSource as the animation source using the AnimationSourceItem.SetAsFCurve and AnimationSourceItem.SetAsStatic methods.

Note: Starting from version 4.0, the SIObject.Type method returns a value contained in the siAnimationSourceItemType enumerator.

Methods

IsClassOf operator IsEqualTo operator SetAsFCurve SetAsStatic

Properties

Active Application Categories FullName operator
Help Name operator NestedObjects Origin
OriginPath Parent Source Target
Type operator      
       

Examples

1. VBScript Example

'
' This example illustrates how to access the fcurves inside a
' model's actionsource
'
NewScene , false
set oRoot = Application.ActiveProject.ActiveScene.Root
' These commands were cut and pasted from scripting history and modified to work in a script.
' The commands create a simple actionsource from some animation on the null's position
set oNull = GetPrim( "Null" )
strPosParams = oNull & ".kine.local.posx," & oNull & ".kine.local.posy," & oNull & ".kine.local.posz"
Translate oNull, -8.153, 7.015, -0.702, siRelative, siView, siObj, siXYZ
SaveKey strPosParams, 1.000
Translate oNull, 8.350, -8.935, 0.894, siRelative, siView, siObj, siXYZ
SaveKey strPosParams, 50.000
Translate oNull, 9.413, 8.935, -0.894, siRelative, siView, siObj, siXYZ
SaveKey strPosParams, 100.000
StoreAction oRoot, strPosParams, 2, "StoredFcvAction", True, 1, 100
' Get the ActionSource from the model
set oActionSource = oRoot.Sources("StoredFcvAction")
LogMessage oActionSource.Name
for each oSourceItem in oActionSource.SourceItems
	LogMessage vbTab & "target: " & oSourceItem.Target
	set oSource = oSourceItem.Source
	if TypeName(oSource) = "FCurve" then
		strKeys=""
		for each oKey in oSource.Keys
			if strKeys<>""then
				strKeys = strKeys & ","
			end if
			strKeys = strKeys & oKey.Time & "," & oKey.Value
		next
		LogMessage vbTab & "source: " & "fcurve keys(" & strKeys & ")"
	else
		LogMessage vbTab & "source ignored"
	end if
next
' Output of above script:
'INFO : StoredFcvAction
'INFO : 	target: null.kine.local.posx
'INFO : 	source: fcurve keys(1,-8.153,50,0.196999999999999,100,9.61)
'INFO : 	target: null.kine.local.posy
'INFO : 	source: fcurve keys(1,7.015,50,-1.92,100,7.015)
'INFO : 	target: null.kine.local.posz
'INFO : 	source: fcurve keys(1,-0.702,50,0.192,100,-0.702)

2. JScript Example

/*
	This example illustrates how to create an empty ActionSource using
	Model.AddActionSource, populate it with 2 static values and 1 fcurve 
	using ActionSource.AddSourceItem, and then replace the fcurve source 
	with a static value for the 2nd and change the static value for the 3rd 
	using AnimationSourceItem.SetAsStatic.
*/
NewScene( null, false );
// Get the scene root
var root = Application.ActiveSceneRoot;
// Create a null and get pointers to the pos parameters
var n = root.AddNull( "null");
var posx = n.posx; var rposx = GetRelativeName(posx);
var posy = n.posy; var rposy = GetRelativeName(posy);
var posz = n.posz; var rposz = GetRelativeName(posz);
// Create an empty actionsource and then populate it with static values
var src = root.AddActionSource( "StaticActionSource" );
var fc = MakeAnFCurve( n, "posy" );
src.AddSourceItem( rposx, 2.0 );	// static value 
src.AddSourceItem( rposy, fc );		// fcurve 
src.AddSourceItem( rposz );		// default static value = 0.0
// Now change the value on the posz parameter using SetAsStatic and change
// the posy parameter source to an fcurve
var animsrcitems = src.SourceItems;
for ( var i=0; i<animsrcitems.Count; i++ ) {
	var srcitem = animsrcitems(i);
	// Get a pointer to the source item (it can be either a StaticSource or an FCurve)
	var datasrc = srcitem.Source;
	if ( datasrc.IsClassOf(siFCurveID) ) {
		// Print the FCurve type
		Application.LogMessage( "AnimationSourceItem[" + i + "] (" + srcitem.Target 
			+ ") has " + datasrc.GetNumKeys() + " keys" );
	}
	if ( datasrc.IsClassOf(siStaticSourceID) ) {
		// Print the current value
		Application.LogMessage( "AnimationSourceItem[" + i + "] (" + srcitem.Target 
			+ ") has this static value: " + datasrc.Value );
	}
	// AnimationSourceItem.Target returns the RelativeName
	if ( srcitem.Target == rposy ) {
		srcitem.SetAsStatic( 1.0 );
		// Check for the new value (we know it's a StaticSource because we just set it)
		var datasrc = srcitem.Source;		// refresh
		Application.LogMessage( "New static value = " + datasrc.Value );
	}
	if ( srcitem.Target == rposz ) {
		srcitem.SetAsStatic( 1.5 );
		// Check for the new value (we know it's a StaticSource because we just set it)
		var datasrc = srcitem.Source;		// refresh
		Application.LogMessage( "New static value = " + datasrc.Value );
	}
}
//INFO : AnimationSourceItem[0] (null.kine.local.posx) has this static value: 2
//INFO : AnimationSourceItem[1] (null.kine.local.posy) has 4 keys
//INFO : New static value = 1
//INFO : AnimationSourceItem[2] (null.kine.local.posz) has this static value: 0
//INFO : New static value = 1.5
// Function to remove the name of the model from the FullName of the specified parameter.
// This is necessary when setting up a source that will later be used to instantiate a
// clip when the parameter lives under a model other than the Scene_Root.
function GetRelativeName( 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, "" );
	}
}
// Convenience function 
function MakeAnFCurve( in_obj, in_param )
{
	var p = in_obj.Kinematics.Local.Parameters( in_param );
	var fc = p.AddFCurve( siStandardFCurve );
	fc.AddKey( 1.0, 1.25 );
	fc.AddKey( 25.0, 2.0 );
	fc.AddKey( 40.0, 2.75 );
	fc.AddKey( 85.0, 0.0 );
	return fc;
}

3. JScript Example

// Simple example showing how to access action source items from a collection
	NewScene( false, false ) ;
	var cube = ActiveSceneRoot.AddPrimitive("Cube") ;
	var actionsource = StoreAction( null, "cube.kine.local.posx, cube.kine.local.posy, cube.kine.local.posz", null, "Test", null, 1, 5, null, null, null, 1);  
	var items = actionsource.SourceItems;
	// Log all items
	for ( var i = 0; i< items.Count; i++ )
	{
		LogMessage( items(i).Name );
	}
	// Log specific items
	LogMessage( "cube.kine.local.posx ActionSourceItem active: " + items("cube.kine.local.posx").Active );
	var filtereditems = items.Filter ("","","cube.kine.local.posx");
	LogMessage( "cube.kine.local.posx ActionSourceItem source value: " + filtereditems(0).Source.Value );

See Also

ActionSource ActionSource.SourceItems ActionSource.AddSourceItem