CMDL (Donkey Kong Country Returns): Difference between revisions

Jump to navigation Jump to search
no edit summary
imported>Antidote
No edit summary
>Aruki
No edit summary
Line 94: Line 94:
==== Visibility Groups ====
==== Visibility Groups ====


This section is present in the header if bit 0x10 is set, after the material set count and before the section sizes.
This data chunk is present in the header if bit 0x10 is set, after the material set count and before the section sizes.


{| class="wikitable"
{| class="wikitable"
Line 169: Line 169:


There's not much known about the material format currently; DKCR seems to use the same material format as Metroid Prime 3. The main difference in DKCR compared to Prime 3 is that in Prime 3, each material set would get its own section. In DKCR, every material set is in the same section. Each material set begins with a material count, and each material begins with its own size. The main thing that's needed to read geometry is the vertex attribute flags, which are located at 0xC in the material structure (not counting the size).
There's not much known about the material format currently; DKCR seems to use the same material format as Metroid Prime 3. The main difference in DKCR compared to Prime 3 is that in Prime 3, each material set would get its own section. In DKCR, every material set is in the same section. Each material set begins with a material count, and each material begins with its own size. The main thing that's needed to read geometry is the vertex attribute flags, which are located at 0xC in the material structure (not counting the size).
=== Geometry ===
==== Vertex Coordinates ====
Vertex coords can be stored as either floats or signed shorts, depending whether flag 0x20 is set in the header. If they're shorts, then they need to be divided by 0x2000 to get the corresponding float value. Since they're signed numbers, that means that 0 to 0x7FFF correspond to the range 0.0-4.0, and 0x8000 to 0xFFFF correspond to the range -4.0-0.0.
==== Normals ====
Vertex normals are usually stored as shorts.
==== Vertex Color ====
Normally unused, so this section is typically empty and zeroed out.
==== Float UV Coordinates ====
These are stored as a sequence of two floats.
==== Short UV Coordinates ====
Like the short vertex coordinates, these are stored as signed shorts that should be divided by 0x2000 to get the corresponding float value. The short UVs section has received a fairly significant increase in usage in DKCR compared to the Prime series; in the Prime games, they were generally only used for lightmaps, whereas in DKCR they're often used by pretty much anything.
==== Submesh Definitions ====
This section is very small and simple; it simply declares a submesh count and then lists the offsets to the end of each submesh. Following this section, there'll be one additional section per submesh.
{| class="wikitable"
! Offset
! Type
! Size
! Description
|-
| 0x0
| u32
| 4
| '''Submesh count''' (SC)
|-
| 0x4
| u32[]
| 4 × SC
| '''Submesh offsets''' (relative to the start of the first submesh)
|-
| colspan=4 {{unknown|Submesh sections begin}}
|}
==== Submesh ====
There will be one of these sections per submesh. Each submesh starts with a small 0x20-byte header; after that, the primitive data begins.
{| class="wikitable"
! Offset
! Type
! Size
! Description
|-
| 0x0
| float[3]
| 0xC
| '''Position''' (or pivot location); unknown purpose
|-
| 0xC
| u16
| 4
| '''Mantissa'''  - always 0x8000
|-
| 0xE
| u16
| 2
| '''Primitive table size''' (''this value may not be reliable'')
|-
| 0x10
| u32
| 4
| {{unknown|'''Unknown'''; always 0?}}
|-
| 0x14
| u32
| 4
| {{unknown|'''Unknown'''; always 0?}}
|-
| 0x18
| u16
| 2
| {{unknown|'''Unknown'''; value varies, but is sometimes 0xFFFF
|-
| 0x1A
| u16
| 2
| '''Material ID'''
|-
| 0x1C
| u8
| 1
| {{unknown|'''Unknown'''; always 0xFF?}}
|-
| 0x1D
| u8
| 1
| '''Visibility Group index'''
|-
| 0x1E
| u16
| 2
| '''UV array flag'''; 0 indicates this submesh uses float UVs, 1 indicates it uses short UVs
|-
| 0x20
| colspan=3 {{unknown|End of header; 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. After that is a 16-bit vertex count, followed by a series of 16-bit vertex attribute indices.
You'll need to check some settings on the material to read the primitive data properly; the material determines which vertex attributes are present.
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 submesh's section size, or the submesh's end offset. It's not recommended to use the primitive table size value because that value has been shown to be inaccurate in some cases in the Prime series and this may be the case in DKCR as well.
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.
{| class="wikitable"
! Value
! Primitive
|-
| 0x80
| Quads
|-
| 0x90
| Triangles
|-
| 0x98
| Triangle strip
|-
| 0xA0
| Triangle fan
|-
| 0xA8
| Lines
|-
| 0xB0
| Line strip
|-
| 0xB8
| Points
|}
[[Category:File Formats]]
[[Category:Donkey Kong Country Returns]]
[[Category:Donkey Kong Country Returns]]
Anonymous user

Navigation menu