2018-05-26 14:44:25 +00:00
|
|
|
#include "recastmeshobject.hpp"
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
|
|
|
|
#include <BulletCollision/CollisionShapes/btCompoundShape.h>
|
|
|
|
|
2018-09-30 22:33:25 +00:00
|
|
|
#include <cassert>
|
2018-05-26 14:44:25 +00:00
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2021-04-18 15:31:21 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType,
|
|
|
|
std::vector<RecastMeshObject>& children)
|
|
|
|
{
|
|
|
|
assert(static_cast<std::size_t>(shape.getNumChildShapes()) == children.size());
|
|
|
|
bool result = false;
|
|
|
|
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
|
|
|
|
{
|
|
|
|
assert(shape.getChildShape(i) == std::addressof(children[static_cast<std::size_t>(i)].getShape()));
|
|
|
|
result = children[static_cast<std::size_t>(i)].update(shape.getChildTransform(i), areaType) || result;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2021-08-01 00:13:55 +00:00
|
|
|
|
2021-08-04 09:35:53 +00:00
|
|
|
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const osg::Referenced>& holder,
|
2021-08-01 00:13:55 +00:00
|
|
|
const btCompoundShape& shape, const AreaType areaType)
|
|
|
|
{
|
|
|
|
std::vector<RecastMeshObject> result;
|
|
|
|
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
|
|
|
|
{
|
2021-08-04 09:35:53 +00:00
|
|
|
const CollisionShape collisionShape {holder, *shape.getChildShape(i)};
|
2021-08-01 00:13:55 +00:00
|
|
|
result.emplace_back(collisionShape, shape.getChildTransform(i), areaType);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-04 09:35:53 +00:00
|
|
|
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const osg::Referenced>& holder,
|
2021-08-01 00:13:55 +00:00
|
|
|
const btCollisionShape& shape, const AreaType areaType)
|
|
|
|
{
|
|
|
|
if (shape.isCompound())
|
2021-08-04 09:35:53 +00:00
|
|
|
return makeChildrenObjects(holder, static_cast<const btCompoundShape&>(shape), areaType);
|
2021-08-01 00:13:55 +00:00
|
|
|
return std::vector<RecastMeshObject>();
|
|
|
|
}
|
2021-04-18 15:31:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-01 00:13:55 +00:00
|
|
|
RecastMeshObject::RecastMeshObject(const CollisionShape& shape, const btTransform& transform,
|
2018-07-18 19:09:50 +00:00
|
|
|
const AreaType areaType)
|
2021-08-04 09:35:53 +00:00
|
|
|
: mHolder(shape.getHolder())
|
2021-08-01 00:13:55 +00:00
|
|
|
, mShape(shape.getShape())
|
2018-05-26 14:44:25 +00:00
|
|
|
, mTransform(transform)
|
2018-07-18 19:09:50 +00:00
|
|
|
, mAreaType(areaType)
|
2021-08-01 00:13:55 +00:00
|
|
|
, mLocalScaling(mShape.get().getLocalScaling())
|
2021-08-04 09:35:53 +00:00
|
|
|
, mChildren(makeChildrenObjects(mHolder, mShape.get(), mAreaType))
|
2018-05-26 14:44:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-18 19:09:50 +00:00
|
|
|
bool RecastMeshObject::update(const btTransform& transform, const AreaType areaType)
|
2018-05-26 14:44:25 +00:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
if (!(mTransform == transform))
|
|
|
|
{
|
|
|
|
mTransform = transform;
|
|
|
|
result = true;
|
|
|
|
}
|
2018-07-18 19:09:50 +00:00
|
|
|
if (mAreaType != areaType)
|
2018-07-12 08:44:11 +00:00
|
|
|
{
|
2018-07-18 19:09:50 +00:00
|
|
|
mAreaType = areaType;
|
2018-07-12 08:44:11 +00:00
|
|
|
result = true;
|
|
|
|
}
|
2019-03-03 12:51:02 +00:00
|
|
|
if (!(mLocalScaling == mShape.get().getLocalScaling()))
|
|
|
|
{
|
|
|
|
mLocalScaling = mShape.get().getLocalScaling();
|
|
|
|
result = true;
|
|
|
|
}
|
2018-05-26 14:44:25 +00:00
|
|
|
if (mShape.get().isCompound())
|
2018-07-18 19:09:50 +00:00
|
|
|
result = updateCompoundObject(static_cast<const btCompoundShape&>(mShape.get()), mAreaType, mChildren)
|
|
|
|
|| result;
|
2018-05-26 14:44:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|