Saturday, June 15, 2013

XNA off; Unity On (and how to successfully import a Blender model into Unity...)

XNA being a "dead" language now (or at least no longer supported), I've switched to Unity.  Big change, but I'm liking it so far.  Some of the Unity Engine makes programming so easy, while the rest is just as difficult as XNA was.  The graphics is extremely fun and easy.

So, my Ghost Train project will move to Unity and likely will be 3D, just because I'm having a blast relearning Blender and putting that together with Unity.  I'm a complete noob, so even though there are thousands of tutorials out there for Blender and Unity, I'm going to post notes and examples.  There are some very specific things you can do with these two programs that make the workflow so much easier.  Maybe I can save just one person a headache trying to figure this stuff out.

Currently, I'm using:

Blender 2.67
Unity 4.1.5f1
a very old version of Photoshop (6.0.1 ...no, not even CS...I've had this one for years and years and it's comfortable)

So, here are my steps to create a model in Blender and import into Unity successfully (lots of trial and error and forum scouring to get to this point!).

  1. Well, create the model.
    1. Base mesh, extrude, rotate, scale (more on this in another post).
    2. Knife tool to cut new faces when needed.  Mesh Tools/Add/Knife.  Drag from one area to another and then hit enter to finish cut.  Seems to work best between two established edges.
  2. For each object in the model, first make sure all normals are pointing out, otherwise parts will appear missing or transparent.
    1. Select object
    2. Put into edit mode (tab)
    3. On a 3d view window, type "n".  Brings up a set of info on the right side of the view.
    4. In Mesh Display/Normals, click the face button and set a size that makes sense.  If the normal is pointing out, you will see it radiating from the center of the face (blue line coming out).  If not, it's pointing in.  If it's pointing in, select the faces pointing and do:
      1. From the bottom menu do, Mesh/Normals/Flip Normals.  Repeat this for groups of faces until all are pointing out.

  1. Now UVW Map the object(s)
    1. Go to Edit mode.
    2. Use edge editing and select edges to cut.  Then choose Mesh/Edges/Mark Seam.  This is the cut for the UVW map.
    3. Repeat until you have broken the model down into parts that make sense.  
    4. Now, select all faces, type "u" and choose Unwrap.  If you have one view as UV/Image Editor, you should see the mapping.  
    5. Export that mapping by doing UVs/Export UV Layout
    6. Paint the texture using your favorite image editor.
  2. Apply the texture to the object (Select the object, in UV/Image Editor pick Image/Open Image).
  3. Save as a blend file.
  4. Put the blend file and the text map(s) into the Assets folder of your Unity project.  It will automatically import it (even at runtime).  
  5. This step saved me a lot of headaches:  Go to the import settings of the blend model in Unity, and choose to Calculate Normals.  This makes the model look like you created it in Blender instead of trying to smooth it out and making it look terrible (at least all mine have...even a simple cube).  To me, this is key...especially when doing wall segments that snap together...otherwise the light will break up on each piece making it look like each object is separate instead of one unified wall.  I do this on all models!

No comments:

Post a Comment