Chevron DownAPI Reference

Overview

logo

The @loaders.gl/draco module handles compressing and decompressing of 3D meshes and point clouds with DRACO.

Installation

npm install @loaders.gl/core @loaders.gl/draco

Loaders and Writers

Loader
DracoLoader
DracoWorkerLoader
DracoWriter

Additional APIs

See point cloud / mesh category.

Dependencies

Draco support requires the Draco libraries, which are quite big (see table below). By default, these will be loaded from CDN but can optionally be bundled and supplied by the application through the top-level options.modules option:

Bundling the entire draco3d library:

import draco from 'draco3d';
import {setLoaderOptions} from '@loaders.gl/core';
setLoaderOptions({
  modules: {
    draco3d
  }
});

Bundling only the WebAssembly decoder

import {setLoaderOptions} from '@loaders.gl/core';
setLoaderOptions({
  modules: {
    'draco_wasm_wrapper.js': require('@loaders.gl/draco/libs/draco_wasm_wrapper.js'),
    'draco_decoder.wasm': require('@loaders.gl/draco/libs/draco_decoder.wasm') // NOTE: importing `wasm` requires bundler config
  }
});
LibraryImportInstallSizeDescription
options.libs.draco3drequire('draco3d')npm install draco3d~1.5MBThe full Draco library (encode + decode, web assembly + IE11 javascript fallback).
options.libs['draco_decoder.wasm']ArrayBuffer~320Kmanual copyWeb Assembly Decoder (access using draco_wasm_wrapper.js)
options.libs['draco_wasm_wrapper.js']require('.../draco_decoder.js')~64Kmanual copyJavaScript wrapper for draco_decoder.wasm
options.libs['draco_decoder.js']require('.../draco_decoder.js')~790Kmanual copyJavaScript decoder (fallback for IE11)
options.libs['draco_encoder.js']require('.../draco_encode.js')~900Kmanual copyEncoder part of the library

Remarks

  • Due to the size of the Draco libraries, a reasonable strategy for applications that wish to bundle their dependencies (e.g to avoid relying on a potentially flaky CDN) might be to bundle and supply only draco_decoder.wasm and draco_wasm_wrapper.js, and still rely on the default setup to load the IE11 fallback library and the encoder code from CDN when needed.
  • Web Assembly code (wasm files) must be imported/loaded as binary data (ArrayBuffer). An option for webpack users is the arraybuffer-loader webpack "loader".

Attributions

Based on Draco examples, under the Apache 2.0 license.