Blendering for Unity (Six)

Rigging

;

Posted 05/09/2014 18:15:27 in Blendering for Unity

Updated 08/20/2017 19:14:36

Rigging is the process of adding "bones" to a mesh, greatly simplifying the animation process. Each bone is associated with the nearby vertexes on your mesh, so when you transform a bone, it will drag the vertices with it. The entire set of bones are collectively called an "armature," or a "rig."

First off, you'll want to set up the Blender UI to make rigging your character a bit more manageable. Change your UV frame back to a 3D Viewport, activate Object Mode (Tab, and this will change both of your viewports to Object Mode), and set the shading mode to Solid on both views. You'll also want to set the left viewport to a front ortho view (Numpad 1) and the right viewport to a left ortho view (Numpad 3).

Using two 3D Views.
Using two 3D Views.

I think now is a good time to learn about Blender's 3D Cursor. You've probably accidentally left clicked in the 3D viewport by now, and you might have noticed that it moved the little target cursor. This cursor has a 3D position in your scene, and it has a few uses. The first is that it can be used as a reference point for transformations. I'll go into how to take advantage of that a bit later in this post. The second is that it represents the position where any new object added to your scene, and since we're going to be adding an armature to our mesh, we're going to want to position the cursor to where we want the first bone to be added. Left Click around your viewports to move the cursor, and notice how it maintains its 3D position. If you click it around in the left (front view) viewport, you can see in the right (left view) viewport that it only moves on the X-Z plane, and the Y position remains unchanged. This is because it will only move along the plane that the viewport camera occupies, much like how the grab and rotate tools work. If it has different behavior (e.g. it moves to the surface of the model), there is a setting in User Preferences that can be changed.

Hit Shift-C to relocate the cursor to 0, 0, 0. We'll add our first bone right at the origin of the model.

