Browse Source

loaders circular dependencies

sebavan 6 năm trước cách đây
mục cha
commit
aaecddee79

+ 0 - 9
Tools/Config/tempCircularValidation/loaders.json

@@ -1,9 +0,0 @@
-{
-    "../../loaders/src/glTF/1.0/glTFLoader.ts": [
-        "../../loaders/src/glTF/1.0/glTFLoaderExtension.ts"
-    ],
-    "../../loaders/src/glTF/1.0/glTFLoaderExtension.ts": [
-        "../../loaders/src/glTF/1.0/glTFLoader.ts"
-    ],
-    "errorCount": 2
-}

+ 1 - 1
loaders/src/glTF/1.0/glTFBinaryExtension.ts

@@ -1,4 +1,4 @@
-import { GLTFLoaderExtension } from "./glTFLoaderExtension";
+import { GLTFLoaderExtension } from "./glTFLoader";
 import { GLTFUtils } from "./glTFLoaderUtils";
 import { Scene } from "babylonjs/scene";
 import { IGLTFLoaderData } from "../glTFFileLoader";

+ 156 - 1
loaders/src/glTF/1.0/glTFLoader.ts

@@ -33,7 +33,6 @@ import { Scene } from "babylonjs/scene";
 
 import { GLTFUtils } from "./glTFLoaderUtils";
 import { GLTFFileLoader, IGLTFLoader, GLTFLoaderState, IGLTFLoaderData } from "../glTFFileLoader";
-import { GLTFLoaderExtension } from "./glTFLoaderExtension";
 
 /**
 * Tokenizer. Used for shaders compatibility
@@ -1841,4 +1840,160 @@ export class GLTFLoader implements IGLTFLoader {
     }
 }
 
+/** @hidden */
+export abstract class GLTFLoaderExtension {
+    private _name: string;
+
+    public constructor(name: string) {
+        this._name = name;
+    }
+
+    public get name(): string {
+        return this._name;
+    }
+
+    /**
+    * Defines an override for loading the runtime
+    * Return true to stop further extensions from loading the runtime
+    */
+    public loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean {
+        return false;
+    }
+
+    /**
+     * Defines an onverride for creating gltf runtime
+     * Return true to stop further extensions from creating the runtime
+     */
+    public loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean {
+        return false;
+    }
+
+    /**
+    * Defines an override for loading buffers
+    * Return true to stop further extensions from loading this buffer
+    */
+    public loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean {
+        return false;
+    }
+
+    /**
+    * Defines an override for loading texture buffers
+    * Return true to stop further extensions from loading this texture data
+    */
+    public loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean {
+        return false;
+    }
+
+    /**
+    * Defines an override for creating textures
+    * Return true to stop further extensions from loading this texture
+    */
+    public createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean {
+        return false;
+    }
+
+    /**
+    * Defines an override for loading shader strings
+    * Return true to stop further extensions from loading this shader data
+    */
+    public loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean {
+        return false;
+    }
+
+    /**
+    * Defines an override for loading materials
+    * Return true to stop further extensions from loading this material
+    */
+    public loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean {
+        return false;
+    }
+
+    // ---------
+    // Utilities
+    // ---------
+
+    public static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void {
+        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
+            return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
+        }, () => {
+            setTimeout(() => {
+                if (!onSuccess) {
+                    return;
+                }
+                onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
+            });
+        });
+    }
+
+    public static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void {
+        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
+            return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
+        }, () => {
+            setTimeout(() => {
+                onSuccess();
+            });
+        });
+    }
+
+    public static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void {
+        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
+            return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
+        }, () => {
+            GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
+        });
+    }
+
+    public static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void {
+        GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id,
+            (buffer) => {
+                if (buffer) {
+                    GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
+                }
+            }, onError);
+    }
+
+    public static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void {
+        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
+            return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
+        }, () => {
+            GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
+        });
+    }
+
+    public static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void {
+        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
+            return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
+        }, () => {
+            GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
+        });
+    }
+
+    private static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void {
+        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
+            return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
+        }, () => {
+            GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
+        });
+    }
+
+    private static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void {
+        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
+            return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
+        }, () => {
+            GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
+        });
+    }
+
+    private static ApplyExtensions(func: (loaderExtension: GLTFLoaderExtension) => boolean, defaultFunc: () => void): void {
+        for (var extensionName in GLTFLoader.Extensions) {
+            var loaderExtension = GLTFLoader.Extensions[extensionName];
+            if (func(loaderExtension)) {
+                return;
+            }
+        }
+
+        defaultFunc();
+    }
+}
+
 GLTFFileLoader._CreateGLTF1Loader = () => new GLTFLoader();

