diff --git a/docs/examples/en/loaders/KTX2Loader.html b/docs/examples/en/loaders/KTX2Loader.html index 0eaae0b86d9e61..34efd826f48f5f 100644 --- a/docs/examples/en/loaders/KTX2Loader.html +++ b/docs/examples/en/loaders/KTX2Loader.html @@ -42,7 +42,10 @@

Code Example

var ktx2Loader = new KTX2Loader(); - ktx2Loader.setTranscoderPath( 'examples/jsm/libs/basis/' ); + ktx2Loader.setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) ktx2Loader.detectSupport( renderer ); ktx2Loader.load( 'diffuse.ktx2', function ( texture ) { diff --git a/docs/examples/zh/loaders/KTX2Loader.html b/docs/examples/zh/loaders/KTX2Loader.html index 0fe2de7ad30d47..c8c88baf12eed2 100644 --- a/docs/examples/zh/loaders/KTX2Loader.html +++ b/docs/examples/zh/loaders/KTX2Loader.html @@ -39,7 +39,10 @@

代码示例

var ktx2Loader = new KTX2Loader(); - ktx2Loader.setTranscoderPath( 'examples/jsm/libs/basis/' ); + ktx2Loader.setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) ktx2Loader.detectSupport( renderer ); ktx2Loader.load( 'diffuse.ktx2', function ( texture ) { diff --git a/editor/js/Loader.js b/editor/js/Loader.js index 00fa7295ba522a..46eb2bba74a5ca 100644 --- a/editor/js/Loader.js +++ b/editor/js/Loader.js @@ -992,7 +992,10 @@ function Loader( editor ) { dracoLoader.setDecoderPath( '../examples/jsm/libs/draco/gltf/' ); const ktx2Loader = new KTX2Loader( manager ); - ktx2Loader.setTranscoderPath( '../examples/jsm/libs/basis/' ); + ktx2Loader.setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ); editor.signals.rendererDetectKTX2Support.dispatch( ktx2Loader ); diff --git a/editor/js/libs/ui.three.js b/editor/js/libs/ui.three.js index fa7c3c1337fe49..7544fb3a76edb6 100644 --- a/editor/js/libs/ui.three.js +++ b/editor/js/libs/ui.three.js @@ -117,7 +117,10 @@ class UITexture extends UISpan { const arrayBuffer = event.target.result; const blobURL = URL.createObjectURL( new Blob( [ arrayBuffer ] ) ); const ktx2Loader = new KTX2Loader(); - ktx2Loader.setTranscoderPath( '../../examples/jsm/libs/basis/' ); + ktx2Loader.setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ); editor.signals.rendererDetectKTX2Support.dispatch( ktx2Loader ); ktx2Loader.load( blobURL, function ( texture ) { diff --git a/examples/jsm/libs/basis/README.md b/examples/jsm/libs/basis/README.md index 2d7744fcf80c1d..a22b318e516005 100644 --- a/examples/jsm/libs/basis/README.md +++ b/examples/jsm/libs/basis/README.md @@ -24,7 +24,10 @@ Both are dependencies of `KTX2Loader`: ```js const ktx2Loader = new KTX2Loader(); -ktx2Loader.setTranscoderPath( 'examples/jsm/libs/basis/' ); +ktx2Loader.setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' +} ) ktx2Loader.detectSupport( renderer ); ktx2Loader.load( 'diffuse.ktx2', function ( texture ) { diff --git a/examples/jsm/loaders/KTX2Loader.js b/examples/jsm/loaders/KTX2Loader.js index 951efdb52e1cff..a963cd1edb1ae4 100644 --- a/examples/jsm/loaders/KTX2Loader.js +++ b/examples/jsm/loaders/KTX2Loader.js @@ -100,7 +100,10 @@ let _zstd; * * ```js * const loader = new KTX2Loader(); - * loader.setTranscoderPath( 'examples/jsm/libs/basis/' ); + * loader.setTranscoderPath( { + * js: 'examples/jsm/libs/basis/basis_transcoder.js', + * wasm: 'examples/jsm/libs/basis/basis_transcoder.wasm' + * } ); * loader.detectSupport( renderer ); * const texture = loader.loadAsync( 'diffuse.ktx2' ); * ``` @@ -119,7 +122,8 @@ class KTX2Loader extends Loader { super( manager ); - this.transcoderPath = ''; + this.transcoderJsPath = null; + this.transcoderWasmPath = null; this.transcoderBinary = null; this.transcoderPending = null; @@ -141,16 +145,19 @@ class KTX2Loader extends Loader { } /** - * Sets the transcoder path. + * Sets the transcoder paths. * * The WASM transcoder and JS wrapper are available from the `examples/jsm/libs/basis` directory. * - * @param {string} path - The transcoder path to set. + * @param {Object} paths - An object with js and wasm fields + * @param {string} paths.js - Full URL to the basis_transcoder.js file + * @param {string} paths.wasm - Full URL to the basis_transcoder.wasm file * @return {KTX2Loader} A reference to this loader. */ - setTranscoderPath( path ) { + setTranscoderPath( { js, wasm } ) { - this.transcoderPath = path; + this.transcoderJsPath = js; + this.transcoderWasmPath = wasm; return this; @@ -241,18 +248,22 @@ class KTX2Loader extends Loader { if ( ! this.transcoderPending ) { + if ( ! this.transcoderJsPath || ! this.transcoderWasmPath ) { + + throw new Error( 'THREE.KTX2Loader: Missing transcoder paths. Use .setTranscoderPath() to set the paths.' ); + + } + // Load transcoder wrapper. const jsLoader = new FileLoader( this.manager ); - jsLoader.setPath( this.transcoderPath ); jsLoader.setWithCredentials( this.withCredentials ); - const jsContent = jsLoader.loadAsync( 'basis_transcoder.js' ); + const jsContent = jsLoader.loadAsync( this.transcoderJsPath ); // Load transcoder WASM binary. const binaryLoader = new FileLoader( this.manager ); - binaryLoader.setPath( this.transcoderPath ); binaryLoader.setResponseType( 'arraybuffer' ); binaryLoader.setWithCredentials( this.withCredentials ); - const binaryContent = binaryLoader.loadAsync( 'basis_transcoder.wasm' ); + const binaryContent = binaryLoader.loadAsync( this.transcoderWasmPath ); this.transcoderPending = Promise.all( [ jsContent, binaryContent ] ) .then( ( [ jsContent, binaryContent ] ) => { diff --git a/examples/misc_exporter_gltf.html b/examples/misc_exporter_gltf.html index 146e0b92e8efde..5754c88e2f2813 100644 --- a/examples/misc_exporter_gltf.html +++ b/examples/misc_exporter_gltf.html @@ -484,7 +484,10 @@ // Exporting compressed textures and meshes (KTX2 / Draco / Meshopt) // --------------------------------------------------------------------- const ktx2Loader = new KTX2Loader() - .setTranscoderPath( 'jsm/libs/basis/' ) + .setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) .detectSupport( renderer ); const gltfLoader = new GLTFLoader().setPath( 'models/gltf/' ); diff --git a/examples/webgl_loader_gltf_compressed.html b/examples/webgl_loader_gltf_compressed.html index 49a70665841478..43012642956224 100644 --- a/examples/webgl_loader_gltf_compressed.html +++ b/examples/webgl_loader_gltf_compressed.html @@ -69,7 +69,10 @@ scene.add( grid ); const ktx2Loader = new KTX2Loader() - .setTranscoderPath( 'jsm/libs/basis/' ) + .setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) .detectSupport( renderer ); const loader = new GLTFLoader().setPath( 'models/gltf/' ); diff --git a/examples/webgl_loader_texture_ktx2.html b/examples/webgl_loader_texture_ktx2.html index c41ecc1438c3c1..1e3a4b39111d09 100644 --- a/examples/webgl_loader_texture_ktx2.html +++ b/examples/webgl_loader_texture_ktx2.html @@ -141,7 +141,10 @@ renderer.setPixelRatio( window.devicePixelRatio ); const loader = new KTX2Loader() - .setTranscoderPath( 'jsm/libs/basis/' ) + .setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) .setPath( 'textures/ktx2/' ) .detectSupport( renderer ); diff --git a/examples/webgl_morphtargets_face.html b/examples/webgl_morphtargets_face.html index 02b0c2b6ff0c78..d61e3b4ec2cc12 100644 --- a/examples/webgl_morphtargets_face.html +++ b/examples/webgl_morphtargets_face.html @@ -68,7 +68,10 @@ container.appendChild( renderer.domElement ); const ktx2Loader = new KTX2Loader() - .setTranscoderPath( 'jsm/libs/basis/' ) + .setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) .detectSupport( renderer ); new GLTFLoader() diff --git a/examples/webgl_morphtargets_webcam.html b/examples/webgl_morphtargets_webcam.html index a54f8fca03fd91..9a02dd6136c17d 100644 --- a/examples/webgl_morphtargets_webcam.html +++ b/examples/webgl_morphtargets_webcam.html @@ -130,7 +130,10 @@ const eyeRotationLimit = THREE.MathUtils.degToRad( 30 ); const ktx2Loader = new KTX2Loader() - .setTranscoderPath( 'jsm/libs/basis/' ) + .setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) .detectSupport( renderer ); new GLTFLoader() diff --git a/examples/webgl_texture2darray_compressed.html b/examples/webgl_texture2darray_compressed.html index 1f0b4a7fabdb3b..fb7b20086d0238 100644 --- a/examples/webgl_texture2darray_compressed.html +++ b/examples/webgl_texture2darray_compressed.html @@ -96,7 +96,10 @@ // const ktx2Loader = new KTX2Loader(); - ktx2Loader.setTranscoderPath( 'jsm/libs/basis/' ); + ktx2Loader.setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ); ktx2Loader.detectSupport( renderer ); ktx2Loader.load( 'textures/spiritedaway.ktx2', function ( texturearray ) { diff --git a/examples/webgl_texture2darray_layerupdate.html b/examples/webgl_texture2darray_layerupdate.html index 3c9f89841fea18..61f643681c2e19 100644 --- a/examples/webgl_texture2darray_layerupdate.html +++ b/examples/webgl_texture2darray_layerupdate.html @@ -94,7 +94,10 @@ // Configure the KTX2 loader. const ktx2Loader = new KTX2Loader(); - ktx2Loader.setTranscoderPath( 'jsm/libs/basis/' ); + ktx2Loader.setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ); ktx2Loader.detectSupport( renderer ); // Load several KTX2 textures which will later be used to modify diff --git a/examples/webgpu_loader_gltf_compressed.html b/examples/webgpu_loader_gltf_compressed.html index 0cef58c00620ee..9b1e0e91c28b96 100644 --- a/examples/webgpu_loader_gltf_compressed.html +++ b/examples/webgpu_loader_gltf_compressed.html @@ -68,7 +68,10 @@ controls.update(); const ktx2Loader = await new KTX2Loader() - .setTranscoderPath( 'jsm/libs/basis/' ) + .setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) .detectSupportAsync( renderer ); const loader = new GLTFLoader(); diff --git a/examples/webgpu_morphtargets_face.html b/examples/webgpu_morphtargets_face.html index 9640686a43455e..35f376bb84e088 100644 --- a/examples/webgpu_morphtargets_face.html +++ b/examples/webgpu_morphtargets_face.html @@ -74,7 +74,10 @@ scene.environment = pmremGenerator.fromScene( environment ).texture; const ktx2Loader = await new KTX2Loader() - .setTranscoderPath( 'jsm/libs/basis/' ) + .setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) .detectSupportAsync( renderer ); new GLTFLoader() diff --git a/examples/webgpu_sandbox.html b/examples/webgpu_sandbox.html index 749e249625cc31..6cb7e8499bb8bf 100644 --- a/examples/webgpu_sandbox.html +++ b/examples/webgpu_sandbox.html @@ -64,7 +64,10 @@ textureDisplace.wrapT = THREE.RepeatWrapping; const ktxLoader = await new KTX2Loader() - .setTranscoderPath( 'jsm/libs/basis/' ) + .setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ) .detectSupportAsync( renderer ); const ktxTexture = await ktxLoader.loadAsync( './textures/ktx2/2d_uastc.ktx2' ); diff --git a/examples/webgpu_textures_2d-array_compressed.html b/examples/webgpu_textures_2d-array_compressed.html index 0d208d9c83d273..2681c9c1459a3c 100644 --- a/examples/webgpu_textures_2d-array_compressed.html +++ b/examples/webgpu_textures_2d-array_compressed.html @@ -67,7 +67,10 @@ // const ktx2Loader = new KTX2Loader(); - ktx2Loader.setTranscoderPath( 'jsm/libs/basis/' ); + ktx2Loader.setTranscoderPath( { + js: 'jsm/libs/basis/basis_transcoder.js', + wasm: 'jsm/libs/basis/basis_transcoder.wasm' + } ); await ktx2Loader.detectSupportAsync( renderer ); ktx2Loader.load( 'textures/spiritedaway.ktx2', function ( texturearray ) {