Difference between revisions of "MDL0 (File Format)"

From Custom Mario Kart
Jump to navigation Jump to search
Tags: Mobile web edit Mobile edit Advanced mobile edit
 
(86 intermediate revisions by 14 users not shown)
Line 1: Line 1:
This page describes the [[Mario Kart Wii]] '''MDL0''' file format, as found within [[BRRES (File Format)|BRRES files]].
+
== Overview ==
 +
This article describes the [[Mario Kart Wii]] '''MDL0''' file format, as found within [[BRRES (File Format)|BRRES]] files.
  
__TOC__
 
 
== File Format ==
 
== File Format ==
 
=== File Header ===
 
=== File Header ===
 
 
{{BRRES sub file header|MDL0}}
 
{{BRRES sub file header|MDL0}}
  
All offsets are relative to the start of the header.<br />
+
* All offsets are relative to the start of the header.
The Section Count is stored as 3 less than it should be. <br />
+
* [[Mario Kart Wii]] uses MDL0 v11 with (N=) 14 sections.
The section offsets point to [[BRRES Index Group (File Format)|BRRES Index Group]] structures for the directories, which in turn point to the actual data sections within the MDL0 file. <br />
+
* The section offsets point to [[BRRES Index Group (File Format)|BRRES Index Group]] structures for the directories, which in turn point to the actual data sections within the MDL0 file.
The meaning of each section is defined by number as below.
+
* Sections are linked by names. The names are stored in a common string pool for all [[BRRES]] sub files. MDL0 itself stores only 32-bit offsets into the common string pool.
  
 +
The meaning of each section is defined by numbers as below:
 
{| class="wikitable"
 
{| class="wikitable"
! Section !! description
+
! Section !! Description
|-
 
| 0 || Draw lists
 
 
|-
 
|-
| 1 || Bones
+
| 0 || Draw lists.
 
|-
 
|-
| 2 || Verticies
+
| 1 || Bones.
 
|-
 
|-
| 3 || Normals
+
| 2 || Vertices.
 
|-
 
|-
| 4 || Colors
+
| 3 || Normals.
 
|-
 
|-
| 5 || Texture Coordinates
+
| 4 || Colors.
 
|-
 
|-
| 6 || '''Unknown (Not Seen in v9 mdl0s)'''
+
| 5 || Texture coordinates.
 
|-
 
|-
| 7 || '''Unknown (Not Seen in v9 mdl0s)'''
+
| 6 || Fur vectors '''(seen in v10+ MDL0's)'''.
 
|-
 
|-
| 8 || Materials
+
| 7 || Fur layers '''(seen in v10+ MDL0's)'''.
 
|-
 
|-
| 9 || Material Nodes (TEV's)
+
| 8 || Materials.
 
|-
 
|-
| 10 || Objects (Polygons)
+
| 9 || TEV's (shader-like operations).
 
|-
 
|-
| 11 || Texture Links
+
| 10 || Objects (polygons).
 
|-
 
|-
| 12 || Pallet Links '''(Not Seen in [[Mario Kart Wii]])'''
+
| 11 || Texture links.
 
|-
 
|-
| 13 || '''Unknown (Not Seen in [[Mario Kart Wii]] or v9 mdl0s)'''
+
| 12 || Palette links '''(not seen in Mario Kart Wii)'''.
 
|-
 
|-
 +
| 13 || User Data. Not seen in Mario Kart Wii or v9 MDL0's.
 
|}
 
|}
  
 
=== MDL0 Header ===
 
=== MDL0 Header ===
Following the section offsets is the MDL0 header structure.
+
Following the section offsets, there is a MDL0 header structure.
  
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Header Length (0x40)
+
| 0x00 || UInt32 || Header length (0x40).
 +
|-
 +
| 0x04 || Int32 || File header offset.
 +
|-
 +
| 0x08 || UInt32 || '''Scaling Mode'''
 +
{| class="wikitable
 +
! Value !! Description
 
|-
 
|-
| 0x04 || 4 || File Header Offset
+
| 0x0 || Standard
 
|-
 
|-
| 0x08 || 4 || '''Unknown'''
+
| 0x1 || SoftImage
 +
|-
 +
| 0x2 || Maya
 +
|}
 
|-
 
|-
| 0x0C || 4 || '''Unknown'''
+
| 0x0C || UInt32 || '''Texture Matrix Mode'''
 +
{| class="wikitable
 +
! Value !! Description
 
|-
 
|-
| 0x10 || 4 || Vertex Count
+
| 0x0 || Maya
 
|-
 
|-
| 0x14 || 4 || Face Count
+
| 0x1 || XSI
 +
|-
 +
| 0x2 || 3ds Max
 +
|}
 
|-
 
|-
| 0x18 || 4 || '''Unknown'''
+
| 0x10 || Int32 || Vertex count.
 
|-
 
|-
| 0x1C || 4 || Bone Count
+
| 0x14 || Int32 || Face count.
 
|-
 
|-
| 0x20 || 4 || '''Unknown''' (0x01000000)
+
| 0x18 || Int32 || {{Unknown-left|Unused. Offset to absolute path of intermediate file.}}
 
|-
 
|-
| 0x24 || 4 || Bone Table Offset
+
| 0x1C || UInt32 || Matricies count.
 
|-
 
|-
| 0x28 || 12 || Minimum (float3)
+
| 0x20 || Byte || Requires normalized matricies array if not 0.
 
|-
 
|-
| 0x34 || 12 || Maximum (float3)
+
| 0x21 || Byte || Requires texture matrices array if not 0.
 
|-
 
|-
 +
| 0x22 || Byte || Enable bounding volume data if not 0.
 +
|-
 +
| 0x23 || Byte || {{Unknown-left|'''Unknown.''' Padding?}}
 +
|-
 +
| 0x24 || Int32 || Offset to matricies table.
 +
|-
 +
| 0x28 || Float[3] || Bounding volume minimum.
 +
|-
 +
| 0x34 || Float[3] || Bounding volume maximum.
 
|}
 
|}
All offsets are relative to the start of the header.<br />
+
 
=== Bone Table ===
+
All offsets are relative to the start of the header.
The bone table usually follows directly after the MDL0 Header. Its offset also lies within the header however. The table describes how the IDs of Bone sections related to their indicies. If the Wii needs a specific bone, it looks up the id in this table, and the loads the bone from the index given.
+
 
 +
=== Bone-Link Table ===
 +
The bone-link table usually follows directly after the MDL0 header. However, its offset also lies within the header. The table below describes how the IDs of bone sections are related to their indices. If the game needs a specific bone, it looks up the ID from this table, and then loads the bone from the index given.
  
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Entry Count
+
| 0x00 || 4 || Entry count.
|-
 
| 0x04 || 4 * Entry Count || Node index (-1 for not present)
 
 
|-
 
|-
 +
| 0x04 || 4 * Entry count || Node index (-1 if not present).
 
|}
 
|}
  
 +
If a model has five bones and nine weights, and bones 0 and 3 do not affect geometry, the block would look like this:
 +
 +
<span style="font-family: Courier New;">00000001 00000002 00000004 FFFFFFFF<br/>
 +
FFFFFFFF FFFFFFFF FFFFFFFF 00000000<br/>
 +
00000003</span>
 +
 +
The weights that have one bone affecting geometry come first, then the ones with multiple influences (all as 0xFFFFFFFF), and finally, the weights for joints with no geometry.
  
notes:<br />
+
The indices in the Nodemix block will match up to the weights' position here, and the 0x10 block in a joint will be the index of its weight as it appears here (so the value of 0x10 in joint 0 above would be 0x00000007).
If a model has 5 bones, and 9 weights, and bones 0 and 3 do not affect geometry the block would look like this:
 
  
 +
=== BRRES Index Group ===
 +
Following the bone-link table, one [[BRRES Index Group (File Format)|BRRES Index Group]] for each non empty section is defined. The sections in the MDL0 header link to the groups.
  
<span style="font-family: Courier New;">00000001 00000002 00000004 FFFFFFFF<br />
+
== Section Order ==
FFFFFFFF FFFFFFFF FFFFFFFF 00000000<br />
+
In [[Mario Kart Wii]], we can find some old and unused v8 MDL0 files (<tt>old_mario_gc_*.szs</tt>; 11 sections) and v11 (the rest of them; 14 sections).
00000003</span>
 
  
 +
The v8 MDL0 files use sections 0–9, but not 10. The general section order is: 9, 0, 1, 6, 7, 8, 2, 3, 4, 5.
  
So the weights with one bone affecting geometry come first, the weights with multiple influences (all as 0xFFFFFFFF), and finally the weights for joints with no geometry.
+
All the v11 ones use sections 0–5 and 8–11, but not 6, 7, 12 and 13. The general order here is 11, 0, 1, 8, 9, 10, 2, 3, 4, 5.
  
The indexes in the Nodemix block will match up to the weights position here, and the 0x10 block in a joint will be the index of its weight as it appears here (So the value of 0x10 in joint 0 above would be 0x00000007).
+
If creating a new v11 MDL0 file, it is recommended to use this section order: 11, 0, 1, 6, 7, 8, 9, 10, 2, 3, 4, 5. The order of sections 12 and 13 is unknown.
  
== Section formats ==
+
== Section Formats ==
 
=== Section 0 - Draw Lists ===
 
