Просмотр исходного кода

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 8 лет назад
Родитель
Сommit
b3286a4da9

Разница между файлами не показана из-за своего большого размера
+ 634 - 1057
loaders/src/glTF/2.0/babylon.glTFLoader.ts


+ 6 - 17
loaders/src/glTF/2.0/babylon.glTFLoaderExtension.ts

@@ -14,35 +14,24 @@ module BABYLON.GLTF2 {
             return this._name;
         }
 
-        protected postCreateRuntime(runtime: IGLTFRuntime): void {}
-
-        // Return true to stop other extensions from loading materials.
-        protected loadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): boolean { return false; }
+        protected loadMaterial(index: number): Material { return null; }
 
         // ---------
         // Utilities
         // ---------
 
-        public static PostCreateRuntime(runtime: IGLTFRuntime): void {
-            for (var extensionName in GLTFLoader.Extensions) {
-                var extension = GLTFLoader.Extensions[extensionName];
-                if (extension.enabled) {
-                    extension.postCreateRuntime(runtime);
-                }
-            }
-        }
-
-        public static LoadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): void {
+        public static LoadMaterial(index: number): Material {
             for (var extensionName in GLTFLoader.Extensions) {
                 var extension = GLTFLoader.Extensions[extensionName];
                 if (extension.enabled) {
-                    if (extension.loadMaterialAsync(runtime, index, onSuccess, onError)) {
-                        return;
+                    var babylonMaterial = extension.loadMaterial(index);
+                    if (babylonMaterial) {
+                        return babylonMaterial;
                     }
                 }
             }
 
-            GLTFLoader.LoadCoreMaterialAsync(runtime, index, onSuccess, onError);
+            return GLTFLoader.LoadCoreMaterial(index);
         }
     }
 }

+ 13 - 34
loaders/src/glTF/2.0/babylon.glTFLoaderInterfaces.ts

@@ -103,6 +103,9 @@ module BABYLON.GLTF2 {
     export interface IGLTFAnimation extends IGLTFChildRootProperty {
         channels: IGLTFAnimationChannel[];
         samplers: IGLTFAnimationSampler[];
+
+        // Runtime values
+        targets?: any[];
     }
 
     export interface IGLTFAssetProfile extends IGLTFProperty {
@@ -121,8 +124,9 @@ module BABYLON.GLTF2 {
         uri?: string;
         byteLength: number;
 
-        // Loaded buffer (optimize)
-        loadedBufferView: ArrayBufferView
+        // Runtime values
+        loadedData: ArrayBufferView;
+        loadedObservable: Observable<IGLTFBuffer>;
     }
 
     export interface IGLTFBufferView extends IGLTFChildRootProperty {
@@ -184,7 +188,7 @@ module BABYLON.GLTF2 {
         alphaCutoff: number;
         doubleSided?: boolean;
 
-        // Babylon.js values (optimize)
+        // Runtime values
         babylonMaterial?: PBRMaterial;
     }
 
@@ -212,7 +216,8 @@ module BABYLON.GLTF2 {
         translation?: number[];
         weights?: number[];
 
-        // Babylon.js values (optimize)
+        // Runtime values
+        index?: number;
         babylonNode?: Node;
     }
 
@@ -232,7 +237,7 @@ module BABYLON.GLTF2 {
         skeleton?: number;
         joints: number[];
 
-        // Babylon.js values (optimize)
+        // Runtime values
         babylonSkeleton?: Skeleton;
     }
 
@@ -240,9 +245,9 @@ module BABYLON.GLTF2 {
         sampler?: number;
         source: number;
 
-        // Babylon.js values (optimize, one per coordinate index)
-        babylonTextures: Texture[];
-        blobURL: string;
+        // Runtime values (one per coordinate index)
+        babylonTextures?: Texture[];
+        blobURL?: string;
     }
 
     export interface IGLTFTextureInfo {
@@ -270,30 +275,4 @@ module BABYLON.GLTF2 {
         skins?: IGLTFSkin[];
         textures?: IGLTFTexture[];
     }
-
-    export interface IGLTFRuntime {
-        gltf: IGLTF;
-
-        babylonScene: Scene;
-        rootUrl: string;
-
-        importOnlyMeshes: boolean;
-        importMeshesNames?: string[];
-
-        defaultMaterial?: PBRMaterial;
-    }
-
-    /**
-    * Bones
-    */
-    export interface INodeToRoot {
-        bone: Bone;
-        node: IGLTFNode;
-        index: number;
-    }
-
-    export interface IJointNode {
-        node: IGLTFNode;
-        index: number;
-    }
 }

+ 1 - 50
loaders/src/glTF/2.0/babylon.glTFLoaderUtils.ts

@@ -76,39 +76,6 @@ module BABYLON.GLTF2 {
             }
         }
 
-        public static GetBufferFromBufferView(runtime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView {
-            byteOffset += (bufferView.byteOffset || 0);
-
-            var loadedBufferView = runtime.gltf.buffers[bufferView.buffer].loadedBufferView;
-            if (byteOffset + byteLength > loadedBufferView.byteLength) {
-                throw new Error("Buffer access is out of range");
-            }
-
-            var buffer = loadedBufferView.buffer;
-            byteOffset += loadedBufferView.byteOffset;
-
-            switch (componentType) {
-                case EComponentType.BYTE: return new Int8Array(buffer, byteOffset, byteLength);
-                case EComponentType.UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
-                case EComponentType.SHORT: return new Int16Array(buffer, byteOffset, byteLength);
-                case EComponentType.UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
-                case EComponentType.UNSIGNED_INT: return new Uint32Array(buffer, byteOffset, byteLength);
-                default: return new Float32Array(buffer, byteOffset, byteLength);
-            }
-        }
-
-        /**
-         * Returns a buffer from its accessor
-         * @param runtime: the GLTF runtime
-         * @param accessor: the GLTF accessor
-         */
-        public static GetBufferFromAccessor(runtime: IGLTFRuntime, accessor: IGLTFAccessor): ArrayBufferView {
-            var bufferView = runtime.gltf.bufferViews[accessor.bufferView];
-            var byteOffset = accessor.byteOffset || 0;
-            var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
-            return GLTFUtils.GetBufferFromBufferView(runtime, bufferView, byteOffset, byteLength, accessor.componentType);
-        }
-
         /**
          * Decodes a buffer view into a string
          * @param view: the buffer view
@@ -123,21 +90,5 @@ module BABYLON.GLTF2 {
 
             return result;
         }
-
-        /**
-         * Returns the default material of gltf.
-         * @param scene: the Babylon.js scene
-         */
-        public static GetDefaultMaterial(runtime: IGLTFRuntime): PBRMaterial {
-            if (!runtime.defaultMaterial) {
-                var material = new PBRMaterial("gltf_default", runtime.babylonScene);
-                material.sideOrientation = Material.CounterClockWiseSideOrientation;
-                material.metallic = 1;
-                material.roughness = 1;
-                runtime.defaultMaterial = material;
-            }
-
-            return runtime.defaultMaterial;
-        }
     }
-}
+}

