Recast: add traverse link filter for anim types

Add new filter + light cleanup.
This commit is contained in:
Kawe Mazidjatari 2024-08-11 16:23:33 +02:00
parent 6342266091
commit ea38d4764a
6 changed files with 48 additions and 22 deletions

View File

@ -63,9 +63,7 @@ Editor::Editor() :
m_loadedNavMeshType(NAVMESH_SMALL),
m_navmeshName(NavMesh_GetNameForType(NAVMESH_SMALL)),
m_tool(0),
m_ctx(0),
m_traverseLinkDrawTypes(-1),
m_traverseLinkDrawDistances(-1)
m_ctx(0)
{
resetCommonSettings();
m_navQuery = dtAllocNavMeshQuery();
@ -867,8 +865,9 @@ void Editor::renderDetourDebugMenu()
if (isEnabled)
{
ImGui::PushItemWidth(190);
ImGui::SliderInt("Traverse Type", &m_traverseLinkDrawTypes, -1, 31);
ImGui::SliderInt("Traverse Dist", &m_traverseLinkDrawDistances, -1, 255);
ImGui::SliderInt("Traverse Type", &m_traverseLinkParams.traverseLinkType, -1, 31);
ImGui::SliderInt("Traverse Dist", &m_traverseLinkParams.traverseLinkDistance, -1, 255);
ImGui::SliderInt("Traverse Anim", &m_traverseLinkParams.traverseAnimType, -1, m_navMesh->getParams()->traverseTableCount-1);
ImGui::PopItemWidth();
}
}

View File

@ -22,7 +22,7 @@
#include "DebugUtils/Include/RecastDebugDraw.h"
#include "DebugUtils/Include/DetourDebugDraw.h"
#include "Include/InputGeom.h"
#include <DetourTileCache/Include/DetourTileCache.h>
#include "DetourTileCache/Include/DetourTileCache.h"
static void EditorCommon_DrawInputGeometry(duDebugDraw* const dd, const InputGeom* const geom,
const float maxSlope, const float textureScale)
@ -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, m_traverseLinkDrawDistances);
duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, detourDrawOffset, m_navMeshDrawFlags, m_traverseLinkParams);
duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, EDITOR_POLYFLAGS_DISABLED, detourDrawOffset, detourDrawFlags, duRGBA(0, 0, 0, 128));
}
}
@ -572,7 +572,7 @@ void Editor_DynamicTileMeshCommon::renderTileMeshData()
{
if (recastDrawFlags & TM_DRAWFLAGS_NAVMESH)
{
duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, detourDrawOffset, detourDrawFlags);
duDebugDrawNavMeshWithClosedList(&m_dd, *m_navMesh, *m_navQuery, detourDrawOffset, detourDrawFlags, m_traverseLinkParams);
duDebugDrawNavMeshPolysWithFlags(&m_dd, *m_navMesh, EDITOR_POLYFLAGS_DISABLED, detourDrawOffset, detourDrawFlags, duRGBA(0, 0, 0, 128));
}
}

View File

@ -188,7 +188,7 @@ void Editor_Debug::handleRender()
}
if (m_navMesh)
duDebugDrawNavMesh(&m_dd, *m_navMesh, m_detourDrawOffset, DU_DRAWNAVMESH_OFFMESHCONS);
duDebugDrawNavMesh(&m_dd, *m_navMesh, m_detourDrawOffset, DU_DRAWNAVMESH_OFFMESHCONS, m_traverseLinkParams);
if (m_ref && m_navMesh)
duDebugDrawNavMeshPoly(&m_dd, *m_navMesh, m_ref, m_detourDrawOffset, m_navMeshDrawFlags, duRGBA(255,0,0,128));

View File

@ -21,6 +21,8 @@
#include "Recast/Include/Recast.h"
#include "NavEditor/Include/EditorInterfaces.h"
#include "DebugUtils/Include/RecastDebugDraw.h"
#include "DebugUtils/Include/DetourDebugDraw.h"
#include "game/server/ai_navmesh.h"
@ -172,8 +174,7 @@ protected:
EditorDebugDraw m_dd;
unsigned int m_navMeshDrawFlags;
int m_traverseLinkDrawTypes;
int m_traverseLinkDrawDistances;
duDrawTraverseLinkParams m_traverseLinkParams;
float m_recastDrawOffset[3];
float m_detourDrawOffset[3];

