Quake 2′s 3D models in Flash 10
Loading and rendering Quake 2's maps is a challenge because Flash 10 doesn't handle complex 3D geometry very well. But what about a smaller count of polygons ? Say a 3D model for example... already done! What about an animated 3D model then?
Details, pictures and a demo application right after the jump...
MD2 file format
Quake 2 uses the MD2 file formatĀ to store animated 3D models. It is a quite simple file format: each MD2 file stores a single mesh and its animations. Each animation is just copy of the original mesh with different positions for each vertex. The number of vertices and the indices are the same for each frame. Therefore, the MD2 file format is easy to adapt to the Flash Platform because no complicated shaders/bones are required to animate the model: you just have to display the right vertices!
But it is not THAT simple. Each animation is actually subdivided into frames (vertices really). Because storing a fluid animation would take a lot of frames (and a lot of memory), only a few keyframes are stored. When rendering, one must compute the interpolation coefficient between the current and the next keyframe and use it to get the interpolated vertices. The following code does it all:
var frame1 : Vector.<Number> = _currentFrame.vertices; var frame2 : Vector.<Number> = _nextFrame.vertices; var c2 : Number = _frame - int(_frame); var c1 : Number = 1 - c2; var length : Number = frame1.length; for (var i : uint = 0; i < length; ++i) _vertices[i] = frame1[i] * c1 + frame2[i] * c2;
... and here is the demo application :
What it does...
- load Quake 2's MD2 files
- basic z-sorting using faces barycenter
- add a "frame" property to the mesh to handle animations
- interpolate and update vertices only when necessary
- wireframe material (press "w")
- "free chase" camera (mouse click + drag'n'drop to turn around the model)
What it doesn't do...
- use BSP trees to handle z-sorting (1 BSP tree / frame takes a lot of time and memory...)
- loop through a specific animation
- read Quake 2's animation files
Known issue(s)
None. If you find one please let me know! Performance seems to be very good actually...

October 7th, 2009 - 20:52
Awesome!
Now where is the source?
October 7th, 2009 - 23:56
Sources are coming… not yet but soon enough!
I want the main 3D API to be reliable and stable first. Then and only then, I “might” releases all the sources!
I have to finish my MD3 (Quake 3 models
) loader first to test a few implementation choices. Yes, I just said “Quake 3″, and yes, I said “finish” which means it’s already “working”… a bit…
October 8th, 2009 - 12:08
Looking forward to it
October 8th, 2009 - 18:23
Very interesting. Can’t wait to see that source!
December 8th, 2009 - 01:46
Dude!, can’t wait
I am following you from 1 year. Do you want to be forgotten because of yougurt3D? You still have a chance to impress some ppl and get other developers hand into it. That’s the only way yo keep project running.
December 8th, 2009 - 11:07
First things first: thank you for your interest in my work!
I certainly don’t want to be “forgotten”
My work should be available as soon as the beginning of next year. I’am building my own company and this 3D “stuff” will be part of our core business. It might be open source with a fee for commercial licenses.
Yougurt3D looks like a very nice 3D engine. But it works with Alchemy which is still in beta, produces very (very) large files and makes it very hard to mix it with the rest of the Flash Platform. Those are major issues because any Flash developper wants his SWF to be very small, stable and easily redistributable.
December 27th, 2009 - 19:15
Looks interesting. I am using Quake software for design purposes. The Quake-series is really awesome.