Przeglądaj źródła

Fix Animation Circular dep

sebastien 6 lat temu
rodzic
commit
8795f51d2f

+ 4 - 9
src/Animations/animation.ts

@@ -10,6 +10,7 @@ import { Scene } from "scene";
 import { IAnimatable } from "Tools/tools";
 import { Node } from "node";
 import { Texture } from "Materials/Textures/texture";
+import { SerializationHelper } from "Tools/decorators";
 
     /**
      * Represents the range of an animation
@@ -1233,15 +1234,9 @@ import { Texture } from "Materials/Textures/texture";
          * @param destination Target to store the animations
          */
         public static AppendSerializedAnimations(source: IAnimatable, destination: any): void {
-            if (source.animations) {
-                destination.animations = [];
-                for (var animationIndex = 0; animationIndex < source.animations.length; animationIndex++) {
-                    var animation = source.animations[animationIndex];
-
-                    destination.animations.push(animation.serialize());
-                }
-            }
+            SerializationHelper.AppendSerializedAnimations(source, destination);
         }
     }
 
-    Texture._AnimationParser = Animation.Parse;
+    Texture._AnimationParser = Animation.Parse;
+    Node._AnimationRangeFactory = (name: string, from: number, to: number) => new AnimationRange(name, from, to);

+ 1 - 1
src/Cameras/camera.ts

@@ -1131,7 +1131,7 @@ declare type TargetCamera = import("./targetCamera").TargetCamera;
                 this.inputs.serialize(serializationObject);
             }
             // Animations
-            Animation.AppendSerializedAnimations(this, serializationObject);
+            SerializationHelper.AppendSerializedAnimations(this, serializationObject);
             serializationObject.ranges = this.serializeAnimationRanges();
 
             return serializationObject;

+ 1 - 1
src/Lights/light.ts

@@ -549,7 +549,7 @@ import { IShadowGenerator } from "./Shadows/shadowGenerator";
             }
 
             // Animations
-            Animation.AppendSerializedAnimations(this, serializationObject);
+            SerializationHelper.AppendSerializedAnimations(this, serializationObject);
             serializationObject.ranges = this.serializeAnimationRanges();
 
             return serializationObject;

+ 6 - 4
src/Materials/Textures/baseTexture.ts

@@ -1,6 +1,6 @@
 import { serialize, SerializationHelper } from "Tools/decorators";
 import { Observer, Observable } from "Tools/observable";
-import { Tools } from "Tools/tools";
+import { Tools, IAnimatable } from "Tools/tools";
 import { CubeMapToSphericalPolynomialTools } from "Tools/HDR/cubemapToSphericalPolynomial";
 import { Nullable } from "types";
 import { Scene } from "scene";
@@ -8,16 +8,18 @@ import { Matrix, Size, ISize } from "Math/math";
 import { SphericalPolynomial } from "Math/sphericalPolynomial";
 import { Engine } from "Engine/engine";
 import { InternalTexture } from "Materials/Textures/internalTexture";
-import { Animation } from "Animations/animation";
 import { _TimeToken } from "Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "States";
 import { Constants } from "Engine/constants";
+
+declare type Animation = import("Animations/animation").Animation;
+
     /**
      * Base class of all the textures in babylon.
      * It groups all the common properties the materials, post process, lights... might need
      * in order to make a correct use of the texture.
      */
