From 727a4377ba0a0360e08b8cf30d710975a5ffebc1 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:27:57 +0200 Subject: [PATCH] Recast: reset poly mesh area flags after build Flags are changed to game specific flags, but never reset after build causing the recast debug draw to be incorrect. Reset area flags to fix this issue. --- src/naveditor/Editor_TileMesh.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/naveditor/Editor_TileMesh.cpp b/src/naveditor/Editor_TileMesh.cpp index 520dfa66..7a9b67bb 100644 --- a/src/naveditor/Editor_TileMesh.cpp +++ b/src/naveditor/Editor_TileMesh.cpp @@ -669,7 +669,7 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const // Allocate array that can hold triangle flags. // If you have multiple meshes you need to process, allocate - // and array which can hold the max number of triangles you need to process. + // an array which can hold the max number of triangles you need to process. m_triareas = new unsigned char[chunkyMesh->maxTrisPerChunk]; if (!m_triareas) { @@ -970,12 +970,26 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const params.cs = m_cfg.cs; params.ch = m_cfg.ch; params.buildBvTree = true; - - if (!dtCreateNavMeshData(¶ms, &navData, &navDataSize)) + + const bool navMeshBuildSuccess = dtCreateNavMeshData(¶ms, &navData, &navDataSize); + + // Restore poly areas. + for (int i = 0; i < m_pmesh->npolys; ++i) + { + // The game's poly area (ground) shares the same value as + // RC_NULL_AREA, if we try to render the recast polymesh cache + // without restoring this, the renderer will draw it as NULL area + // even though it's walkable. The other values will get color ID'd + // by the renderer so we don't need to check on those. + if (m_pmesh->areas[i] == EDITOR_POLYAREA_GROUND) + m_pmesh->areas[i] = RC_WALKABLE_AREA; + } + + if (!navMeshBuildSuccess) { m_ctx->log(RC_LOG_ERROR, "Could not build Detour navmesh."); return 0; - } + } } m_tileMemUsage = navDataSize/1024.0f;