Maya 2020 fundamentals - modelling the real world
Get halfway through a model and find it's an unworkable mess? Can't add edge loops where you need them? Can't subdivide a mesh properly? If any of this sounds familiar check this course out.
# 1 10-03-2006 , 07:26 AM
skywola's Avatar
Registered User
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224

Walkerman's addSkeleton Procedure

This is a detailed explaination of the Walkerman procedure for creating a biped skeleton . . . .

If you want a procedure to only be callable within a larger procedure, you would build it this way:

proc nameOfProcedure (){

procedure coding . . .

} <---- after you forget this bracket a few times and spend a few
hours trying to figure out why the hell your code is not
working, you will remember it without fail.


If you want to be able to call your procedure from other procedures within your script folder . . . . always want to put the "global" keyword in front of "proc".

global proc nameOfProcedure (){

procedure coding . . .

} After you forget to put "global" there few times and can't
get your procedure to run you'll make it a habit . . . . it is
really rare to NOT use global. . .


This addSkeleton procedure has something else though . . .


global proc addSkeleton (int $n){

In the parenthesis, it has "int $n". This is how you pass something into a procedure. It is called passing a parameter.
the $n is considered to be the parameter. You should include the variable type too, in this case "integer".

When the procedure is called in code, it will look like this:

addSkeleton 1; or

addSkeleton 3;

It really appears in the Walkerman program as:

addSkeleton($n);

Why would I want to pass a parameter?

Because this procedure builds the skeleton . . . every time I build a skeleton, I need to have unique names, so if I build two characters in the scene, there will be no confusion whenever I need to control one of them. So by naming the first skeleton
with a name followed by a number, it makes every part of that skeleton unique. When I build the next skeleton, I just increment the number.

skeleton1 . .. skeleton2 . . . . skeleton3 . .. etc. . .

So on the first skeleton, for example, if you want to rotate X on the left shoulder, you would do it on the joint called

ls1.rotateX

To do the same thing on the second skeleton,

ls2.rotateX

therefore no confusion on what you are doing . . .


global proc addSkeleton (int $n){





Use radians not degrees .. . . . easier for coding and
mathematical calculation, especially when dealing with
trigonometric functions. . .

currentUnit -angle radian;



Here each joint name is created with the parameter that I mentioned earlier to uniquely ID each character part that is created. Also, I used short coding names to limit coding clutter and they really are simple, like bb = base back, hc = hip center
hr = hip right, kr = knee right etc. So I get bb1, hc1, hr1, kr1 or for the second character I would have bb2, hc2, hr2, kr2.

// BODY JOINTS
string $bb = "bb" + $n;
string $hc = "hc" + $n;
string $hr = "hr" + $n;
string $kr = "kr" + $n;
string $ar = "ar" + $n;
string $br = "br" + $n;
string $tr = "tr" + $n;
string $hl = "hl" + $n;
string $kl = "kl" + $n;
string $al = "al" + $n;
string $bl = "bl" + $n;
string $tl = "tl" + $n;
string $mb = "mb" + $n;
string $ub = "ub" + $n;
string $nb = "nb" + $n;
string $mn = "mn" + $n;
string $jb = "jb" + $n;
string $ht = "ht" + $n;
string $hb = "hb" + $n;
string $leye = "leye" + $n;
string $rs = "rs" + $n;
string $rMidBiceps = "rMidBiceps" + $n;
string $re = "re" + $n;
string $lMidForearm = "lMidForearm" + $n;
string $rMidForearm = "rMidForearm" + $n;
string $rw = "rw" + $n;
string $RPone = "RPone" + $n;
string $RJone = "RJone" + $n;
string $RTone = "RTone" + $n;
string $REone = "REone" + $n;
string $RKtwo = "RKtwo" + $n;
string $RBtwo = "RBtwo" + $n;
string $RJtwo = "RJtwo" + $n;
string $RTtwo = "RTtwo" + $n;
string $REtwo = "REtwo" + $n;
string $RKthree = "RKthree" + $n;
string $RBthree = "RBthree" + $n;
string $RJthree = "RJthree" + $n;
string $RTthree = "RTthree" + $n;
string $REthree = "REthree" + $n;
string $RKfour = "RKfour" + $n;
string $RBfour = "RBfour" + $n;
string $RJfour = "RJfour" + $n;
string $RTfour = "RTfour" + $n;
string $REfour = "REfour" + $n;
string $RPfive = "RPfive" + $n;
string $RKfive = "RKfive" + $n;
string $RBfive = "RBfive" + $n;
string $RJfive = "RJfive" + $n;
string $RTfive = "RTfive" + $n;
string $REfive = "REfive" + $n;
string $ls = "ls" + $n;
string $lMidBiceps = "lMidBiceps" + $n;
string $le = "le" + $n;
string $lMidForearm = "$lMidForearm" + $n;
string $lw = "lw" + $n;
string $LPone = "LPone" + $n;
string $LJone = "LJone" + $n;
string $LTone = "LTone" + $n;
string $LEone = "LEone" + $n;
string $LKtwo = "LKtwo" + $n;
string $LBtwo = "LBtwo" + $n;
string $LJtwo = "LJtwo" + $n;
string $LTtwo = "LTtwo" + $n;
string $LEtwo = "LEtwo" + $n;
string $LKthree = "LKthree" + $n;
string $LBthree = "LBthree" + $n;
string $LJthree = "LJthree" + $n;
string $LTthree = "LTthree" + $n;
string $LEthree = "LEthree" + $n;
string $LKfour = "LKfour" + $n;
string $LBfour = "LBfour" + $n;
string $LJfour = "LJfour" + $n;
string $LTfour = "LTfour" + $n;
string $LEfour = "LEfour" + $n;
string $LPfive = "LPfive" + $n;
string $LKfive = "LKfive" + $n;
string $LBfive = "LBfive" + $n;
string $LJfive = "LJfive" + $n;
string $LTfive = "LTfive" + $n;
string $LEfive = "LEfive" + $n;
string $reye = "reye" + $n;
string $jaw = "jaw" + $n;
string $jawTip = "jawTip" + $n;
string $mouthTop = "mouthTop" + $n;
string $mouthTopEnd = "mouthTopEnd" + $n;
string $leftEar = "leftEar" + $n;
string $rightEar = "rightEar" + $n;

The code above was building the names for the joints by adding the number to the end . . . now we need to actually create them . . .


The if - then statement is checking to see if the skeleton that we are set up to build already exists or not. . . . it should not exist, so if it does, we get a warning only and nothing is built.

if( `objExists $bb` ) { warning("Skeleton already exists"); } else { // run this procedure

The code below makes sure nothing is selected . . . if something WAS selected, you might be building your skeleton onto something that already exists . . .

select -cl;

Now we actually start creating the joints . . . . .

joint -p 0 8.6 0 -name $bb;

The 0 = the x-coordinate, the 8.6 the y-coordinate
and the following 0 is the z-coordinate.

Relative means that we are building the joint relative to the
selected joint, in this case the one above that we just built, that is selected.

joint -p 0 -.92 -.1 -relative -name $hc;


Labeling is good as if you need to find out why something is
being built in the wrong place, you can find what code is doing it!
// Right Leg joints
joint -p -1.000000 0 0 -relative -name $hr;
joint -p 0 -3.58 .21 -relative -name $kr;
joint -p 0 -3.3 .1 -relative -name $ar;
joint -p 0 -0.5 1.2 -relative -name $br;
joint -p 0 0 .4 -relative -name $tr;
select -r $hc;

// Left Leg joints
joint -relative -p 1.000000 0 0 -name $hl;
joint -p 0 -3.58 .21 -relative -name $kl;
joint -p 0 -3.3 .1 -relative -name $al;
joint -p 0 -0.5 1.2 -relative -name $bl;
joint -p 0 0 .4 -relative -name $tl;

select -r $bb;
joint -p 0 1.29 -.2 -relative -name $mb;
joint -p 0 2 -.1 -relative -name $ub;
joint -p 0 .7 .1 -relative -name $nb;
joint -p 0 .3 .08 -relative -name $mn; // new middle neck
joint -p 0 .34 .17 -relative -name $jb;
joint -p 0 1.1 -.3 -relative -name $ht;
joint -p 0 -.7 -.24 -relative -name $hb;

// right arm
select -r $ub;
joint -relative -p -1.4 0 0 -name $rs;
joint -p -1 0 0 -relative -name $rMidBiceps;
joint -p -1 0 0 -relative -name $re;
joint -p -1 0 0 -relative -name $rMidForearm;
joint -p -1 0 .04 -relative -name $rw;
joint -p -.2 0 .24 -relative -name $RPone;
joint -p -.1 -.02 0.19 -relative -name $RJone;
joint -p -.17 -.02 0.12 -relative -name $RTone;
joint -p -.1 -.02 .08 -relative -name $REone;

// right index finger
select -r $rw;
joint -p -.58 0 .2 -relative -name $RKtwo;
joint -p -.1 0 0 -relative -name $RBtwo;
joint -p -.28 0 0 -relative -name $RJtwo;
joint -p -.18 0 0 -relative -name $RTtwo;
joint -p -.08 0 0 -relative -name $REtwo;

// right middle finger
select -r $rw;
joint -p -.6 0 .05 -relative -name $RKthree;
joint -p -.1 0 0 -relative -name $RBthree;
joint -p -.3 0 0 -relative -name $RJthree;
joint -p -.19 0 0 -relative -name $RTthree;
joint -p -.1 0 0 -relative -name $REthree;

// right ring Finger
select -r $rw;
joint -p -.6 0 -0.09 -relative -name $RKfour;
joint -p -.1 0 0 -relative -name $RBfour;
joint -p -.28 0 0 -relative -name $RJfour;
joint -p -.18 0 0 -relative -name $RTfour;
joint -p -.1 0 0 -relative -name $REfour;

// right pinky
select -r $rw;
joint -p -.4 0 -0.2 -relative -name $RPfive;
joint -p -.19 0 -.04 -relative -name $RKfive;
joint -p -.1 0 0 -relative -name $RBfive;
joint -p -.22 0 0 -relative -name $RJfive;
joint -p -.13 0 0 -relative -name $RTfive;
joint -p -.1 0 0 -relative -name $REfive;


// left arm
select -r $ub;
joint -relative -p 1.4 0 0 -name $ls;
joint -p 1 0 0 -relative -name $lMidBiceps;
joint -p 1 0 0 -relative -name $le;
joint -p 1 0 0 -relative -name $lMidForearm;
joint -p 1 0 .04 -relative -name $lw;
joint -p .2 0 .24 -relative -name $LPone;
joint -p .1 -.02 0.19 -relative -name $LJone;
joint -p .17 -.02 0.12 -relative -name $LTone;
joint -p .1 -.02 .08 -relative -name $LEone;

// left index finger
select -r $lw;
joint -p .58 0 0.2 -relative -name $LKtwo;
joint -p .1 0 0 -relative -name $LBtwo;
joint -p .28 0 0 -relative -name $LJtwo;
joint -p .18 0 0 -relative -name $LTtwo;
joint -p .08 0 0 -relative -name $LEtwo;

// Left middle finger
select -r $lw;
joint -p .6 0 0.05 -relative -name $LKthree;
joint -p .1 0 0 -relative -name $LBthree;
joint -p .3 0 0 -relative -name $LJthree;
joint -p .19 0 0 -relative -name $LTthree;
joint -p .1 0 0 -relative -name $LEthree;

// Left ring finger
select -r $lw;
joint -p .6 0 -0.09 -relative -name $LKfour;
joint -p .1 0 0 -relative -name $LBfour;
joint -p .28 0 0 -relative -name $LJfour;
joint -p .18 0 0 -relative -name $LTfour;
joint -p .1 0 0 -relative -name $LEfour;

// Left pinky
select -r $lw;
joint -p .4 0 -0.2 -relative -name $LPfive;
joint -p .19 0 -.04 -relative -name $LKfive;
joint -p .1 0 0 -relative -name $LBfive;
joint -p .22 0 0 -relative -name $LJfive;
joint -p .13 0 0 -relative -name $LTfive;
joint -p .1 0 0 -relative -name $LEfive;



// Eye and jaw
select -r $ht; // select parent for the new joint (head top)
joint -relative -p -0.26 -.38 .83 -name $reye;
select -r $ht;
joint -relative -p 0.26 -.38 .83 -name $leye;
select -r $jb;
joint -relative -p 0 -.1 .2 -name $jaw;
joint -relative -p 0 -.1 .46 -name $jawTip;

select -r $jb;
joint -p 0 .21 0.2 -relative -name $mouthTop;
joint -p 0 0 .54 -relative -name $mouthTopEnd;

select -r $jb;
joint -p -.5 .3 0 -relative -name $leftEar;
select -r $jb;
joint -p .5 .3 0 -relative -name $rightEar;


select -r $bb;

Have the base back selected for when the next procedure, which adds attributes starts up . . . . more on that later. . . .

}}
Two brackets, one for the procedure itself and one from the if-then statement that checked to make sure we were not trying to create a skeleton that already exists.

That's all on that procedure . . . . user added image


"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads