Difference between revisions of "MDL0 (File Format)"
(Updated with information from SZS Modifier, CTools, Brawl and Dolphin. Incomplete.) |
(Updated with information from SZS Modifier, CTools, Brawl and Dolphin. Incomplete.) |
||
Line 346: | Line 346: | ||
| 0x4 || 0x8 || float | | 0x4 || 0x8 || float | ||
|- | |- | ||
+ | |} | ||
+ | === 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. | ||
+ | {| class="wikitable" | ||
+ | ! Offset !! Size !! Description | ||
+ | |- | ||
+ | | 0x00 || 4 || Length (0xD0) | ||
+ | |- | ||
+ | | 0x04 || 4 || MDL0 Offset | ||
+ | |- | ||
+ | | 0x08 || 4 || Name Offset | ||
+ | |- | ||
+ | | 0x0C || 4 || Index | ||
+ | |- | ||
+ | | 0x10 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x14 || 1 || '''Unknown''' (0x1 typical) | ||
+ | |- | ||
+ | | 0x15 || 1 || '''Unknown''' (0x1 typical) | ||
+ | |- | ||
+ | | 0x16 || 1 || '''Unknown''' (0x1 typical) | ||
+ | |- | ||
+ | | 0x17 || 1 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x18 || 4 || '''Unknown''' (0x2 typical) | ||
+ | |- | ||
+ | | 0x1C || 1 || '''Unknown''' (0x1 typical) | ||
+ | |- | ||
+ | | 0x1D || 1 || '''Unknown''' (0xff typical) | ||
+ | |- | ||
+ | | 0x1E || 1 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x1F || 1 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x20 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x24 || 4 || '''Unknown''' (-1 typical) | ||
+ | |- | ||
+ | | 0x28 || 4 || Shader Offset | ||
+ | |- | ||
+ | | 0x2C || 4 || Layer Count | ||
+ | |- | ||
+ | | 0x30 || 4 || Layer Offset | ||
+ | |- | ||
+ | | 0x34 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x38 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x3c || 4 || Setup Code Offset | ||
+ | |- | ||
+ | | 0x40 || 360 || '''Unknown''' | ||
+ | |- | ||
+ | | 0x1a8 || 4 || '''Unknown Layer Flags (4 bits per layer, starting at lsb)''' (0xf typical) | ||
+ | |- | ||
+ | | 0x1ac || 4 || '''Unknown''' | ||
+ | |- | ||
+ | | 0x1b0 || 20 * 8 || 8 copies of the following structure <br /> | ||
+ | {| class="wikitable" | ||
+ | ! Offset !! Size !! Description | ||
+ | |- | ||
+ | | 0x00 || 8 || float2 '''Unknown Texture Coordinate''' | ||
+ | |- | ||
+ | | 0x08 || 4 || float '''Unknown Angle''' | ||
+ | |- | ||
+ | | 0x0C || 8 || float2 '''Unknown Texture Coordinate''' | ||
+ | |- | ||
+ | |} | ||
+ | |- | ||
+ | | 0x250 || 52 * 8 || 8 copies of the following structure <br /> | ||
+ | {| class="wikitable" | ||
+ | ! Offset !! Size !! Description | ||
+ | |- | ||
+ | | 0x00 || 1 || '''Unknown''' (0xff typical) | ||
+ | |- | ||
+ | | 0x01 || 1 || '''Unknown''' (0xff typical) | ||
+ | |- | ||
+ | | 0x02 || 1 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x03 || 1 || '''Unknown''' (0x1 typical) | ||
+ | |- | ||
+ | | 0x04 || 48 || float4x3 '''Unknown Matrix''' | ||
+ | |- | ||
+ | |} | ||
+ | |- | ||
+ | | 0x3f0 || 4 || '''Unknown''' (0x3f typical) | ||
+ | |- | ||
+ | | 0x3f4 || 16 * 2 || 2 copies of the following structure <br /> | ||
+ | {| class="wikitable" | ||
+ | ! Offset !! Size !! Description | ||
+ | |- | ||
+ | | 0x00 || 4 || '''Unknown RGBA Color''' | ||
+ | |- | ||
+ | | 0x04 || 4 || '''Unknown RGBA Color''' | ||
+ | |- | ||
+ | | 0x08 || 4 || '''Unknown''' | ||
+ | |- | ||
+ | | 0x0c || 4 || '''Unknown''' | ||
+ | |- | ||
+ | |} | ||
+ | |- | ||
+ | |} | ||
+ | All offsets are relative to the start of the file.<br /> | ||
+ | Normally immediately after this data is the layer information. It is at the layer offset. Each lay information structure is as follows.<br /> | ||
+ | {| class="wikitable" | ||
+ | ! Offset !! Size !! Description | ||
+ | |- | ||
+ | | 0x00 || 4 || Name Offset | ||
+ | |- | ||
+ | | 0x04 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x08 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x0c || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x10 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x14 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x18 || 4 || X Texture Address Settings | ||
+ | |- | ||
+ | | 0x1c || 4 || Y Texture Address Settings | ||
+ | |- | ||
+ | | 0x20 || 4 || '''Unknown''' (0x1 typical) | ||
+ | |- | ||
+ | | 0x24 || 4 || '''Unknown''' (0x1 typical) | ||
+ | |- | ||
+ | | 0x28 || 4 || float '''Unknown''' (0 typical) | ||
+ | |- | ||
+ | | 0x2c || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | | 0x30 || 4 || '''Unknown''' (0x0 typical) | ||
+ | |- | ||
+ | |} | ||
+ | All offsets are relative to the start of the file.<br /> | ||
+ | The X and Y texture settings values are given below.<br /> | ||
+ | {| class="wikitable" | ||
+ | ! Settings !! Description | ||
+ | |- | ||
+ | | 0x0 || Clamp | ||
+ | |- | ||
+ | | 0x1 || Repeat | ||
+ | |- | ||
+ | | 0x2 || Mirror | ||
+ | |- | ||
+ | |} | ||
+ | Normally after the layer information (and padding to 0x20) is the material setup code. It is at the material setup code offset. This is [[Wii Graphics Code]] which describes how the material is created. It is broken down into four basic sections. | ||
+ | {| class="wikitable" | ||
+ | ! Offset !! Size !! Description | ||
+ | |- | ||
+ | | 0x00 || 32 || Mode Information | ||
+ | |- | ||
+ | | 0x20 || 128 || Tev Regs | ||
+ | |- | ||
+ | | 0xa0 || 64 || Texture Transformations | ||
+ | |- | ||
+ | | 0xe0 || 160 || Texture Matricies | ||
+ | |- | ||
|} | |} | ||
[[category:File Format]] | [[category:File Format]] |
Revision as of 18:25, 4 May 2011
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 |
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.
Offset | Size | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0x00 | 4 | Length (0xD0) | ||||||||||||||||||
0x04 | 4 | MDL0 Offset | ||||||||||||||||||
0x08 | 4 | Name Offset | ||||||||||||||||||
0x0C | 4 | Index | ||||||||||||||||||
0x10 | 4 | Unknown (0x0 typical) | ||||||||||||||||||
0x14 | 1 | Unknown (0x1 typical) | ||||||||||||||||||
0x15 | 1 | Unknown (0x1 typical) | ||||||||||||||||||
0x16 | 1 | Unknown (0x1 typical) | ||||||||||||||||||
0x17 | 1 | Unknown (0x0 typical) | ||||||||||||||||||
0x18 | 4 | Unknown (0x2 typical) | ||||||||||||||||||
0x1C | 1 | Unknown (0x1 typical) | ||||||||||||||||||
0x1D | 1 | Unknown (0xff typical) | ||||||||||||||||||
0x1E | 1 | Unknown (0x0 typical) | ||||||||||||||||||
0x1F | 1 | Unknown (0x0 typical) | ||||||||||||||||||
0x20 | 4 | Unknown (0x0 typical) | ||||||||||||||||||
0x24 | 4 | Unknown (-1 typical) | ||||||||||||||||||
0x28 | 4 | Shader Offset | ||||||||||||||||||
0x2C | 4 | Layer Count | ||||||||||||||||||
0x30 | 4 | Layer Offset | ||||||||||||||||||
0x34 | 4 | Unknown (0x0 typical) | ||||||||||||||||||
0x38 | 4 | Unknown (0x0 typical) | ||||||||||||||||||
0x3c | 4 | Setup Code Offset | ||||||||||||||||||
0x40 | 360 | Unknown | ||||||||||||||||||
0x1a8 | 4 | Unknown Layer Flags (4 bits per layer, starting at lsb) (0xf typical) | ||||||||||||||||||
0x1ac | 4 | Unknown | ||||||||||||||||||
0x1b0 | 20 * 8 | 8 copies of the following structure
| ||||||||||||||||||
0x250 | 52 * 8 | 8 copies of the following structure
| ||||||||||||||||||
0x3f0 | 4 | Unknown (0x3f typical) | ||||||||||||||||||
0x3f4 | 16 * 2 | 2 copies of the following structure
|
All offsets are relative to the start of the file.
Normally immediately after this data is the layer information. It is at the layer offset. Each lay information structure is as follows.
Offset | Size | Description |
---|---|---|
0x00 | 4 | Name Offset |
0x04 | 4 | Unknown (0x0 typical) |
0x08 | 4 | Unknown (0x0 typical) |
0x0c | 4 | Unknown (0x0 typical) |
0x10 | 4 | Unknown (0x0 typical) |
0x14 | 4 | Unknown (0x0 typical) |
0x18 | 4 | X Texture Address Settings |
0x1c | 4 | Y Texture Address Settings |
0x20 | 4 | Unknown (0x1 typical) |
0x24 | 4 | Unknown (0x1 typical) |
0x28 | 4 | float Unknown (0 typical) |
0x2c | 4 | Unknown (0x0 typical) |
0x30 | 4 | Unknown (0x0 typical) |
All offsets are relative to the start of the file.
The X and Y texture settings values are given below.
Settings | Description |
---|---|
0x0 | Clamp |
0x1 | Repeat |
0x2 | Mirror |
Normally after the layer information (and padding to 0x20) is the material setup code. It is at the material setup code offset. This is Wii Graphics Code which describes how the material is created. It is broken down into four basic sections.
Offset | Size | Description |
---|---|---|
0x00 | 32 | Mode Information |
0x20 | 128 | Tev Regs |
0xa0 | 64 | Texture Transformations |
0xe0 | 160 | Texture Matricies |