Skip to main content

glTF module / loader

GLTFLoader

Load a standards-shaped scene while the loader resolves buffers, images, compressed meshes, and other linked resources around it.

A layered 3D format stack

Choose the delivery layer. Keep the data path.

A scene file, a tiled world, and a compressed payload solve different problems. loaders.gl keeps those boundaries visible while providing the readers needed to move between them.

Application-facing results

scenegraphtile contentMesh / point-listTextureLevel

What GLTFLoader handles

Resolve a scene without hiding the source document.

GLTFLoader loads the standards-shaped scene first, then optionally resolves linked assets, decompresses payloads, and exposes derived data in parallel fields for applications that need it.

Input

.gltf JSON, .glb binary, or a resolved response

Resolution

Buffers, images, external files, and nested assets

Compression

Draco, meshopt, and KTX2/Basis extension paths

Output

Scenegraph JSON plus optional typed and decoded resources

From-v1.0

Parses a glTF file. It loads both the .glb (binary) and .gltf (application/json) variants, then keeps the standards-shaped JSON available alongside any resolved buffers, images, and decoded extension data.

Start with the output you need
  • Use GLTFLoader when you need the glTF document, linked resources, or extension processing.
  • Use GLTFIterator or GLTFScenegraph when traversal should be more convenient than following indices in the source JSON.
  • Use convertGLTFToMeshArrow() when static primitive attributes should enter a shared Mesh Arrow table without baking scene transforms into the geometry.
InputOutputAPIs
.gltf JSON, .glb binary, and draft glTF 2.1 assetsScenegraph category data: source json plus optional buffers, images, files, and externalAssetsload, parse

The loader automatically attempts best-effort conversion of older glTF v1 files to glTF v2 by default (options.gltf.normalize: true). This conversion has limitations; use the normalization helpers below when an application needs diagnostics or strict rejection of unsupported legacy features. See the glTF 1 to glTF 2 conversion support table for required transformations, implemented subsets, and known gaps. Strict mode only rejects reported unsupported features; it does not perform complete glTF 2 validation. Setting normalize: false rejects glTF 1 input rather than returning an unconverted asset.

Conversion includes camera dictionaries and references, conventional vertex attribute aliases (JOINT, WEIGHT, TEXCOORD, and COLOR), inverse-bind accessor references, and embedded KHR_binary_glTF images. Untouched external buffer URIs are retained; the named binary body is moved to buffer index zero with its references and loaded payloads. Compatible accessor strides move to separate buffer views. Other safe raw layouts are repacked after buffers load, repairing strides, component/vertex alignment, and matrix-column padding while preserving original bytes and image views. Joint names resolve in order within explicit skeleton subtrees per instance, or globally when unique; multiple disjoint roots are supported when they share an unambiguous common ancestor; shared skins are cloned for distinct bindings. Absent or identity bind shapes are consumed. Finite affine non-identity bind shapes are baked into packed FLOAT MAT4 inverse-bind matrices after buffers load. The conversion appends aligned results to copied buffers, preserving original accessor data and palette order. Missing payloads, invalid spans or strides, unresolved or disconnected skin bindings, unsupported matrix data, and sparse or extension-bearing data requiring repacking are reported and rejected in strict mode. Complete skin/attribute validation remains unsupported.

The direct normalization helpers require loaded buffers for binary repacking, attribute component conversion, bounds calculation, payload checks, and non-identity bind shapes. GLTFLoader completes these conversions after linked buffers load; loadBuffers: false can only convert already available embedded payloads. Missing payloads are reported in best-effort mode and rejected in strict mode. When direct conversion changes a URI-backed buffer, its URI becomes an updated data URI. Other URIs are retained.

