SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 22-03-2006, 04:31 PM   #1
leni
Registered User
 
Join Date: Jan 2006
Location: Austria
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Joints and mel

hi,

does anyone know, how to get informations like:
parent, child, length, head or tail
from a joint with mel?

lg, leni
leni is offline   Reply With Quote
Old 22-03-2006, 05:02 PM   #2
skywola
Registered User
 
skywola's Avatar
 
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is possible, I have been planning on a tutorial somewhat like what you are asking, the coding is more advanced, in that it takes several steps. I do have examples of it in my Walkerman program :

http://www.simplymaya.com/download_p...tid=6&typeid=4

or

Download > Mel Download > Animation Download


If you want to see working examples. All of it works thru following the joint heirarchy and querying attributes.

Listed below is a snippet of code I used in the module that turns the hand control on by editing expressions that control the joints in the hand. You can use the same process to get joint information.

Because of the limited width of this window, your better off downloading the Walkerman program and looking at the code in the handControlOn procedure in notepad . . .


// get main parent of all character parts
string $selectedObjects[] = `ls -sl -type joint`;
string $relBuffer[];
string $ultimate;
int $characterType;
int $characterNumber;

if (size($selectedObjects) == 0) {
string $window;
$window = `window -title "Walkerman" -iconName "Name" -widthHeight 200 55`;
columnLayout -adjustableColumn true;
text -label "\r\n\r\n Select a character to use its control window. \r\n\r\n" -fn "boldLabelFont" -align "center";
button -label "Close" -align "center" -command ("deleteUI -window " + $window);
setParent ..;
showWindow $window;
// Resize the main window
window -edit -widthHeight 300 114 $window;
}
else{
string $relBuffer[] = `listRelatives -f $selectedObjects[0]`;
$numTokens = `tokenize $relBuffer[0] "|" $relBuffer`;
if (size($selectedObjects) == 0)
print("You must select a character to turn hand control off.");
if (size($selectedObjects) > 1)
print("Select only one character part to get its control window.");
// Get characterNumber and characterType 1 = Human 2 = Bird 3 = Spider 4 = Quadraped (four legged) //
if (size($selectedObjects) == 1)
$ultimate = $relBuffer[0] + ".characterType";
$characterType = `getAttr $ultimate`;
$ultimate = $relBuffer[0] + ".characterNumber";
$characterNumber = `getAttr $ultimate`;

// HAND JOINTS
string $LBone = "LBone" + $characterNumber; string $FL2J1 = "FL2J1" + $characterNumber;
string $FL3J1 = "FL3J1" + $characterNumber; string $FL4J1 = "FL4J1" + $characterNumber;
string $FL5J2 = "FL5J2" + $characterNumber;
string $lw = "lw" + $characterNumber;

string $RBone = "RBone" + $characterNumber; string $FR2J1 = "FR2J1" + $characterNumber;
string $FR3J1 = "FR3J1" + $characterNumber; string $FR4J1 = "FR4J1" + $characterNumber;
string $FR5J2 = "FR5J2" + $characterNumber;
string $rw = "rw" + $characterNumber;
string $exp;



// get expressions from FL2J0
string $FL2J0 = "FL2J0" + $characterNumber;
// Get expressions connected to above joint
string $buffer[] = `listConnections -type expression $FL2J0`;
string $element;
string $compString;
string $expressionToEdit;

// edit expressions to de-activate hand control
for( $element in $buffer ){
$compString = `expression -q -s $element`; // query for present expression //
$expressionToEdit = $FL2J0 + ".rotateZ";
if(startsWith($compString, $expressionToEdit)){ // boolean - look for rotateZ //
$exp = $FL2J1 + ".rotateZ = " + $lw + ".leftGrab;"; // Left RZ Index Finger
expression -e -s $exp -o FL2J1 -ae 1 -uc all $element; // edit it
}
$expressionToEdit = $FL2J0 + ".rotateY";
if(startsWith($compString, $expressionToEdit)){ // boolean - look for rotateY //
$exp = $FL2J1 + ".rotateY = " + $lw + ".leftSpread * -.5;"; // Left RY Index Finger
expression -e -s $exp -o FL2J1 -ae 1 -uc all $element; // edit it
}
}
__________________
"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
skywola is offline   Reply With Quote
Old 22-03-2006, 06:16 PM   #3
leni
Registered User
 
Join Date: Jan 2006
Location: Austria
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Smile thanks!

thanks for your helpful information!

listConnection is one of the commands i searched for!
i will check out some of your code - it will help me a lot

lg, leni
leni is offline   Reply With Quote
Old 23-03-2006, 10:34 AM   #4
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

ok you don't need to search though all that code:

to get the

parent:
listRelatives -p <<object name>>

children:
listRelatives -c <<object name>>

to calculate the length of a joint just get the position of joint1 and then joint2 and do some vector maths to give you the length between them:

global proc float getJointLength(string $jnt1, string $jnt2)
{
//get jnt1 worldspace position
float $jnt1Pos[] = `xform -q -ws -t $jnt1`;

//get jnt2 worldspace position
float $jnt2Pos[] = `xform -q -ws -t $jnt2`;

//calculate the vector between them
float $xcomp = $jnt2Pos[0] -$jnt1Pos[0];
float $ycomp = $jnt2Pos[1] -$jnt1Pos[1];
float $zcomp = $jnt2Pos[2] -$jnt1Pos[2];

vector $tmp = << $xcomp, $ycomp, $zcomp>>;

//get the vector length
float $res = mag($tmp);
return $res;
}

getJointLength("joint1", "joint2");

and what do you mean by "head and tail"?


A
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 24-03-2006, 06:38 AM   #5
leni
Registered User
 
Join Date: Jan 2006
Location: Austria
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

thanks for your advices,
i am working on an export script for a bone-animated character (mesh + boneanimation)
the authors of the fileformat and the first script made their work with blender

i have used the fileformat to write an exporter with maxscript, and now i will do the same with mel

head = startposition of a bone
tail = endposition of a bone

so i will use position for head and position + length for tail

i am a little bit confused about the bone handling in maya, because i have worked with max before, where you have no joints, just bones - so every bone has a length
in maya seems to be joints (last joint of a bone-chain), which have no length

i have been searching for commands where i can get informations about joints and their hierachy, but i didn't search for the listX commands
...and coming from maxscripting, i was spoilt with a huge amount of commands for each kind of node, a lot of commands for mathematics and so on...

lg, leni
leni is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.