Auto Rigging tool for maya

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Auto Rigging tool for maya

Postby Richard on Sun Feb 07, 2010 7:03 pm

Hey gang, because reviving the forum also means creating new topics, here is my contribution:


I've been wanting to learn mel for a while, and figured that learning it while creating an autorig setup would be interesting and challenging enough. Turns out, it's as hard as I thought, but it's soooo much fun!

For some reason it feels like scripting is right for me. It feels like i'm using my full brain power and having lots of fun doing so. I not felt that exited and challenged about 3D in a loooong while. And even though it's just been 24 hours, I feel extremely comfortable! weird right?

So far i actually hand wrote 730 line of mel with no auto rig reference.

i've strugled here and there as i did not speak mel 24 hours ago, but averall it's going fine.

here is the UI:

Image

i'm almost finished with the template skeleton that you use to reposition over your model,

and this is what you get when you click on the create template rig button:

Image

Most of the spheres are not just spheres, i made attributes and other things so that it takes just a few minutes to place them correctly
as you see it's still missing the spline, hands and feet. but i needed to stop and make the UI first as they will depend on the user's selection.

once I'll be finished with that, i will move on and create the skeleton. using values from the template skeleton.
Image

User avatar
Cameron
Site Admin
 
Posts: 2373
Joined: Tue Jun 14, 2005 5:45 am
Location: Behind the stalker, outside your window
x4
x2

Re: Auto Rigging tool for maya

Postby Cameron on Mon Feb 08, 2010 9:50 am

wow thats very impressive, you're going places sir.

Be careful though, using your full brain is great at first, but do that for 2 years solid and you'll need to book yourself in for at least 10 years remedial tropical island therapy!
This website proudly brought to you by CameronJamesDesign.com.

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Mon Feb 08, 2010 10:55 am

wow cool! that sounds like fun!
Image

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Mon Feb 08, 2010 12:26 pm

hey mel scripters, care to help?

because when change options in the ui, i then need to query it to use it during the script

so i declared this

string $name = `textField -query -text autorigName`;
int $sym = `checkBoxGrp -query -value1 autorigSym`;

so that i can find the name and use it down the line, and so that i can see if a symmetry checkbox is checked (new option since screenshot)

further down the line, in the creation of the sphere i have this

if ($sym = 1){
expression -e -s "rig_rt_clav.translateX = -rig_lf_clav.translateX;\rrig_rt_clav.translateY = rig_lf_clav.translateY;\rrig_rt_clav.translateZ = rig_lf_clav.translateZ;" -n "symm_clav_rt_exp" -o rig_rt_clav -ae 1 -uc all ;
}

all i'm saying:

if $sym =1, then create an expression so that the clavicle spheres move symmetrically.


yesterday i just had the name string, and it worked great, renamed controlers accordingly during the script. But since i added the new integer it tells me this

// Error: Only one expression allowed for edit/query. //
// Error: Unable to parse command argument list. //

can you only do one query?
am i doing something wrong?
Image

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Mon Feb 08, 2010 8:08 pm

found it,

i had to use
if ==1
rather than
if =1
cause in the above I was telling it that it was equal to one

also, i had a problem in my expression, i used a -e flag for no reason as i was creating the expression
Image

User avatar
JayG
Supreme Master
 
Posts: 1154
Joined: Sun Nov 19, 2006 8:25 am
Location: Los Angeles, CA

Re: Auto Rigging tool for maya

Postby JayG on Mon Feb 08, 2010 8:22 pm

Lookin' good man, off to a great start!

I subscribed to this topic so I can help you with any MEL issues you run into.

Personally I would use a buffer node/multiplyDivide setup to mirror your sides, instead of expressions...but both work, your preference of course.

Expressions are just messy in Maya in general so I tend to avoid them altogether.

