brres
WIP Rust/C++ crate for reading BRRES files
BRRES (.brres) is Nintendo's first-party 3D model format for the Nintendo Wii. Used in games like Mario Kart Wii, Twilight Princess and Super Smash Bros: Brawl, .brres is a versatile and efficient file format. Nearly all data is stored as raw GPU display lists that are directly read by the Wii's "flipper" GPU.
Related crates
gctex[https://crates.io/crates/gctex]: For encoding/decoding raw Wii texture datarsmeshopt[https://crates.io/crates/rsmeshopt]: For performing "triangle strip" mesh optimization for Wii.
File format: .brres
At the very root, ".brres" is an archive format for the following sub-files. All but SHP0 are supported.
| Filetype | Description | Rust structure |
|---|---|---|
| BRRES v0 | 3D Resource | Archive |
| MDL0 v11 | 3D Model | Model |
| TEX0 v1/v3 | Texture | Texture |
| SRT0 v5 | Texture scale/rotate/translate animation | JSONSrtData |
| VIS0 v4 | Bone visibility animation | JSONVisData |
| CLR0 v4 | Shader uniform animation | JSONClrAnim, editing limitations |
| CHR0 v4 | Bone/character animation | ChrData, editing limitations |
| PAT0 v4 | Texture image animation | JSONPatAnim, editing limitations |
| SHP0 | Vertex morph animation | Unsupported |
File format: .mdl0
| Filetype | Description | Rust structure |
|---|---|---|
| MDL0.ByteCode | Draw calls + Skeleton | Merged into JSONBoneData, JSONDrawMatrix |
| MDL0.Bone | Bone | JSONBoneData |
| MDL0.PositionBuf | Holds vertex positions | VertexPositionBuffer |
| MDL0.NormalBuf | Holds vertex normals | VertexNormalBuffer |
| MDL0.ColorBuf | Holds vertex colors | VertexColorBuffer |
| MDL0.UVBuf | Holds UV maps | VertexTextureCoordinateBuffer |
| MDL0.FurVecBuf | Fur related | Not supported |
| MDL0.FurPosBuf | Fur related | Not supported |
| MDL0.Material | Material data | JSONMaterial |
| MDL0.TEV | Shader data | Merged into JSONMaterial |
| MDL0.Mesh | 3D mesh data | Mesh |
| MDL0.TextureLink | Internal | Recomputed |
| MDL0.PaletteLink | Internal | Recomputed |
| MDL0.UserData | Metadata | Not supported |
Thus, the Rust view of a MDL0 file looks like this:
Reading a file
Read a .brres file from a path on the filesystem.
let archive = from_path.unwrap;
assert!;
println!;
Read a .brres file from a raw slice of bytes.
let raw_bytes = read.expect;
let archive = from_memory.unwrap;
assert!;
println!;
Writing a file
(to a file)
let buf = kuribo.write_path.unwrap;
(to memory)
let buf = kuribo.write_memory.unwrap;
write.unwrap;
Examples
Progress
Implements a Rust layer on top of librii::g3d's JSON export-import layer. Importantly, large buffers like texture data and vertex data are not actually encoded in JSON but passed directly as a binary blob. This allows JSON files to stay light and results in minimal encoding latency (tests TBD).
| Format | Supported |
|---|---|
| MDL0 | Yes |
| TEX0 | Yes |
| SRT0 | Yes |
| PAT0 | Yes* |
| CLR0 | Yes* |
| CHR0 | Yes* |
| VIS0 | Yes |
| SHP0 | No |
- Restrictions on track ordering when editing.
Current limitations
- PAT0, CLR0 and CHR0 support is slightly less than ideal. In particular, existing code emphasizes bit-perfect rebuilding, but lacks the flexibility useful for editing. Future versions should address this.
- The internal parts of the library are written in C++. Additionally, the
clangcompiler is needed on Windows. The Microsoft Visual C++ compiler cannot be used. - A lot of documentation is still needed.
- SHP0 is unsupported, although almost never used.
- Only V11 MDL0 is supported. For older titles we should support older (and newer) versions (v7: Wii Sports?, v9: Brawl, v12: Kirby, etc.)
- JSON* structures probably shouldn't be directly exposed.
- The names of enum values do not always follow Rust convention.
Tests
Unit tests are being used to validate correctness. Run the suite with cargo test
brres-sys
Low level documentation available here.