PDA

View Full Version : moving controller to joint


mccollom73
07-02-2010, 05:51 PM
Hey,

So I am trying to find a mel command that will move the controller to the respect joint no matter where it is. I tried this, but it didn't really seem to work the way I wanted it to. Is there a simpler solution?




global proc controlSnap()

{

string $leftlegSideLong;

string $leftlegSide;


group -n ($leftlegSideLong + "leftFootControlAlign") ($leftlegSideLong + "leftFootControl");

delete `orientConstraint ($leftlegSide + "lBall") ($leftlegSideLong + "leftFootControlAlign")`;

delete `pointConstraint ($leftlegSide + "lBall") ($leftlegSideLong + "leftFootControlAlign")`;

select -r ($leftlegSideLong + "leftFootControl");

FreezeTransformations;

performFreezeTransformations(0);


}




Thanks,
Josh

JayG
07-02-2010, 09:09 PM
delete `pointConstraint $obj $targetObj` ;
delete `orientConstraint $obj $targetObj` ;

The above will always snap your target to the object, but you'll end up with non-zero values on it since it's moving. After that just run makeIdentity to freeze transforms.


delete `pointConstraint $obj $targetObj` ;
delete `orientConstraint $obj $targetObj` ;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $targetObj ;

mccollom73
07-03-2010, 01:37 AM
delete `pointConstraint $obj $targetObj` ;
delete `orientConstraint $obj $targetObj` ;

The above will always snap your target to the object, but you'll end up with non-zero values on it since it's moving. After that just run makeIdentity to freeze transforms.


delete `pointConstraint $obj $targetObj` ;
delete `orientConstraint $obj $targetObj` ;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $targetObj ;


ah, and that fixes my problem I was having. Thank you so much!

Josh

BigRoyNL
07-03-2010, 09:40 AM
Is there any reason why you should do the point AND orient constraint instead of just using a parentConstraint? Can't really think of any reason why you should do it this way.

Thanks for an explanation if you have one.

Oh, and how come I never thought of instantly deleting the results of a constraint (for just aligning). I always had like 2 or 3 lines of code. The creation of the constraint and a line for the deletion.
Dumb. hehe.

Roy

EDIT:

If there's no difference between the two I'd rather go for the parentConstraint solution as this one provides a higher speed.

Here's the speed difference:
3.06 to pointConstraint and orientConstraint 2500 pCubes to 2500 pCubes
2.11 to parentConstraint 2500 pCubes to 2500 pCubes

Here's how I tested:
// warning: this first 'creates a new file' (so be sure to close whatever is opened! //
// warning: this first 'creates a new file' (so be sure to close whatever is opened! // // New file
file -f -new;
// Create 5000 pCubes
$startTime = `timerX`;
polyCube;
$amountIterations = 5000;
for ($i = 1; $i < 5000; $i++) {
duplicate;
}
print (`timerX -st $startTime`+" to create 5000 polyCubes\n");
// Check speed for 2500 point and orientConstraints
$startTime = `timerX`;
$amountIterations = 2500;
for ($i = 1; $i <= $amountIterations; $i++) {
delete `pointConstraint ("pCube"+$i) ("pCube"+(2*$i))` ;
delete `orientConstraint ("pCube"+$i) ("pCube"+(2*$i))` ;
}
print (`timerX -st $startTime`+" to pointConstraint and orientConstraint 2500 pCubes to 2500 pCubes\n");
// Check speed for 2500 parentConstraints
$startTime = `timerX`;
$amountIterations = 2500;
for ($i = 1; $i <= $amountIterations; $i++) {
delete `parentConstraint ("pCube"+$i) ("pCube"+(2*$i))` ;
}
print (`timerX -st $startTime`+" to parentConstraint 2500 pCubes to 2500 pCubes\n");

JayG
07-06-2010, 07:23 PM
The reason I use point/orient instead of just one parentConstraint is that there are as many times as there aren't in my day to day workflow where I only want one or the other snapped, not both. This way when I copy and paste code or do a search/replace I can just delete one of the lines without needing to constantly retype 'parent' to 'point' or vice-versa.

Whatever floats your boat though really, it doesn't matter.

CGTalk Moderation
07-06-2010, 07:23 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.