Game Creation with XNA/3D Development/Importing Models

Importing Models
''In the previous chapter we learned how and where to find 3D models. The real problem comes about when you actually want to use them in your game. There are many issues to worry about. So here we show you how to import models generated with'' into your XNA game.
 * Cinema4D
 * Maya
 * Blender
 * Sketchup
 * Others

Introduction
The topic of this short intro is, how to import models in XNA. Why we put this import stuff in the introduction has a simple reason... it is everytime the same with the .x files or with the .fbx files.

Now, how do we Import the model into the XNA framework?
First of all, the bones and polygons of your model are limited in XNA:
 * 1) Bones: max. 59 up to 79 in 4.0
 * 2) Polygons: depends on the hardware

I will show you how to import the model by using the simple code from the msdn.com site. This demo shows the most important methods which we need. Demo: http://create.msdn.com/en-US/education/catalog/sample/skinned_model

First we need a model:

next we take a look at the LoadContent method:

The LoadContent method is the only way to import your models. We do not take a look on the animation so far, but this is either the topic.

Author
FixSpix

Cinema4D
Cinema 4D is a 3D modelling tool from Maxon and is comparable with Autodesk Maya. C4D is able to export .fbx files which then can be imported to XNA. There's no possibility to export directely to .x files like in Google's SketchUp.

In the link below you can find helpful links concerning Cinema 4D: http://www.der-webdesigner.net/forum/cinema-4d-f3/linksammlung-cinema-4d-t5919.html

Simple .fbx file export
When you are using the normal .fbx export, sometimes the textures aren't exported as well. It's a bug caused by Maxon's C4D - maybe it works, maybe not.


 * File
 * Export
 * Expot as .fbx

Settings for the normal import: http://iclone-freebies.wikispaces.com/file/view/fbxexport.png/176558803/fbxexport.png

Exporting a .fbx file with a plug-in
In the link below you can find an exporting/importing plug-in for C4D: http://forums.creativecow.net/readpost/19/873735

YouTube Turtorial: http://www.youtube.com/watch?v=nX2k81T1eaQ

Download: http://www.cactus3d.com/Plugins.html

Now you can import the .fbx file into your XNA program. It may be more reliable than the export into a .x file.

Importing in XNA
Actually for XNA it is insignificant whether the file is a .fbx or a .x file. It is only important for the modeler concerning the software they are using.

--> Introduction

Author
sfittje

Maya
Maya is a commercial 3D computer graphics software from Autodesk. It runs an many different operatings systems like Linux, Mac OSX or Windows. Its used for all 3D applications like video games, animations, films or visual effects. Maya and 3Ds MAX are both from Autodesk, these are consimilar with each other.

Is it possible to export .x files from Maya?
The main problem in Maya and XNA is that both are written in different languages. Maya is written in OpenGL and XNA is basend on DirectX. According to this problem it is tricky to import .x files from OpenGL to DirectX but there are tools to manage this, like the cvXporter.

How to Export (.x)?
If you use the cvXporter, here are a few steps to use this tool. Click http://www.chadvernon.com/blog/resources/cvxporter/

Here is an example how to manage the problem if your plug-in doesn't work! Click http://www.gamedev.net/topic/383794-exporting-x-files-from-maya-70/

Please do only these steps if the fbx and .x importer doesn't work. I will talk more about the fbx importer later.

How to Export (.fbx)?
The fbx format is the simplest way to export a file which can be used in XNA. Maya doesn't support the fbx file format so we have to use a plug-in. http://usa.autodesk.com/adsk/servlet/pc/item?id=10775855&siteID=123112 This plug-in allows us to export fbx files in Maya.

What an amazing coincidence... Autodesk knows a lot of problems and wrote a whole e-book for fbx files in Maya. So if you have some problems with the fbx exporter, please use this quite useful link. E-Book on fbx & Maya: http://download.autodesk.com/us/fbx/2010/Maya_online/_index.html

How to Import?
--> Introduction

Author
FixSpix

3ds Max
3D Studio MAX called 3ds MAX is a commercial 3D modeling tool from Autodeks.In the use and logic between Maya and 3ds Maya are not so many differences. The one and only diffence is 3ds MAX runs only on Windows systems.

Is it possible to export .x files from 3ds Max?
First of all there is no possibility to export a .x file from 3ds Max, but there are a lot of quite useful plug-ins for 3ds Max. One of those is KWXPorts.

http://www.kwxport.org/

This tool allows you to put the x into 3ds Max. XNA support also the FBX Format as well. But there could be some problems with the animations and textures of your model.

How to export?
...a few minutes later...
 * First download the plug-in from the web-source above and install the tool.
 * In 3ds Max
 * File-->
 * Export-->
 * KWXPort(format)-->
 * The KWXPort Export Options
 * 1) Geometry
 * 2) Import the Normalt(lightning)
 * 3) Make Y up (for the right alignment)
 * 4) Export flight-handed Mesh (the mesh from the model)
 * 5) Materials
 * 6) Export Materials
 * 7) Export Textures
 * 8) Animations
 * 9) Export Animation: There is a list of all your animations, if you setup some of them in 3ds Max.Your have the option to give names to the different animations and put these animations in the correct frames from your hole animation.
 * 10) Finaly
 * 11) Export as Binary(gives us the best format)

