Difference between revisions of "MDL0 (File Format)"

From Custom Mario Kart
Jump to navigation Jump to search
Line 619: Line 619:
 
| 0x18 || 4 || Vertex Declaration Size (0xe0)
 
| 0x18 || 4 || Vertex Declaration Size (0xe0)
 
|-
 
|-
| 0x1c || 4 || '''Unknown''' (0x80 typical)
+
| 0x1c || 4 || '''Unknown Flags''' (0x80 typical)
 
|-
 
|-
 
| 0x20 || 4 || Vertex Declaration Offset (0x68 typical)
 
| 0x20 || 4 || Vertex Declaration Offset (0x68 typical)

Revision as of 17:46, 30 June 2012

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 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.
The Section Count is stored as 3 less than it should be.
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.
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 Unknown (Not Seen in v9 mdl0s)
7 Unknown (Not Seen in v9 mdl0s)
8 Materials
9 Material Nodes (TEV's)
10 Objects (Polygons)
11 Texture Links
12 Pallet Links (Not Seen in Mario Kart Wii)
13 Unknown (Not Seen in Mario Kart Wii or v9 mdl0s)

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)


notes:
If a model has 5 bones, and 9 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


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.

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

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 Weight index Parent Weight index None bone mapping
0x03 Weight ID Weight count Table ID weight * 4 bytes weighting
0x04 Object Index Material Index Bone index Unknown Draw polygon. Draws polygon
0x05 Weight ID Weight index None indexing

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 Padding
0x1C 4 Padding
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 Part 2 Offset
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
0x04 4 MDL0 Offset
0x08 4 Data Offset
0x0C 4 Name Offset
0x10 4 Index
0x14 4 Has Bounds
0x18 4 Format (data type)
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
0x04 4 MDL0 Offset
0x08 4 Data Offset
0x0C 4 Name Offset
0x10 4 Index
0x14 4 Has Bounds (usu 0)
0x18 4 Format (data type)
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
0x04 4 MDL0 Offset
0x08 4 Data Offset
0x0C 4 Name Offset
0x10 4 Index
0x14 4 Has Alpha
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
0x04 4 MDL0 Offset
0x08 4 Data Offset
0x0C 4 Name Offset
0x10 4 Index
0x14 4 Has Bounds
0x18 4 Format (data type)
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.

The following table describes the general layout of MDL 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 4 Length
0x04 4 MDL0 Offset
0x08 4 Name Offset
0x0C 4 Index (0..0x1e)
0x10 4 XLU-Material (0x0 for disabled or 0x80000000 for enabled)
0x14 1 Texgens
0x15 1 Light Channels
0x16 1 Shader Stages
0x17 1 Indirect Textures
0x18 4 Cull-mode
0x1C 1 Alpha Function
0x1D 1 Lightset
0x1E 1 Fogset
0x1F 1 Unknown (always 0)
0x20 4 Unknown (always 0)
0x24 4 Unknown (always 0xffffffff)
0x28 4 Shader Offset
0x2C 4 Amount of Textures
0x30 4 Layer Offset
0x34 4 Part 2 Offset
0x38 4 Display List Offset 8_9
0x3c 4 Display List Offset 10_11
0x40 360 Unknown (always 0)
0x1a8 4/8*4 4 bit Layer Flags value; 1 for each layer with the msb containing the last layer.
Bit (lsb = 0) 2 Description
0 Enable Layer
1 Scaling Fixed
2 Rotation Fixed
3 Translation Fixed
0x1ac 4 Unknown Flags
0x1b0 20 * 8 8 copies of the following structure
Offset Size Description
0x00 8 float2 Coordinate Scale
0x08 4 float Coordinate Rotation
0x0C 8 float2 Coordinate Translation
0x250 52 * 8 Texture Matrix - 8 copies of the following structure
Offset Size Description
0x00 1 Texture Unknown 1 (0xff typical)
0x01 1 Texture Unknown 2 (0xff typical)
0x02 1 Texture Unknown 3 (0x0 typical)
0x03 1 Texture Unknown 4 (0x1 typical)
0x04 48 float4x3 Texture Matrix
0x3f0 4 Unknown Flags (0x3f typical)
0x3f4 36 Lightnings
Offset Size Description
0x00 4 Color0Color 0
0x04 4 Color0Color 1
0x08 2 Padding
0x0a 2 Color0Enums 0 and 1
0x0c 2 Padding
0x0e 2 Color0Enums 2 and 3
0x10 4 Unknown Flags
0x14 4 Color0Color 0
0x18 4 Color0Color 1
0x1c 2 Padding
0x1e 2 Color0Enums 0 and 1
0x20 2 Padding
0x22 2 Color0Enums 2 and 3

All offsets are relative to the start of the file.

Layers

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 layer section.
The X and Y texture settings values are given below.

Settings Description
0x0 Clamp
0x1 Repeat
0x2 Mirror

Shader

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.

Offset Size Description
0x000 0x20 Mode Information
0x020 0x80 Tev Regs
0x0a0 0x40 Texture Transformations
0x0e0 0xa0 Texture Matricies
0x180 End of Shader.

Section 9 - Material Nodes (TEV's)

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.

Offset Size Description
0x00 4 Length
0x04 4 MDL0 Offset
0x08 4 Index
0x0c 1 Layer Count (material flag)
0x0d 1 Res0 (0x0 typical)
0x0e 1 Res1 (0x0 typical)
0x0f 1 Res2 (0x0 typical)
0x10 1 * 8 [TRef0:TRef7] (0x0 typical, 0xff for unused layers)
0x18 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.

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 typical)
0x10 4 CP_Tex (0x2 typical)
0x14 4 XF_Nor_Spec (0x11 typical)
0x18 4 Vertex Declaration Size (0xe0)
0x1c 4 Unknown Flags (0x80 typical)
0x20 4 Vertex Declaration Offset (0x68 typical)
0x24 4 Vertex Data Size
0x28 4 Vertex Data Size
0x2c 4 Vertex Data Offset (0x13c typical)
0x30 4 XF_Flags (0x2a00 typical)
0x34 4 Unknown (0x0 typical)
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 Indicies
0x50 2 * 8 8 Texture Coordinate Group Indicies
0x60 4 Unknown (-1 typical) (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, 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.

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

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

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.

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.


All about BRRES files

BRRES fileIndex GroupSub Files

CHR0CLR0MDL0PAT0SCN0SHP0SRT0TEX0