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, padded at the end with spaces (0x20) |
| 0x004E4942 | BIN and a zero byte | BIN | none or one, and the second chunk: binary buffer data, padded at the end with zero bytes |
Every chunk starts and ends on a 4-byte boundary, so chunkLength is a
multiple of 4. A loader must skip chunks of any other type.
The BIN chunk as a buffer
The BIN chunk is the data of the first entry in buffers, which then has
no uri. Its byteLength may be up to three bytes shorter than
the chunk, because of the padding. Other buffers can still point to separate files
or data URIs. Because the chunk length is 32-bit, a buffer stored this way can be at
most 232 − 1 bytes.
Worked example
00000000 67 6C 54 46 02 00 00 00 8C 0B 00 00 68 04 00 00
00000010 4A 53 4F 4E 7B 22 61 73 73 65 74 22 3A 7B 22 76
{"asset":{"vThe BIN chunk would start at 12 + 8 + 1,128 = 1,148 bytes, and its data at 1,156.