ImageBitmapLoader.html 3.9 KB

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