BCRES (File Format)

From Wexos's Wiki
Jump to navigationJump to search
Under Construction
This article is not finished. Help improve it by adding accurate information or correcting grammar and spelling.

BCRES (Binary Citra RESource) is a file format used on Nintendo 3DS games, and contains model, texture and animation data.

File Format

Header

The file starts with a header.

Offset Type Description
0x00 String File magic. Always CGFX in ASCII.
0x04 UInt16 Byte-order-mark. FE FF for big endian, FF FE for little endian.
0x06 UInt16 Header size. Always 0x14.
0x08 UInt32 Version number of the file format.
0x0C UInt32 File size in bytes.
0x10 UInt16 Number of sections.
0x12 UInt16 Reserved

DATA

After the header comes the DATA section.

Offset Type Description
0x00 String Section magic. Always DATA in ASCII.
0x04 UInt32 Section size. Also includes the data that comes after.

After the DATA header comes N entries of the following structure. N seems to be depending on the version number.

Offset Type Description
0x00 UInt32 Number of entries.
0x04 Int32 DICT offset.

DICT

A DICT (DICTionary) is used to represent named entries. It is also a binary search tree, which allows faster name look-ups.

Offset Type Description
0x00 String Magic to identify this section. Always DICT in ASCII.
0x04 UInt32 Section size.
0x08 UInt32 N = Number of entries in this dictionary.

After the header structure follows N + 1 number of entries. The first entry is a dummy node which never contains any data. It is used as a reference entry. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Search value.
0x04 UInt16 Left entry index.
0x06 UInt16 Right entry index.
0x08 Int32 Name offset.
0x0C Int32 Data offset.

CMDL

Offset Type Description
0x00 UInt32 Flags. xxxxxxxx xxxxxxxx xxxxxxxx Axxxxxxx:
  • A determines if the model has bones.
0x04 String Magic. Always CMDL in ASCII.
0x08 UInt32 Revision.
0x0C Int32 Name offset.
0x10 UInt32 Number of user data.
0x14 Int32 User data DICT offset.
0x18 UInt32 Unknown.
0x1C UInt32 Flags.
0x20 UInt32 Unknown.
0x24 UInt32 Unknown.
0x28 UInt32 Unknown.
0x2C UInt32 Unknown.
0x30 Float[3] Scale affecting this model.
0x3C Float[3] Rotation affecting this model.
0x48 Float[3] Translation affecting this model.
0x54 Float[12] Local 4x3 matrix.
0x84 Float[12] World 4x3 matrix.
0xB4 UInt32 Number of meshes.
0xB8 Int32 Mesh pointer table offset. Links to a Int32[] which points to the structures.
0xBC UInt32 Number of material.
0xC0 Int32 Material DICT offset.
0xC4 UInt32 Number of Shape.
0xC8 Int32 Shape pointer table offset. Links to a Int32[] which points to the structures.
0xCC UInt32 Number of object nodes.
0xD0 Int32 Object nodes DICT offset.
0xD4 UInt32 Flags.
0xD8 UInt32 Unknown.
0xDC UInt32 Unknown.
0xE0 Int32 Bone offset. Only stored if A is 1 at 0x00.

Mesh

Offset Type Description
0x00 UInt32 Flags.
0x04 String Section magic. Always SOBJ in ASCII.
0x08 UInt32 Revision.
0x0C Int32 Name offset.
0x10 UInt32 Number of user data.
0x14 Int32 User data DICT offset.
0x18 UInt32 Shape index.
0x1C UInt32 Material index.
0x20 Int32 Offset to the owner model.
0x24 Byte Visible.
0x25 Byte Render priority.
0x26 UInt16 Unknown.
0x28 UInt16 Unknown.
0x2A ? Unknown.

Material

Offset Type Description
0x00 UInt32 Flags.
0x04 String Section magic. Always MTOB in ASCII.
0x08 UInt32 Revision.
0x0C Int32 Name offset.
0x10 UInt32 Number of user data.
0x14 Int32 User data DICT offset.
0x18 UInt32 Flags. xxxxxxxx xxxxxxxx xxxxxxxx xxABCDEF:
  • A determines if polygon offset is enabled.
  • B enables fog.
  • C enables hemi sphere pcclusion.
  • D enables hemi sphere light.
  • E enables vertex light.
  • F enables fragment light.
0x1C UInt32 UV config.
0x20 UInt32 Unknown.
0x24 Material Color Material color.
0x100 Rasterization Rasterization.
0x114 Depth Operation Depth operation.
0x128 Blend Operation Blend operation.
0x154 Stencil Operation Stencil operation.
0x164 UInt32 Number of active texture coordinates.
0x168 Texture Coordinate Source Texture coordinate source 0
0x198 Texture Coordinate Source Texture coordinate source 1
0x1C8 Texture Coordinate Source Texture coordinate source 1
0x1F8 Int32[4] Offset to 4 texture mappers.
0x208 Int32 Shader offset.
0x20C Int32 Fragment shader offset.
0x210 UInt32 Shader program description index.
0x214 UInt32 Number of shader parameters.
0x218 UInt32 Shader parameter array offset.
0x21C UInt32 Light set index.
0x220 UInt32 Fox index.
0x224 UInt32 Shading parameter hash.
0x228 UInt32 Shader parameters hash.
0x22C UInt32 Texture coordinators hash.
0x230 UInt32 Texture samplers hash.
0x234 UInt32 Texture mappers hash.
0x238 UInt32 Material color hash.
0x23C UInt32 Rasterization hash.
0x240 UInt32 Fragment lighting hash.
0x244 UInt32 Fragment lighting table hash.
0x248 UInt32 Fragment lighting table parameters hash.
0x24C UInt32 Texture combiners hash.
0x250 UInt32 Alpha test hash.
0x254 UInt32 Hash of depth operation, blend operation and stencil operation.
0x258 UInt32 Material index.

