Browse Source

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 6 years ago
parent
commit
8768aea211
3 changed files with 42 additions and 4 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 31 4
      src/Animations/animationGroup.ts
  3. 10 0
      src/Misc/sceneSerializer.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -20,6 +20,7 @@
 - Added `ShadowGenerator.onAfterShadowMapRenderObservable` and `ShadowGenerator.onAfterShadowMapMeshRenderObservable` ([Deltakosh](https://github.com/deltakosh/))
 
 ## Bug fixes
+- Added support for `AnimationGroup` serialization ([Drigax](https://github.com/drigax/))
 - Removing assetContainer from scene will also remove gui layers ([TrevorDev](https://github.com/TrevorDev))
 
 ## Breaking changes

+ 31 - 4
src/Animations/animationGroup.ts

@@ -21,6 +21,14 @@ export class TargetedAnimation {
      * Target to animate
      */
     public target: any;
+
+    public serialize(): any {
+        var serializationObject: any = {};
+        serializationObject.animation = this.animation.serialize();
+        serializationObject.targetId = this.target.id;
+
+        return serializationObject;
+    }
 }
 
 /**
@@ -177,10 +185,9 @@ export class AnimationGroup implements IDisposable {
      * @returns the TargetedAnimation object
      */
     public addTargetedAnimation(animation: Animation, target: any): TargetedAnimation {
-        let targetedAnimation = {
-            animation: animation,
-            target: target
-        };
+        let targetedAnimation = new TargetedAnimation ();
+        targetedAnimation.animation = animation;
+        targetedAnimation.target = target;
 
         let keys = animation.getKeys();
         if (this._from > keys[0].frame) {
@@ -486,6 +493,26 @@ export class AnimationGroup implements IDisposable {
         return newGroup;
     }
 
+    /**
+     * Serializes the animationGroup to an object
+     * @returns Serialized object
+     */
+    public serialize(): any {
+        var serializationObject: any = {};
+
+        serializationObject.name = this.name;
+        serializationObject.from = this.from;
+        serializationObject.to = this.to;
+        serializationObject.targetedAnimations = []
+        for(var targetedAnimationIndex = 0; targetedAnimationIndex < this.targetedAnimations.length; targetedAnimationIndex++)
+        {
+            var targetedAnimation = this.targetedAnimations[targetedAnimationIndex];
+            serializationObject.targetedAnimations[targetedAnimationIndex] = targetedAnimation.serialize();
+        }
+
+        return serializationObject;
+    }
+
     // Statics
     /**
      * Returns a new AnimationGroup object parsed from the source provided.

+ 10 - 0
src/Misc/sceneSerializer.ts

@@ -190,6 +190,16 @@ export class SceneSerializer {
         // Animations
         SerializationHelper.AppendSerializedAnimations(scene, serializationObject);
 
+        // Animation Groups
+        if(scene.animationGroups && scene.animationGroups.length > 0){
+            serializationObject.animationGroups = [];
+            for (var animationGroupIndex = 0; animationGroupIndex < scene.animationGroups.length; animationGroupIndex++) {
+                var animationGroup = scene.animationGroups[animationGroupIndex];
+
+                serializationObject.animationGroups.push(animationGroup.serialize());
+            }
+        }
+
         // Reflection probes
         if (scene.reflectionProbes && scene.reflectionProbes.length > 0) {
             serializationObject.reflectionProbes = [];