From 51eac9c91cb91116bf536719fb40b18b1d38b39a Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 8 Aug 2024 19:52:28 +0200 Subject: [PATCH] Recast: add option to filter traverse links by distance --- src/naveditor/Editor.cpp | 4 +++- src/naveditor/Editor_Common.cpp | 2 +- src/naveditor/include/Editor.h | 1 + .../DebugUtils/Include/DetourDebugDraw.h | 4 ++-- .../DebugUtils/Source/DetourDebugDraw.cpp | 20 +++++++++++-------- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/naveditor/Editor.cpp b/src/naveditor/Editor.cpp index 82dd0f4d..e6f2ebaf 100644 --- a/src/naveditor/Editor.cpp +++ b/src/naveditor/Editor.cpp @@ -64,7 +64,8 @@ Editor::Editor() : m_navmeshName(NavMesh_GetNameForType(NAVMESH_SMALL)), m_tool(0), m_ctx(0), - m_traverseLinkDrawTypes(-1) + m_traverseLinkDrawTypes(-1), + m_traverseLinkDrawDistances(-1) { resetCommonSettings(); m_navQuery = dtAllocNavMeshQuery(); @@ -518,6 +519,7 @@ void Editor::renderDetourDebugMenu() { ImGui::PushItemWidth(190); ImGui::SliderInt("Traverse Type", &m_traverseLinkDrawTypes, -1, 31); + ImGui::SliderInt("Traverse Distance", &m_traverseLinkDrawDistances, -1, 255); ImGui::PopItemWidth(); } } diff --git a/src/naveditor/Editor_Common.cpp b/src/naveditor/Editor_Common.cpp index 07953542..0d9f9cba 100644 --- a/src/naveditor/Editor_Common.cpp +++ b/src/naveditor/Editor_Common.cpp @@ -307,7 +307,7 @@ void Editor_StaticTileMeshCommon::renderTileMeshData() { if (m_tileMeshDrawFlags & TM_DRAWFLAGS_NAVMESH) { - duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, detourDrawOffset, m_navMeshDrawFlags, m_traverseLinkDrawTypes); + duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, detourDrawOffset, m_navMeshDrawFlags, m_traverseLinkDrawTypes, m_traverseLinkDrawDistances); duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, EDITOR_POLYFLAGS_DISABLED, detourDrawOffset, detourDrawFlags, duRGBA(0, 0, 0, 128)); } } diff --git a/src/naveditor/include/Editor.h b/src/naveditor/include/Editor.h index 5b37546c..eee38c57 100644 --- a/src/naveditor/include/Editor.h +++ b/src/naveditor/include/Editor.h @@ -171,6 +171,7 @@ protected: EditorDebugDraw m_dd; unsigned int m_navMeshDrawFlags; int m_traverseLinkDrawTypes; + int m_traverseLinkDrawDistances; float m_recastDrawOffset[3]; float m_detourDrawOffset[3]; diff --git a/src/thirdparty/recast/DebugUtils/Include/DetourDebugDraw.h b/src/thirdparty/recast/DebugUtils/Include/DetourDebugDraw.h index aa522548..e97e1a38 100644 --- a/src/thirdparty/recast/DebugUtils/Include/DetourDebugDraw.h +++ b/src/thirdparty/recast/DebugUtils/Include/DetourDebugDraw.h @@ -42,8 +42,8 @@ enum DrawNavMeshFlags DU_DRAWNAVMESH_TRAVERSE_LINKS = 1 << 14, // Render traverse links. }; -void duDebugDrawNavMesh(struct duDebugDraw* dd, const dtNavMesh& mesh, const float* offset, unsigned int flags, const int linkTypes = -1); -void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, const float* offset, unsigned int flags, const int linkTypes = -1); +void duDebugDrawNavMesh(struct duDebugDraw* dd, const dtNavMesh& mesh, const float* offset, unsigned int flags, const int linkTypes = -1, const int linkDistance = -1); +void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, const float* offset, unsigned int flags, const int linkTypes = -1, const int linkDistance = -1); void duDebugDrawNavMeshNodes(struct duDebugDraw* dd, const dtNavMeshQuery& query, const float* offset); void duDebugDrawNavMeshBVTree(struct duDebugDraw* dd, const dtNavMesh& mesh, const float* offset); void duDebugDrawNavMeshPortals(struct duDebugDraw* dd, const dtNavMesh& mesh, const float* offset); diff --git a/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp b/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp index 76a1d018..2c6dc174 100644 --- a/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp +++ b/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp @@ -134,7 +134,7 @@ static void drawPolyCenters(duDebugDraw* dd, const dtMeshTile* tile, const unsig } static void drawTraverseLinks(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery* query, - const dtMeshTile* tile, const float* offset, const int drawLinkType) + const dtMeshTile* tile, const float* offset, const int drawLinkType, const int drawLinkDistance) { for (int i = 0; i < tile->header->polyCount; ++i) { @@ -155,10 +155,14 @@ static void drawTraverseLinks(duDebugDraw* dd, const dtNavMesh& mesh, const dtNa if (link->traverseType == DT_NULL_TRAVERSE_TYPE) continue; - // Filter, drawLinkType -1 means draw all + // Filter, drawLinkType -1 means draw all types if (drawLinkType != -1 && link->traverseType != drawLinkType) continue; + // Filter, drawLinkDistance -1 means draw all distances + if (drawLinkDistance != -1 && link->traverseDist > drawLinkDistance) + continue; + const dtPoly* endPoly; const dtMeshTile* endTile; @@ -213,7 +217,7 @@ static void drawTileCells(duDebugDraw* dd, const dtMeshTile* tile, const float* } static void drawMeshTile(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery* query, - const dtMeshTile* tile, const float* offset, unsigned int flags, const int linkTypes) + const dtMeshTile* tile, const float* offset, unsigned int flags, const int linkTypes, const int linkDistance) { // If the "Alpha" flag isn't set, force the colour to be opaque instead of semi-transparent. const int tileAlpha = flags & DU_DRAWNAVMESH_ALPHA ? 170 : 255; @@ -272,7 +276,7 @@ static void drawMeshTile(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMesh drawPolyCenters(dd, tile, duRGBA(255, 255, 255, 100), 1.0f, offset); if (flags & DU_DRAWNAVMESH_TRAVERSE_LINKS) - drawTraverseLinks(dd, mesh, query, tile, offset, linkTypes); + drawTraverseLinks(dd, mesh, query, tile, offset, linkTypes, linkDistance); if (flags & DU_DRAWNAVMESH_CELLS) drawTileCells(dd, tile, offset); @@ -358,7 +362,7 @@ static void drawMeshTile(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMesh dd->depthMask(true); } -void duDebugDrawNavMesh(duDebugDraw* dd, const dtNavMesh& mesh, const float* offset, unsigned int flags, const int linkTypes) +void duDebugDrawNavMesh(duDebugDraw* dd, const dtNavMesh& mesh, const float* offset, unsigned int flags, const int linkTypes, const int linkDistance) { if (!dd) return; @@ -366,11 +370,11 @@ void duDebugDrawNavMesh(duDebugDraw* dd, const dtNavMesh& mesh, const float* off { const dtMeshTile* tile = mesh.getTile(i); if (!tile->header) continue; - drawMeshTile(dd, mesh, 0, tile, offset, flags, linkTypes); + drawMeshTile(dd, mesh, 0, tile, offset, flags, linkTypes, linkDistance); } } -void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, const float* offset, unsigned int flags, const int linkTypes) +void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, const float* offset, unsigned int flags, const int linkTypes, const int linkDistance) { if (!dd) return; @@ -380,7 +384,7 @@ void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& m { const dtMeshTile* tile = mesh.getTile(i); if (!tile->header) continue; - drawMeshTile(dd, mesh, q, tile, offset, flags, linkTypes); + drawMeshTile(dd, mesh, q, tile, offset, flags, linkTypes, linkDistance); } if (flags & DU_DRAWNAVMESH_BVTREE)