Exporting FBX Files from 3DS Max
XNA requires graphical models FBX format. It will also read .X format, but FBX is a much better format and is recommended. This page is primarily to provide hints on how to get a model from what you start with to a usable FBX model. This should be an easy process. In general, it isn't at all easy, though. The models you get often have problems and are not designed for animation. 3DS Max has a quirky and cumbersome user interface and is very buggy. If you have an associate who is familiar with 3DS Max, that will be a great benefit.
This page is specifically for working with models that will be either static or only have rigid animation.
Before you begin, install the Dr. Owen XNA Utilities Maxscript in 3DS Studio Max.
An Example Asset
I thought it might be useful to just detail how I went through the process one time. I obtained a model for an arachnid from Starship Troopers from an online free site. I thought it might make an interesting model to work with. I'll try to tell just about everything I did.
You will need to test the model to see if it works in XNA pretty regularly. I suggest using the XNA Model Viewer program from this site as a tool for doing so.
Be sure to save often. I find 3DS Max will crash pretty easily.
First, I dropped the model and all of it's textures into a directory called Arachnid. Before anything else I worked on the textures. I created a subdirectory called "originals" and copied them all into there so I would have them later if I needed them. Then I loaded all of them into Photoshop. The main thing you'll want to do is to get the sizes to a power of two in each dimension. They rarely are. Also, they are often much larger than you need. Texture memory is limited, so do you really need a 1218 by 913 image for a butterfly wing? This model has a lot of textures (24), so it could use some texture optimization. Most images were reduced to 128 x 128. Don't worry that the texture aspect ratio changes. The graphics system will stretch it right back out when it draws in on you model.
I loaded the .3ds file into 3DS Max. I immediately saved with the new name Arachnid.max in the directory with the resized texture images.
I recommend that you now reload the file in 3DS Max from its new location. That should get it looking in the right directory for the texture maps.
Now, do File/Manage/Asset Tracking... I selected all of the textures and do Paths/Set Path and set the path to .\ It should show all of the textures as "Found" and you butterfly should be textured. If not, try Views/Global Viewport Rendering Setting/Standard Display with Maps.
Scale and Units
Now a few housekeeping issues. Choose Customize/Units Setup and set Centimeters or whatever standard unit you are using. Then I used Tools/Measure Distance... to measure the height of the bug. This towering scifi monster is a whopping 2.36cm tall! Artists just don't seem to care about scale, but it makes it much easier to use graphic assets if they are scaled correctly. I figured this monster at closer to 300cm tall, so I selected the entire object and scaled by 12712%. Now he is really 300cm tall. That's more like it. Then I used the move tool to set him centered on the origin, feet at z=0. I rotated him so he faces forward (what will be the Z direction in XNA).
Now, 3DS Max uses Z as up, but don't worry about that, since the exporter will change that to Y as up.
One of my pet peeves is not scaling models. A butterfly and an arachnid has a size; any model should also have a reasonable size. I get so many 3D models where the artist didn't pay any attention to the scale.
Now I can export and test this. Do File/Export. Select Autodesk (*.FBX) at the bottom and I usually browse right to the project content directory and add directly from there. I'm saving as Arachnid.FBX. Here are the options I use:
Important: For XNA 4.0, I have been using the 2010 version. That's the FBX library XNA 4.0 is based on. Note the Embed media option. That includes the textures in the FBX file so you don't have to copy them over. Don't check the TIFF option, it's not supported by XNA. I'm not using animation for this object, but if you do, you have to bake it as you see.
It probably won't work when you try it. The following sections detail potential fixes.
Missing Model Parts
This butterfly model looks pretty nice, but guess what happens when I try to look at it from the bottom:
The artist only modeled the wing on one side, thank you very much. I selected the front left wing. I changed the name to WingLeft1Top. Then I did Edit/Clone. Select "Copy", not Instance! I entered the new name as WingLeft1Bot. Then I used the Move box to move it down 0.1cm. In the modifier panel, add the Normal modifier and select "Flip Normals". I did this for all four wings.
I brought up a Scene Explorer:
You can see the new wings on the bottom and they are children of BUTTMAIN (what a horrid name), which I promptly renamed "Butterfly".
Texture and Material Problems
When I first viewed the Arachnid model in the Model Viewer, it looked like this:
The problem was that the artist used the 3DS Max Composite tool to create a texture from two textures. I used Photoshop to combine the textures myself (just a multiply). It still did not show because the material was "Metal" for some reason. I changed it to Phong and the one texture I was working on finally did appear:
For textures that will appear in XNA, the best material is Phong. Set the diffuse color to white. If it is something other that white, that may modulate with the texture color, tinting it.
I had to fix pretty much all of the materials. Most were metal. But, after about a half hour I finally had this:
If all you care about is displaying the model, you are pretty much done, now.
Procedural animation support
I want to be able to animate the limbs under program control. In order to do so, I need to set the pivot points for them. Also, you want a more reasonable skeletal structure. It's also helpful go give things reasonable names.
As I received it, this model has names of various types and no structure at all. Use Scene Explorer to see the structure of the model:
The model was not structured for any kind of animation at all. As an example, the legs were in only two pieces, not three and all four upper legs were one model. I did some mesh splitting to make it all make more sense. I renamed the nodes to be more meaningful. Then, I dragged them in Scene Explorer so they formed a reasonable heirarchy. Here is the hierarchy I ended up with:
If you export this and load with Model Explorer, you will see this structure in the Bones dialog box. If you try rotating any bones, you'll see that they do not rotate around the logical places. So, I used 3DS Max to set the pivot points for each bone. This is in the Hierarchy rollout. I moved and rotated the pivot points so they make sense for an animator.
If you set a pivot point in 3DS Max and then load the model into XNA, you will find the the pivot point "did not take". The model will still rotate around what was the original pivot point. After you set a pivot point, go to the Utilities rollout and click on MAXScript. If you have run the XNA Utilities Maxscript, you should find it in the list of Utilities. Select it to open it and you'll see a new button appear named Pivot Fix. Hit that button to make the pivot work in XNA.
I commonly use the MultiRes modifier to decrease the complexity of a model. It can decrease the number of polygons.
You can collapse a bunch of operations on the stack for an object. Doesn't make much difference, but looks nicer.
Always save before you do Reset XForm or Pivot Fix. It's not undoable and can do strange things sometimes. Avoid doing a Reset XForm to an object with children.