View File

@ -43,8 +43,21 @@ enum DrawNavMeshFlags
DU_DRAWNAVMESH_TRAVERSE_LINKS = 1 << 15, // Render traverse links.
};
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);
struct duDrawTraverseLinkParams
{
duDrawTraverseLinkParams() :
traverseLinkType(-1),
traverseLinkDistance(-1),
traverseAnimType(-1)
{}
int traverseLinkType;
int traverseLinkDistance;
int traverseAnimType;
};
void duDebugDrawNavMesh(struct duDebugDraw* dd, const dtNavMesh& mesh, const float* offset, unsigned int flags, const duDrawTraverseLinkParams& traverseLinkParams);
void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, const float* offset, unsigned int flags, const duDrawTraverseLinkParams& traverseLinkParams);
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 int drawLinkDistance)
const dtMeshTile* tile, const float* offset, const duDrawTraverseLinkParams& traverseLinkParams)
{
for (int i = 0; i < tile->header->polyCount; ++i)
{
@ -156,13 +156,26 @@ static void drawTraverseLinks(duDebugDraw* dd, const dtNavMesh& mesh, const dtNa
continue;
// Filter, drawLinkType -1 means draw all types
const int drawLinkType = traverseLinkParams.traverseLinkType;
if (drawLinkType != -1 && link->traverseType != drawLinkType)
continue;
// Filter, drawLinkDistance -1 means draw all distances
const int drawLinkDistance = traverseLinkParams.traverseLinkDistance;
if (drawLinkDistance != -1 && link->traverseDist > drawLinkDistance)
continue;
// Filter, drawAnimType -1 means draw all distances
const int drawAnimType = traverseLinkParams.traverseAnimType;
const dtPolyRef basePolyRef = mesh.getPolyRefBase(tile) | (dtPolyRef)i;
if (drawAnimType != -1 &&
!mesh.isGoalPolyReachable(basePolyRef, link->ref, false, drawAnimType) &&
!mesh.isGoalPolyReachable(link->ref, basePolyRef, false, drawAnimType))
continue;
const dtPoly* endPoly;
const dtMeshTile* endTile;
@ -175,8 +188,8 @@ static void drawTraverseLinks(duDebugDraw* dd, const dtNavMesh& mesh, const dtNa
float startPos[3];
float endPos[3];
query->getEdgeMidPoint(mesh.getPolyRefBase(tile) | (dtPolyRef)i, link->ref, startPos);
query->getEdgeMidPoint(link->ref, mesh.getPolyRefBase(tile) | (dtPolyRef)i, endPos);
query->getEdgeMidPoint(basePolyRef, link->ref, startPos);
query->getEdgeMidPoint(link->ref, basePolyRef, endPos);
// Unique color for each type.
const int col = duIntToCol(link->traverseType, 128);
@ -216,7 +229,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 int linkDistance)
const dtMeshTile* tile, const float* offset, unsigned int flags, const duDrawTraverseLinkParams& traverseLinkParams)
{
// 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;
@ -276,7 +289,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, linkDistance);
drawTraverseLinks(dd, mesh, query, tile, offset, traverseLinkParams);
if (flags & DU_DRAWNAVMESH_TILE_CELLS)
drawTileCells(dd, tile, offset);
@ -365,7 +378,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, const int linkDistance)
void duDebugDrawNavMesh(duDebugDraw* dd, const dtNavMesh& mesh, const float* offset, unsigned int flags, const duDrawTraverseLinkParams& traverseLinkParams)
{
if (!dd) return;
@ -373,11 +386,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, linkDistance);
drawMeshTile(dd, mesh, 0, tile, offset, flags, traverseLinkParams);
}
}
void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, const float* offset, unsigned int flags, const int linkTypes, const int linkDistance)
void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, const float* offset, unsigned int flags, const duDrawTraverseLinkParams& traverseLinkParams)
{
if (!dd) return;
@ -387,7 +400,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, linkDistance);
drawMeshTile(dd, mesh, q, tile, offset, flags, traverseLinkParams);
}
if (flags & DU_DRAWNAVMESH_BVTREE)