=== Section 0 - Draw Lists ===
The draw list format is poorly understood. It is known to control the fundamentals of how things are rendered, and in what order. It is used to link polygons to materials. The format is simply a series of command bytes followed by a variable amount of parameters. Known commands are listed below.
+
The draw list format is poorly understood. It is known to control the fundamentals of how things are rendered, and in a specified order. It is used to link polygons to materials. The format is simply a series of command bytes followed by a variable amount of parameters. Known commands are listed below.
  
 
{| class="wikitable"
 
{| class="wikitable"
! rowspan=2 | Code !! colspan=7 | Parameters bytes !! rowspan=2 | Description
+
! rowspan=2 | Code !! rowspan=2 | Length !! colspan=9 | Parameters bytes !! rowspan=2 | Description
 +
|-
 +
! 00 !! 01 !! 02 !! 03 !! 04 !! 05 !! 06 !! 07 !! 08
 
|-
 
|-
! 00 !! 01 !! 02 !! 03 !! 04 !! 05 !! 06
+
| 0x00 || 0x1 || colspan=9 {{Unknown-left|None}} || No operation.
 
|-
 
|-
| 0x01 || colspan=7 | None || End of commands. Keep reading until encountered.
+
| 0x01 || 0x1 || colspan=9 {{Unknown-left|None}} || End of commands. Keep reading until encountered.
 
|-
 
|-
| 0x02 || colspan=2 | Weight index || colspan=2 | Parent Weight index || colspan=3 | None || bone mapping
+
| 0x02 || 0x5 || colspan=2 | Bone index || colspan=2 | Parent matrix index || colspan=5 {{Unknown-left|None}} || Node mapping.
 
|-
 
|-
| 0x03 || colspan=2 | Weight ID || Weight count || colspan=2 | Table ID || colspan=2 | weight * 4 bytes || weighting
+
| 0x03 || 0x4+0x6*'''N''' || colspan=2 | Weight ID || '''N''' + Weight count || colspan=2 | Table ID || colspan=4 | '''N''' * Weight || Weighting.
 
|-
 
|-
| 0x04 || colspan=2 | Object Index || colspan=2 | Material Index || colspan=2 | Bone index || '''Unknown''' || Draw polygon. Draws polygon
+
| 0x04 || 0x8 || colspan=2 | Object index || colspan=2 | Material index || colspan=2 | Bone index || Priority || colspan=2 {{Unknown-left|None}} ||Draw polygon.
 
|-
 
|-
| 0x05 || colspan=2 | Weight ID || colspan=2 | Weight index || colspan=3 | None || indexing
+
| 0x05 || 0x5 || colspan=2 | Matrix ID || colspan=2 | Weight index || colspan=5 {{Unknown-left|None}} || Indexing.
 
|-
 
|-
 +
| 0x06 || 0x5 || colspan=2 | To matrix || colspan=2 | From matrix || colspan=5 {{Unknown-left|None}} || Duplicate matrix.
 
|}
 
|}
  
=== Section 1 - Bones ===  
+
=== Section 1 - Bones ===
The bone files are used to describe the structure of polygons within the model, in order to allow animation. It is also used in [[Mario Kart Wii]] by map_model.brres to describe map placement. It is still not completely understood. <br />
+
The bone files are used to describe the structure of polygons within the model, in order to allow [[CHR0 (File Format)|CHR0]] animations. It is also used in [[Mario Kart Wii]] by map_model.brres to describe the map placement in courses.
The bones obey a tree structure, using the parent, first child, next child and previous child offsets to point to other bones in the tree. Most files have their first bone named the same as the entire MDL0 file, and having no transformation, and use child bones to perform transformations. 0 means no bone for these offsets.
+
 
 +
The bones obey a tree structure, using the parent, first child, next child and previous child offsets to point to other bones in the tree. 0 means no bone for these offsets.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Length (0xD0)
+
| 0x00 || UInt32 || '''Length''' of data structure (0xD0).
 
|-
 
|-
| 0x04 || 4 || MDL0 Offset
+
| 0x04 || Int32 || '''MDL0 offset'''.
 
|-
 
|-
| 0x08 || 4 || Name Offset
+
| 0x08 || Int32 || '''Name offset'''.
 
|-
 
|-
| 0x0C || 4 || Index
+
| 0x0C || UInt32 || '''Index'''.
 
|-
 
|-
| 0x10 || 4 || ID
+
| 0x10 || UInt32 || '''ID'''.
 
|-
 
|-
| 0x14 || 4 || '''Unknown Flags''' (0x31f typical)
+
| 0x14 || UInt32 || '''Flags'''.
 +
{| class="wikitable"
 +
! Bit !! f !! e !! d !! c !! b !! a !! 9 !! 8
 
|-
 
|-
| 0x18 || 4 || '''Unknown'''
+
! Meaning
 +
| colspan="5" {{Unknown-left|'''Unused'''}} || Is a Child of Billboard Bone || Is Display Matrix || Is Visible
 
|-
 
|-
| 0x1C || 4 || '''Unknown'''
+
! Bit !! 7 !! 6 !! 5 !! 4 !! 3 !! 2 !! 1 !! 0
 
|-
 
|-
| 0x20 || 12 || Scale (float3)
+
! Meaning
 +
| Disable Classic Scale || Apply Child Scale Compensate || Apply Scale Compensate || Scale Uniform || Scale Isotropic || Rotation Isotropic || Translation Isotropic || Use Identity
 +
|}
 +
|-
 +
| 0x18 || UInt32 || '''Billboard setting'''.
 +
* 0x0000 = None.
 +
* 0x0001 = Influenced by rotation of the parent node. The Z-axis direction is parallel to the camera lens axis.
 +
* 0x0002 = Influenced by rotation of the parent node. The Z-axis direction points toward the camera direction.
 +
* 0x0003 = Not influenced by the rotation of the parent node and restricted by the camera's Up vector. The Z-axis direction is parallel to the camera lens axis.
 +
* 0x0004 = Not influenced by the rotation of the parent node and restricted by the camera's Up vector. The Z-axis direction points toward the camera direction.
 +
* 0x0005 = Influenced by the rotation of the parent node and rotates only around the Y-axis. The Z-axis direction is parallel to the camera lens axis.
 +
* 0x0006 = Influenced by the rotation of the parent node and rotates only around the Y-axis. The Z-axis direction points toward the camera direction.
 +
|-
 +
| 0x1C || UInt32 || Billboard transformation of this bone if parent is a Billboard bone.
 
|-
 
|-
| 0x2C || 12 || Rotation (float3)
+
| 0x20 || Float[3] || A '''3D scaling vector'''
 
|-
 
|-
| 0x38 || 12 || Translation (float3)
+
| 0x2C || Float[3] || A '''[[3D rotation vector]]''' (in degrees).
 
|-
 
|-
| 0x44 || 12 || Minimum (float3)
+
| 0x38 || Float[3] || A '''3D translation vector'''.
 
|-
 
|-
| 0x50 || 12 || Maximum (float3)
+
| 0x44 || Float[3] || Bounding volume minimum.
 
|-
 
|-
| 0x5C || 4 || Parent Offset
+
| 0x50 || Float[3] || Bounding volume maximum.
 
|-
 
|-
| 0x60 || 4 || First Child Offset
+
| 0x5C || Int32 || '''Parent''' offset.
 
|-
 
|-
| 0x64 || 4 || Next Sibling Offset
+
| 0x60 || Int32 || '''First Child''' offset.
 
|-
 
|-
| 0x68 || 4 || Previous Sibling Offset
+
| 0x64 || Int32 || '''Next Sibling''' offset.
 
|-
 
|-
| 0x6C || 4 || '''Unknown'''
+
| 0x68 || Int32 || '''Previous Sibling''' offset.
 
|-
 
|-
| 0x70 || 48 || Tranformation Matrix (float4x3)
+
| 0x6C || Int32 || '''User Data''' offset.
 
|-
 
|-
| 0xA0 || 48 || Inverse Matrix (float4x3)
+
| 0x70 || MTX34 || '''Transformation matrix''', 12 floats organized in 3 rows with 4 column values. It is a clockwise [[wikipedia:Rotation matrix#General rotations|Rotation matrix]] with Euler angles and x-y-z convention. A fourth matrix line is assumed to always be "0 0 0 1", but not stored. The matrix can be calculated by '''Scale''' (0x20), '''Rotation''' (0x2c) and '''Translation''' (0x38).
 +
 
 +
All tests to modify the matrix did not have any impact. It seems, that the matrix is calculated after loading.
 +
|-
 +
| 0xA0 || MTX34 || This is the '''Inverse matrix''' of '''Transformation matrix''' (0x70), organised in the same way. Again, the fourth matrix line is assumed to always be "0 0 0 1" without storing the data.
 +
 
 +
All tests to modify the matrix did not have any impact. It seems, that the matrix is calculated after loading.
 
|-
 
|-
 
|}
 
|}
All offsets are relative to the start of the file.<br />
+
 
=== Section 2 - Verticies ===
+
All offsets are relative to the start of the file.
The vertex sections contain information on the veritices in the model. Each polygon specifies which vertex group it is going to use, and indexes the items within.
+
 
 +
=== Section 2 - Vertices ===
 +
The vertex section contains information of the vertices in the model. Each polygon specifies which vertex group is it going to use, and indexes the items within.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Length
+
| 0x00 || UInt32 || Length.
 
|-
 
|-
| 0x04 || 4 || MDL0 Offset
+
| 0x04 || Int32 || MDL0 offset.
 
|-
 
|-
| 0x08 || 4 || Data Offset
+
| 0x08 || Int32 || Data offset.
 
|-
 
|-
| 0x0C || 4 || Name Offset
+
| 0x0C || Int32 || Name offset.
 
|-
 
|-
| 0x10 || 4 || Index
+
| 0x10 || UInt32 || Index.
 
|-
 
|-
| 0x14 || 4 || Has Bounds
+
| 0x14 || UInt32 || Component count.
 +
{| class="wikitable"
 +
! Enum !! Size !! Description.
 +
|-
 +
| 0x0 || Format*2 || XY position.
 +
|-
 +
| 0x1 || Format*3 || XYZ position.
 +
|}
 
|-
 
|-
| 0x18 || 4 || Format (data type)
+
| 0x18 || UInt32 || Format (data type):
|-
+
{| class="wikitable"
| 0x1C || 1 || Divisor
+
! Format !! Stride !! Description
 +
|-
 +
| 0x0 || 0x3 || UInt8
 +
|-  
 +
| 0x1 || 0x3 || Int8
 +
|-
 +
| 0x2 || 0x6 || UInt16
 +
|-
 +
| 0x3 || 0x6 || Int16
 +
|-
 +
| 0x4 || 0xc || Float
 +
|}
 +
For all formats except float, the value is divided by 2 ^ divisor.
 
|-
 
|-
| 0x1D || 1 || Stride
+
| 0x1C || Byte || Divisor.
 
|-
 
|-
| 0x1E || 2 || Vertex Count
+
| 0x1D || Byte || Stride.
 
|-
 
|-
| 0x20 || 12 || Minimum (float3)
+
| 0x1E || UInt16 || Vertex count.
 
|-
 
|-
| 0x2C || 12 || Maximum (float3)
+
| 0x20 || Float[3] || Bounding volume minimum.
 
|-
 
|-
 +
| 0x2C || Float[3] || Bounding volume maximum.
 
|}
 
|}
 +
 
All offsets are relative to the start of the file.<br />
 
All offsets are relative to the start of the file.<br />
After the header, at the data offset (0x40 typical) is the vertex data. The format values are given below. For all formats except float, the value is divided by 2 ^ divisor.
+
After the header, at the data offset (0x40 typically) there is vertex data.
 +
 
 +
