ImageLoader.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. <p 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].<br/>
  16. Unlike [page:FileLoader], [name] does not avoid multiple concurrent requests to the same URL.
  17. </p>
  18. <h2>Example</h2>
  19. <p>
  20. [example:webgl_loader_obj WebGL / loader / obj]<br />
  21. [example:webgl_shaders_ocean WebGL / shaders / ocean]
  22. </p>
  23. <code>
  24. // instantiate a loader
  25. var loader = new THREE.ImageLoader();
  26. // load a image resource
  27. loader.load(
  28. // resource URL
  29. 'textures/skyboxsun25degtest.png',
  30. // onLoad callback
  31. function ( image ) {
  32. // use the image, e.g. draw part of it on a canvas
  33. var canvas = document.createElement( 'canvas' );
  34. var context = canvas.getContext( '2d' );
  35. context.drawImage( image, 100, 100 );
  36. },
  37. // onProgress callback currently not supported
  38. undefined,
  39. // onError callback
  40. function () {
  41. console.error( 'An error happened.' );
  42. }
  43. );
  44. </code>
  45. <p>
  46. Please note three.js r84 dropped support for ImageLoader progress events. For an ImageLoader
  47. that supports progress events, see [link:https://github.com/mrdoob/three.js/issues/10439#issuecomment-275785639 this thread].
  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. <h3>[property:String crossOrigin]</h3>
  57. <p>
  58. If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
  59. attribute of the image to the value of *crossOrigin*, prior to starting the load. Default is *undefined*.
  60. </p>
  61. <h3>[property:LoadingManager manager]</h3>
  62. <p>
  63. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  64. </p>
  65. <h3>[property:String path]</h3>
  66. <p>The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.</p>
  67. <h2>Methods</h2>
  68. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  69. <p>
  70. [page:String url] — the path or URL to the file. This can also be a
  71. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  72. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Image image].<br />
  73. [page:Function onProgress] — This callback function is currently not supported.<br />
  74. [page:Function onError] — Will be called when load errors.<br />
  75. </p>
  76. <p>
  77. Begin loading from url and return the [page:Image image] object that will contain the data.
  78. </p>
  79. <h3>[method:null setCrossOrigin]( [param:String value] )</h3>
  80. <p>Set the [page:.crossOrigin] attribute.</p>
  81. <h3>[method:FileLoader setPath]( [param:String path] )</h3>
  82. <p>
  83. Set the base path or URL from which to load files. This can be useful if
  84. you are loading many images from the same directory.
  85. </p>
  86. <h2>Source</h2>
  87. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  88. </body>
  89. </html>