Another suggestion, having had this beat into me at work all day everyday: Don't hard-code the amount of toes, fingers, etc. he's allowed to have. Make it dynamic so you can tell it exactly what you want. What if they want 15 toes on each foot? How about 64 bones in his spine? It might never happen, but if it does you won't have to re-write your auto-build.
ScriptSwell - IM - JG
------------------------------------------------
Rigger of the Black Sails

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Tue Feb 09, 2010 1:38 am

thx for the thumbs up man, and i'm sure that you'll come in very handy down the line! ^^

- great call for the multiply divide node! i ended up using them for all the symmetry! it works great and it's super duper fast!
- i have no idea what the buffer node is
- how could i make the fingers and all that stuff dynamic? how would i go about doing that?
Image

User avatar
JayG
Supreme Master
 
Posts: 1154
Joined: Sun Nov 19, 2006 8:25 am
Location: Los Angeles, CA

Re: Auto Rigging tool for maya

Postby JayG on Tue Feb 09, 2010 6:44 pm

By Buffer Node I'm just referring to parenting your object to an empty transform (group) node and connect to that which makes it generally a bit more clean. Sometimes your objects will already have incoming connections so you can't connect to them, so you create a buffer as it's parent at the same location/orientation and connect to that instead.

To make it dynamic is a tough question. It essentially requires a lot of planning and being creative to make it work. Example my auto-rig has an attribute to change the amount of spine bones on the fly (at the skeletal stage). The way I coded it was to have the top of the spine and the bottom stay constant, and then wrote a proc to basically "split" the distance between the joints to a certain number of joints. So if I want say 7 joints in the spine, it will add 5 in between them at equal distance.

You can do the same sort of thing with toes and fingers. Allot it a certain amount of space, teach it how to make a finger, and then for however many they want you fit them in there somehow haha. I'm not saying it's easy by any means, but it WILL come up in your rig building future.

One option to consider is using "templates". So you have like a basic humanoid template to start, that you can add to and modify to work with the mesh you're rigging. Then as time goes on you save out new templates and can import them to save yourself time. Need to rig a quadruped? Save out a template when you do so next time half the work is done for you. Enabling you're auto-rigging system to do as much work for you as possible is in essence it's purpose.

Just some more ideas for ya.
ScriptSwell - IM - JG
------------------------------------------------
Rigger of the Black Sails

User avatar
JayG
Supreme Master
 
Posts: 1154
Joined: Sun Nov 19, 2006 8:25 am
Location: Los Angeles, CA

Re: Auto Rigging tool for maya

Postby JayG on Wed Feb 10, 2010 5:40 am

Here's a procedure I wrote you can use to split a joint chain into multiple joints. Play around with it and you can use it to dynamically add any number of spine (or any) joints.

The second proc is a just a small thing I wrote that let's me trick Maya and pass a string array into a regular string argument. Keeps the code shorter and cleaner.

Source them both first and then run it by typing: jgSplitJointChain joint1 joint2 4 (joint1 being the parent of the two, most likely the bottom of the spine.)

(4 being an example of how many joints you want to add.)

One note, currently it assumes y-up as your secondary axis orient. Maya doesn't let you query it so there's no way I know of to dynamically check what to use. Change it in the proc if it's not y-up.

