This page follows the MilkShape 3D 1.8.2 File Format Specification by
Mete Ciragan (ms3dspec.txt.c in the MilkShape SDK; the copy shipped with
SDK 1.8.4 is identical). The last vertex block version, 3, is newer than that text and
is taken from open-source readers and from sample files. All numbers are
little-endian: word is an unsigned 16-bit integer, int a
32-bit integer, float a 32-bit IEEE number, byte an unsigned
8-bit integer and char a signed one. Structures are packed to single
bytes.
Order of the file
| Part | Size in bytes |
|---|---|
| Header | 14 |
nNumVertices (word), then the vertices | 2 + 15 each |
nNumTriangles (word), then the triangles | 2 + 70 each |
nNumGroups (word), then the groups | 2 + (36 + 2 × triangles) each |
nNumMaterials (word), then the materials | 2 + 361 each |
| Animation settings | 12 |
nNumJoints (word), then the joints | 2 + (93 + 16 × keys) each |
| Comment block | varies |
| Vertex extra block | 4 + 6, 10 or 14 per vertex |
| Joint extra block | 4 + 12 per joint |
| Model extra block | 16 |
The last four blocks are absent from older files: a file may end after the last joint, and a reader should stop wherever the data runs out.
The specification sets these maxima: 65534 vertices, 65534 triangles, 255 groups, 128 materials and 128 joints.
Flags
Vertices, triangles, groups and joints each start with a set of editor flags.
| Value | Name | Listed for |
|---|---|---|
| 1 | SELECTED | vertices, triangles, groups, joints |
| 2 | HIDDEN | vertices, triangles, groups |
| 4 | SELECTED2 | vertices, triangles |
| 8 | DIRTY | joints |
Header
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 10 | char[10] | id | Always MS3D000000 (4D 53 33 44 30 30 30 30 30 30), with no terminating zero |
| 10 | 4 | int | version | 4 |
Vertices
15 bytes each (ms3d_vertex_t).
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 1 | byte | flags | Editor flags |
| 1 | 12 | float[3] | vertex | Position x, y, z |
| 13 | 1 | char | boneId | Index of the joint that moves the vertex; −1 for none |
| 14 | 1 | byte | referenceCount | A reference count kept by the editor. The specification gives no rule for it, and the Assimp and Irrlicht loaders do not use it to build the mesh |
Triangles
70 bytes each (ms3d_triangle_t). Normals and texture coordinates are
stored per corner, so two triangles can share a vertex and still differ in both.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 2 | word | flags | Editor flags |
| 2 | 6 | word[3] | vertexIndices | The three corners, indices into the vertex list |
| 8 | 36 | float[3][3] | vertexNormals | A normal (x, y, z) for each corner in turn |
| 44 | 12 | float[3] | s | Horizontal texture coordinate of corners 1, 2, 3 |
| 56 | 12 | float[3] | t | Vertical texture coordinate of corners 1, 2, 3, measured down from the top of the image (Assimp and Blender importers use 1 − t where their origin is at the bottom) |
| 68 | 1 | byte | smoothingGroup | 1 to 32; 0 is used for no smoothing group |
| 69 | 1 | byte | groupIndex | The group the triangle belongs to |
Groups
Groups are the parts of the mesh (ms3d_group_t). The size depends on
the number of triangles.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 1 | byte | flags | Editor flags |
| 1 | 32 | char[32] | name | Group name, padded with zero bytes |
| 33 | 2 | word | numtriangles | Number of triangles in the group |
| 35 | 2n | word[n] | triangleIndices | Indices into the triangle list |
| 35 + 2n | 1 | char | materialIndex | Index into the material list; −1 for no material |
The specification names no character set for any name or comment.
Materials
361 bytes each (ms3d_material_t). Colours are four floats, red,
green, blue and alpha.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 32 | char[32] | name | Material name |
| 32 | 16 | float[4] | ambient | Ambient colour |
| 48 | 16 | float[4] | diffuse | Diffuse colour |
| 64 | 16 | float[4] | specular | Specular colour |
| 80 | 16 | float[4] | emissive | Emissive colour |
| 96 | 4 | float | shininess | 0.0 to 128.0 |
| 100 | 4 | float | transparency | 0.0 to 1.0; 1.0 is opaque |
| 104 | 1 | char | mode | 0, 1 or 2; the specification says it is no longer used |
| 105 | 128 | char[128] | texture | Texture image file name, for example texture.bmp |
| 233 | 128 | char[128] | alphamap | Alpha map file name, for example alpha.bmp |
Animation settings
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | float | fAnimationFPS | Frames per second |
| 4 | 4 | float | fCurrentTime | The editor’s current time |
| 8 | 4 | int | iTotalFrames | Length of the animation in frames |
Joints
93 bytes plus the keyframes (ms3d_joint_t). A joint names its parent;
there are no parent indices.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 1 | byte | flags | Editor flags |
| 1 | 32 | char[32] | name | Joint name |
| 33 | 32 | char[32] | parentName | Name of the parent joint; empty for a root |
| 65 | 12 | float[3] | rotation | Reference rotation relative to the parent: angles about x, y and z, in radians |
| 77 | 12 | float[3] | position | Reference position relative to the parent |
| 89 | 2 | word | numKeyFramesRot | Rotation keyframes |
| 91 | 2 | word | numKeyFramesTrans | Position keyframes |
| 93 | 16 each | keyFramesRot | All rotation keys: float time in seconds, float[3] rotation (x, y, z angles) | |
| … | 16 each | keyFramesTrans | Then all position keys: float time in seconds, float[3] position |
How joints move the mesh
A joint’s reference matrix is built from its rotation and
position, rotating about x, then y, then z, and chained down from the
root. Keyframes are relative to that reference. The specification gives the steps for
a vertex:
- Multiply the vertex by the inverse of the joint’s reference matrix.
- Translate the result by the position key, in the frame of the reference matrix.
- Multiply by the reference matrix combined with the rotation key.
For normals the translation (step 2) is skipped. The Irrlicht loader builds the same result by composing each joint’s local matrix from the reference matrix, the position key and the rotation key.
Vertex extra block
An int subVersion, then one record for every vertex, in vertex
order. The records let up to four joints share a vertex.
| Offset | Size | Type | Name | In versions | Meaning |
|---|---|---|---|---|---|
| 0 | 3 | char[3] | boneIds | 1, 2, 3 | Second, third and fourth joint; −1 means none, and its weight is ignored |
| 3 | 3 | byte[3] | weights | 1, 2, 3 | Weights of the first three joints |
| 6 | 4 | unsigned int | extra | 2, 3 | A free 32-bit value, for a colour or anything else |
| 10 | 4 | unsigned int | extra 2 | 3 | A second free 32-bit value |
subVersion | Record size | Weight scale |
|---|---|---|
| 1 | 6 | 0 to 255 |
| 2 | 10 | 0 to 100 |
| 3 | 14 | 0 to 100 |
The weights belong to joints as follows:
weights[0]is for the vertex’s ownboneId;weights[1]is forboneIds[0];weights[2]is forboneIds[1];boneIds[2]gets what remains: the full weight minus the other three.
When all three stored weights are zero, readers such as the Blender add-on give the
whole weight to boneId.
Maverick Model 3D’s export options describe a version 0 as the original form in which a vertex has one joint only, and note that MilkShape 1.8.0 and later do not draw version 1 models correctly. It writes the two extra values as the same pair for every vertex.
Joint extra block
An int subVersion, then one record per joint, in joint order.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 12 | float[3] | color | The joint’s display colour: red, green, blue |
The only record the specification defines is that of version 1. A comment beside the version number there says 2, and sample files with this block write 1.
Model extra block
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | int | subVersion | 1 |
| 4 | 4 | float | jointSize | Size at which joints are drawn |
| 8 | 4 | int | transparencyMode | 0 simple; 1 depth buffered with an alpha reference value; 2 depth-sorted triangles |
| 12 | 4 | float | alphaRef | Alpha reference value for mode 1 |
Worked example
The start of twospheres.ms3d from Assimp’s test models:
00000000 4D 53 33 44 30 30 30 30 30 30 04 00 00 00 7C 00 MS3D000000....|.
00000010 01 00 00 C0 C1 00 00 81 42 00 00 00 00 FF 0C 01 ........B.......
The signature and version 4 are followed by 124 vertices (7C 00). The
first has flags 1 (selected), position (−24.0, 64.5, 0.0), bone −1 and a reference
count of 12.
The file is 21028 bytes long and ends with the optional blocks. At 19248 the comment block has version 1 and four zero counts. At 19268 the vertex extra block has version 3, and 124 records of 14 bytes take it to 21008. The last 20 bytes are the joint extra version 1 (there are no joints), then the model extra block: version 1, joint size 1.0, transparency mode 0 and alpha reference 0.5.
Divergence from the specification
- Vertex extra version 3 is newer than the 1.8.2 text, which ends
at version 2. Records are 14 bytes, as the sample above shows and the Rust
ms3dcrate and Assimp assume. The Blender add-on and the Irrlicht loader read 10 bytes per vertex for it. - Weight scale: Assimp divides weights by 255 for every version, although versions 2 and 3 count to 100.
- Comment counts: the specification makes them 32-bit, as do Irrlicht, the Blender add-on and the sample files. Assimp reads the group, material and joint counts as 16-bit.
- Model comment: the specification refers to the comment structure, which begins with an index; readers read only the length and text.
- Transparency: Assimp uses
transparencyas opacity, which matches the value 1.0 on materials in Assimp’s sample files. The Blender add-on sets alpha to 1 −transparency.
Comment block
subVersionnNumGroupCommentsnNumMaterialCommentsnNumJointCommentsnHasModelCommentA group, material or joint comment record is:
indexcommentLengthcommentMChas length 2The model comment has only
commentLengthandcomment, with no index.