LoadingManager.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>LoadingManager - 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. <h1 translate="no">LoadingManager</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>Handles and keeps track of loaded and pending data. A default global
  16. instance of this class is created and used by loaders if not supplied
  17. manually.</p>
  18. <p>In general that should be sufficient, however there are times when it can
  19. be useful to have separate loaders - for example if you want to show
  20. separate loading bars for objects and textures.</p></div>
  21. <h2>Code Example</h2>
  22. <div translate="no"><pre><code class="language-js">const manager = new THREE.LoadingManager();
  23. manager.onLoad = () => console.log( 'Loading complete!' );
  24. const loader1 = new OBJLoader( manager );
  25. const loader2 = new ColladaLoader( manager );
  26. </code></pre></div>
  27. </header>
  28. <article>
  29. <div class="container-overview">
  30. <h2>Constructor</h2>
  31. <h3 class="name name-method" id="LoadingManager" translate="no">new <a href="#LoadingManager">LoadingManager</a><span class="signature">( onLoad : <span class="param-type">function</span>, onProgress : <span class="param-type">function</span>, onError : <span class="param-type">function</span> )</span> </h3>
  32. <div class="method">
  33. <div class="description">
  34. <p>Constructs a new loading manager.</p>
  35. </div>
  36. <table class="params">
  37. <tbody>
  38. <tr>
  39. <td class="name">
  40. <strong>onLoad</strong>
  41. </td>
  42. <td class="description last">
  43. <p>Executes when all items have been loaded.</p>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td class="name">
  48. <strong>onProgress</strong>
  49. </td>
  50. <td class="description last">
  51. <p>Executes when single items have been loaded.</p>
  52. </td>
  53. </tr>
  54. <tr>
  55. <td class="name">
  56. <strong>onError</strong>
  57. </td>
  58. <td class="description last">
  59. <p>Executes when an error occurs.</p>
  60. </td>
  61. </tr>
  62. </tbody>
  63. </table>
  64. </div>
  65. </div>
  66. <h2 class="subsection-title">Properties</h2>
  67. <div class="member">
  68. <h3 class="name" id="abortController" translate="no">.<a href="#abortController">abortController</a><span class="type-signature"> : AbortController</span> </h3>
  69. <div class="description">
  70. <p>Used for aborting ongoing requests in loaders using this manager.</p>
  71. </div>
  72. </div>
  73. <div class="member">
  74. <h3 class="name" id="onError" translate="no">.<a href="#onError">onError</a><span class="type-signature"> : function | undefined</span> </h3>
  75. <div class="description">
  76. <p>Executes when an error occurs.</p>
  77. <p>Default is <code>undefined</code>.</p>
  78. </div>
  79. </div>
  80. <div class="member">
  81. <h3 class="name" id="onLoad" translate="no">.<a href="#onLoad">onLoad</a><span class="type-signature"> : function | undefined</span> </h3>
  82. <div class="description">
  83. <p>Executes when all items have been loaded.</p>
  84. <p>Default is <code>undefined</code>.</p>
  85. </div>
  86. </div>
  87. <div class="member">
  88. <h3 class="name" id="onProgress" translate="no">.<a href="#onProgress">onProgress</a><span class="type-signature"> : function | undefined</span> </h3>
  89. <div class="description">
  90. <p>Executes when single items have been loaded.</p>
  91. <p>Default is <code>undefined</code>.</p>
  92. </div>
  93. </div>
  94. <div class="member">
  95. <h3 class="name" id="onStart" translate="no">.<a href="#onStart">onStart</a><span class="type-signature"> : function | undefined</span> </h3>
  96. <div class="description">
  97. <p>Executes when an item starts loading.</p>
  98. <p>Default is <code>undefined</code>.</p>
  99. </div>
  100. </div>
  101. <h2 class="subsection-title">Methods</h2>
  102. <h3 class="name name-method" id="abort" translate="no">.<a href="#abort">abort</a><span class="signature">()</span><span class="type-signature"> : <a href="LoadingManager.html">LoadingManager</a></span> </h3>
  103. <div class="method">
  104. <div class="description">
  105. <p>Can be used to abort ongoing loading requests in loaders using this manager.
  106. The abort only works if the loaders implement <a href="Loader.html#abort">Loader#abort</a> and <code>AbortSignal.any()</code>
  107. is supported in the browser.</p>
  108. </div>
  109. <dl class="details">
  110. <dt class="tag-returns"><strong>Returns:</strong> A reference to this loading manager.</dt>
  111. </dl>
  112. </div>
  113. <h3 class="name name-method" id="addHandler" translate="no">.<a href="#addHandler">addHandler</a><span class="signature">( regex : <span class="param-type">string</span>, loader : <span class="param-type"><a href="Loader.html">Loader</a></span> )</span><span class="type-signature"> : <a href="LoadingManager.html">LoadingManager</a></span> </h3>
  114. <div class="method">
  115. <div class="description">
  116. <p>Registers a loader with the given regular expression. Can be used to
  117. define what loader should be used in order to load specific files. A
  118. typical use case is to overwrite the default loader for textures.</p>
  119. <pre><code class="language-js">// add handler for TGA textures
  120. manager.addHandler( /\.tga$/i, new TGALoader() );
  121. </code></pre>
  122. </div>
  123. <table class="params">
  124. <tbody>
  125. <tr>
  126. <td class="name">
  127. <strong>regex</strong>
  128. </td>
  129. <td class="description last">
  130. <p>A regular expression.</p>
  131. </td>
  132. </tr>
  133. <tr>
  134. <td class="name">
  135. <strong>loader</strong>
  136. </td>
  137. <td class="description last">
  138. <p>A loader that should handle matched cases.</p>
  139. </td>
  140. </tr>
  141. </tbody>
  142. </table>
  143. <dl class="details">
  144. <dt class="tag-returns"><strong>Returns:</strong> A reference to this loading manager.</dt>
  145. </dl>
  146. </div>
  147. <h3 class="name name-method" id="getHandler" translate="no">.<a href="#getHandler">getHandler</a><span class="signature">( file : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Loader.html">Loader</a></span> </h3>
  148. <div class="method">
  149. <div class="description">
  150. <p>Can be used to retrieve the registered loader for the given file path.</p>
  151. </div>
  152. <table class="params">
  153. <tbody>
  154. <tr>
  155. <td class="name">
  156. <strong>file</strong>
  157. </td>
  158. <td class="description last">
  159. <p>The file path.</p>
  160. </td>
  161. </tr>
  162. </tbody>
  163. </table>
  164. <dl class="details">
  165. <dt class="tag-returns"><strong>Returns:</strong> The registered loader. Returns <code>null</code> if no loader was found.</dt>
  166. </dl>
  167. </div>
  168. <h3 class="name name-method" id="itemEnd" translate="no">.<a href="#itemEnd">itemEnd</a><span class="signature">( url : <span class="param-type">string</span> )</span> </h3>
  169. <div class="method">
  170. <div class="description">
  171. <p>This should be called by any loader using the manager when the loader
  172. ended loading an item.</p>
  173. </div>
  174. <table class="params">
  175. <tbody>
  176. <tr>
  177. <td class="name">
  178. <strong>url</strong>
  179. </td>
  180. <td class="description last">
  181. <p>The URL of the loaded item.</p>
  182. </td>
  183. </tr>
  184. </tbody>
  185. </table>
  186. </div>
  187. <h3 class="name name-method" id="itemError" translate="no">.<a href="#itemError">itemError</a><span class="signature">( url : <span class="param-type">string</span> )</span> </h3>
  188. <div class="method">
  189. <div class="description">
  190. <p>This should be called by any loader using the manager when the loader
  191. encounters an error when loading an item.</p>
  192. </div>
  193. <table class="params">
  194. <tbody>
  195. <tr>
  196. <td class="name">
  197. <strong>url</strong>
  198. </td>
  199. <td class="description last">
  200. <p>The URL of the item that produces an error.</p>
  201. </td>
  202. </tr>
  203. </tbody>
  204. </table>
  205. </div>
  206. <h3 class="name name-method" id="itemStart" translate="no">.<a href="#itemStart">itemStart</a><span class="signature">( url : <span class="param-type">string</span> )</span> </h3>
  207. <div class="method">
  208. <div class="description">
  209. <p>This should be called by any loader using the manager when the loader
  210. starts loading an item.</p>
  211. </div>
  212. <table class="params">
  213. <tbody>
  214. <tr>
  215. <td class="name">
  216. <strong>url</strong>
  217. </td>
  218. <td class="description last">
  219. <p>The URL to load.</p>
  220. </td>
  221. </tr>
  222. </tbody>
  223. </table>
  224. </div>
  225. <h3 class="name name-method" id="removeHandler" translate="no">.<a href="#removeHandler">removeHandler</a><span class="signature">( regex : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="LoadingManager.html">LoadingManager</a></span> </h3>
  226. <div class="method">
  227. <div class="description">
  228. <p>Removes the loader for the given regular expression.</p>
  229. </div>
  230. <table class="params">
  231. <tbody>
  232. <tr>
  233. <td class="name">
  234. <strong>regex</strong>
  235. </td>
  236. <td class="description last">
  237. <p>A regular expression.</p>
  238. </td>
  239. </tr>
  240. </tbody>
  241. </table>
  242. <dl class="details">
  243. <dt class="tag-returns"><strong>Returns:</strong> A reference to this loading manager.</dt>
  244. </dl>
  245. </div>
  246. <h3 class="name name-method" id="resolveURL" translate="no">.<a href="#resolveURL">resolveURL</a><span class="signature">( url : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
  247. <div class="method">
  248. <div class="description">
  249. <p>Given a URL, uses the URL modifier callback (if any) and returns a
  250. resolved URL. If no URL modifier is set, returns the original URL.</p>
  251. </div>
  252. <table class="params">
  253. <tbody>
  254. <tr>
  255. <td class="name">
  256. <strong>url</strong>
  257. </td>
  258. <td class="description last">
  259. <p>The URL to load.</p>
  260. </td>
  261. </tr>
  262. </tbody>
  263. </table>
  264. <dl class="details">
  265. <dt class="tag-returns"><strong>Returns:</strong> The resolved URL.</dt>
  266. </dl>
  267. </div>
  268. <h3 class="name name-method" id="setURLModifier" translate="no">.<a href="#setURLModifier">setURLModifier</a><span class="signature">( transform : <span class="param-type">function</span> )</span><span class="type-signature"> : <a href="LoadingManager.html">LoadingManager</a></span> </h3>
  269. <div class="method">
  270. <div class="description">
  271. <p>If provided, the callback will be passed each resource URL before a
  272. request is sent. The callback may return the original URL, or a new URL to
  273. override loading behavior. This behavior can be used to load assets from
  274. .ZIP files, drag-and-drop APIs, and Data URIs.</p>
  275. <pre><code class="language-js">const blobs = {'fish.gltf': blob1, 'diffuse.png': blob2, 'normal.png': blob3};
  276. const manager = new THREE.LoadingManager();
  277. // Initialize loading manager with URL callback.
  278. const objectURLs = [];
  279. manager.setURLModifier( ( url ) => {
  280. url = URL.createObjectURL( blobs[ url ] );
  281. objectURLs.push( url );
  282. return url;
  283. } );
  284. // Load as usual, then revoke the blob URLs.
  285. const loader = new GLTFLoader( manager );
  286. loader.load( 'fish.gltf', (gltf) => {
  287. scene.add( gltf.scene );
  288. objectURLs.forEach( ( url ) => URL.revokeObjectURL( url ) );
  289. } );
  290. </code></pre>
  291. </div>
  292. <table class="params">
  293. <tbody>
  294. <tr>
  295. <td class="name">
  296. <strong>transform</strong>
  297. </td>
  298. <td class="description last">
  299. <p>URL modifier callback. Called with an URL and must return a resolved URL.</p>
  300. </td>
  301. </tr>
  302. </tbody>
  303. </table>
  304. <dl class="details">
  305. <dt class="tag-returns"><strong>Returns:</strong> A reference to this loading manager.</dt>
  306. </dl>
  307. </div>
  308. <h2 class="subsection-title">Source</h2>
  309. <p>
  310. <a href="https://github.com/mrdoob/three.js/blob/master/src/loaders/LoadingManager.js" translate="no" target="_blank" rel="noopener">src/loaders/LoadingManager.js</a>
  311. </p>
  312. </article>
  313. </section>
  314. <script src="../scripts/linenumber.js"></script>
  315. <script src="../scripts/page.js"></script>
  316. </body>
  317. </html>
粤ICP备19079148号