Code: Select all
// **********************************************************
// Adds A Specified Number Of Joints Into A Chain
global proc jgSplitJointChain (string $parent, string $child, int $numJnts) {
   
      // Adjustment For Math Purposes
      $numJnts++ ;
   
      // Checks
      select -cl ;
      if(!`joint -ex $parent`) error ($parent+" doesn't exist in scene or is not a joint.") ; // Does Parent Exist
      if(!`joint -ex $child`) error ($child+" doesn't exist in scene or is not a joint.") ; // Does Child Exist
      if(jgArrToStr(`listRelatives -p $child`, 0) != $parent) error ($parent+" is not the parent of "+$child+".") ; // Check Parent/Child Relationship
      
      // Joint Positions
      float $pPos[] = `joint -q -p $parent` ;
      float $cPos[] = `joint -q -p $child` ;
      
      // Parent Orientation
      string $ro = `joint -q -roo $parent` ;
      string $sao = "yup" ;

      // Unparent Child
      parent -w $child ;

      // Vector
      float $jointVector[] ;
      $jointVector[0] = ($cPos[0]-$pPos[0])/$numJnts;
      $jointVector[1] = ($cPos[1]-$pPos[1])/$numJnts;
      $jointVector[2] = ($cPos[2]-$pPos[2])/$numJnts;

      // Deselect All
      select -cl ;
      
      // Loop And Setup Joints
      string $lastJntCreated = $parent ;
      string $newJnts[] ;
      for($i = 1; $i < $numJnts; $i++) {
         
         // Create Joint
         string $jnt = `joint -p ($pPos[0]+($i*$jointVector[0])) ($pPos[1]+($i*$jointVector[1])) ($pPos[2]+($i*$jointVector[2]))` ;
         
         if($i == 1) parent $jnt $parent ;
                  
         // Set Last Created For Reference (Updates Until Last Iteration)
         $lastJntCreated = $jnt ;

      }

      // Reparent End Joint
      parent $child $lastJntCreated ;
   
      // Orient Joints
      joint -e -oj $ro -secondaryAxisOrient yup -ch -zso $parent ;

}


// **********************************************************
// Returns An Index From A String Array
global proc string jgArrToStr (string $array[], int $index) {

      // Get Index From Array
      string $obj = $array[$index] ;
   
      // Return
      return $obj ;
   
}

ScriptSwell - IM - JG
------------------------------------------------
Rigger of the Black Sails

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Wed Feb 10, 2010 11:59 pm

so i saw this i quite a few scripts...

($i = 1; $i < $numJnts; $i++)

what is it for?

here is an other example

($i=0; $i < $nJnt; ++$i)

i know they mean the same, but what are they for? what do they do? what do you tell the I to be?
Image

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Thu Feb 11, 2010 12:02 am

all i can make out of it it:

($i=0; $i < $nJnt; ++$i) in this example:

"i" is equal to 0,
"i" is smaller than $nJnt (or $whatever)
what's the ++$i for?

is this some sort of an if then statment?
Image

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Thu Feb 11, 2010 12:12 am

and why "i" anyway?
Image

User avatar
JayG
Supreme Master
 
Posts: 1154
Joined: Sun Nov 19, 2006 8:25 am
Location: Los Angeles, CA

Re: Auto Rigging tool for maya

Postby JayG on Thu Feb 11, 2010 12:40 am

A FOR statement is a loop. It will repeat what's inside of it a specified number of times.

In the traditional FOR statement you say : for($i=0; $i < $nJnt; $i++)

It's saying:

$i = 0 ----- $i is the counter, and it begins at zero.
$i < $variable ----- the loop will continue until this is false ($i is greater than $variable)
$i++ ----- This will increment $i by 1 each time the loop happens.

$i is just used a lot in loops for some reason, you can use whatever you want though.
ScriptSwell - IM - JG
------------------------------------------------
Rigger of the Black Sails

User avatar
JayG
Supreme Master
 
Posts: 1154
Joined: Sun Nov 19, 2006 8:25 am
Location: Los Angeles, CA

Re: Auto Rigging tool for maya

Postby JayG on Thu Feb 11, 2010 2:58 am

The reason it's < (less than) is because i starts at 0 and not 1. So if you stopped it when i == numJnts instead of i < numJnts than you would get an extra iteration.

if numJnts is equal to 4, you want it to run 4 times.

so if i = 0,

0,1,2,3 (3 is less than 4, so it stops there.)

Otherwise you get:

0,1,2,3,4 which is actually 5 loops.

Make sense?
ScriptSwell - IM - JG
------------------------------------------------
Rigger of the Black Sails

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Thu Feb 11, 2010 10:50 am

does indeed!

thx man!

as far as the script, it's going well, i figured out how to place my bones on the spheres, and right now, i am going through th comet joint orient scrip to understand it. i've learned a lot from it.

so after the spheres are positions it creates a bone for eatch sphere, with the right rotation order, now i need to figure out how to reorent the joints so that they move symmetricaly. i've almost got it figured out.

