Wednesday, 16 November 2016

Rigify for Blender with Unity

Recently we had a play about with rigging custom characters in Blender. We made some simple rigs and correctly mapped the bones to Unity's Mecanim system. This is great for rigging characters to enable them to pick up and use existing animations within Unity.

But what about animations that don't yet exist?
Blender itself can be used to create custom animations. But animating with such a simple rig can be a bit of a headache. Make a slight adjustment to just one bone and your entire character can be thrown out of whack.

To create realistic animations, we really need to be using IK (inverse kinematics) - not just FK (forward kinematics) as our simple rig provides. This is where the Blender plugin Rigify comes in really, really useful!

Starting with a blank (no bones) mesh, and with our editor in object mode, we use menu Add - Armature - Human Rig


There's a chance that the rig appears at the cursor position, ,rather than centred nicely, so set the rig (in object mode) to 0,0,0. At this stage, it doesn't matter if the rig isn't the same size as our mesh - we'll deal with that in a second.


It's debatable whether you should scale the rig, or scale the mesh to fit. We decided to leave the rig and scale the mesh to match it. It's almost there - just needs a little tweak.


We select the mesh and enter edit mode. Then select all the faces and scale the mesh up, ever so slightly. Doing things this way should make it easier for us to create similarly sized characters in future.

To save on work, we click the "x-axis mirror" option and now start to fit our rig to the mesh. While it's tempting to just grab bone nodes and move them around, we've found that rotating limbs into the arms and legs gives a nicer deform when animating the character in later stages.

So, in edit mode, we select the entire leg chain in the rig, click to place the 3d cursor at the hip joint of the leg, then use the rotate handle to position the leg bones as closely as possible to the leg mesh.


Then - just as we did with our simple rig - we move the bones "into" the mesh, grabbing and moving the ends of the bones so that the shoulder, elbow and knee joints are in the best places within the mesh. Don't forget you can rotate the view around and make sure the bones fit into the rig from the top, side and front!


With all the bones positioned, it's time to create our Rigify Rig. With the armature selected in the main window, and the armature tab selected in the treeview panel, scroll down to the Rigify Buttons entry and click the "generate" button.


After a few seconds, the Rigify Rig appears.
We're done with the "metarig" so you can hide it now...


The Rigify Rig contains loads of bones and controllers, spread across a number of different layers. While we've generated a skeleton, we haven't yet rigged it to the mesh. So we need to show the deformation bones in the Rigify Rig. Shift-Click the layer indicated, and the deformation bones should appear. If you can't see them, try turning on the x-ray option also.


Now in object mode select the mesh first, then shift-click the underlying bones/rig, then ctrl+P to parent the mesh to the rig.


We're almost done.
If everything has gone well, you should now have a controllable rig, mapped to the mesh. Select the rig and enter pose mode.

Grab one of the IK indicators around the feet or hands, and set the IK value from zero to fully one. Move the IK object around and watch your character's legs/arms move around in response to your positioning the hand/foot.


Using IK makes positioning your characters much, much easier than an entirely FK bone-chain. We're now off to have a play with the FK/IK settings in Blender and see what's involved with creating a simple walk cycle.....



No comments:

Post a Comment