Material Color

Offset Type Description
0x00 Float[4][11] Material colors. Each color is stored as four floats in RGBA format. There are a total of 11 colors where 1 is emission, 1 is ambient, 1 is diffuse, 2 are specular and 5 are constants.
0xB0 Byte[4][11] Material colors. Each color is stored as four bytes in RGBA format. There are a total of 11 colors where 1 is emission, 1 is ambient, 1 is diffuse, 2 are specular and 5 are constants.

Rasterization

Offset Type Description
0x00 UInt32 Flags.
0x04 UInt32 Culling mode.
0x08 Float Polygon offset unit.
0x0C UInt32 Command 1.
0x10 UInt32 Command 2.

Depth Operation

Offset Type Description
0x00 UInt32 Flags. xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxAB:
  • A enables death test?
  • B enables mask?
0x04 UInt32 Command 1.
0x08 UInt32 Command 2.
0x0C UInt32 Command 3.
0x10 UInt32 Command 4.

Blend Operation

Offset Type Description
0x00 UInt32 Mode.
0x04 Float[4] Blend color stored as four floats in RGBA format.
0x14 UInt32 Command 1.
0x18 UInt32 Command 2.
0x1C UInt32 Command 3.
0x20 UInt32 Command 4.
0x24 UInt32 Command 5.
0x28 UInt32 Command 6.

Stencil Operation

Offset Type Description
0x00 UInt32 Command 1.
0x04 UInt32 Command 2.
0x08 UInt32 Command 3.
0x0C UInt32 Command 4.

Texture Coordinate Source

Offset Type Description
0x00 UInt32 Source.
0x04 UInt32 Mapping method. 0 = UV, 1 = Cube, 2 = Sphere, 3 = Projection, 4 = Shadow
0x08 Int32 Camera reference.
0x0C UInt32 Matrix mode.
0x10 Float[2] Scale.
0x18 Float Rotation.
0x1C Float[2] Translation.
0x24 UInt32 Unknown.
0x28 Float[12] Matrix 4x3.

Texture Mapper

Offset Type Description
0x00 UInt32 Type.
0x04 UInt32 Dynamic allocator.
0x08 Int32 TXOB offset. Links to the texture header.
0x0C Int32 Sampler offset.
0x10 UInt32 Unknown.
0x14 UInt16 Unknown.
0x16 UInt16 Unknown.
0x18 UInt32 Unknown.
0x1C UInt16 Unknown.
0x1E UInt16 Unknown.
0x20 UInt16 Height.
0x22 UInt16 Width.
0x24 UInt32 Unknown.
0x28 UInt32 Unknown.
0x2C UInt32 Unknown.
0x30 UInt32 Unknown.
0x34 UInt32 Unknown.
0x38 UInt32 Unknown.
0x3C UInt32 Unknown.
0x40 UInt32 Unknown.
0x44 UInt32 Unknown.
0x44 UInt32 The command size to send.

Shape

Offset Type Description
0x00 UInt32 Flags.
0x04 String Section magic. Always SOBJ in ASCII.
0x08 UInt32 Revision.
0x0C Int32 Name offset.
0x10 Int32 Number of user data.
0x14 Int32 User data DICT offset.
0x18 UInt32 Flags.
0x1C Int32 Bounding box offset.
0x20 Float[3] Unknown vector.
0x2C UInt32 Number of face groups.
0x30 Int32 Offset to the face groups.
0x34 UInt32 Unknown.
0x38 UInt32 Number of vertex buffers.
0x3C Int32 Offset to the vertex buffers.
0x40 UInt32 Unknown.

Vertex Buffer

Offset Type Description
0x00 UInt32 Unknown.
0x04 UInt32 Unknown.
0x08 UInt32 Unknown.
0x0C UInt32 Buffer object.
0x10 UInt32 Location flag.
0x14 UInt32 Unknown.
0x18 UInt32 Unknown.
0x1C UInt32 Location address.
0x20 UInt32 Memory area.
0x24 UInt32 Unknown.
0x28 UInt32 Number of vertex attributes.
0x2C UInt32 Vertex attributes pointer table offset. Links to a Int32[] which points to the structures.
Vertex Attribute
Offset Type Description
0x00 UInt32 Flags.
0x04 UInt32 Target.
0x08 UInt32 Flags.
0x0C UInt32 Buffer object.
0x10 UInt32 Location flag.
0x14 UInt32 Stream size.
0x18 UInt32 Stream offset.
0x1C UInt32 Location address.
0x20 UInt32 Memory area.
0x24 UInt32 Flags. xxxxxxxx xxxxxxxx xxxxxxxx xxxxAAAA:
  • AAAA is the format of the stream.
0x28 UInt32 Unknown.
0x2C Float Scale.
0x30 UInt32 Offset.
Formats
Value Description
0x00 SByte.
0x01 Byte.
0x02 Int16.
0x03 Float.
Targets
Value Description.
0x00 Position.
0x01 Normal.
0x02 Tangent.
0x03 Color.
0x04 UV 0.
0x05 UV 1.
0x06 UV 2.
0x07 Bone index.
0x08 Bone weight.
0x09 User attribute 0.
0x0A User attribute 1.
0x0B User attribute 2.
0x0C User attribute 3.
0x0D User attribute 4.
0x0E User attribute 5.
0x0F User attribute 6.
0x10 User attribute 7.
0x11 User attribute 8.
0x12 User attribute 9.
0x13 User attribute 10.
0x14 User attribute 11.
0x15 Interleave.
0x16 Quantity.

Object Node

Offset Type Description
0x00 Int32 Name offset.
0x04 UInt32 Visible.

TXOB