Просмотр исходного кода

Flip triangles when mesh has a negative scale.

Taton Sven 7 лет назад
Родитель
Сommit
6133141122
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      src/Mesh/babylon.mesh.vertexData.ts

+ 11 - 0
src/Mesh/babylon.mesh.vertexData.ts

@@ -326,6 +326,9 @@
          * @returns the VertexData 
          */
         public transform(matrix: Matrix): VertexData {
+            var scaling = Vector3.One();
+            matrix.decompose(scaling, BABYLON.Tmp.Quaternion[0], BABYLON.Tmp.Vector3[0]);
+            var flip = scaling.x * scaling.y * scaling.z < 0;
             var transformed = Vector3.Zero();
             var index: number;
             if (this.positions) {
@@ -369,6 +372,14 @@
                 }
             }
 
+            if (flip && this.indices) {
+                for (index = 0; index < this.indices!.length; index += 3) {
+                    let tmp = this.indices[index + 1];
+                    this.indices[index + 1] = this.indices[index + 2];
+                    this.indices[index + 2] = tmp;
+                }
+            }
+
             return this;
         }