Browse Source

Move multiple animation target support into core

Gary Hsu 7 năm trước cách đây
mục cha
commit
94a5c66e14

+ 4 - 9
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -920,13 +920,12 @@ module BABYLON.GLTF2 {
                             outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
                         })));
 
-                        const multiTarget = new AnimationMultiTarget();
+                        const morphTargets = new Array<any>();
                         this._forEachPrimitive(targetNode, babylonMesh => {
-                            const morphTarget = babylonMesh.morphTargetManager!.getTarget(targetIndex);
-                            multiTarget.subTargets.push(morphTarget);
+                            morphTargets.push(babylonMesh.morphTargetManager!.getTarget(targetIndex));
                         });
 
-                        babylonAnimationGroup.addTargetedAnimation(babylonAnimation, multiTarget);
+                        babylonAnimationGroup.addTargetedAnimation(babylonAnimation, morphTargets);
                     }
                 }
                 else {
@@ -935,11 +934,7 @@ module BABYLON.GLTF2 {
                     babylonAnimation.setKeys(keys);
 
                     if (targetNode._babylonAnimationTargets) {
-                        const multiTarget = new AnimationMultiTarget();
-                        for (const target of targetNode._babylonAnimationTargets) {
-                            multiTarget.subTargets.push(target);
-                        }
-                        babylonAnimationGroup.addTargetedAnimation(babylonAnimation, multiTarget);
+                        babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonAnimationTargets);
                     }
                 }
             });

+ 0 - 28
loaders/src/glTF/2.0/babylon.glTFLoaderUtilities.ts

@@ -14,32 +14,4 @@ module BABYLON.GLTF2 {
             }
         }
     }
-
-    export class AnimationMultiTarget {
-        public subTargets = new Array<any>();
-
-        public set position(value: Vector3) {
-            for (const subTarget of this.subTargets) {
-                subTarget.position = value;
-            }
-        }
-
-        public set rotationQuaternion(value: Quaternion) {
-            for (const subTarget of this.subTargets) {
-                subTarget.rotationQuaternion = value;
-            }
-        }
-
-        public set scaling(value: Vector3) {
-            for (const subTarget of this.subTargets) {
-                subTarget.scaling = value;
-            }
-        }
-
-        public set influence(value: number) {
-            for (const subTarget of this.subTargets) {
-                subTarget.influence = value;
-            }
-        }
-    }
 }

+ 17 - 6
src/Animations/babylon.runtimeAnimation.ts

@@ -242,6 +242,17 @@
          * @param weight defines the weight to apply to this value
          */
         public setValue(currentValue: any, weight = 1.0): void {
+            if (this._target instanceof Array) {
+                for (const target of this._target) {
+                    this._setValue(target, currentValue, weight);
+                }
+            }
+            else {
+                this._setValue(this._target, currentValue, weight);
+            }
+        }
+
+        private _setValue(target: any, currentValue: any, weight = 1.0): void {
             // Set value
             var path: any;
             var destination: any;
@@ -249,7 +260,7 @@
             let targetPropertyPath = this._animation.targetPropertyPath
 
             if (targetPropertyPath.length > 1) {
-                var property = this._target[targetPropertyPath[0]];
+                var property = target[targetPropertyPath[0]];
 
                 for (var index = 1; index < targetPropertyPath.length - 1; index++) {
                     property = property[targetPropertyPath[index]];
@@ -259,7 +270,7 @@
                 destination = property;
             } else {
                 path = targetPropertyPath[0];
-                destination = this._target;
+                destination = target;
             }
 
             this._targetPath = path;
@@ -267,8 +278,8 @@
             this._weight = weight;
 
             // Blending
-            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;
+            let enableBlending = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.enableBlending : this._animation.enableBlending;
+            let blendingSpeed = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;
             
             if (enableBlending && this._blendingFactor <= 1.0) {
                 if (!this._originalBlendValue) {
@@ -337,8 +348,8 @@
                 destination[path] = this._currentValue;
             }
 
-            if (this._target.markAsDirty) {
-                this._target.markAsDirty(this._animation.targetProperty);
+            if (target.markAsDirty) {
+                target.markAsDirty(this._animation.targetProperty);
             }
         }