This proc requires jgArrToStr which you may recognize from yesterday's post. :)
Source them both first and then run it by typing:
jgSplitJointChain joint1 joint2 4 ;
(joint1 being the parent of the two.)
(4 being an example of how many joints you want to add.)
One note, currently it assumes y-up as your secondary axis orient. Maya doesn't let you query SAO so there's no way I know of to dynamically check what to use. Change it in the proc if it's not y-up in you're setup.
// **********************************************************
// Adds A Specified Number Of Joints Into A Chain
global proc jgSplitJointChain (string $parent, string $child, int $numJnts) {
// Adjustment For Math Purposes
$numJnts++ ;
// Checks
select -cl ;
if(!`joint -ex $parent`) error ($parent+" doesn't exist in scene or is not a joint.") ; // Does Parent Exist
if(!`joint -ex $child`) error ($child+" doesn't exist in scene or is not a joint.") ; // Does Child Exist
if(jgArrToStr(`listRelatives -p $child`, 0) != $parent) error ($parent+" is not the parent of "+$child+".") ; // Check Parent/Child Relationship
// Joint Positions
float $pPos[] = `joint -q -p $parent` ;
float $cPos[] = `joint -q -p $child` ;
// Parent Orientation
string $ro = `joint -q -roo $parent` ;
string $sao = "yup" ;
// Unparent Child
parent -w $child ;
// Vector
float $jointVector[] ;
$jointVector[0] = ($cPos[0]-$pPos[0])/$numJnts;
$jointVector[1] = ($cPos[1]-$pPos[1])/$numJnts;
$jointVector[2] = ($cPos[2]-$pPos[2])/$numJnts;
// Deselect All
select -cl ;
// Loop And Setup Joints
string $lastJntCreated = $parent ;
string $newJnts[] ;
for($i = 1; $i < $numJnts; $i++) {
// Create Joint
string $jnt = `joint -p ($pPos[0]+($i*$jointVector[0])) ($pPos[1]+($i*$jointVector[1])) ($pPos[2]+($i*$jointVector[2]))` ;
if($i == 1) parent $jnt $parent ;
// Set Last Created For Reference (Updates Until Last Iteration)
$lastJntCreated = $jnt ;
}
// Reparent End Joint
parent $child $lastJntCreated ;
// Orient Joints
joint -e -oj $ro -secondaryAxisOrient yup -ch -zso $parent ;
}
If you have any trouble using this or have questions/comments, send me a note!
nice tool, I approached the split joint tool differently and used the insert joint tool to create new joints so that I could keep it as simple and fast as possible with out having to deal with all the vector math in mel.
ReplyDeleteNice! I'm in the process of learning vector math so I was inclined to go this route as sort of practice. Seems to be working so far.
ReplyDeleteCool, yeah always like to have a few ways to do something. I think I went the insert joint route because I the script I was fixing at the time was creating strange joint orient values once it added the new joints to the chain and I wanted the orient values to be left alone, and the insert joint method did that.
ReplyDeleteReally nice blog Jay, good resource. thanks.
This comment has been removed by a blog administrator.
ReplyDelete