Conventional indexed joint/weight names and custom attribute namespaces are normalized. Valid scalar/vector joint indices become unsigned byte/short VEC4 data without changing palette indices; smaller joint and weight vectors are padded with zeros. Shared consumers keep separate accessor metadata. Unsigned integer color, weight, and UV values confined to [0, 1] become FLOAT values to retain their glTF 1 numeric inputs. Larger unsigned values are normalized by convention in best-effort mode, with an explicit unsupported-feature diagnostic; strict mode rejects that ambiguity. Compatible explicit normalized unsigned accessors are retained. Signed BYTE/SHORT UVs become FLOAT using literal values or the explicit normalized flag. Signed colors/weights are converted only when values remain in [0, 1]; smaller weight vectors are padded. Integer BYTE/SHORT normals and tangents (including unsigned types) become FLOAT using literal or explicit normalized values only when the decoded directions are already unit length and tangent handedness is ±1. They are not renormalized. Opaque extension consumers block these interpretation conversions. These notes use the supplied logger and do not interpret arbitrary shader code.

Fully detached skeleton hierarchies can be added to scenes that instantiate their skins when the hierarchy contains no renderable objects or opaque node extensions. Local transforms and palette order are preserved. Supplied joint/weight sets are checked per mesh/skin binding for compatible shapes/counts, contiguous pairing, palette ranges, finite weights, sums of one, and repeated weighted joints. Missing JOINTS_0/WEIGHTS_0 is reported; weights are not renormalized. Supplied inverse-bind matrices are validated for FLOAT MAT4 shape, sufficient count, finite values, and an affine fourth row, including absent/identity bind shapes and unused skins.

Required position and animation-input bounds are calculated from validated loaded bytes. Compatible LINEAR/STEP TRS animations retain their samples; checks cover time ordering, target/output shapes, key counts, finite values, unit rotation quaternions, duplicate targets, and unresolved references. Camera projection values are also checked. Invalid values are reported in best effort and rejected in strict mode. Translation-only animated matrices are decomposed to equivalent TRS fields when finite, affine, nonsingular, and free of shear. Their rotation/scale linear transform is preserved and checked by recomposition. Rotation or scale animation on matrix nodes requires an unambiguous basis and remains unsupported, as do conflicting TRS fields and opaque node extensions. Spline generation and complete conformance validation remain unsupported. These diagnostics and bounds checks also require loaded payloads when source bounds already exist.

Every declared buffer/view span is checked, including unused resources. Missing buffer lengths are inferred only from loaded URI-backed data without buffer extensions, using the borrowed logical slice. Declared lengths may be smaller than the resource payload, including GLB padding. Missing buffer-view lengths are inferred from the smallest envelope containing every dense accessor consumer when loaded data proves that span fits the logical buffer. Image or sparse owners, unknown extension consumers, unused views, and invalid accessor layouts prevent inference. Source buffer bytes are retained. Missing BIN-buffer lengths are not guessed. Inferences use the supplied logger.

Primitive vertex attributes must have matching positive counts. Core NORMAL/TANGENT attributes require finite unit directions and tangent handedness ±1. Standard color/UV/joint/weight shapes and component types are checked, and color/weight values must remain in [0, 1]. Attribute sets start at zero and are consecutive. Primitive modes and draw counts are checked for indexed and unindexed core topology; opaque extension topology is not interpreted. Invalid geometry is reported rather than repaired, so strict mode rejects some invalid assets previously accepted. Loaded indices are checked for unnormalized unsigned SCALAR storage and range against every consuming primitive. Byte indices containing 255 are widened to short storage; short indices containing 65535 are widened to integer storage. Widening preserves values and separates shared raw vertex consumers. The UINT32 maximum (4294967295) cannot be represented as a core glTF 2 index and is reported. Missing or opaque index bytes are also reported. A reserved index used by an opaque primitive extension is retained and reported, with a separate accessor for core consumers.

Obsolete asset profile/premultiplied-alpha and texture format/type/target fields move under each object's extras.gltf1.legacyFields, preserving application extras. True premultiplied alpha and non-default texture settings are reported as requiring additional rendering conversion.

