Geometry (Metroid Prime): Difference between revisions

m
Reverted edits by Antidote (talk) to last revision by [[User:imported>Darkszero|imported>Darkszero]]
>Aruki
m (Reverted edits by Antidote (talk) to last revision by [[User:imported>Darkszero|imported>Darkszero]])
Tag: Rollback
 
(7 intermediate revisions by 3 users not shown)
Line 53: Line 53:
| u32
| u32
| ''Surface Count''
| ''Surface Count''
| '''Surface Offsets'''
| '''Surface End Offsets'''
| Relative to the start address of the first surface.
| Relative to the start address of the first surface.
|-
|-
Line 65: Line 65:
{| class="wikitable"
{| class="wikitable"
! Offset
! Offset
! Size
! Type
! Description
! Count
! Name
! Notes
! Notes
|-
|-
| 0x0
| 0x0
| 0xC
| float
| '''Center point'''
| 3
| '''Center Point'''
| Used for depth sorting on CMDL and used as the eye position for reflections
| Used for depth sorting on CMDL and used as the eye position for reflections
|-
|-
| 0xC
| 0xC
| 4
| u32
| '''Material ID'''
| 1
| '''Material Index'''
|  
|  
|-
|-
| 0x10
| 0x10
| 2
| u16
| 1
| '''Mantissa'''
| '''Mantissa'''
| Divide short normals/UVs by this value; always 0x8000
| Always 0x8000.
|-
|-
| 0x12
| 0x12
| 2
| u16
| '''Primitive table size'''  
| 1
| '''Display List Size'''  
| '''Important: this value is not always reliable'''
| '''Important: this value is not always reliable'''
|-
|-
| 0x14
| 0x14
| 4
| u32
| '''CCubeModel pointer storage'''
| 1
| Always 0 in resource; game uses this space to store parent CCubeModel instance pointer
| '''Parent Model Pointer Storage'''
| Always 0; the game uses this space at runtime to store a pointer to the parent CCubeModel instance
|-
|-
| 0x18
| 0x18
| 4
| u32
| '''Next surface pointer storage'''
| 1
| Always 0 in resource; game uses this space to store next surface data pointer
| '''Next Surface Pointer Storage'''
| Always 0; the game uses this space at runtime to store a pointer to the next surface
|-
|-
| 0x1C
| 0x1C
| 4
| u32
| '''Extra data size''' (ES)
| 1
| '''Extra Data Size'''
| Amount of space taken up by extra data. Always 0 on CMDLs, 0x18 on MREAs.
| Amount of space taken up by extra data. Always 0 on CMDLs, 0x18 on MREAs.
|-
|-
| 0x20
| 0x20
| 0xC
| float
| '''Surface normal'''
| 3
| '''Surface Normal'''
| On materials that use the Samus reflection, this is used to project the reflection onto the surface
| On materials that use the Samus reflection, this is used to project the reflection onto the surface
|-
|-
| 0x2C
| 0x2C
| 2
| u16
| {{unknown|'''Unknown'''}}
| 1
| Not in Prime 1
| {{unknown|Unknown}}
| Not in Prime 1.
|-
|-
| 0x2E
| 0x2E
| 2
| u16
| {{unknown|'''Unknown'''}}
| 1
| Not in Prime 1
| {{unknown|Unknown}}
| Not in Prime 1.
|-
|-
| 0x30
| 0x30
| ES
| u8
| '''Extra data'''
| ''Extra Data Size''
| Empty on CMDL; contains a bounding box used for depth sorting on MREA
| '''Extra Data'''
| Empty on CMDL; contains a bounding box used for depth sorting on MREA.
|-
|-
| colspan=4 {{unknown|End of surface header; pad to multiple of 32 before primitive data starts}}
| colspan=5 {{unknown|End of surface header; pad to multiple of 32 before primitive data starts}}
|}
|}


The primitive data is a standard GX display list. Each primitive begins with a byte that contains the primitive type in the upper 5 bits, and the vertex format setting in the lower 3; see below for possible settings. After that is a 16-bit vertex count, followed by a series of 16-bit vertex attribute indices.
The primitive data is a GX display list. Each primitive begins with a byte that contains the primitive type in the upper 5 bits, and the vertex format setting in the lower 3; see below for possible settings. After that is a 16-bit vertex count, followed by a series of 16-bit vertex attribute indices.


Note that you'll need to check some settings on the material to read the primitive data properly; the material determines which vertex attributes are present. The material also determines whether the surface is using lightmaps; if it is, then the first UV coordinate will be read out of the short UV array instead of the float one.
Note that you'll need to check some settings on the material to read the primitive data properly; the material determines which vertex attributes are present. The material also determines whether the surface is using lightmaps; if it is, then the first UV coordinate will be read out of the short UV array instead of the float one.


There is no primitive count value; you'll need to continue reading data until you hit the end of the primitive table. There are a couple values you can use for reference; either the surface's section size, or the surface's end offset. '''Do not use the primitive table size setting from the surface header, though'''; it's usually accurate, but on some models it will give you a size smaller than the table actually is, and you'll miss a bunch of data. See Metroid3/4a11192a.CMDL from Prime 1 (icicle Ridley) or Metroid1/05778239.CMDL from Echoes (Samus's gunship) for an example of this.
There is no primitive count value; you'll need to continue reading data until you hit the end of the display list. There are a couple values you can use for reference; either the surface's section size, or the surface's end offset. '''Do not use the display list size setting from the surface header, though'''; it's usually accurate, but on some models it will give you a size smaller than the table actually is, and you'll miss a bunch of data. See Metroid3/4a11192a.CMDL from Prime 1 (icicle Ridley) or Metroid1/05778239.CMDL from Echoes (Samus's gunship) for an example of this.


There are 7 primitive types supported by GX, indicated in the upper 5 bits of the flag value. Note that the game only ever actually uses triangles, triangle strips, and triangle fans; however, all of these primitives are supported by GX and are therefore supported by the game, and so they could be used in custom model files.
There are 7 primitive types supported by GX, indicated in the upper 5 bits of the flag value. Note that the game only ever actually uses triangles, triangle strips, and triangle fans; however, all of these primitives are supported by GX and are therefore supported by the game, and so they could be used in custom model files.
Line 146: Line 158:
|-
|-
| 0x98
| 0x98
| Triangle strip
| Triangle Strip
|-
|-
| 0xA0
| 0xA0
| Triangle fan
| Triangle Fan
|-
|-
| 0xA8
| 0xA8
Line 155: Line 167:
|-
|-
| 0xB0
| 0xB0
| Line strip
| Line Strip
|-
|-
| 0xB8
| 0xB8