1
0

DRACOLoader.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>DRACOLoader - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="Loader.html">Loader</a> → </p>
  13. <h1 translate="no">DRACOLoader</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>A loader for the Draco format.</p>
  17. <p><a href="https://google.github.io/draco/" target="_blank" rel="noopener">Draco</a> is an open source library for compressing
  18. and decompressing 3D meshes and point clouds. Compressed geometry can be significantly smaller,
  19. at the cost of additional decoding time on the client device.</p>
  20. <p>Standalone Draco files have a <code>.drc</code> extension, and contain vertex positions, normals, colors,
  21. and other attributes. Draco files do not contain materials, textures, animation, or node hierarchies –
  22. to use these features, embed Draco geometry inside of a glTF file. A normal glTF file can be converted
  23. to a Draco-compressed glTF file using <a href="https://github.com/CesiumGS/gltf-pipeline" target="_blank" rel="noopener">glTF-Pipeline</a>.
  24. When using Draco with glTF, an instance of <code>DRACOLoader</code> will be used internally by <a href="GLTFLoader.html">GLTFLoader</a>.</p>
  25. <p>It is recommended to create one DRACOLoader instance and reuse it to avoid loading and creating
  26. multiple decoder instances.</p>
  27. <p><code>DRACOLoader</code> will automatically use either the JS or the WASM decoding library, based on
  28. browser capabilities.</p></div>
  29. <h2>Code Example</h2>
  30. <div translate="no"><pre><code class="language-js">const loader = new DRACOLoader();
  31. loader.setDecoderPath( '/examples/jsm/libs/draco/' );
  32. const geometry = await dracoLoader.loadAsync( 'models/draco/bunny.drc' );
  33. geometry.computeVertexNormals(); // optional
  34. dracoLoader.dispose();
  35. </code></pre></div>
  36. </header>
  37. <article>
  38. <h2 class="subsection-title">Import</h2>
  39. <p><span translate="no">DRACOLoader</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank" rel="noopener">Installation#Addons</a>.</p>
  40. <pre><code class="language-js">import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';</code></pre>
  41. <div class="container-overview">
  42. <h2>Constructor</h2>
  43. <h3 class="name name-method" id="DRACOLoader" translate="no">new <a href="#DRACOLoader">DRACOLoader</a><span class="signature">( manager : <span class="param-type"><a href="LoadingManager.html">LoadingManager</a></span> )</span> </h3>
  44. <div class="method">
  45. <div class="description">
  46. <p>Constructs a new Draco loader.</p>
  47. </div>
  48. <table class="params">
  49. <tbody>
  50. <tr>
  51. <td class="name">
  52. <strong>manager</strong>
  53. </td>
  54. <td class="description last">
  55. <p>The loading manager.</p>
  56. </td>
  57. </tr>
  58. </tbody>
  59. </table>
  60. </div>
  61. </div>
  62. <h2 class="subsection-title">Methods</h2>
  63. <h3 class="name name-method" id="load" translate="no">.<a href="#load">load</a><span class="signature">( url : <span class="param-type">string</span>, onLoad : <span class="param-type">function</span>, onProgress : <span class="param-type"><a href="global.html#onProgressCallback">onProgressCallback</a></span>, onError : <span class="param-type"><a href="global.html#onErrorCallback">onErrorCallback</a></span> )</span> </h3>
  64. <div class="method">
  65. <div class="description">
  66. <p>Starts loading from the given URL and passes the loaded Draco asset
  67. to the <code>onLoad()</code> callback.</p>
  68. </div>
  69. <table class="params">
  70. <tbody>
  71. <tr>
  72. <td class="name">
  73. <strong>url</strong>
  74. </td>
  75. <td class="description last">
  76. <p>The path/URL of the file to be loaded. This can also be a data URI.</p>
  77. </td>
  78. </tr>
  79. <tr>
  80. <td class="name">
  81. <strong>onLoad</strong>
  82. </td>
  83. <td class="description last">
  84. <p>Executed when the loading process has been finished.</p>
  85. </td>
  86. </tr>
  87. <tr>
  88. <td class="name">
  89. <strong>onProgress</strong>
  90. </td>
  91. <td class="description last">
  92. <p>Executed while the loading is in progress.</p>
  93. </td>
  94. </tr>
  95. <tr>
  96. <td class="name">
  97. <strong>onError</strong>
  98. </td>
  99. <td class="description last">
  100. <p>Executed when errors occur.</p>
  101. </td>
  102. </tr>
  103. </tbody>
  104. </table>
  105. <dl class="details">
  106. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Loader.html#load">Loader#load</a></dt>
  107. </dl>
  108. </div>
  109. <h3 class="name name-method" id="parse" translate="no">.<a href="#parse">parse</a><span class="signature">( buffer : <span class="param-type">ArrayBuffer</span>, onLoad : <span class="param-type">function</span>, onError : <span class="param-type"><a href="global.html#onErrorCallback">onErrorCallback</a></span> )</span> </h3>
  110. <div class="method">
  111. <div class="description">
  112. <p>Parses the given Draco data.</p>
  113. </div>
  114. <table class="params">
  115. <tbody>
  116. <tr>
  117. <td class="name">
  118. <strong>buffer</strong>
  119. </td>
  120. <td class="description last">
  121. <p>The raw Draco data as an array buffer.</p>
  122. </td>
  123. </tr>
  124. <tr>
  125. <td class="name">
  126. <strong>onLoad</strong>
  127. </td>
  128. <td class="description last">
  129. <p>Executed when the loading/parsing process has been finished.</p>
  130. </td>
  131. </tr>
  132. <tr>
  133. <td class="name">
  134. <strong>onError</strong>
  135. </td>
  136. <td class="description last">
  137. <p>Executed when errors occur.</p>
  138. </td>
  139. </tr>
  140. </tbody>
  141. </table>
  142. <dl class="details">
  143. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Loader.html#parse">Loader#parse</a></dt>
  144. </dl>
  145. </div>
  146. <h3 class="name name-method" id="setDecoderConfig" translate="no">.<a href="#setDecoderConfig">setDecoderConfig</a><span class="signature">( config : <span class="param-type">Object</span> )</span><span class="type-signature"> : <a href="DRACOLoader.html">DRACOLoader</a></span> </h3>
  147. <div class="method">
  148. <div class="description">
  149. <p>Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.</p>
  150. </div>
  151. <table class="params">
  152. <tbody>
  153. <tr>
  154. <td class="name">
  155. <strong>config</strong>
  156. </td>
  157. <td class="description last">
  158. <p>The decoder config.</p>
  159. </td>
  160. </tr>
  161. </tbody>
  162. </table>
  163. <dl class="details">
  164. <dt class="tag-returns"><strong>Returns:</strong> A reference to this loader.</dt>
  165. </dl>
  166. </div>
  167. <h3 class="name name-method" id="setDecoderPath" translate="no">.<a href="#setDecoderPath">setDecoderPath</a><span class="signature">( path : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="DRACOLoader.html">DRACOLoader</a></span> </h3>
  168. <div class="method">
  169. <div class="description">
  170. <p>Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.</p>
  171. </div>
  172. <table class="params">
  173. <tbody>
  174. <tr>
  175. <td class="name">
  176. <strong>path</strong>
  177. </td>
  178. <td class="description last">
  179. <p>The decoder path.</p>
  180. </td>
  181. </tr>
  182. </tbody>
  183. </table>
  184. <dl class="details">
  185. <dt class="tag-returns"><strong>Returns:</strong> A reference to this loader.</dt>
  186. </dl>
  187. </div>
  188. <h3 class="name name-method" id="setWorkerLimit" translate="no">.<a href="#setWorkerLimit">setWorkerLimit</a><span class="signature">( workerLimit : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="DRACOLoader.html">DRACOLoader</a></span> </h3>
  189. <div class="method">
  190. <div class="description">
  191. <p>Sets the maximum number of Web Workers to be used during decoding.
  192. A lower limit may be preferable if workers are also for other tasks in the application.</p>
  193. </div>
  194. <table class="params">
  195. <tbody>
  196. <tr>
  197. <td class="name">
  198. <strong>workerLimit</strong>
  199. </td>
  200. <td class="description last">
  201. <p>The worker limit.</p>
  202. </td>
  203. </tr>
  204. </tbody>
  205. </table>
  206. <dl class="details">
  207. <dt class="tag-returns"><strong>Returns:</strong> A reference to this loader.</dt>
  208. </dl>
  209. </div>
  210. <h2 class="subsection-title">Source</h2>
  211. <p>
  212. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/DRACOLoader.js" translate="no" target="_blank" rel="noopener">examples/jsm/loaders/DRACOLoader.js</a>
  213. </p>
  214. </article>
  215. </section>
  216. <script src="../scripts/linenumber.js"></script>
  217. <script src="../scripts/page.js"></script>
  218. </body>
  219. </html>
粤ICP备19079148号