Sunday 10 July 2011

Before Animating With Blender

Before you can create animations with Blender you must setup your model the right way.  There are plenty of tutorials on the Internet that will explain this as part of 'how to animate with Blender' but it is easy to miss these important steps.  This is a common reason why people have trouble getting animations to export properly for use in XNA.

The short summary is:
  • Create your model mesh object
  • Add an armature (skeleton)
  • Tell Blender that you want to use that armature
  • Make that armature the parent for each mesh that you want to animate.
  • Assign bone weights to the mesh by weight painting or adding bone vertex groups.
  • Create animations

The initial steps must all be done BEFORE you start creating the animations otherwise you might have problems exporting those animations.  The animations still work in Blender but it may be impossible to export them and you will have to recreate the animations!

Armature

An armature is the skeleton used to pose the model.  I won't go in to detail here about that as this article is about the prerequisites of animations not the animations themselves.

Create the skeleton by adding bones.


Edit: 2 Sept 2015
I came across a very interesting auto-rigger called Rigify.  Worth a look, see the following tutorials:
http://blog.digitaltutors.com/rigging-minutes-blenders-rigify-addon/
http://cgi.tutsplus.com/tutorials/create-an-animation-walk-cycle-in-blender-using-rigify--cg-17812
Note that you need to enable IK (Inverse Kinematics) on both the arms and the legs before the various controls act as you might expect.

Naming Objects

When you name any object especially bones it is worth avoiding the decimal point '.' (period, dot or full stop.)

Blender is happy with a full stop but the FBX exporter will rename it to an underscore '_'.  For example, 'Arm.R' becomes 'Arm_R' in the FBX file.


More Than One Way

This is where it starts to get complicated because there are multiple ways to do the same thing.   I will explain, what I call, the manual process first and then mention the shortcut method at the end.

Modifier


Blender needs to know which armature is used with which object.  Simply select the object mesh you want to animate and add an armature modifier with the desired armature.

This is done in Object mode.  You do NOT need to apply the modifier.  It is just used like a note to Blender so it knows what links to what.

It is common to name the Armature 'Armature' and that can be a bit confusing because that is also the name of the modifier to add.  I tend to rename my armatures but as most new users leave the name as 'Armature' I have done that for this screenshot.


The modifier panel is on the right and the name of the skeleton is shown in the 'Object:' box.  In this case it is called 'Armature' and the mesh to which it is being added is called 'Cube'.

Parent

For animations to export correctly it is also necessary for the armature to be set as the parent for any object mesh that you want to animate. 


Initially the mesh will not have a parent.



Again, in object mode with the object mesh selected.  Go to the Relations panel and change the parent to the name of the armature you want to use.



Same example as above, the object is called 'Cube' and the armature is called 'Armature'.



Weight Paint

When you animate a model with bones you need some way to tell the model which vertices to deform depending on which bones you move.    That is called assigning bone weights.  The techniques for doing that are way beyond this summary post.  There are some links to articles about how to assign weights on my tutorials page:
http://blog.diabolicalgame.co.uk/p/tutorials.html


I find I keep adjusting the bone weights, even after creating the animations, to improve the results.  For complex models I find that manually assigning the vertices to vertex groups is the more reliable method rather than using the pretty paint brush style Weight Paint method.


Shortcut Method

The above methods of 'Add the modifier', 'Parent the armature' and Weight paint' can be done in one go using the Parent function. 

In Object Mode, select the Object you want to animate, shift-select the armature and press Ctrl-P to parent the Armature to the Object.  Select one of the weight paint methods from the list that is displayed and job done.

I find this useful for getting started or for very simple models but invariably I have to adjust the weight painting.

Whatever method you use you can go on to create animations.


Create Animations

With the armature selected you can change to pose mode and create animations.  These must be saved as actions using keyframes.   Press 'I' and from the popup menu select 'LocRotScale' to save each keyframe.  

Use the ActionEditor view to see and edit a list of the keyframes saved. 


The Action Editor is often hidden because it is on a separate menu on a toolbar.  Change the option to Action Editor to see the list and change animations.




With the above settings done first it should be possible to export the animations for use in XNA. 



Export

I have a another post about that:
http://blog.diabolicalgame.co.uk/2011/07/exporting-animated-models-from-blender.html

Multiple animations in one FBX file is possible with Windows Phone SDK v7.1 but there might be a problem:
http://blog.diabolicalgame.co.uk/2011/10/multiple-fbx-animations.html

And the Blender Wiki instructions:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/Autodesk_FBX


==


Discussion thread on the XNA forums: http://forums.create.msdn.com/forums/p/68149/521975.aspx#521975


==

I'd like to thank Ernest Poletaev for pointing out that the mesh had to be parented to the armature and reminding me to include weight painting in the list.

Thanks to Gary Haussmann for pointing out that decimal points will be replaced by the exporter.

4 comments:

Ernest Poletaev said...

Great article, but I think is need to add weight painting step

John C Brown said...

Ernest, thanks. You are right. I've added that step.

Unknown said...

Hi John, it's Gary again. I looked into my problem where the exporter locked up for certain animations. It appears to occur when I have the Cyclic modifier applied to one or more animation curves. Perhaps it appears that the cyclic animation is infinite in length or something? Anyways, after removing the cyclic modifier the animation appears to export fine.

John C Brown said...

Gary. Thanks for the update. That's another tip for everyone to watch out for.