From 513f4a52971f5ca9090a4789c34733b9946ad390 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 20 Aug 2024 02:27:29 +0200 Subject: [PATCH] Recast: many fixes regarding tile numbering Reducing the tile size to 16 for all types completely eliminated the issue where an NPC in-game fails to find a steer poly after traversal (call to dtNavMeshQuery::findNearestPoly fails). Tile size of 16 causes correct tile numbering for world bmins and bmaxs. Also added 2 new sliders allowing the change of min and max tile bits + some additional cleanup. --- src/naveditor/Editor.cpp | 24 ++++++++++++++++-------- src/naveditor/Editor_Common.cpp | 17 +++++------------ src/naveditor/Editor_TempObstacles.cpp | 2 +- src/naveditor/Editor_TileMesh.cpp | 7 +++---- src/naveditor/include/Editor.h | 2 ++ src/naveditor/include/Editor_Common.h | 3 ++- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/naveditor/Editor.cpp b/src/naveditor/Editor.cpp index 0ebfdea4..55b8d3ac 100644 --- a/src/naveditor/Editor.cpp +++ b/src/naveditor/Editor.cpp @@ -149,9 +149,6 @@ Editor::Editor() : rdVset(m_recastDrawOffset, 0.0f,0.0f,4.0f); rdVset(m_detourDrawOffset, 0.0f,0.0f,8.0f); - - initTraverseMasks(); - initTraverseTableParams(); } Editor::~Editor() @@ -250,6 +247,14 @@ void Editor::resetCommonSettings() { selectNavMeshType(NAVMESH_SMALL); +#if DT_NAVMESH_SET_VERSION == 5 + m_minTileBits 14 + m_maxTileBits 22 +#else + m_minTileBits = 16; + m_maxTileBits = 28; +#endif + m_cellSize = 16.0f; m_cellHeight = 5.85f; m_traverseLinkParams.cellHeight = m_cellHeight; @@ -271,6 +276,9 @@ void Editor::resetCommonSettings() m_detailSampleDist = 6.0f; m_detailSampleMaxError = 1.0f; m_partitionType = EDITOR_PARTITION_WATERSHED; + + initTraverseMasks(); + initTraverseTableParams(); } void Editor::handleCommonSettings() { @@ -1227,11 +1235,11 @@ void Editor::renderDetourDebugMenu() // NOTE: the climb height should never equal or exceed the agent's height, see https://groups.google.com/g/recastnavigation/c/L5rBamxcOBk/m/5xGLj6YP25kJ // Quote: "you will get into trouble in cases where there is an overhand which is low enough to step over and high enough for the agent to walk under." const hulldef hulls[NAVMESH_COUNT] = { - { g_navMeshNames[NAVMESH_SMALL] , NAI_Hull::Width(HULL_HUMAN) * NAI_Hull::Scale(HULL_HUMAN) , NAI_Hull::Height(HULL_HUMAN) , NAI_Hull::Height(HULL_HUMAN) * NAI_Hull::Scale(HULL_HUMAN) , 32, 8 }, - { g_navMeshNames[NAVMESH_MED_SHORT] , NAI_Hull::Width(HULL_PROWLER) * NAI_Hull::Scale(HULL_PROWLER), NAI_Hull::Height(HULL_PROWLER), NAI_Hull::Height(HULL_PROWLER) * NAI_Hull::Scale(HULL_PROWLER), 32, 4 }, - { g_navMeshNames[NAVMESH_MEDIUM] , NAI_Hull::Width(HULL_MEDIUM) * NAI_Hull::Scale(HULL_MEDIUM) , NAI_Hull::Height(HULL_MEDIUM) , NAI_Hull::Height(HULL_MEDIUM) * NAI_Hull::Scale(HULL_MEDIUM) , 32, 4 }, - { g_navMeshNames[NAVMESH_LARGE] , NAI_Hull::Width(HULL_TITAN) * NAI_Hull::Scale(HULL_TITAN) , NAI_Hull::Height(HULL_TITAN) , NAI_Hull::Height(HULL_TITAN) * NAI_Hull::Scale(HULL_TITAN) , 64, 2 }, - { g_navMeshNames[NAVMESH_EXTRA_LARGE], NAI_Hull::Width(HULL_GOLIATH) * NAI_Hull::Scale(HULL_GOLIATH), NAI_Hull::Height(HULL_GOLIATH), NAI_Hull::Height(HULL_GOLIATH) * NAI_Hull::Scale(HULL_GOLIATH), 64, 2 }, + { g_navMeshNames[NAVMESH_SMALL] , NAI_Hull::Width(HULL_HUMAN) * NAI_Hull::Scale(HULL_HUMAN) , NAI_Hull::Height(HULL_HUMAN) , NAI_Hull::Height(HULL_HUMAN) * NAI_Hull::Scale(HULL_HUMAN) , 16, 4 }, + { g_navMeshNames[NAVMESH_MED_SHORT] , NAI_Hull::Width(HULL_PROWLER) * NAI_Hull::Scale(HULL_PROWLER), NAI_Hull::Height(HULL_PROWLER), NAI_Hull::Height(HULL_PROWLER) * NAI_Hull::Scale(HULL_PROWLER), 16, 2 }, + { g_navMeshNames[NAVMESH_MEDIUM] , NAI_Hull::Width(HULL_MEDIUM) * NAI_Hull::Scale(HULL_MEDIUM) , NAI_Hull::Height(HULL_MEDIUM) , NAI_Hull::Height(HULL_MEDIUM) * NAI_Hull::Scale(HULL_MEDIUM) , 16, 2 }, + { g_navMeshNames[NAVMESH_LARGE] , NAI_Hull::Width(HULL_TITAN) * NAI_Hull::Scale(HULL_TITAN) , NAI_Hull::Height(HULL_TITAN) , NAI_Hull::Height(HULL_TITAN) * NAI_Hull::Scale(HULL_TITAN) , 16, 1 }, + { g_navMeshNames[NAVMESH_EXTRA_LARGE], NAI_Hull::Width(HULL_GOLIATH) * NAI_Hull::Scale(HULL_GOLIATH), NAI_Hull::Height(HULL_GOLIATH), NAI_Hull::Height(HULL_GOLIATH) * NAI_Hull::Scale(HULL_GOLIATH), 16, 1 }, }; void Editor::selectNavMeshType(const NavMeshType_e navMeshType) diff --git a/src/naveditor/Editor_Common.cpp b/src/naveditor/Editor_Common.cpp index c76e7303..e23261af 100644 --- a/src/naveditor/Editor_Common.cpp +++ b/src/naveditor/Editor_Common.cpp @@ -70,15 +70,8 @@ static void EditorCommon_DrawTilingGrid(duDebugDraw* const dd, const InputGeom* duDebugDrawGridXY(dd, bmax[0], bmin[1], bmin[2], tw, th, s, duRGBA(0, 0, 0, 64), 1.0f, nullptr); } -#if DT_NAVMESH_SET_VERSION == 5 -#define MIN_TILE_BITS 14 -#define MAX_TILE_BITS 22 -#else -#define MIN_TILE_BITS 16 -#define MAX_TILE_BITS 28 -#endif - -int EditorCommon_SetAndRenderTileProperties(const InputGeom* const geom, const int tileSize, +int EditorCommon_SetAndRenderTileProperties(const InputGeom* const geom, + const int minTilebits, const int maxTileBits, const int tileSize, const float cellSize, int& maxTiles, int& maxPolysPerTile) { int gridSize = 1; @@ -94,12 +87,12 @@ int EditorCommon_SetAndRenderTileProperties(const InputGeom* const geom, const i const int th = (gh + ts-1) / ts; ImGui::Text("Tiles: %d x %d", tw, th); - ImGui::Text("Tile Sizes: %g x %g (%g)", tw* cellSize, th*cellSize, tileSize*cellSize); + ImGui::Text("Tile Sizes: %g x %g (%g)", tw*cellSize, th*cellSize, tileSize*cellSize); // Max tiles and max polys affect how the tile IDs are calculated. // There are MAX_TILE_BITS bits available for identifying a tile and a polygon. - const int tileBits = rdMin((int)rdIlog2(rdNextPow2(tw*th)), MIN_TILE_BITS); - const int polyBits = MAX_TILE_BITS - tileBits; + const int tileBits = rdMin((int)rdIlog2(rdNextPow2(tw*th)), minTilebits); + const int polyBits = maxTileBits - tileBits; maxTiles = 1 << tileBits; maxPolysPerTile = 1 << polyBits; diff --git a/src/naveditor/Editor_TempObstacles.cpp b/src/naveditor/Editor_TempObstacles.cpp index 2f824db1..aa7e4ab2 100644 --- a/src/naveditor/Editor_TempObstacles.cpp +++ b/src/naveditor/Editor_TempObstacles.cpp @@ -814,7 +814,7 @@ void Editor_TempObstacles::handleSettings() ImGui::Checkbox("Keep Intermediate Results", &m_keepInterResults); - const int gridSize = EditorCommon_SetAndRenderTileProperties(m_geom, m_tileSize, m_cellSize, m_maxTiles, m_maxPolysPerTile); + const int gridSize = EditorCommon_SetAndRenderTileProperties(m_geom, m_minTileBits, m_maxTileBits, m_tileSize, m_cellSize, m_maxTiles, m_maxPolysPerTile); ImGui::Separator(); ImGui::Text("Tile Cache"); diff --git a/src/naveditor/Editor_TileMesh.cpp b/src/naveditor/Editor_TileMesh.cpp index 1ffd918b..5ad7683a 100644 --- a/src/naveditor/Editor_TileMesh.cpp +++ b/src/naveditor/Editor_TileMesh.cpp @@ -349,9 +349,6 @@ Editor_TileMesh::Editor_TileMesh() : m_tileMemUsage(0), m_tileTriCount(0) { - resetCommonSettings(); - selectNavMeshType(NAVMESH_SMALL); - memset(m_lastBuiltTileBmin, 0, sizeof(m_lastBuiltTileBmin)); memset(m_lastBuiltTileBmax, 0, sizeof(m_lastBuiltTileBmax)); @@ -372,12 +369,14 @@ void Editor_TileMesh::handleSettings() Editor::handleCommonSettings(); ImGui::Text("Tiling"); + ImGui::SliderInt("Min Tile Bits", &m_minTileBits, 14, 32); + ImGui::SliderInt("Max Tile Bits", &m_maxTileBits, 22, 32); ImGui::SliderInt("Tile Size", &m_tileSize, 8, 2048); ImGui::Checkbox("Build All Tiles", &m_buildAll); ImGui::Checkbox("Keep Intermediate Results", &m_keepInterResults); - EditorCommon_SetAndRenderTileProperties(m_geom, m_tileSize, m_cellSize, m_maxTiles, m_maxPolysPerTile); + EditorCommon_SetAndRenderTileProperties(m_geom, m_minTileBits, m_maxTileBits, m_tileSize, m_cellSize, m_maxTiles, m_maxPolysPerTile); ImGui::Separator(); Editor_StaticTileMeshCommon::renderIntermediateTileMeshOptions(); diff --git a/src/naveditor/include/Editor.h b/src/naveditor/include/Editor.h index 75afce46..6e43821c 100644 --- a/src/naveditor/include/Editor.h +++ b/src/naveditor/include/Editor.h @@ -241,6 +241,8 @@ protected: bool m_filterLedgeSpans; bool m_filterWalkableLowHeightSpans; + int m_minTileBits; + int m_maxTileBits; int m_tileSize; float m_cellSize; float m_cellHeight; diff --git a/src/naveditor/include/Editor_Common.h b/src/naveditor/include/Editor_Common.h index 1a8eb3c8..8c21e9f8 100644 --- a/src/naveditor/include/Editor_Common.h +++ b/src/naveditor/include/Editor_Common.h @@ -107,7 +107,8 @@ protected: bool m_keepInterResults; }; -int EditorCommon_SetAndRenderTileProperties(const InputGeom* const geom, const int tileSize, +int EditorCommon_SetAndRenderTileProperties(const InputGeom* const geom, + const int minTilebits, const int maxTileBits, const int tileSize, const float cellSize, int& maxTiles, int& maxPolysPerTile); #endif // RECASTEDITORCOMMON_H