Skip to main content

glTF writer

Write a glTF scenegraph as a binary GLB.

GLTFWriter encodes glTF JSON and loaded buffers as a binary GLB, with optional asynchronous Draco compression.

The scenegraph writing path

Build a portable scene file from common scene data.

The writer takes the loaders.gl scenegraph representation and assembles the JSON, buffers, images, and optional compression extensions required by the target glTF container.

Input

loaders.gl scenegraph data

Assembly

Nodes, meshes, materials, buffers, and images

Compression

Optional asynchronous Draco compression

Output

`.glb` binary

Detailed guide

Writer options and output details

The reference below covers usage, output formats, optional Draco integrations, synchronous encoding, and scenegraph requirements.

The GLTFWriter is a writer for glTF scenegraphs.

GLTFWriter
File Extensions.glb
File TypesBinary
Data FormatScenegraph
File FormatglTF
Supported APIsencode, encodeSync

Usage​

import {GLTFWriter} from '@loaders.gl/scene/gltf';
import {encodeSync} from '@loaders.gl/core';

const arrayBuffer = encodeSync(gltf, GLTFWriter, options);

Materials annotated by the loader with unlit: true are written as required KHR_materials_unlit extensions. Existing raw optional unlit extensions remain optional. The writer omits empty extension declarations and does not invent a binary buffer or BIN chunk for assets without binary data. These repairs do not establish full glTF conformance.

Options​

OptionTypeDefaultDescription
gltf.draco.enabledbooleanfalseGenerate KHR_draco_mesh_compression payloads with async encode.
gltf.draco.skipUnsupportedPrimitivesbooleantrueLeave non-triangle primitives unchanged; set to false to reject them.
byteOffsetnumber0Byte offset passed to binary container encoding.

Additional Draco build settings are accepted under gltf.draco. Input data is not modified. Compression currently requires at most one loaded buffer; original accessors remain available for consumers that do not decode the extension. encodeSync throws when Draco compression is enabled. JSON .gltf files and separate-asset output are not supported by this writer.