Pages

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Saturday, March 16, 2013

CGS Head Rig Animation

Hey everyone! I want to share my latest animation. I rigged the head over several weeks and animated it in the past few days. I haven't worked on any corrective blends yet so I'm still open to critiques. The animation is meant to push the limits of the rig. Thanks for watching!

Wednesday, March 13, 2013

Angle Based Deformers

What I am about to talk about is closely related to Pose Space Deformers--I’m sure you can find the original SIGGRAPH PSD papers online. However, the setup I present below is a simple network that allows you to trigger actions and/or blends based on the angle between two vectors. Vectors save the day once again…

Why ditch Euler angles when we already have angle positions?? Because of the nature of Eulers, the X, Y, and Z components are calculated in a specific way that won’t work in many situations. One of the main reasons for this is Gimbal Lock. This one reason can make things a living nightmare for us.
Using the dot product, we can find the angle between two vectors, A and B, by using the following equation:

Θ = acos(A · B)

This means that if we were to attach a locator to a pair of adjacent joints, where both locator’s origin is positioned where the joints connect, you can find the arc cosine of the dot product of both of these vectors, and return the angle between them. I know… it sounds wordier than it really is.

Here’s how I set this up in Maya:
psdNetwork_v01

To be able to see the results of my network, I attached the output of setRange to a blendshape channel. I then animated the joint driving the location of a locator to get a change in the angle between locator1 and locator2. Maya’s angleBetween node returns 0-180, so I scaled that value down to 0 to 1 using the setRange node.

We could have just as easily used an expression to put this example together. However, I prefer to stay away from expressions for anything that I can build using nodes. Native nodes evaluate faster and you can’t break their dependencies by duplicating the network or changing their names!

I hope you can find many uses for this angle based setup. Let me know what you come up with!

Wednesday, February 6, 2013

A List of My Favorite Books

Several people have asked me about what resources I use to learn my favorite topics. There are informative videos and written tutorials scattered all over the web, and only but a few are concise, efficient, and well prepared. This is why I rely mostly on books that are written by seasoned professionals that know a thing or two about teaching. Here is a list of the books I am in love with:

  • MEL Scripting for Maya Animators
  • Mastering Autodesk Maya
  • Stop Staring: Facial Modeling and Animation Done Right
  • Maya Python for Games and Film
  • Complete Maya Programming I & II
  • Art of Rigging I & II
  • Professional MEL Solutions for Production
  • Maya Visual Effects: The Innovator's Guide
  • 3D Math Primer for Graphics and Game Development
  • Game Development with ActionScript

These gems are not listed in any particular order but MEL Scripting for Maya Animators was the first book I ever read on MEL, or Maya for that matter. I bought the very first edition of that text because I was looking for a source of inspiration when I was stuck at home writing Game Development with ActionScript. They are both considered oldies as far as technology goes, so they might be tough to find.

Thursday, January 31, 2013

Useful Regular Expressions

Regular Expressions, or RegEx, are very powerful string parsers that are usually built into most popular programming languages. Both MEL and Python have a version that can be used to speed up your every day scripting tasks.

Just the other day, I rewrote my sav+.mel script in python; it versions up the current file with the click of a button... It's so convenient to use and made me think of sharing some of the tools that I used to write it.

Anyway, in MEL, two commands you should know are gmatch and match. gmatch lets you know if it found a match, by returning a boolean, and match returns the string result. Let's say you wanted to extract information from a path:
 
string $path = "C:/folder/image01.jpg";
// Note: Windows users might want to look
// into using substituteAllString($str, "/", "\\")
// to replace those '/' with '\' or
// vice versa, as needed 

There are a few important pieces of information that we can immediately extract using RegEx. To extract the file name with its extension, try:

// This says: Starting from the end of
// the line ($), extract every character
// that is not a '/' or '\'
// As soon as it finds an '/' or '\',
// it stops the match and returns the
// string it gathers thus far
string $fullName = `match "[^/\\]*$" $path`;

To extract the file name, try:

// This expression matches everything from the
// beginning of the line (^), except '.'
// After it encounters the '.', it ceases to
// match and returns the string
// Notice we are feeding it the result from
// the previous line above... 
string $fileName = `match "^[^.]+" $fullName`;

To get the extension by itself, execute this line:

// This says: From the end of the line,
// find anything up until the '.' or '\'
// Note that if there isn't a file extension,
// the $result will match the original $path
string $ext = `match "[^/\\.]*$" $path`;

To extract any trailing version numbers at the end of the file name, try:

// This says: From the end of the line,
// extract some digits. It's a good idea
// to check if the file name even trails
// with numbers before extraction by using
// gmatch with the same expression
string $ver = `match "[0-9]+$" $file`;

Now that you have all this data extracted, store it as useful information in an object. Unfortunately, MEL isn't an Object Oriented language so there is no straight forward way to create a class of objects that encapsulates attributes and behaviors. You have full support for these things when using C++ and Python. Here's how I would store the info in MEL:

// Now all the information is neatly packed in an array
string $fileInfo[] = { $path, $fullName, $fileName, $ext, $ver };
print $fileInfo;

If you guys and gals would like to know how to extract other pieces of data from strings, let me know. I'll be happy to discuss similar topics as well. I'll write up another post.