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.

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.

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.

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:

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: (note this is both the order the section numbers are listed in as well as the order that the sections themselves appear in the file)

Materials
See Materials (Metroid Prime 3)

Identical to the material format found in CMDL. There is just one materials section which is shared across all world models.

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:


 * World Model Header
 * Surface Definitions
 * Surface Group IDs
 * Surface Lookup Table

Area Octree
See AROT (MREA Section)

Surface Group Bounding Boxes
See MREA (Metroid Prime 2)

GPU Data
See Geometry (Metroid Prime) or Geometry (Donkey Kong Country Returns)

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, this is the only UV coordinates section, so it's used for everything.
 * 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. For details on the structure of these sections check Geometry (Metroid Prime) page for MP3 and the Geometry (Donkey Kong Country Returns) page for DKCR.

Dependencies
This section is basically a list of all resources that this area depends on, not unlike a DGRP file. After the initial dependency list, there's a second array which provides a list of offsets into the dependency list. These offsets are used to indicate which dependencies are needed for individual script layers, with the last offset pointing to resources that are used by the area itself as a whole (world geometry textures and the PATH/PTLA/EGMC assets).

Generated Script Objects
This section is an extra script layer that contains generated objects (anything spawned by a Generator).

Lights
''See Lights (Metroid Prime)

Unknown Section (LLTE)
This section always contains just a single 32-bit 1. It doesn't appear to do anything, so the purpose of this section is unknown.

RSO Module List
This section is a list of RSO modules used by script objects in the area. Like the dependencies section, there's also a list of offsets to indicate which RSOs are used by each script layer.

Path
This section only contains a single PATH asset ID.

Portal Area
This section only contains a single PTLA asset ID.

Static Geometry Map
This section only contains a single EGMC asset ID.