2015-11-16 23:30:10 +01:00
|
|
|
#ifndef OPENMW_COMPONENTS_RESOURCE_BULLETSHAPE_H
|
|
|
|
#define OPENMW_COMPONENTS_RESOURCE_BULLETSHAPE_H
|
|
|
|
|
|
|
|
#include <map>
|
2021-10-30 03:06:22 +02:00
|
|
|
#include <memory>
|
2015-11-16 23:30:10 +01:00
|
|
|
|
2016-02-05 23:59:37 +01:00
|
|
|
#include <osg/Object>
|
2015-11-16 23:30:10 +01:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Vec3f>
|
|
|
|
|
|
|
|
#include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
|
|
|
|
|
|
|
|
class btCollisionShape;
|
|
|
|
|
|
|
|
namespace Resource
|
|
|
|
{
|
2021-10-30 03:06:22 +02:00
|
|
|
struct DeleteCollisionShape
|
|
|
|
{
|
|
|
|
void operator()(btCollisionShape* shape) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
using CollisionShapePtr = std::unique_ptr<btCollisionShape, DeleteCollisionShape>;
|
2015-11-16 23:30:10 +01:00
|
|
|
|
|
|
|
class BulletShapeInstance;
|
2016-02-05 23:59:37 +01:00
|
|
|
class BulletShape : public osg::Object
|
2015-11-16 23:30:10 +01:00
|
|
|
{
|
|
|
|
public:
|
2021-10-30 03:06:22 +02:00
|
|
|
BulletShape() = default;
|
2016-02-05 23:59:37 +01:00
|
|
|
BulletShape(const BulletShape& copy, const osg::CopyOp& copyop);
|
2015-11-16 23:30:10 +01:00
|
|
|
|
2016-02-05 23:59:37 +01:00
|
|
|
META_Object(Resource, BulletShape)
|
|
|
|
|
2021-10-30 03:06:22 +02:00
|
|
|
CollisionShapePtr mCollisionShape;
|
|
|
|
CollisionShapePtr mAvoidCollisionShape;
|
2015-11-16 23:30:10 +01:00
|
|
|
|
2020-11-16 19:37:30 +03:00
|
|
|
struct CollisionBox
|
|
|
|
{
|
2021-10-28 01:43:25 +02:00
|
|
|
osg::Vec3f mExtents;
|
|
|
|
osg::Vec3f mCenter;
|
2020-11-16 19:37:30 +03:00
|
|
|
};
|
2021-02-05 12:12:34 +01:00
|
|
|
// Used for actors and projectiles. mCollisionShape is used for actors only when we need to autogenerate collision box for creatures.
|
2015-11-16 23:30:10 +01:00
|
|
|
// For now, use one file <-> one resource for simplicity.
|
2020-11-16 19:37:30 +03:00
|
|
|
CollisionBox mCollisionBox;
|
2015-11-16 23:30:10 +01:00
|
|
|
|
|
|
|
// Stores animated collision shapes. If any collision nodes in the NIF are animated, then mCollisionShape
|
|
|
|
// will be a btCompoundShape (which consists of one or more child shapes).
|
|
|
|
// In this map, for each animated collision shape,
|
|
|
|
// we store the node's record index mapped to the child index of the shape in the btCompoundShape.
|
|
|
|
std::map<int, int> mAnimatedShapes;
|
|
|
|
|
2016-02-06 23:30:41 +01:00
|
|
|
osg::ref_ptr<BulletShapeInstance> makeInstance() const;
|
2015-11-16 23:30:10 +01:00
|
|
|
|
2018-07-12 11:44:11 +03:00
|
|
|
btCollisionShape* getCollisionShape() const;
|
2015-11-16 23:30:10 +01:00
|
|
|
|
2018-07-12 11:44:11 +03:00
|
|
|
btCollisionShape* getAvoidCollisionShape() const;
|
|
|
|
|
|
|
|
void setLocalScaling(const btVector3& scale);
|
2018-07-11 01:05:19 +03:00
|
|
|
|
2021-02-05 14:55:42 +01:00
|
|
|
bool isAnimated() const;
|
2015-11-16 23:30:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// An instance of a BulletShape that may have its own unique scaling set on the mCollisionShape.
|
|
|
|
// Vertex data is shallow-copied where possible. A ref_ptr to the original shape is held to keep vertex pointers intact.
|
|
|
|
class BulletShapeInstance : public BulletShape
|
|
|
|
{
|
|
|
|
public:
|
2016-02-06 23:30:41 +01:00
|
|
|
BulletShapeInstance(osg::ref_ptr<const BulletShape> source);
|
2015-11-16 23:30:10 +01:00
|
|
|
|
|
|
|
private:
|
2016-02-06 23:30:41 +01:00
|
|
|
osg::ref_ptr<const BulletShape> mSource;
|
2015-11-16 23:30:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Subclass btBhvTriangleMeshShape to auto-delete the meshInterface
|
|
|
|
struct TriangleMeshShape : public btBvhTriangleMeshShape
|
|
|
|
{
|
2015-11-30 01:39:41 +01:00
|
|
|
TriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true)
|
|
|
|
: btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh)
|
2015-11-16 23:30:10 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~TriangleMeshShape()
|
|
|
|
{
|
|
|
|
delete getTriangleInfoMap();
|
|
|
|
delete m_meshInterface;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|