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 @@

[method:null setDDSLoader]( [param:DDSLoader ddsLoader] )

[page:DDSLoader ddsLoader] — Instance of THREE.DDSLoader, to be used for loading compressed textures with the MSFT_TEXTURE_DDS extension.

+

[method:null setKTX2Loader]( [param:KTX2Loader ktx2Loader] )

+

+ [page:KTX2Loader ktx2Loader] — Instance of THREE.KTX2Loader, to be used for loading KTX2 compressed textures. +

+

[method:null parse]( [param:ArrayBuffer data], [param:String path], [param:Function onLoad], [param:Function onError] )

[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 @@ + + + + + + + + + + [page:Loader] → + +

[name]

+ +

+ 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. +

+ +

Code Example

+ + + 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 ); + + } ); + + +

Examples

+ +

+ [example:webgl_loader_texture_ktx2] +

+ +

Browser compatibility

+ +

+ See notes for [page:BasisTextureLoader]. This loader relies on ES6 Promises and Web Assembly, which are not + supported in IE11. +

+ +
+
+ +

Constructor

+ +

[name]( [param:LoadingManager manager] )

+

+ [page:LoadingManager manager] — The [page:LoadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager]. +

+

+ Creates a new [name]. +

+ +

Properties

+

See the base [page:Loader] class for common properties.

+ +

Methods

+

See the base [page:Loader] class for common methods.

+ +

[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

+ [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]. +

+ +

[method:this detectSupport]( [param:WebGLRenderer renderer] )

+

+ [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. +

+ +

[method:this setTranscoderPath]( [param:String path] )

+

+ [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. +

+ +

[method:this setWorkerLimit]( [param:Number limit] )

+

+ [page:Number limit] — Maximum number of workers. Default is '4'. +

+

+ Sets the maximum number of web workers to be allocated by this instance. +

+ +

[method:this dispose]()

+

+ Disposes the loader object, de-allocating any Web Workers created. +

+ +

Source

+ +

+ [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,