1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-09 21:44:54 +00:00

Use different object id for avoid shape

Otherwise addObject will ignore it as a duplicate and resulting recastmesh will
not match generated by the engine causing navmeshdb cache miss.
This commit is contained in:
elsid 2023-05-14 14:06:53 +02:00
parent a8a76f9a05
commit 2a7b105484
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

View File

@ -3,11 +3,13 @@
#include <components/bullethelpers/aabb.hpp> #include <components/bullethelpers/aabb.hpp>
#include <components/debug/debugging.hpp> #include <components/debug/debugging.hpp>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/detournavigator/debug.hpp>
#include <components/detournavigator/gettilespositions.hpp> #include <components/detournavigator/gettilespositions.hpp>
#include <components/detournavigator/objectid.hpp> #include <components/detournavigator/objectid.hpp>
#include <components/detournavigator/recastmesh.hpp> #include <components/detournavigator/recastmesh.hpp>
#include <components/detournavigator/settings.hpp> #include <components/detournavigator/settings.hpp>
#include <components/detournavigator/tilecachedrecastmeshmanager.hpp> #include <components/detournavigator/tilecachedrecastmeshmanager.hpp>
#include <components/esm/refid.hpp>
#include <components/esm3/cellref.hpp> #include <components/esm3/cellref.hpp>
#include <components/esm3/esmreader.hpp> #include <components/esm3/esmreader.hpp>
#include <components/esm3/loadcell.hpp> #include <components/esm3/loadcell.hpp>
@ -17,6 +19,7 @@
#include <components/esmloader/lessbyid.hpp> #include <components/esmloader/lessbyid.hpp>
#include <components/esmloader/record.hpp> #include <components/esmloader/record.hpp>
#include <components/misc/resourcehelpers.hpp> #include <components/misc/resourcehelpers.hpp>
#include <components/misc/strings/conversion.hpp>
#include <components/misc/strings/lower.hpp> #include <components/misc/strings/lower.hpp>
#include <components/navmeshtool/protocol.hpp> #include <components/navmeshtool/protocol.hpp>
#include <components/resource/bulletshapemanager.hpp> #include <components/resource/bulletshapemanager.hpp>
@ -29,8 +32,8 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <algorithm> #include <algorithm>
#include <components/esm/refid.hpp>
#include <memory> #include <memory>
#include <sstream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <string_view> #include <string_view>
@ -219,6 +222,16 @@ namespace NavMeshTool
const std::vector<std::byte> data = serialize(value); const std::vector<std::byte> data = serialize(value);
getRawStderr().write(reinterpret_cast<const char*>(data.data()), static_cast<std::streamsize>(data.size())); getRawStderr().write(reinterpret_cast<const char*>(data.data()), static_cast<std::streamsize>(data.size()));
} }
std::string makeAddObjectErrorMessage(
ObjectId objectId, DetourNavigator::AreaType areaType, const CollisionShape& shape)
{
std::ostringstream stream;
stream << "Failed to add object to recast mesh objectId=" << objectId.value() << " areaType=" << areaType
<< " fileName=" << shape.getInstance()->mFileName
<< " fileHash=" << Misc::StringUtils::toHex(shape.getInstance()->mFileHash);
return stream.str();
}
} }
WorldspaceNavMeshInput::WorldspaceNavMeshInput( WorldspaceNavMeshInput::WorldspaceNavMeshInput(
@ -318,14 +331,19 @@ namespace NavMeshTool
const CollisionShape shape(object.getShapeInstance(), *object.getCollisionObject().getCollisionShape(), const CollisionShape shape(object.getShapeInstance(), *object.getCollisionObject().getCollisionShape(),
object.getObjectTransform()); object.getObjectTransform());
navMeshInput.mTileCachedRecastMeshManager.addObject( if (!navMeshInput.mTileCachedRecastMeshManager.addObject(
objectId, shape, transform, DetourNavigator::AreaType_ground, guard.get()); objectId, shape, transform, DetourNavigator::AreaType_ground, guard.get()))
throw std::logic_error(
makeAddObjectErrorMessage(objectId, DetourNavigator::AreaType_ground, shape));
if (const btCollisionShape* avoid = object.getShapeInstance()->mAvoidCollisionShape.get()) if (const btCollisionShape* avoid = object.getShapeInstance()->mAvoidCollisionShape.get())
{ {
const ObjectId avoidObjectId(++objectsCounter);
const CollisionShape avoidShape(object.getShapeInstance(), *avoid, object.getObjectTransform()); const CollisionShape avoidShape(object.getShapeInstance(), *avoid, object.getObjectTransform());
navMeshInput.mTileCachedRecastMeshManager.addObject( if (!navMeshInput.mTileCachedRecastMeshManager.addObject(
objectId, avoidShape, transform, DetourNavigator::AreaType_null, guard.get()); avoidObjectId, avoidShape, transform, DetourNavigator::AreaType_null, guard.get()))
throw std::logic_error(
makeAddObjectErrorMessage(avoidObjectId, DetourNavigator::AreaType_null, avoidShape));
} }
data.mObjects.emplace_back(std::move(object)); data.mObjects.emplace_back(std::move(object));