Game Creation with XNA/3D Development/Importing Models
Importing Models
editIn 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
editThe 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?
editFirst 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:
Model currentModel;
next we take a look at the LoadContent() method:
protected override void LoadContent()
{
// Load the model.
currentModel = Content.Load<Model>("ModelName");
// Look up our custom skinning information.
SkinningData skinningData = currentModel.Tag as SkinningData;
if (skinningData == null)
throw new InvalidOperationException
("This model does not contain a SkinningData tag.");
}
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
edithttp://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
editFixSpix
Cinema4D
editCinema 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
Exporting in adequate formats
editSimple .fbx file export
editWhen 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
- Export
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
editIn 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
editActually 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
References
edithttp://www.maxon.net/de/products/cinema-4d-prime/who-should-use-it.html http://de.wikipedia.org/wiki/Cinema_4D http://forums.creativecow.net/readpost/19/873735 http://www.cactus3d.com/Plugins.html http://iclone-freebies.wikispaces.com/file/view/fbxexport.png/176558803/fbxexport.png http://www.youtube.com/watch?v=nX2k81T1eaQ http://www.c4dcafe.com/ipb/topic/43560-coffee-script-export-scene-to-fbx/
Author
editsfittje
Maya
editMaya 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?
editThe 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
editHow to Export (.x)?
editIf 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)?
editThe 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?
edit--> Introduction
References
edithttp://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
editFixSpix
3ds Max
edit3D 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?
editFirst 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.
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
editHow to export?
edit- 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
- KWXPort(format)-->
- Export-->
- File-->
- 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?
edit-->Introduction
References
edithttp://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
editFixSpix
Blender
editBlender 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?
editNo blender cannot export to .X without a plugin.
Exporting in adequate formats
editHow to export(.x)?
edit- File-->
- Export-->
- DirectX(.x)
The result is a nice .x file from your model.
How to export(.fbx)?
editHere 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?
edit-->Introduction
References
edithttp://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
editFixSpix
Sketchup
editSketchup 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
editSimple .fbx file export
editIn Sketchup it is really simple to export 3D files into a .fbx file:
- Select File
- Export
- 3D Model
- Export
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
- 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
editBut 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
edit--> Introduction
References
edithttp://sketchup.google.com/support/bin/answer.py?hl=en&answer=36203 http://sketchup.google.com/support/bin/answer.py?answer=114380 http://sketchup.google.com/support/bin/answer.py?answer=114381 http://www.jamesewelch.com/2008/03/07/how-to-load-a-google-sketchup-model-into-a-xna-game/ http://www.3drad.com/Google-SketchUp-To-DirectX-XNA-Exporter-Plug-in.htm/ http://forums.create.msdn.com/forums/p/69433/424091.aspx/ http://forums.create.msdn.com/forums/p/31246/177968.aspx
Author
editsfittje
Summary
editWhat we learned in this chapter
editIt 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?
editThe 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
editPros & 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
editHere you can find help for the topic "importing models":
- On page 282
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
- On page 261
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
References
edithttp://forums.create.msdn.com/forums/p/57219/349404.aspx http://forums.create.msdn.com/forums/p/31246/177968.aspx 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