BRRES (File Format)

From Wexos's Wiki
Jump to navigationJump to search

BRRES (Binary Revolution RESources) is a file format used on the Wii containing information about models. It stores models, textures, palettes and different types of animations.

All offsets are relative to the start of the structure it's in. Offset value 0 means it null-pointer. This is always the case in this documentation unless noted other.

File Format

Header

The file begins with the following header:

Offset Type Description
0x00 Char[4] File magic. Always bres in ASCII.
0x04 UInt16 Byte-order-mark. FE FF for big endian, FF FE for little endian.
0x06 UInt16 Version number. This field is always set to 0, instead, each sub file has its own version number.
0x08 UInt32 Size of file in bytes.
0x0C UInt16 Root offset.
0x0E UInt16 Number of sections, including the root section.

Dictionary

User Data

Root

The root links to all subfiles stored in the file. It starts with the following structure:

Offset Type Description
0x00 Char[4] File magic. Always root in ASCII.
0x04 UInt32 Section size in bytes.

After the root comes a dictionary which points to more dictionaries which points to sub files. The following elements are valid in the root:

Name Element Description
3DModels(NW4R) MDL0 3D model.
Textures(NW4R) TEX0 Texture.
Palettes(NW4R) PLT0 Color palette which can be used by a texture.
AnmChr(NW4R) CHR0 Bone animation.
AnmClr(NW4R) CLR0 Color animation.
AnmTexPat(NW4R) PAT0 Texture pattern animation.
AnmScn(NW4R) SCN0 Scene animation.
AnmShp(NW4R) SHP0 Shape animation.
AnmTexSrt(NW4R) SRT0 Texture SRT animation.
AnmVis(NW4R) VIS0 Bone visibility animation.
External External file Generic data file which can be embedded into the BRRES which is ignored by the renderer.

MDL0

Offset Type Description
0x00 Char[4] Section magic. Always MDL0 in ASCII.
0x04 UInt32 Section size in bytes.
0x08 UInt32 Version number.
0x0C Int32 BRRES offset.
0x10 Int32 Definition dictionary offset.
0x14 Int32 Bone dictionary offset.
0x18 Int32 Position dictionary offset.
0x1C Int32 Normal dictionary offset.
0x20 Int32 Color dictionary offset.
0x24 Int32 UV dictionary offset.
If version ≥ 10
0x28 Int32 Fur vector dictionary offset.
0x2C Int32 Fur layer dictionary offset.
0x30 Int32 Material dictionary offset
0x34 Int32 TEV dictionary offset
0x38 Int32 Shape dictionary offset
0x3C Int32 Texture link dictionary offset
0x40 Int32 Palette link dictionary offset
If version ≥ 11
0x44 Int32 User data offset.
0x44 Int32 Name offset.
Else
0x40 Int32 Name offset.
Else
0x28 Int32 Material dictionary offset
0x2C Int32 TEV dictionary offset
0x30 Int32 Shape dictionary offset
0x34 Int32 Texture link dictionary offset
0x38 Int32 Palette link dictionary offset
0x3C Int32 Name offset.

After the header follows a structure declaring some common properties for the model. It has the following structure:

Offset Type Description
0x00 UInt32 Section size. Always 0x40.
0x04 Int32 MDL0 offset.
0x08 UInt32 Scaling rule.
ID Description
0 Standard
1 Softimage
2 Maya
0x0C UInt32 Texture matrix mode.
ID Description
0 Maya
1 XSI
2 3ds Max
0x10 UInt32 Total number of vertices in the model.
0x14 UInt32 Total number of faces in the model.
0x18 Int32 Original path offset.
0x1C UInt32 Number of bones.
0x20 Byte Need normal matrix array.
0x21 Byte Need texture matrix array.
0x22 Byte Enable extents.
0x23 Byte Envelope matrix mode.
ID Description
0 Normal
1 Approximate
2 Exact
0x24 Int32 Matrix to bone table offset.
0x28 Float[3] Minimum cooordinates of the whole model.
0x34 Float[3] Maximum cooordinates of the whole model.
Matrix To Bone table
Offset Type Description
0x00 UInt32 Number of entries.
0x04 Int32[] Bone index for each matrix. -1 means that the weight is stored in a definition entry.

