1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-24 21:41:37 +00:00

Don't use Bounding Box node bounds as the original collision shape

Bounding Box node bounds are not used for non-actor collision in Morrowind and the generated box isn't actually used for actor collision in OpenMW
Preserving btBoxShape cloning code because it might get used in the future
This commit is contained in:
Alexei Kotov 2023-11-03 23:25:14 +03:00
parent 8a8d77a444
commit 2c1db92d04
2 changed files with 5 additions and 44 deletions

View file

@ -411,7 +411,7 @@ namespace
EXPECT_EQ(*result, expected);
}
TEST_F(TestBulletNifLoader, for_root_bounding_box_should_return_shape_with_compound_shape_and_box_inside)
TEST_F(TestBulletNifLoader, for_root_bounding_box_should_return_shape_with_bounding_box_data)
{
mNode.mName = "Bounding Box";
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
@ -427,15 +427,11 @@ namespace
Resource::BulletShape expected;
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
expected.mCollisionShape.reset(shape.release());
EXPECT_EQ(*result, expected);
}
TEST_F(TestBulletNifLoader, for_child_bounding_box_should_return_shape_with_compound_shape_with_box_inside)
TEST_F(TestBulletNifLoader, for_child_bounding_box_should_return_shape_with_bounding_box_data)
{
mNode.mName = "Bounding Box";
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
@ -453,15 +449,11 @@ namespace
Resource::BulletShape expected;
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
expected.mCollisionShape.reset(shape.release());
EXPECT_EQ(*result, expected);
}
TEST_F(TestBulletNifLoader, for_root_with_bounds_and_child_bounding_box_but_should_use_bounding_box)
TEST_F(TestBulletNifLoader, for_root_with_bounds_and_child_bounding_box_should_use_bounding_box)
{
mNode.mName = "Bounding Box";
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
@ -483,10 +475,6 @@ namespace
Resource::BulletShape expected;
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
expected.mCollisionShape.reset(shape.release());
EXPECT_EQ(*result, expected);
}
@ -519,10 +507,6 @@ namespace
Resource::BulletShape expected;
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
expected.mCollisionBox.mCenter = osg::Vec3f(-1, -2, -3);
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
expected.mCollisionShape.reset(shape.release());
EXPECT_EQ(*result, expected);
}
@ -555,10 +539,6 @@ namespace
Resource::BulletShape expected;
expected.mCollisionBox.mExtents = osg::Vec3f(4, 5, 6);
expected.mCollisionBox.mCenter = osg::Vec3f(-4, -5, -6);
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(4, 5, 6)));
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-4, -5, -6)), box.release());
expected.mCollisionShape.reset(shape.release());
EXPECT_EQ(*result, expected);
}

View file

@ -6,7 +6,6 @@
#include <variant>
#include <vector>
#include <BulletCollision/CollisionShapes/btBoxShape.h>
#include <BulletCollision/CollisionShapes/btTriangleMesh.h>
#include <components/debug/debuglog.hpp>
@ -171,23 +170,8 @@ namespace NifBullet
}
for (const Nif::NiAVObject* node : roots)
{
// Try to find a valid bounding box first. If one's found for any root node, use that.
if (findBoundingBox(*node))
{
const btVector3 extents = Misc::Convert::toBullet(mShape->mCollisionBox.mExtents);
const btVector3 center = Misc::Convert::toBullet(mShape->mCollisionBox.mCenter);
auto compound = std::make_unique<btCompoundShape>();
auto boxShape = std::make_unique<btBoxShape>(extents);
btTransform transform = btTransform::getIdentity();
transform.setOrigin(center);
compound->addChildShape(transform, boxShape.get());
std::ignore = boxShape.release();
mShape->mCollisionShape.reset(compound.release());
return mShape;
}
}
break;
HandleNodeArgs args;
@ -196,8 +180,6 @@ namespace NifBullet
// TODO: investigate whether this should and could be optimized.
args.mAnimated = pathFileNameStartsWithX(mShape->mFileName);
// If there's no bounding box, we'll have to generate a Bullet collision shape
// from the collision data present in every root node.
for (const Nif::NiAVObject* node : roots)
handleRoot(nif, *node, args);
@ -210,8 +192,7 @@ namespace NifBullet
return mShape;
}
// Find a boundingBox in the node hierarchy.
// Return: use bounding box for collision?
// Find a bounding box in the node hierarchy to use for actor collision
bool BulletNifLoader::findBoundingBox(const Nif::NiAVObject& node)
{
if (Misc::StringUtils::ciEqual(node.mName, "Bounding Box"))