2
0

TextureLoader.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. Class for loading a [page:Texture texture].
  14. This uses the [page:ImageLoader] internally for loading files.
  15. </p>
  16. <h2>Example</h2>
  17. <code>
  18. var texture = new THREE.TextureLoader().load( 'textures/land_ocean_ice_cloud_2048.jpg' );
  19. // immediately use the texture for material creation
  20. var material = new THREE.MeshBasicMaterial( { map: texture } );
  21. </code>
  22. [example:webgl_geometry_cube geometry / cube]
  23. <h2>Example with Callbacks</h2>
  24. <code>
  25. // instantiate a loader
  26. var loader = new THREE.TextureLoader();
  27. // load a resource
  28. loader.load(
  29. // resource URL
  30. 'textures/land_ocean_ice_cloud_2048.jpg',
  31. // onLoad callback
  32. function ( texture ) {
  33. // in this example we create the material when the texture is loaded
  34. var material = new THREE.MeshBasicMaterial( {
  35. map: texture
  36. } );
  37. },
  38. // onProgress callback currently not supported
  39. undefined,
  40. // onError callback
  41. function ( err ) {
  42. console.error( 'An error happened.' );
  43. }
  44. );
  45. </code>
  46. Please note three.js r84 dropped support for TextureLoader progress events. For a TextureLoader that supports progress events, see [link:https://github.com/mrdoob/three.js/issues/10439#issuecomment-293260145 this thread].
  47. <h2>Constructor</h2>
  48. <h3>[name]( [param:LoadingManager manager] )</h3>
  49. <p>
  50. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  51. Creates a new [name].
  52. </p>
  53. <h2>Properties</h2>
  54. <h3>[property:String crossOrigin]</h3>
  55. <p>
  56. If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
  57. attribute of the image to the value of *crossOrigin*, prior to starting the load. Default is *"anonymous"*.
  58. </p>
  59. <h3>[property:LoadingManager manager]</h3>
  60. <p>
  61. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  62. </p>
  63. <h3>[property:String path]</h3>
  64. <p>The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.</p>
  65. <h2>Methods</h2>
  66. <h3>[method:Texture load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  67. <p>
  68. [page:String url] — the path or URL to the file. This can also be a
  69. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  70. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Texture texture].<br />
  71. [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  72. [page:Function onError] — Will be called when load errors.<br /><br />
  73. Begin loading from the given URL and pass the fully loaded [page:Texture texture] to onLoad. The method also returns a new texture object which can directly be used for material creation.
  74. If you do it this way, the texture may pop up in your scene once the respective loading process is finished.
  75. </p>
  76. <h3>[method:null setCrossOrigin]( [param:String value] )</h3>
  77. <p>Set the [page:.crossOrigin] attribute.</p>
  78. <h3>[method:FileLoader setPath]( [param:String path] )</h3>
  79. <p>
  80. Set the base path or URL from which to load files. This can be useful if
  81. you are loading many models from the same directory.
  82. </p>
  83. <h2>Source</h2>
  84. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  85. </body>
  86. </html>