iPhone MD2 example

This movie requires Flash Player 9

The first major step when developing a 3D app is finding a way of importing models created in external editing software. There are hundreds of formats to choose from each with their own pro’s and con’s.

For most 3D apps on the iPhone all that is required is the mesh (vertices, triangles, texture coordinates, normals) so the simpler the format the better.

Using a format that is well supported across a variety of editors and platforms is also essential for an optimal work flow especially if coders and artists are in different cities/states/countries.

The MD2 file format was created by id Software in 1997 for non-level models in Quake II. It is a very light weight file format containing only the mesh. Animation is handled via keyframes with up to 512 frames stored in a file. Vertices are stored in a compressed format while normals are stored as an integer lookup into a pre-calculated table.

It proves to be a great fit for the iPhone in most instances.

Using my KEMD2Object class you can easily load, render and animate MD2 files. Animation is handled by filling a KEMD2Animation struct with the start frame, end frame and FPS of the animation and setting the animation property to that struct.

For animated MD2’s make sure to call the tick method each frame passing in the time in seconds since the last call as this is where the keyframe interpolation occurs.

  • Facebook
  • Twitter
  • Netvibes Share
  • Delicious
  • Share/Bookmark

5 Responses Subscribe to comments


  1. Andy Rifken

    This is great!! I’ve been looking for a lightweight format to bring models+animation in from Maya and I was going to use the PowerVR POD format, but this is great because md2 can also be used on other devices (on android, for example) that don’t use the PowerVR chipset. Thanks!!

    Oct 24, 2009 @ 1:31 pm


  2. Ben

    I’m glad you found it useful. It’s also worth noting that the original Quake 2 implementation faked lighting of MD2 models via vertex color however I simply used GL lighting in the iPhone project. The article linked at the bottom of the post show’s the fake lighting implementation if you’re interested.

    Oct 24, 2009 @ 2:42 pm


  3. Freddie

    Thanks a bunch! Saved me quite a bit of time. Cheers.

    May 10, 2010 @ 5:43 am


  4. Matthew Mitchell

    Thank you for posting this code because it aided me in getting depth to work on my own application.

    I was actually doing things right but after implementing your camera code, I realised I was simple not putting the square somewhere where I could see it.

    Now I’m going past squares and into proper rendering.

    Aug 23, 2010 @ 7:37 am


  5. Ben

    @Matthew no problem, I’m glad it helped!

    Aug 23, 2010 @ 7:39 am

Reply