PDA

View Full Version : Mel Pivot Question


mediumRare
12-24-2003, 02:30 AM
Hi there,
Im an artist learning MEL (slowly)!

I want to take a group node and snap its pivot to a joint.
Im having trouble doing this with the move command because the joint resides in its own space and I cant plug in wolrd space co-ordinates of the joint into the move tool since I dont know how to query those co-ordinates...

BASICALLY, how do you find out in MEL what the wold space co-ordinates of a joint are?


Thanks in advance

galactor
12-24-2003, 01:30 PM
If the bone is selected, and you run this Command

xform -ws -q -t

It will return the right translation.


:: Galactor ::

macaroniKazoo
12-25-2003, 11:21 PM
just FYI, the better way to find out the world space position of an object, is by using:

xform -q -ws -rp $obj;

which finds the world space position of the rotation pivot of an object, instead of the world space translation. for a joint, this doesn't matter, but for any other object, if the translation has been frozen away from the origin, then the xform -q -ws -t command will give you wrong information.

but for joints, what galactor said will work just fine. :)

kiaran
03-12-2004, 07:06 AM
Thanks a bunch guys! I was racking my brain against that one for some time. I'm just starting to write some serious mel scripts and I've discovered I'm not quite the mel expert I thought I was when it comes to anything other than UI building!

I do have a quick question though. Why is it that when I query the position of a joint like this...

joint -q -p leftKneeJoint;

...I don't get the proper position. Seems offset or something. Anyone know why this is?

macaroniKazoo
03-12-2004, 07:13 AM
do you want the world space position of the joint? the joint -q -p command gives world space coords of the joint. you're possibly after local space info?

if so, try using: joint -q -p -r leftKneeJoint;

kiaran
03-12-2004, 08:11 AM
Neither relative nor absolute queries of a joint seem to give the correct coords. I must be doing something wrongly.

All I'm trying to do is snap a sphere to a joint. It's not a big deal though because the xform command is giving me what I want. I was just curious is all.

macaroni- BTW, I'm going to have to buy you a mega huge pint of beer if I'm ever in Australia. You've always got great input on this and other forums (jonhandhisdog). Thanks, mate.

strarup
03-12-2004, 08:24 PM
Hi mediumRare,

you can also use the pointcontraint method...

but it depends on, if it should stick to the joint after it have been snapped... and if the objects inside the group should move... :)

if the objects inside the group shouldn't move, I will suggest you to take them out of the group, and then put them back in the group after the pointContraint...

also if the group should stick to the joint, you can just use the pointConstraint command...
pointConstraint -offset 0 0 0 -weight 1;

the first selected object is the "master" and the second selected object is the "slave"... so in this case, you would first select the joint and then afterwards the group...

and if you don't want it to stick with the joint afterwards, then you can delete the pointContraint afterwards...

quite handy sometimes if you want to snap a handIKControl to a handFKControl... without having it to stick to the FK after the snap... :-)

this method can be used if it is something you want to use more than once, with the same objects, e.g. a IK snap to FK...

select -r Name_Of_Your_First_Selected_Object;
select -add Name_Of_Your_Second_Selected_Object;
pointConstraint -offset 0 0 0 -weight 1;
select -r Name_Of_Your_Second_Selected_Object_pointConstraint1;
delete;

otherwise here's a more generel example, which will snap the second selected object to the first selected object, and then afterwards delete the pointContraint...

e.g. select the Joint first, and then the Group, and afterwards use this command...

//the array containing the 2 selected objects...
string $daObj[] = `ls -sl`;
//pointcontrain $daObj[1] to $daObj[0]...
pointConstraint -offset 0 0 0 -weight 1;
//select the pointcontraint for $daObj[1]...
select -r ($daObj[1]+"_pointConstraint1");
//and then delete it...
delete;

regards

Strarup

macaroniKazoo
03-14-2004, 10:16 PM
hey strarup, while that is a great method, that way is a bit messy in code. :)

you can also do the pointConstraint snap method in one line - which is alot easier to read. if you have two objects, and you want to snap object1 to object2:

delete `pointConstraint $object1 $object2`;

and thats it. by default the offset is zero. and I like to write my mel scripts without select commands... :) strarup, you possibly already know this anyway, but for anyone else, there ya go.

PS if you want to do both position and orientation, use this:

delete `parentConstraint $object1 $object2`;

and kiaran - yeah, bring on the beers if ever you've in the country. :beer:

strarup
03-14-2004, 10:58 PM
Hi Mac,

thanx... :)

I changed it to this because the objects are implicit in the array...
string $daObj[] = `ls -sl`;
delete `pointConstraint $daObj`;

but very handy with the method to delete it on one line, while it's beeing created... I didn't know that... thanx... :)

PS if you want to do both position and orientation, use this:

delete `parentConstraint $object1 $object2`;


btw. do you mean applying the parentContraint on it's own, or afterwards...

why I'm asking is because with the parentContraint you contraint the movement of the transform and rotation, but the object will not get's it position unless it has the same position (e.g. has been snapped to it) before it got parentContraint, and it would also not get the same rotation of the object if it hadn't been e.g. orient contrainted first... with the parentContraint it will just follow the movement with the exact number of units as the object it has been contrainted to... :)

regards

Strarup

macaroniKazoo
03-14-2004, 11:20 PM
why I'm asking is because with the parentContraint you contraint the movement of the transform and rotation, but the object will not get's it position unless it has the same position (e.g. has been snapped to it) before it got parentContraint, and it would also not get the same rotation of the object if it hadn't been e.g. orient contrainted first... with the parentContraint it will just follow the movement with the exact number of units as the object it has been contrainted to... i'm not sure what you mean strarup. try it out. all it does, is snap the target object to the parent. its position and orientation are matched in world space. its exactly as if you had just done:

delete `pointConstraint obj1 obj2`;
delete `orientConstraint obj1 obj2`;

but its all in one line. i mean, all this is doing, is deleting the return object from the constraint command - which is the constraint node. its basically just nesting the commands together.

delete( pointConstraint("obj1","obj2"));

might illustrate how it works better. :) i hope that makes sense...

strarup
03-14-2004, 11:51 PM
Hi Mac,

yup... :)

I'm very sorry... I'm a bit tired and had forgot the Maintain Offset thingie in parentConstraint (-mo), which I usually use when I parentContraint things... and since the -mo flag isn't there it just do what you say... so my mistake... :)

i'm not sure what you mean strarup. try it out. all it does, is snap the target object to the parent. its position and orientation are matched in world space. its exactly as if you had just done:

I just misunderstood you, and therefore wondered a bit about it, because I had forgot about the -mo, that's all... :banghead:

regards

Strarup

macaroniKazoo
03-15-2004, 12:03 AM
I'm very sorry... I'm a bit tired and had forgot :D thats cool dude. i just wasn't sure I was being clear in my previous posts. :) i fully sympathise with the tired thing...

kiaran
03-15-2004, 01:16 AM
delete `pointConstraint object1 object1`;

Awsome tip Macaroni. Anything to help make my scripts more readable and tidy is great. Sometimes my code looks messyer than my house on a weekend!

CGTalk Moderation
01-17-2006, 01:00 AM
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.