Definition

Each definition contains byte-code which is used for various things. The following table shows the known definitions and their usage.

Name Description Node(s)
NodeTree Specifies the parent for all bones. 2
NodeMix Contains weights for non-riggid skinning, thus weights for a vertex which is influenced by more than one bone. 3, 5
DrawOpa Draws a shape opaque. 4
DrawXlu Draws a shape xlu. 4

Each entry starts directly with byte code. Each node starts with a byte respresenting command. The following codes are supported:

ID Description
1 End. No more byte code follows.
2 Specifies the parent bone for a bone.
3 Specifies a vertex weight which doesn't have to be rigid.
4 Specifies draw properties for a shape.
5 Maps a matrix index to a bone index.
Node 2 Data
Offset Type Description
0x00 UInt16 Bone index.
0x02 UInt16 Parent matrix index. If the bone has no parent, this is set to 0.
Node 3 Data
Offset Type Description
0x00 UInt16 Index.
0x02 Byte Number of entries.

The entries follow directly afterwards and have the following structure:

Offset Type Description
0x00 UInt16 Matrix index.
0x02 Float Weight.
Node 4 Data
Offset Type Description
0x00 UInt16 Material index.
0x02 UInt16 Shape index.
0x04 UInt16 Bone index. Specifies the index of the bone which specifies the visibility of the shape.
0x06 UInt16 Render priority. A value of 1 has the most priority, 255 the least. 0 means the renderer will decide the priority.
Node 5 Data
Offset Type Description
0x00 UInt16 Matrix index.
0x02 UInt16 Bone index.

Bone

In the bone dictionary all bones are linked in a big array. The hierarchy is stored within the bones themselves, each bone links to its children, its parent and the previous and next sibling. Each bone has the following structure:

Offset Type Description
0x00 UInt32 Section size. Includes this bone structure and the user data attached to this bone.
0x04 Int32 MDL0 offset.
0x08 Int32 Bone name offset.
0x0C UInt32 Bone index.
0x10 UInt32 Matrix index.
0x14 UInt32 Flags. xxxx xxxx xxxx xxxx xxxx xABC DEFG HIJK.
  • A: has billboard parent
  • B: has geometry
  • C: visible
  • D: classic scale is off
  • E: segment scale compensate parent (for Maya bone transformation)
  • F: segment scale compensate apply (for Maya bone transformation)
  • G: scale uniform
  • H: scale by one
  • I: zero rotation
  • J: zero translation
  • K: identity, no transformation
0x18 UInt32 Billboard flags.
ID Description
0 Off
1 Standard
2 Standard perspective
3 Rotation
4 Rotation perspective
5 Y
6 Perspective Y
0x1C UInt32 Billboard reference. Index of the bone which is used as reference for a billboard bone. 0 if billboard is disabled.
0x20 Float[3] Bone scale.
0x2C Float[3] Bone rotation in degrees.
0x38 Float[3] Bone translation.
0x44 Float[3] Mimimum coordinate.
0x50 Float[3] Maximum coordinate.
0x5C Int32 Parent bone offset.
0x60 Int32 First child bone offset.
0x64 Int32 Next sibling bone offset.
0x68 Int32 Previous sibling bone offset.
0x6C Int32 User data offset.
0x70 Float[3][4] Absolute transformation for this bone stored as a 3x4 matrix. The matrix is stored row by row.
0xA0 Float[3][4] Absolute inverse transformation for this bone stored as a 3x4 matrix. The matrix is stored row by row. Used for non-rigid weights.

Position Data

This section stores position data. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Section size.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset. Points to the position data.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Position type.
ID Description
0 XY
1 XYZ
0x18 UInt32 Position format.
ID Description
0 Byte
1 SByte
2 UInt16
3 Int16
4 Float
0x1C Byte Divisor. When format is not float, the data is divided by (1 << Divisor).
0x1D Byte Position stride. Size of one position in bytes.
0x1E UInt16 Number of positions.
0x20 Float[3] Minimum position.
0x2C Float[3] Maximum position.
0x38 Byte[8] Padding.

