1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 12:39:55 +00:00

Merge branch 'recast_mesh_object' into 'master'

Store holder only in parent RecastMeshObject

See merge request OpenMW/openmw!1332
This commit is contained in:
psi29a 2021-11-02 20:27:49 +00:00
commit cb3ab21c13
2 changed files with 46 additions and 40 deletions

View File

@ -11,7 +11,7 @@ namespace DetourNavigator
namespace namespace
{ {
bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType, bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType,
std::vector<RecastMeshObject>& children) std::vector<ChildRecastMeshObject>& children)
{ {
assert(static_cast<std::size_t>(shape.getNumChildShapes()) == children.size()); assert(static_cast<std::size_t>(shape.getNumChildShapes()) == children.size());
bool result = false; bool result = false;
@ -23,39 +23,33 @@ namespace DetourNavigator
return result; return result;
} }
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const osg::Referenced>& holder, std::vector<ChildRecastMeshObject> makeChildrenObjects(const btCompoundShape& shape, const AreaType areaType)
const btCompoundShape& shape, const AreaType areaType)
{ {
std::vector<RecastMeshObject> result; std::vector<ChildRecastMeshObject> result;
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i) for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
{ result.emplace_back(*shape.getChildShape(i), shape.getChildTransform(i), areaType);
const CollisionShape collisionShape {holder, *shape.getChildShape(i)};
result.emplace_back(collisionShape, shape.getChildTransform(i), areaType);
}
return result; return result;
} }
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const osg::Referenced>& holder, std::vector<ChildRecastMeshObject> makeChildrenObjects(const btCollisionShape& shape, const AreaType areaType)
const btCollisionShape& shape, const AreaType areaType)
{ {
if (shape.isCompound()) if (shape.isCompound())
return makeChildrenObjects(holder, static_cast<const btCompoundShape&>(shape), areaType); return makeChildrenObjects(static_cast<const btCompoundShape&>(shape), areaType);
return std::vector<RecastMeshObject>(); return {};
} }
} }
RecastMeshObject::RecastMeshObject(const CollisionShape& shape, const btTransform& transform, ChildRecastMeshObject::ChildRecastMeshObject(const btCollisionShape& shape, const btTransform& transform,
const AreaType areaType) const AreaType areaType)
: mHolder(shape.getHolder()) : mShape(shape)
, mShape(shape.getShape())
, mTransform(transform) , mTransform(transform)
, mAreaType(areaType) , mAreaType(areaType)
, mLocalScaling(mShape.get().getLocalScaling()) , mLocalScaling(shape.getLocalScaling())
, mChildren(makeChildrenObjects(mHolder, mShape.get(), mAreaType)) , mChildren(makeChildrenObjects(shape, mAreaType))
{ {
} }
bool RecastMeshObject::update(const btTransform& transform, const AreaType areaType) bool ChildRecastMeshObject::update(const btTransform& transform, const AreaType areaType)
{ {
bool result = false; bool result = false;
if (!(mTransform == transform)) if (!(mTransform == transform))
@ -78,4 +72,11 @@ namespace DetourNavigator
|| result; || result;
return result; return result;
} }
RecastMeshObject::RecastMeshObject(const CollisionShape& shape, const btTransform& transform,
const AreaType areaType)
: mHolder(shape.getHolder())
, mImpl(shape.getShape(), transform, areaType)
{
}
} }

View File

@ -32,40 +32,45 @@ namespace DetourNavigator
std::reference_wrapper<const btCollisionShape> mShape; std::reference_wrapper<const btCollisionShape> mShape;
}; };
class ChildRecastMeshObject
{
public:
ChildRecastMeshObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType);
bool update(const btTransform& transform, const AreaType areaType);
const btCollisionShape& getShape() const { return mShape; }
const btTransform& getTransform() const { return mTransform; }
AreaType getAreaType() const { return mAreaType; }
private:
std::reference_wrapper<const btCollisionShape> mShape;
btTransform mTransform;
AreaType mAreaType;
btVector3 mLocalScaling;
std::vector<ChildRecastMeshObject> mChildren;
};
class RecastMeshObject class RecastMeshObject
{ {
public: public:
RecastMeshObject(const CollisionShape& shape, const btTransform& transform, const AreaType areaType); RecastMeshObject(const CollisionShape& shape, const btTransform& transform, const AreaType areaType);
bool update(const btTransform& transform, const AreaType areaType); bool update(const btTransform& transform, const AreaType areaType) { return mImpl.update(transform, areaType); }
const osg::ref_ptr<const osg::Referenced>& getHolder() const const osg::ref_ptr<const osg::Referenced>& getHolder() const { return mHolder; }
{
return mHolder;
}
const btCollisionShape& getShape() const const btCollisionShape& getShape() const { return mImpl.getShape(); }
{
return mShape;
}
const btTransform& getTransform() const const btTransform& getTransform() const { return mImpl.getTransform(); }
{
return mTransform;
}
AreaType getAreaType() const AreaType getAreaType() const { return mImpl.getAreaType(); }
{
return mAreaType;
}
private: private:
osg::ref_ptr<const osg::Referenced> mHolder; osg::ref_ptr<const osg::Referenced> mHolder;
std::reference_wrapper<const btCollisionShape> mShape; ChildRecastMeshObject mImpl;
btTransform mTransform;
AreaType mAreaType;
btVector3 mLocalScaling;
std::vector<RecastMeshObject> mChildren;
}; };
} }