-    export class BaseTexture {
+    export class BaseTexture implements IAnimatable {
         /**
          * Default anisotropic filtering level for the application.
          * It is set to 4 as a good tradeoff between perf and quality.
@@ -621,7 +623,7 @@ import { Constants } from "Engine/constants";
             var serializationObject = SerializationHelper.Serialize(this);
 
             // Animations
-            Animation.AppendSerializedAnimations(this, serializationObject);
+            SerializationHelper.AppendSerializedAnimations(this, serializationObject);
 
             return serializationObject;
         }

+ 3 - 2
src/Mesh/mesh.ts

@@ -23,6 +23,7 @@ import { Skeleton } from "Bones/skeleton";
 import { MorphTargetManager } from "Morph/morphTargetManager";
 import { PhysicsImpostor } from "Physics/physicsImpostor";
 import { Constants } from "Engine/constants";
+import { SerializationHelper } from "Tools/decorators";
 
 declare type LinesMesh = import("./linesMesh").LinesMesh;
 declare type InstancedMesh = import("./instancedMesh").InstancedMesh;
@@ -2554,14 +2555,14 @@ declare type GroundMesh = import("./groundMesh").GroundMesh;
                 serializationObject.instances.push(serializationInstance);
 
                 // Animations
-                Animation.AppendSerializedAnimations(instance, serializationInstance);
+                SerializationHelper.AppendSerializedAnimations(instance, serializationInstance);
                 serializationInstance.ranges = instance.serializeAnimationRanges();
             }
 
             //
 
             // Animations
-            Animation.AppendSerializedAnimations(this, serializationObject);
+            SerializationHelper.AppendSerializedAnimations(this, serializationObject);
             serializationObject.ranges = this.serializeAnimationRanges();
 
             // Layer mask

+ 2 - 1
src/Particles/particleSystem.ts

@@ -22,6 +22,7 @@ import { BaseParticleSystem } from "./baseParticleSystem";
 import { Particle } from "./particle";
 import { SubEmitter, SubEmitterType } from "./subEmitter";
 import { Constants } from "Engine/constants";
+import { SerializationHelper } from "Tools/decorators";
 
     /**
      * This represents a particle system in Babylon.
@@ -2047,7 +2048,7 @@ import { Constants } from "Engine/constants";
             }
 
             // Animations
-            Animation.AppendSerializedAnimations(particleSystem, serializationObject);
+            SerializationHelper.AppendSerializedAnimations(particleSystem, serializationObject);
             serializationObject.beginAnimationOnStart = particleSystem.beginAnimationOnStart;
             serializationObject.beginAnimationFrom = particleSystem.beginAnimationFrom;
             serializationObject.beginAnimationTo = particleSystem.beginAnimationTo;

+ 17 - 0
src/Tools/decorators.ts

@@ -9,6 +9,7 @@ declare type ImageProcessingConfiguration = import("Materials/imageProcessingCon
 declare type FresnelParameters = import("Materials/fresnelParameters").FresnelParameters;
 declare type ColorCurves = import("Materials/colorCurves").ColorCurves;
 declare type BaseTexture = import("Materials/Textures/baseTexture").BaseTexture;
+declare type IAnimatable = import("Tools/tools").IAnimatable;
 
     var __decoratorInitialStore = {};
     var __mergedStore = {};
@@ -227,6 +228,22 @@ declare type BaseTexture = import("Materials/Textures/baseTexture").BaseTexture;
         }
 
         /**
+         * Appends the serialized animations from the source animations
+         * @param source Source containing the animations
+         * @param destination Target to store the animations
+         */
+        public static AppendSerializedAnimations(source: IAnimatable, destination: any): void {
+            if (source.animations) {
+                destination.animations = [];
+                for (var animationIndex = 0; animationIndex < source.animations.length; animationIndex++) {
+                    var animation = source.animations[animationIndex];
+
+                    destination.animations.push(animation.serialize());
+                }
+            }
+        }
+
+        /**
          * Static function used to serialized a specific entity
          * @param entity defines the entity to serialize
          * @param serializationObject defines the optional target obecjt where serialization data will be stored

+ 2 - 2
src/Tools/sceneSerializer.ts

@@ -1,12 +1,12 @@
 import { Geometry, BoxGeometry, SphereGeometry, CylinderGeometry, TorusGeometry, GroundGeometry, TorusKnotGeometry, _PrimitiveGeometry } from "Mesh/geometry";
 import { Mesh } from "Mesh/mesh";
 import { Plane } from "Math/math";
-import { Animation } from "Animations/animation";
 import { Constants } from "Engine/constants";
 import { MultiMaterial } from "Materials/multiMaterial";
 import { Material } from "Materials/material";
 import { Scene } from "scene";
 import { Light } from "Lights/light";
+import { SerializationHelper } from "./decorators";
 
     var serializedGeometries: Geometry[] = [];
     var serializeGeometry = (geometry: Geometry, serializationGeometries: any): any => {
@@ -216,7 +216,7 @@ import { Light } from "Lights/light";
             }
 
             // Animations
-            Animation.AppendSerializedAnimations(scene, serializationObject);
+            SerializationHelper.AppendSerializedAnimations(scene, serializationObject);
 
             // Materials
             serializationObject.materials = [];

+ 11 - 4
src/node.ts

@@ -1,6 +1,3 @@
-import { Animatable } from "Animations/animatable";
-import { AnimationPropertiesOverride } from "Animations/animationPropertiesOverride";
-import { Animation, AnimationRange } from "Animations/animation";
 import { Scene } from "scene";
 import { Nullable } from "types";
 import { Matrix } from "Math/math";
@@ -9,6 +6,11 @@ import { IBehaviorAware, Behavior } from "Behaviors/behavior";
 import { serialize } from "Tools/decorators";
 import { Observable, Observer } from "Tools/observable";
 
+declare type Animatable = import("Animations/animatable").Animatable;
+declare type AnimationPropertiesOverride = import("Animations/animationPropertiesOverride").AnimationPropertiesOverride;
+declare type Animation = import("Animations/animation").Animation;
+declare type AnimationRange = import("Animations/animation").AnimationRange;
+
 declare type AbstractMesh = import("Mesh/abstractMesh").AbstractMesh;
 
     /**
@@ -20,6 +22,11 @@ declare type AbstractMesh = import("Mesh/abstractMesh").AbstractMesh;
      * Node is the basic class for all scene objects (Mesh, Light, Camera.)
      */
     export class Node implements IBehaviorAware<Node> {
+        /** @hidden */
+        public static _AnimationRangeFactory = (name: string, from: number, to: number): AnimationRange => {
+            throw "AnimationRange needs to be imported from animation before being created.";
+        }
+
         private static _NodeConstructors: { [key: string]: any } = {};
 
         /**
@@ -597,7 +604,7 @@ declare type AbstractMesh = import("Mesh/abstractMesh").AbstractMesh;
         public createAnimationRange(name: string, from: number, to: number): void {
             // check name not already in use
             if (!this._ranges[name]) {
-                this._ranges[name] = new AnimationRange(name, from, to);
+                this._ranges[name] = Node._AnimationRangeFactory(name, from, to);
                 for (var i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {
                     if (this.animations[i]) {
                         this.animations[i].createRange(name, from, to);