TextureLoader.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <!DOCTYPE html>
  2. <html lang="zh">
  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. 加载[page:Texture texture]的一个类。
  14. 内部使用[page:ImageLoader]来加载文件。
  15. </p>
  16. <h2>代码示例</h2>
  17. <code>
  18. const texture = new THREE.TextureLoader().load( 'textures/land_ocean_ice_cloud_2048.jpg' );
  19. // 立即使用纹理进行材质创建
  20. const material = new THREE.MeshBasicMaterial( { map: texture } );
  21. </code>
  22. <h2>Code Example with Callbacks</h2>
  23. <code>
  24. // 初始化一个加载器
  25. const loader = new THREE.TextureLoader();
  26. // 加载一个资源
  27. loader.load(
  28. // 资源URL
  29. 'textures/land_ocean_ice_cloud_2048.jpg',
  30. // onLoad回调
  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的回调
  38. undefined,
  39. // onError回调
  40. function ( err ) {
  41. console.error( 'An error happened.' );
  42. }
  43. );
  44. </code>
  45. <p>
  46. 请注意three.js r84遗弃了TextureLoader进度事件。对于支持进度事件的TextureLoader ,
  47. 请参考[link:https://github.com/mrdoob/three.js/issues/10439#issuecomment-293260145 this thread]。
  48. </p>
  49. <h2>例子</h2>
  50. <p>
  51. [example:webgl_geometry_cube geometry / cube]
  52. </p>
  53. <h2>构造函数</h2>
  54. <h3>[name]( [param:LoadingManager manager] )</h3>
  55. <p>
  56. [page:LoadingManager manager] — 加载器使用的[page:LoadingManager loadingManager],默认值为[page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  57. 创建一个新的[name].
  58. </p>
  59. <h2>属性</h2>
  60. <p>共有属性请参见其基类[page:Loader]。</p>
  61. <h2>方法</h2>
  62. <p>共有方法请参见其基类[page:Loader]。</p>
  63. <h3>[method:Texture load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  64. <p>
  65. [page:String url] — 文件的URL或者路径,也可以为
  66. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  67. [page:Function onLoad] — 加载完成时将调用。回调参数为将要加载的[page:Texture texture].<br />
  68. [page:Function onProgress] — 将在加载过程中进行调用。参数为XMLHttpRequest实例,实例包含[page:Integer total]和[page:Integer loaded]字节。<br />
  69. [page:Function onError] — 在加载错误时被调用。<br /><br />
  70. 从给定的URL开始加载并将完全加载的[page:Texture texture]传递给onLoad。该方法还返回一个新的纹理对象,该纹理对象可以直接用于材质创建。
  71. 如果采用此方法,一旦相应的加载过程完成,纹理可能会在场景中出现。
  72. </p>
  73. <h2>源</h2>
  74. <p>
  75. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  76. </p>
  77. </body>
  78. </html>