mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-08 11:38:19 +03:00
58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
![]() |
#include "recastmeshmanager.hpp"
|
||
|
|
||
|
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
|
||
|
|
||
|
namespace DetourNavigator
|
||
|
{
|
||
|
RecastMeshManager::RecastMeshManager(const Settings& settings)
|
||
|
: mShouldRebuild(false)
|
||
|
, mMeshBuilder(settings)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool RecastMeshManager::addObject(std::size_t id, const btHeightfieldTerrainShape& shape, const btTransform& transform)
|
||
|
{
|
||
|
if (!mObjects.insert(std::make_pair(id, Object {&shape, transform})).second)
|
||
|
return false;
|
||
|
mShouldRebuild = true;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool RecastMeshManager::addObject(std::size_t id, const btConcaveShape& shape, const btTransform& transform)
|
||
|
{
|
||
|
if (!mObjects.insert(std::make_pair(id, Object {&shape, transform})).second)
|
||
|
return false;
|
||
|
mShouldRebuild = true;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool RecastMeshManager::removeObject(std::size_t id)
|
||
|
{
|
||
|
if (!mObjects.erase(id))
|
||
|
return false;
|
||
|
mShouldRebuild = true;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
std::shared_ptr<RecastMesh> RecastMeshManager::getMesh()
|
||
|
{
|
||
|
rebuild();
|
||
|
return mMeshBuilder.create();
|
||
|
}
|
||
|
|
||
|
void RecastMeshManager::rebuild()
|
||
|
{
|
||
|
if (!mShouldRebuild)
|
||
|
return;
|
||
|
mMeshBuilder.reset();
|
||
|
for (const auto& v : mObjects)
|
||
|
{
|
||
|
if (v.second.mShape->getShapeType() == TERRAIN_SHAPE_PROXYTYPE)
|
||
|
mMeshBuilder.addObject(*static_cast<const btHeightfieldTerrainShape*>(v.second.mShape), v.second.mTransform);
|
||
|
else if (v.second.mShape->isConcave())
|
||
|
mMeshBuilder.addObject(*static_cast<const btConcaveShape*>(v.second.mShape), v.second.mTransform);
|
||
|
}
|
||
|
mShouldRebuild = false;
|
||
|
}
|
||
|
}
|