Kaynağa Gözat

Merge pull request #9011 from Popov72/ktx2loader-url-config

KTX2 loader: Allow configuring the urls used by the decoder
David Catuhe 4 yıl önce
ebeveyn
işleme
ca62eed218
1 değiştirilmiş dosya ile 35 ekleme ve 6 silme
  1. 35 6
      src/Misc/khronosTextureContainer2.ts

+ 35 - 6
src/Misc/khronosTextureContainer2.ts

@@ -7,7 +7,6 @@ declare var KTX2DECODER: any;
 
 
 /**
 /**
  * Class for loading KTX2 files
  * Class for loading KTX2 files
- * @hidden
  */
  */
 export class KhronosTextureContainer2 {
 export class KhronosTextureContainer2 {
     private static _WorkerPoolPromise?: Promise<WorkerPool>;
     private static _WorkerPoolPromise?: Promise<WorkerPool>;
@@ -15,9 +14,24 @@ export class KhronosTextureContainer2 {
     private static _Ktx2Decoder: any; // used when no worker pool is used
     private static _Ktx2Decoder: any; // used when no worker pool is used
 
 
     /**
     /**
-     * URL to use when loading the KTX2 decoder module
+     * URLs to use when loading the KTX2 decoder module as well as its dependencies
+     * If a url is null, the default url is used (pointing to https://preview.babylonjs.com)
+     * Note that jsDecoderModule can't be null and that the other dependencies will only be loaded if necessary
+     * Urls you can change:
+     *     URLConfig.jsDecoderModule
+     *     URLConfig.wasmUASTCToASTC
+     *     URLConfig.wasmUASTCToBC7
+     *     URLConfig.jsMSCTranscoder
+     *     URLConfig.wasmMSCTranscoder
+     * You can see their default values in this PG: https://playground.babylonjs.com/#EIJH8L#9
      */
      */
-    public static JSModuleURL = "https://preview.babylonjs.com/babylon.ktx2Decoder.js";
+    public static URLConfig = {
+        jsDecoderModule: "https://preview.babylonjs.com/babylon.ktx2Decoder.js",
+        wasmUASTCToASTC: null,
+        wasmUASTCToBC7: null,
+        jsMSCTranscoder: null,
+        wasmMSCTranscoder: null
+    };
 
 
     /**
     /**
      * Default number of workers used to handle data decoding
      * Default number of workers used to handle data decoding
@@ -66,7 +80,7 @@ export class KhronosTextureContainer2 {
 
 
                         worker.postMessage({
                         worker.postMessage({
                             action: "init",
                             action: "init",
-                            jsPath: KhronosTextureContainer2.JSModuleURL
+                            urls: KhronosTextureContainer2.URLConfig
                         });
                         });
                     });
                     });
                 }
                 }
@@ -83,6 +97,7 @@ export class KhronosTextureContainer2 {
 
 
     /**
     /**
      * Constructor
      * Constructor
+     * @param engine The engine to use
      * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
      * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
      */
      */
     public constructor(engine: ThinEngine, numWorkers = KhronosTextureContainer2.DefaultNumWorkers) {
     public constructor(engine: ThinEngine, numWorkers = KhronosTextureContainer2.DefaultNumWorkers) {
@@ -93,6 +108,7 @@ export class KhronosTextureContainer2 {
         }
         }
     }
     }
 
 
+    /** @hidden */
     public uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture): Promise<void> {
     public uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture): Promise<void> {
         const caps = this._engine.getCaps();
         const caps = this._engine.getCaps();
 
 
@@ -237,13 +253,26 @@ declare function postMessage(message: any, transfer?: any[]): void;
 
 
 declare var KTX2DECODER: any;
 declare var KTX2DECODER: any;
 
 
-export function workerFunc(): void {
+function workerFunc(): void {
     let ktx2Decoder: any;
     let ktx2Decoder: any;
 
 
     onmessage = (event) => {
     onmessage = (event) => {
         switch (event.data.action) {
         switch (event.data.action) {
             case "init":
             case "init":
-                importScripts(event.data.jsPath);
+                const urls = event.data.urls;
+                importScripts(urls.jsDecoderModule);
+                if (urls.wasmUASTCToASTC !== null) {
+                    KTX2DECODER.LiteTranscoder_UASTC_ASTC.WasmModuleURL = urls.wasmUASTCToASTC;
+                }
+                if (urls.wasmUASTCToBC7 !== null) {
+                    KTX2DECODER.LiteTranscoder_UASTC_BC7.WasmModuleURL = urls.wasmUASTCToBC7;
+                }
+                if (urls.jsMSCTranscoder !== null) {
+                    KTX2DECODER.MSCTranscoder.JSModuleURL = urls.jsMSCTranscoder;
+                }
+                if (urls.wasmMSCTranscoder !== null) {
+                    KTX2DECODER.MSCTranscoder.WasmModuleURL = urls.wasmMSCTranscoder;
+                }
                 ktx2Decoder = new KTX2DECODER.KTX2Decoder();
                 ktx2Decoder = new KTX2DECODER.KTX2Decoder();
                 postMessage({ action: "init" });
                 postMessage({ action: "init" });
                 break;
                 break;