Open the Add menu in either viewport (make sure you're in Object Mode!), and select Armature->Single Bone. You'll see it appear, but most of it will be obscured by the mesh. We can fix this by going over to the Properties frame, looking in the Display category, and checking X-Ray.

Adding an armature.
Adding an armature.
The armature, added.
The armature, added.

Now that the first bone is created, our armature exists and is ready to be edited! Make sure that the armature is selected and your mesh isn't (it should be by default), and hit Tab to switch to Edit Mode.

Bones are basically made up of two nodes, the head and the tail. Each point is selectable, and the entire bone is selectable as well. Select just the bottom node of this bone (the head), and move it upwards so that it is entirely inside the character (remember, G and Z to lock!). It's important that all of the bones are completely inside your mesh, otherwise when we parent the armature to the mesh (basically, when we tell Blender that we want these bones to affect this particular mesh), it will lead to errors. However, don't worry about it if the middle parts of the bones scale up and poke through (this tends to happen on smaller parts of models, like arms or fingers). All that matters is that the end nodes and the straight line directly between them are inside.

Moving the root bone.
Moving the root bone.

It helps to keep the bones of your armature organized, so look back over to the Properties frame and flip it to the Bone tab. You'll see a space for a name, so type in "Root" there and hit enter. Naming bones will also make the process easier and faster later on, as you'll see.

Selecting the Bone tab.
Selecting the Bone tab.

Let's start fleshing out the armature by adding the left hip. Select the lower node of the Root bone (the head) and hit E to start an extrusion. Do this from the left (front view) viewport, it'll just make your life easier :) Drag it outwards, and left click to confirm. Look back at the Properties frame and name this bone "Hip". (l as in lemon, not #1). The ".l" at the end signifies the left side, and naming your bones with suffixes is a really good habit to get in to. Unity's Mecanim system can use those suffixes to help determine how to properly animate your Humanoid armatures. Currently we're actually working on a Generic rig, but when you go on after these tutorials to create characters with Humanoid rigs it will really help. And really, the only thing you need to do to make a rig humanoid is to make sure you have enough bones and in the proper places. But I digress.

Extrude another bone from the tail of Hip.l and end it at the tip of the foot while making sure it's still within the mesh. It doesn't have to be perfectly on the edge of the foot, just having it nearby will suffice. Name this one "Leg.l".

Now that the leg is finished, select the top (tail) node of the Root bone and extrude once to create "Shoulder.l", and again to create "Arm.l".

Extruding bones automatically parents the new bone to the one that you extrude from. When a bone is a child of another, rotating the parent will automatically rotate the child as well. It's pretty intuitive, but it seems worth mentioning anyway.

Hip bone.
Hip bone.
Shoulder.
Shoulder.
Arm.
Arm.

Take a moment to rotate one of the viewports around to make sure everything looks good and that all of your bones are inside the mesh.

You could go through the same process on the other side to add the right arm and leg, but that would be tedious (especially if you were working on a model that had multiple arm joints, fingers, thumbs, individual toes...). Using the magic of Blender, we can just copy our left side! Select all of the side bones (making sure to leave the Root unselected), and make sure that your 3D cursor is centered (Shift-C). What we're going to do is duplicate these bones, and then scale them by -1 on the X axis (effectively mirroring across the Y-Z plane). However, if we just went ahead and did that now, the bones will just flip in place of where they are right now, giving you two sets of bones on the left side of your character. We can remedy that by changing the "pivot point" to the 3D cursor instead of the active element by using the menu at the bottom of the 3D viewport.

It's pretty useful to know exactly how each of these pivot points work:

  • Active Element: This will apply whatever transformation you're using relative to the currently selected element (or the last one you selected, if you have multiple things selected).
  • Median Point: The transformation will work relative to the median point of everything you have selected.
  • Individual Origins: This applies for transformation made in Object Mode (which you shouldn't be doing!), but the transformation will work separately on each object you have selected, relative to their respective origins.
  • 3D Cursor: The transformation will work relative to the 3D Cursor, which can be super useful.
  • Bounding Box Center: The transformation will work relative to the spacial center of your object. Note that it's the center of the currently selected object, which is our armature. Since the armature is only half finished, the center of the bounding box is the center of what we have so far, not the center of the mesh.

So go ahead and change the pivot point to "3D Cursor."

Pivot on the 3D cursor.
Pivot on the 3D cursor.

Press Shift-D to duplicate the left-side bones. After duplicating them, Blender automatically activates the grab tool, but if we activate our own tools it will cancel that out. Now, press S to activate the scale tool, X to lock to the X axis, and type -1 to scale by -100% and left click to confirm. That's a feature I hadn't mentioned until now; you can type in a number while using any of your basic tools (for example, you can hit R to activate the rotate tool and type 45 to rotate it by 45 degrees). So, again, that whole shortcut sequence was Shift-D to duplicate, then SX-1 and either left click or hit enter to confirm.

By default, Blender has added the suffix ".001" to each of our duplicated bones, resulting in terribly awkward names like "Shoulder.l.001". Since we named all of our bones with a ".l" we can actually have Blender automatically change all the names for us. Make sure that you still have all of the right side bones selected (the ones with ".001" suffixes), open the Armature menu at the bottom of the 3D Viewport, and select Flip Names. Now they all have nice ".r" suffixes!

Flip the names.
Flip the names.

The downside of this flipping technique is that the new bones aren't directly connected to the root bone. Select the Shoulder.r bone, look over to the Properties frame, and check "Connected" in the Bone tab.

An alternate and faster technique, as pointed out in the comments by v_n_j, is to start your rigging process by checking "X-Axis Mirror" in the Tools panel (to the left of your 3D viewport) under Armature Options before doing any extruding. This will allow you to extrude both sides at the same time using Shift-E, and it will also mirror any transforms (grab, rotate, scale) that you do.

You'll want to leave both hip bones _un_connected to the Root bone. They'll still move with the Root bone when you transform the Root (you can see a dotted black line from the head of the hip to the tail of the root representing the parent relationship if you grab and move one of the hips around). Child bones are always attached to the tail end of the parent.

We're leaving the hip bones disconnected to give the armature a normal shape. If you connected the hips, it would result in a strange star-shaped skeleton (you can try checking "Connected" to see what this looks like, but you'll have to hit __Ctrl-Z __to undo the change afterwards). Aside from this use, another useful property of unconnected bones is the ability to use the grab tool to move them when you're posing the armature. Normally, you can only rotate bones. This can be useful if you want to stretch a part of the mesh, while keeping another part intact (I used this technique for the hook dropping animation in Sail! The hook bone kept the hook from stretching, but allowed the rope part of the model to stretch down).

Disconnected bone in Sail's hook.
Disconnected bone in Sail's hook.

Our armature is finished! Look around it once more to make sure all the bones are nicely inside the mesh, then toggle back to Object Mode so we can parent the armature to the mesh.

When you select multiple objects or elements in Blender, the last object you select actually has the special status of being the "primary" selection. I hinted at this before in the Active Element pivot point mode description. In that mode, your transformations will happen relative to your primary selection. Most of the time there isn't much of an effect when that mode isn't active, but it matters here. When you parent an object to another, Blender will parent your primary selection to your secondary selection. The primary selection will have a brighter orange outline than the rest of the selected objects.

Make sure you select the mesh first, then the armature, then hit Ctrl-P to open the parenting context menu. Click "With Automatic Weights" underneath Armature Deform. That's all there is to it! Look at the Info frame at the top of the screen to make sure there weren't any errors. If there was, there are a couple of main things that could've went wrong:

There could be a bone poking out of the mesh somewhere. Check around to make sure they're all inside.

Blender doesn't like it when there are openings in the mesh, and I haven't found a way to get it to automatically parent correctly when you have open meshes. In this case, you'll probably have to manually weight paint each bone. Since we've been working with an entirely closed mesh, you shouldn't have to worry about this now unless you accidentally deleted a face. If you did, you can select the vertexes around the face in the mesh's Edit Mode and press F to fill it in, and then retry the parenting process.

Weight painting was automatically done by Blender when we parented the rig to the mesh. Each bone has a "weight" for, or amount of influence on, each vertex in the mesh. The Blender Wiki has more information if you're interested, and it's a bit beyond the scope of this series, so I'll leave it at that for now.

Parent with Automatic Weights.
Parent with Automatic Weights.

We're done! Now that we have a parented armature, you can flip back to Object Mode, select only the armature, and switch to Pose Mode (using the menu at the bottom of the 3D viewport) to see the results of your work! Rotate the bones (R) in Pose Mode to see the results of your hard work (and make sure you switch the pivot point back to either active element or median pivot point).

Just make sure you undo all your changes to the pose (Ctrl-Z) or cancel your rotations (Right Click or Esc before confirming them with a left click) so that you have a neutral pose when you start animating!

Continue to Part 7: Animating

Striking a pose.
Striking a pose.

Comments

Ankylo

If you follow your way of creating symmetric bones, blender no longer removes the ".001" suffix. They added a new feature though, instead of Ctrl-D --> s x -1 you can hit w -> Symmetrize to do the same thing (and automatically fix the bone names)

06/25/2018 07:00:33

v_n_j

You can actually extrude bones symmetrically, it's much easier than your approach. You just need to select "X-Axis Mirror" in left panel in 3D view(one that toggles with T), and then extrude bones with shift+E and that's it.

05/10/2014 03:06:51

Zak

Awesome! I didn't know that before, I'll add it into the post. Thanks for the tip!

05/10/2014 16:55:19

great tutorials, keep them coming!

05/10/2014 03:12:57

nice

05/13/2014 05:33:54

winhelp

More ways to make symetrical rig: http://www.youtube.com/watch?v=pc_zWUhSmvE

05/28/2014 08:43:05

winhelp

And to the last "Just make sure you undo all your changes to the pose (Ctrl-Z) or cancel your rotations (Right Click or Esc before confirming them with a left click) so that you have a neutral pose when you start animating!" You can back to original pose by reseting rotation of bones (A (select all), Alt + R (clear rotation))

05/28/2014 09:04:25

Zak

Awesome tip! Thanks!

06/02/2014 19:32:00

Ike

When I select x-Ray it doesn't seem to affect the bones, so I have to put the mesh in wire mode so I can see the bones. Am I doing something wrong? D:

01/12/2015 00:15:47

Zak

Hmm what version of Blender are you using? I just tested in v2.72 (the second-to-newest release) and it still works the same way. I would double check that you have the armature selected (not the mesh object) when you check the X-Ray box, and that the mesh object doesn't also have X-Ray on.

01/14/2015 20:19:12

Ike

I think I didn't have the armature selected, but I repeated the steps (also using version 2.72) and now it works lol. Thanks for the reply though, just have to import my little guy into Unity and I will make a post of my creation!

01/16/2015 00:28:10
Today