ImageLoader.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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]. This is used internally by the
  14. [page:CubeTextureLoader], [page:ObjectLoader] and [page:TextureLoader].
  15. </p>
  16. <h2>Code Example</h2>
  17. <code>
  18. // instantiate a loader
  19. const loader = new THREE.ImageLoader();
  20. // load a image resource
  21. loader.load(
  22. // resource URL
  23. 'textures/skyboxsun25degtest.png',
  24. // onLoad callback
  25. function ( image ) {
  26. // use the image, e.g. draw part of it on a canvas
  27. const canvas = document.createElement( 'canvas' );
  28. const context = canvas.getContext( '2d' );
  29. context.drawImage( image, 100, 100 );
  30. },
  31. // onProgress callback currently not supported
  32. undefined,
  33. // onError callback
  34. function () {
  35. console.error( 'An error happened.' );
  36. }
  37. );
  38. </code>
  39. <p>
  40. Please note three.js r84 dropped support for ImageLoader progress events.
  41. For an ImageLoader that supports progress events, see
  42. [link:https://github.com/mrdoob/three.js/issues/10439#issuecomment-275785639 this thread].
  43. </p>
  44. <h2>Examples</h2>
  45. <p>
  46. [example:webgl_loader_obj WebGL / loader / obj]<br />
  47. [example:webgl_shaders_ocean WebGL / shaders / ocean]
  48. </p>
  49. <h2>Constructor</h2>
  50. <h3>[name]( [param:LoadingManager manager] )</h3>
  51. <p>
  52. [page:LoadingManager manager] — The [page:LoadingManager loadingManager]
  53. 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. <h2>Methods</h2>
  59. <p>See the base [page:Loader] class for common methods.</p>
  60. <h3>
  61. [method:HTMLImageElement load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )
  62. </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
  67. will be the loaded [page:Image image].<br />
  68. [page:Function onProgress] (optional) — This callback function is
  69. currently not supported.<br />
  70. [page:Function onError] (optional) — Will be called when load errors.<br />
  71. </p>
  72. <p>
  73. Begin loading from url and return the [page:Image image] object that will
  74. contain the data.
  75. </p>
  76. <h2>Source</h2>
  77. <p>
  78. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  79. </p>
  80. </body>
  81. </html>