ImageBitmapLoader.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ImageBitmapLoader - 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">ImageBitmapLoader</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>A loader for loading images as an <a href="https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap" target="_blank" rel="noopener">ImageBitmap</a>.
  17. An <code>ImageBitmap</code> provides an asynchronous and resource efficient pathway to prepare
  18. textures for rendering.</p>
  19. <p>Note that <a href="Texture.html#flipY">Texture#flipY</a> and <a href="Texture.html#premultiplyAlpha">Texture#premultiplyAlpha</a> are ignored with image bitmaps.
  20. These options need to be configured via <a href="ImageBitmapLoader.html#setOptions">ImageBitmapLoader#setOptions</a> prior to loading,
  21. unlike regular images which can be configured on the Texture to set these options on GPU upload instead.</p>
  22. <p>To match the default behaviour of <a href="Texture.html">Texture</a>, the following options are needed:</p>
  23. <p>Also note that unlike <a href="FileLoader.html">FileLoader</a>, this loader will only avoid multiple concurrent requests to the same URL if <a href="Cache.html">Cache</a> is enabled.</p>
  24. <pre><code class="language-js">const loader = new THREE.ImageBitmapLoader();
  25. loader.setOptions( { imageOrientation: 'flipY' } ); // set options if needed
  26. const imageBitmap = await loader.loadAsync( 'image.png' );
  27. const texture = new THREE.Texture( imageBitmap );
  28. texture.needsUpdate = true;
  29. </code></pre></div>
  30. <h2>Code Example</h2>
  31. <div translate="no"><pre><code class="language-js">{ imageOrientation: 'flipY', premultiplyAlpha: 'none' }
  32. </code></pre></div>
  33. </header>
  34. <article>
  35. <div class="container-overview">
  36. <h2>Constructor</h2>
  37. <h3 class="name name-method" id="ImageBitmapLoader" translate="no">new <a href="#ImageBitmapLoader">ImageBitmapLoader</a><span class="signature">( manager : <span class="param-type"><a href="LoadingManager.html">LoadingManager</a></span> )</span> </h3>
  38. <div class="method">
  39. <div class="description">
  40. <p>Constructs a new image bitmap loader.</p>
  41. </div>
  42. <table class="params">
  43. <tbody>
  44. <tr>
  45. <td class="name">
  46. <strong>manager</strong>
  47. </td>
  48. <td class="description last">
  49. <p>The loading manager.</p>
  50. </td>
  51. </tr>
  52. </tbody>
  53. </table>
  54. </div>
  55. </div>
  56. <h2 class="subsection-title">Properties</h2>
  57. <div class="member">
  58. <h3 class="name" id="isImageBitmapLoader" translate="no">.<a href="#isImageBitmapLoader">isImageBitmapLoader</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  59. <div class="description">
  60. <p>This flag can be used for type testing.</p>
  61. <p>Default is <code>true</code>.</p>
  62. </div>
  63. </div>
  64. <div class="member">
  65. <h3 class="name" id="options" translate="no">.<a href="#options">options</a><span class="type-signature"> : Object</span> </h3>
  66. <div class="description">
  67. <p>Represents the loader options.</p>
  68. <p>Default is <code>{premultiplyAlpha:'none'}</code>.</p>
  69. </div>
  70. </div>
  71. <h2 class="subsection-title">Methods</h2>
  72. <h3 class="name name-method" id="abort" translate="no">.<a href="#abort">abort</a><span class="signature">()</span><span class="type-signature"> : <a href="ImageBitmapLoader.html">ImageBitmapLoader</a></span> </h3>
  73. <div class="method">
  74. <div class="description">
  75. <p>Aborts ongoing fetch requests.</p>
  76. </div>
  77. <dl class="details">
  78. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Loader.html#abort">Loader#abort</a></dt>
  79. </dl>
  80. <dl class="details">
  81. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  82. </dl>
  83. </div>
  84. <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><span class="type-signature"> : ImageBitmap | undefined</span> </h3>
  85. <div class="method">
  86. <div class="description">
  87. <p>Starts loading from the given URL and pass the loaded image bitmap to the <code>onLoad()</code> callback.</p>
  88. </div>
  89. <table class="params">
  90. <tbody>
  91. <tr>
  92. <td class="name">
  93. <strong>url</strong>
  94. </td>
  95. <td class="description last">
  96. <p>The path/URL of the file to be loaded. This can also be a data URI.</p>
  97. </td>
  98. </tr>
  99. <tr>
  100. <td class="name">
  101. <strong>onLoad</strong>
  102. </td>
  103. <td class="description last">
  104. <p>Executed when the loading process has been finished.</p>
  105. </td>
  106. </tr>
  107. <tr>
  108. <td class="name">
  109. <strong>onProgress</strong>
  110. </td>
  111. <td class="description last">
  112. <p>Unsupported in this loader.</p>
  113. </td>
  114. </tr>
  115. <tr>
  116. <td class="name">
  117. <strong>onError</strong>
  118. </td>
  119. <td class="description last">
  120. <p>Executed when errors occur.</p>
  121. </td>
  122. </tr>
  123. </tbody>
  124. </table>
  125. <dl class="details">
  126. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Loader.html#load">Loader#load</a></dt>
  127. </dl>
  128. <dl class="details">
  129. <dt class="tag-returns"><strong>Returns:</strong> The image bitmap.</dt>
  130. </dl>
  131. </div>
  132. <h3 class="name name-method" id="setOptions" translate="no">.<a href="#setOptions">setOptions</a><span class="signature">( options : <span class="param-type">Object</span> )</span><span class="type-signature"> : <a href="ImageBitmapLoader.html">ImageBitmapLoader</a></span> </h3>
  133. <div class="method">
  134. <div class="description">
  135. <p>Sets the given loader options. The structure of the object must match the <code>options</code> parameter of
  136. <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/createImageBitmap" target="_blank" rel="noopener">createImageBitmap</a>.</p>
  137. </div>
  138. <table class="params">
  139. <tbody>
  140. <tr>
  141. <td class="name">
  142. <strong>options</strong>
  143. </td>
  144. <td class="description last">
  145. <p>The loader options to set.</p>
  146. </td>
  147. </tr>
  148. </tbody>
  149. </table>
  150. <dl class="details">
  151. <dt class="tag-returns"><strong>Returns:</strong> A reference to this image bitmap loader.</dt>
  152. </dl>
  153. </div>
  154. <h2 class="subsection-title">Source</h2>
  155. <p>
  156. <a href="https://github.com/mrdoob/three.js/blob/master/src/loaders/ImageBitmapLoader.js" translate="no" target="_blank" rel="noopener">src/loaders/ImageBitmapLoader.js</a>
  157. </p>
  158. </article>
  159. </section>
  160. <script src="../scripts/linenumber.js"></script>
  161. <script src="../scripts/page.js"></script>
  162. </body>
  163. </html>
粤ICP备19079148号