Wednesday, March 14, 2012

Ideas for Developing Easy To Use Mel Rigging Tools

Here I wanted to show a kindof before and after on a short script related to fk ik picking for character animation. I think this may be helpful in making a script generalizable.

1. First I created tool by hand
2. Then I checked what the commands I ran were to find some I understood
3. Then I added short comments to those commands
4. Then I wrote down some of the variables that I used in those commands
5. Then I edited commands to use those variables
6. --would be an interface cause there are lots of variables it would be complicated trying to enter them all in as parameters.

The first example shows how I put in the actual names of everything. I got this right off of the script editor and added a couple of comments.


//make node, this will stay on animator scene for life of rig
createNode blendColors -n l_hand_rotate_blend;

////now we can use ik rotation on our arm hand joint
//
connectAttr -f l_ik_hand_joint.rotateX l_hand_rotate_blend.color2R;
// Result: Connected l_ik_hand_joint.rotate.rotateX to l_hand_rotate_blend.color2.color2R. //
connectAttr -f l_ik_hand_joint.rotateY l_hand_rotate_blend.color2G;
// Result: Connected l_ik_hand_joint.rotate.rotateY to l_hand_rotate_blend.color2.color2G. //
connectAttr -f l_ik_hand_joint.rotateZ l_hand_rotate_blend.color2B;
// Result: Connected l_ik_hand_joint.rotate.rotateZ to l_hand_rotate_blend.color2.color2B. //

////now we can use fk rotation on our arm hand joint
//
connectAttr -f l_fk_hand_joint.rotateX l_hand_rotate_blend.color1R;
// Result: Connected l_fk_hand_joint.rotate.rotateX to l_hand_rotate_blend.color1.color1R. //
connectAttr -f l_fk_hand_joint.rotateY l_hand_rotate_blend.color1G;
// Result: Connected l_fk_hand_joint.rotate.rotateY to l_hand_rotate_blend.color1.color1G. //
connectAttr -f l_fk_hand_joint.rotateZ l_hand_rotate_blend.color1B;
// Result: Connected l_fk_hand_joint.rotate.rotateZ to l_hand_rotate_blend.color1.color1B. //

//now we can use either ik or fk rotation on our arm hand joint
//
connectAttr -f settings_anim.l_arm_state l_hand_rotate_blend.blender;
// Result: Connected settings_anim.l_arm_state to l_hand_rotate_blend.blender. //


The second example show how I slowly move the names out and further up to make the script more generalizable. The second example is not production ready (it needs an interface, a unit test, error checking ...) but it shows some helpful ideas.


//setting some variables
string $ik_joint = "l_ik_hand_joint";
string $fk_joint = "l_fk_hand_joint";
string $joint = "l_hand_joint";
string $attribute[] = {"translateX","translateY","translateZ"}; //change to rotate if need to
string $nameNode = "l_hand_translate_blend"; //change to rotate if need to
string $animatorAttr = "settings_anim.l_arm_state"; //should be able to make two choices only
string $pickArray[] = {"color1","color2"}; // change order if you want to switch how it works with animator picker
string $pick= "";
string $blend_arg="";

//make node, this will stay on animator scene for life of rig
//
createNode blendColors -n $nameNode;


////now we can use ik rotation on our arm hand joint
//
$pick = $pickArray[0];
$blend_arg = $nameNode+"."+$pick;
connectAttr -f ($ik_joint+"."+$attribute[0]) ($blend_arg+"R");
connectAttr -f ($ik_joint+"."+$attribute[1]) ($blend_arg+"G");
connectAttr -f ($ik_joint+"."+$attribute[2]) ($blend_arg+"B");

////now we can use fk rotation on our arm hand joint
//
$pick = $pickArray[1];
$blend_arg = $nameNode+"."+$pick;
connectAttr -f ($fk_joint+"."+$attribute[0]) ($blend_arg+"R");
connectAttr -f ($fk_joint+"."+$attribute[1]) ($blend_arg+"G");
connectAttr -f ($fk_joint+"."+$attribute[2]) ($blend_arg+"B");

//now we can use either ik or fk rotation on our arm hand joint
//
connectAttr -f $animatorAttr ($nameNode+".blender");
connectAttr -f ($nameNode+".output"+"R") ($joint+"."+$attribute[0]);
connectAttr -f ($nameNode+".output"+"G") ($joint+"."+$attribute[1]);
connectAttr -f ($nameNode+".output"+"B") ($joint+"."+$attribute[2]);


Hope this is helpful.

Regards,
Nate


Inspired by Jason Schleifer's Animator Friendly Rigging (jasonschleifer dot com) and Andrew Hunt's (The Pragmatic Programmer)