Bright Hub
 
Matthew Casperson's Hubfolio

Away3D Lite Programming Tutorials - Loading MD2 Models

Article by Matthew Casperson (227,413 pts )
Published on Sep 25, 2009

Learn how to load and animate Quake II MD2 models in Away3D Lite.

Introduction

Away3D Lite can load a number of 3D formats natively: Metasequoia MQO, 3D Studio MAX 3DS, Quake II MD2 and Collada. Being able to load Quake II MD2 models gives those developers without any artistic talent or a library of 3D models access to hundreds of good quality, textured and animated models to prototype an application with. Loading and animating MD2 files is a little different in Away3D Lite compared to Away3D. This tutorial will show you how it is done.

Code Documentation

ApplicationManager.as

The two files you need to display an MD2 file is the model (with the MD2 extension) and the texture. By default MD2 files are textured with PCX image files. Flash/Flex only supports embedding GIF, PNG or JPG files, so you will need to convert the PCX texture to one of these formats.

The MD2 file is embedded, specifying a MIME Type of application/octet-stream. [code]

The texture image is embedded. Here we have converted it to a JPG file, so it can be embedded directly. [code]

The embedded texture image is then used to construct a BitmapMaterial object. [code]

A new instance of the MD2 class is created, and then its parseGeometry function is called, supplying the embedded MD2 file as the data source. The resulting object is a MovieMesh, although the parseGeometry function returns an Object3D, so we need to cast it. [code]

The model is then textured by assigning the BitmapMaterial to its material property. [code]

We then scale and rotate the model so it can be seen. [code]

By default the mesh will play animations at 24 frames per second. This is too fast for an MD2 file, so we drop it down to 12. [code]

We then set the current animation using the play function. For a Quake II model the default animation names are 1stan, 2ru, 3attac, 4pai, 5jum, 6flipof, 7salut, 8taun, 9wav, cr1stan, cr2wal, cr3attc, cr4pai, cr5dea, dead and point. [code]

Final Words

MD2 models are easy to find there is a good selection of well modelled, textured and animated models available. MD2 models tend to have a low polygon count too, which is perfect for 3D Flash applications.

Back to Away3D Tutorials

Related Files

Images

Away3D Lite MD2 Loading

Related Article

Sandy-HX Model LoadingFlash and JavaScript 3D with Sandy-HX - Loading a Model

This tutorial will show you how to load a 3D model and display it using Sandy-HX.

Search More About:

Comments

May 7, 2010 6:07 AM
Todor Jelev
collision
is it possible to detect collision between two loaded models?
Dec 27, 2009 7:13 PM
Ivan Kuckir
3DS
Hi,
can you please give me a clue how to load 3DS model with texture in away3Dlite? I did it in the same way as MD2 (I embedded .3DS and texture, created instance of Max3DS class), but when I parse it
mesh = max3DS.parseGeometry(new Model2()) as MovieMesh;
"mesh" is stil "null".
Thank you in advance
 
Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2010 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape