Skip to main content

Draco module · loader API

DracoLoader

Decode compressed meshes and point clouds into a render-ready Mesh object or a Mesh Arrow table, with worker and backend controls for browser applications.

What it returns

Decode once. Keep the geometry useful downstream.

DracoLoader expands compressed attribute maps into the mesh family used by rendering and processing code, while preserving metadata and optional typed columnar output.

Input

Draco-compressed mesh or point cloud

Default

Mesh Arrow table

Arrow

Mesh Arrow table with attribute columns

Execution

WASM, JavaScript, or injected Draco backend

Detailed guide

DracoLoader reference

The sections below document usage, output shapes, supported attributes, metadata, backends, and module overrides.

DracoLoader decodes a mesh or point cloud (maps of attributes) using DRACO compression. It returns a Mesh Arrow table by default. Set draco.shape: 'mesh' for the legacy Mesh object.

Usage​

import {DracoLoader} from '@loaders.gl/scene/draco';
import {load} from '@loaders.gl/core';

const data = await load(url, DracoLoader, options);
const table = await load(url, DracoLoader, {
worker: false,
draco: {shape: 'arrow'}
});

Shapes​

DracoLoader returns Mesh Arrow tables by default. Set draco.shape to select another representation.

ShapeOutput
meshlegacy loaders.gl Mesh object
arrowloaders.gl Mesh Arrow table with geometry attribute columns

Support​

For detailed information

General:

  • Supports meshes and point clouds.
  • Loads the Draco 1.5.7 decoder dynamically or from package-local assets.
  • Supports meshes and point clouds.

Attributes:

  • Supports custom attributes.
  • Preserves multiple color, texture-coordinate, and other same-category attributes. When a Draco file has no name metadata, inferred names are made unique with numeric suffixes such as COLOR_0, COLOR_1, TEXCOORD_0, and TEXCOORD_1.
  • Ability to prevent decompression of specific attributes (returns quantization or octahedron transform parameters, if application wishes to perform decompression on GPU).

Metadata Support:

  • Extracts metadata dictionaries, both for the full mesh and for each attribute.
  • Supports all Draco metadata field types, including Int32Array.

DracoLoaderOptions​

OptionTypeDefaultDescription
draco.shapestring'arrow'Output shape: 'arrow' or 'mesh'.
draco.backendstring'wasm' when WebAssembly is availableDraco decoder backend: 'wasm', 'javascript', or 'draco3d'.
draco.extraAttributesobject{}Additional custom attributes to decode.
draco.attributeNameEntrystringN/AMetadata entry used to map Draco attribute ids to output attribute names.

Dependencies​

draco.decoderProfile selects 'full' (the default) or 'gltf', the smaller decoder subset for glTF-compatible mesh bitstreams. The glTF loader selects 'gltf' by default when decoding KHR_draco_mesh_compression; callers can explicitly select 'full' to share one runtime.

Draco libraries load from a CDN by default. Browser applications can bundle the vendored runtimes with getDracoLibraryOptions from the existing @loaders.gl/scene/draco entrypoint.

Bundled Library Options​

getDracoLibraryOptions({decoderProfile}) returns the selected profile and a modules map for its matching WASM wrapper and binary, the encoder, and the JavaScript fallback. It preserves supplied CDN and useLocalLibraries settings; explicit modules overrides win. The helper owns the asset URLs, so applications do not need to maintain filename mappings. Only requested runtimes are fetched. This opt-in entrypoint keeps asset references out of the metadata-only root import.

import {parse} from '@loaders.gl/core';
import {DracoLoader} from '@loaders.gl/scene/draco';
import {getDracoLibraryOptions} from '@loaders.gl/scene/draco';

const libraries = getDracoLibraryOptions({decoderProfile: 'gltf'});
const mesh = await parse(bytes, DracoLoader, {
core: {worker: false},
modules: libraries.modules,
draco: {shape: 'mesh', decoderProfile: libraries.decoderProfile}
});

The example uses main-thread parsing; applications using loader workers must also supply a bundled worker URL if CDN worker loading is unwanted. Library URL overrides are strings and can be passed to workers without transferring functions.

Module Overrides​

Use options.modules to override the Draco decoder runtime used by DracoLoader.

  • modules.draco3d: supply the bundled draco3d package. DracoLoader uses createDecoderModule() from this object.
  • Set draco.backend: 'draco3d' to select the injected modules.draco3d backend explicitly.
  • 'draco_wasm_wrapper.js': override the URL used for the Draco WASM decoder wrapper.
  • 'draco_decoder.wasm': override the URL used for the Draco WASM decoder binary.
  • 'draco_decoder.js': override the URL used for the Draco JavaScript fallback decoder.

When the default WebAssembly backend cannot be initialized, DracoLoader attempts the JavaScript decoder before reporting a load failure. Set draco.backend: 'javascript' to select that implementation explicitly.