MESH

**Meshes** define a textured polygon model whose vertices wrap around the bones of a skeleton.

Meshes follow the following format:

* **Version** - A 4-byte unsigned integer specifying the version number of this mesh file; should be equal to 2
* **Bone count** - A 4-byte unsigned integer specifying the number of bones referred to by this mesh
* **Bone names** - A consecutive list of Pascal strings specifying all bones referred to by this mesh
* **Face count** - A 4-byte unsigned integer specifying the number of triangle faces defined in this mesh
* **Faces** - For each face:

* **Vertex A index** - A 4-byte unsigned integer specifying the zero-based index of a real vertex in *Real Vertices* used by this face
* **Vertex B index** - A 4-byte unsigned integer specifying the zero-based index of a real vertex in *Real Vertices* used by this face
* **Vertex C index** - A 4-byte unsigned integer specifying the zero-based index of a real vertex in *Real Vertices* used by this face

Note: All vertices referred to by the faces are real vertices.
Note: Faces oriented outside are defined in clockwise order. Thus, during rendering, you can enable back-face culling such that front faces are defined in clockwise order.
* **Binding count** - A 4-byte unsigned integer specifying the number of bone bindings defined in this mesh; each bone should have exactly one binding
* **Bindings** - For each bone binding:

* **Bone index** - A 4-byte unsigned integer specifying the zero-based index of the bone in *Bone names* which this binding corresponds to
* **First real vertex index** - A 4-byte unsigned integer specifying the zero-based index of the first real vertex in *Real Vertices* to be wrapped around this bone
* **Real vertex count** - A 4-byte unsigned integer specifying the number of real vertices in *Real Vertices* starting from index *First real vertex index* to be wrapped around this bone
* **First blend vertex index** - A 4-byte unsigned integer specifying the zero-based index of the first blend vertex in *Blend Vertices* to be wrapped around this bone
* **Blend vertex count** - A 4-byte unsigned integer specifying the number of blend vertices in *Blend Vertices* starting from index *First blend vertex index* to be wrapped around this bone

* **Real vertex count** - A 4-byte unsigned integer specifying the number of real vertices defined in this mesh
* **Texture vertices** - Texture vertices are defined for real vertices only. For each real vertex:

* **u** - A 32-bit little-endian float specifying the u texture coordinate of this vertex
* **v** - A 32-bit little-endian float specifying the v texture coordinate of this vertex

These values assume top-down textures, meaning that for bottom-up textures, you have to flip the coordinates by negating V.
* **Blend vertex count** - A 4-byte unsigned integer specifying the number of blend vertices defined in this mesh
* **Blend vertex properties** - For each blend vertex:

* **Weight** - A 4-byte unsigned integer in Q1.15 fixed-point format specifying the percentage, from 0.0 (represented by 0x0000) to 1.0 (represented by 0x8000), of the distance that this blend vertex tugs its corresponding real vertex by, starting from the location of the real vertex (corresponding to the weight 0x0000 or 0.0) and ending at the "reach-for" location of this blend vertex (corresponding to the weight 0x8000 or 1.0). \*After\* wrapping the real and blend vertices around their respective bones on the skeleton, perform the following calculation: Real\_Vertex\_Location\_After\_Blending = Weight\*Blend\_Vertex\_Location + (1-Weight)\*Real\_Vertex\_Location\_Before\_Blending.
* **Other vertex index** - A 4-byte unsigned integer specifying the zero-based index of which vertex in *Real Vertices* to influence the location of

Blend vertices themselves are not rendered. They simply affect the locations of real vertices.
Note: Some real vertices on one bone may be blended by the blend vertices on other bones.
* **Total vertex count** - A 4-byte unsigned integer specifying the total number of both real and blend vertices defined in this mesh
* **Real vertices** - For each real vertex:

* **Position** - Three 32-bit little-endian floats: x,y,z
* **Normal vector** - Three 32-bit little-endian floats: x,y,z

* **Blend vertices** - For each blend vertex:

* **Position** - Three 32-bit little-endian floats: x,y,z
* **Normal vector** - Three 32-bit little-endian floats: x,y,z