=== Section 3 - Normals ===
 +
The normal section contains information of the normals in the model. Each polygon specifies which normal group is it going to use, and indexes the items within.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
! Format !! Stride !! Description
+
! Offset !! Size !! Description
 +
|-
 +
| 0x00 || UInt32 || Length.
 +
|-
 +
| 0x04 || Int32 || MDL0 offset.
 +
|-
 +
| 0x08 || Int32 || Data offset.
 +
|-
 +
| 0x0C || Int32 || Name offset.
 +
|-
 +
| 0x10 || UInt32 || Index.
 +
|-
 +
| 0x14 || UInt32 || Component count.
 +
{| class="wikitable"
 +
! Enum !! Size !! Description
 +
|-
 +
| 0x0 || Format*3 || Normal.
 +
|-
 +
| 0x1 || Format*9 || Normal Bi-normal Tangent.
 
|-  
 
|-  
| 0x0 || 0x3 || u8
+
| 0x2 || Format*3 || Normal or Bi-normal or Tangent.
 +
|}
 +
|-
 +
| 0x18 || UInt32 || Format (data type):
 +
{| class="wikitable"
 +
! Enum !! Stride !! Description
 
|-  
 
|-  
| 0x1 || 0x3 || s8
+
| 0x0 || 0x3 || UInt8
 
|-  
 
|-  
| 0x2 || 0x6 || u16
+
| 0x1 || 0x3 || Int8
 
|-  
 
|-  
| 0x3 || 0x6 || s16
+
| 0x2 || 0x6 || UInt16
 
|-  
 
|-  
| 0x4 || 0xc || float
+
| 0x3 || 0x6 || Int16
 
|-  
 
|-  
 +
| 0x4 || 0xc || Float
 
|}
 
|}
 +
For all formats except float, the value is divided by 2 ^ divisor.
 +
|-
 +
| 0x1C || Byte || Divisor.
 +
|-
 +
| 0x1D || Byte || Stride.
 +
|-
 +
| 0x1E || Uint16 || Normal count.
 +
|}
 +
 +
All offsets are relative to the start of the file. After the header at the data offset (0x20 typically) there is normal data.
 +
 +
=== Section 4 - Colors ===
 +
The color section contains information of the colors in the model. Each polygon specifies which color group(s) is it going to use, and indexes the items within.
  
=== Section 3 - Normals ===
 
The normal sections contain information on the normals in the model. Each polygon specifies which normal group it is going to use, and indexes the items within.
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Length
+
| 0x00 || UInt32 || Length.
 
|-
 
|-
| 0x04 || 4 || MDL0 Offset
+
| 0x04 || Int32 || MDL0 offset.
 
|-
 
|-
| 0x08 || 4 || Data Offset
+
| 0x08 || Int32 || Data offset.
 
|-
 
|-
| 0x0C || 4 || Name Offset
+
| 0x0C || Int32 || Name offset.
 
|-
 
|-
| 0x10 || 4 || Index
+
| 0x10 || UInt32 || Index.
 
|-
 
|-
| 0x14 || 4 || Has Bounds (usu 0)
+
| 0x14 || UInt32 || Component count.
|-
+
{| class="wikitable"
| 0x18 || 4 || Format (data type)
+
! Enum !! Size !! Description
|-
+
|-  
| 0x1C || 1 || Divisor
+
| 0x0 || Format (0, 1, or 2) || RGB color.
|-
+
|-  
| 0x1D || 1 || Stride
+
| 0x1 || Format (3, 4, or 5) || RGBA color.
|-
+
|}
| 0x1E || 2 || Normal Count
+
Both component types can range in byte sizes from 2 to 4.
 
|-
 
|-
|}
+
| 0x18 || UInt32 || Format
All offsets are relative to the start of the file.<br />
 
After the header, at the data offset (0x20 typical) is the normal data. The format values are given below. For all formats except float, the value is divided by 2 ^ divisor.
 
 
{| class="wikitable"
 
{| class="wikitable"
! Format !! Stride !! Description
+
! Enum !! Stride !! Description !! Red !! Green !! Blue !! Alpha
 
|-  
 
|-  
| 0x0 || 0x3 || u8
+
| 0x0 || 0x2 || RGB565 || 5 bits || 6 bits || 5 bits || &ndash;
 
|-  
 
|-  
| 0x1 || 0x3 || s8
+
| 0x1 || 0x3 || RGB8 (RGB24) || 8 bits || 8 bits || 8 bits || &ndash;
 
|-  
 
|-  
| 0x2 || 0x6 || u16
+
| 0x2 || 0x4 || RGBX8 (RGBX32) X values discarded. || 8 bits || 8 bits || 8 bits || 8 bits (ignored)
 
|-  
 
|-  
| 0x3 || 0x6 || s16
+
| 0x3 || 0x2 || RGBA4 (RGBA16) || 4 bits || 4 bits || 4 bits || 4 bits
 
|-  
 
|-  
| 0x4 || 0xc || float
+
| 0x4 || 0x3 || RGBA6 (RGBA24) || 6 bits || 6 bits || 6 bits || 6 bits
 
|-  
 
|-  
 +
| 0x5 || 0x4 || RGBA8 (RGBA32) || 8 bits || 8 bits || 8 bits || 8 bits
 
|}
 
|}
 
=== Section 4 - Colors ===
 
The color sections contain information on the colors in the model. Each polygon specifies which color group(s) it is going to use, and indexes the items within.
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
 
|-
 
|-
| 0x00 || 4 || Length
+
| 0x1C || Byte || Stride.
 
|-
 
|-
| 0x04 || 4 || MDL0 Offset
+
| 0x1D || Byte || Padding.
 
|-
 
|-
| 0x08 || 4 || Data Offset
+
| 0x1E || UInt16 || Color count.
 
|-
 
|-
| 0x0C || 4 || Name Offset
+
|}
|-
+
 
| 0x10 || 4 || Index
+
All offsets are relative to the start of the file. After the header at the data offset (0x20 typically) there is color data.
 +
 
 +
=== Section 5 - Texture Coordinates ===
 +
The texture coordinate section contains information of the texture UV coordinates in the model. Each polygon specifies which texture coordinate group(s) is it going to use, and indexes the items within.
 +
 
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 
|-
 
|-
| 0x14 || 4 || Has Alpha
+
| 0x00 || UInt32 || Length.
 
|-
 
|-
| 0x18 || 4 || Format
+
| 0x04 || Int32 || MDL0 offset.
 
|-
 
|-
| 0x1C || 1 || Stride
+
| 0x08 || Int32 || Data offset.
 
|-
 
|-
| 0x1D || 1 || '''Unknown'''
+
| 0x0C || Int32 || Name offset.
 
|-
 
|-
| 0x1E || 2 || Color Count
+
| 0x10 || UInt32 || Index.
 
|-
 
|-
|}
+
| 0x14 || UInt32 || Component count.
All offsets are relative to the start of the file.<br />
 
After the header, at the data offset (0x20 typical) is the normal data. The format values are given below.
 
 
{| class="wikitable"
 
{| class="wikitable"
! Format !! Stride !! Description
+
! Enum !! Size !! Description
 
|-  
 
|-  
| 0x0 || 0x2 || RGB565
+
| 0x0 || Format*1 || S coord.
 
|-  
 
|-  
| 0x1 || 0x3 || RGB8 (RGB24)
+
| 0x1 || Format*2 || ST coord.
 +
|}
 +
|-
 +
| 0x18 || UInt32 || Format (data type):
 +
{| class="wikitable"
 +
! Enum !! Stride !! Description
 
|-  
 
|-  
| 0x2 || 0x4 || RGBX8 (RGBX32) X values discarded.
+
| 0x0 || 0x2 || UInt8
 
|-  
 
|-  
| 0x3 || 0x2 || RGBA4 (RGBA16)
+
| 0x1 || 0x2 || Int8
 
|-  
 
|-  
| 0x4 || 0x3 || RGBA6 (RGBA24)
+
| 0x2 || 0x4 || UInt16
 
|-  
 
|-  
| 0x5 || 0x4 || RGBA8 (RGBA32)
+
| 0x3 || 0x4 || Int16
 
|-  
 
|-  
 +
| 0x4 || 0x8 || Float
 +
|}
 +
For all formats except float, the value is divided by 2 ^ divisor.
 +
|-
 +
| 0x1C || Byte || Divisor.
 +
|-
 +
| 0x1D || Byte || Stride.
 +
|-
 +
| 0x1E || UInt16 || Texture coordinate count.
 +
|-
 +
| 0x20 || Float[2] || Bounding volume minimum.
 +
|-
 +
| 0x28 || Float[2] || Bounding volume maximum.
 
|}
 
|}
  
=== Section 5 - Texture Coordinates ===
+
All offsets are relative to the start of the file. After the header at the data offset (0x40 typically) there is texture coordinate data.
The texture coordinate sections contain information on the texture coordinates in the model. Each polygon specifies which texture coordinate group(s) it is going to use, and indexes the items within.
+
 
 +
=== Section 6 - Fur Vectors ===
 +
: ''Seen in "smallbard.mdl0" v11 (Ridley's pre-mature form) from [[Super Smash Bros. Brawl]].''
 +
 
 +
This section is assumed to draw fur bases on vectors at specific points on the model's surface.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Length
+
| 0x00 || UInt32 || Length.
 
|-
 
|-
| 0x04 || 4 || MDL0 Offset
+
| 0x04 || Int32 || MDL0 offset.
 
|-
 
|-
| 0x08 || 4 || Data Offset
+
| 0x08 || Int32 || Data offset.
 
|-
 
|-
| 0x0C || 4 || Name Offset
+
| 0x0C || Int32 || Name offset.
 
|-
 
|-
| 0x10 || 4 || Index
+
| 0x10 || UInt32 || Index.
 
|-
 
|-
| 0x14 || 4 || Has Bounds
+
| 0x14 || UInt32 || Fur Vector count.
 +
|}
 +
 
 +
Following this, there are (float3) vectors.
 +
 
 +
=== Section 7 - Fur Layer Positions ===
 +
This section is assumed to contain the shelling vectors for the fur vectors section, which is assumed to be used to draw a line-strip from each vector.
 +
 
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 
|-
 
|-
| 0x18 || 4 || Format (data type)
+
| 0x00 || UInt32 || Length.
 
|-
 
|-
| 0x1C || 1 || Divisor
+
| 0x04 || Int32 || MDL0 offset.
 
|-
 
|-
| 0x1D || 1 || Stride
+
| 0x08 || Int32 || Data offset.
 
