Limit oscillating recast mesh object AABB by tile bounds

AABB change outside recast mesh tile should not affect navmesh for this tile.
pull/593/head
elsid 4 years ago
parent d122e184cc
commit f4f9fa4701
No known key found for this signature in database
GPG Key ID: D27B8E8D10A2896B

@ -1,9 +1,23 @@
#include "oscillatingrecastmeshobject.hpp" #include "oscillatingrecastmeshobject.hpp"
#include "tilebounds.hpp"
#include <components/bullethelpers/aabb.hpp> #include <components/bullethelpers/aabb.hpp>
#include <algorithm>
namespace DetourNavigator namespace DetourNavigator
{ {
namespace
{
void limitBy(btAABB& aabb, const TileBounds& bounds)
{
aabb.m_min.setX(std::max(aabb.m_min.x(), static_cast<btScalar>(bounds.mMin.x())));
aabb.m_min.setY(std::max(aabb.m_min.y(), static_cast<btScalar>(bounds.mMin.y())));
aabb.m_max.setX(std::min(aabb.m_max.x(), static_cast<btScalar>(bounds.mMax.x())));
aabb.m_max.setY(std::min(aabb.m_max.y(), static_cast<btScalar>(bounds.mMax.y())));
}
}
OscillatingRecastMeshObject::OscillatingRecastMeshObject(RecastMeshObject&& impl, std::size_t lastChangeRevision) OscillatingRecastMeshObject::OscillatingRecastMeshObject(RecastMeshObject&& impl, std::size_t lastChangeRevision)
: mImpl(std::move(impl)) : mImpl(std::move(impl))
, mLastChangeRevision(lastChangeRevision) , mLastChangeRevision(lastChangeRevision)
@ -19,7 +33,7 @@ namespace DetourNavigator
} }
bool OscillatingRecastMeshObject::update(const btTransform& transform, const AreaType areaType, bool OscillatingRecastMeshObject::update(const btTransform& transform, const AreaType areaType,
std::size_t lastChangeRevision) std::size_t lastChangeRevision, const TileBounds& bounds)
{ {
const btTransform oldTransform = mImpl.getTransform(); const btTransform oldTransform = mImpl.getTransform();
if (!mImpl.update(transform, areaType)) if (!mImpl.update(transform, areaType))
@ -37,6 +51,7 @@ namespace DetourNavigator
} }
const btAABB currentAabb = mAabb; const btAABB currentAabb = mAabb;
mAabb.merge(BulletHelpers::getAabb(mImpl.getShape(), transform)); mAabb.merge(BulletHelpers::getAabb(mImpl.getShape(), transform));
limitBy(mAabb, bounds);
return currentAabb != mAabb; return currentAabb != mAabb;
} }
} }

@ -3,6 +3,7 @@
#include "areatype.hpp" #include "areatype.hpp"
#include "recastmeshobject.hpp" #include "recastmeshobject.hpp"
#include "tilebounds.hpp"
#include <LinearMath/btTransform.h> #include <LinearMath/btTransform.h>
#include <BulletCollision/Gimpact/btBoxCollision.h> #include <BulletCollision/Gimpact/btBoxCollision.h>
@ -15,7 +16,8 @@ namespace DetourNavigator
explicit OscillatingRecastMeshObject(RecastMeshObject&& impl, std::size_t lastChangeRevision); explicit OscillatingRecastMeshObject(RecastMeshObject&& impl, std::size_t lastChangeRevision);
explicit OscillatingRecastMeshObject(const RecastMeshObject& impl, std::size_t lastChangeRevision); explicit OscillatingRecastMeshObject(const RecastMeshObject& impl, std::size_t lastChangeRevision);
bool update(const btTransform& transform, const AreaType areaType, std::size_t lastChangeRevision); bool update(const btTransform& transform, const AreaType areaType, std::size_t lastChangeRevision,
const TileBounds& bounds);
const RecastMeshObject& getImpl() const { return mImpl; } const RecastMeshObject& getImpl() const { return mImpl; }

@ -5,6 +5,7 @@ namespace DetourNavigator
RecastMeshManager::RecastMeshManager(const Settings& settings, const TileBounds& bounds, std::size_t generation) RecastMeshManager::RecastMeshManager(const Settings& settings, const TileBounds& bounds, std::size_t generation)
: mGeneration(generation) : mGeneration(generation)
, mMeshBuilder(settings, bounds) , mMeshBuilder(settings, bounds)
, mTileBounds(bounds)
{ {
} }
@ -29,7 +30,7 @@ namespace DetourNavigator
return false; return false;
const std::size_t lastChangeRevision = mLastNavMeshReportedChange.has_value() const std::size_t lastChangeRevision = mLastNavMeshReportedChange.has_value()
? mLastNavMeshReportedChange->mRevision : mRevision; ? mLastNavMeshReportedChange->mRevision : mRevision;
if (!object->second->update(transform, areaType, lastChangeRevision)) if (!object->second->update(transform, areaType, lastChangeRevision, mTileBounds))
return false; return false;
++mRevision; ++mRevision;
return true; return true;

@ -65,6 +65,7 @@ namespace DetourNavigator
std::size_t mRevision = 0; std::size_t mRevision = 0;
std::size_t mGeneration; std::size_t mGeneration;
RecastMeshBuilder mMeshBuilder; RecastMeshBuilder mMeshBuilder;
TileBounds mTileBounds;
std::list<OscillatingRecastMeshObject> mObjectsOrder; std::list<OscillatingRecastMeshObject> mObjectsOrder;
std::unordered_map<ObjectId, std::list<OscillatingRecastMeshObject>::iterator> mObjects; std::unordered_map<ObjectId, std::list<OscillatingRecastMeshObject>::iterator> mObjects;
std::list<Water> mWaterOrder; std::list<Water> mWaterOrder;

Loading…
Cancel
Save