Difference between revisions of "MDL0 (File Format)"

From Custom Mario Kart
Jump to navigation Jump to search
(Updated with information from SZS Modifier, CTools, Brawl and Dolphin. Incomplete.)
(Updated with information from SZS Modifier, CTools, Brawl and Dolphin. Incomplete.)
Line 3: Line 3:
 
This page describes the [[Mario Kart Wii]] '''MDL0''' file format, as found within [[BRRES (File Format)|BRRES files]].
 
This page 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 ===
Line 89: Line 90:
 
|}
 
|}
 
All offsets are relative to the start of the header.<br />
 
All offsets are relative to the start of the header.<br />
 +
=== Bone Table ===
 +
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.
  
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x00 || 4 || Entry Count
 +
|-
 +
| 0x04 || 4 * Entry Count || Node index (-1 for not present)
 +
|-
 +
|}
 +
== 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 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.
 +
 +
{| class="wikitable"
 +
! rowspan=2 | Code !! colspan=7 | Parameters bytes !! rowspan=2 | Description
 +
|-
 +
! 00 !! 01 !! 02 !! 03 !! 04 !! 05 !! 06
 +
|-
 +
| 0x01 || colspan=7 | None || End of commands. Keep reading until encountered.
 +
|-
 +
| 0x02 || colspan=2 | '''Unkonwn''' || colspan=2 | '''Unkonwn''' || colspan=3 | None || '''Unknown'''
 +
|-
 +
| 0x03 || colspan=2 | '''Unkonwn''' || Parameter Count || colspan=4 | Parameter Count * 6 bytes || '''Unknown'''
 +
|-
 +
| 0x04 || colspan=2 | Polygon Index || colspan=2 | Material Index || colspan=2 | '''Unkonwn''' || '''Unknown''' || Draw polygon. Draws polygon
 +
|-
 +
| 0x05 || colspan=2 | '''Unkonwn''' || colspan=2 | '''Unkonwn''' || colspan=3 | None  || '''Unknown'''
 +
|-
 +
|}
 +
=== 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 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.
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x00 || 4 || Length (0xD0)
 +
|-
 +
| 0x04 || 4 || MDL0 Offset
 +
|-
 +
| 0x08 || 4 || Name Offset
 +
|-
 +
| 0x0C || 4 || Index
 +
|-
 +
| 0x10 || 4 || ID
 +
|-
 +
| 0x14 || 4 || '''Unknown Flags''' (0x31f typical)
 +
|-
 +
| 0x18 || 4 || '''Unknown'''
 +
|-
 +
| 0x1C || 4 || '''Unknown'''
 +
|-
 +
| 0x20 || 12 || Scale (float3)
 +
|-
 +
| 0x2C || 12 || Rotation (float3)
 +
|-
 +
| 0x38 || 12 || Translation (float3)
 +
|-
 +
| 0x44 || 12 || Minimum (float3)
 +
|-
 +
| 0x50 || 12 || Maximum (float3)
 +
|-
 +
| 0x5C || 4 || Parent Offset
 +
|-
 +
| 0x60 || 4 || First Child Offset
 +
|-
 +
| 0x64 || 4 || Next Sibling Offset
 +
|-
 +
| 0x68 || 4 || Previous Sibling Offset
 +
|-
 +
| 0x6C || 4 ||  '''Unknown'''
 +
|-
 +
| 0x70 || 48 || Tranformation Matrix (float4x3)
 +
|-
 +
| 0xA0 || 48 || Inverse Matrix (float4x3)
 +
|-
 +
|}
 +
All offsets are relative to the start of the file.<br />
 +
=== Section 2 - Verticies ===
 +
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.
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x00 || 4 || Length (0xD0)
 +
|-
 +
| 0x04 || 4 || MDL0 Offset
 +
|-
 +
| 0x08 || 4 || Data Offset
 +
|-
 +
| 0x0C || 4 || Name Offset
 +
|-
 +
| 0x10 || 4 || Index
 +
|-
 +
| 0x14 || 4 || '''Unknown''' (0x1 typical)
 +
|-
 +
| 0x18 || 4 || Format
 +
|-
 +
| 0x1C || 1 || Divisor
 +
|-
 +
| 0x1D || 1 || Stride
 +
|-
 +
| 0x1E || 2 || Vertex Count
 +
|-
 +
| 0x20 || 12 || Minimum (float3)
 +
|-
 +
| 0x2C || 12 || Maximum (float3)
 +
|-
 +
|}
 +
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.
 +
{| class="wikitable"
 +
! Format !! Stride !! Description
 +
|-
 +
| 0x0 || 0x3 || u8
 +
|-
 +
| 0x1 || 0x3 || s8
 +
|-
 +
| 0x2 || 0x6 || u16
 +
|-
 +
| 0x3 || 0x6 || s16
 +
|-
 +
| 0x4 || 0xc || float
 +
|-
 +
|}
 +
