diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index c0e79352f8..74d4d28383 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1337,6 +1337,8 @@ namespace MWWorld if (mPhysics->getActor(ptr)) mNavigator->addAgent(getPathfindingHalfExtents(ptr)); + else if (const auto object = mPhysics->getObject(ptr)) + mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator; } void World::rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, bool adjust) @@ -1570,19 +1572,20 @@ namespace MWWorld void World::updateNavigator() { - bool updated = false; - mPhysics->forEachAnimatedObject([&] (const MWPhysics::Object* object) { - updated = updateNavigatorObject(object) || updated; + mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator; }); for (const auto& door : mDoorStates) if (const auto object = mPhysics->getObject(door.first)) - updated = updateNavigatorObject(object) || updated; + mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator; - if (updated) + if (mShouldUpdateNavigator) + { mNavigator->update(getPlayerPtr().getRefData().getPosition().asVec3()); + mShouldUpdateNavigator = false; + } } bool World::updateNavigatorObject(const MWPhysics::Object* object) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index f0c28ea9e2..45653ded2e 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -112,6 +112,7 @@ namespace MWWorld std::string mUserDataPath; osg::Vec3f mDefaultHalfExtents; + bool mShouldUpdateNavigator = false; // not implemented World (const World&); diff --git a/apps/openmw_test_suite/detournavigator/recastmeshobject.cpp b/apps/openmw_test_suite/detournavigator/recastmeshobject.cpp index 9b30cadd7a..a3606f8273 100644 --- a/apps/openmw_test_suite/detournavigator/recastmeshobject.cpp +++ b/apps/openmw_test_suite/detournavigator/recastmeshobject.cpp @@ -69,4 +69,11 @@ namespace object.update(mTransform, AreaType_ground); EXPECT_FALSE(object.update(mTransform, AreaType_ground)); } + + TEST_F(DetourNavigatorRecastMeshObjectTest, update_for_changed_local_scaling_should_return_true) + { + RecastMeshObject object(mBoxShape, mTransform, AreaType_ground); + mBoxShape.setLocalScaling(btVector3(2, 2, 2)); + EXPECT_TRUE(object.update(mTransform, AreaType_ground)); + } } diff --git a/components/detournavigator/recastmeshobject.cpp b/components/detournavigator/recastmeshobject.cpp index 24d3e6b5a8..aac0b4c3c8 100644 --- a/components/detournavigator/recastmeshobject.cpp +++ b/components/detournavigator/recastmeshobject.cpp @@ -13,6 +13,7 @@ namespace DetourNavigator : mShape(shape) , mTransform(transform) , mAreaType(areaType) + , mLocalScaling(shape.getLocalScaling()) , mChildren(makeChildrenObjects(shape, mAreaType)) { } @@ -30,6 +31,11 @@ namespace DetourNavigator mAreaType = areaType; result = true; } + if (!(mLocalScaling == mShape.get().getLocalScaling())) + { + mLocalScaling = mShape.get().getLocalScaling(); + result = true; + } if (mShape.get().isCompound()) result = updateCompoundObject(static_cast(mShape.get()), mAreaType, mChildren) || result; diff --git a/components/detournavigator/recastmeshobject.hpp b/components/detournavigator/recastmeshobject.hpp index aff4681222..f25647ae50 100644 --- a/components/detournavigator/recastmeshobject.hpp +++ b/components/detournavigator/recastmeshobject.hpp @@ -39,6 +39,7 @@ namespace DetourNavigator std::reference_wrapper mShape; btTransform mTransform; AreaType mAreaType; + btVector3 mLocalScaling; std::vector mChildren; static bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType,