ImageLoader.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <div class="desc">
  13. A loader for loading an [page:Image].
  14. This uses the [page:FileLoader] internally for loading files, and is used internally by the
  15. [page:CubeTextureLoader], [page:ObjectLoader] and [page:TextureLoader].
  16. </div>
  17. <h2>Example</h2>
  18. <div>
  19. [example:webgl_loader_obj WebGL / loader / obj]<br />
  20. [example:webgl_shaders_ocean WebGL / shaders / ocean]
  21. </div>
  22. <code>
  23. // instantiate a loader
  24. var loader = new THREE.ImageLoader();
  25. // load a image resource
  26. loader.load(
  27. // resource URL
  28. 'textures/skyboxsun25degtest.png',
  29. // onLoad callback
  30. function ( image ) {
  31. // use the image, e.g. draw part of it on a canvas
  32. var canvas = document.createElement( 'canvas' );
  33. var context = canvas.getContext( '2d' );
  34. context.drawImage( image, 100, 100 );
  35. },
  36. // onProgress callback currently not supported
  37. undefined,
  38. // onError callback
  39. function () {
  40. console.error( 'An error happened.' );
  41. }
  42. );
  43. </code>
  44. Please note three.js r84 dropped support for ImageLoader progress events. For an ImageLoader that supports progress events, see [link:https://github.com/mrdoob/three.js/issues/10439#issuecomment-275785639 this thread].
  45. <h2>Constructor</h2>
  46. <h3>[name]( [page:LoadingManager manager] )</h3>
  47. <div>
  48. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  49. Creates a new [name].
  50. </div>
  51. <h2>Properties</h2>
  52. <h3>[property:String crossOrigin]</h3>
  53. <div>
  54. If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
  55. attribute of the image to the value of *crossOrigin*, prior to starting the load. Default is *undefined*.
  56. </div>
  57. <h3>[property:LoadingManager manager]</h3>
  58. <div>
  59. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  60. </div>
  61. <h3>[property:String path]</h3>
  62. <div>The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.</div>
  63. <h2>Methods</h2>
  64. <h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
  65. <div>
  66. [page:String url] — the path or URL to the file. This can also be a
  67. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  68. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Image image].<br />
  69. [page:Function onProgress] — Will be called while load progresses. The argument will be the progress event.<br />
  70. [page:Function onError] — Will be called when load errors.<br />
  71. </div>
  72. <div>
  73. Begin loading from url and return the [page:Image image] object that will contain the data.
  74. </div>
  75. <h3>[method:null setCrossOrigin]( [page:String value] )</h3>
  76. <div>Set the [page:.crossOrigin] attribute.</div>
  77. <h3>[method:FileLoader setPath]( [page:String path] )</h3>
  78. <div>
  79. Set the base path or URL from which to load files. This can be useful if
  80. you are loading many images from the same directory.
  81. </div>
  82. <h2>Source</h2>
  83. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  84. </body>
  85. </html>