ImageLoader.html 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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].
  14. This is used internally by the
  15. [page:CubeTextureLoader], [page:ObjectLoader] and [page:TextureLoader].
  16. </p>
  17. <h2>Code Example</h2>
  18. <code>
  19. // instantiate a loader
  20. const loader = new THREE.ImageLoader();
  21. // load a image resource
  22. loader.load(
  23. // resource URL
  24. 'textures/skyboxsun25degtest.png',
  25. // onLoad callback
  26. function ( image ) {
  27. // use the image, e.g. draw part of it on a canvas
  28. const canvas = document.createElement( 'canvas' );
  29. const context = canvas.getContext( '2d' );
  30. context.drawImage( image, 100, 100 );
  31. },
  32. // onProgress callback currently not supported
  33. undefined,
  34. // onError callback
  35. function () {
  36. console.error( 'An error happened.' );
  37. }
  38. );
  39. </code>
  40. <p>
  41. Please note three.js r84 dropped support for ImageLoader progress events. For an ImageLoader
  42. that supports progress events, see [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] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  53. Creates a new [name].
  54. </p>
  55. <h2>Properties</h2>
  56. <p>See the base [page:Loader] class for common properties.</p>
  57. <h2>Methods</h2>
  58. <p>See the base [page:Loader] class for common methods.</p>
  59. <h3>[method:HTMLImageElement load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  60. <p>
  61. [page:String url] — the path or URL to the file. This can also be a
  62. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  63. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Image image].<br />
  64. [page:Function onProgress] — This callback function is currently not supported.<br />
  65. [page:Function onError] — Will be called when load errors.<br />
  66. </p>
  67. <p>
  68. Begin loading from url and return the [page:Image image] object that will contain the data.
  69. </p>
  70. <h2>Source</h2>
  71. <p>
  72. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  73. </p>
  74. </body>
  75. </html>