DRACOLoader.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Loader] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">
  14. A loader for geometry compressed with the Draco library. <br /><br />
  15. [link:https://google.github.io/draco/ Draco] is an open source library for compressing and
  16. decompressing 3D meshes and point clouds. Compressed geometry can be significantly smaller,
  17. at the cost of additional decoding time on the client device.
  18. </p>
  19. <p>
  20. Standalone Draco files have a <em>.drc</em> extension, and contain vertex positions,
  21. normals, colors, and other attributes. Draco files <em>do not</em> contain materials,
  22. textures, animation, or node hierarchies – to use these features, embed Draco geometry
  23. inside of a glTF file. A normal glTF file can be converted to a Draco-compressed glTF file
  24. using [link:https://github.com/AnalyticalGraphicsInc/gltf-pipeline glTF-Pipeline]. When
  25. using Draco with glTF, an instance of DRACOLoader will be used internally by [page:GLTFLoader].
  26. </p>
  27. <h2>Example</h2>
  28. <code>
  29. // Instantiate a loader
  30. var loader = new THREE.DRACOLoader();
  31. // Specify path to a folder containing WASM/JS decoding libraries.
  32. loader.setDecoderPath( '/examples/js/libs/draco/' );
  33. // Optional: Pre-fetch Draco WASM/JS module.
  34. loader.preload();
  35. // Load a Draco geometry
  36. loader.load(
  37. // resource URL
  38. 'model.drc',
  39. // called when the resource is loaded
  40. function ( geometry ) {
  41. var material = new THREE.MeshStandardMaterial( { color: 0x606060 } );
  42. var mesh = new THREE.Mesh( geometry, material );
  43. scene.add( mesh );
  44. },
  45. // called as loading progresses
  46. function ( xhr ) {
  47. console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
  48. },
  49. // called when loading has errors
  50. function ( error ) {
  51. console.log( 'An error happened' );
  52. }
  53. );
  54. </code>
  55. [example:webgl_loader_draco]
  56. <h2>Browser compatibility</h2>
  57. <p>DRACOLoader relies on ES6 [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise Promises],
  58. which are not supported in IE11. To use the loader in IE11, you must
  59. [link:https://github.com/stefanpenner/es6-promise include a polyfill]
  60. providing a Promise replacement. DRACOLoader will automatically use
  61. either the JS or the WASM decoding library, based on browser
  62. capabilities.</p>
  63. <br>
  64. <hr>
  65. <h2>Constructor</h2>
  66. <h3>[name]( [param:LoadingManager manager] )</h3>
  67. <p>
  68. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  69. </p>
  70. <p>
  71. Creates a new [name].
  72. </p>
  73. <h2>Properties</h2>
  74. <p>See the base [page:Loader] class for common properties.</p>
  75. <h2>Methods</h2>
  76. <p>See the base [page:Loader] class for common methods.</p>
  77. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  78. <p>
  79. [page:String url] — A string containing the path/URL of the <em>.drc</em> file.<br />
  80. [page:Function onLoad] — A function to be called after the loading is successfully completed.<br />
  81. [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.<br />
  82. [page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.<br />
  83. </p>
  84. <p>
  85. Begin loading from url and call the <em>onLoad</em> function with the decompressed geometry.
  86. </p>
  87. <h3>[method:this setDecoderPath]( [param:String value] )</h3>
  88. <p>
  89. [page:String value] — Path to folder containing the JS and WASM decoder libraries.
  90. </p>
  91. <h3>[method:this setDecoderConfig]( [param:Object config] )</h3>
  92. <p>
  93. [page:String config.type] - (Optional) <em>"js"</em> or <em>"wasm"</em>.<br />
  94. </p>
  95. <p>
  96. Provides configuration for the decoder libraries. Configuration cannot be changed
  97. after decoding begins.
  98. </p>
  99. <h3>[method:this setWorkerLimit]( [param:Number workerLimit] )</h3>
  100. <p>
  101. [page:Number workerLimit] - Maximum number of workers to be allocated. Default is 4.<br />
  102. </p>
  103. <p>
  104. Sets the maximum number of [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers Web Workers]
  105. to be used during decoding. A lower limit may be preferable if workers are also for other tasks
  106. in the application.
  107. </p>
  108. <h3>[method:this preload]()</h3>
  109. <p>
  110. Requests the decoder libraries, if not already loaded.
  111. </p>
  112. <h3>[method:this dispose]()</h3>
  113. <p>
  114. Disposes of the decoder resources and deallocates memory. The decoder
  115. [link:https://github.com/google/draco/issues/349 cannot be reloaded afterward].
  116. </p>
  117. <h2>Source</h2>
  118. <p>
  119. [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/DRACOLoader.js examples/js/loaders/DRACOLoader.js]
  120. </p>
  121. </body>
  122. </html>