You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.3 KiB

2 years ago
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../../" />
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
[page:Loader] &rarr;
<h1>[name]</h1>
<p class="desc">
A loader for geometry compressed with the Draco library. <br /><br />
[link:https://google.github.io/draco/ 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.
</p>
<p>
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 [link:https://github.com/AnalyticalGraphicsInc/gltf-pipeline glTF-Pipeline]. When
using Draco with glTF, an instance of DRACOLoader will be used internally by [page:GLTFLoader].
</p>
<p>
It is recommended to create one DRACOLoader instance and reuse it to avoid loading and creating multiple
decoder instances.
</p>
<h2>Code Example</h2>
<code>
// Instantiate a loader
const loader = new DRACOLoader();
// Specify path to a folder containing WASM/JS decoding libraries.
loader.setDecoderPath( '/examples/js/libs/draco/' );
// Optional: Pre-fetch Draco WASM/JS module.
loader.preload();
// Load a Draco geometry
loader.load(
// resource URL
'model.drc',
// called when the resource is loaded
function ( geometry ) {
const material = new THREE.MeshStandardMaterial( { color: 0x606060 } );
const mesh = new THREE.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' );
}
);
</code>
<h2>Examples</h2>
<p>
[example:webgl_loader_draco]
</p>
<h2>Browser compatibility</h2>
<p>DRACOLoader relies on ES6 [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise Promises],
which are not supported in IE11. To use the loader in IE11, you must
[link:https://github.com/stefanpenner/es6-promise include a polyfill]
providing a Promise replacement. DRACOLoader will automatically use
either the JS or the WASM decoding library, based on browser
capabilities.</p>
<br>
<hr>
<h2>Constructor</h2>
<h3>[name]( [param:LoadingManager manager] )</h3>
<p>
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
</p>
<p>
Creates a new [name].
</p>
<h2>Properties</h2>
<p>See the base [page:Loader] class for common properties.</p>
<h2>Methods</h2>
<p>See the base [page:Loader] class for common methods.</p>
<h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
<p>
[page:String url] — A string containing the path/URL of the `.drc` file.<br />
[page:Function onLoad] — A function to be called after the loading is successfully completed.<br />
[page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, that contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.<br />
[page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.<br />
</p>
<p>
Begin loading from url and call the `onLoad` function with the decompressed geometry.
</p>
<h3>[method:this setDecoderPath]( [param:String value] )</h3>
<p>
[page:String value] — Path to folder containing the JS and WASM decoder libraries.
</p>
<h3>[method:this setDecoderConfig]( [param:Object config] )</h3>
<p>
[page:String config.type] - (Optional) `"js"` or `"wasm"`.<br />
</p>
<p>
Provides configuration for the decoder libraries. Configuration cannot be changed
after decoding begins.
</p>
<h3>[method:this setWorkerLimit]( [param:Number workerLimit] )</h3>
<p>
[page:Number workerLimit] - Maximum number of workers to be allocated. Default is 4.<br />
</p>
<p>
Sets the maximum number of [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers Web Workers]
to be used during decoding. A lower limit may be preferable if workers are also for other tasks
in the application.
</p>
<h3>[method:this preload]()</h3>
<p>
Requests the decoder libraries, if not already loaded.
</p>
<h3>[method:this dispose]()</h3>
<p>
Disposes of the decoder resources and deallocates memory. The decoder
[link:https://github.com/google/draco/issues/349 cannot be reloaded afterward].
</p>
<h2>Source</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/DRACOLoader.js examples/jsm/loaders/DRACOLoader.js]
</p>
</body>
</html>