MREA (Metroid Prime 2): Difference between revisions

From Retro Modding Wiki
Jump to navigation Jump to search
>Aruki
mNo edit summary
(fix and add links in TOC)
 
(27 intermediate revisions by 5 users not shown)
Line 10: Line 10:


Like CMDL, 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.
Like CMDL, 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.
These are the sections in each MREA file, in the order they appear in the file:
{| class="wikitable"
! Identifier
! Name
|-
| {{none}}
| [[#World Geometry|World Geometry]]
|-
| {{none}}
| [[#Unknown Section 1|Unknown Section 1]]
|-
| <code>SCLY</code>
| [[Scriptable_Layers_(Metroid_Prime_2)|Script Layers]]
|-
| <code>SCGN</code>
| Generated Script Objects
|-
| <code>0xDEAFBABE</code>
| [[#Collision|Collision]]
|-
| {{none}}
| [[MREA (Metroid Prime)#Unknown Section|Unknown Section 2]]
|-
| <code>0xBABEDEAD</code>
| [[Lights (Metroid Prime)|Lights]]
|-
| <code>VISI</code>
| [[VISI (MREA Section)|Visibility Tree]]
|-
| {{none}}
| [[#Path|Path]]
|-
| {{none}}
| [[#Portal Area|Portal Area]]
|-
| {{none}}
| [[#Static Geometry Map|Static Geometry Map]]
|}


=== Header ===
=== Header ===
Line 15: Line 55:
{| class="wikitable"
{| class="wikitable"
! Offset
! Offset
! Size
! Type
! Count
! Name
! Description
! Description
|-
|-
| 0x0
| 0x0
| 4
| u32
| '''Magic'''; always 0xDEADBEEF
| 1
| '''Magic'''
| Always <code>0xDEADBEEF</code>.
|-
|-
| 0x4
| 0x4
| 4
| u32
| '''Version'''; see [[MREA (File Format)|hub article]]
| 1
| '''Version'''
| See [[MREA (File Format)|hub article]] for a list of possible version numbers.
|-
|-
| 0x8
| 0x8
| 4 &times; 12
| float
| '''Transform matrix'''
| 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
| 0x38
| 4
| u32
| '''Mesh count'''
| 1
| '''World Model Count'''
| Number of world models in this area.
|-
|-
| 0x3C
| 0x3C
| 4
| u32
| '''SCLY layer count'''
| 1
| '''Script Layer Count'''
| Number of script layers in this area.
|-
|-
| 0x40
| 0x40
| 4
| u32
| '''Section count''' (SC)
| 1
| '''Data Section Count'''
| Number of data sections in the file.
|-
|-
| 0x44
| 0x44
| 4
| u32
| '''Geometry section number''' (starts on materials)
| 1
| '''Geometry Section'''
| Section index for world geometry data. Always 0; starts on materials.
|-
|-
| 0x48
| 0x48
| 4
| u32
| '''SCLY section number'''
| 1
| '''Script Layers Section'''
| Section index for script layer data.
|-
|-
| 0x4C
| 0x4C
| 4
| u32
| '''SCGN section number'''
| 1
| '''Generated Script Objects Section'''
| Section index for generated script object data.
|-
|-
| 0x50
| 0x50
| 4
| u32
| '''Collision section number'''
| 1
| '''Collision Section'''
| Section index for collision data.
|-
|-
| 0x54
| 0x54
| 4
| u32
| '''Unknown section number'''
| 1
| '''Unknown Section 1'''
| Section index for first unknown section.
|-
|-
| 0x58
| 0x58
| 4
| u32
| '''Lights section number'''
| 1
| '''Lights Section'''
| Section index for light data.
|-
|-
| 0x5C
| 0x5C
| 4
| u32
| '''Empty section number'''
| 1
| '''Visibility Tree Section'''
| Section index for visibility tree data.
|-
|-
| 0x60
| 0x60
| 4
| u32
| '''PATH section number'''
| 1
| '''Path Section'''
| Section index for path data.
|-
|-
| 0x64
| 0x64
| 4
| u32
| '''FFFFFFFF section number'''
| 1
| '''Unknown Section 2'''
| Section index for second unknown section.
|-
|-
| 0x68
| 0x68
| 4
| u32
| '''Unknown section 2 number'''
| 1
| '''Portal Area Section'''
| Section index for portal area data.
|-
|-
| 0x6C
| 0x6C
| 4
| u32
| '''EGMC section number'''
| 1
| '''Static Geometry Map Section'''
| Section index for static geometry map data.
|-
|-
| 0x70
| 0x70
| 4
| u32
| '''Compressed cluster count'''
| 1
| '''Compressed Block Count'''
| Number of compressed data blocks in the file.
|-
|-
| 0x74
| 0x74
| 0xC
| u32
| 3
| '''Padding'''
| '''Padding'''
| Padding bytes that align the file with the next multiple-of-32 offset.
|-
|-
| 0x80
| 0x80
| 4 &times; SC
| u32
| '''Section sizes'''
| ''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.
|-
|-
| colspan=3 {{unknown|Pad to 32 bytes before compressed cluster definitions begins}}
| colspan=5 {{unknown|Pad to 32 bytes before compressed block definitions begins}}
|}
|}


Following the section sizes comes an array defining the file's compressed cluster. Each definition is 0x10 bytes and is formatted like this:
==== Compressed Blocks ====
 
The MREA format contains compressed blocks that can each contain a number of regular file sections within them. The data defining these blocks is at the end of the MREA header; the beginning and end of the compressed block list is padded to 32 bytes. The decompressed size of a block is capped at 0x20000 bytes; each section contains as many MREA sections as it can fit under that size limit. There are two exceptions:
 
* If a single section's uncompressed size is larger than 0x20000, then its corresponding compressed block can exceed the size limit.
* Each SCLY and SCGN layer is always in its own block, regardless of how close to the limit it is.
 
This is the structure of each block definition:


{| class="wikitable"
{| class="wikitable"
! Offset
! Offset
! Size
! Type
! Description
! Count
! Name
! Notes
|-
|-
| 0x0
| 0x0
| 4
| u32
| '''Buffer size''' (usually 0x120 bytes bigger than uncompressed size)
| 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
| 0x4
| 4
| u32
| '''Uncompressed size'''
| 1
| '''Uncompressed Size'''
|
|-
|-
| 0x8
| 0x8
| 4
| u32
| '''Compressed size''' (if 0, that indicates an uncompressed cluster)
| 1
| '''Compressed Size'''
| This is 0 on uncompressed blocks.
|-
|-
| 0xC
| 0xC
| 4
| u32
| '''Section count''' (the number of regular sections contained in this cluster)
| 1
| '''Data Section Count'''
| The number of regular data sections contained in this block.
|-
|-
| 0x10
| 0x10
| colspan=2 {{unknown|Cluster definition end}}
| colspan=5 {{unknown|Block definition end}}
|}
 
The actual data contained in these blocks is 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. Thee data is compressed using segmented LZO1X-999; the "segmented" part 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).
 
=== World Geometry ===
''See [[MREA (Metroid Prime)#World Geometry]], [[Materials (Metroid Prime)]] and [[Geometry (Metroid Prime)]]''
 
Largely [[MREA (Metroid Prime)#World Geometry|the same as Prime 1]]. There are two new sections to watch out for on each world model (described on the [[Geometry (Metroid Prime)]] page). There's two sections that are now grouped under the same section number as world geometry.
 
==== Area Octree ====
 
The [[MREA (Metroid Prime)#Area Octree|area octree]] section is back from Prime 1, but no longer has its own section number - it's now grouped under the same section number as world geometry.
 
==== Surface Group Bounding Boxes ====
 
This is a new section introduced in Metroid Prime 2, which is grouped under the world geometry section number and appears after the area octree. It contains an array of a structure that provides the bounding box for every surface group. The first entry in the array has the combined bounding box for all of the world geometry in the entire area, then each surface group is listed in order.
 
{| class="wikitable"
! Type
! Count
! Name
! Notes
|-
| u32
| 1
| '''Group Bounds Entry Count'''
| Count of elements in the following array.
|-
| [[#Group Bounds|Group Bounds Entry]]
| ''Group Bounds Entry Count''
| '''Group Bounds Entry Array'''
| Array of a struct that provides the bounding box for each surface group in the area.
|}
 
===== Group Bounds Entry =====
 
{| class="wikitable"
! Offset
! Type
! Count
! Name
! Notes
|-
| 0x0
| float
| 6
| '''Group Bounding Box'''
| Axis-aligned bounding box of all surfaces contained in the group.
|-
| 0x18
| u16
| 1
| '''World Model Index'''
| Index of the world model that contains this group.
|-
| 0x1A
| u16
| 1
| '''Surface Group Index'''
| Model-relative index of the surface group.
|-
| 0x1C
| u16
| 1
| {{unknown|Unknown}}
| On the first entry, always 1. On other entries, always -1.
|-
| 0x1E
| u16
| 1
| {{unknown|Unknown}}
| On the first entry, always -1. On other entries, always the entry's index position + 1.
|-
| 0x20
| colspan=4 {{unknown|End of bounds entry}}
|}
 
=== Unknown Section 1 ===
 
This section appears to be related to world geometry.
 
{| class="wikitable"
! Type
! Count
! Name
! Notes
|-
| u32
| 1
| '''Element Count 1'''
| Count of elements in the next array. Always 0 in light world areas.
|-
| u32
| ''Element Count 1''
| {{unknown|Unknown}}
| May also be a pair of u16s?
|-
| u32
| 1
| '''Element Count 2'''
| Count of elements in the next array. Matches the area's surface group count.
|-
| u8
| ''Element Count 2''
| {{unknown|Unknown}}
| Every entry is always 0xFF in light world areas. Dark world appears to include both 0x00 and 0xFF?
|-
| colspan=4 {{unknown|End of section}}
|}
|}
=== Collision ===
''Main article: [[Area Collision (File Format)]]''
=== Path ===
This section only contains a single [[PATH (File Format)|PATH]] asset ID.
{| class="wikitable"
! Type
! Count
! Name
|-
| Asset ID
| 1
| '''Area PATH Resource'''
|-
| colspan=3 {{unknown|End of section}}
|}
=== Portal Area ===
This section only contains a single [[PTLA (File Format)|PTLA]] asset ID.
{| class="wikitable"
! Type
! Count
! Name
|-
| Asset ID
| 1
| '''Area PTLA Resource'''
|-
| colspan=3 {{unknown|End of section}}
|}
=== Static Geometry Map ===
This section only contains a single [[EGMC (File Format)|EGMC]] asset ID.
{| class="wikitable"
! Type
! Count
! Name
|-
| Asset ID
| 1
| '''Area EGMC Resource'''
|-
| colspan=3 {{unknown|End of section}}
|}
[[Category:File Formats]]
[[Category:Metroid Prime 2: Echoes]]

Latest revision as of 21:07, 24 January 2022

See MREA (File Format) for the other revisions of this format.

The MREA format defines areas (rooms) in Metroid Prime 2. It serves the same purpose as the MREA files from Prime 1, but in Echoes it was updated with new features, including some new data sections and the ability to compress most of the data in the file.


To do:
Rest of the article needs to be written. There's a lot known about this format that should be documented.

Format

Like CMDL, 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.

These are the sections in each MREA file, in the order they appear in the file:

Identifier Name
World Geometry
Unknown Section 1
SCLY Script Layers
SCGN Generated Script Objects
0xDEAFBABE Collision
Unknown Section 2
0xBABEDEAD Lights
VISI Visibility Tree
Path
Portal Area
Static Geometry Map

Header

Offset Type Count Name Description
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 Geometry Section Section index for world geometry data. Always 0; starts on materials.
0x48 u32 1 Script Layers Section Section index for script layer data.
0x4C u32 1 Generated Script Objects Section Section index for generated script object data.
0x50 u32 1 Collision Section Section index for collision data.
0x54 u32 1 Unknown Section 1 Section index for first unknown section.
0x58 u32 1 Lights Section Section index for light data.
0x5C u32 1 Visibility Tree Section Section index for visibility tree data.
0x60 u32 1 Path Section Section index for path data.
0x64 u32 1 Unknown Section 2 Section index for second unknown section.
0x68 u32 1 Portal Area Section Section index for portal area data.
0x6C u32 1 Static Geometry Map Section Section index for static geometry map data.
0x70 u32 1 Compressed Block Count Number of compressed data blocks in the file.
0x74 u32 3 Padding Padding bytes that align the file with the next multiple-of-32 offset.
0x80 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.
Pad to 32 bytes before compressed block definitions begins

Compressed Blocks

The MREA format contains compressed blocks that can each contain a number of regular file sections within them. The data defining these blocks is at the end of the MREA header; the beginning and end of the compressed block list is padded to 32 bytes. The decompressed size of a block is capped at 0x20000 bytes; each section contains as many MREA sections as it can fit under that size limit. There are two exceptions:

  • If a single section's uncompressed size is larger than 0x20000, then its corresponding compressed block can exceed the size limit.
  • Each SCLY and SCGN layer is always in its own block, regardless of how close to the limit it is.

This is the structure of each block definition:

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

The actual data contained in these blocks is 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. Thee data is compressed using segmented LZO1X-999; the "segmented" part 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).

World Geometry

See MREA (Metroid Prime)#World Geometry, Materials (Metroid Prime) and Geometry (Metroid Prime)

Largely the same as Prime 1. There are two new sections to watch out for on each world model (described on the Geometry (Metroid Prime) page). There's two sections that are now grouped under the same section number as world geometry.

Area Octree

The area octree section is back from Prime 1, but no longer has its own section number - it's now grouped under the same section number as world geometry.

Surface Group Bounding Boxes

This is a new section introduced in Metroid Prime 2, which is grouped under the world geometry section number and appears after the area octree. It contains an array of a structure that provides the bounding box for every surface group. The first entry in the array has the combined bounding box for all of the world geometry in the entire area, then each surface group is listed in order.

Type Count Name Notes
u32 1 Group Bounds Entry Count Count of elements in the following array.
Group Bounds Entry Group Bounds Entry Count Group Bounds Entry Array Array of a struct that provides the bounding box for each surface group in the area.
Group Bounds Entry
Offset Type Count Name Notes
0x0 float 6 Group Bounding Box Axis-aligned bounding box of all surfaces contained in the group.
0x18 u16 1 World Model Index Index of the world model that contains this group.
0x1A u16 1 Surface Group Index Model-relative index of the surface group.
0x1C u16 1 Unknown On the first entry, always 1. On other entries, always -1.
0x1E u16 1 Unknown On the first entry, always -1. On other entries, always the entry's index position + 1.
0x20 End of bounds entry

Unknown Section 1

This section appears to be related to world geometry.

Type Count Name Notes
u32 1 Element Count 1 Count of elements in the next array. Always 0 in light world areas.
u32 Element Count 1 Unknown May also be a pair of u16s?
u32 1 Element Count 2 Count of elements in the next array. Matches the area's surface group count.
u8 Element Count 2 Unknown Every entry is always 0xFF in light world areas. Dark world appears to include both 0x00 and 0xFF?
End of section

Collision

Main article: Area Collision (File Format)

Path

This section only contains a single PATH asset ID.

Type Count Name
Asset ID 1 Area PATH Resource
End of section

Portal Area

This section only contains a single PTLA asset ID.

Type Count Name
Asset ID 1 Area PTLA Resource
End of section

Static Geometry Map

This section only contains a single EGMC asset ID.

Type Count Name
Asset ID 1 Area EGMC Resource
End of section