Ver código fonte

Fix for babylon -> .babylon scene serialization bug where animation groups arent serialized properly. Added serializer for TargetAnimation and AnimationGroup

Nicholas Barlow 6 anos atrás
pai
commit
a21a7fdc5d
3 arquivos alterados com 47 adições e 4 exclusões
  1. 35 4
      src/Animations/animationGroup.ts
  2. 10 0
      src/Misc/decorators.ts
  3. 2 0
      src/Misc/tools.ts

+ 35 - 4
src/Animations/animationGroup.ts

@@ -21,6 +21,19 @@ export class TargetedAnimation {
      * Target to animate
      */
     public target: any;
+
+    public constructor(animation: Animation, target: any){
+        this.animation = animation;
+        this.target = target;
+    }
+
+    public serialize(): any {
+        var serializationObject: any = {};
+        serializationObject.animation = this.animation.serialize();
+        serializationObject.targetId = this.target.id;
+
+        return serializationObject;
+    }
 }
 
 /**
@@ -177,10 +190,7 @@ 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 (animation, target);
 
         let keys = animation.getKeys();
         if (this._from > keys[0].frame) {
@@ -486,6 +496,27 @@ 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/decorators.ts

@@ -247,6 +247,16 @@ export class SerializationHelper {
                 destination.animations.push(animation.serialize());
             }
         }
+
+        if (source.animationGroups)
+        {
+            destination.animationGroups = [];
+            for (var animationGroupIndex = 0; animationGroupIndex < source.animationGroups.length; animationGroupIndex++) {
+                var animationGroup = source.animationGroups[animationGroupIndex];
+
+                destination.animationGroups.push(animationGroup.serialize());
+            }
+        }
     }
 
     /**

+ 2 - 0
src/Misc/tools.ts

@@ -16,6 +16,7 @@ import { WebRequest } from './webRequest';
 declare type Camera = import("../Cameras/camera").Camera;
 declare type Engine = import("../Engines/engine").Engine;
 declare type Animation = import("../Animations/animation").Animation;
+declare type AnimationGroup = import("../Animations/animationGroup").AnimationGroup;
 
 /**
  * Interface for any object that can request an animation frame
@@ -45,6 +46,7 @@ export interface IAnimatable {
      * Array of animations
      */
     animations: Nullable<Array<Animation>>;
+    animationGroups: Nullable<Array<AnimationGroup>>;
 }
 
 /** Interface used by value gradients (color, factor, ...) */