ImageBitmapLoader.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Loader] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. A loader for loading an [page:Image] as an [link:https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap ImageBitmap].
  14. An ImageBitmap provides an asynchronous and resource efficient pathway to prepare textures for rendering in WebGL.<br/>
  15. Unlike [page:FileLoader], [name] does not avoid multiple concurrent requests to the same URL.
  16. </p>
  17. <p>
  18. Note that [page:Texture.flipY] and [page:Texture.premultiplyAlpha] with [link:https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap ImageBitmap] are ignored.
  19. [link:https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap ImageBitmap] needs these configuration on bitmap creation
  20. unlike regular images need them on uploading to GPU. You need to set the equivalent options via [page:ImageBitmapLoader.setOptions]
  21. instead. Refer to [link:https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.10 WebGL specification] for the detail.
  22. </p>
  23. <h2>Code Example</h2>
  24. <code>
  25. // instantiate a loader
  26. const loader = new THREE.ImageBitmapLoader();
  27. // set options if needed
  28. loader.setOptions( { imageOrientation: 'flipY' } );
  29. // load a image resource
  30. loader.load(
  31. // resource URL
  32. 'textures/skyboxsun25degtest.png',
  33. // onLoad callback
  34. function ( imageBitmap ) {
  35. const texture = new THREE.CanvasTexture( imageBitmap );
  36. const material = new THREE.MeshBasicMaterial( { map: texture } );
  37. },
  38. // onProgress callback currently not supported
  39. undefined,
  40. // onError callback
  41. function ( err ) {
  42. console.log( 'An error happened' );
  43. }
  44. );
  45. </code>
  46. <h2>Examples</h2>
  47. <p>
  48. [example:webgl_loader_imagebitmap WebGL / loader / ImageBitmap]
  49. </p>
  50. <h2>Constructor</h2>
  51. <h3>[name]( [param:LoadingManager manager] )</h3>
  52. <p>
  53. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  54. Creates a new [name].
  55. </p>
  56. <h2>Properties</h2>
  57. <p>See the base [page:Loader] class for common properties.</p>
  58. <h3>[property:String options]</h3>
  59. <p>An optional object that sets options for the internally used [link:https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap createImageBitmap] factory method. Default is *undefined*.</p>
  60. <h2>Methods</h2>
  61. <p>See the base [page:Loader] class for common methods.</p>
  62. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  63. <p>
  64. [page:String url] — the path or URL to the file. This can also be a
  65. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  66. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Image image].<br />
  67. [page:Function onProgress] — This callback function is currently not supported.<br />
  68. [page:Function onError] — Will be called when load errors.<br />
  69. </p>
  70. <p>
  71. Begin loading from url and return the [page:ImageBitmap image] object that will contain the data.
  72. </p>
  73. <h3>[method:ImageBitmapLoader setOptions]( [param:Object options] )</h3>
  74. <p>
  75. Sets the options object for [link:https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap createImageBitmap].
  76. </p>
  77. <h2>Source</h2>
  78. <p>
  79. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  80. </p>
  81. </body>
  82. </html>