|-
 
|-
| 0x1E || 2 || Texture Coordinate Count
+
| 0x0C || Int32 || Name offset.
 
|-
 
|-
| 0x20 || 8 || Minimum (float2)
+
| 0x10 || UInt32 || Index.
 
|-
 
|-
| 0x28 || 8 || Maximum (float2)
+
| 0x14 || UInt32 || Component count.
 +
{| class="wikitable"
 +
! Enum !! Size !! Description.
 +
|-
 +
| 0x0 || Format*2 || XY position.
 +
|-
 +
| 0x1 || Format*3 || XYZ position.
 +
|}
 
|-
 
|-
|}
+
| 0x18 || UInt32 || Format (data type):
All offsets are relative to the start of the file.<br />
 
After the header, at the data offset (0x40 typical) is the texture coordinate data. The format values are given below. For all formats except float, the value is divided by 2 ^ divisor.
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Format !! Stride !! Description
 
! Format !! Stride !! Description
 
|-  
 
|-  
| 0x0 || 0x2 || u8
+
| 0x0 || 0x3 || UInt8
 
|-  
 
|-  
| 0x1 || 0x2 || s8
+
| 0x1 || 0x3 || Int8
 
|-  
 
|-  
| 0x2 || 0x4 || u16
+
| 0x2 || 0x6 || UInt16
 
|-  
 
|-  
| 0x3 || 0x4 || s16
+
| 0x3 || 0x6 || Int16
|-
 
| 0x4 || 0x8 || float
 
 
|-  
 
|-  
 +
| 0x4 || 0xc || Float
 +
|}
 +
For all formats except float, the value is divided by 2 ^ divisor.
 +
|-
 +
| 0x1C || Byte || Divisor.
 +
|-
 +
| 0x1D || Byte || Stride.
 +
|-
 +
| 0x1E || UInt16 || Vertex Count in fur layer.
 +
|-
 +
| 0x20 || UInt32 || Number of fur layers.
 +
|-
 +
| 0x24 || UInt32 || Offset to fur layer.
 
|}
 
|}
 +
 +
 +
Following this there is layer-vector data (data_type * vector_count * layer_count). The layer's size may mean there is padding in some cases.
 +
 +
Actual tests for these fur sections have not been performed yet.
 +
It is unsure if the vector positioning here is local to the fur vectors (like normals), or globally oriented.
  
 
=== Section 8 - Materials ===
 
=== Section 8 - Materials ===
The materials sections contain information about the texturing of models. The draw lists commands specify which polygons are linked to which materials.
+
The material section contains information about the texturing of models. The draw list commands specify which polygons are linked to which materials.
  
The following table describes the general layout of '''MDL v11 section 8'''.
+
The following table describes the general layout of '''MDL0 v11 section 8'''.
 
All [[Mario Kart Wii]] files use exactly this layout:
 
All [[Mario Kart Wii]] files use exactly this layout:
  
Line 376: Line 549:
 
|}
 
|}
  
==== Basic data structure ====
+
==== Basic Data Structure ====
 
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Length
+
| 0x00 || UInt32 || Length.
 +
|-
 +
| 0x04 || Int32 || MDL0 offset.
 +
|-
 +
| 0x08 || Int32 || Name offset.
 +
|-
 +
| 0x0C || UInt32 || Index.
 +
|-
 +
| 0x10 || UInt32 || Material Flags.<br>
 +
'''A'''xxxxxxx xxxxxxxx xxxxxxxx '''BCDEFGHI'''.
 +
* '''A''' - XLU Material.
 +
* '''B''' - Do not send texture matrix data.
 +
* '''C''' - Do not send texture coordinate data.
 +
* '''D''' - Do not send generator mode data.
 +
* '''E''' - Do not send lighting channel data.
 +
* '''F''' - Do not send indirect matrix data.
 +
* '''G''' - Do not send texture coordinate scale data.
 +
* '''H''' - Do not send TEV color data.
 +
* '''I''' - Do not send pixel display data.
 +
|-
 +
| 0x14 || Byte || Texgens.
 +
|-
 +
| 0x15 || Byte || Light channels.
 +
|-
 +
| 0x16 || Byte || Shader stages.
 +
|-
 +
| 0x17 || Byte || Indirect textures.
 +
|-
 +
| 0x18 || UInt32 || Culling.
 +
{| class="wikitable"
 +
! ID !! Description
 +
|-
 +
| 0x0x || None.
 +
|-
 +
| 0x01 || Front.
 +
|-
 +
| 0x02 || Back.
 +
|-
 +
| 0x03 || All.
 +
|}
 +
|-
 +
| 0x1C || Byte || Depth test.
 +
|-
 +
| 0x1D || Byte || Lightset Index.
 
|-
 
|-
| 0x04 || 4 || MDL0 Offset
+
| 0x1E || Byte || Fog Index.
 
|-
 
|-
| 0x08 || 4 || Name Offset
+
| 0x1F || Byte || Padding.
 
|-
 
|-
| 0x0C || 4 || Index (0..0x1e)
+
| 0x20 || Byte[4] || Indirect Method.  
 +
{| class="wikitable"
 +
! ID !! Description
 
|-
 
|-
| 0x10 || 4 || '''Unknown''' (0x0 or 0x80000000)
+
| 0 || Wrap
 
|-
 
|-
| 0x14 || 1 || Layer Count
+
| 1 || Normal map
 
|-
 
|-
| 0x15 || 1 || '''Unknown''' (1 or 2)
+
| 2 || Normal map specular
 
|-
 
|-
| 0x16 || 1 || Direct Layer Count
+
| 3 || Fur
 
|-
 
|-
| 0x17 || 1 || Indirect Layer Count
+
| 4 || Reserved
 
|-
 
|-
| 0x18 || 4 || '''Unknown''' (0,1 or 2)
+
| 5 || Reserved
 
|-
 
|-
| 0x1C || 1 || '''Unknown''' (0 or 1)
+
| 6 || User 0
 
|-
 
|-
| 0x1D || 1 || '''Unknown''' (0x7f or 0xff)
+
| 7 || User 1
 +
|}
 
|-
 
|-
| 0x1E || 1 || '''Unknown''' (0x00 or 0xff)
+
| 0x24 || Byte[4] || Light normal map reference, used by indirect stages.
 
|-
 
|-
| 0x1F || 1 || '''Unknown''' (always 0)
+
| 0x28 || Int32 || Shader offset.
 
|-
 
|-
| 0x20 || 4 || '''Unknown''' (always 0)
+
| 0x2C || UInt32 || Amount of textures.
 
|-
 
|-
| 0x24 || 4 || '''Unknown''' (always 0xffffffff)
+
| 0x30 || Int32 || Layer offset.
 
|-
 
|-
| 0x28 || 4 || Node Offset (pointer to section 9 data)
+
| 0x34 || Int32 || Fur data offset. (version 10 and 11 MDL0s). User Data (version 8 and 9 MDL0s).
 
|-
 
|-
| 0x2C || 4 || Layer Count
+
| 0x38 || Int32 || Display list offset (version 8 and 9 MDL0s). User Data (version 10 and 11 MDL0s).
 
|-
 
|-
| 0x30 || 4 || Layer Offset
+
| 0x3c || Int32 || Display list offset (version 10 and 11 MDL0s).
 
|-
 
|-
| 0x34 || 4 || '''Unknown''' (always 0)
+
| 0x40 || UInt32 || Bitflag. Used texture maps. Bit 0 (LSB) means texture map 0 is used, bit 1 - texture map 1 etc.
 
|-
 
|-
| 0x38 || 4 || '''Unknown''' (always 0)
+
| 0x44 || Byte[8][32] || Precompiled code space containing texture information.
 
|-
 
|-
| 0x3c || 4 || Shader Offset
+
| 0x144 || UInt32 || Bitflag. Used palletes. Bit 0 (LSB) means pallete 0 is used, bit 1 - pallete 1 etc.
 
|-
 
|-
| 0x40 || 360 || '''Unknown''' (always 0)
+
| 0x148 || Byte[8][12] || Precompiled code space containing palette information.
 
|-
 
|-
| 0x1a8 || 4/8*4 || 4 bit Layer Flags value; 1 for each layer with the msb containing the last layer.
+
| 0x1a8 || UInt32 || Bit flag.
 
{| class="wikitable"
 
{| class="wikitable"
! Bit (lsb = 0) 2!! Description
+
! Bit !! Description
 
|-
 
|-
| 0 || Enable Layer
+
| 0 || Enable layer.
 
|-
 
|-
| 1 || Scaling Fixed
+
| 1 || Scale fixed.
 
|-
 
|-
| 2 || Rotation Fixed
+
| 2 || Rotation fixed.
 
|-
 
|-
| 3 || Translation Fixed
+
| 3 || Translation fixed.
|-
 
 
|}
 
|}
 
|-
 
|-
| 0x1ac || 4 || '''Unknown''' (0 or 2)
+
| 0x1ac || UInt32 || Texture matrix mode
 +
{| class="wikitable"
 +
! Value !! Description
 +
|-
 +
| 0 || Maya
 
|-
 
|-
| 0x1b0 || 20 * 8 || 8 copies of the following structure <br />
+
| 1 || XSI
 +
|-
 +
| 2 || 3DS Max
 +
|}
 +
|-
 +
| 0x1b0 || 20 * 8 || 8 copies of the following structure: <br />
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 8 || float2 Coordinate Scale
+
| 0x00 || Float[2] || Scale coordinate.
 
|-
 
|-
| 0x08 || 4 || float Coordinate Rotation
+
| 0x08 || Float || Rotation coordinate.
 
|-
 
|-
| 0x0C || 8 || float2 Coordinate Translation
+
| 0x0C || Float[2] || Translation coordinate.
|-
 
 
|}
 
|}
 
|-
 
|-
| 0x250 || 52 * 8 || 8 copies of the following structure <br />
+
| 0x250 || 52 * 8 || '''Texture matrix''' - 8 copies of the following structure: <br />
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 1 || '''Unknown''' (0xff typical)
+
| 0x00 || SByte || SCN0 camera reference
 +
|-
 +
| 0x01 || SByte || SCN0 light reference
 +
|-
 +
