MD2 (file format)

MD2 (file format)

MD2 is a model format used by id's id Tech 2 engine as well as many other games that use this engine such as Half-Life and sin. The format is used mostly for player models and static models in maps. Unlike modern formats, animations are not bone based but frame based; the keyframes are stored in the model and the engine must create the frames between them.

File format

The MD2 file format is made of two things a header and then the model data such as texture coordinates and vertices.

MD2 Header
At the offset ofs_st there is num_st * this structure

short s
short t

These are compressed texture coordinates to decompress them into a float you devide them by the skinwidth and skinheight intigers like this:

sfloat = (float)s / skinwidth
tfloat = (float)t / skinheight

At offset ofs_tris there are num_tris * this structure short vertexindex [3] short textureindex [3] These are indexs to each vertex and texture coordinate and tell the engine what vertex comes next. You use these indexs to find the right vertex in a frame to display. At offset ofs_frames frame data is stored each frame has a header and then a number of vertex and lightnormal indexs after it the frame header is like this: float scale [3] float translate [3] char name [16] Then there is num_xyz of this structure after it: unsigned char v [3] unsigned char lightnormalindex Each vertex is compressed to decompress them you must multiply each coordinate by the frames scale and then add the frames translation vector onto that. The light normal index reffers to a premade array of light normals. The frames scale and translation vector can be found in the frames header here is an example of how to decompress this. (v [0] * scale [0] ) + translate [0] // x (v [1] * scale [1] ) + translate [1] // y (v [2] * scale [2] ) + translate [2] // z

Example

This is an example of how to decompress a single frame and display it. Its not in any specific programing language to try and make it easy for every one to interperate. variables have $ before them and their type
loop while $(int)index is less than $(int)num_tris texture_function_s $(float)texture_coordinates [ $(short)triangle [ $(int)index ] .textureindex [0] ] .s / skinwidth texture_function_t $(float)texture_coordinates [ $(short)triangle [ $(int)index ] .textureindex [0] ] .t / skinheight normal_function $(unsigned char)vertex [ $(short)triangle [ $(int)index ] .vertexindex [0] ] .lightnormalindex vertex_function_x ($(unsigned char)vertex [ $(short)triangle [ $(int)index ] .vertexindex [0] ] .v [0] * scale [0] ) + translate [0] vertex_function_y ($(unsigned char)vertex [ $(short)triangle [ $(int)index ] .vertexindex [0] ] .v [1] * scale [1] ) + translate [1] vertex_function_z ($(unsigned char)vertex [ $(short)triangle [ $(int)index ] .vertexindex [0] ] .v [2] * scale [2] ) + translate [2] $(int)index = $(int)index + 1 end loop

ee also

*id Tech 2 Engine.
*Id Software.

Resources

[http://tfc.duke.free.fr/old/models/md2.htm The Quake II's MD2 file format]
[ftp://ftp.idsoftware.com/idstuff/source/quake2.zip Quake2 Source]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • MD3 (file format) — Example of two MD3 model assets from Quake III Arena that have been linked together using tags. MD3 is a model format used by the Quake 3 engine as well as its many mods. The format is used mostly for player models and non structural geometry… …   Wikipedia

  • MD2 — can refer to: MD2 (cryptography) MD 2 (immunology) Maryland s 2nd congressional district Maryland Route 2 MD2 (file format) IMBEL MD2 Rifle This disambiguation page lists articles associated with the same title formed as a letter number… …   Wikipedia

  • List of file formats — This is an incomplete list, which may never be able to satisfy particular standards for completeness. You can help by expanding it with reliably sourced entries. See also: List of file formats (alphabetical) This is a list of file formats… …   Wikipedia

  • Comparison of 3D computer graphics software — 3D computer graphics software refers to programs used to create 3D computer generated imagery. Contents 1 General information 2 Operating system support 3 Features 4 …   Wikipedia

  • Ultimate 3D — Infobox Software name = Ultimate 3D author = Christoph Peters developer = Christoph Peters website = http://www.ultimate3d.org/ license = Creative Commons Attribution 3.0 Unported operating system = Microsoft Windows latest release version = 2.1… …   Wikipedia

  • MPQ — (Mo PaQ, short for Mike O Brien Pack, named after its creator[citation needed]), is an archiving file format used in several of Blizzard Entertainment s games. MPQs used in Blizzard s games generally contain a game s data files, including… …   Wikipedia

  • Crystalspace — Crystal Space ist ein freies (LGPL) und portables 3D Game Development Kit und Game Engine, geschrieben in der Programmiersprache C++. Das Framework ist nicht nur für die Spieleentwicklung geeignet, sondern lässt sich für generelle 3D… …   Deutsch Wikipedia

  • Blender — Pour les articles homonymes, voir Blender (homonymie) …   Wikipédia en Français

  • Id Tech 3 — Infobox Software name = id Tech 3 caption = collapsible = author = developer = id Software released = latest release version = latest release date = latest preview version = latest preview date = frequently updated = programming language = C… …   Wikipedia

  • AutoQ3D — Infobox Software name = AutoQ3D caption = developer = The AutoQ3D Project Team latest release version = 1.36b latest release date = July 2007 operating system = Cross platform genre = 3D computer graphics license = GPL website =… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”