From 9616931f45684567e1acc4db533c05f7c4c70603 Mon Sep 17 00:00:00 2001 From: SamuelRe Date: Mon, 26 Aug 2024 12:22:27 +0200 Subject: [PATCH 1/2] change face logic --- source/xatlas/xatlas.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/xatlas/xatlas.cpp b/source/xatlas/xatlas.cpp index 5c5c57e..ce8a5fa 100644 --- a/source/xatlas/xatlas.cpp +++ b/source/xatlas/xatlas.cpp @@ -9087,13 +9087,14 @@ AddMeshError AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountH uint32_t warningCount = 0; internal::Array triIndices; internal::Triangulator triangulator; + uint32_t currentFaceIndexStart = 0; for (uint32_t face = 0; face < faceCount; face++) { // Decode face indices. const uint32_t faceVertexCount = meshDecl.faceVertexCount ? (uint32_t)meshDecl.faceVertexCount[face] : 3; uint32_t polygon[UINT8_MAX]; for (uint32_t i = 0; i < faceVertexCount; i++) { if (hasIndices) { - polygon[i] = DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, face * faceVertexCount + i); + polygon[i] = DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, currentFaceIndexStart + i); // Check if any index is out of range. if (polygon[i] >= meshDecl.vertexCount) { mesh->~Mesh(); @@ -9101,9 +9102,10 @@ AddMeshError AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountH return AddMeshError::IndexOutOfRange; } } else { - polygon[i] = face * faceVertexCount + i; + polygon[i] = currentFaceIndexStart + i; } } + currentFaceIndexStart += faceVertexCount; // Ignore faces with degenerate or zero length edges. bool ignore = false; for (uint32_t i = 0; i < faceVertexCount; i++) { From 73e5b7301042b0a8a290619e35ce33882ec7b06a Mon Sep 17 00:00:00 2001 From: SamuelRe Date: Mon, 26 Aug 2024 12:23:21 +0200 Subject: [PATCH 2/2] rename --- source/xatlas/xatlas.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/xatlas/xatlas.cpp b/source/xatlas/xatlas.cpp index ce8a5fa..fb78655 100644 --- a/source/xatlas/xatlas.cpp +++ b/source/xatlas/xatlas.cpp @@ -9087,14 +9087,14 @@ AddMeshError AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountH uint32_t warningCount = 0; internal::Array triIndices; internal::Triangulator triangulator; - uint32_t currentFaceIndexStart = 0; + uint32_t currentFaceStartIndex = 0; for (uint32_t face = 0; face < faceCount; face++) { // Decode face indices. const uint32_t faceVertexCount = meshDecl.faceVertexCount ? (uint32_t)meshDecl.faceVertexCount[face] : 3; uint32_t polygon[UINT8_MAX]; for (uint32_t i = 0; i < faceVertexCount; i++) { if (hasIndices) { - polygon[i] = DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, currentFaceIndexStart + i); + polygon[i] = DecodeIndex(meshDecl.indexFormat, meshDecl.indexData, meshDecl.indexOffset, currentFaceStartIndex + i); // Check if any index is out of range. if (polygon[i] >= meshDecl.vertexCount) { mesh->~Mesh(); @@ -9102,10 +9102,10 @@ AddMeshError AddMesh(Atlas *atlas, const MeshDecl &meshDecl, uint32_t meshCountH return AddMeshError::IndexOutOfRange; } } else { - polygon[i] = currentFaceIndexStart + i; + polygon[i] = currentFaceStartIndex + i; } } - currentFaceIndexStart += faceVertexCount; + currentFaceStartIndex += faceVertexCount; // Ignore faces with degenerate or zero length edges. bool ignore = false; for (uint32_t i = 0; i < faceVertexCount; i++) {