| 0x02 || Byte  || Map mode:
 +
{| class="wikitable"
 +
! Value !! Description
 +
|-
 +
| 0 || Texture coordinates
 
|-
 
|-
| 0x01 || 1 || '''Unknown''' (0xff typical)
+
| 1 || EnvCamera
 
|-
 
|-
| 0x02 || 1 || '''Unknown''' (0x0 typical)
+
| 2 || Projection
 
|-
 
|-
| 0x03 || 1 || '''Unknown''' (0x1 typical)
+
| 3 || EnvLight
 
|-
 
|-
| 0x04 || 48 || float4x3 '''Unknown Matrix'''
+
| 4 || EnvSpec
|-
 
 
|}
 
|}
 
|-
 
|-
| 0x3f0 || 4 || '''Unknown''' (0x3f typical)
+
| 0x03 || Byte || Enable identity matrix effect
 +
|-
 +
| 0x04 || MTX34 || Texture matrix.
 +
|}
 
|-
 
|-
| 0x3f4 || 16 * 2 || 2 copies of the following structure <br />
+
| 0x3f0 || 20 * 2 || '''Lighting channels:'''<br />
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || '''Unknown RGBA Color'''
+
| 0x00 || UInt32 || Flags
 +
{| class="wikitable"
 +
! Bit !! Description
 +
|-
 +
| 0 || Material color enabled.
 +
|-
 +
| 1 || Material alpha enabled.
 +
|-
 +
| 2 || Ambient color enabled.
 
|-
 
|-
| 0x04 || 4 || '''Unknown RGBA Color'''
+
| 3 || Ambient alpha enabled.
 
|-
 
|-
| 0x08 || 4 || '''Unknown'''
+
| 4 || Raster color enabled.
 
|-
 
|-
| 0x0c || 4 || '''Unknown'''
+
| 5 || Raster alpha enabled.
|-
 
 
|}
 
|}
 
|-
 
|-
 +
| 0x04 || RGBA || Material color.
 +
|-
 +
| 0x08 || RGBA || Ambient color.
 +
|-
 +
| 0x0c || UInt32 || Color light channel control.
 +
|-
 +
| 0x10 || UInt32 || Alpha light channel control.
 
|}
 
|}
 +
|}
 +
 
All offsets are relative to the start of the file.
 
All offsets are relative to the start of the file.
  
==== Layers ====
+
==== Texture References ====
Normally immediately after this data is the layer information. It is at the layer offset. Each lay information structure is as follows.<br />
+
Normally, immediately after this data, there is layer information. It is at the layer offset. Each layer information structure is described as below.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Name Offset
+
| 0x00 || Int32 || Name offset, used as link into section 11.
 
|-
 
|-
| 0x04 || 4 || '''Unknown''' (0x0 typical)
+
| 0x04 || Int32 || Palette name offset, used as link into section 12.
 
|-
 
|-
| 0x08 || 4 || '''Unknown''' (0x0 typical)
+
| 0x08 || Int32 || Texture data offset.* 0x0 typically.
 
|-
 
|-
| 0x0c || 4 || '''Unknown''' (0x0 typical)
+
| 0x0c || Int32 || Palette data offset.* 0x0 typically.
 
|-
 
|-
| 0x10 || 4 || '''Unknown''' (0x0 typical)
+
| 0x10 || UInt32 || Texture data ID, indexes an entry in the texture information list.
 
|-
 
|-
| 0x14 || 4 || '''Unknown''' (0x0 typical)
+
| 0x14 || UInt32 || Palette data ID, indexes an entry in the palette information list.
 
|-  
 
|-  
| 0x18 || 4 || X Texture Address Settings
+
| 0x18 || UInt32 || U texture wrapping mode.
 
|-  
 
|-  
| 0x1c || 4 || Y Texture Address Settings
+
| 0x1c || UInt32 || V texture wrapping mode.
 
|-
 
|-
| 0x20 || 4 || '''Unknown''' (0x1 typical)
+
| 0x20 || UInt32 || Minification texture filtering.
 +
{| class="wikitable"
 +
! Enum !! Description
 
|-
 
|-
| 0x24 || 4 || '''Unknown''' (0x1 typical)
+
| 0x00 || Nearest
 
|-
 
|-
| 0x28 || 4 || float '''Unknown''' (0 typical)
+
| 0x01 || Linear
 
|-
 
|-
| 0x2c || 4 || '''Unknown''' (0x0 typical)
+
| 0x02 || Nearest Mipmap Nearest
 
|-
 
|-
| 0x30 || 4 || '''Unknown''' (0x0 typical)
+
| 0x03 || Linear Mipmap Nearest
 +
|-
 +
| 0x04 || Nearest Mipmap Linear
 +
|-
 +
| 0x05 || Linear Mipmap Linear
 +
|}
 +
|-
 +
| 0x24 || UInt32 || Magnification texture filtering.
 +
{| class="wikitable"
 +
! Enum !! Description
 +
|-
 +
| 0x00 || Nearest
 +
|-
 +
| 0x01 || Linear
 +
|}
 +
|-
 +
| 0x28 || Float || LOD bias.
 +
|-
 +
| 0x2c || UInt32 || Max Anisotropy filtering. Can improve texture quality, but not recommended to use on many materials.
 +
{| class="wikitable"
 +
! Enum !! Description
 +
|-
 +
| 0x00 || One
 +
|-
 +
| 0x01 || Two
 +
|-
 +
| 0x02 || Four
 +
|}
 +
|-
 +
| 0x30 || Byte || Clamp bias.
 +
|-
 +
| 0x31 || Byte || Texel interpolate.
 +
|-
 +
| 0x32 || Byte[2] || Padding.
 
|-  
 
|-  
 
|}
 
|}
All offsets are relative to the start of the layer section.<br />
+
* These offsets are calculated by the game during track load, whether or not non-zero values are kept is unknown.
The X and Y texture settings values are given below.<br />
+
 
 +
Wrapping modes
 
{| class="wikitable"
 
{| class="wikitable"
 
! Settings !! Description
 
! Settings !! Description
 
|-  
 
|-  
| 0x0 || Clamp
+
| 0x0 || Clamp.
 
|-  
 
|-  
| 0x1 || Repeat
+
| 0x1 || Repeat.
 
|-  
 
|-  
| 0x2 || Mirror
+
| 0x2 || Mirror.
 +
|}
 +
==== Fur Data ====
 +
This section appears right after the texture references only if a material uses fur.
 +
{| class="wikitable"
 +
! Offset !! Type !! Description
 +
|-
 +
| 0x00 || Float || Maximum length to which fur can grow.
 +
|-
 +
| 0x04 || UInt32 || Number of fur layers.
 +
|-
 +
| 0x08 || UInt32 || Type of spacing between fur layers.
 +
{| class="wikitable"
 +
! Enum !! Description
 +
|-
 +
| 0x0 || Uniform interval.
 
|-  
 
|-  
 +
| 0x1 || More dense at tips.
 +
|}
 +
|-
 +
| 0x0C || Float || Alpha curvature parameter.
 +
|-
 +
| 0x10 || Float || Specular lighting curvature parameter.
 
|}
 
|}
  
 
==== Shader ====
 
==== Shader ====
 +
After the layer information (and padding to 0x20), there is always shader data directly at its offset. This is the [[Wii Graphics Code]], which describes how the material is created. It is split down into four basic sections.
  
Always after the layer information (and padding to 0x20) is the Shader. It is directly at the Shader offset. This is [[Wii Graphics Code]] which describes how the material is created. It is broken down into four basic sections.
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x000 || 0x20 || Mode Information
+
| 0x000 || 0x20 || Mode information.
 
|-
 
|-
| 0x020 || 0x80 || Tev Regs
+
| 0x020 || 0x80 || Tev color regs.
 
|-
 
|-
| 0x0a0 || 0x40 || Texture Transformations
+
| 0x0a0 || 0x40 || Indirect texture transformations.
 
|-
 
|-
| 0x0e0 || 0xa0 || Texture Matricies
+
| 0x0e0 || 0xa0 || Texture matrices.
|-
 
| 0x180 || colspan=2 | End of Shader.
 
 
|-
 
|-
 +
| 0x180 || colspan=2 | End of shader.
 
|}
 
|}
  
=== Section 9 - Material Nodes (TEV's) ===
+
=== Section 9 - TEVs ===
The material nodes section has information about how the color and texture information is to be combined in the wii graphics card. Each material has a link to a node structure. Several materials often use the same nodes. The structure is often referenced many times in the index group too. Most large MDL0 may only have three or four structures, but many more appear in the file tree due to repeats. The repeats always ensure that each material has a structure with the same name, which it links to.
+
This section has information about how the color and texture informations are combined in the Wii's GPU. Each material has a link to a TEV structure. Several materials often share the same TEV. The structure is often referenced many times in the index group too. Most large MDL0's may only have three or four structures, but many more appear in the file tree due to repeats. The repeats always ensure that each material has a structure with the same name, which it links to.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Length  
+
| 0x00 || UInt32 || Length.
|-
 
| 0x04 || 4 || MDL0 Offset
 
|-
 
| 0x08 || 4 || Index
 
|-
 
| 0x0c || 1 || Layer Count (material flag)
 
 
|-
 
|-
| 0x0d || 1 || Res0 (0x0 typical)
+
| 0x04 || Int32 || MDL0 offset.
 
|-
 
|-
| 0x0e || 1 || Res1 (0x0 typical)
+
| 0x08 || Int32 || Index.
 
|-
 
|-
| 0x0f || 1 || Res2 (0x0 typical)
+
| 0x0C || Byte || TEV Stage Count.
 
|-
 
|-
| 0x10 || 1 * 8 || [TRef0:TRef7] (0x0 typical, 0xff for unused layers)
+
| 0x0d || Byte[3] || Padding.
 
|-
 
|-
| 0x18 || 8 || Padding
+
| 0x10 || Byte[8] || [TexScale0:TexScale7] (0xff for unused references). Indices to a material layer.
 
|-
 
|-
 +
| 0x18 || Byte[8] || Padding.
 
|}
 
|}
All offsets are relative to the start of the file.<br />
+
 
After this section follows [[Wii Graphics Code]] which describes how information is transformed into colors by the graphics card. The length of this code is Length - 0x20.
+
All offsets are relative to the start of the file. After this section follows [[Wii Graphics Code]], which describes how information is transformed into colors by the graphics card. The length of this code is ''Length - 0x20''. Normally those commands control color and alpha blending, indirect texture mapping and color channel swapping.
  
 
=== Section 10 - Objects (Polygons) ===
 
=== Section 10 - Objects (Polygons) ===
 
The objects section describes how vertex data is combined optionally with colors, texture coordinates and normals, as well as bones and materials in order to produce the rendered model.
 
