Переглянути джерело

added _scalingDeterminant to fix reversed normals when scaling a bone in world space that uses a right-handed coordinate system

Adam Bowman 8 роки тому
батько
коміт
5a12187d16
1 змінених файлів з 7 додано та 2 видалено
  1. 7 2
      src/Bones/babylon.bone.ts

+ 7 - 2
src/Bones/babylon.bone.ts

@@ -16,6 +16,7 @@
         private _scaleMatrix = Matrix.Identity();
         private _scaleVector = new Vector3(1, 1, 1);
         private _negateScaleChildren = new Vector3(1, 1, 1);
+        private _scalingDeterminant = 1;
         
         constructor(public name: string, skeleton: Skeleton, parentBone: Bone, matrix: Matrix, restPose?: Matrix) {
             super(name, skeleton.getScene());
@@ -34,6 +35,10 @@
             }
 
             this._updateDifferenceMatrix();
+
+            if (this.getAbsoluteTransform().determinant() < 0) {
+                this._scalingDeterminant *= -1;
+            }
         }
 
         // Members
@@ -405,7 +410,7 @@
 					scaleMatrix.multiplyToRef(meshScale, scaleMatrix);
                 }
 				rotMatInv.invert();
-                scaleMatrix.m[0] *= -1;
+                scaleMatrix.m[0] *= this._scalingDeterminant;
                 rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);
             } else {
                 rotMatInv.copyFrom(this.getLocalMatrix());
@@ -418,7 +423,7 @@
                     pscaleMatrix.invert();
                     pscaleMatrix.multiplyToRef(rotMatInv, rotMatInv);
                 } else {
-                    scaleMatrix.m[0] *= -1;
+                    scaleMatrix.m[0] *= this._scalingDeterminant;
                 }
                 rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);
             }