Recast: add option to filter traverse links by distance

This commit is contained in:
Kawe Mazidjatari 2024-08-08 19:52:28 +02:00
parent acaf4cf32b
commit 51eac9c91c
5 changed files with 19 additions and 12 deletions

View File

@ -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();
}
}

View File

@ -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));
}
}

View File

@ -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];

View File

@ -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);

View File

@ -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)