Demonstration of switching between 2D and 3D rendering, along displaying an animated Blender model in XNA
Today, I worked on getting my simple character model animation to display in the game world. Currently, the player model displays fine, but it does not display the arms and legs moving as the player moves. I found quite a few references for animating a Model, but none were very simplistic. One thing in common with all of the examples is that model animations are not handled “out of the box” by XNA. The technique used requires that the animation information be extracted from the model using the “Tag” property, which is sent to a custom Pipeline animation processor. Two good examples of how to do this are the Microsoft SkinnedSample project and Michael Neel’s XNA 3D Primer. Using these references, I was able to get my player model moving in a XNA game window.
However, I found that the method I was using to generate the sprite animations was not compatible with importing for 3D animations. The process for preparing a Blender model for export to FBX format for XNA is nicely explained in this article by StormCode. Using that information, I was able to use the Action Editor in Blender to create a named animation. In the 2.6 version of Blender, this is located under the DopeSheet screen. The article also gives valuable tips on how to create a keyframe containing all bone information and how to duplicate keyframes. Previously, I used the record button in Blender to create keyframes, but that only records the bones that are actually changed.
After exporting my model to FBX format, I was able to import it into the SkinnedSample project. I created new Model and Animation objects for my model. That project is covered by the Microsoft Permissive License (Ms-PL), so I think I can use that code in my own project. However, before I do that I want to compile it into its own library, so I can just link it and pass my models to it without having to add Microsoft’s code to my own project. The only problem I’ve seen so far is that some polygons will sometimes incorrectly overlap each other, so that is something I will need to resolve.
While I was working on the game screen, I was able to resolve the issue with the model appearing so dark. This was because the diffuse property on the mesh effect needed to be set to White.