For applications that need explicit conversion diagnostics, normalizeGLTFV1() returns a report listing unsupported legacy features. Use normalize: 'strict' to reject those features instead of continuing with a best-effort conversion. convertGLTFV1ToGLTF2() performs the same conversion on a cloned JSON document and leaves the caller's asset untouched. Legacy techniques, programs, and shaders are preserved under json.extras.gltf1Resources; their shader behavior is not translated.

GLTFLoader sends conversion notes and warnings about assumptions and unsupported features through options.core.log, using probe.gl-compatible lazy logging methods. The direct helpers accept the same logger as options.log; absent or null loggers leave diagnostics in the report only. Informational start and completion messages use log level 1, and warnings are emitted as they occur, including before strict-mode rejection. The report's aggregate warning does not duplicate logger output.

const converted = convertGLTFV1ToGLTF2(gltfWithLoadedBuffers, {
normalize: 'best-effort',
log // A probe.gl-compatible logger supplied by the application.
});

Best-effort material conversion recognizes conventional values.diffuse RGBA factors and diffuse texture IDs (tex, texture2d_0, diffuseTex, or diffuse). It approximates these as non-metallic, rough PBR materials. A finite scalar values.transparency in [0, 1] multiplies the diffuse alpha, with 0 meaning transparent and 1 opaque; resulting alpha below 1 enables blending unless an alpha mode is already supplied. Explicit PBR factors are retained. Invalid diffuse factors are not emitted as PBR factors. The original technique and values remain in material.extras.gltf1, and the report identifies the approximation and unsupported technique. Strict mode rejects these legacy material techniques even when a diffuse texture or color is recognized. This does not reproduce arbitrary shaders, legacy lighting, or premultiplied-alpha rendering, and does not establish visual equivalence in downstream viewers.

Material-level KHR_materials_common conversion resolves diffuse/emission texture IDs and supports LAMBERT and diffuse-only PHONG/BLINN with rough, non-metallic PBR factors. These lighting models are approximated, and the supplied logger and report receive a note even in strict mode. Nonzero ambient or specular lighting is reported as unsupported and rejected in strict mode; shininess has no effect when specular color is zero. Lit emission maps to emissive properties, with a white multiplier for texture-only emission. CONSTANT uses emission as unlit base color, never diffuse, and generates KHR_materials_unlit. Its default emission is black; ambient-dependent behavior remains unsupported. The loader's existing unlit decoder annotates these materials with unlit: true. GLTFWriter restores that annotation as a required KHR_materials_unlit extension for export; raw optional unlit extensions remain optional. Assets without binary data omit the optional BIN chunk.

Common transparent and double-sided flags may occur in values or at the extension root. They must be booleans, default to false, and conflicting locations are reported. Valid transparency multiplies base-color alpha. The transparent flag controls BLEND versus OPAQUE independently of that alpha; explicit glTF 2 material fields take precedence. Recognized color values require finite RGBA factors in [0, 1]; images are not transcoded. All original common data is retained under material.extras.gltf1.commonMaterial without discarding existing application extras.

Consumed common declarations are removed only when no live common payload remains. Unresolved common lights and unknown models retain their payloads and declarations. Generated unlit is required when the source common extension was required. Complete fallback technique/program/shader chains overridden by converted common materials are preserved without strict rejection; this exemption does not apply to unaccounted resources, remaining programmable materials, or opaque extension consumers. Small material exports are independently validated in tests; runtime conversion still does not provide a full validator or appearance guarantee.

Usage​

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

To decompress Draco-compressed meshes:

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

Draco mesh indices are decoded as triangle lists (mode: 4), including compressed triangle-strip primitives. This keeps the decoded index buffer and primitive mode consistent; the standalone Draco loader's topology option does not change this glTF representation.

Draco decompression preserves attributes stored outside the compressed bitstream. Compression is decoded before metadata and feature extensions, so EXT_mesh_features can consume both decoded and uncompressed feature ID attributes. Later topology decoders also accept decoded Draco index accessors.

