Today, I worked some more on getting my player model to render correctly in XNA. Previously, I got the animated model to display, however I noticed some clipping issues with polygons. To tackle this problem, I decided to make an animated textured cube, since that would be easy to analyze. I quickly realized that I was seeing the inside of the cube instead of the outside.
This was happening because I was using a reflect modifier to display my model. Originally, the player model was displaying on its side because Blender uses a Z-Up coordinate system, so in my code I would apply an X rotation of Pi (180 degrees) to fix that. However, this resulted in the model displaying up-side-down. To fix that, I used a reflection on the x-z plane where Y equals zero, Matrix.CreateReflection(new Plane(0f, 1f, 0f, 0f)), to display it correctly. What I didn’t realize was that this apparently also flips all of the normals, so what I was actually seeing was the inside of the player model (with the outside transparent). I believe there is a way to render both sides of the polygons, but that is typically wasteful since the player shouldn’t ever see the inside of a model.
After some searching, I found a good article by John C Brown at Diabolical the Shooter which explains how to make the necessary rotations in the content processor to get all models to display correctly. Similar to his rotation example, I just added a method to the content processor which rotates the NodeContent by MathHelper.PiOver2 on the X axis and MathHelper.Pi on the Z axis. Then that rotation matrix is passed to the MeshHelper.TransformScene method to rotate the model and animation. It is important to note that this modification does not replace the “XNA Rotate Animation Hack” export option in Blender, which is still required to be checked when exporting a model.
After updating that code, I reran the Skinning Sample project with my player model and it now displays correctly. The existing model (“Dude”) is now displaying on its side, since the rotation for Blender is applied to all objects. It would have been nice if XNA provided a method natively to import models using Z Up coordinates. Maybe they consider this a part of “paying your dues” to get a model to display.