View Full Version : Orienting joints with MEL?
11-12-2002, 09:51 AM
Lately I´ve been writing a script that takes an existing joint chain and creates a series of control arms for it. Initially, my idea was to take the existing chain and recreate a control chain on top of it, using the position, joint orient, and rotation axis of the existing chain to re-align the new chain I created. HOWEVER, this never gave predictable results; it only gave correct results when the chain was initially created in a certain way (all joint lying on one axis, for example). In my case, the script had to work in ALL cases.
Try this as an example to see what I mean:
-Create a random chain with 3-4 joints.
-Rotate each joint randomly.
-Freeze rotations on all joints.
-reorient the chain (joint -e -zso -ch -oj xyz <jointname>)
-Now orient the local rotational axis manually in some way (for example, say you were creating an arm).
-Now try and create a new chain on top of this chain, using the position, joint orient, and rotation axis of the first chain as input variables to create the second chain.
This NEVER produces predictable results for me in a consistent way. Sometimes it works, but rarely. Which leads me to the following question: is it even possible in MEL to create a joint chain and make sure the joint orientations are aligned correctly?
It seems the answer is NO. :( I would appreciate comments here.
HOWEVER, I did finally get my script working by simply duplicating the existing chain, and reworking some of the joints to fit my control rig. This was the only way scripting a control rig worked for me.
If you guys have tried this I´d appreciate hearing your feedback.
11-15-2002, 01:42 PM
i did the same, I just duplicated the chain and modified it, never thought about something else.
I guess, the reason why you don`t get the same result by setting the attribs, is you dont` t really set --all-- attribs.
the joint Node is inherited from the transformNode. if you see the Node Doku, transform has some more attributes.
if you freeze transformation for example your translate values are 0 0 0. but your "real translation" is the translate minus transMinusRotatePivot. this compensates your frozen values.
try your script again, make shure all the translate values are copied.
tell me please if it works
11-15-2002, 07:05 PM
If you want to orient joints to a predefined position. You could do this with an aim constraints.
1. De-parent the joint, so it's standing alone (no children)
2. Aim constraint it to it's previous child joint, using either a locator as an upvector or a world axis.
3. Delete the aim constraint (and up vector object if any).
4. Set the joint orient attributes of the joint to it's rotate values.
5. Set the rotate values to zero.
This, of course, depends on some kind of up vector. Though that might be easy to define.
Here's a snippet from the sciprt I'm working on that does this (it won't run as written here, as it needs the rest of the script, but might give you some idea):
// Create joints at even intervals along the curve
float $x = `getAttr ($group +".tx")`;
float $y = `getAttr ($group +".ty")`;
float $z = `getAttr ($group +".tz")`;
$spine[$i/10] = `joint -name ("spine_"+ $i/10) -position $x $y $z`;
setAttr .displayLocalAxis 1; // !!! Debug, remove later
// Orient joints correctly
string $tempAim = `aimConstraint -worldUpVector 0 0 -1 -worldUpType "vector" $spine[$i+1] $spine[$i]`;
float $rot = `getAttr ($spine[$i]+".r")`;
//setAttr ($spine[$i]+".ra") $rot $rot $rot;
setAttr ($spine[$i]+".jo") $rot $rot $rot;
setAttr ($spine[$i]+".r") 0 0 0;
// Parent the joints together
parent $spine[$i+1] $spine[$i];
11-18-2002, 09:54 AM
constraint it to it's previous child joint
Don´t you mean "successive joint" here? I´ll have to see if this works in my case. What I want to do is get the joint orientation from an existing chain in which the joints have already been oriented correctly. Currently my script works by duplicating the original chain and removing joints to create a more simplified chain (joint orientations are therefore preserved).
01-13-2006, 11:00 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.