Normal Data

This section stores normal data, and optionally tangents and binormals. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Section size.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset. Points to the normal data.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Normal type.
ID Description
0 Normal
1 Normal and Binormal and Tangent
2 Normal or Binormal or Tangent
0x18 UInt32 Normal format.
ID Description
0 Byte
1 SByte
2 UInt16
3 Int16
4 Float
0x1C Byte Divisor. When format is not float, the data is divided by (1 << Divisor).
0x1D Byte Normal stride. Size of one normal in bytes.
0x1E UInt16 Number of normals.

Color Data

This section stores color data. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Section size.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset. Points to the color data.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Color type.
ID Description
0 RGB
1 RGBA
0x18 UInt32 Color format.
ID Description
0 RGB565
1 RGB8
2 RGBX8
3 RGBA4
4 RGBA6
5 RGBA8
0x1C Byte Color stride. Size of one color in bytes.
0x1D Byte Padding.
0x1E UInt16 Number of colors.

UV Data

This section stores UV data. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Section size.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset. Points to the UV data.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 UV type.
ID Description
0 S
1 ST
0x18 UInt32 UV format.
ID Description
0 Byte
1 SByte
2 UInt16
3 Int16
4 Float
0x1C Byte Divisor. When format is not float, the data is divided by (1 << Divisor).
0x1D Byte UV stride. Size of one UV in bytes.
0x1E UInt16 Number of positions.
0x20 Float[2] Minimum UV.
0x28 Float[2] Maximum UV.
0x30 Byte[10] Padding.

Fur Vector Data

This section stores fur vectors, used to produce fur. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Section size.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset. Points to the fur vector data. Each vector is stored as 3 floats.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt16 Number of fur vectors.
0x16 Byte[0x0A] Padding.

Fur Layer Data

This section stores fur layers, used to produce fur. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Section size.
0x04 Int32 MDL0 offset.
0x08 Int32 Data offset. Points to the fur layer data.
0x0C Int32 Name offset.
0x10 UInt32 Index.
0x14 UInt32 Fur layer type.
ID Description
0 S
1 ST
0x18 UInt32 Fur layer format.
ID Description
0 Byte
1 SByte
2 UInt16
3 Int16
4 Float
0x1C Byte Divisor. When format is not float, the data is divided by (1 << Divisor).
0x1D Byte Fur layer stride. Size of one fur layer position in bytes.
0x1E UInt16 Number of fur layer positions.
0x20 UInt32 Number of layers.
0x24 UInt32 Layer size. Size of one layer in bytes.
0x28 Byte[0x18] Padding.

Material

A material contains information about how a shape is displayed, for example textures and lighting. The material is used as input to a TEV, which transforms the material input into the final pixel color on the screen. A lot of material data is stored as GPU commands, which are sent directly to the GPU. Each material contains two lighting channels, up to eight textures and other parameters.

Offset Type Description
0x00 UInt32 Section size.
0x04 Int32 MDL0 offset.
0x08 Int32 Material name offset.
0x0C UInt32 Index.
0x10 UInt32 Usage flag. Axxx xxxx xxxx xxxx xxxx xxxx BCDE FGHI.
  • A: XLU (1) or opaque (0).
  • B: do not send texture matrix display list
  • C: do not send texture coordinate generator display list
  • D: do not send generator mode display list
  • E: do not send lighting channel display list
  • F: do not send indirect matrix and scale display list
  • G: do not send texture coordinate scale display list
  • H: do not send TEV color display list
  • I: do not send pixel display list

Note that BI should be 0 in all files, it is intended to be set and used on runtime.

