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

Remove old animations with same target property as a new one

noalak 5 лет назад
Родитель
Сommit
bd48adfd1f
1 измененных файлов с 15 добавлено и 0 удалено
  1. 15 0
      src/Loading/sceneLoader.ts

+ 15 - 0
src/Loading/sceneLoader.ts

@@ -1117,6 +1117,21 @@ export class SceneLoader {
         animatableObjectsInAC.forEach(animatableObjectInAC => {
         animatableObjectsInAC.forEach(animatableObjectInAC => {
             let objectInScene = _targetConverter(animatableObjectInAC);
             let objectInScene = _targetConverter(animatableObjectInAC);
             if (objectInScene != null) {
             if (objectInScene != null) {
+                // Remove old animations with same target property as a new one
+                animatableObjectInAC.animations.forEach((animationInAC: Animation) => {
+                    // Doing treatment on an array for safety measure
+                    let animationsWithSameProperty = objectInScene.animations.filter((animationInScene: Animation) => {
+                        return animationInScene.targetProperty === animationInAC.targetProperty
+                    })
+                    animationsWithSameProperty.forEach((animationWithSameProperty: Animation) => {
+                        const index = objectInScene.animations.indexOf(animationWithSameProperty, 0);
+                        if (index > -1) {
+                            objectInScene.animations.splice(index, 1);
+                        }
+                    })
+                });
+
+                // Append new animations
                 objectInScene.animations = objectInScene.animations.concat(animatableObjectInAC.animations);
                 objectInScene.animations = objectInScene.animations.concat(animatableObjectInAC.animations);
             }
             }
         });
         });