=== 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"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x00 || 4 || Length (0xD0)
 +
|-
 +
| 0x04 || 4 || MDL0 Offset
 +
|-
 +
| 0x08 || 4 || Data Offset
 +
|-
 +
| 0x0C || 4 || Name Offset
 +
|-
 +
| 0x10 || 4 || Index
 +
|-
 +
| 0x14 || 4 || '''Unknown''' (0x0 typical)
 +
|-
 +
| 0x18 || 4 || Format
 +
|-
 +
| 0x1C || 1 || Divisor
 +
|-
 +
| 0x1D || 1 || Stride
 +
|-
 +
| 0x1E || 2 || Normal 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. For all formats except float, the value is divided by 2 ^ divisor.
 +
{| class="wikitable"
 +
! Format !! Stride !! Description
 +
|-
 +
| 0x0 || 0x3 || u8
 +
|-
 +
| 0x1 || 0x3 || s8
 +
|-
 +
| 0x2 || 0x6 || u16
 +
|-
 +
| 0x3 || 0x6 || s16
 +
|-
 +
| 0x4 || 0xc || float
 +
|-
 +
|}
 +
=== 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 (0xD0)
 +
|-
 +
| 0x04 || 4 || MDL0 Offset
 +
|-
 +
| 0x08 || 4 || Data Offset
 +
|-
 +
| 0x0C || 4 || Name Offset
 +
|-
 +
| 0x10 || 4 || Index
 +
|-
 +
| 0x14 || 4 || '''Unknown''' (0x1 typical)
 +
|-
 +
| 0x18 || 4 || Format
 +
|-
 +
| 0x1C || 1 || Stride
 +
|-
 +
| 0x1D || 1 || '''Unknown'''
 +
|-
 +
| 0x1E || 2 || Color 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"
 +
! Format !! Stride !! Description
 +
|-
 +
| 0x0 || 0x2 || RGB565
 +
|-
 +
| 0x1 || 0x3 || RGB8 (RGB24)
 +
|-
 +
| 0x2 || 0x4 || RGBX8 (RGBX32) X values discarded.
 +
|-
 +
| 0x3 || 0x2 || RGBA4 (RGBA16)
 +
|-
 +
| 0x4 || 0x3 || RGBA6 (RGBA24)
 +
|-
 +
| 0x5 || 0x4 || RGBA8 (RGBA32)
 +
|-
 +
|}
 +
=== Section 5 - Texture Coordinates ===
 +
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.
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x00 || 4 || Length (0xD0)
 +
|-
 +
| 0x04 || 4 || MDL0 Offset
 +
|-
 +
| 0x08 || 4 || Data Offset
 +
|-
 +
| 0x0C || 4 || Name Offset
 +
|-
 +
| 0x10 || 4 || Index
 +
|-
 +
| 0x14 || 4 || '''Unknown''' (0x1 typical)
 +
|-
 +
| 0x18 || 4 || Format
 +
|-
 +
| 0x1C || 1 || Divisor
 +
|-
 +
| 0x1D || 1 || Stride
 +
|-
 +
| 0x1E || 2 || Texture Coordinate Count
 +
|-
 +
| 0x20 || 8 || Minimum (float2)
 +
|-
 +
| 0x28 || 8 || Maximum (float2)
 +
|-
 +
|}
 +
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"
 +
! Format !! Stride !! Description
 +
|-
 +
| 0x0 || 0x2 || u8
 +
|-
 +
| 0x1 || 0x2 || s8
 +
|-
 +
| 0x2 || 0x4 || u16
 +
|-
 +
| 0x3 || 0x4 || s16
 +
|-
 +
| 0x4 || 0x8 || float
 +
|-
 +
|}
 
[[category:File Format]]
 
[[category:File Format]]

Revision as of 17:33, 4 May 2011

Under Construction
This article is not finished. Help improve it by adding accurate information or correcting grammar and spelling.

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

File Format

File Header

Offset Size Description
0x00 4 Magic "MDL0"
0x04 4 Length of MDL0 file
0x08 4 Section Count - 3
0x0c 4 BRRES File Offset
0x10 4 * Section Count Section Offsets

All offsets are relative to the start of the header.
The Section Count is stored as 3 less than it should be.
The section offsets point to BRRES Index Group strctures 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.

Section description
0 Draw lists
1 Bones
2 Verticies
3 Normals
4 Colors
5 Texture Coordinates
6 Not Seen
7 Not Seen
8 Materials
9 Shaders
10 Polygons
11 Texture Links
12 Not Seen in Mario Kart Wii
13 Not Seen in Mario Kart Wii

