Learn how to load and animate Quake II MD2 models in Away3D Lite.
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.
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]
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
Flash 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.