Sunday, 13 June 2021

Transformation vs Deformation: The Two Pillars of Rigging

Food for thought:
What is rigging, exactly?

Perhaps it's simply making stuff move. But that could also be a description of the animator's job.
Making stuff able to move then, perhaps?
When I need to explain what I do to my grandparents... well I usually just tell them I'm an animator. I work at an animation studio, mine and the efforts of many others are to make animations, I'm an animator. Fuck it. That'll do.

But it really is about making stuff move.
And in Maya there are two kinds of motion. Transformation and deformation.
Every frame, Maya has to figure out where to draw the hundreds, thousands, potentially millions of points in 3d space that we call vertices. Whenever an object is either transforms or deformed, Maya has to run complex calculations to reevaluate the vertices of that object.

Transforming

Yet again, the technical term doesn't sound very accurate to what it describes.
Oh yeah! Transforming. That's that magic button the artists who worked on the Transformers movies pressed and then they all got to go home and be with their families and were not overworked at all! ...Right?

No.
Transformation is very simple, computationally speaking. Translating, rotating, and scaling an object (also shearing, but let's not go there today) is very easy for Maya to think about. If you translate an object 13 units in the X axis, then Maya knows that the new world positions of those vertices just need 13 units added to their x vectors. Computationally, it's very cheap. That's why transformations are quicker to compute than deformations.
If you have a rig that's all rigid bodies, like an automaton of some kind, with no bendy, flexible parts, you could probably rig it without an deformers. And lemme tell you, that would be one buttery smooth rig for the animators to work with.

This is what's possible even when using only transformation:

But just grabbing an object, including all its vertices at once and performing some blanket transformation on it usually isn't enough. Sometimes you need objects to deform (this is a rare case where the technical term and layman's term are the same word). Stuff needs to bend, twist, stretch, flow, flex, bulge, wobble, jiggle, squash, warp.
I doubt this post has had any new information for you so far (unless you're sitting there like "Hoooh! hold up. Go back. What the hell is 'shear?'") but I think it's important to understand the two different mind sets you need to be in when thinking about these two methods of motion.

Deformation

Deformers are the methods by which Maya allows you change the shape of an object non-uniformly. The shape of a mesh object in Maya is determined by the positions of its vertices, so to change the shape of an object non-uniformly means to move the vertices of an object non-uniformly.
What does it mean to bend an object in Maya? It means to rotate some but not all of the vertices about a pivot.
What does it mean to bulge an object in Maya? It means to scale out from a point the vertices of an object, but not all by the same amount.

This is the kind of thing that's only possible with deformers:

Transformation is easy. You just take a transformation, and apply the algorithm uniformly across all the object's vertices.

But deformations have more complex instructions - different instructions for different vertices. Consequently, deformers have more potential to weigh down a rig. Riggers often plan out their rigs to involve no more deformers than are truly needed.

Deformer stacks can be especially heavy. That's when an object has multiple deformers acting upon it, and then the calculations Maya needs to perform can ramp up in complexity very quickly.
If an object has a bend deformer applied to it and then a lattice on top of that, the lattice algorithm cannot just ask "where does this vertex end up once the lattice moves it?" it has to instead ask "where will the vertex be once the bend deform has displaced it, and then the lattice displaces it further?"

You may hear people telling you stay away from this or that deformer because it's simply too heavy. But understand, the time spent calculating a deformer is just the sum of all time it took to calculate the deformer's effects on each vertex. So how heavy a deformer is in any given situation is at least dependent on the vert count of the object concerned.
If it's a simple object with only a few dozen verts, you might be able to go to town with deformers!
But larger meshes, like the body of a character might be a different story.

One of the most commonly used deformers is the skinCluster that connects the vertices of an object to any number of joint objects and transforms the vertices with those joints in accordance with the weight of each joint upon each vertex.
The complexity of this kind of calculation is why game engines often limit you to not having more than a certain number of joints acting upon any given vertex - because every additional joint they allow to join the party pushed up how complex a task it is for the program to figure out the vertex's new position every time the joint moves.

But I've just been describing deformers by their apparent effects - maybe you want a more tangible explanation of what is a deformer.
Well... literally? Deformers are snippets of code, deep under Maya's proverbial hood. They're algorithms. But you'll be interacting with them mostly in the form of nodes, so from that angle it's practical enough to say deformers are nodes, just like everything else in Maya.
When you expand a deformer in the stack over on the channel box, the values you're invited to edit are all attributes on that deformer's node.
And when you graph a deformer node's connections, you'll usually find it taking information from the related object's shape node, and outputting another shape node. These are basically the before and after shapes, and it's the after shape we see reflected in the viewport.

Some other deformers that ship with Maya are blendShape, lattice, bend, cluster, deltaMush, wire, and many many more. There's no complete list of deformers, because people can and do write their own. Writing one's own deformers in the form of plugins is something super smartypants riggers and technical artists do when Maya isn't given them the kind of effect of performance they need, and that's a matter of writing one's own algorithm (in C++ or in Python) for how a given object's vertices should move, all wrapped up in a new custom node which they then access just like any native node.

But that's like... next level. Don't worry about that.

Transforming and deforming...
... at the same time!!

Say we have a very simple scene, with a root control, and under it we have a cube, and a joint, and the cube is skinned to the joint.
What do you think will happen if we move the root control?

What gives? The joint is following the root, and the cube is supposed to be following the joint, so why not cube follow root?
What's happening is the cube is being transformed and deformed at the same time.
The cube is parented under the root control, so when we translate the root control, those translate values are being inherited by the cube.
That is enough to make the cube follow the root control, but joint to which the cube is skinned is also inheriting those translation values, and the cube's vertices are being offset in accordance with the joint's transformation.
The term "double transforms" tends to get thrown around in these scenarios, but I think that's a little inaccurate. Even when the cube has leapt ahead and left the root control behind, notice that according to its pivot point, the cube is still where the root control is:

Don't be fooled by the term 'double transform', the cube has indeed only been transformed once, but then on top of that, it's been deformed, its vertices pushed forward away from its transform position.

In scenario's like these we'd probably like to decide whether or not the cube inherits the transforms of its parent. And we can do so in the attribute editor:

No comments:

Post a Comment