diff --git a/docs/examples/en/loaders/GLTFLoader.html b/docs/examples/en/loaders/GLTFLoader.html index caa562674d7531..2d659546417230 100644 --- a/docs/examples/en/loaders/GLTFLoader.html +++ b/docs/examples/en/loaders/GLTFLoader.html @@ -199,6 +199,11 @@
+ [page:KTX2Loader ktx2Loader] — Instance of THREE.KTX2Loader, to be used for loading KTX2 compressed textures. +
+
[page:ArrayBuffer data] — glTF asset to parse, as an ArrayBuffer or JSON string.
diff --git a/docs/examples/en/loaders/KTX2Loader.html b/docs/examples/en/loaders/KTX2Loader.html
new file mode 100644
index 00000000000000..7f8d4d5584b363
--- /dev/null
+++ b/docs/examples/en/loaders/KTX2Loader.html
@@ -0,0 +1,133 @@
+
+
+
+ Loader for KTX 2.0 GPU Texture containers.
+
+ [link:http://github.khronos.org/KTX-Specification/ KTX 2.0] is a container format for various GPU texture formats. The loader
+ supports Basis Universal GPU textures, which can be quickly transcoded to
+ a wide variety of GPU texture compression formats. While KTX 2.0 also allows
+ other hardware-specific formats, this loader does not yet parse them.
+
+ This loader parses the KTX 2.0 container and then relies on + [page:BasisTextureLoader] to complete the transcoding process. + The required WASM transcoder and JS wrapper are available from the + [link:https://github.com/mrdoob/three.js/tree/dev/examples/js/libs/basis examples/js/libs/basis] + directory. +
+ +
+ var ktx2Loader = new THREE.KTX2Loader();
+ ktx2Loader.setTranscoderPath( 'examples/js/libs/basis/' );
+ ktx2Loader.detectSupport( renderer );
+ ktx2Loader.load( 'diffuse.ktx2', function ( texture ) {
+
+ var material = new THREE.MeshStandardMaterial( { map: texture } );
+
+ }, function () {
+
+ console.log( 'onProgress' );
+
+ }, function ( e ) {
+
+ console.error( e );
+
+ } );
+
+
+ + [example:webgl_loader_texture_ktx2] +
+ ++ See notes for [page:BasisTextureLoader]. This loader relies on ES6 Promises and Web Assembly, which are not + supported in IE11. +
+ ++ [page:LoadingManager manager] — The [page:LoadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager]. +
++ Creates a new [name]. +
+ +See the base [page:Loader] class for common properties.
+ +See the base [page:Loader] class for common methods.
+ +
+ [page:String url] — A string containing the path/URL of the .basis file.
+ [page:Function onLoad] — A function to be called after the loading is successfully completed.
+ [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.
+ [page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.
+
+ Load from url and call the onLoad function with the transcoded [page:CompressedTexture]. +
+ ++ [page:WebGLRenderer renderer] — A renderer instance. +
++ Detects hardware support for available compressed texture formats, to determine + the output format for the transcoder. Must be called before loading a texture. +
+ ++ [page:String path] — Path to folder containing the WASM transcoder and JS wrapper. +
++ The WASM transcoder and JS wrapper are available from the + [link:https://github.com/mrdoob/three.js/tree/dev/examples/js/libs/basis examples/js/libs/basis] + directory. +
+ ++ [page:Number limit] — Maximum number of workers. Default is '4'. +
++ Sets the maximum number of web workers to be allocated by this instance. +
+ ++ Disposes the loader object, de-allocating any Web Workers created. +
+ ++ [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/KTX2Loader.js examples/jsm/loaders/KTX2Loader.js] +
+ + diff --git a/docs/list.json b/docs/list.json index 24074a1df5fb81..da8f86899fc67d 100644 --- a/docs/list.json +++ b/docs/list.json @@ -370,6 +370,7 @@ "BasisTextureLoader": "examples/en/loaders/BasisTextureLoader", "DRACOLoader": "examples/en/loaders/DRACOLoader", "GLTFLoader": "examples/en/loaders/GLTFLoader", + "KTX2Loader": "examples/en/loaders/KTX2Loader", "MMDLoader": "examples/en/loaders/MMDLoader", "MTLLoader": "examples/en/loaders/MTLLoader", "OBJLoader": "examples/en/loaders/OBJLoader", diff --git a/examples/js/libs/basis/README.md b/examples/js/libs/basis/README.md index 8451f57ded00c6..150a27b081aaa2 100644 --- a/examples/js/libs/basis/README.md +++ b/examples/js/libs/basis/README.md @@ -10,27 +10,23 @@ a wide variety of GPU texture compression formats. ## Transcoders Basis Universal texture data may be used in two different file formats: -`.basis` and `.ktx2`. Texture data is identical in both cases, but different -transcoders are required to read the two file types. Both transcoders are -available in this folder now, but they may be merged in the future. +`.basis` and `.ktx2`, where `ktx2` is a standardized wrapper around basis texture data. For further documentation about the Basis compressor and transcoder, refer to the [Basis GitHub repository](https://github.com/BinomialLLC/basis_universal). -### .basis - -The folder contains two files required for transcoding `.basis` textures: +The folder contains two files required for transcoding `.basis` or `.ktx2` textures: * `basis_transcoder.js` — JavaScript wrapper for the WebAssembly transcoder. * `basis_transcoder.wasm` — WebAssembly transcoder. -Both are dependencies of `THREE.BasisTextureLoader`: +Both are dependencies of `THREE.KTX2Loader` and `THREE.BasisTextureLoader`: ```js -var basisLoader = new THREE.BasisTextureLoader(); -basisLoader.setTranscoderPath( 'examples/js/libs/basis/' ); -basisLoader.detectSupport( renderer ); -basisLoader.load( 'diffuse.basis', function ( texture ) { +var ktx2Loader = new THREE.KTX2Loader(); +ktx2Loader.setTranscoderPath( 'examples/js/libs/basis/' ); +ktx2Loader.detectSupport( renderer ); +ktx2Loader.load( 'diffuse.ktx2', function ( texture ) { var material = new THREE.MeshStandardMaterial( { map: texture } ); @@ -45,18 +41,6 @@ basisLoader.load( 'diffuse.basis', function ( texture ) { } ); ``` -### .ktx2 - -The folder contains two files required for transcoding `.ktx2` textures: - -* `msc_basis_transcoder.js` — JavaScript wrapper for the WebAssembly transcoder. -* `msc_basis_transcoder.wasm` — WebAssembly transcoder. - -Currently, the `msc_basis_transcoder.js` file must be added to the page as a -global script. The WASM transcoder will be downloaded from the same directory -automatically. These will likely be replaced with ES modules, and merged with -the `.basis` transcoder, in the future. See `KTX2Loader` for usage. - ## License [Apache License 2.0](https://github.com/BinomialLLC/basis_universal/blob/master/LICENSE) diff --git a/examples/jsm/loaders/KTX2Loader.d.ts b/examples/jsm/loaders/KTX2Loader.d.ts index c6f73f861e6b4a..778d7a5d1a1e4e 100644 --- a/examples/jsm/loaders/KTX2Loader.d.ts +++ b/examples/jsm/loaders/KTX2Loader.d.ts @@ -9,8 +9,10 @@ export class KTX2Loader extends CompressedTextureLoader { constructor( manager?: LoadingManager ); + setTranscoderPath( path: string ): KTX2Loader; + setWorkerLimit( limit: number ): KTX2Loader; detectSupport( renderer: WebGLRenderer ): KTX2Loader; - initModule(): void; + dispose(): KTX2Loader; parse( buffer: ArrayBuffer,