From 5ddc96dc347a2d7b231761f2fe267252ece9b570 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:00:36 +0200 Subject: [PATCH] Recast: allocate extra links for detail edge boundaries We need more links as detail edges are used for traverse linking. Unused links will be removed during the prune stage. --- .../Detour/Source/DetourNavMeshBuilder.cpp | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp index 2a572450..95998948 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp @@ -875,24 +875,53 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData, // Find portal edges which are at tile borders. int edgeCount = 0; int portalCount = 0; + int detailBoundCount = 0; for (int i = 0; i < params->polyCount; ++i) { const unsigned short* p = ¶ms->polys[i*2*nvp]; + int numPolyBounds = 0; + for (int j = 0; j < nvp; ++j) { if (p[j] == RD_MESH_NULL_IDX) break; edgeCount++; - if (p[nvp+j] & 0x8000) + if (!p[nvp+j]) + numPolyBounds++; + else if (p[nvp+j] & 0x8000) { unsigned short dir = p[nvp+j] & 0xf; if (dir != 0xf) portalCount++; } } + + int numDetailBounds = 0; + + if (params->detailMeshes) + { + const unsigned int tb = params->detailMeshes[i*4+2]; + const unsigned int tc = params->detailMeshes[i*4+3]; + + for (unsigned int j = 0; j < tc; j++) + { + const unsigned char* tris = ¶ms->detailTris[(tb+j)*4]; + + const int ANY_BOUNDARY_EDGE = + (RD_DETAIL_EDGE_BOUNDARY << 0) | + (RD_DETAIL_EDGE_BOUNDARY << 2) | + (RD_DETAIL_EDGE_BOUNDARY << 4); + + if ((tris[3] & ANY_BOUNDARY_EDGE)) + numDetailBounds++; + } + } + + // Subtract as polygon bounds are already counted in edgeCount. + detailBoundCount += (numDetailBounds-numPolyBounds); } - const int maxLinkCount = edgeCount + portalCount*2 + baseOffMeshConLinkCount*3 + landOffMeshConLinkCount; + const int maxLinkCount = edgeCount + detailBoundCount*4 + portalCount*2 + baseOffMeshConLinkCount*3 + landOffMeshConLinkCount; // Find unique detail vertices. int uniqueDetailVertCount = 0;