(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page is about the 3DS CGFX 3d format.
Offsets
All offsets in CGFX are self-relative. That means that the file offset of the offset itself has to be added to the offset.
So if you got an offset of 0x14 at address 0x80, it points to 0x80 + 0x14 = 0x94. And if it is 0x14 at 0x90, it points to 0x90 + 0x14 = 0xA4.
DICT
A dictionary is a common way used in CGFX files to store the offset to some data with a name. This is the structure:
Offset |
Length |
Type |
Description
|
0x00 |
0x04 |
String |
Signature (DICT)
|
0x04 |
0x04 |
UInt32 |
Section Size
|
0x08 |
0x04 |
UInt32 |
Nr Entries (excluding the root entry, so add 1)
|
After this, the entries follow
|
This is the structure of one entry:
Offset |
Length |
Type |
Description
|
0x00 |
0x04 |
UInt32 |
Refbit
|
0x04 |
0x02 |
UInt16 |
Left Node Index
|
0x06 |
0x02 |
UInt16 |
Right Node Index
|
0x08 |
0x04 |
UInt32 |
Name Offset
|
0x0C |
0x04 |
UInt32 |
Data Offset
|
Offset |
Length |
Type |
Description
|
0x00 |
0x04 |
String |
Signature (CGFX)
|
0x04 |
0x02 |
UInt16 |
Endianness
|
0x06 |
0x04 |
UInt16 |
Header Size (0x14)
|
0x0A |
0x02 |
UInt32 |
Version
|
0x0C |
0x04 |
UInt32 |
File Size
|
0x10 |
0x04 |
UInt32 |
Nr Blocks (1 or 2)
|
DATA
Offset |
Length |
Type |
Description
|
0x00 |
0x04 |
String |
Signature (DATA)
|
0x04 |
0x04 |
UInt32 |
Section Size
|
0x08 |
0x04 |
UInt32 |
Nr Models
|
0x0C |
0x04 |
UInt32 |
Models DICT Offset (0 if Nr Models = 0)
|
0x10 |
0x04 |
UInt32 |
Nr Textures
|
0x14 |
0x04 |
UInt32 |
Textures DICT Offset (0 if Nr Textures = 0)
|
0x18 |
0x04 |
UInt32 |
Nr Look Up Tables
|
0x1C |
0x04 |
UInt32 |
Look Up Tables DICT Offset (0 if Nr Look Up Tables = 0)
|
0x20 |
0x04 |
UInt32 |
Nr Materials (not the ones inside a model)
|
0x24 |
0x04 |
UInt32 |
Materials DICT Offset (0 if Nr Material = 0)
|
0x28 |
0x04 |
UInt32 |
Nr Shaders
|
0x2C |
0x04 |
UInt32 |
Shaders DICT Offset (0 if Nr Shaders = 0)
|
0x30 |
0x04 |
UInt32 |
Nr Cameras
|
0x34 |
0x04 |
UInt32 |
Cameras DICT Offset (0 if Nr Cameras = 0)
|
0x38 |
0x04 |
UInt32 |
Nr Lights
|
0x3C |
0x04 |
UInt32 |
Lights DICT Offset (0 if Nr Lights = 0)
|
0x40 |
0x04 |
UInt32 |
Nr Fogs
|
0x44 |
0x04 |
UInt32 |
Fogs DICT Offset (0 if Nr Fogs = 0)
|
0x48 |
0x04 |
UInt32 |
Nr Environments
|
0x4C |
0x04 |
UInt32 |
Environments DICT Offset (0 if Nr Environments = 0)
|
0x50 |
0x04 |
UInt32 |
Nr Bone Animations
|
0x54 |
0x04 |
UInt32 |
Bone Animations DICT Offset (0 if Nr Bone Animations = 0)
|
0x58 |
0x04 |
UInt32 |
Nr Material Animations
|
0x5C |
0x04 |
UInt32 |
Material Animations DICT Offset (0 if Nr Material Animations = 0)
|
0x60 |
0x04 |
UInt32 |
Nr Visibility Animations
|
0x64 |
0x04 |
UInt32 |
Visibility Animations DICT Offset (0 if Nr Visibility Animations = 0)
|
0x68 |
0x04 |
UInt32 |
Nr Camera Animations
|
0x6C |
0x04 |
UInt32 |
Camera Animations DICT Offset (0 if Nr Camera Animations = 0)
|
0x70 |
0x04 |
UInt32 |
Nr Light Animations
|
0x74 |
0x04 |
UInt32 |
Light Animations DICT Offset (0 if Nr Light Animations = 0)
|
0x78 |
0x04 |
UInt32 |
Nr Emitters
|
0x7C |
0x04 |
UInt32 |
Emitters DICT Offset (0 if Nr Emitters = 0)
|
The following data does not always exist.
|
0x80 |
0x04 |
UInt32 |
Nr Particles
|
0x84 |
0x04 |
UInt32 |
Particles DICT Offset (0 if Nr Particles = 0)
|
Models (CMDL)
The data offset in the Models DICT points to this structure:
Offset |
Length |
Type |
Description
|
0x00 |
0x04 |
UInt32 |
Type Flags
|
0x04 |
0x04 |
String |
Signature (CMDL)
|
0x08 |
0x04 |
UInt32 |
Revision
|
0x0C |
0x04 |
UInt32 |
Name Offset
|
0x10 |
0x04 |
UInt32 |
?
|
0x14 |
0x04 |
UInt32 |
?
|
0x18 |
0x04 |
UInt32 |
?
|
0x1C |
0x04 |
UInt32 |
?
|
0x20 |
0x04 |
UInt32 |
?
|
0x24 |
0x04 |
UInt32 |
?
|
0x28 |
0x04 |
UInt32 |
Nr Animation Types
|
0x2C |
0x04 |
UInt32 |
Animation Type Info DICT Offset
|
0x30 |
0x0C |
Vector3 |
Scale
|
0x3C |
0x0C |
Vector3 |
Rotation
|
0x48 |
0x0C |
Vector3 |
Translation
|
0x54 |
0x30 |
Matrix43 |
Local Matrix
|
0x84 |
0x30 |
Matrix43 |
World Matrix
|
0xB4 |
0x04 |
UInt32 |
Nr Meshes
|
0xB8 |
0x04 |
UInt32 |
Mesh Offset List Offset
|
0xBC |
0x04 |
UInt32 |
Nr Materials
|
0xC0 |
0x04 |
UInt32 |
Materials DICT Offset
|
0xC4 |
0x04 |
UInt32 |
Nr Shapes
|
0xC8 |
0x04 |
UInt32 |
Shape Offset List Offset
|
0xCC |
0x04 |
UInt32 |
Nr Mesh Nodes
|
0xD0 |
0x04 |
UInt32 |
Mesh Nodes Visibility DICT Offset
|
0xD4 |
0x04 |
UInt32 |
?
|
0xD8 |
0x04 |
UInt32 |
?
|
0xDC |
0x04 |
UInt32 |
?
|
The following data only exists if bit 7 of Flags is set
|
0xE0 |
0x04 |
UInt32 |
Skeleton Info SOBJ Offset
|
Animation Type Info
Materials (MTOB)
Texture Info
Linked Texture Info (TXOB)
Shader (SHDR)
Offset |
Length |
Type |
Description
|
0x00 |
0x04 |
UInt32 |
Flags
|
0x04 |
0x04 |
String |
Signature (SHDR)
|
0x08 |
0x04 |
UInt32 |
Revision
|
0x0C |
0x04 |
UInt32 |
Name Offset
|
0x10 |
0x04 |
UInt32 |
?
|
0x14 |
0x04 |
UInt32 |
?
|
0x18 |
0x04 |
UInt32 |
Linked Vertex Shader Name Offset
|
0x1C |
0x04 |
UInt32 |
?
|
Fragment Shader
Offset |
Length |
Type |
Description
|
0x00 |
0x10 |
Color (4 x Float) |
Buffer Color
|
0x10 |
0x04 |
UInt32 |
?
|
0x14 |
0x04 |
UInt32 |
?
|
0x18 |
0x04 |
UInt32 |
?
|
0x1C |
0x04 |
UInt32 |
?
|
0x20 |
0x04 |
UInt32 |
?
|
0x24 |
0x04 |
UInt32 |
?
|
0x28 |
0x04 |
UInt32 |
Fragment Lighting Table Offset
|
0x2C |
0xA8 |
TexEnvInfo[6] |
Texture Environment Infos
|
0xD4 |
0x04 |
UInt32 |
?
|
0xD8 |
0x04 |
UInt32 |
?
|
0xDC |
0x04 |
Color (RGBA8) |
Buffer Color
|
0xE0 |
0x14 |
? |
? (unidentified)
|
Texture Environment Info
Offset |
Length |
Type |
Description
|
0x00 |
0x04 |
UInt32 |
Constant Color Type
|
0x04 |
0x02 |
UInt16 |
Source Rgb
|
0x06 |
0x02 |
UInt16 |
Source Alpha
|
0x08 |
0x04 |
UInt32 |
Texture Environment Command Header
|
0x0C |
0x04 |
UInt32 |
Operands
|
0x10 |
0x02 |
UInt16 |
Combine Rgb
|
0x12 |
0x02 |
UInt16 |
Combine Alpha
|
0x14 |
0x04 |
Color |
Constant Color
|
0x18 |
0x02 |
UInt16 |
Scale Rgb
|
0x1A |
0x02 |
UInt16 |
Scale Alpha
|
This is the content of both source values:
Bits |
Description
|
0-3 |
Source 1
|
4-7 |
Source 2
|
8-11 |
Source 3
|
12-15 |
Unused
|
Source ID |
Description
|
0x00 |
Primary Color
|
0x01 |
Fragment Lighting Primary Color
|
0x02 |
Fragment Lighting Secondary Color
|
0x03 |
Texture 0
|
0x04 |
Texture 1
|
0x05 |
Texture 2
|
0x06 |
Texture 3
|
0x07 |
Unknown/Unused
|
0x08 |
Unknown/Unused
|
0x09 |
Unknown/Unused
|
0x0A |
Unknown/Unused
|
0x0B |
Unknown/Unused
|
0x0C |
Unknown/Unused
|
0x0D |
Buffer Color
|
0x0E |
Constant Color
|
0x0F |
Previous Color (Output of previous stage)
|
This is the content of the operand value:
Bits |
Description
|
0-3 |
Rgb Operand 1
|
4-7 |
Rgb Operand 2
|
8-11 |
Rgb Operand 3
|
12-15 |
Alpha Operand 1
|
16-19 |
Alpha Operand 2
|
20-23 |
Alpha Operand 3
|
24-31 |
Unused
|
The operand values describe how the source values are used as input values for the combiner. The operands are not fully known yet, so it could be wrong. The source values are i1, i2 and i3. The output comes in j1, j2 and j3. The following table is for rgb:
Operand ID |
Description
|
0x00 |
i#.rgb (# is the current operand index)
|
0x01 |
vec3(1.0) - i#.rgb (# is the current operand index)
|
0x02 |
i#.aaa (# is the current operand index)
|
0x03 |
vec3(1.0) - i#.aaa (# is the current operand index)
|
0x04 |
i1.rgb
|
0x05 |
vec3(1.0) - i1.rgb
|
0x06 |
i1.aaa
|
0x07 |
vec3(1.0) - i1.aaa
|
0x08 |
i2.rgb
|
0x09 |
vec3(1.0) - i2.rgb
|
0x0A |
i2.aaa
|
0x0B |
vec3(1.0) - i2.aaa
|
0x0C |
i3.rgb
|
0x0D |
vec3(1.0) - i3.rgb
|
0x0E |
i3.aaa
|
0x0F |
vec3(1.0) - i3.aaa
|
This one is for alpha:
Operand ID |
Description
|
0x00 |
i#.a (# is the current operand index)
|
0x01 |
1.0 - i#.a (# is the current operand index)
|
0x02 |
i1.a
|
0x03 |
1.0 - i1.a
|
0x04 |
i2.a
|
0x05 |
1.0 - i2.a
|
0x06 |
i3.a
|
0x07 |
1.0 - i3.a
|
0x08 |
Unused?
|
0x09 |
Unused?
|
0x0A |
Unused?
|
0x0B |
Unused?
|
0x0C |
Unused?
|
0x0D |
Unused?
|
0x0E |
Unused?
|
0x0F |
Unused?
|
The following table describes the different combiners for Rgb. The input values are called j1, j2 and j3. If the rgb operand is 0x07, the alpha component is not used.
Combine ID |
Description
|
0x00 |
j1.rgb
|
0x01 |
j1.rgb * j2.rgb
|
0x02 |
j1.rgb + j2.rgb
|
0x03 |
j1.rgb + j2.rgb - vec3(0.5)
|
0x04 |
j1.rgb * j3.rgb + j2.rgb * (vec3(1.0) - j3.rgb)
|
0x05 |
j1.rgb - j2.rgb
|
0x06 |
vec3(4 * ((j1.r - 0.5) * (j1.r - 0.5) + (j1.g - 0.5) * (j2.g - 0.5) + (j1.b - 0.5) * (j2.b - 0.5)))
|
0x07 |
vec4(4 * ((j1.r - 0.5) * (j1.r - 0.5) + (j1.g - 0.5) * (j2.g - 0.5) + (j1.b - 0.5) * (j2.b - 0.5)))
|
0x08 |
Unknown
|
0x09 |
Unknown
|
These are for alpha:
Combine ID |
Description
|
0x00 |
j1.a
|
0x01 |
j1.a * j2.a
|
0x02 |
j1.a + j2.a
|
0x03 |
j1.a + j2.a - 0.5
|
0x04 |
j1.a * j3.a + j2.a * (1.0 - j3.a)
|
0x05 |
j1.a - j2.a
|
0x06 |
Unknown. Maybe 4 * ((j1.r - 0.5) * (j1.r - 0.5) + (j1.g - 0.5) * (j2.g - 0.5) + (j1.b - 0.5) * (j2.b - 0.5))
|
0x07 |
Unknown. May be invalid.
|
0x08 |
Unknown
|
0x09 |
Unknown
|
Tableset Info
Mesh (SOBJ)
Vertex (SOBJ)
Textures (TXOB)
The data offset in the Textures DICT points to this structure:
Offset |
Length |
Type |
Description
|
0x00 |
0x04 |
UInt32 |
Flags
|
0x04 |
0x04 |
String |
Signature (TXOB)
|
0x08 |
0x04 |
UInt32 |
Revision
|
0x0C |
0x04 |
UInt32 |
Name Offset
|
0x10 |
0x04 |
UInt32 |
?
|
0x14 |
0x04 |
UInt32 |
?
|
0x18 |
0x04 |
UInt32 |
Height
|
0x1C |
0x04 |
UInt32 |
Width
|
0x20 |
0x04 |
UInt32 |
?
|
0x24 |
0x04 |
UInt32 |
?
|
0x28 |
0x04 |
UInt32 |
Nr Mipmap Levels
|
0x2C |
0x04 |
UInt32 |
?
|
0x30 |
0x04 |
UInt32 |
?
|
0x34 |
0x04 |
UInt32 |
Format
|
0x38 |
0x04 |
UInt32 |
?
|
0x3C |
0x04 |
UInt32 |
Height
|
0x40 |
0x04 |
UInt32 |
Width
|
0x44 |
0x04 |
UInt32 |
Data Size
|
0x48 |
0x04 |
UInt32 |
Data Offset
|
0x4C |
0x04 |
UInt32 |
?
|
0x50 |
0x04 |
UInt32 |
?
|
0x54 |
0x04 |
UInt32 |
?
|
Format is one of these:
Format |
Description
|
0x00 |
RGBA8
|
0x01 |
RGB8
|
0x02 |
RGBA5551
|
0x03 |
RGB565
|
0x04 |
RGBA4
|
0x05 |
LA8
|
0x06 |
HILO8
|
0x07 |
L8
|
0x08 |
A8
|
0x09 |
LA4
|
0x0A |
L4
|
0x0B |
A4
|
0x0C |
ETC1
|
0x0D |
ETC1A4
|
Look Up Tables (LUTS)
Shaders (SHDR)
Lights
Fragment Lights (CFLT)
Hemisphere Lights (CHLT)
Fogs (CFOG)
Environments (CENV)
Bone Animations (CANM)
The data offset in the Bone Animations DICT points to this structure:
Texture Animations (CANM)
The data offset in the Texture Animations DICT points to this structure:
Links