The GLB binary container.
A .glb is a 12-byte header followed by length-prefixed chunks: a JSON
chunk holding the glTF document, and usually a BIN chunk holding the buffer
data that document refers to. Bundling them avoids the base64 inflation of
embedding binary in JSON, which is why almost every real asset ships as GLB
rather than .gltf.
Layout
magic 4 bytes "glTF"
version uint32 2
length uint32 total file length, including this header
chunk:
length uint32 payload length, excluding this 8-byte prefix
type uint32 0x4E4F534A "JSON", or 0x004E4942 "BIN\0"
data length bytes, then padding to a 4-byte boundaryEverything is little-endian regardless of the host.
Summary
Functions
Whether a binary looks like a GLB container.
Splits a GLB into its JSON document and its binary chunk.
Functions
Whether a binary looks like a GLB container.
iex> Gltf.Glb.glb?(<<"glTF", 2::little-32, 12::little-32>>)
true
iex> Gltf.Glb.glb?("{\"asset\": {}}")
false
@spec parse(binary()) :: {:ok, String.t(), binary() | nil} | {:error, Gltf.Error.t()}
Splits a GLB into its JSON document and its binary chunk.
The BIN chunk is optional — a GLB may reference external buffers instead —
so it comes back as nil when absent rather than as an error.