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:

… and here is the demo application :

Flash 10 MD2 loader

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…

  • Awesome!

    Now where is the source? πŸ™‚

    • 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 :D) 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… πŸ™‚

  • Looking forward to it πŸ™‚

  • Very interesting. Can’t wait to see that source!

  • Pingback: Augmented Reality in Flash 10 | Promethe's Blog()

  • 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.

    • 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.

  • Pingback: Frustum Culling in Flash 10 | Promethe's Blog()

  • Looks interesting. I am using Quake software for design purposes. The Quake-series is really awesome.

  • Pingback: Back from Adobe “Retour de MAX” 2010 | Jean-Marc Le Roux()