CMDL (Donkey Kong Country Returns): Difference between revisions

From Retro Modding Wiki
Jump to navigation Jump to search
>Cornyfisch
(Fixed mantissa byte size)
>Aruki
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
The '''CMDL format''' is DKCR's model format. It's similar to the CMDL format found in the Metroid Prime trilogy, but with a lot of additions and changes, and some layout changes.
The '''CMDL format''' is DKCR's model format. It's similar to the CMDL format found in the Metroid Prime trilogy, but with a lot of additions and changes, and some layout changes.


{{research|moderate|Where to begin? Materials need a lot of research (they're very similar if not the same as Metroid Prime 3). A lot of the visibility group data is unknown. The submesh headers contain a lot of unknowns, and the possible vertex format settings are unknown. Geometry should be split off into a separate article if it's confirmed that it's the same format that's used in MREA (which is fairly likely). Materials should also be split off once more is known about them.}}
{{research|moderate|The visibility group data in the header has a lot of unknown values.}}


__TOC__
__TOC__
Line 16: Line 16:
! Offset
! Offset
! Type
! Type
! Size
! Count
! Description
! Name
! Notes
|-
|-
| 0x0
| 0x0
| u32
| u16
| 4
| 1
| {{unknown|'''Unknown'''; always 0x9381000A - likely either magic value or 16-bit magic/version}}
| '''Magic'''
| Always <code>0x9381</code>
|-
| 0x2
| u16
| 1
| '''Version'''
| Always 0xA. See [[CMDL (File Format)|hub article]] for a list of possible version numbers.
|-
|-
| 0x4
| 0x4
| u32
| u32
| 4
| 1
| '''Flags'''; see below
| '''Flags'''
| [[#Flags|See below]]
|-
|-
| 0x8
| 0x8
| float[6]
| float
| 0x18
| 6
| '''Model Bounding Box'''
| '''Model Bounding Box'''
|
|-
|-
| 0x20
| 0x20
| u32
| u32
| 4
| 1
| '''Section count''' (SC)
| '''Section Count'''
| Count of data sections in the file.
|-
|-
| 0x24
| 0x24
| u32
| u32
| 4
| 1
| '''Material set count'''
| '''Material Set Count'''
| Count of material sets in the model.
|-
|-
| 0x28
| 0x28
| -
| [[#Visibility Groups|Visibility Groups]]
| -
| 1
| '''Visibility group data'''; present if flag 0x10 is set. See below for structure.
| '''Visibility Group Data'''
| Only present if flag 0x10 is set.
|-
|-
| -
| {{none}}
| u32[]
| u32
| 4 &times; SC
| ''Section Count''
| '''Section sizes'''
| '''Section Sizes'''
|
|-
|-
| colspan=4 {{unknown|End of header; pad to multiple of 32 before first section starts}}
| colspan=5 {{unknown|End of header; pad to multiple of 32 before first section starts}}
|}
|}


Line 68: Line 82:
| 0
| 0
| 0x1
| 0x1
| {{unknown|Unknown}}
| Indicates the model is skinned
|-
|-
| 1
| 1
Line 93: Line 107:
==== Visibility Groups ====
==== Visibility Groups ====


Visibility group data is present in the header if bit 0x10 is set, after the material set count and before the section sizes. Visibility groups are used to toggle the visibility of certain meshes on or off during animations; for instance, Diddy's jetpack.
Visibility group data is present in the header if bit 0x10 is set, after the material set count and before the section sizes. Visibility groups are used to toggle the visibility of certain surfaces on or off during animations; for instance, Diddy's jetpack is part of his model but doesn't render in most of his animations.


{| class="wikitable"
{| class="wikitable"
! Offset
! Offset
! Type
! Type
! Size
! Count
! Description
! Name
! Notes
|-
|-
| 0x0
| 0x0
| u32
| u32
| 4
| 1
| {{unknown|'''Unknown'''}}
| {{unknown|'''Unknown'''}}
|
|-
|-
| 0x4
| 0x4
| u32
| u32
| 4
| 1
| '''Visibility Group count'''
| '''Visibility Group Count'''
|}
|  
 
The following structure repeats for each group:
 
{| class="wikitable"
! Offset
! Type
! Size
! Description
|-
|-
| 0x0
| 0x8
| u32
| [[#Visibility Group Name|Visibility Group Name]]
| 4
| ''Visibility Group Count''
| '''Name length'''
| '''Visibility Group Name Array'''
|-
|  
| 0x4
| string
| -
| '''Visibility Group name'''
|}
 
Finally, it ends with this before the sizes begin:
 
{| class="wikitable"
! Offset
! Type
! Size
! Description
|-
|-
| 0x0
| {{none}}
| u32
| u32
| 4
| 1
| {{unknown|'''Unknown'''}}
| {{unknown|'''Unknown'''}}
|
|-
|-
| 0x4
| {{none}}
| u32
| u32
| 4
| 1
| {{unknown|'''Unknown'''}}
| {{unknown|'''Unknown'''}}
|
|-
|-
| 0x8
| {{none}}
| u32
| u32
| 4
| 1
| {{unknown|'''Unknown'''}}
| {{unknown|'''Unknown'''}}
|
|-
|-
| 0xC
| {{none}}
| u32
| u32
| 4
| 1
| {{unknown|'''Unknown'''}}
| {{unknown|'''Unknown'''}}
|
|-
|-
| 0x10
| {{none}}
| u32
| u32
| 4
| 1
| {{unknown|'''Unknown'''}}
| {{unknown|'''Unknown'''}}
|
|}
|}


=== Materials ===
===== Visibility Group Name =====
 
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. To get the corresponding float value, read as a signed short and divide by 0x4000.
 
==== 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 &times; 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"
{| class="wikitable"
! Offset
! Offset
! Type
! Type
! Size
! Count
! Description
! Name
! Notes
|-
|-
| 0x0
| 0x0
| float[3]
| 0xC
| '''Position''' (or pivot location); unknown purpose
|-
| 0xC
| u16
| 2
| '''Mantissa'''  - always 0x8000
|-
| 0xE
| u16
| 2
| '''Primitive table size''' (''this value may not be reliable'')
|-
| 0x10
| u32
| 4
| {{unknown|'''Unknown'''; always 0?}}
|-
| 0x14
| u32
| 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
| 1
| {{unknown|'''Unknown'''; always 0xFF?}}
| '''Name Length'''
|
|-
|-
| 0x1D
| 0x4
| u8
| char
| 1
| ''Name Length''
| '''Visibility Group index'''
| '''Visibility Group Name'''
|-
| Zero-terminated.
| 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.
=== Materials ===


You'll need to check some settings on the material to read the primitive data properly; the material determines which vertex attributes are present.
''See [[Materials (Metroid Prime 3)]]''


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.
DKCR uses the same material format as Metroid Prime 3, with the main differences being what pass types and UV animation modes are supported (a few have been added/removed). The only other significant 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.


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.
=== Geometry ===


{| class="wikitable"
''See [[Geometry (Donkey Kong Country Returns)]]''
! Value
! Primitive
|-
| 0x80
| Quads
|-
| 0x90
| Triangles
|-
| 0x98
| Triangle strip
|-
| 0xA0
| Triangle fan
|-
| 0xA8
| Lines
|-
| 0xB0
| Line strip
|-
| 0xB8
| Points
|}


[[Category:File Formats]]
[[Category:File Formats]]
[[Category:Donkey Kong Country Returns]]
[[Category:Donkey Kong Country Returns]]

Latest revision as of 12:49, 8 September 2016

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

The CMDL format is DKCR's model format. It's similar to the CMDL format found in the Metroid Prime trilogy, but with a lot of additions and changes, and some layout changes.


This file format needs more research
The visibility group data in the header has a lot of unknown values.


Format

Like the previous CMDL formats, DKCR CMDL 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

Offset Type Count Name Notes
0x0 u16 1 Magic Always 0x9381
0x2 u16 1 Version Always 0xA. See hub article for a list of possible version numbers.
0x4 u32 1 Flags See below
0x8 float 6 Model Bounding Box
0x20 u32 1 Section Count Count of data sections in the file.
0x24 u32 1 Material Set Count Count of material sets in the model.
0x28 Visibility Groups 1 Visibility Group Data Only present if flag 0x10 is set.
u32 Section Count Section Sizes
End of header; pad to multiple of 32 before first section starts

Flags

The following flags are possible:

Bit Hex Description
0 0x1 Indicates the model is skinned
1 0x2 Unknown
2 0x4 Unknown
3 0x8 Unknown
4 0x10 Enable visibility groups
5 0x20 Store vertex positions as shorts

Visibility Groups

Visibility group data is present in the header if bit 0x10 is set, after the material set count and before the section sizes. Visibility groups are used to toggle the visibility of certain surfaces on or off during animations; for instance, Diddy's jetpack is part of his model but doesn't render in most of his animations.

Offset Type Count Name Notes
0x0 u32 1 Unknown
0x4 u32 1 Visibility Group Count
0x8 Visibility Group Name Visibility Group Count Visibility Group Name Array
u32 1 Unknown
u32 1 Unknown
u32 1 Unknown
u32 1 Unknown
u32 1 Unknown
Visibility Group Name
Offset Type Count Name Notes
0x0 u32 1 Name Length
0x4 char Name Length Visibility Group Name Zero-terminated.

Materials

See Materials (Metroid Prime 3)

DKCR uses the same material format as Metroid Prime 3, with the main differences being what pass types and UV animation modes are supported (a few have been added/removed). The only other significant 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.

Geometry

See Geometry (Donkey Kong Country Returns)