A new fangled Maya script for zeroing!..

3 February, 2010

Ive been hard at work on a little animation utility to help with zeroing any animated thing in maya to point in space.. For example youve animated an awesome run/jump/death.. but the hips start nowhere near 0,0,0 so on exporting to your game engine theres a whole bunch of issues.

Damn, thats annoying. Heres a gif, below is the explanation and below that is the code..

So I made a script that easily saved me my sanity, in a nutshell all you do is select what you want zerod, e.g the hips of a character.  Then click the “joint to offset” button.

Select the actual world controller thats animated (usually a big round one at the characters feet). Then click the button “Controller to be moved”. (its gotta have a key btw).

Tick which channels you wanna edit.. and below them are some boxes you can enter actual coords if you like ;D

Put in which frame you want it to edit on e.g Frame 0.

Hit the “Check” button and Bang its done ;D

Simply all it does is compares the distance between the coords in the “value to start frame on” boxs with the world position of the “joint to offset” selected, if theres a differance it adjusts the entire the animation curves to shoehorn in the joint to the coords wanted on the channels ticked.

Code below:::::::::::::::::::::::::::::::::::::

string $controlSel=”not selected”;
string $jointSel = “not selected”;
string $checkboxChannelss[];

string $window = `window -sizeable 0 -resizeToFitChildren 1 -title “AnimOffset”
-iconName “AnimOffset”
-widthHeight 100 1`;

rowColumnLayout -numberOfColumns 2 -columnWidth 1 200 -columnWidth 2 300;

button -label “Controller to be moved” -command selControlProc;

textFieldGrp -label “Selected”
-text  $controlSel
-editable false ControlTextField; // this will be the controller to manipulate..

button -label “Joint to offset” -command selJointProc;

textFieldGrp -label “Selected”
-text  $jointSel
-editable false JointTextField;// this will be the goal to move by adjusting the controller

text -label “Translation channels to edit” -align “right”;

checkBoxGrp
-numberOfCheckBoxes 3
-labelArray3 “X” “Y” “Z”
-onCommand ticked
-offCommand ticked
myChkBxGrp;// these are the channels il edit to get the result

text -label “Value to start first frame on” -align “right”;

floatFieldGrp -numberOfFields 3
-value1 0.0 MyDistanceGRP; // Actual float values user puts in

text -label “Frame to start work on” -align “right”;// frame to start script on

intFieldGrp -numberOfFields 1
-value1 0 MyFrame;// Frame to start on that user inputs

text -label “How far off the goal is” -align “right”;

textFieldGrp -label “X,Y,Z”
-text  “distance”
-editable false DistanceToMove;

button -label “check” -command runMetests;

button -label “Close” -command (“deleteUI -window ” + $window);

setParent ..;
showWindow $window;

