From ed9cd80034e8b69347b3c6d9f70bddcc79fc7d09 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 25 Oct 2024 01:12:51 +0200 Subject: [PATCH] Recast: fix generation of concave polygons These changes seem to yield better results for the larger maps. The improvements are minimal however. This change is probably more noticable on tile cache. --- .../Source/DetourTileCacheBuilder.cpp | 20 +++++++++---------- .../recast/Recast/Source/RecastMesh.cpp | 20 +++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/thirdparty/recast/DetourTileCache/Source/DetourTileCacheBuilder.cpp b/src/thirdparty/recast/DetourTileCache/Source/DetourTileCacheBuilder.cpp index 390d0c37..cd7af04e 100644 --- a/src/thirdparty/recast/DetourTileCache/Source/DetourTileCacheBuilder.cpp +++ b/src/thirdparty/recast/DetourTileCache/Source/DetourTileCacheBuilder.cpp @@ -1284,18 +1284,16 @@ static int triangulate(int n, const unsigned char* verts, unsigned short* indice for (int k = i1; k < n; k++) indices[k] = indices[k+1]; - if (i1 >= n) i1 = 0; - i = REV_STEP_DIR(i1,n); // Update diagonal flags. - if (diagonal(REV_STEP_DIR(i, n), i1, n, verts, indices)) - indices[i] |= 0x8000; - else - indices[i] &= 0x7fff; - - if (diagonal(i, STEP_DIR(i1, n), n, verts, indices)) - indices[i1] |= 0x8000; - else - indices[i1] &= 0x7fff; + for (int k = 0; k < n; k++) // See https://github.com/recastnavigation/recastnavigation/pull/734 + { + const int k1 = STEP_DIR(k, n); + const int k2 = STEP_DIR(k1, n); + if (diagonal(k, k2, n, verts, indices)) + indices[k1] |= 0x8000; + else + indices[k1] &= 0x7fff; + } } // Append the remaining triangle. diff --git a/src/thirdparty/recast/Recast/Source/RecastMesh.cpp b/src/thirdparty/recast/Recast/Source/RecastMesh.cpp index 913983c6..ee114c7c 100644 --- a/src/thirdparty/recast/Recast/Source/RecastMesh.cpp +++ b/src/thirdparty/recast/Recast/Source/RecastMesh.cpp @@ -457,18 +457,16 @@ static int triangulate(int n, const int* verts, int* indices, int* tris) for (int k = i1; k < n; k++) indices[k] = indices[k+1]; - if (i1 >= n) i1 = 0; - i = REV_STEP_DIR(i1,n); // Update diagonal flags. - if (diagonal(REV_STEP_DIR(i, n), i1, n, verts, indices)) - indices[i] |= 0x80000000; - else - indices[i] &= 0x0fffffff; - - if (diagonal(i, STEP_DIR(i1, n), n, verts, indices)) - indices[i1] |= 0x80000000; - else - indices[i1] &= 0x0fffffff; + for (int k = 0; k < n; k++) // See https://github.com/recastnavigation/recastnavigation/pull/734 + { + const int k1 = STEP_DIR(k, n); + const int k2 = STEP_DIR(k1, n); + if (diagonal(k, k2, n, verts, indices)) + indices[k1] |= 0x80000000; + else + indices[k1] &= 0x0fffffff; + } } // Append the remaining triangle.