mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-27 21:35:24 +00:00
Merge branch 'unbound' into 'master'
Don't use Bounding Box node bounds as the original collision shape See merge request OpenMW/openmw!3562
This commit is contained in:
commit
9b6d82566f
@ -411,7 +411,7 @@ namespace
|
|||||||
EXPECT_EQ(*result, expected);
|
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.mName = "Bounding Box";
|
||||||
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
|
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
|
||||||
@ -427,15 +427,11 @@ namespace
|
|||||||
Resource::BulletShape expected;
|
Resource::BulletShape expected;
|
||||||
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
||||||
expected.mCollisionBox.mCenter = 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);
|
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.mName = "Bounding Box";
|
||||||
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
|
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
|
||||||
@ -453,15 +449,11 @@ namespace
|
|||||||
Resource::BulletShape expected;
|
Resource::BulletShape expected;
|
||||||
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
||||||
expected.mCollisionBox.mCenter = 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);
|
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.mName = "Bounding Box";
|
||||||
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
|
mNode.mBounds.mType = Nif::BoundingVolume::Type::BOX_BV;
|
||||||
@ -483,10 +475,6 @@ namespace
|
|||||||
Resource::BulletShape expected;
|
Resource::BulletShape expected;
|
||||||
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
||||||
expected.mCollisionBox.mCenter = 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);
|
EXPECT_EQ(*result, expected);
|
||||||
}
|
}
|
||||||
@ -519,10 +507,6 @@ namespace
|
|||||||
Resource::BulletShape expected;
|
Resource::BulletShape expected;
|
||||||
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
expected.mCollisionBox.mExtents = osg::Vec3f(1, 2, 3);
|
||||||
expected.mCollisionBox.mCenter = 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);
|
EXPECT_EQ(*result, expected);
|
||||||
}
|
}
|
||||||
@ -555,10 +539,6 @@ namespace
|
|||||||
Resource::BulletShape expected;
|
Resource::BulletShape expected;
|
||||||
expected.mCollisionBox.mExtents = osg::Vec3f(4, 5, 6);
|
expected.mCollisionBox.mExtents = osg::Vec3f(4, 5, 6);
|
||||||
expected.mCollisionBox.mCenter = 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);
|
EXPECT_EQ(*result, expected);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <BulletCollision/CollisionShapes/btBoxShape.h>
|
|
||||||
#include <BulletCollision/CollisionShapes/btTriangleMesh.h>
|
#include <BulletCollision/CollisionShapes/btTriangleMesh.h>
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
@ -171,23 +170,8 @@ namespace NifBullet
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const Nif::NiAVObject* node : roots)
|
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))
|
if (findBoundingBox(*node))
|
||||||
{
|
break;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HandleNodeArgs args;
|
HandleNodeArgs args;
|
||||||
|
|
||||||
@ -196,8 +180,6 @@ namespace NifBullet
|
|||||||
// TODO: investigate whether this should and could be optimized.
|
// TODO: investigate whether this should and could be optimized.
|
||||||
args.mAnimated = pathFileNameStartsWithX(mShape->mFileName);
|
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)
|
for (const Nif::NiAVObject* node : roots)
|
||||||
handleRoot(nif, *node, args);
|
handleRoot(nif, *node, args);
|
||||||
|
|
||||||
@ -210,8 +192,7 @@ namespace NifBullet
|
|||||||
return mShape;
|
return mShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a boundingBox in the node hierarchy.
|
// Find a bounding box in the node hierarchy to use for actor collision
|
||||||
// Return: use bounding box for collision?
|
|
||||||
bool BulletNifLoader::findBoundingBox(const Nif::NiAVObject& node)
|
bool BulletNifLoader::findBoundingBox(const Nif::NiAVObject& node)
|
||||||
{
|
{
|
||||||
if (Misc::StringUtils::ciEqual(node.mName, "Bounding Box"))
|
if (Misc::StringUtils::ciEqual(node.mName, "Bounding Box"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user