Week5 - 3D content creation
Week5.png

Start Files: Week5.zip shiptexture.png ship.fbx ship.wings

Finished Project: Week5Finish.zip

Notes

This week instead of programming we created the ship shown above using a 3D modelling program called Wings3D. I won't go over the steps taken to create the model because there are many tutorials on the wings3d website that can do a better job than I can. The one thing I will go over is how to export your wings3d model into XNA. I am using Wings3D version 1.0.2 for this tutorial.

From this point on I will assume you have created a model you'd like to export. If you haven't done this and just want to continue with the tutorial you can use ship.wings and shiptexture.png above as a starting point.

Exporting from Wings3D

  • If you want to skip the Wings3D part and just learn to load the file into XNA, use ship.fbx and shiptexture.png and skip this section.
  • First thing to do is load ship.wings into Wings3D (or whatever model you've created).
  • One thing to note is that when you save a model you're saving its size as well. Though not necessary, one think I like to do is scale all models to a uniform size so that when I'm loading them in XNA I'll always know how big models are and will also be able to specify in code how big or small they will be. The uniform size I always choose is a size of 1.
  • Unfortunately, the normal scale command only allows us to scale by a percentage and not to an absolute size. Instead we'll select the whole body of the model, right-click, and select absolute commands and then scale. Set the new size for x, y, and z all to 1. Make sure all of the Link checkboxes are checked. Finally, all of the Set scale center boxes should be 0. The first set of text boxes in conjunction with the link check boxes force the largest size to 1 and link the other sizes so that the model will remain proportional. Setting the scale centers to 0 will center the object on the origin. If you are using ship.wings the ship is already scaled so you can do this but it won't change anything.
  • Save now as Wings3D has a tendency to crash a lot.
  • The next thing we want to do is export to a file that XNA can read. Click File->Export and you'll see Autodesk FBX (.fbx)… as one of the choices. We don't want to click on that, but instead click on the little box right next to it. This will bring up options for exporting it.
  • The options that we will want to change are Export scale. Set it to 1. Also make sure the ASCII FBX check box is checked. Click OK to export and save it.
  • There is one very peculiar problem that Wings3D has and will cause some serious frustration if you don't change it. Open up the .fbx file you just created using some text editor like Notepad or Wordpad. Search (Ctrl+F) for "C:". You'll notice that the path to the textures being used is absolute and not relative. This is bad. Any time you find "C:", remove the path and replace it with the relative path that will be used in the content folder of XNA. For example, in the ship.wings model, it will be saved as ship.fbx. I open the file, search for "C:" and for each instance I remove "c:/Documents and Settings/student/Desktop/" and leave "shiptexture.png". I think there are 3 instances of this occurring in ship.fbx.

Importing into XNA

  • Open the XNA project you would like to import the model into. Week5.zip has an XNA project that will allow you to view any model of length 1 and centered about the origin. I will be using this project as an example. Once the project is open we need to put the model file and any file it relies on in the proper location. In the ship.fbx file I specified the texture to be in the same directory as the model file. In C#, I right-click the Content directory and go to Add->Existing Item. Instead of adding just the model file I also add any texture files that the model file relies on (for ship.fbx we also need to add shiptexture.png). This will copy all needed files from wherever they were before to the Content directory.
  • You can now run the project and your model will be displayed.
  • One thing to note is that you're getting a warning every time you build the project. This warning says that the asset shiptexture.png is being built twice. The texture file is being referenced because it is included in the Content references and by the model file. We don't need it to be referenced for anything other than the model file, so we can actually just remove it from the project. However, We need it in the Content folder, though. That's why we included it in the first place. To get rid of this error, right-click on the texture file in Solution Explorer and click Exclude From Project (NOT delete).

That's everything.

back to SIGXNA

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License