Selaa lähdekoodia

Fix bug with animationGroup stop

Gary Hsu 7 vuotta sitten
vanhempi
commit
9bac689168

+ 2 - 3
src/Animations/babylon.animationGroup.ts

@@ -270,9 +270,8 @@ module BABYLON {
                 return this;
             }
 
-            for (var index = 0; index < this._animatables.length; index++) {
-                let animatable = this._animatables[index];
-                animatable.stop();
+            while (this._animatables.length > 0) {
+                this._animatables[0].stop();
             }
 
             this._isStarted = false;

+ 73 - 0
tests/unit/babylon/src/Animations/babylon.animationGroup.tests.ts

@@ -0,0 +1,73 @@
+/**
+ * Describes the test suite.
+ */
+describe('Babylon Animation Group', function () {
+    let subject: BABYLON.Engine;
+
+    /**
+     * Loads the dependencies.
+     */
+    before(function (done) {
+        this.timeout(180000);
+        (BABYLONDEVTOOLS).Loader
+            .useDist()
+            .load(function () {
+                // Force apply promise polyfill for consistent behavior between PhantomJS, IE11, and other browsers.
+                BABYLON.PromisePolyfill.Apply(true);
+                done();
+            });
+    });
+
+    /**
+     * Create a new engine subject before each test.
+     */
+    beforeEach(function () {
+        subject = new BABYLON.NullEngine({
+            renderHeight: 256,
+            renderWidth: 256,
+            textureSize: 256,
+            deterministicLockstep: false,
+            lockstepMaxSteps: 1
+        });
+
+        // Avoid creating normals in PBR materials.
+        subject.getCaps().standardDerivatives = true;
+    });
+
+    /**
+     * Animation group tests.
+     */
+    describe('#AnimationGroup', () => {
+        it('start and stop', () => {
+            const scene = new BABYLON.Scene(subject);
+            const node = new BABYLON.TransformNode("node0", scene);
+
+            const animationGroup = new BABYLON.AnimationGroup("animationGroup0", scene);
+
+            const length = 10;
+            for (let i = 0; i < length; i++) {
+                const animation = new BABYLON.Animation(`animation${i}`, "", 1, BABYLON.Animation.ANIMATIONTYPE_VECTOR3);
+                animation.setKeys([
+                    {
+                        frame: 0,
+                        value: BABYLON.Vector3.Zero()
+                    },
+                    {
+                        frame: 1,
+                        value: BABYLON.Vector3.Zero()
+                    }
+                ]);
+
+                animationGroup.addTargetedAnimation(animation, node);
+            }
+
+            animationGroup.start();
+            expect(animationGroup.animatables.length, "animationGroup.animatables.length").to.equal(length);
+            expect(scene.animatables.length, "scene.animatables.length").to.equal(length);
+
+            animationGroup.stop();
+            expect(animationGroup.animatables.length, "animationGroup.animatables.length").to.equal(0);
+            expect(scene.animatables.length, "scene.animatables.length").to.equal(0);
+        });
+    });
+});

+ 1 - 0
tests/unit/karma.conf.js

@@ -16,6 +16,7 @@ module.exports = function (config) {
             './tests/unit/babylon/babylon.example.tests.js',
             './tests/unit/babylon/serializers/babylon.glTFSerializer.tests.js',
             './tests/unit/babylon/src/babylon.node.tests.js',
+            './tests/unit/babylon/src/Animations/babylon.animationGroup.tests.js',
             './tests/unit/babylon/src/Helpers/babylon.particleHelper.tests.js',
             './tests/unit/babylon/src/Loading/babylon.sceneLoader.tests.js',
             './tests/unit/babylon/src/PostProcess/babylon.postProcess.tests.js',