# 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
* Cinema4D
* Maya
* Blender
* Sketchup
* Others
into your XNA game.

## 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:
* Bones: max. 59 up to 79 in 4.0
* 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.

### References

http://create.msdn.com/en-US/education/catalog/sample/skinned_model http://www.stromcode.com/2008/03/10/modelling-for-xna-with-blender-part-i/ http://www.stromcode.com/2008/03/11/modelling-for-xna-with-blender-part-ii/ http://www.stromcode.com/2008/03/13/modeling-for-xna-with-blender-iii/ http://www.stromcode.com/2008/03/16/modeling-for-xna-with-blender-part-iv/

### 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:

### Exporting in adequate formats
#### 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

#### Exporting a .fbx file with a plug-in

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.

### Exporting in adequate formats
##### 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

#### References

http://www.gamedev.net/topic/383794-exporting-x-files-from-maya-70/ http://www.chadvernon.com/blog/resources/cvxporter/ http://usa.autodesk.com/adsk/servlet/pc/item?id=10775855&siteID=123112 http://download.autodesk.com/us/fbx/2010/Maya_online/_index.html

#### 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.

### Exporting in adequate formats
##### How to export?

* First download the plug-in from the web-source above and install the tool.
...a few minutes later...
* In 3ds Max
** File-->
*** Export-->
**** KWXPort(format)-->
***** The KWXPort Export Options
* Geometry
** Import the Normalt(lightning)
** Make Y up (for the right alignment)
** Export flight-handed Mesh (the mesh from the model)
* Materials
** Export Materials
** Export Textures
* Animations
** 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.
* Finaly
** Export as Binary(gives us the best format)
The result is a combination of three files.
* The Texture: nameofthemodel.png
* The DirectX File: nameofthemodel.x
* The .X Log-file: nameofthemodel.log
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.
DirectX SDK http://msdn.microsoft.com/en-us/directx/default

##### How to import?

-->Introduction

### References

http://www.youtube.com/watch?v=h5gmTpvlFZI http://3ds-max.software.informer.com/wiki/ http://en.wikipedia.org/wiki/Autodesk_3ds_Max http://www.kwxport.org/ http://msdn.microsoft.com/en-us/directx/default

### 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.

#### Is it possible to export .x files from Blender?

No blender cannot export to .X without a plugin.

### Exporting in adequate formats
##### How to export(.x)?

* File-->
* Export-->
* DirectX(.x)
The result is a nice .x file from your model.

##### 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

#### References

http://www.stromcode.com/category/xna/ http://www.blender.org/education-help/tutorials/ http://de.wikibooks.org/wiki/Blender_Dokumentation http://de.wikibooks.org/wiki/Blender_Dokumentation

#### 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).

### Exporting in adequate formats
#### Simple .fbx file export

In Sketchup it is really simple to export 3D files into a .fbx file:
* 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.

### Importing in XNA

--> Introduction

### Author

sfittje

## Summary
### 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:
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

### Pros & Cons

| Pros & Cons | .fbx | .x |
| Pros | 3DS Max & Maya support .fbx out of the box Supports animation Supports skeletons & skinning Supports embedded media | Smaller file sizes Supports animation Supports skeletons & skinning Is a format designed specifically for 3D game models Supports embeded media |
| Cons | Lots of unneeded options in the exporter, since it is not game-specific Does not support animation clips within the file Usually 1 order of magnitude larger than .X | Requires a third-party exporter |
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":
* On page 282
* On page 261