Tuesday, September 4, 2012

Script To Align Geometry With Joint

Hi,
I was trying to add vertebra to a spine but since there were lots of them I came up with this short script to help me duplicate over a modeled vertebra and have it follow along a path. This tool works by selecting all joints then the single geometry. It has little error checking and still has a few bugs like not changing geo's local axis to match joint before doing the alignment to joint path.

Hope this is helpful,

Cheers,
Nate

Script get thorasic vertebra follow spine should work if have a geometry we 
want to follow the joint path.


//
//first select all joints and then select single geometry. 
//probably want error checking  and geo gets 
//its local transformation axis in first joints local axis prior to procedure via
//freeze rotate transform

//location match version
//
string $sel[] = `ls -sl`;
if(size($sel) >= 2 ){
int $numberJoints = size($sel) - 1;
 
//get joints from user selection probably want to verify these are joints
string $jointArray[] = {};
for($j=0; $j < $numberJoints; $j++){$jointArray[size($jointArray)] = $sel[$j];}

//get single geometry from user selection
string $geo = $sel[size($sel) - 1];

string $dupGeo[] = {};
for($i = 0; $i < size($jointArray); $i++)
{
 $joint = $jointArray[$i];
 $dupGeo = {};
 $dupGeo = `duplicate -rr $geo`;
 string $constr[] = `pointConstraint -weight 1  $joint $dupGeo[0]`;
 delete $constr[0];
}

}
//

//both location and orientation match version
string $sel[] = `ls -sl`;
if(size($sel) >= 2 ){
int $numberJoints = size($sel) - 1;
 
//get joints from user selection probably want to verify these are joints
string $jointArray[] = {};
for($j=0; $j < $numberJoints; $j++){$jointArray[size($jointArray)] = $sel[$j];}

//get single geometry from user selection
string $geo = $sel[size($sel) - 1];

string $dupGeo[] = {};
for($i = 0; $i < size($jointArray); $i++)
{
 $joint = $jointArray[$i];
 $dupGeo = {};
 $dupGeo = `duplicate -rr $geo`;
 string $constr[] = `parentConstraint -weight 1  $joint $dupGeo[0]`;
 delete $constr[0];
}

}
//