The objects section describes how vertex data is combined optionally with colors, texture coordinates and normals, as well as bones and materials in order to produce the rendered model.
 +
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Length
+
| 0x00 || 4 || Length.
 
|-
 
|-
| 0x04 || 4 || MDL0 Offset
+
| 0x04 || 4 || MDL0 offset.
 
|-
 
|-
| 0x08 || 4 || Bone Index (for single bone references) '''(-1 for table usage)'''
+
| 0x08 || 4 || Bone index (for single bone references) '''(-1 for table usage)'''.
 
|-
 
|-
| 0x0c || 4 || CP_Vtx (0x4400 typical)
+
| 0x0c || 4 || ''CP_Vtx'' (0x4400 typically).
 
|-
 
|-
| 0x10 || 4 || CP_Tex (0x2 typical)
+
| 0x10 || 4 || ''CP_Tex'' (0x2 typically).
 
|-
 
|-
| 0x14 || 4 || XF_Nor_Spec (0x11 typical)
+
| 0x14 || 4 || ''XF_Nor_Spec'' (0x11 typically).
 
|-
 
|-
| 0x18 || 4 || Vertex Declaration Size (0xe0)
+
| 0x18 || 4 || Vertex declaration size (0xe0).
 
|-
 
|-
| 0x1c || 4 || '''Unknown''' (0x80 typical)
+
| 0x1c || 4 || {{unknown-left|'''Unknown flags'''.}} 0x80 typically.
 
|-
 
|-
| 0x20 || 4 || Vertex Declaration Offset (0x68 typical)
+
| 0x20 || 4 || Vertex declaration offset (0x68 typically).
 
|-
 
|-
| 0x24 || 4 || Vertex Data Size
+
| 0x24 || 4 || Vertex data size.
 
|-
 
|-
| 0x28 || 4 || Vertex Data Size
+
| 0x28 || 4 || Vertex data size.
 
|-
 
|-
| 0x2c || 4 || Vertex Data Offset (0x13c typical)
+
| 0x2c || 4 || Vertex data offset (0x13c typically).
 
|-
 
|-
| 0x30 || 4 || XF_Flags (0x2a00 typical)
+
| 0x30 || 4 || ''XF_Flags'' (0x2a00 typically).
 
|-
 
|-
| 0x34 || 4 || '''Unknown''' (0x0 typical)
+
| 0x34 || 4 || {{Unknown-left|'''Unknown'''.}} 0x0 typically.
 
|-
 
|-
| 0x38 || 4 || Name Offset
+
| 0x38 || 4 || Name offset.
 
|-
 
|-
| 0x3c || 4 || Index
+
| 0x3c || 4 || Index.
 
|-
 
|-
| 0x40 || 4 || Vertex Count
+
| 0x40 || 4 || Vertex count.
 
|-
 
|-
| 0x44 || 4 || Face Count
+
| 0x44 || 4 || Face count.
 
|-
 
|-
| 0x48 || 2 || Vertex Group Index
+
| 0x48 || 2 || Vertex group index.
 
|-
 
|-
| 0x4a || 2 || Normal Group Index
+
| 0x4a || 2 || Normal group index.
 
|-
 
|-
| 0x4c || 2 * 2 || 2 Color Group Indicies
+
| 0x4c || 2 * 2 || 2 color group indices.
 
|-
 
|-
| 0x50 || 2 * 8 || 8 Texture Coordinate Group Indicies
+
| 0x50 || 2 * 8 || 8 texture coordinate group indices.
 
|-
 
|-
| 0x60 || 4 || '''Unknown''' (-1 typical) '''(Not seen in version 9 MDL0's)'''
+
| 0x60 || 4 || {{unknown-left|'''Unknown'''.}} -1 typically '''(not seen in version 9 MDL0's)'''.
 
|-
 
|-
| 0x64 || 4 || Bone table offset
+
| 0x64 || 4 || Bone table offset.
 +
|}
 +
 
 +
All offsets are relative to the start of the file, except the vertex declaration and vertex data offsets. The vertex declaration offset is relative to 0x20, itself. The vertex data offset is relative to 0x24. Normally directly after the header, there is a bone table at its offset. This table is only used in objects which use multiple bones, and therefore have a value of -1 in their bone offset field. The use of this table is still not fully understood.
 +
 
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 
|-
 
|-
 +
| 0x00 || 4 || Entry count.
 +
|-
 +
| 0x04 || 2 * Entry count || Bone ID.
 
|}
 
|}
All offsets are relative to the start of the file, except the vertex declaration and vertex data offsets. The vertex declaration offset is relative to 0x20, itself. The vertex data offset is relative to 0x24.<br />
+
 
Normally directly after the header, is the bone table. It is at the bone table offset. This table is only used in objects which use multiple bones, and therefore have a -1 in their bone offset field. The use of this table is still not fully understood.
+
After the bone table, there is vertex declaration. This is the [[Wii Graphics Code]], which describes the format of each vertex in the polygon. This is at the vertex declaration offset. After the vertex declaration, there is vertex code. This is also the Wii Graphics Code, which describes how the model is rendered. It contains commands such as triangle drawing. The indices of the points are also here.
 +
 
 +
=== Section 11 - Texture Links ===
 +
There is one texture link section for each texture used in the model. Each section contains a table with links (offset values) into material sections. These sections have no names.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Entry Count
+
| 0x00 || 4 || Entry count.
 
|-
 
|-
| 0x04 || 2 * Entry Count || Bone ID
+
| 0x04 || 8 * Entry count || Entry count copies of the following structure: <br />
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 
|-
 
|-
 +
| 0x00 || 4 || Offset relative to section start into a material section (#8).
 +
|-
 +
| 0x04 || 4 || Offset relative to section start into a material layer. The layer is part of the material section above.
 +
|}
 
|}
 
|}
After the bone table is the vertex declaration. This is [[Wii Graphics Code]] which describes the format of each vertex in the polygon. This is at the vertex declaration offset. <br/>
 
After the vertex declaration is the vertex code. This is [[Wii Graphics Code]] which describes how the model is rendered. It contains commands such as draw triangles. The indicies of the points are also here.
 
  
=== Section 11 - Texture Links ===
+
=== Section 12 - Palette Links ===
There is one texture link section for each texture used in the model. Each section contains a table with links (offset values) into material sections. These section has no names.
+
There is one palette link section for each palette used in the model. Each section contains a table with links (offset values) into material sections. These sections also have no names.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
 
|-
 
|-
| 0x00 || 4 || Entry Count
+
| 0x00 || 4 || Entry count.
 
|-
 
|-
| 0x04 || 8 * Entry Count || Entry count copies of the following structure <br />
+
| 0x04 || 8 * Entry count || Entry count copies of the following structure: <br />
 
{| class="wikitable"
 
{| class="wikitable"
 
! Offset !! Size !! Description
 
! Offset !! Size !! Description
Line 662: Line 985:
 
| 0x04 || 4 || Offset relative to section start into a material layer. The layer is part of the material section above.
 
| 0x04 || 4 || Offset relative to section start into a material layer. The layer is part of the material section above.
 
|}
 
|}
|-
 
 
|}
 
|}
All offsets are relative to the start of the file.<br />
 
  
 +
All offsets are relative to the start of the file.
 +
 +
== Tools ==
 +
The following tools can handle MDL0 files:
 +
* [[BrawlBox]], by Kryal & BlackJax.
 +
* [[BrawlCrate]], by soopercool101.
 +
* [[CTools]], by [[Chadderz]].
 +
* [[SZS Modifier]], by [[Chadderz]].
 +
* [[Wiimms SZS Tools]], by [[Wiimm]].
  
 +
== Links ==
 
{{BRRES links}}
 
{{BRRES links}}
[[category:File Format]]
+
[[Category:File Format/Wii]]

Latest revision as of 22:34, 21 February 2024

Overview

This article describes the Mario Kart Wii MDL0 file format, as found within BRRES files.

File Format

File Header

Offset Type Description
0x00 String The magic "MDL0" to identify the sub file. See »BRRES Sub Files« for other magics.
0x04 UInt32 Length of the sub file.
0x08 UInt32 Sub file version number. The number of sections (N) is dependent of this version number. See »BRRES Sub Files« for details.
0x0C Int32 Offset to outer BRRES File.
0x10 Int32[N] N section offsets. N is implied in the version number (offset 0x08).
0x10+N*4 Int32 String offset to the name of this sub file. This name equal to the name of the entry name of the BRRES Index Group pointing to this data.
0x14+N*4 End of this header
  • All offsets are relative to the start of the header.
  • Mario Kart Wii uses MDL0 v11 with (N=) 14 sections.
  • The section offsets point to BRRES Index Group structures for the directories, which in turn point to the actual data sections within the MDL0 file.
  • Sections are linked by names. The names are stored in a common string pool for all BRRES sub files. MDL0 itself stores only 32-bit offsets into the common string pool.

The meaning of each section is defined by numbers as below:

