MD3 File Loader - Readme
Since I have no artistic talent, I decided that loading in other people's artistic work compiled on professional modeling applications would be the way to go. MD3 is the file format used by Id Software for Quake 3 and a lot of Quake 3 mods and derivative games. Although Id has not yet GPL'd the source (although I hear it will in a few months), the file format is already fairly well understood. The files contain quaternion-based animations as well as bounding coordinates, triangles, their associated vertexes, normals, and UV texture coordinates. Although I originally hoped to animate the model as well, the work that went into simply loading the model correctly and texture mapping it surpassed 40 hours. The documentation on MD3 needed to code this project was acquired from various sources found by Google.
How To Use the Executable
I didn't include a model with the executable due to lack of space and copyright issues. To start, download an MD3 model from the Internet (I suggest PolyCount). Unzip the file, and it will probably give you a .pk3 file. Unzip that file, and dig down into the "model" folder or something similar which contains the .md3, .skin, and .tga files. Drag the entire contents of that directory into a directory named "model", which should reside in the same folder as the executable. Make sure the following conditions are obeyed (they should be already):
Then launch the program. Note that not all models may work with the loader (see "Known Problems and Limitations" below).
- The lower body should be named "lower.md3", the upper body is named "upper.md3", and the head is named "head.md3"
- The lower body skin should be named "lower_default.skin", the upper body skin should be named "upper_default.skin", and the head skin should be named "head_default.skin"
- The .tga files should stay as they're named, as they're specified by the .skin filesIf you wish, replace the file "skywall.tga" with your own .tga image. It's used for the cheesy last-minute background hack I used to make my screenshots look prettier.
The keyboard commands are as follows:
- "a": Rotate model left
- "d": Rotate model right
- Left Arrow: Rotate camera left
- Right Arrow: Rotate camera right
- Up Arrow: Move camera forward a step
- Down Arrow: Move camera backward a step
- shift-"w": Toggle wireframe mode
- "t": Toggle texture mapping
- "b": Toggle last-minute background hack
- "1", "2", "3": Toggle lights 1, 2, 3, respectively
- "c": Toggle backface culling
The loader uses the standard OpenGL library, GLUT, and C standard library for input/output and error messages. I designed it with the goal of being cross-compatible with other systems, but this was secondary; in theory I have only to implement little-to-big-endian conversions to compile on a different platform. This version also includes windows.h in order to spew out message boxes for error messages.
In addition to .md3 files, the executable also reads .skin and .tga files. Skin files are simply text files which match body surfaces to the filenames for the .tga files. Since different skins may use the same .tga files more than once, the program keeps track of them to ensure that duplicate textures are not stored in memory. The program is capable of loading Targa (.tga) files as textures, provided they are 24-bit or 32-bit color and uncompressed. As it turned out, the mechanisms for loading Targa files are pretty simple; using them as textures took much more time.
As my base, I copied over my Project 4 C files and deleted the shapes from the last scene. I expanded the base plane and tiled it with quads, mainly to get the cool grid effect when wireframe was on, but it had the bonus effect of making the lights look like spotlights, thanks to the added vertices. The MD3 file loading was designed mostly from the specification page linked to above, and a Targa loading tutorial was found on the Web from which I learned how to load Targa files. The linking aspect of the format remains something of a mystery for me, which is probably why the loader doesn't work with all models (see below). The loader works by looking for fixed-name .md3 and .skin files (see above), but it extracts and loads texture names from the .skin files. It then links the lower body part to the upper, which links to the head, and rasterizes them in that order.
To view the model properly, I needed to rotate it, scale it, specify the vertices in reverse order, and flip the v-coordinates of the imported texture coords, which seems to demonstrate the difference between Quake 3's native mode and OpenGL.
Most models were drawn a little dark, but instead of tweaking the lighting, I decided to give the scene a background. I did this by shamefully placing a polygon at a distance of 2000 behind the origin at all times and texturing it. I realize that I should have used glDrawPixels() or something, but I didn't have the time and I wanted a quick effect. Hopefully no one will change the window's aspect ratio.
Known Problems and Limitations
The program seems to have difficulty loading a good number of models, especially the more complex ones. I think this is due to the hack-job I did linking the models together (i.e., I assume there are only 3 MD3 files: lower, upper, and head), when the format should allow for more body parts and more complex linking. I wasn't able to find much documentation on this, and I didn't discover the problem until recently, so I'll just suggest loading the more conservative models for now.
In the future I would hope to fully support loading all types of .tga files, not just 24-bit color, and I would hope for animation and fully player control for the model's movements. I would hope for a lot of things. As it stands, the entire program will fail if you feed it a non-24-bit Targa. And I really wanted the camera to sidestep, but it doesn't sidestep.