Away3D workflow using Blender

Due to the nature of a project I am working on, I cannot load external files. So this workflow is designed to have all objects and images embedded. I prefer using AS3 classes over embedding Collada, since more portions of the Away3D scene are in the same format.

The program overview is

  • Blender – bake textures and output 3d model.
  • FlashDevelop – edit model, adding material to the object.
  • Away3d – show the model.

Even though I think this works, I have not followed this process verbatim. I may have added or forgotten a step along the way, or have some bad ideas about why something works. I will correct this over the next few weeks/months as this workflow gets more use.

Also, this is using Blender 2.49b, not 2.5.x or 2.6. At the time of this writing, 2.5 is too buggy and still in flux, so cannot be used in a production workflow.

  1. Set up model in Blender
    • If the model is coming from Lightwave, export to a form readable by Blender (OBJ, Collada?).
    • In Blender, copy the hi-res object.
    • Do not move the lo-res object in space at all. It must have exactly the same coordinates as the hi-res.
      • If you want to hide one of the models from view, put it to a different layer.
        • M-key, and a popup with layer icons will appear.
        • Pick an unused layer, and the popup will close.
        • Click on the layer icon in object mode’s layer panel until the object is hidden.
    • Reduce polys (object mode -> add modifier -> decimator) for a low resolution version of the model.
  2. Set up textures
    • From what I have been able to make work, baking textures is a 3-step process, with each of the steps having multiple parts.
      • Pre: Import.
      • Import the model. The models I import have no textures at this point.
      • If you are planning to reduce the number of triangles, this is probably the best place to convert from hi-res to lo-res. My assumption is that all materials can be set up on the lo-res model, if there are enough triangles (this has not been tested by me).
      • Note: There are no lights in this scene. This means that everything you are seeing is the actual texture color, and not the effect of lighting. This is how I am setting up my environment, but you may need to add lighting. How baking textures works on that model is not covered here.
      • Step 1: Setting up the materials.
      • In Editing (F9), make multiple textures accessible by this model’s mesh. In the “Link and Materials” panel, hit the “New” button (the one underneath the “# Mat #” box).
      • You should see the number of materials increase: 2 Mat 2, 3 Mat 3, etc. The new textures copy the current one, renaming it: matl.001, matl.002, etc. These will be renamed/revised later, so don’t worry about what the material actually is at this point. There are arrows on either side of the “# Mat #” box, which will allow you to pick which material is active. It’s now easy to understand what these #’s mean: {total number of materials accessed in this model} Mat {current active material}. Use the arrows to get to the first material.
      • In Edit Mode, select the appropriate triangles for this material.
      • Click the “Assign” button. These triangles will now use this material. Even though it may seem that now is a good time to edit the material, I find it is better to assign all the mesh groups in order to not flip back and forth.
      • Repeat the previous 3 steps until you have assigned a new material to the entire mesh. These settings can be changed or reassigned as needed, so if you get it wrong, you can fix it later. Just select the correct triangles, pick the correct material, and click “Assign” again.
      • Switch over to the Shading (F5) environment, and click on the Material Buttons view (this is found in the set of buttons next to the Shading buttons). In the “Link to Object” panel, you will see the same “# Mat #” reference box.
      • Pick the first material that you want to change. Rename it here. You don’t have to do anything else in this view for now.
      • Switch to the Texture Buttons (F6) view.
      • Create (or verify the existence of) the textures for this material.
      • Switch to the Material Buttons view. Locate the “Texture” panel. Add all the textures you are going to use for this material here by clicking on a blank button (on the left side of this panel), and selecting a texture you created: there is a little up-down arrow beneath the “Add New” button which allows you to pick a material.
      • Once you have a material highlighted, switch to the “Map Input” panel, and select “Orco” (if you are using an image map, you might have to select “UV” instead).
      • Switch to the “Map To” panel, and select the appropriate output channels. This is something you will have to play around with to get right, probably.
      • That’s all for this texture. Repeat this process for all textures in this material, and all materials on this mesh.
      • Step 2: Baking the materials.
      • Still in the Shading environment, click on the World Buttons view.
      • On the panel that is titled “Amb Occ” (for Ambient Occlusion), click on the “Ambient Occlusion” button.
      • Set the Samples. 4-6 for most uses. Higher number = better and slower. Set it too high, and it will take hours to render.
      • Activate “Add” button, and the “Plain” button, though you may want to experiment with the others for more accurate colors.
      • Switch to Edit Mode, if not. Select all your triangles, and unwrap the UVs. “Smart Projections” is really useful for fairly simple objects. Otherwise, set the seams and unwrap that way (this is not documented here – look for a tutorial on this).
      • In your UV view (split the scene window and switch to a UV view, if you don’t have that set up already), create a new UV image. Find the “Image” button at the bottom of your UV window, click to show the menu, and click “New”. Name the image something obvious, like {model name}Matl. You may have to scale down your view to see the whole UV.
      • Switch to the Scene (F10) environment.
      • On the “Bake” panel, click on “Ambient Occlusion” button, and hit “Bake”. The AO output will appear in your UV window.
      • Save the AO Bake to file. Saving it as a TIF preserves everything needed, generally.
      • Back on the “Bake” panel, click on “Textures” button, and hit “Bake”. The Texture output will appear in your UV window.
      • Save the Texture Bake to file. Saving it as a TIF preserves everything needed, generally.
      • These two images will make up your final texture.
      • Step 3: Baking the final material.
      • It may be a good idea to copy this model, and move the copy to a hidden layer.
      • Select the model you want to use for your final texture. In the Editing (F9) environment, delete all the materials on this object. Now add a new material. Switch to Edit Mode, select all triangles, and click “Assign”.
      • As before, switch to Shading (F5) environment, and name the material. Switch to Texture Buttons view, and create two new textures. Both of these will be “Image” type. For the first, load the AO Bake TIF file. For the second, load the Textures Bake TIF file. Switch back to Material Buttons. In the Texture panel, select the Textures Bake texture; click the next open texture button down, and select the AO Bake texture. Click the Textures Bake texture, switch to the Map Input panel, and select “UV”; switch to the “Map To” panel and click the “Col” button. Go back to the Texture panel, and click the AO Bake texture, switch to the Map Input panel, and select “UV”; switch to the “Map To” panel and click the “Col” and “Amb” buttons.
      • If you render the object now (F12), you will only see the AO Bake texture (or else only the Textures Bake texture, depending on which is the last texture on this material). In order to see both textures, you have to change the mix between the textures. Go back to the “Map To” panel, and find the slider named “Col”. Set this to .5, and render. Now both textures should be visible. Play with these settings until it looks correct.
      • For the last step, this is a part that caught me short a number of times: the UV needs a new image to store the final render on, and this image needs to be saved to a file before the final render. If the image is not saved, the UV image reverts back to a previous image, and may change the texture! (If this happens, go back into the Texture buttons (F6), on the “Texture” panel click on the changed texture, then in the “Image” panel and click the “Reload” button.) So, go to your UV view, click the “Image” menu, click “New” then “OK”, then click the “Image” menu, click “Save as” and save it as a JPEG this time.
      • Go back to the “Bake” panel, click on “Textures” button, and hit “Bake”. The final mixed texture will appear in your UV window.
      • Finally, in the UV window, click “Image”, click “Save”. This is the image file to use in Away3D.
  3. Hi-res to lo-res baking.
    • Make a new UV for the lo-res.
    • Make a new image in the lo-res UV.
    • Select hi-res model alone.
    • Select lo-res next (shift right-click).
    • Bake AO (or Textures, Normals, etc.), using “Selected to Active”.
      • The lo-res now has the AO map from the hi-res projected onto it’s UV image. This happens ‘magically’, so you don’t need to do anything to get this right.
    • Save to 32-bit file.
    • This will be used to mix with current lo-res texture.
  4. Bake normals.
    • Concept: As far as I understand it, the texture on the lo-res model is magically applied to the hi-res model, changing the displacement, normals, color, etc. on the hi-res model; then the hi-res model’s normals are captured in the form of a 32-bit image, and that image is magically painted on the UV image of the lo-res model. The result it that the lo-res model now has an imagemap of the hi-res’ normals. Saving the UV image as a JPEG, this image can then be used in Away3D for normal mapping.
    • If no lo-res UV, make a new UV for the lo-res.
    • If no lo-res UV image, make a new image in the lo-res UV.
    • Select hi-res model alone.
    • Select lo-res next (shift right-click).
    • Bake Normals, using “Selected to Active”.
      • The lo-res now has the Normals map from the hi-res projected onto it’s UV image.
    • Save to JPEG file.
    • This will be used as the normal map in Away3D.
  5. Export model to AS3 format
    • Need the AS3 export plugin.
    • I have made some changes to the above script. Mostly, my changes makes the exporter script a bit more automated and intuitive. If you would like to use it, please visit this post:
    • Note: it may be necessary to apply scale and rotation info onto the meshes that you are going to export. In Object Mode, press CTRL-A (aka, menu item “Object | Clear/Apply | Apply Scale/Rotation to ObjData”).
    • Select lo-res model.
    • Export -> “Actionscript 3.0”.
    • Export type as “Away3d 2.2, 2.3, . . . “. This is the only model that is set up correctly for the most recent version of Away3D.
    • Click “Only export current selection”.
    • Output to same path as texture/normal images.
  6. Adjust the ouptut AS3 model
    • Have to add the “project” reference by hand in the output AS3 file, since it doesn’t handle periods correctly (a bug, obviously)
    • If you are using my modified output script, uncomment the texture [Embed] lines within the output mesh file. Otherwise, set up your textures for the mesh (not covered here). Don’t uncomment the [Embed] line for the normal texture image unless you actually have a normal image.
  7. Test: Set up object reader in AS3 using the exported AS3 object file. Run in Flash
  8. Build scene with final model/texture

That’s it! Simple! Only 3 days of work so far!

– 30 –