Recast: add option to limit portal creation between 2 polys to 1

The algorithm can create multiple portals of different traverse types between 2 specific polygons, this option allows the user to override this behavior by limiting this to 1.
This commit is contained in:
Kawe Mazidjatari 2024-11-12 14:20:51 +01:00
parent 46e2424bb2
commit cb598e397d
4 changed files with 11 additions and 3 deletions

View File

@ -150,6 +150,7 @@ Editor::Editor() :
m_filterWalkableLowHeightSpans(true),
m_buildTraversePortals(true),
m_traverseRayDynamicOffset(true),
m_traverseLinkSinglePortalPerPolyPair(false),
m_collapseLinkedPolyGroups(false),
m_buildBvTree(true),
m_selectedNavMeshType(NAVMESH_SMALL),
@ -471,6 +472,8 @@ void Editor::handleCommonSettings()
ImGui::Checkbox("Build Traverse Portals", &m_buildTraversePortals);
ImGui::Checkbox("Single Portal Per Poly Pair", &m_traverseLinkSinglePortalPerPolyPair);
ImGui::Checkbox("Collapse Linked Poly Groups", &m_collapseLinkedPolyGroups);
if (ImGui::Checkbox("Dynamic Traverse Ray Offset", &m_traverseRayDynamicOffset))
@ -900,7 +903,7 @@ static int addToPolyMap(void* userData, const dtPolyRef basePolyRef, const dtPol
try
{
auto ret = editor->getTraverseLinkPolyMap().emplace(TraverseLinkPolyPair(basePolyRef, landPolyRef), traverseTypeBit);
const auto ret = editor->getTraverseLinkPolyMap().emplace(TraverseLinkPolyPair(basePolyRef, landPolyRef), traverseTypeBit);
if (!ret.second)
{
rdAssert(ret.second); // Called 'addToPolyMap' while poly link already exists.
@ -925,6 +928,7 @@ void Editor::createTraverseLinkParams(dtTraverseLinkConnectParams& params)
params.userData = this;
params.minEdgeOverlap = m_traverseEdgeMinOverlap;
params.maxPortalAlign = m_traversePortalMaxAlign;
params.singlePortalPerPair = m_traverseLinkSinglePortalPerPolyPair;
}
bool Editor::createTraverseLinks()

View File

@ -247,6 +247,7 @@ protected:
bool m_filterWalkableLowHeightSpans;
bool m_buildTraversePortals;
bool m_traverseRayDynamicOffset;
bool m_traverseLinkSinglePortalPerPolyPair;
bool m_collapseLinkedPolyGroups;
bool m_buildBvTree;

View File

@ -678,6 +678,7 @@ struct dtTraverseLinkConnectParams
void* userData; ///< The user defined data that will be provided to all callbacks, for example: your editor's class instance.
float minEdgeOverlap; ///< The minimum amount of projection overlap required between the 2 edges before they are considered overlapping. [Unit: wu]
float maxPortalAlign; ///< The maximum amount of portal alignment the system will apply. [Limit: 0 >= align <= 0.5]
bool singlePortalPerPair; ///< Whether to limit the number of portal connections between 2 polygon pairs to 1.
bool linkToNeighbor; ///< Whether to link to polygons in neighboring tiles. Limits linkage to internal polygons if false.
};

View File

@ -1026,9 +1026,11 @@ dtStatus dtNavMesh::connectTraverseLinks(const dtTileRef tileRef, const dtTraver
unsigned int* const linkedTraverseType = params.findPolyLink(params.userData, basePolyRef, landPolyRef);
// These 2 polygons are already linked with the same traverse type.
if (params.singlePortalPerPair && linkedTraverseType)
continue; // User has specified to limit link count between 2 polygons to 1.
if (linkedTraverseType && (rdBitCellBit(traverseType) & *linkedTraverseType))
continue;
continue; // These 2 polygons are already linked with the same traverse type.
float landEdgeNorm[3];
rdCalcEdgeNormal2D(landEdgeDir, landEdgeNorm);