Explorar o código

Merge pull request #9322 from aWeirdo/patch-1

Update meshSimplification.ts
David Catuhe %!s(int64=4) %!d(string=hai) anos
pai
achega
0e619b7d82
Modificáronse 2 ficheiros con 12 adicións e 10 borrados
  1. 2 1
      dist/preview release/what's new.md
  2. 10 9
      src/Meshes/meshSimplification.ts

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

@@ -364,6 +364,7 @@
 - Fixed bug in `Mesh.IncreaseVertices` assuming null value if a property didn't exist. ([aWeirdo](https://github.com/aWeirdo))
 - Fix issue when taking a screenshot with multi-cameras using method `CreateScreenshotUsingRenderTarget` ([#9201](https://github.com/BabylonJS/Babylon.js/issues/9201)) ([gabrielheming](https://github.com/gabrielheming))
 - Fix inTangent in animationGroup ([dad72](https://github.com/dad72))
+- Fixed bug in `QuadraticErrorSimplification` not correctly optimizing mesh. ([aWeirdo](https://github.com/aWeirdo))
 
 ## Breaking changes
 
@@ -378,4 +379,4 @@
 - `smoothstep` in NME is now taking any type of parameters for its `value` input. If you use generated code from the NME ("Generate code" button), you may have to move the smoothstep output connection AFTER the input connections ([Popov72](https://github.com/Popov72))
 - `SoundTrack.RemoveSound` and `SoundTrack.AddSound` were renamed to `SoundTrack.removeSound` and `SoundTrack.addSound` ([Deltakosh](https://github.com/deltakosh))
 - `PolygonPoints.add` no longer filters out points that are close to the first point ([bghgary](https://github.com/bghgary))
-- `Material` created with matching names now have auto-incrementing IDs.
+- `Material` created with matching names now have auto-incrementing IDs.

+ 10 - 9
src/Meshes/meshSimplification.ts

@@ -473,7 +473,7 @@ export class QuadraticErrorSimplification implements ISimplifier {
         var findInVertices = (positionToSearch: Vector3) => {
             if (optimizeMesh) {
                 for (var ii = 0; ii < this.vertices.length; ++ii) {
-                    if (this.vertices[ii].position.equals(positionToSearch)) {
+                    if (this.vertices[ii].position.equalsWithEpsilon(positionToSearch, 0.0001)) {
                         return this.vertices[ii];
                     }
                 }
@@ -582,21 +582,20 @@ export class QuadraticErrorSimplification implements ISimplifier {
             vertex.id = vertexCount;
             if (vertex.triangleCount) {
                 vertex.originalOffsets.forEach((originalOffset) => {
-                    if (!normalData) {
-                        return;
-                    }
 
                     newPositionData.push(vertex.position.x);
                     newPositionData.push(vertex.position.y);
                     newPositionData.push(vertex.position.z);
-                    newNormalData.push(normalData[originalOffset * 3]);
-                    newNormalData.push(normalData[(originalOffset * 3) + 1]);
-                    newNormalData.push(normalData[(originalOffset * 3) + 2]);
+
+                    if (normalData && normalData.length) {
+                        newNormalData.push(normalData[originalOffset * 3]);
+                        newNormalData.push(normalData[(originalOffset * 3) + 1]);
+                        newNormalData.push(normalData[(originalOffset * 3) + 2]);
+                    }
                     if (uvs && uvs.length) {
                         newUVsData.push(uvs[(originalOffset * 2)]);
                         newUVsData.push(uvs[(originalOffset * 2) + 1]);
                     }
-
                     if (colorsData && colorsData.length) {
                         newColorsData.push(colorsData[(originalOffset * 4)]);
                         newColorsData.push(colorsData[(originalOffset * 4) + 1]);
@@ -630,7 +629,9 @@ export class QuadraticErrorSimplification implements ISimplifier {
 
         this._reconstructedMesh.setIndices(newIndicesArray);
         this._reconstructedMesh.setVerticesData(VertexBuffer.PositionKind, newPositionData);
-        this._reconstructedMesh.setVerticesData(VertexBuffer.NormalKind, newNormalData);
+        if (newNormalData.length > 0) {
+            this._reconstructedMesh.setVerticesData(VertexBuffer.NormalKind, newNormalData);
+        }
         if (newUVsData.length > 0) {
             this._reconstructedMesh.setVerticesData(VertexBuffer.UVKind, newUVsData);
         }