BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »

Friday, September 17, 2010

Substep Matrix

Finding middle points is easy, but what if you want to find a bunch of midpoints or evenly space out objects between two points. This little proc will generate a matrix of positions that are evenly spaced between two nodes.

global proc matrix jsGenerateSubStepMatrix(string $obj1, string $obj2, int $divisions) {
string $objs[] = {$obj1, $obj2};
matrix $subStepPos[20][3];

float $position1[] = `xform -q -ws -t $objs[0]`;
float $position2[] = `xform -q -ws -t $objs[1]`;
float $divideVec[];
$divideVec[0] = ($position2[0] - $position1[0]) / ($divisions - 1);
$divideVec[1] = ($position2[1] - $position1[1]) / ($divisions - 1);
$divideVec[2] = ($position2[2] - $position1[2]) / ($divisions - 1);
for ($i=0; $i<$divisions; $i++) {
$subStepPos[$i][0] = $position1[0] + ($divideVec[0] * $i);
$subStepPos[$i][1] = $position1[1] + ($divideVec[1] * $i);
$subStepPos[$i][2] = $position1[2] + ($divideVec[2] * $i);
}
return $subStepPos;
}

0 comments: