mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Recast: only check edge dir if slope threshold is exceeded
Prevents the creation of traverse links that run parallel with the edge when linking to poly edges from external tiles.
This commit is contained in:
parent
b585c96106
commit
ef0f9a7770
@ -406,8 +406,8 @@ enum TraverseType_e // todo(amos): move elsewhere
|
|||||||
|
|
||||||
struct TraverseType_s // todo(amos): move elsewhere
|
struct TraverseType_s // todo(amos): move elsewhere
|
||||||
{
|
{
|
||||||
float minSlope;
|
float minSlope; // todo(amos): use height difference instead of slope angles.
|
||||||
float maxSlope;
|
float maxSlope; // todo(amos): use height difference instead of slope angles.
|
||||||
|
|
||||||
unsigned char minDist;
|
unsigned char minDist;
|
||||||
unsigned char maxDist;
|
unsigned char maxDist;
|
||||||
@ -504,10 +504,13 @@ TraverseType_e GetBestTraverseType(const float slopeAngle, const unsigned char t
|
|||||||
return bestTraverseType;
|
return bestTraverseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo(amos): find the best threshold...
|
||||||
|
// todo(amos): use height difference instead of slope angles.
|
||||||
|
#define TRAVERSE_OVERLAP_SLOPE_THRESHOLD 5.0f
|
||||||
|
|
||||||
bool CanOverlapPoly(const TraverseType_e traverseType)
|
bool CanOverlapPoly(const TraverseType_e traverseType)
|
||||||
{
|
{
|
||||||
// todo(amos): find the best threshold...
|
return s_traverseTypes[traverseType].minSlope >= TRAVERSE_OVERLAP_SLOPE_THRESHOLD;
|
||||||
return s_traverseTypes[traverseType].minSlope > 5.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool traverseLinkInPolygon(const dtMeshTile* tile, const float* midPoint)
|
static bool traverseLinkInPolygon(const dtMeshTile* tile, const float* midPoint)
|
||||||
@ -623,27 +626,36 @@ void Editor::connectTileTraverseLinks(dtMeshTile* const baseTile, const bool lin
|
|||||||
if (distance == 0)
|
if (distance == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float baseEdgeDir[3], landEdgeDir[3];
|
// todo(amos): use height difference instead of slope angles.
|
||||||
rdVsub(baseEdgeDir, basePolyEpos, basePolySpos);
|
const float slopeAngle = rdMathFabsf(rdCalcSlopeAngle(basePolyEdgeMid, landPolyEdgeMid));
|
||||||
rdVsub(landEdgeDir, landPolyEpos, landPolySpos);
|
|
||||||
|
|
||||||
const float dotProduct = rdVdot(baseEdgeDir, landEdgeDir);
|
if (slopeAngle < TRAVERSE_OVERLAP_SLOPE_THRESHOLD)
|
||||||
|
{
|
||||||
|
float baseEdgeDir[3], landEdgeDir[3];
|
||||||
|
rdVsub(baseEdgeDir, basePolyEpos, basePolySpos);
|
||||||
|
rdVsub(landEdgeDir, landPolyEpos, landPolySpos);
|
||||||
|
|
||||||
// Edges facing the same direction should not be linked.
|
const float dotProduct = rdVdot(baseEdgeDir, landEdgeDir);
|
||||||
// Doing so causes links to go through from underneath
|
|
||||||
// geometry. E.g. we have an HVAC on a roof, and we try
|
// Edges facing the same direction should not be linked.
|
||||||
// to link our roof poly edge facing north to the edge
|
// Doing so causes links to go through from underneath
|
||||||
// of the poly on the HVAC also facing north, the link
|
// geometry. E.g. we have an HVAC on a roof, and we try
|
||||||
// will go through the HVAC and thus cause the NPC to
|
// to link our roof poly edge facing north to the edge
|
||||||
// jump through it.
|
// of the poly on the HVAC also facing north, the link
|
||||||
if (dotProduct > 0)
|
// will go through the HVAC and thus cause the NPC to
|
||||||
continue;
|
// jump through it.
|
||||||
|
// Another case where this is necessary is when having
|
||||||
|
// a land edge that connects with the base edge, this
|
||||||
|
// prevents the algorithm from establishing a parallel
|
||||||
|
// traverse link.
|
||||||
|
if (dotProduct > 0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
float t, s;
|
float t, s;
|
||||||
if (rdIntersectSegSeg2D(basePolySpos, basePolyEpos, landPolySpos, landPolyEpos, t, s))
|
if (rdIntersectSegSeg2D(basePolySpos, basePolyEpos, landPolySpos, landPolyEpos, t, s))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const float slopeAngle = rdMathFabsf(rdCalcSlopeAngle(basePolyEdgeMid, landPolyEdgeMid));
|
|
||||||
const bool samePolyGroup = basePoly->groupId == landPoly->groupId;
|
const bool samePolyGroup = basePoly->groupId == landPoly->groupId;
|
||||||
|
|
||||||
const TraverseType_e traverseType = GetBestTraverseType(slopeAngle, distance, samePolyGroup);
|
const TraverseType_e traverseType = GetBestTraverseType(slopeAngle, distance, samePolyGroup);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user