0x14 Byte Number of texture generators.
0x15 Byte Number of used lighting channels.
0x16 Byte Active number of TEV stages.
0x17 Byte Active number of indirect TEV stages.
0x18 UInt32 Culling.
ID Description
0 None (display both faces)
1 Front (display back face)
2 Back (display front face)
3 Both (display no faces)
0x1C Byte Depth test before texturing.
0x1D SByte SCN0 light set. -1 if none.
0x1E SByte SCN0 fog set. -1 if none.
0x1F Byte Padding.
0x20 Byte[4] Indirect methods for 4 indirect textures.
ID Description
0 Wrap
1 Normal map
2 Normal map specular
3 Fur
4 Reserved
5 Reserved
6 User 0
7 User 1
0x24 SByte[4] Normal map reference lights. -1 if none.
0x28 Int32 TEV offset.
0x2C UInt32 Number of textures.
0x30 Int32 Texture reference array offset.
If version ≥ 10
0x34 Int32 Fur data offset.
0x38 Int32 User data offset.
0x3C Int32 Material display list offset.
Else
0x34 Int32 User data offset.
0x38 Int32 Material display list offset.
Texture Look-Up

The following two structures follows. They are both initialized on runtime and should always be filled with zeros in a file.

Offset Type Description
0x00 UInt32 Used texture maps flag. xxxx xxxx xxxx xxxx xxxx xxxx ABCD DEFG.

G is set if texture 0 is used, F is set if texture 1 is used, and so on.

0x04 Byte[8][0x20] Space for 8 texture object structures.
Offset Type Description
0x00 UInt32 Used palettes flag. xxxx xxxx xxxx xxxx xxxx xxxx ABCD DEFG.

G is set if palette 0 is used, F is set if palette 1 is used, and so on.

0x04 Byte[8][0x0C] Space for 8 texture object structures.
Texture SRT

After that follows texture SRT (scale, rotate, translate) information. It starts with the following structure:

Offset Type Description
0x00 UInt32 Flag storing information for 8 textures. The 4 LSB bits are for texture 0, and the 4 MSB bits are for texture 7. The 4-bit flag has the following layout: ABCD.
  • A: translate zero
  • B: rotate zero
  • C: scale by one
  • D: animation exists (always 1 for used texture slots)
0x04 UInt32 Texture matrix mode.
ID Description
0 Maya
1 XSI
2 3ds Max

8 instances of the following structure follows:

Offset Type Description
0x00 Float[2] Scale.
0x08 Float Rotation in degrees.
0x0C Float[2] Translation.

8 instances of the following structure follows:

Offset Type Description
0x00 SByte SCN0 camera reference. -1 for none.
0x01 SByte SCN0 light reference. -1 for none.
0x02 Byte Mapping method.
ID Description
0 Texture coordinate
1 Enviroment camera
2 Projection
3 Enviroment light
4 Environment specular
0x03 Byte Identity matrix.
0x04 Float[3][4] Texture transformation stored as a 3x4 matrix. The data is stored row by row. An identity matrix is always stored in the file.
Lighting Channel

Two channels are always stored in the file. How many of them are activated is set in the material structure.

Offset Type Description
0x00 UInt32 Flag. xxxx xxxx xxxx xxxx xxxx xxxx xxAB CDEF.
  • A: enable rasterized alpha
  • B: enable rasterized color
  • C: enable ambient alpha
  • D: enable ambient color
  • E: enable material alpha
  • F: enable material color
0x04 UInt32 Material color in RGBA format.
0x08 UInt32 Ambient color in RGBA format.
0x0C UInt32 Color control flag. xxxx xxxx xxxx xxxx xABC DEFG GHIJ KLMN.
  • A: enable light 7 (runtime)
  • B: enable light 6 (runtime)
  • C: enable light 5 (runtime)
  • D: enable light 4 (runtime)
  • E: attenuation, either specular (0) or spotlight (1)
  • F: enable attenuation
  • G: diffuse function, either disable (0), enable (1) or clamp (2)
  • H: ambient source, either register (0) or vertex (1)
  • I: enable light 3 (runtime)
  • J: enable light 2 (runtime)
  • K: enable light 1 (runtime)
  • L: enable light 0 (runtime)
  • M: enable material
  • N: material souce, either register (0) or vertex (1)
0x10 UInt32 Alpha control flag. Identical to the color control flag, but controls alpha instead of color.

