mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
Use btScaledBvhTriangleMeshShape, bump required bullet version to 2.83
This commit is contained in:
parent
20af2b67a8
commit
27751db99a
3 changed files with 28 additions and 11 deletions
|
@ -123,7 +123,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
||||||
mCompoundShape = NULL;
|
mCompoundShape = NULL;
|
||||||
mStaticMesh = NULL;
|
mStaticMesh = NULL;
|
||||||
|
|
||||||
Nif::NIFFilePtr pnif (Nif::Cache::getInstance().load(mResourceName.substr(0, mResourceName.length()-7)));
|
Nif::NIFFilePtr pnif (Nif::Cache::getInstance().load(mResourceName));
|
||||||
Nif::NIFFile & nif = *pnif.get ();
|
Nif::NIFFile & nif = *pnif.get ();
|
||||||
if (nif.numRoots() < 1)
|
if (nif.numRoots() < 1)
|
||||||
{
|
{
|
||||||
|
@ -134,7 +134,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
||||||
// Have to load controlled nodes from the .kf
|
// Have to load controlled nodes from the .kf
|
||||||
// FIXME: the .kf has to be loaded both for rendering and physics, ideally it should be opened once and then reused
|
// FIXME: the .kf has to be loaded both for rendering and physics, ideally it should be opened once and then reused
|
||||||
mControlledNodes.clear();
|
mControlledNodes.clear();
|
||||||
std::string kfname = mResourceName.substr(0, mResourceName.length()-7);
|
std::string kfname = mResourceName;
|
||||||
Misc::StringUtils::toLower(kfname);
|
Misc::StringUtils::toLower(kfname);
|
||||||
if(kfname.size() > 4 && kfname.compare(kfname.size()-4, 4, ".nif") == 0)
|
if(kfname.size() > 4 && kfname.compare(kfname.size()-4, 4, ".nif") == 0)
|
||||||
kfname.replace(kfname.size()-4, 4, ".kf");
|
kfname.replace(kfname.size()-4, 4, ".kf");
|
||||||
|
|
|
@ -457,8 +457,7 @@ namespace Physic
|
||||||
float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
|
float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
|
||||||
Ogre::Vector3* scaledBoxTranslation, Ogre::Quaternion* boxRotation, bool raycasting, bool placeable)
|
Ogre::Vector3* scaledBoxTranslation, Ogre::Quaternion* boxRotation, bool raycasting, bool placeable)
|
||||||
{
|
{
|
||||||
std::string sid = (boost::format("%07.3f") % scale).str();
|
std::string outputstring = mesh;
|
||||||
std::string outputstring = mesh + sid;
|
|
||||||
|
|
||||||
//get the shape from the .nif
|
//get the shape from the .nif
|
||||||
mShapeLoader->load(outputstring,"General");
|
mShapeLoader->load(outputstring,"General");
|
||||||
|
@ -477,20 +476,35 @@ namespace Physic
|
||||||
|
|
||||||
btCollisionShape* collisionShape = raycasting ? shape->mRaycastingShape : shape->mCollisionShape;
|
btCollisionShape* collisionShape = raycasting ? shape->mRaycastingShape : shape->mCollisionShape;
|
||||||
|
|
||||||
|
// TODO: check this from cmake?
|
||||||
|
#if BT_BULLET_VERSION < 283
|
||||||
|
#error "Bullet version 2.83 or later required"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool needDelete = false;
|
||||||
|
if (btBvhTriangleMeshShape* triangleShape = dynamic_cast<btBvhTriangleMeshShape*>(shape->mCollisionShape))
|
||||||
|
{
|
||||||
|
btScaledBvhTriangleMeshShape* scaled = new btScaledBvhTriangleMeshShape(triangleShape, btVector3(scale,scale,scale));
|
||||||
|
collisionShape = scaled;
|
||||||
|
needDelete = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// If this is an animated compound shape, we must duplicate it so we can animate
|
// If this is an animated compound shape, we must duplicate it so we can animate
|
||||||
// multiple instances independently.
|
// multiple instances independently.
|
||||||
if (!raycasting && !shape->mAnimatedShapes.empty())
|
if (!raycasting && !shape->mAnimatedShapes.empty())
|
||||||
collisionShape = duplicateCollisionShape(collisionShape);
|
collisionShape = duplicateCollisionShape(collisionShape);
|
||||||
if (raycasting && !shape->mAnimatedRaycastingShapes.empty())
|
if (raycasting && !shape->mAnimatedRaycastingShapes.empty())
|
||||||
collisionShape = duplicateCollisionShape(collisionShape);
|
collisionShape = duplicateCollisionShape(collisionShape);
|
||||||
|
}
|
||||||
collisionShape->setLocalScaling( btVector3(scale,scale,scale));
|
|
||||||
|
|
||||||
//create the real body
|
//create the real body
|
||||||
btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo
|
btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo
|
||||||
(0,0, collisionShape);
|
(0,0, collisionShape);
|
||||||
RigidBody* body = new RigidBody(CI,name);
|
RigidBody* body = new RigidBody(CI,name);
|
||||||
body->mPlaceable = placeable;
|
body->mPlaceable = placeable;
|
||||||
|
if (needDelete)
|
||||||
|
body->mCollisionShape.reset(collisionShape);
|
||||||
|
|
||||||
if (!raycasting && !shape->mAnimatedShapes.empty())
|
if (!raycasting && !shape->mAnimatedShapes.empty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,6 +63,9 @@ namespace Physic
|
||||||
virtual ~RigidBody();
|
virtual ~RigidBody();
|
||||||
std::string mName;
|
std::string mName;
|
||||||
|
|
||||||
|
// May be empty if the collision shape is a shared resource
|
||||||
|
std::auto_ptr<btCollisionShape> mCollisionShape;
|
||||||
|
|
||||||
// Hack: placeable objects (that can be picked up by the player) have different collision behaviour.
|
// Hack: placeable objects (that can be picked up by the player) have different collision behaviour.
|
||||||
// This variable needs to be passed to BulletNifLoader.
|
// This variable needs to be passed to BulletNifLoader.
|
||||||
bool mPlaceable;
|
bool mPlaceable;
|
||||||
|
|
Loading…
Reference in a new issue