Chapter 6. Models and Animations

As we saw in Chapter 2, Creating and Displaying Primitives, it is possible to create a 3D object from the ground up using basic elements like vertices, triangle faces, Sprite3D objects, and segments. However, creating each element manually in code is not practical for more complex models. While the classes from the away3d.primitives package offer a solution by providing a way to quickly create some standard shapes, advanced applications will need to display more complex shapes. For those situations where these standard primitive shapes do not provide enough flexibility, Away3D can load and display 3D models created by external 3D modeling applications.

3D modeling applications are specifically designed to provide a visual environment in which 3D models can be manipulated. It is certainly much more convenient to create or edit a 3D mesh in one of these applications than it is to build up a mesh in code using ActionScript.

Away3D can directly load a wide range of 3D formats. The process of exporting a 3D mesh into a file that can be used with Away3D will be covered for the following 3D modeling applications:

  • 3ds Max: A popular commercial modeling, animation, and rendering application which runs on Windows.
  • Blender: A free and open source modeling application, which is available on a number of platforms, including Windows, Linux, and MacOS.
  • Milkshape: A commercial low-polygon modeler which runs on Windows that was originally designed for the game Half-Life.
  • Sketch-up: A free 3D modeling application provided by Google. A commercial version is also available that includes a number of additional features. Sketch-up runs on Windows and MacOS.

Actually creating a model in these 3D modeling applications is outside the scope of this book. However, 3D models are provided that can be loaded and then exported from these applications, which will allow you run through the procedure without having to know how to make a 3D model from scratch.

This chapter covers the following:

  • Exporting a model from a number of 3D modeling applications
  • Loading a model file in Away3D, both from an embedded resource and from an external file
  • Converting 3D models into ActionScript classes

3D formats supported by Away3D

Away3D includes classes that can load a wide range of 3D model file formats. All the supported formats can be used to load a static 3D model, while a smaller number can be used to load animated models. The following table lists the 3D model formats supported by Away3D, their common extensions, whether they can load animated 3D models, and the Away3D class that is used to load and parse them.

Format

Extension

Static

Animated

Away3D Class

Collada

DAE

*

*

Collada

Quake II

MD2

*

*

Md2

3DS MAX Ascii

ASE

*

 

Ase

Away3D

AWD

*

 

AWData

Google Earth

KMZ

*

 

Kmz

3DS Max

3DS

*

 

Max3DS

Wavefront

OBJ

*

 

Obj

ActionScript

AS

*

*

 

Exporting 3D models

The following instructions show you how to export a Collada file from a number of different 3D modeling applications. Collada is an open, XML-based format that has been designed to provide a way to exchange data between 3D applications. Away3D supports loading both static and animated 3D models from the Collada format.

Exporting from 3ds Max

3ds Max is a commercial 3D modeling application. At the time of writing, the latest version of the ColladaMax plugin, which is the plugin that we will use to export the 3D model, was 3.05C. This version supports 3ds Max 2008, 3ds Max 9, 3ds Max 8 SP3, or 3ds Max 7 SP1. Note that this version does not support 3ds Max 2010 or 2011.

A trial version of 3ds Max 9 is available, although it can be difficult to find. You should be able to find a copy if you search the Internet for Autodesk3dsMax2009_ENU_TrialDownload.exe, which is the name of file that will install the trial version of 3ds Max 9.

  1. Download and install the ColladaMax plugin from http://sourceforge.net/projects/colladamaya/files/.
  2. Open 3ds Max.
  3. Click File | Open. Select the MAX file you wish to open and click on the Open button.
  4. Click File | Export from within 3ds Max.
  5. Select COLLADA (*.DAE) from the Save as type drop-down list.
  6. Select the same directory where the original MAX file was located.
  7. Type a file name for the exported file in the File name textbox, and click on the Save button.
  8. In the ColladaMax Export dialog box make sure the following checkboxes are enabled:
    • Relative Paths
    • Normals
    • Triangulate
  9. If you want to export animations, enable the Enable export checkbox.
  10. If you want to export a specific range of frames, enable the Sample animation checkbox and enter the required values in the Start and End textboxes.
  11. Click on the OK button to export the file.
Exporting from 3ds Max

Exporting from MilkShape

The Collada exporter supplied with MilkShape does not export animations. So even if the MilkShape MS3D file we are loading contains an animated model, the exported Collada DAE file will be a static mesh. A trial version of MilkShape can be downloaded and installed from its website at http://chumbalum.swissquake.ch/.

  1. Click File | Open. Select the MS3D file you wish to open and click on the Open button.
  2. Click File | Export | COLLADA….
  3. Select the same directory where the original MS3D file was located.
  4. Type a filename for the exported file in the File name textbox and click the Save button.

Exporting from Sketch-Up

Like Milkshape, Sketch-up does not support exporting animated Collada files. Sketch-Up can be downloaded for free from http://sketchup.google.com/.

  1. Click File | Open. Select the SKP file you wish to open and click on the Open button.
  2. Click File | Export | 3D Model….
  3. Select Collada File (*.dae) from the Export type combobox.
  4. Select an appropriate directory, and type a filename for the exported file in the File name textbox.
  5. Click on the Options... button.
  6. Make sure the Triangulate All Faces checkbox is enabled.
  7. If the Export Texture Maps option is enabled, Sketch-Up will export the textures along with the DAE file.
  8. Click on the OK button to save the options.
  9. Click on the Export button to export the file.
Exporting from Sketch-Up

Exporting from Blender

The latest version of the Collada exporter for Blender, which is version 0.3.162 at the time of writing, does support exporting animations. However, in most cases Away3D will not load these animations correctly. It is recommended that only static meshes be exported from Blender to a Collada file.

  1. Click File | Open.... Select the BLEND file you wish to open and click on the Open button.
  2. Click File | Export | COLLADA1.4 (*.dae) ....
  3. Type a filename for the exported file in the directory where the original BLEND file was located in the Export File textbox.
  4. Make sure the Triangles and Use Relative Paths buttons are pressed.
  5. Click on the Export and Close button.
Exporting from Blender

A note about the Collada exporters

Despite being free and open standard, exporting to a Collada file that can be correctly parsed by Away3D can be a hit-and-miss affair. The Collada exporters for 3ds Max are a good example. During testing, neither the built-in Collada exporter included with 3ds Max, nor the third-party OpenCollada exporter from http://opencollada.org (version 1.2.5 was the latest version at the time of writing) would export an animated Collada file that Away3D could read. At best Away3D would display a static mesh, and at worst it would throw an exception when reading the DAE file. Likewise, neither of the Collada exporters that come with Blender (which was at version 2.49b at the time of writing) would consistently export an animated Collada mesh that was compatible with Away3D.

It is important to be aware that just because a 3D modeling application says that it can export to a Collada file, this is no guarantee that the resulting file can be read correctly by Away3D.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.38.99