Skip to content

Commit

Permalink
[Tool] Add hit for liquid mesh
Browse files Browse the repository at this point in the history
We can now simulate path follow on liquid navmesh too
  • Loading branch information
cyberium committed Aug 4, 2023
1 parent b788602 commit a03e728
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions contrib/recastdemomod/Include/GeomData.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class GeomData

private:
void ComputeBounds();
bool MeshHitTest(MeshInfos const* mesh, float* src, float* dst, float& dist) const;
MeshObjectsMap m_MeshObjectsMap;
BuildContext* m_Ctx;
unsigned int m_MapId;
Expand Down
58 changes: 54 additions & 4 deletions contrib/recastdemomod/Source/GeomData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,52 @@ bool GeomData::RaycastMesh(MeshDetails const* mesh, float* src, float* dst, floa
return hit;
}

// check hit on either map mesh and liquid mesh
bool GeomData::MeshHitTest(MeshInfos const* mesh, float* src, float* dst, float& dist) const
{
bool result = false;
if (mesh)
{
bool mHit = false;
bool lHit = false;
float mDist = FLT_MAX;
float lDist = FLT_MAX;
if (mesh->GetSolidMesh())
{
mHit = RaycastMesh(mesh->GetSolidMesh(), src, dst, mDist);
}

if (mesh->GetLiquidMesh())
{
lHit = RaycastMesh(mesh->GetLiquidMesh(), src, dst, lDist);
}

if (mHit || lHit)
{
if (mHit && lHit)
{
if (mDist > lDist)
{
dist = lDist;
}
else
{
dist = mDist;
}
}
else if (mHit)
dist = mDist;
else
dist = lDist;

result = true;
}

}

return result;
}

bool GeomData::RaycastMesh(float* src, float* dst, float& tmin) const
{
if (m_MeshObjectsMap.empty())
Expand All @@ -626,12 +672,15 @@ bool GeomData::RaycastMesh(float* src, float* dst, float& tmin) const
MeshInfos const* mmi = mo->GetMap();
MeshInfos const* vmmi = mo->GetVMap();

if (mmi && mmi->GetSolidMesh())
vmapHit = RaycastMesh(mmi->GetSolidMesh(), src, dst, vmapDist);
// test hit on map data if any
if (mmi)
mapHit = MeshHitTest(mmi, src, dst, mapDist);

if (vmmi && vmmi->GetSolidMesh())
mapHit = RaycastMesh(vmmi->GetSolidMesh(), src, dst, mapDist);
// test hit on vmap data if any
if (vmmi)
vmapHit = MeshHitTest(vmmi, src, dst, vmapDist);

// take the most near hit we have
if (mapHit || vmapHit)
{
if (mapHit && vmapHit)
Expand All @@ -648,6 +697,7 @@ bool GeomData::RaycastMesh(float* src, float* dst, float& tmin) const
else
tmin = vmapDist;

// break out of the while loop
break;
}

Expand Down

0 comments on commit a03e728

Please sign in to comment.