Dan Lane has kindly provided a script for me that creates 4x4 matrix node(s) based on the global kinematics of multiple objects selected (as well as the ICE tree to paste the nodes in).
The code also demonstrates how to add comments to the nodes.
(Thanks Dan!)
[code]
var iceTreeArray = new Array();
var objectArray = new
Array();
// Loop through selection and check their type
store them in arrays
for ( var i = 0 ; i < selection.count ;
i++)
{
var objType =
selection.item(i).type
if ( objType ==
"ICETree")
{
// it's an ice tree store it in
the iceTree Array
iceTreeArray[iceTreeArray.length] =
selection.item(i);
}else{
//
it's an object store it in the object
Array
objectArray[objectArray.length] =
selection.item(i);
}// end
else
}// end i
loop
// check if we have ice trees
and objects
if(objectArray.length != 0 && iceTreeArray.length
!= 0 )
{
// loop through the ice tree
array
for ( var i = 0 ; i < iceTreeArray.length ;
i++)
{
// get an ice tree from the array to work
with
var currentIceTree =
iceTreeArray[i];
// loop through the
obj
for (var j = 0 ; j < objectArray.length; j++
)
{
var currentObject =
objectArray[j];
var IceMatrixNode =
AddICENode("$XSI_DSPRESETS\\ICENodes\\4x4MatrixNode.Preset" ,
currentIceTree.fullname );
// name the
matrix node so we know which object it relates
to.
CreateICENodeComment(IceMatrixNode.fullname);
SetValue(
IceMatrixNode.fullname + ".ICETreeComment.Text", currentObject.fullname ,
null);
// collect the objects
transform
var obj_Trans =
currentObject.Kinematics.Global.GetTransform2(0);
//
convert transform to 4x4 matrix
var GlobalMatrix =
XSIMath.CreateMatrix4();
obj_Trans.GetMatrix4( GlobalMatrix
);
// loop through object matrix
rows and colums and insert values into ice node
for ( var
row = 0 ; row < 4 ; row++ )
{
for( var col = 0 ; col
< 4 ; col++ )
{
var the
= GlobalMatrix.Value( row, col
);
SetValue(IceMatrixNode.fullname + ".value_" + row
+ col , the , null);
}// end colume
loop
}// end row
loop
}// end j loop
}// end i
loop
}// end if
[/code]
No comments:
Post a Comment