MDL0 Header

Following the section offsets is the MDL0 header structure.

Offset Size Description
0x00 4 Header Length (0x40)
0x04 4 File Header Offset
0x08 4 Unknown
0x0C 4 Unknown
0x10 4 Vertex Count
0x14 4 Face Count
0x18 4 Unknown
0x1C 4 Bone Count
0x20 4 Unknown (0x01000000)
0x24 4 Bone Table Offset
0x28 12 Minimum (float3)
0x34 12 Maximum (float3)

All offsets are relative to the start of the header.

Bone Table

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.

Offset Size Description
0x00 4 Entry Count
0x04 4 * Entry Count Node index (-1 for not present)

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 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.

Code Parameters bytes Description
00 01 02 03 04 05 06
0x01 None End of commands. Keep reading until encountered.
0x02 Unkonwn Unkonwn None Unknown
0x03 Unkonwn Parameter Count Parameter Count * 6 bytes Unknown
0x04 Polygon Index Material Index Unkonwn Unknown Draw polygon. Draws polygon
0x05 Unkonwn Unkonwn None Unknown

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.
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.

Offset Size Description
0x00 4 Length (0xD0)
0x04 4 MDL0 Offset
0x08 4 Name Offset
0x0C 4 Index
0x10 4 ID
0x14 4 Unknown Flags (0x31f typical)
0x18 4 Unknown
0x1C 4 Unknown
0x20 12 Scale (float3)
0x2C 12 Rotation (float3)
0x38 12 Translation (float3)
0x44 12 Minimum (float3)
0x50 12 Maximum (float3)
0x5C 4 Parent Offset
0x60 4 First Child Offset
0x64 4 Next Sibling Offset
0x68 4 Previous Sibling Offset
0x6C 4 Unknown
0x70 48 Tranformation Matrix (float4x3)
0xA0 48 Inverse Matrix (float4x3)

All offsets are relative to the start of the file.

Section 2 - Verticies

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.

Offset Size Description
0x00 4 Length (0xD0)
0x04 4 MDL0 Offset
0x08 4 Data Offset
0x0C 4 Name Offset
0x10 4 Index
0x14 4 Unknown (0x1 typical)
0x18 4 Format
0x1C 1 Divisor
0x1D 1 Stride
0x1E 2 Vertex Count
0x20 12 Minimum (float3)
0x2C 12 Maximum (float3)

All offsets are relative to the start of the file.
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.

Format Stride Description
0x0 0x3 u8
0x1 0x3 s8
0x2 0x6 u16
0x3 0x6 s16
0x4 0xc float

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.

Offset Size Description
0x00 4 Length (0xD0)
0x04 4 MDL0 Offset
0x08 4 Data Offset
0x0C 4 Name Offset
0x10 4 Index
0x14 4 Unknown (0x0 typical)
0x18 4 Format
0x1C 1 Divisor
0x1D 1 Stride
0x1E 2 Normal Count

All offsets are relative to the start of the file.
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.

Format Stride Description
0x0 0x3 u8
0x1 0x3 s8
0x2 0x6 u16
0x3 0x6 s16
0x4 0xc float

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.

Offset Size Description
0x00 4 Length (0xD0)
0x04 4 MDL0 Offset
0x08 4 Data Offset
0x0C 4 Name Offset
0x10 4 Index
0x14 4 Unknown (0x1 typical)
0x18 4 Format
0x1C 1 Stride
0x1D 1 Unknown
0x1E 2 Color Count

All offsets are relative to the start of the file.
After the header, at the data offset (0x20 typical) is the normal data. The format values are given below.

Format Stride Description
0x0 0x2 RGB565
0x1 0x3 RGB8 (RGB24)
0x2 0x4 RGBX8 (RGBX32) X values discarded.
0x3 0x2 RGBA4 (RGBA16)
0x4 0x3 RGBA6 (RGBA24)
0x5 0x4 RGBA8 (RGBA32)

Section 5 - Texture Coordinates

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.

Offset Size Description
0x00 4 Length (0xD0)
0x04 4 MDL0 Offset
0x08 4 Data Offset
0x0C 4 Name Offset
0x10 4 Index
0x14 4 Unknown (0x1 typical)
0x18 4 Format
0x1C 1 Divisor
0x1D 1 Stride
0x1E 2 Texture Coordinate Count
0x20 8 Minimum (float2)
0x28 8 Maximum (float2)

All offsets are relative to the start of the file.
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.

Format Stride Description
0x0 0x2 u8
0x1 0x2 s8
0x2 0x4 u16
0x3 0x4 s16
0x4 0x8 float