#include "recastmeshobject.hpp" #include #include #include namespace DetourNavigator { RecastMeshObject::RecastMeshObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType) : mShape(shape) , mTransform(transform) , mAreaType(areaType) , mLocalScaling(shape.getLocalScaling()) , mChildren(makeChildrenObjects(shape, mAreaType)) { } bool RecastMeshObject::update(const btTransform& transform, const AreaType areaType) { bool result = false; if (!(mTransform == transform)) { mTransform = transform; result = true; } if (mAreaType != areaType) { mAreaType = areaType; result = true; } if (!(mLocalScaling == mShape.get().getLocalScaling())) { mLocalScaling = mShape.get().getLocalScaling(); result = true; } if (mShape.get().isCompound()) result = updateCompoundObject(static_cast(mShape.get()), mAreaType, mChildren) || result; return result; } bool RecastMeshObject::updateCompoundObject(const btCompoundShape& shape, const AreaType areaType, std::vector& children) { assert(static_cast(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(i)].mShape.get())); result = children[static_cast(i)].update(shape.getChildTransform(i), areaType) || result; } return result; } std::vector makeChildrenObjects(const btCollisionShape& shape, const AreaType areaType) { if (shape.isCompound()) return makeChildrenObjects(static_cast(shape), areaType); else return std::vector(); } std::vector makeChildrenObjects(const btCompoundShape& shape, const AreaType areaType) { std::vector result; for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i) result.emplace_back(*shape.getChildShape(i), shape.getChildTransform(i), areaType); return result; } }