Draco and meshopt decoders are maintained by the glTF module. For linked buffers, images, or draft glTF 2.1 files, enable the matching gltf.load* options described below.

Detailed guide

Loader behavior and options

The reference below covers loading modes, post-processing, extension handling, scenegraph conversion, and the complete option surface.

Overview​

The GLTFLoader aims to take care of as much processing as possible, while remaining framework-independent.

Draft glTF 2.1 readiness includes the new accessor component type definitions. GLTFScenegraph and getGLTFAccessorValue expose these values through the corresponding JavaScript typed arrays.

The loader also supports draft glTF 2.1 thumbnails. When asset.thumbnail references an image, gltf.loadImages: true loads that image even if it is not used by a texture.

The GLTF Loader returns an object with a json field containing the glTF Scenegraph. In its basic mode, the GLTFLoader does not modify the loaded JSON in any way. Instead, the results of additional processing are placed in parallel top-level fields such as buffers and images. This ensures that applications that want to work with the standard glTF data structure can do so.

Audio extensions add the following optional fields to the loader result. Original audio extension declarations and extension lists are retained.

Result fieldExtensionContents
audioClipsDraft KHR_audio_emitterEncoded Uint8Array data and original resource declarations, parallel to the extension's audio array.
audioEmittersDraft KHR_audio_emitterNode and scene emitter instances with resolved source and clip references.
spatialAudioMPEG_audio_spatialRoot and node audio declarations, including accessor indices, listeners and reverbs.

gltf.loadAudio: false retains KHR emitter and clip metadata without fetching audio URIs or populating audioClips[].data. External buffers containing audio still load when gltf.loadBuffers is true; disable both options to avoid those downloads. The application handles media decoding, playback, spatialization, and MPEG timed-media behavior. autoplay remains a declaration for that application to interpret.

The extension schemas and helpers also expose material variants, GPU instance attributes, animation pointers, node interaction flags and XMP packets. These schemas validate known fields while preserving unknown data; the loader retains runtime-dependent declarations in the source JSON.

For applications that need static geometry in the Mesh Arrow layout, use convertGLTFToMeshArrow() after loading. It converts each source primitive once and returns node placements separately, preserving mesh reuse. Dense, packed accessors retain views of source buffers; interleaved, sparse, and implicit-zero accessors are materialized without changing their logical component values. Conversion does not modify the glTF or bake node transforms, skinning, morph targets, or GPU instancing.

import {load} from '@loaders.gl/core';
import {GLTFLoader} from '@loaders.gl/scene/gltf';
import {convertGLTFToMeshArrow} from '@loaders.gl/scene/gltf/mesh-arrow';

const gltf = await load(url, GLTFLoader);
const meshArrow = convertGLTFToMeshArrow(gltf);

The result separates reusable source geometries from scene placements. Each geometry contains one Arrow table per mesh primitive plus the original attribute component types and normalization metadata; each placement identifies the source node and its world transform. All glTF primitive attributes are projected as columns, including normals, tangents, texture coordinates, colors, joints, and weights. Standard glTF point, line, and triangle modes are represented by the table's topology metadata. The converter does not modify the input JSON or buffers.

Optionally, the loaded gltf can be "post processed", which lightly annotates and transforms the loaded JSON structure to make it easier to use. Refer to postProcessGLTF for details.

In addition, certain glTF extensions, including Draco and meshopt compression, can be fully or partially processed during loading. When possible (and extension processing is enabled), such extensions will be resolved/decompressed and replaced with standards conformant representations.

GLTFLoader provides asynchronous parsing through parse and load; it does not provide parseSync. Async parsing supports the following resource processing:

  • linked binary resource URI:s will be loaded and resolved (assuming a valid base url is available).
  • base64 encoded binary URI:s inside the JSON payload will be decoded.
  • linked image URI:s can be loaded and decoded.
  • linked raster image URI:s are decoded through ImageLoader, producing ImageBitmap in browsers and the Node.js ImageBitmap polyfill when @loaders.gl/core/polyfills is installed.
  • Draco meshes can be decoded asynchronously on worker threads (in parallel!).

