Explorar o código

Merge pull request #4577 from SvenFrankson/master

Flip triangles when calling MergeMeshes on a mesh with negative scaling.
David Catuhe %!s(int64=7) %!d(string=hai) anos
pai
achega
dd55ac23a9
Modificáronse 2 ficheiros con 10 adicións e 0 borrados
  1. 1 0
      dist/preview release/what's new.md
  2. 9 0
      src/Mesh/babylon.mesh.vertexData.ts

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

@@ -85,6 +85,7 @@
 - WindowsMotionController's trackpad field will be updated prior to it's onTrackpadChangedObservable event ([TrevorDev](https://github.com/TrevorDev))
 - VR experience helper's controllers will not fire pointer events when laser's are disabled, instead the camera ray pointer event will be used ([TrevorDev](https://github.com/TrevorDev))
 - Node's setParent(node.parent) will no longer throw an exception when parent is undefined and will behave the same as setParent(null) ([TrevorDev](https://github.com/TrevorDev))
+- Mesh.MergeMeshes flips triangles on meshes with negative scaling ([SvenFrankson](http://svenfrankson.com))
 
 ### Core Engine
 

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

@@ -326,6 +326,7 @@
          * @returns the VertexData 
          */
         public transform(matrix: Matrix): VertexData {
+            var flip = matrix.m[0] * matrix.m[5] * matrix.m[10] < 0;
             var transformed = Vector3.Zero();
             var index: number;
             if (this.positions) {
@@ -369,6 +370,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;
         }