Skip to main content

GLB loader

Open the binary envelope around a glTF asset.

GLBLoader parses the GLB container and returns its JSON and binary chunks. Use GLTFLoader when the goal is a complete glTF scenegraph; use this lower-level loader when the envelope itself is the data you need.

The GLB boundary

Read one binary file. Expose its JSON and byte ranges.

GLB packages a JSON chunk and one or more binary chunks into a single file. The loader preserves chunk offsets and lengths so higher-level code can decide how to interpret them.

Input

`.glb` binary data

Envelope

Header, version, and chunk lengths

JSON

Parsed glTF or application JSON

Binary

One or more ArrayBuffer chunks

From-v1.0

The GLBLoader parses a GLB binary "envelope" extracting the embedded JSON and binary chunks.

Choose the layer
  • Use GLTFLoader when the binary envelope contains a glTF scene and linked resources should be resolved for you.
  • Use GLBLoader when an application needs to inspect, preserve, or reinterpret the JSON and binary chunks directly.
InputOutputAPIs
.glb binary dataHeader metadata, parsed JSON, and one or more binary chunksload, parse, parseSync

The loader reads GLB v1 and v2 files, plus the draft GLB v3 chunk layout. GLB v1 is returned in the standard GLB shape with version: 1; it is not silently presented as a v2 file.

Usage​

Detailed guide

Container and data-shape details

The reference below covers supported GLB versions, options, parsed output fields, chunk offsets, and the distinction from GLTFLoader.

import {load} from '@loaders.gl/core';
import {GLBLoader} from '@loaders.gl/scene/gltf';
const gltf = await load(url, GLBLoader);

Options​

OptionTypeDefaultDescription
glb.strict (DEPRECATED)BooleanfalseWhether to reject deprecated XVIZ chunk type numbers; false keeps compatibility.

Remarks:

  • Parses GLB v2 encoded data.
  • Parses draft GLB v3 encoded data, including 64-bit file/chunk lengths and multiple binary chunks.
  • Parses GLB v1 encoded data (enabling support for the glTF v1 KHR_binary_gltf extension).
  • Extracts multiple binary chunks if present, even though the glTF specification normally uses one.

Data Format​

Returns

{
"header": {
"byteLength": number,
"byteOffset": number
},

"type": string,
"version": number,

// JSON Chunk
"json": any,

// BIN Chunk
"hasBinChunk": boolean,
"binChunks": [
{
"arrayBuffer": ArrayBuffer,
"byteOffset": Number,
"byteLength": Number
}
]
}
FieldTypeDefaultDescription
typeStringglTFString containing the first four bytes of the file
versionNumber2The GLB version number
jsonObject{}Parsed JSON from the JSON chunk
binChunksArrayBuffernullThe binary chunk
binChunks[\*].arrayBufferArrayBuffernullThe binary chunk
binChunks[\*].byteOffsetNumbernulloffset of BIN (e.g. embedded in larger binary block)
binChunks[\*].byteLengthArrayBuffernulllength of BIN (e.g. embedded in larger binary block)
header.byteLengthNumber-length of GLB (e.g. embedded in larger binary block)
header.byteOffsetNumber0offset of GLB (e.g. embedded in larger binary block)