KTX2Loader.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. Loader for KTX 2.0 GPU Texture containers.<br><br>
  14. [link:http://github.khronos.org/KTX-Specification/ KTX 2.0] is a container format for various GPU texture formats. The loader
  15. supports Basis Universal GPU textures, which can be quickly transcoded to
  16. a wide variety of GPU texture compression formats. While KTX 2.0 also allows
  17. other hardware-specific formats, this loader does not yet parse them.
  18. </p>
  19. <p>
  20. This loader parses the KTX 2.0 container and transcodes to a supported GPU compressed
  21. texture format. The required WASM transcoder and JS wrapper are available from the
  22. [link:https://github.com/mrdoob/three.js/tree/dev/examples/jsm/libs/basis examples/jsm/libs/basis]
  23. directory.
  24. </p>
  25. <h2>Import</h2>
  26. <p>
  27. [name] is an add-on, and must be imported explicitly.
  28. See [link:#manual/introduction/Installation Installation / Addons].
  29. </p>
  30. <code>
  31. import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
  32. </code>
  33. <h2>Code Example</h2>
  34. <code>
  35. var ktx2Loader = new KTX2Loader();
  36. ktx2Loader.setTranscoderPath( 'examples/jsm/libs/basis/' );
  37. ktx2Loader.detectSupport( renderer );
  38. ktx2Loader.load( 'diffuse.ktx2', function ( texture ) {
  39. var material = new THREE.MeshStandardMaterial( { map: texture } );
  40. }, function () {
  41. console.log( 'onProgress' );
  42. }, function ( e ) {
  43. console.error( e );
  44. } );
  45. </code>
  46. <h2>Examples</h2>
  47. <p>
  48. [example:webgl_loader_texture_ktx2]
  49. </p>
  50. <h2>Browser compatibility</h2>
  51. <p>
  52. This loader relies on Web Assembly which is not supported in older browsers.
  53. </p>
  54. <br>
  55. <hr>
  56. <h2>Constructor</h2>
  57. <h3>[name]( [param:LoadingManager manager] )</h3>
  58. <p>
  59. [page:LoadingManager manager] — The [page:LoadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  60. </p>
  61. <p>
  62. Creates a new [name].
  63. </p>
  64. <h2>Properties</h2>
  65. <p>See the base [page:Loader] class for common properties.</p>
  66. <h2>Methods</h2>
  67. <p>See the base [page:Loader] class for common methods.</p>
  68. <h3>[method:CompressedTexture load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  69. <p>
  70. [page:String url] — A string containing the path/URL of the `.ktx2` file.<br />
  71. [page:Function onLoad] — A function to be called after the loading is successfully completed.<br />
  72. [page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, that contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.<br />
  73. [page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.<br />
  74. </p>
  75. <p>
  76. Load from url and call the `onLoad` function with the transcoded [page:CompressedTexture].
  77. </p>
  78. <h3>[method:this detectSupport]( [param:WebGLRenderer renderer] )</h3>
  79. <p>
  80. [page:WebGLRenderer renderer] — A renderer instance.
  81. </p>
  82. <p>
  83. Detects hardware support for available compressed texture formats, to determine
  84. the output format for the transcoder. Must be called before loading a texture.
  85. </p>
  86. <h3>[method:this setTranscoderPath]( [param:String path] )</h3>
  87. <p>
  88. [page:String path] — Path to folder containing the WASM transcoder and JS wrapper.
  89. </p>
  90. <p>
  91. The WASM transcoder and JS wrapper are available from the
  92. [link:https://github.com/mrdoob/three.js/tree/dev/examples/jsm/libs/basis examples/jsm/libs/basis]
  93. directory.
  94. </p>
  95. <h3>[method:this setWorkerLimit]( [param:Number limit] )</h3>
  96. <p>
  97. [page:Number limit] — Maximum number of workers. Default is '4'.
  98. </p>
  99. <p>
  100. Sets the maximum number of web workers to be allocated by this instance.
  101. </p>
  102. <h3>[method:this dispose]()</h3>
  103. <p>
  104. Disposes the loader object, de-allocating any Web Workers created.
  105. </p>
  106. <h2>Source</h2>
  107. <p>
  108. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/KTX2Loader.js examples/jsm/loaders/KTX2Loader.js]
  109. </p>
  110. </body>
  111. </html>