MREA (Metroid Prime 3)
See MREA (File Format) for the other revisions of this format.
The MREA format, which defines areas/levels, received another large layout overhaul in Metroid Prime 3. The level geometry data received the biggest update, with a new material format, lot of things being moved around, and a few entirely new sections being introduced. This article covers Metroid Prime 3, the MP3 E3 prototype, and Donkey Kong Country Returns.
This file format needs more research There are a few sections we know nothing about. |
Format
MREA files are split up into a number of 32-byte aligned sections. Every section both starts and ends on a 32-byte boundary. These are used to separate different parts of the file; different types of sections typically indicate different sets of data. The header declares the section count and the size of each one; using these is the only way to navigate the file.
Header
The header is identical between MP3 and DKCR.
Offset | Type | Count | Name | Notes |
---|---|---|---|---|
0x0 | u32 | 1 | Magic | Always 0xDEADBEEF .
|
0x4 | u32 | 1 | Version | See hub article for a list of possible version numbers. |
0x8 | float | 12 | Area Transform | Matrix that represents the area's transform from the origin. Most area data is pre-transformed, so this matrix is only used occasionally. |
0x38 | u32 | 1 | World Model Count | Number of world models in this area. |
0x3C | u32 | 1 | Script Layer Count | Number of script layers in this area. |
0x40 | u32 | 1 | Data Section Count | Number of data sections in the file. |
0x44 | u32 | 1 | Compressed Block Count | Number of compressed data blocks in the file. |
0x48 | u32 | 1 | Section Number Count | Number of section numbers at the end of the header. |
0x4C | u32 | 5 | Padding | Padding bytes that align the file with the next multiple-of-32 offset. |
0x60 | u32 | Data Section Count | Data Section Sizes | Array containing the size of each data section in the file. Every size is always a multiple of 32. |
End of main header data; pad to 32 bytes before compressed section definitions |
Compressed Blocks
Compressed blocks are defined in the same manner as Metroid Prime 2. The MREA format contains compressed blocks that can each contain a number of regular file sections within them. These blocks are compressed using segmented LZO1X-999 in Metroid Prime 3, and segmented zlib in Donkey Kong Country Returns. Compressed blocks are padded to 32 bytes, but their padding is located at the beginning of the block rather than the end, so it's required to account for the padding before you start decompressing. The compressed data is segmented, which means there's multiple segments of data that are compressed/decompressed separately. Each segment starts with a 16-bit size value. The size value is signed; a negative value indicates the segment is not compressed (this is done when compressing a segment doesn't reduce its size). Each segment is 0x4000 bytes large when decompressed (except the last one).
Compressed blocks are defined after the main header. After reading them, pad to 32 bytes before the section numbers portion of the header starts.
Offset | Type | Count | Name | Notes | |
---|---|---|---|---|---|
0x0 | u32 | 1 | Buffer Size | This is always 0x120 bytes larger than the uncompressed size on compressed bytes, and the same value as the uncompressed size on uncompressed blocks | |
0x4 | u32 | 1 | Uncompressed Size | ||
0x8 | u32 | 1 | Compressed Size | This is 0 on uncompressed blocks. | |
0xC | u32 | 1 | Data Section Count | The number of regular data sections contained in this block. | |
0x10 | Block definition end |
Section Numbers
The section numbers portion of the header indicates the section index of each major data chunk. Some of these chunks contain multiple sections; in that case the number will point to the first section of the chunk. Each number is a short 8-byte struct:
Offset | Type | Count | Name |
---|---|---|---|
0x0 | char | 4 | Section Type |
0x4 | u32 | 1 | Section Index |
WOBJ
can be listed multiple times, but its section index is always 0 (pointing to the materials section). Every other section number always appears in every MREA file once (none are optional). Here are all possible section numbers and what they are, in the order that they appear in the file:
FourCC | Description | MP3 | DKCR |
---|---|---|---|
WOBJ
|
Materials + World Model Definition | ✔ | ✔ |
ROCT
|
Area Octree | ✔ | ✔ |
AABB
|
Surface Group Bounding Boxes | ✔ | ✔ |
GPUD
|
World Geometry GPU Data | ✔ | ✔ |
DEPS
|
Dependencies | ✔ | ✔ |
SOBJ
|
Script Layers | ✔ | ✔ |
SGEN
|
Generated Script Objects | ✔ | ✔ |
COLI
|
Collision | ✔ | ✔ |
LITE
|
Lights | ✔ | ✔ |
LLTE
|
Unknown | ✔ | ✔ |
PVS!
|
Visibility Tree | ✔ | ✔ |
RSOS
|
RSO Module List | ✔ | ✔ |
PFL2
|
Path | ✔ | ✖ |
APTL
|
Portal Area | ✔ | ✖ |
EGMC
|
Static Geometry Map | ✔ | ✖ |
Materials
See Materials (Metroid Prime 3)
Identical to the material format found in CMDL.
World Model Definition
The world geometry definitions always appear immediately following the materials section. Each definition is a sequence of four sections. All four of these sections are identical to their structure in the previous MREA formats in both MP3 and DKCR, so check those pages:
Area Octree
Surface Group Bounding Boxes
See MREA (Metroid Prime 2)#Surface Group Bounding Boxes
GPU Data
This section contains the GPU buffer data used to render world geometry. This is generally the same as in previous games, with the following sequence of sections repeated once per world model:
- Vertices: Always floats; world geometry vertices are never packed into shorts.
- Normals: Always floats; world geometry normals are never packed into shorts.
- Colors: Contains 32-bit RGBA8 colors. This section is not used in any official assets and is always zeroed out.
- Float UV Coordinates: In Metroid Prime 3, these are used exclusively, even for lightmaps.
- Short UV Coordinates: Only appears in Donkey Kong Country Returns; can be used for anything, not only lightmaps as in previous games.
- Surfaces: One section per surface.