Model Rendering in Game

Today, I exported my Blender helmet model to AutoDesk FBX format to try to get it to render in my game in real time.  The first problem I encountered was that it could not detect my texture.  This was because I was borrowing the texture from the “boot” folder when I did the mapping in Blender.  Therefore, I had to move the texture I  was using in Blender to a “texture” folder at the same level as my exported FBX model.

After loading the FBX model and texture as content items in my project, I created a new Screen subclass which is the 3D display.  Theoretically, this could run concurrently with the existing 2D game screen.  For now, I just created a new main menu item for the 3D game screen.  Using an example from Microsoft, I created a new method in the 3D game screen which renders the model(s).  The model is first loaded in my main game class, then the new model draw method takes the list of models as a parameter.  It also takes the aspect ratio as a parameter, since that is what the example does, but I may remove it or make it a constant later if it does not change.

screen073

Finally, after I finished setting up my model and I ran the program and all I saw was the blue clear color.  Then I noticed a small speck which I first thought was a piece of dust.  This at least let me know that something was rendering, because removing the model drawing code would also remove the black speck.  I think this was because the example code has the camera Z position at 5000f, which I guess was for a really huge model.  Next I tried removing the lines of code in the effects loop for World, View, and Projection one at a time.  By removing all three, I was able to see a rendering of what looks to be the top side of the helmet.  After thinking about it, this makes since because in Blender the Z axis is up, but in XNA the Y axis is up.  Another possible problem is that some of the transformations in the example code look for a parent bone, which I don’t currently have defined for my helmet.

I remembered having to change the export coordinates when exporting my building objects for TetraCity to OBJ format, so that it makes Y up instead of Z.  In the FBX exporter for Blender 2.6, this option is found in the lower left corner of the file save menu of the exporter.  This is really easy to miss if you’re not looking for it, because previous versions of Blender had most options in a popup dialog box.  The fix is made by setting “Forward” to “-Y Forward” and “Up” to “Z Up”.  Selecting “-Y Forward” should automatically set “Z Up”, which is faster because “Z Up” can not be selected with “-Z Forward” selected.  There are also two options for XNA.  I don’t know what these do, but I went ahead and selected them.  Select “XNA Strict Options” should automatically select the other XNA option.  Even with selecting Z Up option, my model was still displaying as if Y is on the horizontal plane.  Either the exporter is broken or my model is not getting updated in the XNA project.  I tried exporting my model to a new filename, and I imported the new model but I still got the same results.  Therefore, the exporter does not appear to be translating the coordinates appropriately for some reason.  Alternatively, I could fix the rotation in code, but that is just one more additional thing to have to do.

screen074

So to get an object moving around the screen, I basically had to go back to step one from three months ago.  I added my helmet object, and added velocity controls to move it up and down.  Once I figure out how to get my current game coordinates to map to 3D space, then I think most of my game world coordinates should translate over with little effort (hopefully).  There also appears to be some tearing with the polygons, which I think may be due to the Z ordering of the faces, because some of the lower polygons will appear above the higher ones.

screen075