The result is a combination of three files. In the log file are quite useful information for us. The number of verteces......and the whole bone-structure of the model with the complete hierarchy of these. The DirectX SDK Viewer is a nice tool to check your .x file. There you have the possibility to see the normals, the textures... on your model from the .x file.
 * 1) The Texture: nameofthemodel.png
 * 2) The DirectX File: nameofthemodel.x
 * 3) The .X Log-file: nameofthemodel.log

DirectX SDK http://msdn.microsoft.com/en-us/directx/default

How to import?
-->Introduction

Author
FixSpix

Blender
Blender is the Linux under the 3D modeling software, it is a completely open source program and it runs on all known operating systems. You can do anything with blender like in the other commercial tools like Maya and so on.... UV Mapping, rigging, skinning.... and also for animations in games and film.

Here is a list of nice tutorials for Blender in combination with XNA. Part1: http://www.stromcode.com/2008/03/10/modelling-for-xna-with-blender-part-i/ Part2: http://www.stromcode.com/2008/03/11/modelling-for-xna-with-blender-part-ii/ Part3: http://www.stromcode.com/2008/03/13/modeling-for-xna-with-blender-iii/ Part4: http://www.stromcode.com/2008/03/16/modeling-for-xna-with-blender-part-iv/

Is it possible to export .x files from Blender?
No blender cannot export to .X without a plugin.

How to export(.x)?
The result is a nice .x file from your model.
 * 1) File-->
 * 2) Export-->
 * 3) DirectX(.x)

How to export(.fbx)?
Here we are, again the only solution is a plugin. What else? Blender supports the script language Python, here is a nice script for the export to xna. http://www.triplebgames.com/export_fbx__for_xna.py

How to import?
-->Introduction

Author
FixSpix

Sketchup
Sketchup is an opensource software from Google for developing 3D models. There are two different versions available - the "normal" and the Pro Sketchup. In the normal version 3D exporting is restricted supported. You can only export your models into 2D image formats like .jpg, .png, .tif and .bmp or the one and only 3D format COLLADA (.dae). The Pro version allows exports into additional 2D formats (.pdf, .eps, .epx, .dwg, .dxf) and other 3D formats (.3ds, .dwg, .dfx, .fbx, .xsi, .vrml).

Simple .fbx file export
In Sketchup it is really simple to export 3D files into a .fbx file: The Export Model dialog box is displayed (Microsoft Windows). In the link below you can find information about the export dialog box and what settings you can conduct: http://sketchup.google.com/support/bin/answer.py?answer=114381
 * Select File
 * Export
 * 3D Model
 * Enter a file name for the exported file in the 'File name' (Microsoft Windows) or 'Save As' (Mac OS X) field.
 * Select the FBX export type from the 'Export type' (Microsoft Windows) or 'Format' (Mac OS X) drop-down list.
 * (optional) Click on the Options button. The FBX Export Options dialog box is displayed.
 * (optional) Adjust the options in the FBX Export Options dialog box.
 * (optional) Click the OK button.
 * Click the Export button.

Now you can import the .fbx file into your XNA program. It may be more reliable than exporting it into a .x file.

Exporting a .x file with a plug-in
But there is also another possibility! Thanks to a free plug-in, we can also directely export the 3D model into a .x file to simply importing it into our XNA program.

In the link below you can find a really nice tutorial which explains step by step the usage of this plug-in:

http://www.jamesewelch.com/2008/03/07/how-to-load-a-google-sketchup-model-into-a-xna-game/

Another link... to another plug-in:

http://www.3drad.com/Google-SketchUp-To-DirectX-XNA-Exporter-Plug-in.htm

Importing in XNA
--> Introduction

Author
sfittje

What we learned in this chapter
It seems like it is really simple to export models into .fbx or .x files and also to import them into the xna framework. But actually it only seems ike that. When you keep yourself busy with reading forums concerning the importation of 3D models, you have to assert that there are many problems which can occur. Textures are not shown, the models are shown wrong in the xna game...

To avoid those bugs aroused by the modelling software you can work with the free Autodesk Softimage Mod Tool: http://usa.autodesk.com/adsk/servlet/pc/item?id=13571257&siteID=123112

But most of you won't create models themselves. So what about our "Finding free models"-models? In our Introduction the "normal" way of importing is explained, also that for the xna framework the file extension is irrelevant.

Thus I will concentrate on the pros&cons of the export of these files.

But is it better to export to .fbx or to .x files?
The difference between these two:
 * FBX represents an entire scene within a modeling tool, with animations, modifiers, geometry and other properties, in fairly high detail
 * The .X format stores only the data needed to render animated geometry at runtime - there is no explicit support for things like cameras, lights, morphers or modifiers in the format

More details about the difference can be found in the link below http://forums.create.msdn.com/forums/p/31246/177968.aspx

Pros & Cons
Now you have to measure and to decide which is the best approach for you. But please be aware of importing only .fbx or .x files into your program!

Help and solutions
Here you can find help for the topic "importing models":

http://books.google.com/books?id=P049UmI9GuYC&pg=PA282&dq=xna+importing+models&hl=de&ei=slTzTbCzCsXxsgbA-8W1Bg&sa=X&oi=book_result&ct=result&resnum=3&ved=0CDgQ6AEwAg#v=onepage&q&f=false http://books.google.com/books?id=jjJ1tH1k4uEC&pg=PA257&dq=xna+importing+models&hl=de&ei=slTzTbCzCsXxsgbA-8W1Bg&sa=X&oi=book_result&ct=result&resnum=5&ved=0CEQQ6AEwBA#v=onepage&q=xna%20importing%20models&f=false
 * On page 282
 * On page 261