+ 0 - 164
loaders/src/glTF/1.0/glTFLoaderExtension.ts

@@ -1,164 +0,0 @@
-import { Nullable } from "babylonjs/types";
-import { Material } from "babylonjs/Materials/material";
-import { Texture } from "babylonjs/Materials/Textures/texture";
-import { Scene } from "babylonjs/scene";
-
-import { IGLTFLoaderData } from "../glTFFileLoader";
-import { IGLTFRuntime } from "./glTFLoaderInterfaces";
-import { GLTFLoader, GLTFLoaderBase } from "./glTFLoader";
-
-/** @hidden */
-export abstract class GLTFLoaderExtension {
-        private _name: string;
-
-        public constructor(name: string) {
-            this._name = name;
-        }
-
-        public get name(): string {
-            return this._name;
-        }
-
-        /**
-        * Defines an override for loading the runtime
-        * Return true to stop further extensions from loading the runtime
-        */
-    public loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean {
-        return false;
-    }
-
-    /**
-     * Defines an onverride for creating gltf runtime
-     * Return true to stop further extensions from creating the runtime
-     */
-    public loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean {
-        return false;
-    }
-
-    /**
-    * Defines an override for loading buffers
-    * Return true to stop further extensions from loading this buffer
-    */
-    public loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean {
-        return false;
-    }
-
-    /**
-    * Defines an override for loading texture buffers
-    * Return true to stop further extensions from loading this texture data
-    */
-    public loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean {
-        return false;
-    }
-
-    /**
-    * Defines an override for creating textures
-    * Return true to stop further extensions from loading this texture
-    */
-    public createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean {
-        return false;
-    }
-
-    /**
-    * Defines an override for loading shader strings
-    * Return true to stop further extensions from loading this shader data
-    */
-    public loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean {
-        return false;
-    }
-
-    /**
-    * Defines an override for loading materials
-    * Return true to stop further extensions from loading this material
-    */
-    public loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean {
-        return false;
-    }
-
-    // ---------
-    // Utilities
-    // ---------
-
-    public static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void {
-        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
-            return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
-        }, () => {
-            setTimeout(() => {
-                if (!onSuccess) {
-                    return;
-                }
-                onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
-            });
-        });
-    }
-
-    public static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void {
-        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
-            return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
-        }, () => {
-            setTimeout(() => {
-                onSuccess();
-            });
-        });
-    }
-
-    public static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void {
-        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
-            return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
-        }, () => {
-            GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
-        });
-    }
-
-    public static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void {
-        GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id,
-            (buffer) => {
-                if (buffer) {
-                    GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
-                }
-            }, onError);
-    }
-
-    public static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void {
-        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
-            return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
-        }, () => {
-            GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
-        });
-    }
-
-    public static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void {
-        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
-            return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
-        }, () => {
-            GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
-        });
-    }
-
-    private static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void {
-        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
-            return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
-        }, () => {
-            GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
-        });
-    }
-
-    private static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void {
-        GLTFLoaderExtension.ApplyExtensions((loaderExtension) => {
-            return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
-        }, () => {
-            GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
-        });
-    }
-
-    private static ApplyExtensions(func: (loaderExtension: GLTFLoaderExtension) => boolean, defaultFunc: () => void): void {
-        for (var extensionName in GLTFLoader.Extensions) {
-            var loaderExtension = GLTFLoader.Extensions[extensionName];
-            if (func(loaderExtension)) {
-                return;
-            }
-        }
-
-        defaultFunc();
-    }
-}

+ 1 - 1
loaders/src/glTF/1.0/glTFMaterialsCommonExtension.ts

@@ -1,4 +1,4 @@
-import { GLTFLoaderExtension } from "./glTFLoaderExtension";
+import { GLTFLoaderExtension } from "./glTFLoader";
 import { GLTFLoaderBase } from "./glTFLoader";
 
 import { IGLTFRuntime, IGLTFMaterial } from "./glTFLoaderInterfaces";

+ 0 - 1
loaders/src/glTF/1.0/index.ts

@@ -1,6 +1,5 @@
 export * from "./glTFBinaryExtension";
 export * from "./glTFLoader";
-export * from "./glTFLoaderExtension";
 export * from "./glTFLoaderInterfaces";
 export * from "./glTFLoaderUtils";
 export * from "./glTFMaterialsCommonExtension";