Loader

DRACOLoader

A loader for geometry compressed with the Draco library.

Draco is an open source library for compressing and decompressing 3D meshes and point clouds. Compressed geometry can be significantly smaller, at the cost of additional decoding time on the client device.

Standalone Draco files have a .drc extension, and contain vertex positions, normals, colors, and other attributes. Draco files do not contain materials, textures, animation, or node hierarchies – to use these features, embed Draco geometry inside of a glTF file. A normal glTF file can be converted to a Draco-compressed glTF file using glTF-Pipeline. When using Draco with glTF, an instance of DRACOLoader will be used internally by GLTFLoader.

Example

// Instantiate a loader var loader = new v3d.DRACOLoader(); // Specify path to a folder containing WASM/JS decoding libraries. v3d.DRACOLoader.setDecoderPath('/examples/js/libs/draco'); // Optional: Pre-fetch Draco WASM/JS module. v3d.DRACOLoader.getDecoderModule(); // Load a Draco geometry loader.load( // resource URL 'model.drc', // called when the resource is loaded function(geometry) { var material = new v3d.MeshStandardMaterial({ color: 0x606060 }); var mesh = new v3d.Mesh(geometry, material); scene.add(mesh); }, // called as loading progresses function(xhr) { console.log((xhr.loaded / xhr.total * 100) + '% loaded'); }, // called when loading has errors function(error) { console.log('An error happened'); } ); webgl_loader_draco

Browser compatibility

DRACOLoader relies on ES6 Promises, which are not supported in IE11. To use the loader in IE11, you must include a polyfill providing a Promise replacement. DRACOLoader will automatically use either the JS or the WASM decoding library, based on browser capabilities.



Constructor

DRACOLoader(manager : LoadingManager)

manager — The loadingManager for the loader to use. Default is v3d.DefaultLoadingManager.

Creates a new DRACOLoader.

Static Methods

.setDecoderPath (value : String) : null

value — Path to folder containing the JS and WASM decoder libraries.

.setDecoderConfig (config : Object) : null

config.type - (Optional) "js" or "wasm".

Provides configuration for the decoder libraries. Configuration cannot be changed after loading the decoders.

.getDecoderModule () : Promise

Requests the decoder libraries, if not already loaded.

.releaseDecoderModule () : null

Disposes of the decoder library and deallocates memory. The decoder cannot be reloaded afterward.

Methods

.load (url : String, onLoad : Function, onProgress : Function, onError : Function) : null

url — A string containing the path/URL of the .drc file.
onLoad — A function to be called after the loading is successfully completed.
onProgress — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, that contains .total and .loaded bytes.
onError — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.

Begin loading from url and call the onLoad function with the decompressed geometry.

.setPath (path : String) : DRACOLoader

path — Base path.

Set the base path for the .drc file.

Source

For more info on how to obtain the source code of this module see this page.