Thursday, 20 October 2011

Multiple FBX Animations

Today I used the Windows Phone SDK v7.1 for the first time.  This includes a fix for the FBX importer so that multiple animations can now be imported from one FBX file.

This is great but a friend of mine managed to find a bug with the process already!  I have also carried out some tests.

Whatever the length of the first animation in the FBX file is the length of all animation imported from that FBX file.  I only have access to FBX files exported myself from Blender.

To try to explain a bit better, if your first animation has 30 frames and your second take has 60 frames, the second animation in XNA will only play 30 frames instead of 60!  It is also a problem the other way round.  If the first animation is 240 frames and the you have an animation that should loop at 60 frames unfortunately it will pause after the 60th frame and not loop until it gets to 240 frames!

With that knowledge it is possible to create separate files with all the same length animations in each file, or just export one action per file as I already do.

As far as I can tell the Blender FBX file lists the correct number of frames and times for each action.  I would like to know if this affects other exporters, such as 3DS.  Unless I have a sample FBX file that does work with multiple takes in XNA with the first being a different length to the others then there is little chance of me being able to create a script that works round this peculiarity!

For myself I am already used to exporting individual animations so I will continue to do so. 

== Follow up ==
I posted a question on the XNA forums to see if it is a problem for others:

I had a very nice reply from one of the XNA developers who confirmed that they see the same problem and it will now be reported as a bug.

I have a project that may help some people.  It includes methods for splitting FBX files and allows loading of one animation at a time for testing:

I keep my animations separate from the model anyway so they can be shared but if you want to merge them all together the following article explains how:


Anonymous said...

Still working with that workaround. Added a new animation with more frames then increased first action. All works well!

OlssN said...

How would i export a single animation using blender 2.60?

John C Brown said...

Within the Blender Autodesk FBX exporter remove the tick from the 'All Actions' option. Whatever animation is selected in the action editor will be included in the FBX file.

Anonymous said...

I simply have a system that holds "animation definitions". It's the one big take in the FBX, like ALL systems output, and switching animations is a matter of switching the "start" and "end" frame. Each animation definition also holds:

int startFrame
int endFrame
bool Loop
double TimeScale

Switching start / end frame is going to be faster than dealing with separate assets. (i would think). Also, by having an abstraction, in this case, a "definition", i can hold those extra two values. Time scale is really nice when i want to speed up or slow down a specific animation and leave others untouched.

The only time i wish i could get animations separate, is when i want to apply the same keyframes to other models. Of course, this requires the other models to have pretty much the exact same "bones", which is fine when i'm dealing with lots of "humans"

John C Brown said...

The main part of my design is your last comment. I use the same animations for more than one model. In fact all the human models I use are based on the same armature for that very purpose.

The disadvantage is that I cannot easily use the animations that are often included with 3D characters.

I find the takes easier to manage as separate files. Similar to your method, it is relatively easy to extract a range of keyframes from a long list to convert in to a separate animation.

I also use my own file format with a header containing extra information.

Perhaps I need to do a post on my animation design because it is a hybrid between keyframe animation and coded bone movements. This is so the arms and head can be moved independantly based on where the player is aiming. It makes the over the shoulder view look and feel more realistic.