Pārlūkot izejas kodu

Fix exception when material does not define a technique

Gary Hsu 9 gadi atpakaļ
vecāks
revīzija
13f558c8ee

+ 7 - 0
loaders/glTF/babylon.glTFFileLoader.js

@@ -1192,6 +1192,13 @@ var BABYLON;
         GLTFFileLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
             var material = gltfRuntime.materials[id];
             var technique = gltfRuntime.techniques[material.technique];
+            if (!technique) {
+                var defaultMaterial = new BABYLON.StandardMaterial(id, gltfRuntime.scene);
+                defaultMaterial.diffuseColor = new BABYLON.Color3(0.5, 0.5, 0.5);
+                defaultMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
+                onSuccess(defaultMaterial);
+                return;
+            }
             var program = gltfRuntime.programs[technique.program];
             var states = technique.states;
             var vertexShader = BABYLON.Effect.ShadersStore[program.vertexShader + "VertexShader"];

+ 7 - 0
loaders/glTF/babylon.glTFFileLoader.ts

@@ -1349,6 +1349,13 @@
         public static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): void {
             var material: IGLTFMaterial = gltfRuntime.materials[id];
             var technique: IGLTFTechnique = gltfRuntime.techniques[material.technique];
+            if (!technique) {
+                var defaultMaterial = new StandardMaterial(id, gltfRuntime.scene);
+                defaultMaterial.diffuseColor = new Color3(0.5, 0.5, 0.5);
+                defaultMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
+                onSuccess(defaultMaterial);
+                return;
+            }
 
             var program: IGLTFProgram = gltfRuntime.programs[technique.program];
             var states: IGLTFTechniqueStates = technique.states;