A .glb file holds a glTF asset’s JSON and its binary buffer in one file,
so nothing has to be fetched separately and the buffer needs no base64. Section 4 of
the Khronos glTF 2.0 specification defines it. Its media type is
model/gltf-binary. All numbers are little-endian.
Header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | magic | 0x46546C67, the bytes glTF |
| 4 | 4 | u32 | version | 2; a loader must also check asset.version in the JSON |
| 8 | 4 | u32 | length | the size of the whole file, header and chunks included |
Chunks
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | chunkLength | the length of chunkData in bytes |
| 4 | 4 | u32 | chunkType | what the chunk holds (below) |
| 8 | chunkLength | bytes | chunkData | the contents |
| Type | Bytes | Name | Rules |
|---|---|---|---|
| 0x4E4F534A | JSON | JSON | exactly one, and the first chunk: the glTF JSON in UTF-8, as a standalone glTF file would hold it; to reach a multiple of four it may be padded with any JSON whitespace: space (0x20, the usual choice), tab, line feed or carriage return |
| 0x004E4942 | BIN and a zero byte | BIN | none or one, and the second chunk: binary buffer data, usually the first glTF buffer; it may be padded with any bytes (writers use zeros) |
Every chunk starts and ends on a 4-byte boundary, so chunkLength is a
multiple of 4. A GLB may contain chunks of other types; what they mean is outside the
specification, and a reader that does not know one skips it. The specification sees
the layout as an 8-byte GLB header (magic, version), a size
header (length) and the chunks. The version in the GLB header is the
version of the container only; the version of the glTF asset comes from its JSON. A
GLB can still refer to external buffers and images, for example when the images are
kept as separate files. Reading the JSON chunk first lets a reader fetch the rest
progressively.
The BIN chunk as a buffer
The BIN chunk is the data of the first entry in buffers, which then has
no uri; the file must then have a BIN chunk. A buffer with no uri
that is not the first entry has undefined behaviour. The chunk’s length must be at least
the buffer’s byteLength, so the buffer’s length may be shorter than the
chunk (normally by the up to three bytes of padding). Other buffers can still point to separate files
or data URIs. Because lengths are 32-bit, the specification gives an implicit limit of
232 − 4 bytes for the whole GLB file, and so for a buffer stored this way.
Worked example
The start of Duck.glb, the Khronos sample model, which is 120,484 bytes:
00000000 67 6C 54 46 02 00 00 00 A4 D6 01 00 40 08 00 00
00000010 4A 53 4F 4E 7B 22 61 73 73 65 74 22 3A 7B 22 67
glTF, version 2, a file length of 0x0001D6A4 = 120,484, then the
JSON chunk: length 0x00000840 = 2,112 bytes, type JSON, and the data beginning
{"asset":{"g (the generator name)The JSON chunk's data runs from 20 to 2,132, so the next chunk starts at 12 + 8 + 2,112 = 2,132 (0x854):
00000854 48 CE 01 00 42 49 4E 00 39 B8 44 BE EA 3F 6F BF
BIN and a zero
byte, then the first buffer’s data starting at 2,140. 12 + 8 + 2,112 + 8 + 118,344 = 120,484
bytes, which is the length in the header.Not described
What this page and the explorer leave out. All of it is defined by the Khronos glTF specifications.
Known, not yet covered
- Reference: GLB version 1 (the glTF 1.0 container, KHR_binary_glTF, with a different header) is not described.
- Viewer: a second BIN chunk, an unknown chunk and bytes after the last chunk are shown as bytes with a note, not interpreted.