Skip to content

Instantly share code, notes, and snippets.

@JustinPedersen
Created August 23, 2017 11:51
Show Gist options
  • Save JustinPedersen/faf7c20ad921fbdf4332a84222789410 to your computer and use it in GitHub Desktop.
Save JustinPedersen/faf7c20ad921fbdf4332a84222789410 to your computer and use it in GitHub Desktop.
/*
Axle Finder
Select two edge loops on a mesh and run the script.
A locator will be created in the center of the two pieces with the correct axle.
*/
string $Edges[] = `ls -sl`;
int $SelSize = size($Edges);
for($E=0; $E<$SelSize; ++$E){
select -r $Edges[$E];
polyToCurve -form 2 -degree 1 -n ("PollyToCurve" + $E);
CenterPivot;
spaceLocator -n ("CenterLoc_0" + $E);
parentConstraint -n "SnapConst" -weight 1 ("PollyToCurve" + $E) ("CenterLoc_0" + $E) ;
delete "SnapConst";
delete ("PollyToCurve" + $E);
}
// Doing an aim const to find the correct axis of rotation
aimConstraint -offset 0 0 0 -weight 1 -aimVector 1 0 0 -upVector 0 1 0 -worldUpType "vector" -worldUpVector 0 1 0 -n "AimConst" CenterLoc_00 CenterLoc_01;
delete "AimConst";
// Finding the center point of the locs
float $LocA[] = `xform -q -t -ws "CenterLoc_00"`;
float $LocB[] = `xform -q -t -ws "CenterLoc_01"`;
// moving one of the locs to the mid point
float $midPT[] = {($LocA[0] + $LocB[0])/2 ,($LocA[1] + $LocB[1])/2 ,($LocA[2] + $LocB[2])/2};
xform -t $midPT[0] $midPT[1] $midPT[2] "CenterLoc_01";
// deleting the other Loc
delete "CenterLoc_00";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment