Author Topic: Information about the .md2 format or How to write a .md2 exporter  (Read 919 times)

Toolwut

  • Stingray
  • Posts: 60
I didn't figure the details out yet but I think all the important parts.

general information about the format and how to load such files:
http://tfc.duke.free.fr/old/models/md2.htm
https://linux.ucla.edu/~phaethon/q3a/formats/md2-schoenblum.html#glCommandVertex_st

specific information about animations:
http://www.mbsoftworks.sk/tutorials/opengl3/24-animation-pt1-keyframe-md2/
MD2 files don't store animations as a list of frames with a set frame rate but stores "keyframes". Frames in between are generated by linear interpolation, you just have to know how many frames there are to generate when loading an MD2 object. Quake 2 has a predefined list of animations so you couldn't simply animate a tree or something. Those animations are defined for player models (citing myself: https://forums.digitalpaint.org/index.php?topic=28720.0). Also, not sure yet if the keyframe labels (e.g. "wave1") are actually required.

For lighting, the dp2/q2 engine needs surface normals (to calculate how light bounces off a surface). MD2 files don't store them directly as a vector, but (probably for keeping the file size low?) stores indices to a normal list. Those indices are probably generated by finding the normal that's most similar to the actual one. The normal list (https://www.gamedev.net/forums/topic/511911-does-md2-contain-normals--where-are-they/) is

static const float MD2_NORMAL_TABLE[162][3] = {   {-0.525731f, 0.000000f, 0.850651f},   {-0.442863f, 0.238856f, 0.864188f},   {-0.295242f, 0.000000f, 0.955423f},   {-0.309017f, 0.500000f, 0.809017f},   {-0.162460f, 0.262866f, 0.951056f},   {0.000000f, 0.000000f, 1.000000f},   {0.000000f, 0.850651f, 0.525731f},   {-0.147621f, 0.716567f, 0.681718f},   {0.147621f, 0.716567f, 0.681718f},   {0.000000f, 0.525731f, 0.850651f},   {0.309017f, 0.500000f, 0.809017f},   {0.525731f, 0.000000f, 0.850651f},   {0.295242f, 0.000000f, 0.955423f},   {0.442863f, 0.238856f, 0.864188f},   {0.162460f, 0.262866f, 0.951056f},   {-0.681718f, 0.147621f, 0.716567f},   {-0.809017f, 0.309017f, 0.500000f},   {-0.587785f, 0.425325f, 0.688191f},   {-0.850651f, 0.525731f, 0.000000f},   {-0.864188f, 0.442863f, 0.238856f},   {-0.716567f, 0.681718f, 0.147621f},   {-0.688191f, 0.587785f, 0.425325f},   {-0.500000f, 0.809017f, 0.309017f},   {-0.238856f, 0.864188f, 0.442863f},   {-0.425325f, 0.688191f, 0.587785f},   {-0.716567f, 0.681718f, -0.147621f},   {-0.500000f, 0.809017f, -0.309017f},   {-0.525731f, 0.850651f, 0.000000f},   {0.000000f, 0.850651f, -0.525731f},   {-0.238856f, 0.864188f, -0.442863f},   {0.000000f, 0.955423f, -0.295242f},   {-0.262866f, 0.951056f, -0.162460f},   {0.000000f, 1.000000f, 0.000000f},   {0.000000f, 0.955423f, 0.295242f},   {-0.262866f, 0.951056f, 0.162460f},   {0.238856f, 0.864188f, 0.442863f},   {0.262866f, 0.951056f, 0.162460f},   {0.500000f, 0.809017f, 0.309017f},   {0.238856f, 0.864188f, -0.442863f},   {0.262866f, 0.951056f, -0.162460f},   {0.500000f, 0.809017f, -0.309017f},   {0.850651f, 0.525731f, 0.000000f},   {0.716567f, 0.681718f, 0.147621f},   {0.716567f, 0.681718f, -0.147621f},   {0.525731f, 0.850651f, 0.000000f},   {0.425325f, 0.688191f, 0.587785f},   {0.864188f, 0.442863f, 0.238856f},   {0.688191f, 0.587785f, 0.425325f},   {0.809017f, 0.309017f, 0.500000f},   {0.681718f, 0.147621f, 0.716567f},   {0.587785f, 0.425325f, 0.688191f},   {0.955423f, 0.295242f, 0.000000f},   {1.000000f, 0.000000f, 0.000000f},   {0.951056f, 0.162460f, 0.262866f},   {0.850651f, -0.525731f, 0.000000f},   {0.955423f, -0.295242f, 0.000000f},   {0.864188f, -0.442863f, 0.238856f},   {0.951056f, -0.162460f, 0.262866f},   {0.809017f, -0.309017f, 0.500000f},   {0.681718f, -0.147621f, 0.716567f},   {0.850651f, 0.000000f, 0.525731f},   {0.864188f, 0.442863f, -0.238856f},   {0.809017f, 0.309017f, -0.500000f},   {0.951056f, 0.162460f, -0.262866f},   {0.525731f, 0.000000f, -0.850651f},   {0.681718f, 0.147621f, -0.716567f},   {0.681718f, -0.147621f, -0.716567f},   {0.850651f, 0.000000f, -0.525731f},   {0.809017f, -0.309017f, -0.500000f},   {0.864188f, -0.442863f, -0.238856f},   {0.951056f, -0.162460f, -0.262866f},   {0.147621f, 0.716567f, -0.681718f},   {0.309017f, 0.500000f, -0.809017f},   {0.425325f, 0.688191f, -0.587785f},   {0.442863f, 0.238856f, -0.864188f},   {0.587785f, 0.425325f, -0.688191f},   {0.688191f, 0.587785f, -0.425325f},   {-0.147621f, 0.716567f, -0.681718f},   {-0.309017f, 0.500000f, -0.809017f},   {0.000000f, 0.525731f, -0.850651f},   {-0.525731f, 0.000000f, -0.850651f},   {-0.442863f, 0.238856f, -0.864188f},   {-0.295242f, 0.000000f, -0.955423f},   {-0.162460f, 0.262866f, -0.951056f},   {0.000000f, 0.000000f, -1.000000f},   {0.295242f, 0.000000f, -0.955423f},   {0.162460f, 0.262866f, -0.951056f},   {-0.442863f, -0.238856f, -0.864188f},   {-0.309017f, -0.500000f, -0.809017f},   {-0.162460f, -0.262866f, -0.951056f},   {0.000000f, -0.850651f, -0.525731f},   {-0.147621f, -0.716567f, -0.681718f},   {0.147621f, -0.716567f, -0.681718f},   {0.000000f, -0.525731f, -0.850651f},   {0.309017f, -0.500000f, -0.809017f},   {0.442863f, -0.238856f, -0.864188f},   {0.162460f, -0.262866f, -0.951056f},   {0.238856f, -0.864188f, -0.442863f},   {0.500000f, -0.809017f, -0.309017f},   {0.425325f, -0.688191f, -0.587785f},   {0.716567f, -0.681718f, -0.147621f},   {0.688191f, -0.587785f, -0.425325f},   {0.587785f, -0.425325f, -0.688191f},   {0.000000f, -0.955423f, -0.295242f},   {0.000000f, -1.000000f, 0.000000f},   {0.262866f, -0.951056f, -0.162460f},   {0.000000f, -0.850651f, 0.525731f},   {0.000000f, -0.955423f, 0.295242f},   {0.238856f, -0.864188f, 0.442863f},   {0.262866f, -0.951056f, 0.162460f},   {0.500000f, -0.809017f, 0.309017f},   {0.716567f, -0.681718f, 0.147621f},   {0.525731f, -0.850651f, 0.000000f},   {-0.238856f, -0.864188f, -0.442863f},   {-0.500000f, -0.809017f, -0.309017f},   {-0.262866f, -0.951056f, -0.162460f},   {-0.850651f, -0.525731f, 0.000000f},   {-0.716567f, -0.681718f, -0.147621f},   {-0.716567f, -0.681718f, 0.147621f},   {-0.525731f, -0.850651f, 0.000000f},   {-0.500000f, -0.809017f, 0.309017f},   {-0.238856f, -0.864188f, 0.442863f},   {-0.262866f, -0.951056f, 0.162460f},   {-0.864188f, -0.442863f, 0.238856f},   {-0.809017f, -0.309017f, 0.500000f},   {-0.688191f, -0.587785f, 0.425325f},   {-0.681718f, -0.147621f, 0.716567f},   {-0.442863f, -0.238856f, 0.864188f},   {-0.587785f, -0.425325f, 0.688191f},   {-0.309017f, -0.500000f, 0.809017f},   {-0.147621f, -0.716567f, 0.681718f},   {-0.425325f, -0.688191f, 0.587785f},   {-0.162460f, -0.262866f, 0.951056f},   {0.442863f, -0.238856f, 0.864188f},   {0.162460f, -0.262866f, 0.951056f},   {0.309017f, -0.500000f, 0.809017f},   {0.147621f, -0.716567f, 0.681718f},   {0.000000f, -0.525731f, 0.850651f},   {0.425325f, -0.688191f, 0.587785f},   {0.587785f, -0.425325f, 0.688191f},   {0.688191f, -0.587785f, 0.425325f},   {-0.955423f, 0.295242f, 0.000000f},   {-0.951056f, 0.162460f, 0.262866f},   {-1.000000f, 0.000000f, 0.000000f},   {-0.850651f, 0.000000f, 0.525731f},   {-0.955423f, -0.295242f, 0.000000f},   {-0.951056f, -0.162460f, 0.262866f},   {-0.864188f, 0.442863f, -0.238856f},   {-0.951056f, 0.162460f, -0.262866f},   {-0.809017f, 0.309017f, -0.500000f},   {-0.864188f, -0.442863f, -0.238856f},   {-0.951056f, -0.162460f, -0.262866f},   {-0.809017f, -0.309017f, -0.500000f},   {-0.681718f, 0.147621f, -0.716567f},   {-0.681718f, -0.147621f, -0.716567f},   {-0.850651f, 0.000000f, -0.525731f},   {-0.688191f, 0.587785f, -0.425325f},   {-0.587785f, 0.425325f, -0.688191f},   {-0.425325f, 0.688191f, -0.587785f},   {-0.425325f, -0.688191f, -0.587785f},   {-0.587785f, -0.425325f, -0.688191f},   {-0.688191f, -0.587785f, -0.425325f},};

The worst thing in the end: md2 files contain a list of GL_TRIANGLE_FAN and GL_TRIANGLE_STRIP commands. Those increase the fps by rendering less vertices or something. Obsolete in modern engines according to people in the internet. This might show how they work https://i.stack.imgur.com/sfQdh.jpg . I don't know yet what might be a good / the best way to calculate these commands but just SOMETHING should be enough in 2020.

These are probably just notes for my future self or nobody at all, but when I started working with .md2 files I hated the lack of actually relevant information in these forums so I'm sharing what I found out. If someone decides to give this a try he might want to know that the only animated MD2 model in this game is the flag model which jitspoe also wants to replace by a .skm model for getting better animations.


jitspoe

  • Administrator
  • Autococker
  • Posts: 18801
Re: Information about the .md2 format or How to write a .md2 exporter
« Reply #1 on: April 22, 2020, 01:25:46 AM »
This might be helpful if you want to look into skm support: https://github.com/Qfusion/qfusion/wiki/%5BOUTDATED%5D-SKM,-skeletal-models