Support btCompoundShape for RecastMesh

pull/1633/head
elsid 7 years ago
parent 373adc6ec4
commit dd5e6a61a3
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -3,6 +3,7 @@
#include <limits>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
#include <components/debug/debuglog.hpp>
#include <components/loadinglistener/loadinglistener.hpp>
@ -83,12 +84,9 @@ namespace
if (const auto object = physics.getObject(ptr))
{
if (const auto concaveShape = dynamic_cast<const btConcaveShape*>(object->getShapeInstance()->mCollisionShape))
{
const auto navigator = MWBase::Environment::get().getWorld()->getNavigator();
navigator->addObject(reinterpret_cast<std::size_t>(object), *concaveShape,
object->getCollisionObject()->getWorldTransform());
}
const auto navigator = MWBase::Environment::get().getWorld()->getNavigator();
navigator->addObject(reinterpret_cast<std::size_t>(object), *object->getCollisionObject()->getCollisionShape(),
object->getCollisionObject()->getWorldTransform());
}
else if (const auto actor = physics.getActor(ptr))
{

@ -5,7 +5,14 @@ namespace DetourNavigator
{
CachedRecastMeshManager::CachedRecastMeshManager(const Settings& settings)
: mImpl(settings)
{}
bool CachedRecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform)
{
if (!mImpl.addObject(id, shape, transform))
return false;
mCached.reset();
return true;
}
boost::optional<RecastMeshManager::Object> CachedRecastMeshManager::removeObject(std::size_t id)
@ -21,5 +28,5 @@ namespace DetourNavigator
if (!mCached)
mCached = mImpl.getMesh();
return mCached;
}
}
}

@ -12,14 +12,7 @@ namespace DetourNavigator
public:
CachedRecastMeshManager(const Settings& settings);
template <class T>
bool addObject(std::size_t id, const T& shape, const btTransform& transform)
{
if (!mImpl.addObject(id, shape, transform))
return false;
mCached.reset();
return true;
}
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform);
boost::optional<RecastMeshManager::Object> removeObject(std::size_t id);

@ -25,6 +25,11 @@ namespace DetourNavigator
mNavMeshManager.reset(agentHalfExtents);
}
bool Navigator::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform)
{
return mNavMeshManager.addObject(id, shape, transform);
}
bool Navigator::removeObject(std::size_t id)
{
return mNavMeshManager.removeObject(id);

@ -17,11 +17,7 @@ namespace DetourNavigator
void removeAgent(const osg::Vec3f& agentHalfExtents);
template <class T>
bool addObject(std::size_t id, const T& shape, const btTransform& transform)
{
return mNavMeshManager.addObject(id, shape, transform);
}
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform);
bool removeObject(std::size_t id);

@ -19,6 +19,15 @@ namespace DetourNavigator
, mAsyncNavMeshUpdater(settings)
{}
bool NavMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform)
{
if (!mRecastMeshManager.addObject(id, shape, transform))
return false;
++mRevision;
addChangedTiles(shape, transform);
return true;
}
bool NavMeshManager::removeObject(std::size_t id)
{
const auto object = mRecastMeshManager.removeObject(id);

@ -23,15 +23,7 @@ namespace DetourNavigator
public:
NavMeshManager(const Settings& settings);
template <class T>
bool addObject(std::size_t id, const T& shape, const btTransform& transform)
{
if (!mRecastMeshManager.addObject(id, shape, transform))
return false;
++mRevision;
addChangedTiles(shape, transform);
return true;
}
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform);
bool removeObject(std::size_t id);

@ -1,12 +1,15 @@
#include "recastmeshbuilder.hpp"
#include "chunkytrimesh.hpp"
#include "debug.hpp"
#include "settings.hpp"
#include "settingsutils.hpp"
#include "exceptions.hpp"
#include <components/bullethelpers/processtrianglecallback.hpp>
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
#include <BulletCollision/CollisionShapes/btCompoundShape.h>
#include <BulletCollision/CollisionShapes/btConcaveShape.h>
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
namespace
{
@ -22,7 +25,25 @@ namespace DetourNavigator
RecastMeshBuilder::RecastMeshBuilder(const Settings& settings)
: mSettings(settings)
{}
void RecastMeshBuilder::addObject(const btCollisionShape& shape, const btTransform& transform)
{
if (shape.isCompound())
return addObject(static_cast<const btCompoundShape&>(shape), transform);
else if (shape.getShapeType() == TERRAIN_SHAPE_PROXYTYPE)
return addObject(static_cast<const btHeightfieldTerrainShape&>(shape), transform);
else if (shape.isConcave())
return addObject(static_cast<const btConcaveShape&>(shape), transform);
std::ostringstream message;
message << "Unsupported shape type: " << BroadphaseNativeTypes(shape.getShapeType());
throw InvalidArgument(message.str());
}
void RecastMeshBuilder::addObject(const btCompoundShape& shape, const btTransform& transform)
{
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
addObject(*shape.getChildShape(i), transform * shape.getChildTransform(i));
}
void RecastMeshBuilder::addObject(const btConcaveShape& shape, const btTransform& transform)

@ -3,6 +3,8 @@
#include "recastmesh.hpp"
class btCollisionShape;
class btCompoundShape;
class btConcaveShape;
class btHeightfieldTerrainShape;
class btTransform;
@ -16,6 +18,10 @@ namespace DetourNavigator
public:
RecastMeshBuilder(const Settings& settings);
void addObject(const btCollisionShape& shape, const btTransform& transform);
void addObject(const btCompoundShape& shape, const btTransform& transform);
void addObject(const btConcaveShape& shape, const btTransform& transform);
void addObject(const btHeightfieldTerrainShape& shape, const btTransform& transform);

@ -9,15 +9,7 @@ namespace DetourNavigator
, 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)
bool RecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform)
{
if (!mObjects.insert(std::make_pair(id, Object {&shape, transform})).second)
return false;

@ -24,9 +24,7 @@ namespace DetourNavigator
RecastMeshManager(const Settings& settings);
bool addObject(std::size_t id, const btHeightfieldTerrainShape& shape, const btTransform& transform);
bool addObject(std::size_t id, const btConcaveShape& shape, const btTransform& transform);
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform);
boost::optional<Object> removeObject(std::size_t id);

Loading…
Cancel
Save