Fur Data

The fur data structure stores information about how fur is rendered. It has the following structure:

Offset Type Description
0x00 Float Fur length.
0x04 UInt32 Number of layers.
0x08 UInt32 Interval.
ID Description
0x00 Uniform
0x01 Tip
0x0C Float Alpha curve.
0x10 Float Specular curve.

Texture Reference

This structure references a texture and optionally a palette, as well as specifying parameters for how the texture is rendered. Each reference has the following structure:

Offset Type Description
0x00 Int32 Texture name offset.
0x04 Int32 Palette name offset.
0x08 Int32 Texture pointer, set on runtime.
0x0C Int32 Palette pointer, set on runtime.
0x10 UInt32 Texture slot ID.
0x14 UInt32 Palette slot ID.
0x18 UInt32[2] Wrap mode for U respectively V.
ID Description
0 Clamp
1 Repeat
2 Mirror
0x20 UInt32 Min filter.
ID Description
0 Nearest
1 Linear
2 Nearest Mipmap Nearest
3 Linear Mipmap Nearest
4 Nearest Mipmap Linear
5 Linear Mipmap Linear
0x24 UInt32 Mag filter.
ID Description
0 Nearest
1 Linear
0x28 Float LOD bias.
0x2C UInt32 Max anisotropy.
ID Description
0 One
1 Two
2 Four
0x30 Byte Clamp bias.
0x31 Byte Texel interpolate.
0x32 Byte[2] Padding.

Material Display List

This section contains GPU commands containing different material data. It first stores 0xE0 bytes of BP commands, then 0xA0 bytes of XF commands. While the commands are always stored in a specific order, the order of most of the commands doesn't matter.

TEV

TEV stands for Texture EnVironment and is the code which specifies the color output. A material specifies data to send into a TEV, and the TEV performs all the calculations. While TEV is a fixed-function pipeline shader system, and not at all as generic as GLSL or HLSL, it can still do a lot of impressive work.

A TEV is devided into stages and groups. A group is made of 2 stages, but both doesn't have to be used. The GPU supports 16 stages, meaning 8 groups, and there are always 16 stages stored in the file. Unused commands in a stage, or the whole stage, is filled with NOP (no operation) commands.

Offset Type Description
0x00 UInt32 Section size. Always 0x200.
0x04 Int32 MDL0 offset.
0x08 UInt32 Index.
0x0C Byte Number of used stages.
0x0D Byte[3] Padding.
0x10 SByte[8] Eight texture references, each reference points to a texture slot. -1 means none.
0x18 Byte[8] Padding.

After comes GPU commands specifying the TEV stages and some other commands.

Shape

A shape is used to link together the buffers, materials and more, to be able to render a model. It contains the draw commands for rendering the model and indexes the different buffers.

Offset Type Description
0x00 UInt32 Section size.
0x04 Int32 MDL0 offset.
0x08 Int32 Single-bind matrix index. -1 means the model is rigged to multiple bones.
0x0C UInt32 CP vertex format low.
0x10 UInt32 CP vertex format low.
0x14 UInt32 XF vertex specification.
0x18 Primitive Data Group Vertex definition. Contains the display list for vertex setup.
0x24 Primitive Data Group Vertex primitives. Contains the display list for rendering primitives.
0x30 UInt32 Enable array flag. xxxx xxxx xxxA BCDE FGHI JKLM NOPQ RSTU.
  • A: UV 7
  • B: UV 6
  • C: UV 5
  • D: UV 4
  • E: UV 3
  • F: UV 2
  • G: UV 1
  • H: UV 0
  • I: color 1
  • J: color 0
  • K: normal
  • L: position
  • M: texture matrix 7
  • N: texture matrix 6
  • O: texture matrix 5
  • P: texture matrix 4
  • Q: texture matrix 3
  • R: texture matrix 2
  • S: texture matrix 1
  • T: texture matrix 0
  • U: position matrix
0x34 UInt32 Shape flag. xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxAB.
  • A: invisible (1) or visible (0)
  • B: change current matrix
