浏览代码

Merge pull request #4734 from kcoley/fixNaNData

glTFSerializer: fixed bug in normalize tangent
David Catuhe 7 年之前
父节点
当前提交
85e1a0f6c6
共有 1 个文件被更改,包括 10 次插入8 次删除
  1. 10 8
      serializers/src/glTF/2.0/babylon.glTFUtilities.ts

+ 10 - 8
serializers/src/glTF/2.0/babylon.glTFUtilities.ts

@@ -170,8 +170,8 @@ module BABYLON.GLTF2 {
          * @param quaternion Source quaternion to convert to right-handed
          */
         public static _GetRightHandedQuaternionFromRef(quaternion: Quaternion) {
-             quaternion.x *= -1;
-             quaternion.y *= -1;
+            quaternion.x *= -1;
+            quaternion.y *= -1;
         }
 
         /**
@@ -179,15 +179,17 @@ module BABYLON.GLTF2 {
          * @param quaternion Source quaternion to convert to right-handed
          */
         public static _GetRightHandedQuaternionArrayFromRef(quaternion: number[]) {
-             quaternion[0] *= -1;
-             quaternion[1] *= -1;
+            quaternion[0] *= -1;
+            quaternion[1] *= -1;
         }
 
         public static _NormalizeTangentFromRef(tangent: Vector4) {
-            const length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z + tangent.z);
-            tangent.x /= length;
-            tangent.y /= length;
-            tangent.z /= length;
+            const length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);
+            if (length > 0) {
+                tangent.x /= length;
+                tangent.y /= length;
+                tangent.z /= length;
+            }
         }
     }
 }