Section Description
0 Draw lists.
1 Bones.
2 Vertices.
3 Normals.
4 Colors.
5 Texture coordinates.
6 Fur vectors (seen in v10+ MDL0's).
7 Fur layers (seen in v10+ MDL0's).
8 Materials.
9 TEV's (shader-like operations).
10 Objects (polygons).
11 Texture links.
12 Palette links (not seen in Mario Kart Wii).
13 User Data. Not seen in Mario Kart Wii or v9 MDL0's.

MDL0 Header

Following the section offsets, there is a MDL0 header structure.

Offset Size Description
0x00 UInt32 Header length (0x40).
0x04 Int32 File header offset.
0x08 UInt32 Scaling Mode
Value Description
0x0 Standard
0x1 SoftImage
0x2 Maya
0x0C UInt32 Texture Matrix Mode
Value Description
0x0 Maya
0x1 XSI
0x2 3ds Max
0x10 Int32 Vertex count.
0x14 Int32 Face count.
0x18 Int32 Unused. Offset to absolute path of intermediate file.
0x1C UInt32 Matricies count.
0x20 Byte Requires normalized matricies array if not 0.
0x21 Byte Requires texture matrices array if not 0.
0x22 Byte Enable bounding volume data if not 0.
0x23 Byte Unknown. Padding?
0x24 Int32 Offset to matricies table.
0x28 Float[3] Bounding volume minimum.
0x34 Float[3] Bounding volume maximum.

All offsets are relative to the start of the header.

Bone-Link Table

The bone-link table usually follows directly after the MDL0 header. However, its offset also lies within the header. The table below describes how the IDs of bone sections are related to their indices. If the game needs a specific bone, it looks up the ID from this table, and then loads the bone from the index given.

Offset Size Description
0x00 4 Entry count.
0x04 4 * Entry count Node index (-1 if not present).

If a model has five bones and nine weights, and bones 0 and 3 do not affect geometry, the block would look like this:

00000001 00000002 00000004 FFFFFFFF
FFFFFFFF FFFFFFFF FFFFFFFF 00000000
00000003

The weights that have one bone affecting geometry come first, then the ones with multiple influences (all as 0xFFFFFFFF), and finally, the weights for joints with no geometry.

The indices in the Nodemix block will match up to the weights' position here, and the 0x10 block in a joint will be the index of its weight as it appears here (so the value of 0x10 in joint 0 above would be 0x00000007).

BRRES Index Group

Following the bone-link table, one BRRES Index Group for each non empty section is defined. The sections in the MDL0 header link to the groups.

Section Order

In Mario Kart Wii, we can find some old and unused v8 MDL0 files (old_mario_gc_*.szs; 11 sections) and v11 (the rest of them; 14 sections).

The v8 MDL0 files use sections 0–9, but not 10. The general section order is: 9, 0, 1, 6, 7, 8, 2, 3, 4, 5.

All the v11 ones use sections 0–5 and 8–11, but not 6, 7, 12 and 13. The general order here is 11, 0, 1, 8, 9, 10, 2, 3, 4, 5.

If creating a new v11 MDL0 file, it is recommended to use this section order: 11, 0, 1, 6, 7, 8, 9, 10, 2, 3, 4, 5. The order of sections 12 and 13 is unknown.

Section Formats

Section 0 - Draw Lists

The draw list format is poorly understood. It is known to control the fundamentals of how things are rendered, and in a specified order. It is used to link polygons to materials. The format is simply a series of command bytes followed by a variable amount of parameters. Known commands are listed below.

Code Length Parameters bytes Description
00 01 02 03 04 05 06 07 08
0x00 0x1 None No operation.
0x01 0x1 None End of commands. Keep reading until encountered.
0x02 0x5 Bone index Parent matrix index None Node mapping.
0x03 0x4+0x6*N Weight ID N + Weight count Table ID N * Weight Weighting.
0x04 0x8 Object index Material index Bone index Priority None Draw polygon.
0x05 0x5 Matrix ID Weight index None Indexing.
0x06 0x5 To matrix From matrix None Duplicate matrix.

Section 1 - Bones

The bone files are used to describe the structure of polygons within the model, in order to allow CHR0 animations. It is also used in Mario Kart Wii by map_model.brres to describe the map placement in courses.

The bones obey a tree structure, using the parent, first child, next child and previous child offsets to point to other bones in the tree. 0 means no bone for these offsets.

Offset Size Description
0x00 UInt32 Length of data structure (0xD0).
0x04 Int32 MDL0 offset.
0x08 Int32 Name offset.
0x0C UInt32 Index.
0x10 UInt32 ID.
0x14 UInt32 Flags.
Bit f e d c b a 9 8
Meaning Unused Is a Child of Billboard Bone Is Display Matrix Is Visible
Bit 7 6 5 4 3 2 1 0
Meaning Disable Classic Scale Apply Child Scale Compensate Apply Scale Compensate Scale Uniform Scale Isotropic Rotation Isotropic Translation Isotropic Use Identity
0x18 UInt32 Billboard setting.
  • 0x0000 = None.
  • 0x0001 = Influenced by rotation of the parent node. The Z-axis direction is parallel to the camera lens axis.
  • 0x0002 = Influenced by rotation of the parent node. The Z-axis direction points toward the camera direction.
  • 0x0003 = Not influenced by the rotation of the parent node and restricted by the camera's Up vector. The Z-axis direction is parallel to the camera lens axis.
  • 0x0004 = Not influenced by the rotation of the parent node and restricted by the camera's Up vector. The Z-axis direction points toward the camera direction.
  • 0x0005 = Influenced by the rotation of the parent node and rotates only around the Y-axis. The Z-axis direction is parallel to the camera lens axis.
  • 0x0006 = Influenced by the rotation of the parent node and rotates only around the Y-axis. The Z-axis direction points toward the camera direction.
0x1C UInt32 Billboard transformation of this bone if parent is a Billboard bone.
0x20 Float[3] A 3D scaling vector
0x2C Float[3] A 3D rotation vector (in degrees).
0x38 Float[3] A 3D translation vector.
0x44 Float[3] Bounding volume minimum.
0x50 Float[3] Bounding volume maximum.
0x5C Int32 Parent offset.
0x60 Int32 First Child offset.
0x64 Int32 Next Sibling offset.
0x68 Int32 Previous Sibling offset.
0x6C Int32 User Data offset.
0x70 MTX34 Transformation matrix, 12 floats organized in 3 rows with 4 column values. It is a clockwise Rotation matrix with Euler angles and x-y-z convention. A fourth matrix line is assumed to always be "0 0 0 1", but not stored. The matrix can be calculated by Scale (0x20), Rotation (0x2c) and Translation (0x38).

All tests to modify the matrix did not have any impact. It seems, that the matrix is calculated after loading.

0xA0 MTX34 This is the Inverse matrix of Transformation matrix (0x70), organised in the same way. Again, the fourth matrix line is assumed to always be "0 0 0 1" without storing the data.

All tests to modify the matrix did not have any impact. It seems, that the matrix is calculated after loading.

All offsets are relative to the start of the file.

Section 2 - Vertices

The vertex section contains information of the vertices in the model. Each polygon specifies which vertex group is it going to use, and indexes the items within.

Offset Size Description
0x00 UInt32 Length.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Component count.
Enum Size Description.
0x0 Format*2 XY position.
0x1 Format*3 XYZ position.
0x18 UInt32 Format (data type):
Format Stride Description
0x0 0x3 UInt8
0x1 0x3 Int8
0x2 0x6 UInt16
0x3 0x6 Int16
0x4 0xc Float

For all formats except float, the value is divided by 2 ^ divisor.

0x1C Byte Divisor.
0x1D Byte Stride.
0x1E UInt16 Vertex count.
0x20 Float[3] Bounding volume minimum.
0x2C Float[3] Bounding volume maximum.

All offsets are relative to the start of the file.
After the header, at the data offset (0x40 typically) there is vertex data.

Section 3 - Normals

The normal section contains information of the normals in the model. Each polygon specifies which normal group is it going to use, and indexes the items within.

Offset Size Description
0x00 UInt32 Length.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Component count.
Enum Size Description
0x0 Format*3 Normal.
0x1 Format*9 Normal Bi-normal Tangent.
0x2 Format*3 Normal or Bi-normal or Tangent.
0x18 UInt32 Format (data type):
Enum Stride Description
0x0 0x3 UInt8
0x1 0x3 Int8
0x2 0x6 UInt16
0x3 0x6 Int16
0x4 0xc Float

For all formats except float, the value is divided by 2 ^ divisor.

0x1C Byte Divisor.
0x1D Byte Stride.
0x1E Uint16 Normal count.

All offsets are relative to the start of the file. After the header at the data offset (0x20 typically) there is normal data.

Section 4 - Colors

The color section contains information of the colors in the model. Each polygon specifies which color group(s) is it going to use, and indexes the items within.

Offset Size Description
0x00 UInt32 Length.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Component count.
Enum Size Description
0x0 Format (0, 1, or 2) RGB color.
0x1 Format (3, 4, or 5) RGBA color.

Both component types can range in byte sizes from 2 to 4.

0x18 UInt32 Format
Enum Stride Description Red Green Blue Alpha
0x0 0x2 RGB565 5 bits 6 bits 5 bits
0x1 0x3 RGB8 (RGB24) 8 bits 8 bits 8 bits
0x2 0x4 RGBX8 (RGBX32) X values discarded. 8 bits 8 bits 8 bits 8 bits (ignored)
0x3 0x2 RGBA4 (RGBA16) 4 bits 4 bits 4 bits 4 bits
0x4 0x3 RGBA6 (RGBA24) 6 bits 6 bits 6 bits 6 bits
0x5 0x4 RGBA8 (RGBA32) 8 bits 8 bits 8 bits 8 bits
0x1C Byte Stride.
0x1D Byte Padding.
0x1E UInt16 Color count.

All offsets are relative to the start of the file. After the header at the data offset (0x20 typically) there is color data.

Section 5 - Texture Coordinates

The texture coordinate section contains information of the texture UV coordinates in the model. Each polygon specifies which texture coordinate group(s) is it going to use, and indexes the items within.

Offset Size Description
0x00 UInt32 Length.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Component count.
Enum Size Description
0x0 Format*1 S coord.
0x1 Format*2 ST coord.
0x18 UInt32 Format (data type):
Enum Stride Description
0x0 0x2 UInt8
0x1 0x2 Int8
0x2 0x4 UInt16
0x3 0x4 Int16
0x4 0x8 Float

For all formats except float, the value is divided by 2 ^ divisor.

0x1C Byte Divisor.
0x1D Byte Stride.
0x1E UInt16 Texture coordinate count.
0x20 Float[2] Bounding volume minimum.
0x28 Float[2] Bounding volume maximum.

All offsets are relative to the start of the file. After the header at the data offset (0x40 typically) there is texture coordinate data.

Section 6 - Fur Vectors

Seen in "smallbard.mdl0" v11 (Ridley's pre-mature form) from Super Smash Bros. Brawl.

This section is assumed to draw fur bases on vectors at specific points on the model's surface.

Offset Size Description
0x00 UInt32 Length.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Fur Vector count.

Following this, there are (float3) vectors.

Section 7 - Fur Layer Positions

This section is assumed to contain the shelling vectors for the fur vectors section, which is assumed to be used to draw a line-strip from each vector.

Offset Size Description
0x00 UInt32 Length.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Component count.
Enum Size Description.
0x0 Format*2 XY position.
0x1 Format*3 XYZ position.
0x18 UInt32 Format (data type):
Format Stride Description
0x0 0x3 UInt8
0x1 0x3 Int8
0x2 0x6 UInt16
0x3 0x6 Int16
0x4 0xc Float

For all formats except float, the value is divided by 2 ^ divisor.

0x1C Byte Divisor.
0x1D Byte Stride.
0x1E UInt16 Vertex Count in fur layer.
0x20 UInt32 Number of fur layers.
0x24 UInt32 Offset to fur layer.


Following this there is layer-vector data (data_type * vector_count * layer_count). The layer's size may mean there is padding in some cases.

Actual tests for these fur sections have not been performed yet. It is unsure if the vector positioning here is local to the fur vectors (like normals), or globally oriented.

Section 8 - Materials

The material section contains information about the texturing of models. The draw list commands specify which polygons are linked to which materials.

The following table describes the general layout of MDL0 v11 section 8. All Mario Kart Wii files use exactly this layout:

Size Description
0x418 Basic data structure. The first 32 bit value is the size of the complete section.
N * 0x34 N * layer data. N is a 32 bit number in the range 0 to 6 read from 'base+0x2c'. The start offset is stored at 'base+0x30' and is 0 (if N is 0) or 0x418 for all Mario Kart Wii files.
0..0x1c Alignment to a multiple of 0x20 (relative to MDL file start) for the next field.
0x180 Setup Code. The start offset is stored at 'base+0x3c'.

Basic Data Structure

Offset Size Description
0x00 UInt32 Length.
0x04 Int32 MDL0 offset.
0x08 Int32 Name offset.
0x0C UInt32 Index.
0x10 UInt32 Material Flags.

Axxxxxxx xxxxxxxx xxxxxxxx BCDEFGHI.

  • A - XLU Material.
  • B - Do not send texture matrix data.
  • C - Do not send texture coordinate data.
  • D - Do not send generator mode data.
  • E - Do not send lighting channel data.
  • F - Do not send indirect matrix data.
  • G - Do not send texture coordinate scale data.
  • H - Do not send TEV color data.
  • I - Do not send pixel display data.
0x14 Byte Texgens.
0x15 Byte Light channels.
0x16 Byte Shader stages.
0x17 Byte Indirect textures.
0x18 UInt32 Culling.
ID Description
0x0x None.
0x01 Front.
0x02 Back.
0x03 All.
0x1C Byte Depth test.
0x1D Byte Lightset Index.
0x1E Byte Fog Index.
0x1F Byte Padding.
0x20 Byte[4] Indirect Method.
ID Description
0 Wrap
1 Normal map
2 Normal map specular
3 Fur
4 Reserved
5 Reserved
6 User 0
7 User 1
0x24 Byte[4] Light normal map reference, used by indirect stages.
0x28 Int32 Shader offset.
0x2C UInt32 Amount of textures.
0x30 Int32 Layer offset.
0x34 Int32 Fur data offset. (version 10 and 11 MDL0s). User Data (version 8 and 9 MDL0s).
0x38 Int32 Display list offset (version 8 and 9 MDL0s). User Data (version 10 and 11 MDL0s).
0x3c Int32 Display list offset (version 10 and 11 MDL0s).
0x40 UInt32 Bitflag. Used texture maps. Bit 0 (LSB) means texture map 0 is used, bit 1 - texture map 1 etc.
0x44 Byte[8][32] Precompiled code space containing texture information.
0x144 UInt32 Bitflag. Used palletes. Bit 0 (LSB) means pallete 0 is used, bit 1 - pallete 1 etc.
0x148 Byte[8][12] Precompiled code space containing palette information.
0x1a8 UInt32 Bit flag.
Bit Description
0 Enable layer.
1 Scale fixed.
2 Rotation fixed.
3 Translation fixed.
0x1ac UInt32 Texture matrix mode
Value Description
0 Maya
1 XSI
2 3DS Max
0x1b0 20 * 8 8 copies of the following structure:
Offset Size Description
0x00 Float[2] Scale coordinate.
0x08 Float Rotation coordinate.
0x0C Float[2] Translation coordinate.
0x250 52 * 8 Texture matrix - 8 copies of the following structure:
Offset Size Description
0x00 SByte SCN0 camera reference
0x01 SByte SCN0 light reference
0x02 Byte Map mode:
Value Description
0 Texture coordinates
1 EnvCamera
2 Projection
3 EnvLight
4 EnvSpec
0x03 Byte Enable identity matrix effect
0x04 MTX34 Texture matrix.
0x3f0 20 * 2 Lighting channels:
Offset Size Description
0x00 UInt32 Flags
Bit Description
0 Material color enabled.
1 Material alpha enabled.
2 Ambient color enabled.
3 Ambient alpha enabled.
4 Raster color enabled.
5 Raster alpha enabled.
0x04 RGBA Material color.
0x08 RGBA Ambient color.
0x0c UInt32 Color light channel control.
0x10 UInt32 Alpha light channel control.

All offsets are relative to the start of the file.

Texture References

Normally, immediately after this data, there is layer information. It is at the layer offset. Each layer information structure is described as below.

Offset Size Description
0x00 Int32 Name offset, used as link into section 11.
0x04 Int32 Palette name offset, used as link into section 12.
0x08 Int32 Texture data offset.* 0x0 typically.
0x0c Int32 Palette data offset.* 0x0 typically.
0x10 UInt32 Texture data ID, indexes an entry in the texture information list.
0x14 UInt32 Palette data ID, indexes an entry in the palette information list.
0x18 UInt32 U texture wrapping mode.
0x1c UInt32 V texture wrapping mode.
0x20 UInt32 Minification texture filtering.
Enum Description
0x00 Nearest
0x01 Linear
0x02 Nearest Mipmap Nearest
0x03 Linear Mipmap Nearest
0x04 Nearest Mipmap Linear
0x05 Linear Mipmap Linear
0x24 UInt32 Magnification texture filtering.
Enum Description
0x00 Nearest
0x01 Linear
0x28 Float LOD bias.
0x2c UInt32 Max Anisotropy filtering. Can improve texture quality, but not recommended to use on many materials.
Enum Description
0x00 One
0x01 Two
0x02 Four
0x30 Byte Clamp bias.
0x31 Byte Texel interpolate.
0x32 Byte[2] Padding.
  • These offsets are calculated by the game during track load, whether or not non-zero values are kept is unknown.

Wrapping modes

Settings Description
0x0 Clamp.
0x1 Repeat.
0x2 Mirror.

Fur Data

This section appears right after the texture references only if a material uses fur.

Offset Type Description
0x00 Float Maximum length to which fur can grow.
0x04 UInt32 Number of fur layers.
0x08 UInt32 Type of spacing between fur layers.
Enum Description
0x0 Uniform interval.
0x1 More dense at tips.
0x0C Float Alpha curvature parameter.
0x10 Float Specular lighting curvature parameter.

Shader

After the layer information (and padding to 0x20), there is always shader data directly at its offset. This is the Wii Graphics Code, which describes how the material is created. It is split down into four basic sections.

Offset Size Description
0x000 0x20 Mode information.
0x020 0x80 Tev color regs.
0x0a0 0x40 Indirect texture transformations.
0x0e0 0xa0 Texture matrices.
0x180 End of shader.

Section 9 - TEVs

This section has information about how the color and texture informations are combined in the Wii's GPU. Each material has a link to a TEV structure. Several materials often share the same TEV. The structure is often referenced many times in the index group too. Most large MDL0's may only have three or four structures, but many more appear in the file tree due to repeats. The repeats always ensure that each material has a structure with the same name, which it links to.

Offset Size Description
0x00 UInt32 Length.
0x04 Int32 MDL0 offset.
0x08 Int32 Index.
0x0C Byte TEV Stage Count.
0x0d Byte[3] Padding.
0x10 Byte[8] [TexScale0:TexScale7] (0xff for unused references). Indices to a material layer.
0x18 Byte[8] Padding.

All offsets are relative to the start of the file. After this section follows Wii Graphics Code, which describes how information is transformed into colors by the graphics card. The length of this code is Length - 0x20. Normally those commands control color and alpha blending, indirect texture mapping and color channel swapping.

Section 10 - Objects (Polygons)

The objects section describes how vertex data is combined optionally with colors, texture coordinates and normals, as well as bones and materials in order to produce the rendered model.

Offset Size Description
0x00 4 Length.
0x04 4 MDL0 offset.
0x08 4 Bone index (for single bone references) (-1 for table usage).
0x0c 4 CP_Vtx (0x4400 typically).
0x10 4 CP_Tex (0x2 typically).
0x14 4 XF_Nor_Spec (0x11 typically).
0x18 4 Vertex declaration size (0xe0).
0x1c 4 Unknown flags. 0x80 typically.
0x20 4 Vertex declaration offset (0x68 typically).
0x24 4 Vertex data size.
0x28 4 Vertex data size.
0x2c 4 Vertex data offset (0x13c typically).
0x30 4 XF_Flags (0x2a00 typically).
0x34 4 Unknown. 0x0 typically.
0x38 4 Name offset.
0x3c 4 Index.
0x40 4 Vertex count.
0x44 4 Face count.
0x48 2 Vertex group index.
0x4a 2 Normal group index.
0x4c 2 * 2 2 color group indices.
0x50 2 * 8 8 texture coordinate group indices.
0x60 4 Unknown. -1 typically (not seen in version 9 MDL0's).
0x64 4 Bone table offset.

All offsets are relative to the start of the file, except the vertex declaration and vertex data offsets. The vertex declaration offset is relative to 0x20, itself. The vertex data offset is relative to 0x24. Normally directly after the header, there is a bone table at its offset. This table is only used in objects which use multiple bones, and therefore have a value of -1 in their bone offset field. The use of this table is still not fully understood.

Offset Size Description
0x00 4 Entry count.
0x04 2 * Entry count Bone ID.

After the bone table, there is vertex declaration. This is the Wii Graphics Code, which describes the format of each vertex in the polygon. This is at the vertex declaration offset. After the vertex declaration, there is vertex code. This is also the Wii Graphics Code, which describes how the model is rendered. It contains commands such as triangle drawing. The indices of the points are also here.

Section 11 - Texture Links

There is one texture link section for each texture used in the model. Each section contains a table with links (offset values) into material sections. These sections have no names.

Offset Size Description
0x00 4 Entry count.
0x04 8 * Entry count Entry count copies of the following structure:
Offset Size Description
0x00 4 Offset relative to section start into a material section (#8).
0x04 4 Offset relative to section start into a material layer. The layer is part of the material section above.

Section 12 - Palette Links

There is one palette link section for each palette used in the model. Each section contains a table with links (offset values) into material sections. These sections also have no names.

Offset Size Description
0x00 4 Entry count.
0x04 8 * Entry count Entry count copies of the following structure:
Offset Size Description
0x00 4 Offset relative to section start into a material section (#8).
0x04 4 Offset relative to section start into a material layer. The layer is part of the material section above.

All offsets are relative to the start of the file.

Tools

The following tools can handle MDL0 files:

Links

All about BRRES files

BRRES fileIndex GroupSub Files

CHR0CLR0MDL0PAT0SCN0SHP0SRT0TEX0