0x38 Int32 Name offset.
0x3C UInt32 Index.
0x40 UInt32 Number of vertices.
0x44 UInt32 Number of faces.
0x48 Int16 Position index. -1 for none.
0x4A Int16 Normal index. -1 for none.
0x4C Int16[2] Color indices. -1 for none.
0x50 Int16[8] UV indices. -1 for none.
If version ≥ 10
0x60 Int16 Fur vector index. -1 for none.
0x62 Int16 Fur layer index. -1 for none.
0x64 Int32 Used matrix table offset.
Else
0x60 Int32 Used matrix table offset.
Used Matrix Table

The used matrix table has the following structure:

Offset Type Description
0x00 UInt32 Number of matrix indices.
0x04 UInt16[] Matrix indices.

Primitive Data Group

This structure points to a display list. It has the following structure:

Offset Type Description
0x00 UInt32 Buffer size. Actual size of the display list in bytes, including padding.
0x04 UInt32 Used size. Size including all commands, excluding padding.
0x08 Int32 Display list offset.

Texture Palette Link

A texture palette link points a used texture or palette to where it's used. It points to both the owning material and the texture reference where it's referenced. It starts with the following structure:

Offset Type Description
0x00 UInt32 Number of entries.

Texture Palette Link Entry

All entries follow directly afterwards and has the following structure:

Offset Type Description
0x00 Int32 Material offset, relative to the start of the texture palette link.
0x00 Int32 Texture reference offset, relative to the start of the texture palette link.

TEX0

Offset Type Description
0x00 Char[4] File magic. Always TEX0 in ASCII.
0x04 UInt32 Section size in bytes.
0x08 UInt32 Version number.
0x0C Int32 BRRES offset.
If version = 2
0x10 UInt32 Is palette. Specifies if the image uses a palette.
0x14 Int32 Texture data offset.
0x18 Int32 Texture name offset.
0x1C Int32 Original path offset.
0x20 UInt16 Texture width in pixels.
0x22 UInt16 Texture height in pixels.
0x24 UInt32 Image format.
0x28 UInt32 Number of mipmaps, including the main image.
0x2C Float Min LOD.
0x30 Float Max LOD.
0x34 Byte[0x0C] Padding.
Else
0x10 Int32 Texture data offset.
0x14 Int32 Texture name offset.
0x18 UInt32 Is palette. Specifies if the image uses a palette.
0x1C UInt16 Texture width in pixels.
0x1E UInt16 Texture height in pixels.
0x20 UInt32 Image format.
0x24 UInt32 Number of mipmaps, including the main image.
0x28 Float Min LOD.
0x2C Float Max LOD.
0x30 Int32 Original path offset.
If version ≥ 3
0x30 Int32 User data offset.
0x34 Byte[8] Padding.
Else
0x30 Byte[0x0C] Padding.

PLT0

Offset Type Description
0x00 Char[4] File magic. Always PLT0 in ASCII.
0x04 UInt32 Section size in bytes.
0x08 UInt32 Version number.
0x0C Int32 BRRES offset.
0x10 Int32 Palette data offset.
0x14 Int32 Palette name offset.
0x18 Int32 Palette format.
0x1C UInt16 Number of palette entries.
0x1E Byte[2] Padding.
0x20 Int32 Original path offset.
If version ≥ 3
0x24 Int32 User data offset.
0x28 Byte[0x18] Padding.
Else
0x24 Byte[0x1C] Padding.

CHR0

CLR0

PAT0

SCN0

SHP0

SRT0

VIS0

External File

Version List

MDL0

Version Found in
8
9
10
11

TEX0

Version Found in
1
2
3

PLT0

Version Found in
1
3

CHR0

Version Found in
3
4
5

CLR0

Version Found in
3
4

PAT0

Version Found in
3
4

SCN0

Version Found in
4
5

SHP0

Version Found in
3
4

SRT0

Version Found in
4
5

VIS0

Version Found in
3
4

Tools

The following tools can handle BRRES files:

  • BrawlBox, by Kryal and BlackJax96
  • CTools, by Chadderz
  • SZS Modifier, by Chadderz