Introduction
B3D is the model and scene format of Blitz3D, the game programming language by Mark Sibly of Blitz Research. One file holds a tree of nodes with textures, brushes (surface materials), meshes, bones with vertex weights and animation keys. Textures are separate image files referred to by name.
The format description, Blitz3D file format V0.01, was placed in the public domain, and Blitz3D’s source code, including its B3D loader, has since been published. Besides Blitz3D, the Irrlicht engine and the Assimp library read B3D files.
Structure
A B3D file is a tree of chunks. All values are little-endian. Each chunk starts with an 8-byte header:
| Size | Type | Name | Meaning |
|---|---|---|---|
| 4 | char[4] | tag | The chunk type |
| 4 | int32 | length | Bytes that follow, not counting this header |
A chunk with both data and child chunks puts its fixed-length data first. Lists have no count: they repeat until the chunk ends. A reader should skip chunks it does not know. Anything referred to by index appears earlier in the file than whatever refers to it. Strings end with a zero byte, floats are 32-bit, and colour values run from 0 to 1.
BB3DFile version, then the three chunks below, each optionalTEXSTextures file names and placementBRUSBrushes colour, blending and texturesNODENode tree each node may holdMESHorBONE,KEYS,ANIMand child nodesMESHMesh oneVRTSand one or moreTRIS
BB3D: the file
The first chunk, whose length covers the rest of the file.
| Type | Name | Meaning |
|---|---|---|
| int32 | version | Major × 100 + minor; the default is 1. A reader should refuse a higher major number, and can expect a higher minor number to remain readable |
| chunk | TEXS | Optional textures |
| chunk | BRUS | Optional brushes |
| chunk | NODE | Optional root node |
TEXS: textures
Repeated until the end of the chunk. A texture’s index is its position in the list, from 0.
| Type | Name | Default | Meaning |
|---|---|---|---|
| string | file | Texture file name | |
| int32 | flags | 1 | Texture flags |
| int32 | blend | 2 | Texture blend mode |
| float[2] | x_pos, y_pos | 0, 0 | Texture position |
| float[2] | x_scale, y_scale | 1, 1 | Texture scale |
| float | rotation | 0 | Texture rotation in radians |
Texture flags
Bit values, added together, as for Blitz3D’s LoadTexture.
| Value | Meaning |
|---|---|
| 1 | Colour (the default) |
| 2 | Alpha |
| 4 | Masked |
| 8 | Mipmapped |
| 16 | Clamp U |
| 32 | Clamp V |
| 64 | Spherical environment map |
| 128 | Cubic environment map |
| 256 | Keep the texture in video memory |
| 512 | Force high-colour textures |
| 65536 | The texture uses the second set of texture coordinates |
BRUS: brushes
| Type | Name | Meaning |
|---|---|---|
| int32 | n_texs | Texture slots in every brush of this chunk; Blitz3D has room for 8 |
Then, repeated until the end of the chunk:
| Type | Name | Default | Meaning |
|---|---|---|---|
| string | name | Brush name, such as WATER; the texture name by default | |
| float[4] | red, green, blue, alpha | 1, 1, 1, 1 | Brush colour and opacity |
| float | shininess | 0 | Brush shininess |
| int32 | blend | 1 | Brush blend mode |
| int32 | fx | 0 | Effect flags |
| int32[n_texs] | texture_id | Texture indices; −1 for an empty slot |
Blend modes
| Value | Texture blend | Brush blend |
|---|---|---|
| 0 | Do not blend | |
| 1 | No blend, or alpha when the texture was loaded with the alpha flag | Alpha (default) |
| 2 | Multiply (default) | Multiply |
| 3 | Add | Add |
| 4 | Dot3 | |
| 5 | Multiply 2 |
Effect flags
| Value | Meaning |
|---|---|
| 1 | Full-bright |
| 2 | Use vertex colours instead of the brush colour |
| 4 | Flat shaded |
| 8 | No fog |
| 16 | No back-face culling |
| 32 | Force alpha blending |
NODE: a scene node
A node is a Blitz3D entity. Nesting NODE chunks forms the
hierarchy.
| Type | Name | Meaning |
|---|---|---|
| string | name | Node name |
| float[3] | position | Position relative to the parent |
| float[3] | scale | Local scale |
| float[4] | rotation | Local rotation as a quaternion: w, then x, y, z. No rotation is 1, 0, 0, 0 |
| chunk | MESH or BONE | What kind of node it is; not both. With neither, or an unknown kind, it is an empty pivot |
| chunks | KEYS | Optional animation keys, any number |
| chunks | NODE | Optional children |
| chunk | ANIM | Optional: an animation starts at this node. Nested animations may differ in speed and length |
Blitz3D uses a left-handed system with y upwards. Assimp mirrors the scene, reverses the triangle winding and negates the quaternion’s w to bring B3D data into its own right-handed form.
MESH
| Type | Name | Meaning |
|---|---|---|
| int32 | brush_id | Brush for the whole mesh; −1 (the default) for none |
| chunk | VRTS | The one vertex list |
| chunks | TRIS | One or more triangle lists |
VRTS: vertices
| Type | Name | Meaning |
|---|---|---|
| int32 | flags | 1: normals present; 2: colours present |
| int32 | tex_coord_sets | Texture coordinate sets per vertex, at most 8 |
| int32 | tex_coord_set_size | Components in each set, at most 4 (2 for u, v) |
Then one record per vertex until the end of the chunk. A vertex’s index is its position in this list, from 0.
| Type | Name | Present |
|---|---|---|
| float[3] | x, y, z | Always |
| float[3] | nx, ny, nz | If flags & 1 |
| float[4] | red, green, blue, alpha | If flags & 2 |
| float[sets][size] | tex_coords | As counted above; set by set |
The record is therefore 12, plus 12 for a normal, plus 16 for a colour, plus 4 × sets × size bytes. When normals are absent Blitz3D computes them.
TRIS: triangles
| Type | Name | Meaning |
|---|---|---|
| int32 | brush_id | Brush of these triangles; −1 (the default) for none |
| int32[3], repeated | vertex_id | Three vertex indices per triangle |
BONE: vertex weights
The node holding this chunk is a bone. The weights apply to the mesh of the enclosing animation, normally the mesh in the root node. Repeated until the end of the chunk:
| Type | Name | Meaning |
|---|---|---|
| int32 | vertex_id | A vertex the bone moves |
| float | weight | How strongly |
Blitz3D keeps the four largest weights of each vertex and scales them to add up to 1. It numbers bones in the order it meets them, and one byte holds the number, with 255 meaning none.
KEYS: animation keys
| Type | Name | Meaning |
|---|---|---|
| int32 | flags | 1: position; 2: scale; 4: rotation; any combination |
Then one key after another until the end of the chunk:
| Type | Name | Present |
|---|---|---|
| int32 | frame | Always: the frame of the key |
| float[3] | position | If flags & 1 |
| float[3] | scale | If flags & 2 |
| float[4] | rotation (w, x, y, z) | If flags & 4 |
A node may have several KEYS chunks, for instance one for each kind
of key.
ANIM: an animation
| Type | Name | Default | Meaning |
|---|---|---|---|
| int32 | flags | 0 | Unused |
| int32 | frames | Length in frames | |
| float | fps | 60 | Frames per second |
Worked example
The start of WusonBlitz.b3d, one of Assimp’s test models:
00000000 42 42 33 44 E1 54 01 00 01 00 00 00 54 45 58 53 BB3D.T......TEXS
00000010 00 00 00 00 42 52 55 53 04 00 00 00 01 00 00 00 ....BRUS........
00000020 4E 4F 44 45 C1 54 01 00 52 4F 4F 54 00 00 00 00 NODE.T..ROOT....
BB3D is 87265 bytes long, which with its header makes the 87273-byte
file; the version is 1. TEXS is empty. BRUS holds only
n_texs = 1 and no brushes. The root NODE is named
ROOT and holds a MESH and an ANIM. The
VRTS chunk, at offset 97, is 42352 bytes: its three integers and 2117
vertices of 20 bytes (a position and one set of two coordinates). The
TRIS chunk that follows holds 3732 triangles.
How Blitz3D draws the brushes
From the engine’s published source.
- The triangles of one mesh whose brushes are alike form one surface, with its own copy of the vertices. A surface without stored normals gets, at each position, the normalised sum of the face normals that meet there.
- The brush of the
MESHis laid over that of theTRIS: colours and opacities multiply, shininess adds, effect flags are combined, a blend mode other than 0 on the mesh brush replaces the other, and each texture slot takes the mesh brush’s texture where it has one. A list with brush −1 uses a plain white brush. - Brush blend 2 multiplies the picture behind and 3 adds to it. With blend 1 a surface is alpha blended if a texture has the alpha flag without the masked flag, if the opacity is below 1 or if effect flag 32 is set; otherwise it replaces what is behind. With blend 0 the texture’s alpha counts only when slot 0 is the one slot used.
- A masked texture in slot 0 turns on an alpha test: a pixel is drawn when its alpha is above 128 times the opacity (of 255), or above 0 with effect flag 32. Black pixels of a masked texture are clear. A texture with the alpha flag whose file has no alpha takes the mean of red, green and blue.
- Effect flag 1 turns lighting off, 2 takes colour and alpha from the vertices (a vertex without a stored colour is opaque white), 4 shades each face flat, 8 turns fog off and 16 draws both sides; without it only the side whose corners run clockwise on screen is drawn.
- A shininess above 0 gives a highlight of that strength (at most 1) with a specular power of 128 times the shininess.
- Texture layers are applied in slot order, leaving out those with texture blend 0. Position, scale and rotation turn a coordinate pair (u, v) into (cos·sx·u + sin·sx·v + tx, −sin·sy·u + cos·sy·v + ty). Texture names are looked up in lower case.
Divergence from the specification
Blitz3D’s own loader behaves as follows.
- It rejects any file whose
versionis greater than 1. - Of the texture coordinate sets it keeps the first two, with two components each.
- It clamps vertex colours to the range 0 to 1.
- It ignores the
flagsandfpsofANIMand takes only the frame count. - If the file chunk holds more than one top-level
NODE, the last one is returned.
In the explorer
A dropped .b3d file shows every chunk and record in the byte tree; chunks
the specification does not describe appear as their bytes. The meshes are drawn in 3D
with every triangle, as Blitz3D draws their brushes: opacity,
shininess, blend mode, the effect flags, vertex colours and their alpha where effect
flag 2 asks for them, and a mesh’s brush combined with a triangle set’s.
Textures are separate files. Drop the model together with its folder and PNG, JPEG, BMP, Targa and netpbm pictures are laid on it; those not found are named. Of a brush with several texture layers the first is drawn, and cube maps are not drawn.
Where the file has nodes and keys, the skeleton and the posed model are shown and each animation can be played; every frame opens as a pose. As in Blitz3D, positions and scales are interpolated linearly and rotations along the sphere, the four largest bone weights of a vertex are used, and Y is up. Blitz3D is left-handed, so Z is mirrored in the pictures; the tables give the values as stored. Rotations turn by the conjugate of the stored quaternion, as Assimp reads them. Weights follow Blitz3D’s source: a vertex without weights moves with its mesh. Where an animation gives no positive frame rate, the rate is an option of the animated views, 60 frames a second to begin with.
Tables list the textures, brushes, nodes, meshes, vertices, triangles, bone weights, keys, animations and chunks. Files up to 256 MB are read.
Not described
Known, not yet covered
- Viewer: the second and later texture layers of a brush are not drawn.
- Viewer: cube map textures are not drawn.
- Viewer: texture pictures in kinds other than PNG, JPEG, BMP, Targa and netpbm are not read; pictures over 512 MB are not read, and PNG pictures of more than 128 million pixels are drawn reduced.
Links
Software
- Blitz3D – the language and engine the format belongs to, published with source (Windows)
Developers
Reference
- Blitz3D file format specification – a reformatted copy of the public-domain V0.01 text
- b3dfile_specs.txt – the V0.01 text as plain text
- loader_b3d.cpp – Blitz3D’s own loader
- Blitz3D command help – the texture flag, blend and effect values