Introduction
IQM, the Inter-Quake Model format by Lee Salzman, is a binary format for skeletal animated models that an engine can load with little processing: vertex data is in ready-to-use arrays and animation is a block of 16-bit channel values. It comes with a text counterpart, IQE, a compiler that builds IQM from IQE, MD5, SMD, FBX and OBJ files, and Blender exporters.
The current version is 2, of 31 May 2011, which stores the w component of rotations. Version 1 dates from 20 April 2010.
Structure
All values are little-endian; uint is an unsigned 32-bit integer. A
124-byte header gives the count and offset of every other part. Offsets count from
the start of the header, are 0 when the data is absent, and are aligned to at least
4 bytes. The parts are found only through their offsets; the order below is the one
the IQM compiler writes.
0Header 124 bytestextString table zero-terminated stringsmeshesMeshes 24 bytes eachvertex arraysArray descriptors 20 bytes each, then the vertex datatrianglesTriangles and adjacency 12 bytes eachjoints, posesSkeleton 48 and 88 bytes eachanimsAnimations 20 bytes eachframes, boundsFrame data 16-bit channels, then 32 bytes per framecomment, extensionsOptional free text and a linked list of extra blocks
Header
| Offset | Type | Name | Meaning |
|---|---|---|---|
| 0 | char[16] | magic | INTERQUAKEMODEL and a zero byte |
| 16 | uint | version | 2 (older files: 1) |
| 20 | uint | filesize | Size of the file in bytes |
| 24 | uint | flags | No bits are defined |
| 28, 32 | uint | num_text, ofs_text | String table length in bytes, and offset |
| 36, 40 | uint | num_meshes, ofs_meshes | Meshes |
| 44 | uint | num_vertexarrays | Vertex array descriptors |
| 48 | uint | num_vertexes | Vertices in every array |
| 52 | uint | ofs_vertexarrays | Offset of the descriptors |
| 56, 60 | uint | num_triangles, ofs_triangles | Triangles |
| 64 | uint | ofs_adjacency | Adjacency, one entry per triangle |
| 68, 72 | uint | num_joints, ofs_joints | Joints of the skeleton |
| 76, 80 | uint | num_poses, ofs_poses | Pose descriptors for animation |
| 84, 88 | uint | num_anims, ofs_anims | Named animations |
| 92 | uint | num_frames | Frames in the file |
| 96 | uint | num_framechannels | 16-bit values in one frame |
| 100 | uint | ofs_frames | Frame data |
| 104 | uint | ofs_bounds | One bounding record per frame |
| 108, 112 | uint | num_comment, ofs_comment | Comment bytes |
| 116, 120 | uint | num_extensions, ofs_extensions | Extension count and offset of the first |
A file may hold meshes, animations or both.
String table and comment
Names are byte offsets into the string table, a run of zero-terminated strings
whose first byte is zero, so offset 0 is the empty string. The comment is a separate
block of num_comment bytes of free text. The compiler pads both with
zeros to a multiple of 4.
Meshes
| Offset | Type | Name | Meaning |
|---|---|---|---|
| 0 | uint | name | Unique name of the mesh, if wanted |
| 4 | uint | material | Material or texture name; need not be unique |
| 8 | uint | first_vertex | First vertex of the mesh |
| 12 | uint | num_vertexes | Number of vertices |
| 16 | uint | first_triangle | First triangle |
| 20 | uint | num_triangles | Number of triangles |
Vertex arrays
Each vertex attribute is its own tightly packed array of
num_vertexes × size components; the data is not
interleaved. Arrays that are present are listed in the order of their type
numbers.
| Offset | Type | Name | Meaning |
|---|---|---|---|
| 0 | uint | type | What the array holds |
| 4 | uint | flags | No bits are defined |
| 8 | uint | format | Component data type |
| 12 | uint | size | Components per vertex |
| 16 | uint | offset | Offset of the data, aligned to the larger of the component size and 4 |
Types
The format and size shown are the ones portable models should use. A program need not accept others.
| Value | Name | Format × size | Contents |
|---|---|---|---|
| 0 | IQM_POSITION | float × 3 | Position |
| 1 | IQM_TEXCOORD | float × 2 | Texture coordinate |
| 2 | IQM_NORMAL | float × 3 | Normal |
| 3 | IQM_TANGENT | float × 4 | Tangent, and in w the sign of the bitangent: cross(normal, tangent) × w |
| 4 | IQM_BLENDINDEXES | ubyte × 4 | Joints that move the vertex |
| 5 | IQM_BLENDWEIGHTS | ubyte × 4 | Their weights, in 255ths |
| 6 | IQM_COLOR | ubyte × 4 | Vertex colour |
| 7–15 | Reserved | ||
| 16 up | IQM_CUSTOM | any | A custom attribute; type − 16 is the string table offset of its name |
The compiler keeps each vertex’s four largest blend weights, scales them to total 255 and leaves unused places zero.
Formats
| Value | Name | Bytes |
|---|---|---|
| 0 | IQM_BYTE | 1 |
| 1 | IQM_UBYTE | 1 |
| 2 | IQM_SHORT | 2 |
| 3 | IQM_USHORT | 2 |
| 4 | IQM_INT | 4 |
| 5 | IQM_UINT | 4 |
| 6 | IQM_HALF | 2 |
| 7 | IQM_FLOAT | 4 |
| 8 | IQM_DOUBLE | 8 |
Triangles and adjacency
A triangle is uint vertex[3], indices into the vertex arrays counted
across all meshes. An adjacency entry is uint triangle[3]: for edges 0,
1 and 2 of the triangle with the same number, the index of the neighbouring
triangle, counted across all meshes, or 0xFFFFFFFF where there is none.
Joints
The base pose of the skeleton, 48 bytes a joint.
| Offset | Type | Name | Meaning |
|---|---|---|---|
| 0 | uint | name | Joint name |
| 4 | int | parent | Parent joint; negative for a root |
| 8 | float[3] | translate | Translation |
| 20 | float[4] | rotate | Rotation quaternion x, y, z, w, relative to the parent |
| 36 | float[3] | scale | Scale |
A point is transformed as (input × scale), rotated, plus the translation. The joint’s transform in model space is its parent’s combined with its own.
Poses and frames
There is one pose descriptor per animated joint, 88 bytes each; a file with both joints and poses has the same number of each. A joint pose has ten channels: 0–2 translation, 3–6 rotation (x, y, z, w) and 7–9 scale.
| Offset | Type | Name | Meaning |
|---|---|---|---|
| 0 | int | parent | Parent joint; negative for a root |
| 4 | uint | channelmask | Bit k set: channel k varies and is stored in the frames |
| 8 | float[10] | channeloffset | Base value of each channel |
| 48 | float[10] | channelscale | Step of each channel |
The frame data is one array of unsigned 16-bit values,
num_frames × num_framechannels long. A frame runs through
the poses in order and, for each, through its channels in ascending order, holding a
value only for the channels in the mask. A channel is
value = channeloffset[k] + (stored ? u16 × channelscale[k] : 0)
The compiler sets the offset to the channel’s minimum over all frames and the scale to its range divided by 65535; a channel that never changes is left out of the mask. It writes rotations with w zero or negative. The sample loader normalises the quaternion after decoding, and animates a vertex with, for each joint, parent base × frame pose × inverse base of the joint, combined down the hierarchy.
Animations
| Offset | Type | Name | Meaning |
|---|---|---|---|
| 0 | uint | name | Animation name |
| 4 | uint | first_frame | First frame |
| 8 | uint | num_frames | Number of frames |
| 12 | float | framerate | Frames per second |
| 16 | uint | flags | Bit 0, IQM_LOOP: the animation loops |
Bounds
| Offset | Type | Name | Meaning |
|---|---|---|---|
| 0 | float[3] | bbmins | Lower corner of the frame’s bounding box |
| 12 | float[3] | bbmaxs | Upper corner |
| 24 | float | xyradius | Radius of a circle in the X-Y plane |
| 28 | float | radius | Radius of a sphere |
Extensions
Extensions form a linked list, not an array. The header points to the first, and each points to the next.
| Offset | Type | Name | Meaning |
|---|---|---|---|
| 0 | uint | name | Name of the extension |
| 4 | uint | num_data | Size of its data |
| 8 | uint | ofs_data | Offset of its data |
| 12 | uint | ofs_extensions | Offset of the next extension |
Extensions of the FTE engine
The format defines no extension of its own. The FTE QuakeWorld engine reads three,
matching names without regard to case, with num_data in bytes.
FTE_MESH, 28 bytes for each mesh:
| Type | Name | Meaning |
|---|---|---|
| uint | contents | Collision contents bits |
| uint | surfaceflags | Surface flags reported by traces |
| uint | surfaceid | Body part number reported by traces |
| uint | geomset | Geometry set of the mesh |
| uint | geomid | Number within the set |
| float | mindist | Minimum view distance |
| float | maxdist | Maximum view distance |
FTE_EVENT, any number of 16-byte records:
| Type | Name | Meaning |
|---|---|---|
| uint | anim | Animation the event belongs to |
| float | timestamp | Time of the event within it |
| uint | evcode | Event code |
| uint | evdata_str | Event text, a string table offset |
FTE_SKINS: two uints, the number of skin frames and the number of mesh
skins; then one uint per mesh with its skin count; then the skin frames, 8 bytes each
(material_idx and shadertext_idx); then the mesh skins, 12
bytes each (uint firstframe into the skin frames, uint
countframes, float interval), those of mesh 0 first.
Version 1
Version 1 has the same header. Its rotations omit w:
- a joint is 44 bytes, with
rotateas float[3] (x, y, z); - a pose is 80 bytes, with nine channels (translation 0–2, rotation 3–5, scale 6–8) and nine-element offset and scale arrays.
w is recovered as −√(max(1 − x² − y² − z², 0)). The IQM upgrader rewrites version 1 files as version 2, and regenerates tangents.
Worked example
The start of mrfixit.iqm, the model shipped with the format’s sample
code:
00000000 49 4E 54 45 52 51 55 41 4B 45 4D 4F 44 45 4C 00 INTERQUAKEMODEL.
00000010 02 00 00 00 10 EF 03 00 00 00 00 00 60 03 00 00 ............`...
00000020 7C 00 00 00 02 00 00 00 DC 03 00 00 06 00 00 00 |...............
00000030 45 07 00 00 0C 04 00 00 AC 0B 00 00 A0 9B 01 00 E...............
Version 2, 257808 bytes, no flags; 864 bytes of strings at 124; 2 meshes at 988; 6
vertex arrays of 1861 vertices, described at 1036; 2988 triangles at 105376. The
rest of the header gives 75 joints and 75 poses, one animation, and 101 frames of 333
channels. The first mesh is Body with material Body.tga,
1476 vertices and 2386 triangles; the animation runs at 24 frames per second.
Divergence from the specification
- The sample loader accepts only version 2, refuses files over 16 MB and requires the recommended format and size for the standard vertex arrays.
- The
FTE_SKINSdeclaration in FTE’siqm.hlists the two leading counts in the opposite order to the engine’s loader, which reads the skin frame count first; the table above follows the loader.
In the explorer
A dropped .iqm file of version 2 or 1 shows every structure in the byte
tree, the string table, every vertex array, the frame channels and the FTE extensions
included. The model is drawn in 3D with every triangle, the skeleton in views of its
own, and the animations can be played; every frame opens as a pose.
Tables list the meshes, vertex arrays, vertices, triangles with their neighbours, joints, poses, animations, frames with their bounds, strings and extensions. Materials name separate files: the names are shown and no textures are applied. Vertex colours are drawn without their alpha byte, which has no effect in the developer kit’s demo either. An animation without a usable frame rate has the rate as an option of the animated views, 24 frames a second to begin with. Files up to 256 MB are read.
Links
Software
- IQM Developer Kit – the compiler, upgrader, Blender exporters and sample loaders (C++, Python)
- FTE QuakeWorld – engine that loads IQM, with the extensions above (C)
Developers
Reference
- Inter-Quake Model – the format’s home page
- iqm.txt – the format description
- iqm.cpp and upgrade.cpp – the writer, and the version 1 reader
- com_mesh.c – FTE’s IQM loader and its extension structures