Skip to content

Commit

Permalink
Make undermaps filter optional
Browse files Browse the repository at this point in the history
  • Loading branch information
celguar committed Nov 11, 2024
1 parent 5a42c11 commit 67525c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions contrib/mmap/src/MapBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void from_json(const json& j, rcConfig& config)
config.detailSampleDist = j["detailSampleDist"].get<float>();
config.detailSampleMaxError = j["detailSampleMaxError"].get<float>();
config.liquidFlagMergeThreshold = j["liquidFlagMergeThreshold"].get<float>();
config.filterUnderTerrain = j["filterUnderTerrain"].get<int>();
}

namespace MMAP
Expand Down Expand Up @@ -651,7 +652,7 @@ namespace MMAP
void filterSteepSlopeTriangles(rcContext* ctx,
const float* verts, int nv,
const int* tris, int nt,
unsigned char* areas, MeshData& meshData, TerrainBuilder* m_terrainBuilder, VMAP::IVMapManager* vmapManager)
unsigned char* areas, bool filterUnderTerrain, MeshData& meshData, TerrainBuilder* m_terrainBuilder, VMAP::IVMapManager* vmapManager)
{
rcIgnoreUnused(ctx);
rcIgnoreUnused(nv);
Expand Down Expand Up @@ -701,7 +702,7 @@ namespace MMAP

// Now we remove underterrain triangles (actually set flags to 0)
// This prevents selecting wrong poly for a player in the server later.
if (vmapManager && !terrain && areas[i])
if (filterUnderTerrain && vmapManager && !terrain && areas[i])
{
// Get triangle corners (as usual, yzx positions)
// (actually we push these corners towards the center a bit to prevent collision with border models etc...)
Expand Down Expand Up @@ -1160,7 +1161,8 @@ namespace MMAP
rcClearUnwalkableTriangles(m_rcContext, tileCfg.walkableSlopeAngle, tVerts, tVertCount, tTris, tTriCount, triFlags);

// mark almost unwalkable triangles with steep flag
rcModAlmostUnwalkableTriangles(m_rcContext, 50.0f, tVerts, tVertCount, tTris, tTriCount, triFlags);
//rcModAlmostUnwalkableTriangles(m_rcContext, 50.0f, tVerts, tVertCount, tTris, tTriCount, triFlags);
filterSteepSlopeTriangles(m_rcContext, tVerts, tVertCount, tTris, tTriCount, triFlags, tileCfg.filterUnderTerrain, meshData, m_terrainBuilder, vmapManager);

rcRasterizeTriangles(m_rcContext, tVerts, tVertCount, tTris, triFlags, tTriCount, *tile.solid, tileCfg.walkableClimb);
delete[] triFlags;
Expand Down Expand Up @@ -1352,6 +1354,7 @@ namespace MMAP
{"walkableRadius", 2},
{"walkableSlopeAngle", 75.0f},
{"liquidFlagMergeThreshold", 0.0f},
{"filterUnderTerrain", 0},
};
}

Expand Down
5 changes: 5 additions & 0 deletions dep/recastnavigation/Recast/Include/Recast.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ struct rcConfig

/// Vertical threshold for merging spans with higher priority areas when rasterizing liquids
float liquidFlagMergeThreshold;

/// Filter vmap polygons under terrain when generating mmaps. Can fix mmaps being generated on objects surfaces
/// that go under the map, e.g. trees. Prevents pathfinder select underterrain mmaps when moving near such objects,
/// but may cause issues in some dungeons, e.g. RFK, RFD. So is configurable
int filterUnderTerrain;
};

/// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax.
Expand Down

0 comments on commit 67525c0

Please sign in to comment.