From 2a602a031f8a2963f7f3e3bb0ddc7ba4cd0f3e0e Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Sat, 15 Oct 2022 22:52:10 +1100 Subject: [PATCH] Fix triangles crossing over in tube mesh builder --- dust3d/mesh/tube_mesh_builder.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dust3d/mesh/tube_mesh_builder.cc b/dust3d/mesh/tube_mesh_builder.cc index 6411613d..f49ebdb4 100644 --- a/dust3d/mesh/tube_mesh_builder.cc +++ b/dust3d/mesh/tube_mesh_builder.cc @@ -144,12 +144,27 @@ void TubeMeshBuilder::build() size_t i = (j + cutFaceIndices.size() - 1) % cutFaceIndices.size(); const auto &cutFaceI = cutFaceIndices[i]; const auto &cutFaceJ = cutFaceIndices[j]; - for (size_t m = 0; m < cutFaceI.size(); ++m) { + size_t halfSize = cutFaceI.size() / 2; + for (size_t m = 0; m < halfSize; ++m) { size_t n = (m + 1) % cutFaceI.size(); + // KEEP QUAD ORDER TO MAKE THE TRIANLES NO CROSSING OVER ON EACH SIDE (1) + // The following quad vertices should follow the order strictly, + // This will group two points from I, and one point from J as a triangle in the later quad to triangles processing. + // If not follow this order, the front triangle and back triangle maybe cross over because of not be parallel. m_generatedFaces.emplace_back(std::vector { cutFaceI[m], cutFaceI[n], cutFaceJ[n], cutFaceJ[m] }); } + for (size_t m = halfSize; m < cutFaceI.size(); ++m) { + size_t n = (m + 1) % cutFaceI.size(); + // KEEP QUAD ORDER TO MAKE THE TRIANLES NO CROSSING OVER ON EACH SIDE (2) + // The following quad vertices should follow the order strictly, + // This will group two points from I, and one point from J as a triangle in the later quad to triangles processing. + // If not follow this order, the front triangle and back triangle maybe cross over because of not be parallel. + m_generatedFaces.emplace_back(std::vector { + cutFaceJ[m], cutFaceI[m], cutFaceI[n], cutFaceJ[n] + }); + } } if (!m_isCircle) { m_generatedFaces.emplace_back(cutFaceIndices.back());