Delta Engine Blog

AI, Robotics, multiplatform game development and Strict programming language

How to export .X files from 3DS Max for use in XNA

This little article give tips on how to export an .X file from 3DS Max 8/9/2008 into the XNA Racing Game engine. I got several emails on how to do that and instead of repeating myself, here is the article :)

First of all you (or your graphic artist) need a version of 3DS Max, I recommend the most recent available version (e.g. Max 2008 has much better support for .DDS files and makes the exporting process way easier). If you do not have 3DS Max, you can test it for 30 days, that should be enough for testing and exporting some existing 3D Models ^^

Ok, next you will need the Pandasoft DirectX Exporter for your Max version, you can find all versions and downloads here. Also make sure you meet all the prerequisites:
http://www.andytather.co.uk/Panda/directxmax_downloads.aspx

Before you start exporting you have to understand that XNA can only render 3D geometry when a shader is used. You can't just put up a gray box like in 3DS Max that easily (if you would like to do that you will need a simple gray box shader). For this reason you will have to make sure that each mesh that you export has a shader material assigned to it and in order to work correctly with the XNA Racing Game engine it must be a shader that is supported by the engine like ParallaxMapping.fx, NormalMapping.fx or some other test shader.

Lets go through all the steps. Please note that experienced 3DS Max users will probably only need the Panda Exporter and figure the rest out themselves. This tutorial is for beginners and people having trouble getting 3D Models exported for the XNA Racing Game (or other games that used my XNA Graphic Engine project).

Step 1: Load the Cactus.max (312 KB) model as an example. If you put the used texture Cactus.dds (170.8 KB) in the same directory you should see the following result:


Step 2: In case you can't see the model, also make sure the used Shader (NormalMapping.fx (10.99 KB, for 3ds Max) for this model, make sure you have a NormalMapping.fx in your XNA Graphic engine) and all other required files exist in the same directory; like the normal map texture CactusNormal.dds (341.47 KB).
If you want to change an existing 3D model and let it use a shader, open up the Material Editor in 3DS Max (e.g. by using the M hotkey) and create a new DirectX shader material. To do that click on a free material spot, click Standard (1.) and then select DirectX Shader (2.), now select the shader you want to use and fill in all the required shader parameters (colors, textures, etc.).


Step 3: Now export the 3D Model as an .X file via the Panda DirectX Exporter mentioned above. Make sure settings in the Texture & .fx files and the X File Settings are as shown below. Most importantly you need to make sure all fx parameters are exported and the file does not use a left handed axis (default behavior) because our XNA engine defaults to the default right handed axis behavior in XNA. Using a binary file type will improve the file loading time.


Step 4: Now you should have the Cactus.X (26.21 KB) model file. You can drag this file and the textures into the Content directory of your project now (1.), then exclude the Cactus.dds and CactusNormal.dds textures (2.) because they are automatically generated by the dependencies in Cactus.X. Finally click properties of the Cactus.X file (3.) and make sure you use the XnaGraphicEngine Model (Tangent support) content processor (4.).


Step 5: Now with everything in place it is time to test if we can load the model and see it on the screen. I usually use the following unit test in the Model.cs class called TestSingleModel:


Step 6: Which finally leaves us with the result if everything worked out. It rarely does on the first try, go through the steps again and make sure all files are there and you can use the shader and textures in the engine as expected, you might have to rename shaders and directories and resave the .x file until everything is correct. BTW: I used the XnaRacingGame engine from http://XnaProjects.net here. Good luck :)
Comments are closed