浏览代码

Fix glTF loader bug when the node of animation channel target is missing

Gary Hsu 6 年之前
父节点
当前提交
1e6f1a09bd
共有 2 个文件被更改,包括 12 次插入5 次删除
  1. 4 0
      loaders/src/glTF/2.0/babylon.glTFLoader.ts
  2. 8 5
      sandbox/index.js

+ 4 - 0
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -1037,6 +1037,10 @@ module BABYLON.GLTF2 {
         }
         }
 
 
         private _loadAnimationChannelAsync(context: string, animationContext: string, animation: Loader.IAnimation, channel: Loader.IAnimationChannel, babylonAnimationGroup: AnimationGroup): Promise<void> {
         private _loadAnimationChannelAsync(context: string, animationContext: string, animation: Loader.IAnimation, channel: Loader.IAnimationChannel, babylonAnimationGroup: AnimationGroup): Promise<void> {
+            if (channel.target.node == undefined) {
+                return Promise.resolve();
+            }
+
             const targetNode = ArrayItem.Get(`${context}/target/node`, this.gltf.nodes, channel.target.node);
             const targetNode = ArrayItem.Get(`${context}/target/node`, this.gltf.nodes, channel.target.node);
 
 
             // Ignore animations that have no animation targets.
             // Ignore animations that have no animation targets.

+ 8 - 5
sandbox/index.js

@@ -119,11 +119,14 @@ if (BABYLON.Engine.isSupported()) {
 
 
         // Sync the slider with the current frame
         // Sync the slider with the current frame
         babylonScene.registerBeforeRender(function() {
         babylonScene.registerBeforeRender(function() {
-            if (currentGroup != null && currentGroup.targetedAnimations[0].animation.runtimeAnimations[0] != null) {
-                var currentValue = slider.valueAsNumber;
-                var newValue = currentGroup.targetedAnimations[0].animation.runtimeAnimations[0].currentFrame;
-                var range = Math.abs(currentGroup.from - currentGroup.to);
-                slider.value = newValue;
+            if (currentGroup) {
+                var targetedAnimations = currentGroup.targetedAnimations;
+                if (targetedAnimations.length > 0) {
+                    var runtimeAnimations = currentGroup.targetedAnimations[0].animation.runtimeAnimations;
+                    if (runtimeAnimations.length > 0) {
+                        slider.value = runtimeAnimations[0].currentFrame;
+                    }
+                }
             }
             }
         });
         });