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.

1 comment:

Anonymous said...

Can't wait for the houdini part!
Tks a lot Calin.

Labuzz from france.