after that, i will try to find a way to make the user select however many bones he or she wants in the spline and tail.

so right now, it's mainly problem solving and figuring out how to do things. once i have the major things in place i will continue building the tool.

as far as the for statment, if i want letters instead of numbers, is that possible? a, b, c, d, e, etc..
Image

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Thu Feb 11, 2010 4:34 pm

so i tried this to rotate the joint orient by 180 on selected joints, but it's not working... any idea why?

Code: Select all
   string $joints[] = `ls -type "joint" -sl`;
   int $numJnt = size($joints) ;
   for ($i = 0; $i < $numJnt; $i++)
   {
   float $bla = `getAttr $joints[$i].jointOrientY`;
   setAttr $joints[$i].jointOrientY ($bla + 180);
   };

Image

User avatar
Richard
5th member of the Fantastic 4
 
Posts: 1942
Joined: Thu Dec 15, 2005 4:31 pm
Location: Wine, Bagette, Snails
x2
x1

Re: Auto Rigging tool for maya

Postby Richard on Thu Feb 11, 2010 6:03 pm

after reading more mel,

this seams closer to what i want,

Code: Select all
string $joints[] = `ls -type "joint" -sl`;
    for ($joint in $joints){
         float $bla = `getAttr $joint.jointOrientY`;
         setAttr $joint.jointOrientY ($bla + 180);
};


this time i get // Error: No attribute was specified. //
Image

User avatar
JayG
Supreme Master
 
Posts: 1154
Joined: Sun Nov 19, 2006 8:25 am
Location: Los Angeles, CA

Re: Auto Rigging tool for maya

Postby JayG on Thu Feb 11, 2010 6:19 pm

So close, simple fix.

When you add an attribute to a variable ($joint) you need to use a + and quotes, and wrap it in parentheses. This is called "concatenating". So...

Code: Select all
getAttr ($joint+".jointOrientY")

// as opposed to below will give you an error

getAttr $joint.jointOrientY


It's sort of the same way you added 180 to $bla. You are adding a number to another number, so you do the same, add a string to another string.

So the whole thing would be:

Code: Select all
string $joints[] = `ls -type "joint" -sl`;
    for ($joint in $joints){
         float $bla = `getAttr ($joint+".jointOrientY")` ;
         setAttr ($joint+".jointOrientY") ($bla + 180) ;
};

ScriptSwell - IM - JG
------------------------------------------------
Rigger of the Black Sails

User avatar
JayG
Supreme Master
 
Posts: 1154
Joined: Sun Nov 19, 2006 8:25 am
Location: Los Angeles, CA

Re: Auto Rigging tool for maya

Postby JayG on Thu Feb 11, 2010 6:24 pm

Another cool trick, see if you can make it work this way: :)

Code: Select all
for($joint in `ls -type "joint" -sl`) setAttr ($joint+".jointOrientY") (`getAttr ($joint+".jointOrientY")`+180) ;


You can bring your entire loop into one line that way, and if you only have one line in your loop, you don't need brackets. It does the same thing, just shows you what MEL can do.
ScriptSwell - IM - JG
------------------------------------------------
Rigger of the Black Sails

User avatar
JayG
Supreme Master
 
Posts: 1154
Joined: Sun Nov 19, 2006 8:25 am
Location: Los Angeles, CA

Re: Auto Rigging tool for maya

Postby JayG on Thu Feb 11, 2010 6:24 pm

Another cool trick, see if you can make it work this way: :)

Code: Select all
for($joint in `ls -type "joint" -sl`) setAttr ($joint+".jointOrientY") (`getAttr ($joint+".jointOrientY")`+180) ;


You can bring your entire loop into one line that way, and if you only have one line in your loop, you don't need brackets. It does the same thing, just shows you what MEL can do.
ScriptSwell - IM - JG
------------------------------------------------
Rigger of the Black Sails

Next

Return to The Factory

Who is online

Users browsing this forum: No registered users and 1 guest