Saturday, April 19, 2008

Spine Rig Part 2: Maya and Houdini implementation

It's been a while since my last post, sorry about that but I've been kind of busy. Anyway I found some time to put together 3 files, 1 Maya file and 2 Houdini files. 
The Maya file is the 1:1 implementation of the diagram presented in my last post. For 
implementation I used utility nodes. Here is the hypergraph shot with the relevant nodes:
You can download the Maya file here:
The first Houdini file is the 1:1 implementation of the diagram. Notice that instead of utility nodes I used expressions. The expression to compute the stretch ratio is on the spineCurve object in the Custom folder and it looks like this:
((arclen("./OUT_ARCLEN", 0, 0, 1) - ch("originalLength")) * ch("../spineOptions/spineStretchiness") + ch("originalLength")) / ch("originalLength")
  • arclen() computes the arclength of the node, OUT_ARCLEN, inside the spineCurve object.
  • ch() is a channel reference to other parameters, something like connections in Maya.
Now that I have the ratio I wrote this expression in each bone length parameter:
ch("../spineCurve/stretchRatio") * ch("originalLength")

The Houdini file is located here:

As you can see in both files you have one parameter to control the stretchiness and the spine behaves in the same way but there are 2 different ways. One uses utility nodes and the other uses simple expressions. Now I could build a Maya file that uses expressions too but I'm after the speed of the rigs and using utility nodes is the fastest way in Maya. 

But some Houdini users may say that there must be a "Houdini way" build this spine. Next I'm going to talk about this way, to please the users and point some interesting advantages.
The file in question is here:

Once you open the file you'll notice that is significantly lighter than the other one. That's because I don't have the 20 bones anymore. I have small cubes where the bones should be. If you go inside the spineCurve node you'll discover this network:
This network is a bit different than the one that belong to the bones version by a couple of nodes. The most important one is the carve node. The carve node lets you to cut a curve the way you want. In my case I'll cut it twice in U.
I jumped the gun here and implemented new features because it was very easy, the spine compression and hip/chest lead. 
Spine compression is a parameter that allows you to compress the spine, or slide the spine down along the curve. 
Hip/Chest lead will let you decide with which part of the body you want to lead. This translates into which part you want to stay put when stretchiness occur.
The other important piece in our puzzle is the resample node after the carve. This node basically stands for the whole bone network. The node resamples the curve in linear segments, how many, in my case 20 because I had 20 bones in the other example.
Next I copied onto each curve point a cube. I've done this for purely visualization purpose.  
Notice that the stretch ratio expression is the same but now instead the bone length expression I have 2 expressions on the carve node.
First U:
(ch("../../spineOptions/hipChestLead")) * (1 - ch("../stretchRatio"))

Second U:
ch("../stretchRatio") + (ch("../../spineOptions/hipChestLead")) * (1-ch("../stretchRatio"))

Play with the parameters and see how the two values changes.
The biggest advantage using this method is the fact that on stretchiness = 1 the last cube will always be where the control point is regardless how crazy the curve shape is. This doesn't happen in a regular spline IK solution. 
Please watch the following movie for a short overview of the 3 files and to see what I meant by the advantage mentioned above. 

Here is the same video in higher resolution:

Next blog entry should be on implementing the spine compression and hip/chest lead across the board and  twist/stabilizing the spine.

see ya soon

Friday, March 21, 2008

Spine Rig Part 1: Building a Stretchy Spine

Building a stretchy spine isn't much of a secret anymore. I'm sure there are tons of scripts that build a spine for you, which is a good thing, but here I'll explain how to build one from scratch and what happens under the hood so YOU can build the script.

Here is a generic diagram of things you have to do to achieve a stretchy spine.
Here is a bigger version of the diagram.

As you can see there are a couple of constants as attributes and a variable parameter.
The term 'at creation' means the state before we start to modify any attribute or parameter from that particular object.
The term 'current' refers at the current state, after we modified attributes/parameters/point and so on for the object in question.

Original curve length is an constant and it stores the length of the curve at creation.
The "Original bone length" is the length of the bone at creation.
Stretchiness is a parameter that takes values between 0 ad 1 and it represents the amount of stretchiness in the bones. 
The goal is to compute a scale ratio for the bone length in such a way that the sum of all bones will meet the stretchiness factor. It will be more clear later.

We take the current curve shape and we find out it's arc length. By subtracting the original curve length we'll know if the current curve is longer or shorter and by how much. The next step will be to multiply the "stretchiness" parameter with the result of the subtract. This way we have the exact amount (positive or negative depending if the curve is longer or shorter) that we need to add to the original curve length in respect to the "stretchiness" parameter.

Now that we have the new current length we have to find a scale ratio for each bone. We do that by dividing the new curve length by the original curve length and we find the ratio. The ratio is greater than 1 if the current curve is longer, and between 0 and 1 if the curve is shorter. The ratio of 0 basically means that our current curve length is 0, in other words the curve is collapsed into a single point, very unlikely. It is this ratio that we need to multiply with the original bone length to find out the current bone length.

That was the basics of a stretchy spine which has a parameter, "stretchiness", that controls how much of a stretch we want.
I hope you enjoyed it and please make sure you'll check the next post about stretchy spine implementation in Maya.

Saturday, March 15, 2008

Why vanilla rigs?

Because I like vanilla ice cream? No, actually I don't like vanilla ice cream, chocolate is my favorite. Ok, let's not make this blog about culinary preferences, I'm sure there are others out there with far more experience than I am in that matter.

I DO like vanilla rigs. Why? simple because you take advantage of the package at hand. 
What do I mean by vanilla rigs? Rigs that use only nodes, expressions and other tools made available by the software developers and no custom plug-ins of any kind, free or not. 
I don't have anything against custom stuff but for the purpose of this blog I'd like to keep everything within the boundaries of a specific application.
Productions these days can spread across continents and make use of vast number of applications. Because of that, vanilla rigs will make everybody's life easier.

Ok I think you got my point and it's time to move on to the specifics of this blog.
I would like to create a series of video examples, not necessary tutorials on how to do stuff, and by stuff I mean rigs or rig bits, because everybody has their own way.
So... in the beginning there was a problem. Then there was a solution to that problem. I'll record how to implement that solution and share it with you. I'll let you decide if it's a good solution, a fast solution, a flexible solution or a crappy one. I very much appreciate any comments to the solution. Also any improvements to the solution are welcomed.

I don't have a specific timeline, I do have a full time job, but I would like to post every week or every other week.

Please feel free to suggest problems in either form, comments to an existing entry or e-mailing me directly. 

That's about it.