From f4f9fa4701c8a41a13289c2b7a8f421f6a21be81 Mon Sep 17 00:00:00 2001 From: elsid Date: Thu, 27 May 2021 01:59:07 +0200 Subject: [PATCH] Limit oscillating recast mesh object AABB by tile bounds AABB change outside recast mesh tile should not affect navmesh for this tile. --- .../oscillatingrecastmeshobject.cpp | 17 ++++++++++++++++- .../oscillatingrecastmeshobject.hpp | 4 +++- .../detournavigator/recastmeshmanager.cpp | 3 ++- .../detournavigator/recastmeshmanager.hpp | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/detournavigator/oscillatingrecastmeshobject.cpp b/components/detournavigator/oscillatingrecastmeshobject.cpp index 5b8423183..fbe4b77ff 100644 --- a/components/detournavigator/oscillatingrecastmeshobject.cpp +++ b/components/detournavigator/oscillatingrecastmeshobject.cpp @@ -1,9 +1,23 @@ #include "oscillatingrecastmeshobject.hpp" +#include "tilebounds.hpp" #include +#include + namespace DetourNavigator { + namespace + { + void limitBy(btAABB& aabb, const TileBounds& bounds) + { + aabb.m_min.setX(std::max(aabb.m_min.x(), static_cast(bounds.mMin.x()))); + aabb.m_min.setY(std::max(aabb.m_min.y(), static_cast(bounds.mMin.y()))); + aabb.m_max.setX(std::min(aabb.m_max.x(), static_cast(bounds.mMax.x()))); + aabb.m_max.setY(std::min(aabb.m_max.y(), static_cast(bounds.mMax.y()))); + } + } + OscillatingRecastMeshObject::OscillatingRecastMeshObject(RecastMeshObject&& impl, std::size_t lastChangeRevision) : mImpl(std::move(impl)) , mLastChangeRevision(lastChangeRevision) @@ -19,7 +33,7 @@ namespace DetourNavigator } 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(); if (!mImpl.update(transform, areaType)) @@ -37,6 +51,7 @@ namespace DetourNavigator } const btAABB currentAabb = mAabb; mAabb.merge(BulletHelpers::getAabb(mImpl.getShape(), transform)); + limitBy(mAabb, bounds); return currentAabb != mAabb; } } diff --git a/components/detournavigator/oscillatingrecastmeshobject.hpp b/components/detournavigator/oscillatingrecastmeshobject.hpp index 78a0c4b68..f8aabce62 100644 --- a/components/detournavigator/oscillatingrecastmeshobject.hpp +++ b/components/detournavigator/oscillatingrecastmeshobject.hpp @@ -3,6 +3,7 @@ #include "areatype.hpp" #include "recastmeshobject.hpp" +#include "tilebounds.hpp" #include #include @@ -15,7 +16,8 @@ namespace DetourNavigator explicit OscillatingRecastMeshObject(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; } diff --git a/components/detournavigator/recastmeshmanager.cpp b/components/detournavigator/recastmeshmanager.cpp index 5fbcedff6..e168a3304 100644 --- a/components/detournavigator/recastmeshmanager.cpp +++ b/components/detournavigator/recastmeshmanager.cpp @@ -5,6 +5,7 @@ namespace DetourNavigator RecastMeshManager::RecastMeshManager(const Settings& settings, const TileBounds& bounds, std::size_t generation) : mGeneration(generation) , mMeshBuilder(settings, bounds) + , mTileBounds(bounds) { } @@ -29,7 +30,7 @@ namespace DetourNavigator return false; const std::size_t lastChangeRevision = mLastNavMeshReportedChange.has_value() ? mLastNavMeshReportedChange->mRevision : mRevision; - if (!object->second->update(transform, areaType, lastChangeRevision)) + if (!object->second->update(transform, areaType, lastChangeRevision, mTileBounds)) return false; ++mRevision; return true; diff --git a/components/detournavigator/recastmeshmanager.hpp b/components/detournavigator/recastmeshmanager.hpp index ac17a347b..e1606f0a9 100644 --- a/components/detournavigator/recastmeshmanager.hpp +++ b/components/detournavigator/recastmeshmanager.hpp @@ -65,6 +65,7 @@ namespace DetourNavigator std::size_t mRevision = 0; std::size_t mGeneration; RecastMeshBuilder mMeshBuilder; + TileBounds mTileBounds; std::list mObjectsOrder; std::unordered_map::iterator> mObjects; std::list mWaterOrder;