TextureLoader.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. Class for loading a [page:Texture texture].
  14. This uses the [page:ImageLoader] internally for loading files.
  15. </p>
  16. <h2>Code Example</h2>
  17. <code>
  18. const texture = new THREE.TextureLoader().load( 'textures/land_ocean_ice_cloud_2048.jpg' );
  19. // immediately use the texture for material creation
  20. const material = new THREE.MeshBasicMaterial( { map: texture } );
  21. </code>
  22. <h2>Code Example with Callbacks</h2>
  23. <code>
  24. // instantiate a loader
  25. const loader = new THREE.TextureLoader();
  26. // load a resource
  27. loader.load(
  28. // resource URL
  29. 'textures/land_ocean_ice_cloud_2048.jpg',
  30. // onLoad callback
  31. function ( texture ) {
  32. // in this example we create the material when the texture is loaded
  33. const material = new THREE.MeshBasicMaterial( {
  34. map: texture
  35. } );
  36. },
  37. // onProgress callback currently not supported
  38. undefined,
  39. // onError callback
  40. function ( err ) {
  41. console.error( 'An error happened.' );
  42. }
  43. );
  44. </code>
  45. <p>
  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. </p>
  48. <h2>Examples</h2>
  49. <p>
  50. [example:webgl_geometry_cube geometry / cube]
  51. </p>
  52. <h2>Constructor</h2>
  53. <h3>[name]( [param:LoadingManager manager] )</h3>
  54. <p>
  55. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  56. Creates a new [name].
  57. </p>
  58. <h2>Properties</h2>
  59. <p>See the base [page:Loader] class for common properties.</p>
  60. <h2>Methods</h2>
  61. <p>See the base [page:Loader] class for common methods.</p>
  62. <h3>[method:Texture load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  63. <p>
  64. [page:String url] — the path or URL to the file. This can also be a
  65. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  66. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Texture texture].<br />
  67. [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 />
  68. [page:Function onError] — Will be called when load errors.<br /><br />
  69. 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.
  70. If you do it this way, the texture may pop up in your scene once the respective loading process is finished.
  71. </p>
  72. <h2>Source</h2>
  73. <p>
  74. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  75. </p>
  76. </body>
  77. </html>