////////////////////
global proc selControlProc ()
{
string $selObjs[]= `ls -sl `;
$controlSel = “not selected”;
if(size($selObjs)<1)
{
//do nothing
}
else
{
$controlSel = $selObjs[0];
$controlSeld = $controlSel;

}

textFieldGrp -edit -text $controlSel ControlTextField;
}
///////////////////
global proc selJointProc ()
{
string $selObjss[]= `ls -sl `;
$jointSel = “not selected”;
if(size($selObjss)<1)
{
//do nothing
}
else
{
$jointSel = $selObjss[0];
$jointSeld = $jointSel;

}

textFieldGrp -edit -text $jointSel JointTextField;
}
//////////////////
global proc ticked ()// decide on whats ticked
{
int $xTicked =`checkBoxGrp -q -value1 myChkBxGrp`;
int $yTicked =`checkBoxGrp -q -value2 myChkBxGrp`;
int $zTicked =`checkBoxGrp -q -value3 myChkBxGrp`;
int $xyzStates[] = {$xTicked,$yTicked,$zTicked};

}
//////////////////
global proc runMetests ()
{
//need to go to the frame specified.. before calculating..
int $frameStart = `intFieldGrp -q -value1 MyFrame`;

currentTime $frameStart;

//user input coords for the goal to end up at..
float $targetX =`floatFieldGrp -q -value1 MyDistanceGRP`;
float $targetY =`floatFieldGrp -q -value2 MyDistanceGRP`;
float $targetZ =`floatFieldGrp -q -value3 MyDistanceGRP`;

float $pointB[]= {$targetX,$targetY,$targetZ}; //gives the 3 floats of where i need the object to be

string $values = `textFieldGrp -q -tx JointTextField`;
//the users selected goal to be moved (not the actual thing i move though..)
float $pointA[]=`xform -q -ws -a -t $values`; // gives 3 float values of where the object is in the world!

float $distanceX = $pointB[0] – $pointA[0]; // adds all 3 XYZ together// need to work out a way to not do that
float $distanceY = $pointB[1] – $pointA[1];
float $distanceZ = $pointB[2] – $pointA[2];
string $distances= $distanceX+$distanceY+$distanceZ;

//broken at the minute
textFieldGrp -edit -text $distances DistanceToMove;
//still need to work out distances but for each channel alone!

$xTicked =`checkBoxGrp -q -value1 myChkBxGrp`;
$yTicked =`checkBoxGrp -q -value2 myChkBxGrp`;
$zTicked =`checkBoxGrp -q -value3 myChkBxGrp`;
int $frameStart = `intFieldGrp -q -value1 MyFrame`;

select -clear;

if($xTicked<1)
{
//do nothing ignore and move on..
print “doing nothing for x channel”;
}
else
{
//run the entire loop but just for x..
print “start doing x channel”;
string $objectInUse = `textFieldGrp -q -tx ControlTextField`;
string $objectAndChannel = ($objectInUse + “.” + “tx”);
string $chans = (“.” + “tx”);
//float $val[0] = `keyframe -at $chans $frameStart -q -eval $objectInUse`;//should find the
//print $val[0];//need to make validateShelfName[0] be the distance no
$val[0]= $distanceX;

if($val[0] != 0)
{
select $objectInUse;
float $valChange = $val[0];
keyframe -edit -relative -vc $valChange -time “-200000:2000000″ $objectAndChannel;
print “sorted”;
}
select -clear;
}

if($yTicked<1)
{
//do nothing ignore and move on..
print “doing nothing for y channel”;
}
else
{
//run the entire loop but just for x..
print “start doing y channel”;
string $objectInUse = `textFieldGrp -q -tx ControlTextField`;
string $objectAndChannel = ($objectInUse + “.” + “ty”);
string $chans = (“.” + “ty”);
//float $val[0] = `keyframe -at $chans $frameStart -q -eval $objectInUse`;//should find the
//print $val[0];//need to make validateShelfName[0] be the distance no
$val[0]= $distanceY;

if($val[0] != 0)
{
select $objectInUse;
float $valChange = $val[0];
keyframe -edit -relative -vc $valChange -time “-200000:2000000″ $objectAndChannel;
print “sorted”;
}
select -clear;
}

if($zTicked<1)
{
//do nothing ignore and move on..
print “doing nothing for z channel”;
}
else
{
//run the entire loop but just for x..
print “start doing z channel\n”;
string $objectInUse = `textFieldGrp -q -tx ControlTextField`;
string $objectAndChannel = ($objectInUse + “.” + “tz”);
string $chans = (“.” + “tz”);
//float $val[0] = `keyframe -at $chans $frameStart -q -eval $objectInUse`;//should find the
//print $val[0];//need to make validateShelfName[0] be the distance no
$val[0]= $distanceZ;
print($val[0]+”\n”);
if($val[0] != 0)
{
select $objectInUse;
float $valChange = $val[0];
keyframe -edit -relative -vc $valChange -time “-200000:2000000″ $objectAndChannel;
print “sorted”;
}
select -clear;
}

print “Done all script”;

}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.