Legacy Gaussian splats​

Some draft SPZ2-compressed Gaussian glTF files, including the Cesium Gaussian splat test assets, omit the now-required kernel and color-space metadata. When the asset's color space is known, set gltf.legacyGaussianSplatColorSpace to 'srgb_rec709_display' or 'lin_rec709_display'. The loader then supplies the missing color space and an ellipse kernel in the returned Gaussian primitive descriptor. It retains the original JSON and never overrides authored values. Without the option, missing metadata remains an error. This option is an application-provided assumption, not a conversion of color values; choose it based on the asset's provenance. Inject an SPZ loader in the normal loader list to decode the payload.

Options​

OptionTypeDefaultDescription
gltf.loadBuffersBooleantrueFetch any referenced binary buffer files (and decode base64 encoded URIs).
gltf.loadFilesBooleanfalseResolve draft glTF 2.1 files entries from URIs or buffer views.
gltf.loadExternalAssetsBooleanfalseRecursively parse draft glTF 2.1 external assets instantiated by scene nodes.
gltf.loadImagesBooleantrueLoad images referenced by textures or the draft glTF 2.1 thumbnail.
gltf.loadAudioBooleantrueLoad encoded draft KHR_audio_emitter clips. Independent of loadBuffers; does not decode or play audio.
gltf.decompressMeshesBooleantrueDecompress Draco and KHR/EXT meshopt data.
gltf.normalizeBoolean or stringtrueAutomatically attempt glTF 1 to 2 conversion. true / 'best-effort' continue through reported gaps; 'strict' rejects reported unsupported features; false rejects glTF 1 input.

Meshopt decompression​

GLTFLoader supports both the existing EXT_meshopt_compression extension and the newer KHR_meshopt_compression extension. KHR adds version 1 attribute streams and the COLOR filter; support for KHR does not replace EXT because glTF capability negotiation uses the exact extension name and existing assets continue to declare EXT.

Meshopt decoding is available during asynchronous parsing when gltf.loadBuffers and gltf.decompressMeshes are both enabled. The maintained decoder ships with @loaders.gl/scene/gltf, so there is no decoder option or application-level initialization step. Successful decoding writes the uncompressed bytes into the buffer range described by the parent buffer view and removes the processed extension declarations. The compressed source buffer remains in the returned data.

Set gltf.decompressMeshes to false to retain both KHR and EXT declarations for another component to process. See Meshopt compression for the stream versions, modes, filters, fallback-buffer behavior, and comparison with Draco.

Draft glTF 2.1 File Resolution​

resolveGLTFFile(gltf, fileReference, options, context) resolves one entry from the draft glTF 2.1 files array. fileReference can be an array index, a package name matching files[*].name, or an original URI matching files[*].uri. URI-backed files are fetched relative to the containing asset; buffer-view-backed files return a view of the already loaded buffer without copying it. Resolved entries are cached in the parallel gltf.files array.

findGLTFFileIndex(gltf, reference) performs only the virtual package lookup and returns -1 when there is no matching entry. Ambiguous package names are rejected.

Draft glTF 2.1 External Assets​

With gltf.loadExternalAssets: true, GLTFLoader parses external assets referenced by json.nodes[*].externalAsset. Parsed children are stored in gltf.externalAssets at the same index as their json.externalAssets definition. Repeated references to the same URI share one parsed result, and cyclical references are rejected.

Dependencies of URI-backed children resolve relative to the child URI. Dependencies of embedded children resolve through the containing asset's files array, allowing an unmodified nested glTF and its buffers or textures to be packaged together. Unreferenced definitions remain unloaded.

Working with GLTF data​

The job of GLTFLoader is to open the glTF container file(s) and extract the glTF JSON, together with any associated binary chunks and images.

