Преглед изворни кода

deserialize morph target animations in animation groups

Kacey Coley пре 6 година
родитељ
комит
776bd21f6c
3 измењених фајлова са 45 додато и 1 уклоњено
  1. 1 0
      dist/preview release/what's new.md
  2. 20 0
      src/Morph/babylon.morphTarget.ts
  3. 24 1
      src/babylon.scene.ts

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

@@ -52,6 +52,7 @@
 - Make sure that `Material.markAsDirty` and all the `markXXXDirty` methods early out when `scene.blockMaterialDirtyMechanism` is true. ([barroij](https://github.com/barroij))
 - Add updateUpVectorFromRotation to target camera to allow the up vector to be computed from rotation ([TrevorDev](https://github.com/TrevorDev))
 - Added opacity texture support to `GridMaterial` ([Deltakosh](https://github.com/deltakosh))
+- Added support for deserializing morph target animations in animation groups
 
 ### glTF Loader
 

+ 20 - 0
src/Morph/babylon.morphTarget.ts

@@ -43,6 +43,12 @@ module BABYLON {
             }
         }
 
+        /**
+         * Gets or sets the id of the morph Target
+         */
+        @serialize()
+        public id: string;
+
         private _animationPropertiesOverride: Nullable<AnimationPropertiesOverride> = null;
 
         /**
@@ -169,6 +175,9 @@ module BABYLON {
             serializationObject.influence = this.influence;
 
             serializationObject.positions = Array.prototype.slice.call(this.getPositions());
+            if (this.id != null) {
+                serializationObject.id = this.id;
+            }
             if (this.hasNormals) {
                 serializationObject.normals = Array.prototype.slice.call(this.getNormals());
             }
@@ -182,6 +191,14 @@ module BABYLON {
             return serializationObject;
         }
 
+        /**
+         * Returns the string "MorphTarget"
+         * @returns "MorphTarget"
+         */
+        public getClassName(): string {
+            return "MorphTarget";
+        }
+
         // Statics
 
         /**
@@ -194,6 +211,9 @@ module BABYLON {
 
             result.setPositions(serializationObject.positions);
 
+            if (serializationObject.id) {
+                result.id = serializationObject.id;
+            }
             if (serializationObject.normals) {
                 result.setNormals(serializationObject.normals);
             }

+ 24 - 1
src/babylon.scene.ts

@@ -3803,7 +3803,7 @@ module BABYLON {
          * @param id defines the id to search for
          * @return the found node or null if not found at all
          */
-        public getNodeByID(id: string): Nullable<Node> {
+        public getNodeByID(id: string): Nullable<Node | MorphTarget> {
             const mesh = this.getMeshByID(id);
             if (mesh) {
                 return mesh;
@@ -3829,6 +3829,11 @@ module BABYLON {
                 return bone;
             }
 
+            const morphTarget = this.getMorphTargetByID(id);
+            if (morphTarget) {
+                return morphTarget;
+            }
+
             return null;
         }
 
@@ -3957,6 +3962,24 @@ module BABYLON {
         }
 
         /**
+         * Gets a morph target using a given id (if many are found, this function will pick the last one)
+         * @param id defines the id to search for
+         * @return the found morph target or null if not found at all.
+         */
+        public getMorphTargetByID(id: string): Nullable<MorphTarget> {
+            for (let managerIndex = 0; managerIndex < this.morphTargetManagers.length; ++managerIndex) {
+                const morphTargetManager = this.morphTargetManagers[managerIndex];
+                for (let index = 0; index < morphTargetManager.numTargets; ++index) {
+                    const target = morphTargetManager.getTarget(index);
+                    if (target.id === id) {
+                        return target;
+                    }
+                }
+            }
+            return null;
+        }
+
+        /**
          * Gets a boolean indicating if the given mesh is active
          * @param mesh defines the mesh to look for
          * @returns true if the mesh is in the active list