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!