If you already have access to libraries or code that process standard glTF JSON directly, this format may be appropriate. However, in this storage-optimized form, traversing the loaded glTF scene graph tends to require verbose and repetitive code with many checks and guards.

To simplify traversal and manipulation of glTF data, loaders.gl provides indexed traversal and editing APIs:

  • The GLTFIterator class lazily resolves references while preserving the original glTF JSON objects, making it suitable for extension transformations.
  • For rendering, luma.gl owns postProcessGLTF(), which creates a separate resolved document.
  • The GLTFScenegraph class accepts glTF data and provides methods for accessing or modifying APIs.

The gltf module provides typescript definitions for the glTF JSON that align with the glTF specification, and all APIs and return values are strongly typed to assist applications to write robust code.

Data Format​

The data format returned by the GLTFLoader is the unmodified glTF JSON extracted from any binary containers, together with loaded binary chunks and optionally loaded images.

The standard glTF JSON structure will be available in the json field.

{
json: {
scenes: [...],
scene: ...,
nodes: [...],
...
}
}

References inside these arrays remain numeric. Resource decoding may replace compressed storage with decoded accessors; use getGLTFAccessorValue or GLTFIterator to read them.

{
// The base URI used to load this glTF, if any. For resolving relative uris to linked resources.
baseUri: String,

// JSON Chunk
json: Object, // Contains the unmodified parsed glTF JSON (the parsed GLB JSON chunk)

// Length and indices of this array will match `json.buffers`
// GLB v1/v2's bin chunk, or GLB v3 chunks selected by json.buffers[*].chunk.
// Additional glTF json `buffers` are fetched and base64 decoded from the JSON uri:s.
buffers: [{
arrayBuffer: ArrayBuffer,
byteOffset: Number,
byteLength: Number
}],

// Draft glTF 2.1 generic files. Length and indices match json.files.
files: [{
arrayBuffer: ArrayBuffer,
byteOffset: Number,
byteLength: Number,
mimeType: String,
name: String, // optional virtual package name
url: String // optional resolved URL
}],

// Recursively parsed glTF 2.1 assets. Indices match json.externalAssets.
// Unreferenced definitions remain null.
externalAssets: Array<GLTFWithBuffers | null>,

// Images can optionally be loaded and decoded, they will be stored here.
// Standard raster images are decoded through ImageLoader.
// Length and indices of this array will match `json.buffers`
images: Array<ImageBitmap | object>,

// GLBLoader output, if this was a GLB encoded glTF
_glb?: Object
}

For draft GLB v3 files, GLTFLoader resolves each json.buffers[*].chunk index to the corresponding BIN chunk. See the GLB format documentation for indexing and legacy fallback rules.

FieldTypeDefaultDescription
baseUriString``length of GLB (e.g. embedded in larger binary block)
jsonObject{}Parsed JSON from the JSON chunk
buffersObject[][]The version number
buffers[\*].arrayBufferArrayBuffernullThe binary chunk
buffers[\*].byteOffsetNumbernulloffset of buffer (embedded in larger binary block)
buffers[\*].byteLengthArrayBuffernulllength of buffer (embedded in larger binary block)
_glb?ObjectN/AThe output of the GLBLoader if the parsed file was GLB formatted

Interactivity graphs​

The loader preserves KHR_interactivity graph declarations. See the glTF format guide for the graph types, getGLTFInteractivity accessor, validation, and runtime responsibilities.

Double-precision accessor declarations​

For assets declaring the draft KHR_accessor_float64, GLTFLoader verifies that both extension declaration arrays contain the extension and that accessors with componentType: 5130 are not normalized. Invalid declarations throw before resource loading. The extension is retained, and accessor reads preserve binary64 precision using the existing Float64Array path. No new loader option is required.

This check uses the standard extension pipeline and is skipped if the extension is listed in gltf.excludeExtensions. It does not certify renderer support or validate every accessor usage site. See the format documentation for the pinned draft and limitations.