+ 11 - 41
loaders/src/glTF/2.0/babylon.glTFMaterialsPbrSpecularGlossinessExtension.ts

@@ -14,12 +14,14 @@ module BABYLON.GLTF2 {
             super("KHR_materials_pbrSpecularGlossiness");
         }
 
-        protected loadMaterialAsync(runtime: IGLTFRuntime, index: number, onSuccess: () => void, onError: () => void): boolean {
-            var material = GLTFLoader.LoadMaterial(runtime, index);
-            if (!material || !material.extensions) return false;
+        protected loadMaterial(index: number): Material {
+            var material = GLTFLoader.LoadMaterial(index);
+            if (!material || !material.extensions) return null;
 
             var properties: IGLTFMaterialsPbrSpecularGlossiness = material.extensions[this.name];
-            if (!properties) return false;
+            if (!properties) return null;
+
+            GLTFLoader.LoadCommonMaterialProperties(material);
 
             //
             // Load Factors
@@ -33,49 +35,17 @@ module BABYLON.GLTF2 {
             // Load Textures
             //
 
-            var commonMaterialPropertiesSuccess = false;
-
-            var checkSuccess = () => {
-                if ((!properties.diffuseTexture || material.babylonMaterial.albedoTexture) &&
-                    (!properties.specularGlossinessTexture || material.babylonMaterial.reflectivityTexture) &&
-                    commonMaterialPropertiesSuccess) {
-                    onSuccess();
-                }
-            };
-
             if (properties.diffuseTexture) {
-                GLTFLoader.LoadTextureAsync(runtime, properties.diffuseTexture,
-                    texture => {
-                        material.babylonMaterial.albedoTexture = texture;
-                        GLTFLoader.LoadAlphaProperties(runtime, material);
-                        checkSuccess();
-                    },
-                    () => {
-                        Tools.Warn("Failed to load diffuse texture");
-                        onError();
-                    });
+                material.babylonMaterial.albedoTexture = GLTFLoader.LoadTexture(properties.diffuseTexture);
+                GLTFLoader.LoadAlphaProperties(material);
             }
 
             if (properties.specularGlossinessTexture) {
-                GLTFLoader.LoadTextureAsync(runtime, properties.specularGlossinessTexture,
-                    texture => {
-                        material.babylonMaterial.reflectivityTexture = texture;
-                        material.babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
-                        checkSuccess();
-                    },
-                    () => {
-                        Tools.Warn("Failed to load metallic roughness texture");
-                        onError();
-                    });
+                material.babylonMaterial.reflectivityTexture = GLTFLoader.LoadTexture(properties.specularGlossinessTexture);
+                material.babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
             }
 
-            GLTFLoader.LoadCommonMaterialPropertiesAsync(runtime, material,
-                () => {
-                    commonMaterialPropertiesSuccess = true;
-                    checkSuccess();
-                }, onError);
-
-            return true;
+            return material.babylonMaterial;
         }
     }