فهرست منبع

Merge pull request #1500 from abow/more_bone_work

fixed problem with SkeletonViewer not aligning with skeleton when mes…
David Catuhe 8 سال پیش
والد
کامیت
5e4b85fe2b
3فایلهای تغییر یافته به همراه21 افزوده شده و 16 حذف شده
  1. 6 0
      src/Bones/babylon.bone.ts
  2. 12 0
      src/Bones/babylon.skeleton.ts
  3. 3 16
      src/Debug/babylon.skeletonViewer.ts

+ 6 - 0
src/Bones/babylon.bone.ts

@@ -470,6 +470,12 @@
                 this._matrix.multiplyToRef(this._parent._absoluteTransform, this._absoluteTransform);
             } else {
                 this._absoluteTransform.copyFrom(this._matrix);
+
+                var poseMatrix = this._skeleton.getPoseMatrix();
+
+                if(poseMatrix){
+					this._absoluteTransform.multiplyToRef(poseMatrix, this._absoluteTransform);					
+				}
             }
 
             var children = this.children;

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

@@ -416,5 +416,17 @@
             
         }
 
+        public getPoseMatrix(): Matrix {
+            
+            var poseMatrix: Matrix;
+            
+            if(this._meshesWithPoseMatrix.length > 0){
+                poseMatrix = this._meshesWithPoseMatrix[0].getPoseMatrix();
+            }
+
+            return poseMatrix;
+
+        }
+
     }
 }

+ 3 - 16
src/Debug/babylon.skeletonViewer.ts

@@ -90,15 +90,15 @@
                     points = [Vector3.Zero(), Vector3.Zero()];
                     this._debugLines[boneNum] = points;
                 }
-                this._getBonePosition(points[0], childBone, meshMat);
-                this._getBonePosition(points[1], parentBone, meshMat);
+                childBone.getAbsolutePositionToRef(this.mesh, points[0]);
+				parentBone.getAbsolutePositionToRef(this.mesh, points[1]);
                 boneNum++;
             }
         }
 
         public update() {
             if (this.autoUpdateBonesMatrices) {
-                this._updateBoneMatrix(this.skeleton.bones[0]);
+                this.skeleton.computeAbsoluteTransforms();
             }
 
             if (this.skeleton.bones[0].length === undefined) {
@@ -116,19 +116,6 @@
             this._debugMesh.color = this.color;
         }
 
-        private _updateBoneMatrix(bone: Bone) {
-            if (bone.getParent()) {
-                bone.getLocalMatrix().multiplyToRef(bone.getParent().getAbsoluteTransform(), bone.getAbsoluteTransform());
-            }
-
-            var children = bone.children;
-            var len = children.length;
-
-            for (var i = 0; i < len; i++) {
-                this._updateBoneMatrix(children[i]);
-            }
-        }
-
         public dispose() {
             if (this._debugMesh) {
                 this.isEnabled = false;