From f7f54036f20547b446600476abf1cae902d8148d Mon Sep 17 00:00:00 2001 From: Jackie9527 <80555200+Jackie9527@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:10:03 +0800 Subject: [PATCH] bugfix the three vertices are collinear when converting a polygon to a triangle. Signed-off-by: Jackie9527 <80555200+Jackie9527@users.noreply.github.com> --- code/PostProcessing/TriangulateProcess.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/code/PostProcessing/TriangulateProcess.cpp b/code/PostProcessing/TriangulateProcess.cpp index 52e760361..8ba6456b7 100644 --- a/code/PostProcessing/TriangulateProcess.cpp +++ b/code/PostProcessing/TriangulateProcess.cpp @@ -468,6 +468,21 @@ bool TriangulateProcess::TriangulateMesh( aiMesh* pMesh) continue; } + // Skip when three point is in a line + aiVector2D left = *pnt0 - *pnt1; + aiVector2D right = *pnt2 - *pnt1; + + left.Normalize(); + right.Normalize(); + auto mul = left * right; + + // if the angle is 0 or 180 + if (std::abs(mul - 1.f) < ai_epsilon || std::abs(mul + 1.f) < ai_epsilon) { + // skip this ear + ASSIMP_LOG_WARN("Skip a ear, due to its angle is near 0 or 180."); + continue; + } + // and no other point may be contained in this triangle for ( tmp = 0; tmp < max; ++tmp) {