Forráskód Böngészése

Merge pull request #4563 from bghgary/support-one-key

Allow only one key frame in runtime animation
David Catuhe 7 éve
szülő
commit
64a7bf4955

+ 10 - 2
src/Animations/babylon.runtimeAnimation.ts

@@ -399,9 +399,17 @@
                 this._stopped = true;
                 return false;
             }
-            var returnValue = true;
+
             let keys = this._animation.getKeys();
 
+            // Return immediately if there is only one key frame.
+            if (keys.length === 1) {
+                this.setValue(keys[0].value, weight);
+                return !loop;
+            }
+
+            var returnValue = true;
+
             // Adding a start key at frame 0 if missing
             if (keys[0].frame !== 0) {
                 var newKey = { frame: 0, value: keys[0].value };
@@ -424,7 +432,7 @@
                     to++;
                 }
             }
-            
+
             // Compute ratio
             var range = to - from;
             var offsetValue;

+ 1 - 1
tests/unit/babylon/src/Animations/babylon.animationGroup.tests.ts

@@ -46,7 +46,7 @@ describe('Babylon Animation Group', function () {
 
             const length = 10;
             for (let i = 0; i < length; i++) {
-                const animation = new BABYLON.Animation(`animation${i}`, "", 1, BABYLON.Animation.ANIMATIONTYPE_VECTOR3);
+                const animation = new BABYLON.Animation(`animation${i}`, "position", 1, BABYLON.Animation.ANIMATIONTYPE_VECTOR3);
                 animation.setKeys([
                     {
                         frame: 0,