ImageLoader.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 is used internally by the
  15. [page:CubeTextureLoader], [page:ObjectLoader] and [page:TextureLoader].
  16. </p>
  17. <h2>Example</h2>
  18. <p>
  19. [example:webgl_loader_obj WebGL / loader / obj]<br />
  20. [example:webgl_shaders_ocean WebGL / shaders / ocean]
  21. </p>
  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. <p>
  45. Please note three.js r84 dropped support for ImageLoader progress events. For an ImageLoader
  46. that supports progress events, see [link:https://github.com/mrdoob/three.js/issues/10439#issuecomment-275785639 this thread].
  47. </p>
  48. <h2>Constructor</h2>
  49. <h3>[name]( [param:LoadingManager manager] )</h3>
  50. <p>
  51. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  52. Creates a new [name].
  53. </p>
  54. <h2>Properties</h2>
  55. <h3>[property:String crossOrigin]</h3>
  56. <p>
  57. If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
  58. attribute of the image to the value of *crossOrigin*, prior to starting the load. Default is *"anonymous"*.
  59. </p>
  60. <h3>[property:LoadingManager manager]</h3>
  61. <p>
  62. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  63. </p>
  64. <h3>[property:String path]</h3>
  65. <p>The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.</p>
  66. <h2>Methods</h2>
  67. <h3>[method:HTMLImageElement load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  68. <p>
  69. [page:String url] — the path or URL to the file. This can also be a
  70. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  71. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Image image].<br />
  72. [page:Function onProgress] — This callback function is currently not supported.<br />
  73. [page:Function onError] — Will be called when load errors.<br />
  74. </p>
  75. <p>
  76. Begin loading from url and return the [page:Image image] object that will contain the data.
  77. </p>
  78. <h3>[method:null setCrossOrigin]( [param:String value] )</h3>
  79. <p>Set the [page:.crossOrigin] attribute.</p>
  80. <h3>[method:FileLoader setPath]( [param:String path] )</h3>
  81. <p>
  82. Set the base path or URL from which to load files. This can be useful if
  83. you are loading many images from the same directory.
  84. </p>
  85. <h2>Source</h2>
  86. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  87. </body>
  88. </html>