handle water verts

now we correctly mark water verts as water area and add the swim flag to them
This commit is contained in:
marauder2k7 2025-07-25 12:41:59 +01:00
parent 5c2ed84b24
commit edf4d47be0
2 changed files with 44 additions and 4 deletions

View file

@ -222,6 +222,9 @@ NavMesh::NavMesh()
mBuilding = false;
mCurLinkID = 0;
mWaterVertStart = 0;
mWaterTriStart = 0;
}
NavMesh::~NavMesh()
@ -488,6 +491,8 @@ bool NavMesh::getLinkDir(U32 idx)
{
return mLinkDirs[idx];
}
return false;
}
F32 NavMesh::getLinkRadius(U32 idx)
@ -496,6 +501,8 @@ F32 NavMesh::getLinkRadius(U32 idx)
{
return mLinkRads[idx];
}
return -1.0f;
}
void NavMesh::setLinkDir(U32 idx, bool biDir)
@ -680,8 +687,8 @@ bool NavMesh::build(bool background, bool saveIntermediates)
getContainer()->findObjects(worldBox, StaticObjectType | DynamicShapeObjectType, buildCallback, &info);
// Parse water objects into the same list, but remember how much geometry was /not/ water.
U32 nonWaterVertCount = m_geo->getVertCount();
U32 nonWaterTriCount = m_geo->getTriCount();
mWaterVertStart = m_geo->getVertCount();
mWaterTriStart = m_geo->getTriCount();
if (mWaterMethod != Ignore)
{
getContainer()->findObjects(worldBox, WaterObjectType, buildCallback, &info);
@ -912,8 +919,8 @@ void NavMesh::buildNextTile()
getContainer()->findObjects(worldBox, StaticObjectType | DynamicShapeObjectType, buildCallback, &info);
// Parse water objects into the same list, but remember how much geometry was /not/ water.
U32 nonWaterVertCount = m_geo->getVertCount();
U32 nonWaterTriCount = m_geo->getTriCount();
mWaterVertStart = m_geo->getVertCount();
mWaterTriStart = m_geo->getTriCount();
if (mWaterMethod != Ignore)
{
getContainer()->findObjects(worldBox, WaterObjectType, buildCallback, &info);
@ -1084,6 +1091,37 @@ unsigned char *NavMesh::buildTileData(const Tile &tile, U32 &dataSize)
rcMarkWalkableTriangles(ctx, m_cfg.walkableSlopeAngle,
m_geo->getVerts(), m_geo->getVertCount(), ctris, nctris, m_triareas);
// Post-process triangle areas if we need to capture water.
if (mWaterMethod != Ignore)
{
for (int t = 0; t < nctris; ++t)
{
const int* tri = &ctris[t * 3];
bool isWater = false;
for (int j = 0; j < 3; ++j)
{
if (tri[j] >= mWaterVertStart)
{
isWater = true;
break;
}
}
if (isWater)
{
if (mWaterMethod == Solid)
{
m_triareas[t] = WaterArea; // Custom enum you define, like 64
}
else if (mWaterMethod == Impassable)
{
m_triareas[t] = RC_NULL_AREA;
}
}
}
}
if (!rcRasterizeTriangles(ctx, m_geo->getVerts(), m_geo->getVertCount(), ctris, m_triareas, nctris, *m_solid, m_cfg.walkableClimb))
return NULL;
}

View file

@ -443,6 +443,8 @@ protected:
rcPolyMeshDetail* m_dmesh;
rcConfig m_cfg;
DrawMode m_drawMode;
U32 mWaterVertStart;
U32 mWaterTriStart;
void cleanup();
};