ソースを参照

Introduced animationPropertiesOverride

David Catuhe 7 年 前
コミット
a08d1de034

+ 1 - 0
Tools/Gulp/config.json

@@ -385,6 +385,7 @@
         },
         "animations": {
             "files": [
+                "../../src/Animations/babylon.animationPropertiesOverride.js",
                 "../../src/Animations/babylon.animation.js",
                 "../../src/Animations/babylon.animationGroup.js",
                 "../../src/Animations/babylon.runtimeAnimation.js",

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

@@ -19,6 +19,7 @@
 ## Updates
 
 - Tons of functions and classes received the code comments they deserved (All the community)
+- New `AnimationPropertiesOverride` class used to simplify setting animation properties on child animations. [Documentation](http://doc.babylonjs.com/babylon101/animations#overriding-properties) ([deltakosh](https://github.com/deltakosh))
 - New `Texture.UseSerializedUrlIfAny` static property to let textures serialize complete URL instead of using side by side loading ([deltakosh](https://github.com/deltakosh))
 - Added `particleSystem.reset()` to clear a particle system ([deltakosh](https://github.com/deltakosh))
 - Added support for all RGBA orders (BGR, RGB, etc..) for the DDS loader ([deltakosh](https://github.com/deltakosh))

+ 21 - 0
src/Animations/babylon.animationPropertiesOverride.ts

@@ -0,0 +1,21 @@
+module BABYLON {
+    /**
+     * Class used to override all child animations of a given target
+     */
+    export class AnimationPropertiesOverride {
+        /**
+         * Gets or sets a value indicating if animation blending must be used
+         */
+        public enableBlending = false;
+
+        /**
+         * Gets or sets the blending speed to use when enableBlending is true
+         */
+        public blendingSpeed = 0.01;
+
+        /**
+         * Gets or sets the default loop mode to use
+         */
+        public loopMode = Animation.ANIMATIONLOOPMODE_CYCLE;
+    }
+}

+ 16 - 5
src/Animations/babylon.runtimeAnimation.ts

@@ -197,7 +197,10 @@
             }
 
             // Blending
-            if (this._animation.enableBlending && this._blendingFactor <= 1.0) {
+            let enableBlending = this._target && this._target.animationPropertiesOverride ? this._target.animationPropertiesOverride.enableBlending : this._animation.enableBlending;
+            let blendingSpeed = this._target && this._target.animationPropertiesOverride ? this._target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;
+            
+            if (enableBlending && this._blendingFactor <= 1.0) {
                 if (!this._originalBlendValue) {
                     if (destination[path].clone) {
                         this._originalBlendValue = destination[path].clone();
@@ -219,7 +222,7 @@
                 } else { // Direct value
                     destination[path] = this._originalBlendValue * (1.0 - this._blendingFactor) + this._blendingFactor * currentValue;
                 }
-                this._blendingFactor += this._animation.blendingSpeed;
+                this._blendingFactor += blendingSpeed;
             } else {
                 destination[path] = currentValue;
             }
@@ -229,6 +232,14 @@
             }
         }
 
+        private _getCorrectLoopMode(): number | undefined {
+            if ( this._target && this._target.animationPropertiesOverride) {
+                return this._target.loopMode;
+            }
+
+            return this._animation.loopMode;
+        }
+
         public goToFrame(frame: number): void {
             let keys = this._animation.getKeys();
 
@@ -238,7 +249,7 @@
                 frame = keys[keys.length - 1].frame;
             }
 
-            var currentValue = this._interpolate(frame, 0, this._animation.loopMode);
+            var currentValue = this._interpolate(frame, 0, this._getCorrectLoopMode());
 
             this.setValue(currentValue);
         }
@@ -301,7 +312,7 @@
             } else {
                 // Get max value if required
 
-                if (this._animation.loopMode !== Animation.ANIMATIONLOOPMODE_CYCLE) {
+                if (this._getCorrectLoopMode() !== Animation.ANIMATIONLOOPMODE_CYCLE) {
 
                     var keyOffset = to.toString() + from.toString();
                     if (!this._offsetsCache[keyOffset]) {
@@ -371,7 +382,7 @@
             // Compute value
             var repeatCount = (ratio / range) >> 0;
             var currentFrame = returnValue ? from + ratio % range : to;
-            var currentValue = this._interpolate(currentFrame, repeatCount, this._animation.loopMode, offsetValue, highLimitValue);
+            var currentValue = this._interpolate(currentFrame, repeatCount, this._getCorrectLoopMode(), offsetValue, highLimitValue);
 
             // Set value
             this.setValue(currentValue);

+ 5 - 0
src/Bones/babylon.skeleton.ts

@@ -23,6 +23,11 @@
          */
         public doNotSerialize = false;        
 
+        /**
+         * Gets or sets the animation properties override
+         */
+        public animationPropertiesOverride: AnimationPropertiesOverride;        
+
         // Events
         /**
          * An event triggered before computing the skeleton's matrices

+ 5 - 0
src/babylon.node.ts

@@ -70,6 +70,11 @@
         private _children: Node[];
 
         /**
+         * Gets or sets the animation properties override
+         */
+        public animationPropertiesOverride: AnimationPropertiesOverride;
+
+        /**
          * Gets a boolean indicating if the node has been disposed
          * @returns true if the node was disposed
          */