From b5afdfe2f3385c2654a7b89fb0a546563e891933 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:24:39 +0200 Subject: [PATCH] Recast: add more render options --- src/naveditor/Editor_TileMesh.cpp | 15 +++++++++++++++ src/naveditor/include/Editor.h | 8 ++++---- src/naveditor/include/OffMeshConnectionTool.h | 2 +- .../DebugUtils/Include/DetourDebugDraw.h | 18 ++++++++++-------- .../DebugUtils/Source/DetourDebugDraw.cpp | 12 ++++++------ 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/naveditor/Editor_TileMesh.cpp b/src/naveditor/Editor_TileMesh.cpp index ccf907a4..12f34dda 100644 --- a/src/naveditor/Editor_TileMesh.cpp +++ b/src/naveditor/Editor_TileMesh.cpp @@ -377,6 +377,15 @@ void Editor_TileMesh::handleDebugMode() imguiLabel("Render Options"); + if (imguiCheck("Draw Off-Mesh Connections", (getNavMeshDrawFlags() & DU_DRAWNAVMESH_OFFMESHCONS))) + toggleNavMeshDrawFlag(DU_DRAWNAVMESH_OFFMESHCONS); + + if (imguiCheck("Draw Closed List", (getNavMeshDrawFlags() & DU_DRAWNAVMESH_CLOSEDLIST))) + toggleNavMeshDrawFlag(DU_DRAWNAVMESH_CLOSEDLIST); + + if (imguiCheck("Draw Tile ID Colors", (getNavMeshDrawFlags() & DU_DRAWNAVMESH_COLOR_TILES))) + toggleNavMeshDrawFlag(DU_DRAWNAVMESH_COLOR_TILES); + if (imguiCheck("Draw Vertex Points", (getNavMeshDrawFlags() & DU_DRAWNAVMESH_VERTS))) toggleNavMeshDrawFlag(DU_DRAWNAVMESH_VERTS); @@ -386,6 +395,12 @@ void Editor_TileMesh::handleDebugMode() if (imguiCheck("Draw Outer Poly Boundaries", (getNavMeshDrawFlags() & DU_DRAWNAVMESH_OUTERBOUND))) toggleNavMeshDrawFlag(DU_DRAWNAVMESH_OUTERBOUND); + if (imguiCheck("Draw Poly Centers", (getNavMeshDrawFlags() & DU_DRAWNAVMESH_POLYCENTERS))) + toggleNavMeshDrawFlag(DU_DRAWNAVMESH_POLYCENTERS); + + if (imguiCheck("Disable NavMesh Depth Mask", (getNavMeshDrawFlags() & DU_DRAWNAVMESH_NO_DEPTH_MASK))) + toggleNavMeshDrawFlag(DU_DRAWNAVMESH_NO_DEPTH_MASK); + if (imguiCheck("Disable NavMesh Transparency", (getNavMeshDrawFlags() & DU_DRAWNAVMESH_NO_ALPHA))) toggleNavMeshDrawFlag(DU_DRAWNAVMESH_NO_ALPHA); diff --git a/src/naveditor/include/Editor.h b/src/naveditor/include/Editor.h index 100495c6..ae35adb1 100644 --- a/src/naveditor/include/Editor.h +++ b/src/naveditor/include/Editor.h @@ -113,7 +113,7 @@ protected: class dtNavMeshQuery* m_navQuery; class dtCrowd* m_crowd; - unsigned char m_navMeshDrawFlags; + unsigned int m_navMeshDrawFlags; bool m_filterLowHangingObstacles; bool m_filterLedgeSpans; bool m_filterWalkableLowHeightSpans; @@ -179,10 +179,10 @@ public: virtual float getAgentHeight() { return m_agentHeight; } virtual float getAgentClimb() { return m_agentMaxClimb; } - inline unsigned char getNavMeshDrawFlags() const { return m_navMeshDrawFlags; } - inline void setNavMeshDrawFlags(unsigned char flags) { m_navMeshDrawFlags = flags; } + inline unsigned int getNavMeshDrawFlags() const { return m_navMeshDrawFlags; } + inline void setNavMeshDrawFlags(unsigned int flags) { m_navMeshDrawFlags = flags; } - inline void toggleNavMeshDrawFlag(unsigned char flag) { m_navMeshDrawFlags ^= flag; } + inline void toggleNavMeshDrawFlag(unsigned int flag) { m_navMeshDrawFlags ^= flag; } void updateToolStates(const float dt); void initToolStates(Editor* editor); diff --git a/src/naveditor/include/OffMeshConnectionTool.h b/src/naveditor/include/OffMeshConnectionTool.h index 13ae2ee3..1b1657e9 100644 --- a/src/naveditor/include/OffMeshConnectionTool.h +++ b/src/naveditor/include/OffMeshConnectionTool.h @@ -29,7 +29,7 @@ class OffMeshConnectionTool : public EditorTool float m_hitPos[3]; bool m_hitPosSet; bool m_bidir; - unsigned char m_oldFlags; + unsigned int m_oldFlags; public: OffMeshConnectionTool(); diff --git a/src/thirdparty/recast/DebugUtils/Include/DetourDebugDraw.h b/src/thirdparty/recast/DebugUtils/Include/DetourDebugDraw.h index 7feb44cf..e5a84816 100644 --- a/src/thirdparty/recast/DebugUtils/Include/DetourDebugDraw.h +++ b/src/thirdparty/recast/DebugUtils/Include/DetourDebugDraw.h @@ -25,17 +25,19 @@ enum DrawNavMeshFlags { - DU_DRAWNAVMESH_OFFMESHCONS = 1 << 0, - DU_DRAWNAVMESH_CLOSEDLIST = 1 << 1, - DU_DRAWNAVMESH_COLOR_TILES = 1 << 2, - DU_DRAWNAVMESH_VERTS = 1 << 3, // Render vertex points - DU_DRAWNAVMESH_INNERBOUND = 1 << 4, // Render inner poly boundaries - DU_DRAWNAVMESH_OUTERBOUND = 1 << 5, // Render outer poly boundaries - DU_DRAWNAVMESH_NO_ALPHA = 1 << 6, // Render meshes as opaque. + DU_DRAWNAVMESH_OFFMESHCONS = 1 << 0, // Render off-mesh connections. + DU_DRAWNAVMESH_CLOSEDLIST = 1 << 1, // Render navmesh with closed list. + DU_DRAWNAVMESH_COLOR_TILES = 1 << 2, // Render tiles colored by their ID's. + DU_DRAWNAVMESH_VERTS = 1 << 3, // Render vertex points. + DU_DRAWNAVMESH_INNERBOUND = 1 << 4, // Render inner poly boundaries. + DU_DRAWNAVMESH_OUTERBOUND = 1 << 5, // Render outer poly boundaries. + DU_DRAWNAVMESH_POLYCENTERS = 1 << 6, // Render poly centers. + DU_DRAWNAVMESH_NO_DEPTH_MASK = 1 << 7, // Disable render depth mask. + DU_DRAWNAVMESH_NO_ALPHA = 1 << 8, // Disable navmesh transparency. }; void duDebugDrawNavMesh(struct duDebugDraw* dd, const dtNavMesh& mesh, unsigned char flags); -void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, unsigned char flags); +void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, unsigned int flags); void duDebugDrawNavMeshNodes(struct duDebugDraw* dd, const dtNavMeshQuery& query); void duDebugDrawNavMeshBVTree(struct duDebugDraw* dd, const dtNavMesh& mesh); void duDebugDrawNavMeshPortals(struct duDebugDraw* dd, const dtNavMesh& mesh); diff --git a/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp b/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp index 4503b080..376e45fa 100644 --- a/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp +++ b/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp @@ -134,18 +134,17 @@ static void drawPolyCenters(duDebugDraw* dd, const dtMeshTile* tile, const unsig } static void drawMeshTile(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery* query, - const dtMeshTile* tile, unsigned char flags) + const dtMeshTile* tile, unsigned int flags) { dtPolyRef base = mesh.getPolyRefBase(tile); - int tileNum = mesh.decodePolyIdTile(base); // If "No Alpha" flag is set, force the colour to be opaque instead of semi-transparent. const int tileAlpha = flags & DU_DRAWNAVMESH_NO_ALPHA ? 255 : 170; - const unsigned int tileColor = duIntToCol(tileNum, tileAlpha); - dd->depthMask(true); + const bool disableDepthTest = flags & DU_DRAWNAVMESH_NO_DEPTH_MASK; + dd->depthMask(!disableDepthTest); dd->begin(DU_DRAW_TRIS); for (int i = 0; i < tile->header->polyCount; ++i) @@ -190,7 +189,8 @@ static void drawMeshTile(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMesh drawPolyBoundaries(dd, tile, 2.5f, false); // Draw poly centers - drawPolyCenters(dd, tile, duRGBA(255, 255, 255, 100), 1.0f); + if (flags & DU_DRAWNAVMESH_POLYCENTERS) + drawPolyCenters(dd, tile, duRGBA(255, 255, 255, 100), 1.0f); if (flags & DU_DRAWNAVMESH_OFFMESHCONS) { @@ -277,7 +277,7 @@ void duDebugDrawNavMesh(duDebugDraw* dd, const dtNavMesh& mesh, unsigned char fl } } -void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, unsigned char flags) +void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, unsigned int flags) { if (!dd) return;