Sei sulla pagina 1di 6

14-12-2010

MD3 (file format) - Wikipedia, the fre

MD3 (file format)


From Wikipedia, the free encyclopedia

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 nonstructural geometry (non-static models) although it may be used for structural uses. Unlike modern formats, animations are not bone based but instead vertex based and are directly contained within the file.

Contents
1 File format 1.1 MD3 header 1.1.1 Frame 1.1.2 Tag 1.1.3 Surface 1.1.3.1 Shader 1.1.3.2 Triangle 1.1.3.3 TexCoord 1.1.3.4 Vertex 1.2 Normals 1.2.1 Encoding 1.2.2 Decoding 2 See also 3 Resources

Example of two MD3 model assets from Quake III Arena that have been linked together using tags.

File format
Data Name Type U8 S16 S32 F32 char short int float 8-bit unsigned octet (character) little-endian signed 16-bit integer little-endian signed 32-bit integer IEEE-754 32-bit floating-point triplet of F32 in sequence (read 4 octets, make float, read 4, make float, read 4, make float), describing a 3-space vector indicates sequential repeat count (homogenous aggregation, array, vector), as in "U8 * 16" to mean a 16-octet array (i.e. character string file/array offset of which to make special note aggregate complex data that should be described elsewhere
1/6

Description

VEC3 vec3_t * ! []

en.wikipedia.org//MD3_(file_format)

14-12-2010

MD3 (file format) - Wikipedia, the fre

MD3 header
Data Type S32 Name MD3_START IDENT Description Offset of MD3 object. Usually 0, but not guaranteed. Magic number. As a string of 4 octets, reads "IDP3"; as unsigned little-endian 860898377 (0x33504449); as unsigned big-endian 1229213747 (0x49445033). MD3 version number, latest known is 15, but use the constant MD3_VERSION. MD3 name, usually its pathname in the PK3. ASCII character string, NULLterminated (C-style). ??? Number of Frame objects, with a maximum of MD3_MAX_FRAMES. Current value of MD3_MAX_FRAMES is 1024. Number of Tag objects, with a maximum of MD3_MAX_TAGS. Current value of MD3_MAX_TAGS is 16. There is one set of tags per frame so the total number of tags to read is (NUM_TAGS * NUM_FRAMES). Number of Surface objects, with a maximum of MD3_MAX_SURFACES. Current value of MD3_MAX_SURFACES is 32. Number of Skin objects. I should note that I have not seen an MD3 using this particular field for anything; this appears to be an artifact from the Quake 2 MD2 format. Surface objects have their own Shader field. Relative offset from start of MD3 object where Frame objects start. The Frame objects are written sequentially, that is, when you read one Frame object, you do not need to seek() for the next object. Relative offset from start of MD3 where Tag objects start. Similarly written sequentially. Relative offset from start of MD3 where Surface objects start. Again, written sequentially. Relative offset from start of MD3 to the end of the MD3 object. Note there is no offset for Skin objects. The array of Frame objects usually starts immediately afterwards, but OFS_FRAMES should be used. The array of Tag objects usually starts immediately after FRAMES, but OFS_TAGS should be used. The array of Surface objects usually start after TAGS, but OFS_SURFACES should be used. End of MD3 object. Should match MD3_START.

S32

VERSION

U8 * NAME 64 S32 S32 FLAGS NUM_FRAMES

S32

NUM_TAGS

S32

NUM_SURFACES

S32

NUM_SKINS

S32

OFS_FRAMES

S32 S32 S32 ! ! ! Frame

OFS_TAGS OFS_SURFACES OFS_EOF (Frame) (Tag) (Surface) MD3_END

en.wikipedia.org//MD3_(file_format)

2/6

14-12-2010

MD3 (file format) - Wikipedia, the fre

General properties of a single animation frame. Data Type VEC3 VEC3 VEC3 F32 U8 * 16 Tag An attachment point for another MD3 model. Data Type Name U8 * 64 VEC3 ORIGIN Coordinates of Tag object. 3x3 rotation matrix associated with the Tag. Description Name MIN_BOUNDS Description First corner of the bounding box.

MAX_BOUNDS Second corner of the bounding box. LOCAL_ORIGIN Local origin, usually (0, 0, 0). RADIUS NAME Radius of bounding sphere. Name of Frame. ASCII character string, NUL-terminated (C-style)

NAME Name of Tag object. ASCII character string, NUL-terminated (C-style).

VEC3 * 3 AXIS Surface

An animated triangle mesh. Data Type S32 Name SURFACE_START IDENT Description Offset relative to start of MD3 object. Magic number. As a string of 4 octets, reads "IDP3"; as unsigned littleendian 860898377 (0x33504449); as unsigned big-endian 1229213747 (0x49445033). Name of Surface object. ASCII character string, NUL-terminated (C-style). ??? Number of animation frames. This should match NUM_FRAMES in the MD3 header. Number of Shader objects defined in this Surface, with a limit of MD3_MAX_SHADERS. Current value of MD3_MAX_SHADERS is 256. Number of Vertex objects defined in this Surface, up to MD3_MAX_VERTS. Current value of MD3_MAX_VERTS is 4096.

U8 * NAME 64 S32 S32 S32 S32 FLAGS NUM_FRAMES NUM_SHADERS NUM_VERTS

S32

Number of Triangle objects defined in this Surface, maximum of NUM_TRIANGLES MD3_MAX_TRIANGLES. Current value of MD3_MAX_TRIANGLES is 8192. OFS_TRIANGLES Relative offset from SURFACE_START where the list of Triangle objects starts.
3/6

S32

en.wikipedia.org//MD3_(file_format)

14-12-2010

MD3 (file format) - Wikipedia, the fre

S32 S32 S32 S32 !

OFS_SHADERS OFS_ST OFS_XYZNORMAL OFS_END (Shader)

Relative offset from SURFACE_START where the list of Shader objects starts. Relative offset from SURFACE_START where the list of ST objects (s-t texture coordinates) starts. Relative offset from SURFACE_START where the list of Vertex objects (X-Y-Z-N vertices) starts. Relative offset from SURFACE_START to where the Surface object ends. List of Shader objects usually starts immediate after the Surface header, but use OFS_SHADERS (or rather, OFS_SHADERS+SURFACE_START for files). List of Triangle objects usually starts immediately after the list of Shader objects, but use OFS_TRIANGLES (+ SURFACE_START). List of ST objects usually starts immediately after the list of Triangle objects, but use OFS_ST (+ SURFACE_START). List of Vertex objects usually starts immediate after the list of St objects, but use OFS_XYZNORMALS (+ SURFACE_START). The total number of objects is (NUM_FRAMES * NUM_VERTS). One set of NUM_VERTS Vertex objects describes the Surface in one frame of animation; the first NUM_VERTS Vertex objects describes the Surface in the first frame of animation, the second NUM_VERTEX Vertex objects describes the Surface in the second frame of animation, and so forth. End of Surface object. Should match OFS_END.

! !

(Triangle) (ST)

(XYZNormal)

Shader

SURFACE_END

Data Type

Name

Description Pathname of shader in the PK3. ASCII character string, NUL-terminated (C-style). Shader index number. No idea how this is allocated, but presumably in sequential order of definition.

U8 * 64 NAME S32 SHADER_INDEX

Triangle

Data Type S32 *3

Name

Description

List of offset values into the list of Vertex objects that constitute the corners of the INDEXES Triangle object. Vertex numbers are used instead of actual coordinates, as the coordinates are implicit in the Vertex object. The triangles have clockwise winding.

TexCoord

Data Name Type


en.wikipedia.org//MD3_(file_format)

Description
4/6

14-12-2010

MD3 (file format) - Wikipedia, the fre

F32 *2

ST

s and t texture coordinates, normalized to the range [0, 1]. Values outside the range indicate wraparounds/repeats. Unlike UV coordinates, the origin for texture coordinates is located in the upper left corner (similar to the coordinate system used for computer screens) whereas, in UV mapping, it is placed in the lower left corner. As such, the t value must be flipped to correspond with UV coordinates. See also Left-hand coordinates

Vertex

Data Type S16 * 3 U8*2

Name COORD NORMAL

Description x, y, and z coordinates in left-handed 3-space, scaled down by factor 1.0/64. (Multiply by 1.0/64 to obtain original coordinate value.) Zenith and azimuth angles of normal vector. 255 corresponds to 2 pi. See spherical coordinates.

Normals
Encoding The normal vector uses a spherical coordinate system. Since the normal vector is, by definition, a length of one, only the angles need to be recorded. Each angle is constrained between 0 - 255 to fit in one octet. A normal vector encodes into 16 bits. (Code in q3tools/common/mathlib.c:NormalToLatLong) azimuth <- atan2(y, x) * 255 / (2 * pi) zenith <- acos(z) * 255 / (2 * pi) Decoding (Code in q3tools/q3map/misc_model.c:InsertMD3Model) lat <- zenith * (2 * pi ) / 255 lng <- azimuth * (2 * pi) / 255 x <- cos ( lat ) * sin ( lng ) y <- sin ( lat ) * sin ( lng ) z <- cos ( lng )

See also
Quake III Arena id Tech 3 id Software

Resources
Various post at QuakeSrc Forums (http://www.quakesrc.org) Quake3 Source (ftp://ftp.idsoftware.com/idstuff/source/quake3-1.32b-source.zip) Various discussions in IRC chats.
en.wikipedia.org//MD3_(file_format) 5/6

14-12-2010

MD3 (file format) - Wikipedia, the fre

MD3 Specification by Phaethon H. (http://linux.ucla.edu/~phaethon/q3/formats/md3format.html) Retrieved from "http://en.wikipedia.org/wiki/MD3_(file_format)" Categories: CAD file formats | 3D graphics software | Quake | Filename extensions This page was last modified on 4 December 2010 at 13:04. Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. See Terms of Use for details. Wikipedia is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.

en.wikipedia.org//MD3_(file_format)

6/6

Potrebbero piacerti anche