Pages

Thursday, April 12, 2012

Using Preinfinity Linear

Hi,

I was trying to use pre-infinity linear and was running into problems, unlike post-infinity linear which created a linear line, so I wrote this script to change the in-angle of the first index of an animation curve(s) to be the same as its out angle. After running script on linear animation curves pre-infinity linear worked fine.

Hope this is helpful,




/**make in angle at first index of curve to be equal to out angle this is so we can use MEL's preinfinity command
@pre
@post first index in angle changed to equal first index out angle
*/
global proc
na_setFirstIndexInAngleToOutAngle(string $animCurve[])
{
na_setFirstIndexInAngleToOutAngle_assert($animCurve);

string $curve = "";
float $firstFrameOutAngle[]={};

for( $i = 0; $i < size($animCurve); $i++ )
{
$curve = $animCurve[$i];

//gets first frame out angle
$firstFrameOutAngle = `keyTangent -index 0 -q -outAngle $curve`;

//sets the inangle to the out angle at first frame
keyTangent -index 0 -inAngle $firstFrameOutAngle[0] $curve;
}
}
global proc
na_setFirstIndexInAngleToOutAngle_assert(string $animCurve[])
{
string $object = "";
for( $i = 0; $i < size($animCurve); $i++ )
{
$object = $animCurve[$i];
if( `objExists $object` == 0 ){error("cannot find object--"+$object);}
if( size( `keyTangent -index 0 -q -inAngle $object`) == 0 ){error("cannot find anim curve of--"+$object);}
}
}
/**
@pre clean maya scene
*/
global proc
na_setFirstIndexInAngleToOutAngle_unitTest()
{
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; objectMoveCommand;
addAttr -ln "anim" -at double |nurbsCircle1;
setAttr -e-keyable true |nurbsCircle1.anim;
select -r pCube1 ;
setDrivenKeyframe -currentDriver nurbsCircle1.anim pCube1.translateX;
select -r nurbsCircle1 ;
setAttr "nurbsCircle1.anim" 10;
select -r pCube1 ;
setAttr "pCube1.translateX" 10;
setDrivenKeyframe -currentDriver nurbsCircle1.anim pCube1.translateX;
setAttr "nurbsCircle1.anim" 0;

selectKey -add -k -f 0 -f 10 pCube1_translateX ;
keyTangent -itt linear -ott linear;

na_setFirstIndexInAngleToOutAngle({"pCube1_translateX"});

}

Regards,
Nate