From 0a296c5a5f8e292bda46630f0dbb415132d1cc31 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:24:54 +0200 Subject: [PATCH] Recast: fix group merging bug in static path building Don't merge poly islands under the same group id if there's an off-mesh connection linking the 2. The off-mesh connection polygon also gets its own group id now. The reason we don't want to merge them is because not all ai can take the off-mesh link under on the same navmesh, and if we merge them the ai would still try and reach a goal poly it couldn't, causing it to become hard stuck on the poly island's boundary. --- .../Detour/Source/DetourNavMeshBuilder.cpp | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp index a3880311..60a806aa 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp @@ -320,19 +320,27 @@ bool dtCreateStaticPathingData(dtNavMesh* nav) { dtPoly& poly = tile->polys[j]; unsigned int plink = poly.firstLink; - while (plink != DT_NULL_LINK) + + // Off-mesh connections need their own ID's + if (poly.getType() != DT_POLYTYPE_OFFMESH_CONNECTION) { - const dtLink l = tile->links[plink]; - const dtMeshTile* t; - const dtPoly* p; - nav->getTileAndPolyByRefUnsafe(l.ref, &t, &p); + while (plink != DT_NULL_LINK) + { + const dtLink l = tile->links[plink]; + const dtMeshTile* t; + const dtPoly* p; + nav->getTileAndPolyByRefUnsafe(l.ref, &t, &p); - if (p->groupId != (unsigned short)-1) - nlabels.insert(p->groupId); + if (p->groupId != (unsigned short)-1) + nlabels.insert(p->groupId); - plink = l.next; + plink = l.next; + } } - if (nlabels.empty()) + + const bool noLabels = nlabels.empty(); + + if (noLabels) { // This poly isn't connected to anything, mark it so the game // won't consider this poly in path generation. @@ -349,7 +357,9 @@ bool dtCreateStaticPathingData(dtNavMesh* nav) for (const int nl : nlabels) data.setUnion(l, nl); } - nlabels.clear(); + + if (!noLabels) + nlabels.clear(); } }