From deb051639e644e24c61c486f27c6bcaea2ed9488 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 14 Sep 2023 12:39:44 +0300 Subject: [PATCH] Refactor NiBoundingVolume --- .../nifloader/testbulletnifloader.cpp | 72 +++++++++---------- components/nif/node.cpp | 12 ++-- components/nif/node.hpp | 10 +-- components/nifbullet/bulletnifloader.cpp | 10 +-- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp b/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp index 1971895936..2c2b60db36 100644 --- a/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp +++ b/apps/openmw_test_suite/nifloader/testbulletnifloader.cpp @@ -415,9 +415,9 @@ namespace TestBulletNifLoader, for_root_nif_node_with_bounding_box_should_return_shape_with_compound_shape_and_box_inside) { mNode.mFlags |= Nif::NiAVObject::Flag_BBoxCollision; - mNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNode.mBounds.box.extents = osg::Vec3f(1, 2, 3); - mNode.mBounds.box.center = osg::Vec3f(-1, -2, -3); + mNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNode.mBounds.mBox.mExtents = osg::Vec3f(1, 2, 3); + mNode.mBounds.mBox.mCenter = osg::Vec3f(-1, -2, -3); Nif::NIFFile file("test.nif"); file.mRoots.push_back(&mNode); @@ -439,9 +439,9 @@ namespace TEST_F(TestBulletNifLoader, for_child_nif_node_with_bounding_box) { mNode.mFlags |= Nif::NiAVObject::Flag_BBoxCollision; - mNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNode.mBounds.box.extents = osg::Vec3f(1, 2, 3); - mNode.mBounds.box.center = osg::Vec3f(-1, -2, -3); + mNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNode.mBounds.mBox.mExtents = osg::Vec3f(1, 2, 3); + mNode.mBounds.mBox.mCenter = osg::Vec3f(-1, -2, -3); mNode.mParents.push_back(&mNiNode); mNiNode.mChildren = Nif::NiAVObjectList{ Nif::NiAVObjectPtr(&mNode) }; @@ -466,14 +466,14 @@ namespace for_root_and_child_nif_node_with_bounding_box_but_root_without_flag_should_use_child_bounds) { mNode.mFlags |= Nif::NiAVObject::Flag_BBoxCollision; - mNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNode.mBounds.box.extents = osg::Vec3f(1, 2, 3); - mNode.mBounds.box.center = osg::Vec3f(-1, -2, -3); + mNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNode.mBounds.mBox.mExtents = osg::Vec3f(1, 2, 3); + mNode.mBounds.mBox.mCenter = osg::Vec3f(-1, -2, -3); mNode.mParents.push_back(&mNiNode); - mNiNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNiNode.mBounds.box.extents = osg::Vec3f(4, 5, 6); - mNiNode.mBounds.box.center = osg::Vec3f(-4, -5, -6); + mNiNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNiNode.mBounds.mBox.mExtents = osg::Vec3f(4, 5, 6); + mNiNode.mBounds.mBox.mCenter = osg::Vec3f(-4, -5, -6); mNiNode.mChildren = Nif::NiAVObjectList{ Nif::NiAVObjectPtr(&mNode) }; Nif::NIFFile file("test.nif"); @@ -497,19 +497,19 @@ namespace for_root_and_two_children_where_both_with_bounds_but_only_first_with_flag_should_use_first_bounds) { mNode.mFlags |= Nif::NiAVObject::Flag_BBoxCollision; - mNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNode.mBounds.box.extents = osg::Vec3f(1, 2, 3); - mNode.mBounds.box.center = osg::Vec3f(-1, -2, -3); + mNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNode.mBounds.mBox.mExtents = osg::Vec3f(1, 2, 3); + mNode.mBounds.mBox.mCenter = osg::Vec3f(-1, -2, -3); mNode.mParents.push_back(&mNiNode); - mNode2.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNode2.mBounds.box.extents = osg::Vec3f(4, 5, 6); - mNode2.mBounds.box.center = osg::Vec3f(-4, -5, -6); + mNode2.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNode2.mBounds.mBox.mExtents = osg::Vec3f(4, 5, 6); + mNode2.mBounds.mBox.mCenter = osg::Vec3f(-4, -5, -6); mNode2.mParents.push_back(&mNiNode); - mNiNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNiNode.mBounds.box.extents = osg::Vec3f(7, 8, 9); - mNiNode.mBounds.box.center = osg::Vec3f(-7, -8, -9); + mNiNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNiNode.mBounds.mBox.mExtents = osg::Vec3f(7, 8, 9); + mNiNode.mBounds.mBox.mCenter = osg::Vec3f(-7, -8, -9); mNiNode.mChildren = Nif::NiAVObjectList{ Nif::NiAVObjectPtr(&mNode), Nif::NiAVObjectPtr(&mNode2) }; Nif::NIFFile file("test.nif"); @@ -532,20 +532,20 @@ namespace TEST_F(TestBulletNifLoader, for_root_and_two_children_where_both_with_bounds_but_only_second_with_flag_should_use_second_bounds) { - mNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNode.mBounds.box.extents = osg::Vec3f(1, 2, 3); - mNode.mBounds.box.center = osg::Vec3f(-1, -2, -3); + mNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNode.mBounds.mBox.mExtents = osg::Vec3f(1, 2, 3); + mNode.mBounds.mBox.mCenter = osg::Vec3f(-1, -2, -3); mNode.mParents.push_back(&mNiNode); mNode2.mFlags |= Nif::NiAVObject::Flag_BBoxCollision; - mNode2.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNode2.mBounds.box.extents = osg::Vec3f(4, 5, 6); - mNode2.mBounds.box.center = osg::Vec3f(-4, -5, -6); + mNode2.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNode2.mBounds.mBox.mExtents = osg::Vec3f(4, 5, 6); + mNode2.mBounds.mBox.mCenter = osg::Vec3f(-4, -5, -6); mNode2.mParents.push_back(&mNiNode); - mNiNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNiNode.mBounds.box.extents = osg::Vec3f(7, 8, 9); - mNiNode.mBounds.box.center = osg::Vec3f(-7, -8, -9); + mNiNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNiNode.mBounds.mBox.mExtents = osg::Vec3f(7, 8, 9); + mNiNode.mBounds.mBox.mCenter = osg::Vec3f(-7, -8, -9); mNiNode.mChildren = Nif::NiAVObjectList{ Nif::NiAVObjectPtr(&mNode), Nif::NiAVObjectPtr(&mNode2) }; Nif::NIFFile file("test.nif"); @@ -568,9 +568,9 @@ namespace TEST_F(TestBulletNifLoader, for_root_nif_node_with_bounds_but_without_flag_should_return_shape_with_bounds_but_with_null_collision_shape) { - mNode.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNode.mBounds.box.extents = osg::Vec3f(1, 2, 3); - mNode.mBounds.box.center = osg::Vec3f(-1, -2, -3); + mNode.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNode.mBounds.mBox.mExtents = osg::Vec3f(1, 2, 3); + mNode.mBounds.mBox.mCenter = osg::Vec3f(-1, -2, -3); Nif::NIFFile file("test.nif"); file.mRoots.push_back(&mNode); @@ -608,9 +608,9 @@ namespace TEST_F(TestBulletNifLoader, for_tri_shape_root_node_with_bounds_should_return_static_shape_with_bounds_but_with_null_collision_shape) { - mNiTriShape.mBounds.type = Nif::NiBoundingVolume::Type::BOX_BV; - mNiTriShape.mBounds.box.extents = osg::Vec3f(1, 2, 3); - mNiTriShape.mBounds.box.center = osg::Vec3f(-1, -2, -3); + mNiTriShape.mBounds.mType = Nif::NiBoundingVolume::Type::BOX_BV; + mNiTriShape.mBounds.mBox.mExtents = osg::Vec3f(1, 2, 3); + mNiTriShape.mBounds.mBox.mCenter = osg::Vec3f(-1, -2, -3); Nif::NIFFile file("test.nif"); file.mRoots.push_back(&mNiTriShape); diff --git a/components/nif/node.cpp b/components/nif/node.cpp index ef0ff18599..cf4df3c733 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -14,8 +14,8 @@ namespace Nif void NiBoundingVolume::read(NIFStream* nif) { - nif->read(type); - switch (type) + nif->read(mType); + switch (mType) { case BASE_BV: break; @@ -26,9 +26,9 @@ namespace Nif } case BOX_BV: { - nif->read(box.center); - nif->read(box.axes); - nif->read(box.extents); + nif->read(mBox.mCenter); + nif->read(mBox.mAxes); + nif->read(mBox.mExtents); break; } case CAPSULE_BV: @@ -69,7 +69,7 @@ namespace Nif default: { throw Nif::Exception( - "Unhandled NiBoundingVolume type: " + std::to_string(type), nif->getFile().getFilename()); + "Unhandled NiBoundingVolume type: " + std::to_string(mType), nif->getFile().getFilename()); } } } diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 790a85d876..d539298995 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -28,9 +28,9 @@ namespace Nif struct NiBoxBV { - osg::Vec3f center; - Matrix3 axes; - osg::Vec3f extents; + osg::Vec3f mCenter; + Matrix3 mAxes; + osg::Vec3f mExtents; }; struct NiCapsuleBV @@ -51,9 +51,9 @@ namespace Nif osg::Vec3f mOrigin; }; - uint32_t type{ BASE_BV }; + uint32_t mType{ BASE_BV }; osg::BoundingSpheref mSphere; - NiBoxBV box; + NiBoxBV mBox; NiCapsuleBV mCapsule; NiLozengeBV mLozenge; std::vector mChildren; diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index 59d5cd61d8..7d1ccc99ff 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -181,7 +181,7 @@ namespace NifBullet bool hasCollisionShape = false; if (colNode != nullptr) { - if (colNode->mBounds.type == Nif::NiBoundingVolume::Type::BASE_BV && !colNode->mChildren.empty()) + if (colNode->mBounds.mType == Nif::NiBoundingVolume::Type::BASE_BV && !colNode->mChildren.empty()) hasCollisionShape = true; else mShape->mVisualCollisionType = Resource::VisualCollisionType::Camera; @@ -205,14 +205,14 @@ namespace NifBullet // Return: use bounding box for collision? bool BulletNifLoader::findBoundingBox(const Nif::NiAVObject& node, const std::string& filename) { - unsigned int type = node.mBounds.type; + unsigned int type = node.mBounds.mType; switch (type) { case Nif::NiBoundingVolume::Type::BASE_BV: break; case Nif::NiBoundingVolume::Type::BOX_BV: - mShape->mCollisionBox.mExtents = node.mBounds.box.extents; - mShape->mCollisionBox.mCenter = node.mBounds.box.center; + mShape->mCollisionBox.mExtents = node.mBounds.mBox.mExtents; + mShape->mCollisionBox.mCenter = node.mBounds.mBox.mCenter; break; default: { @@ -335,7 +335,7 @@ namespace NifBullet // NOTE: a trishape with bounds, but no BBoxCollision flag should NOT go through handleNiTriShape! // It must be ignored completely. // (occurs in tr_ex_imp_wall_arch_04.nif) - if (node.mBounds.type == Nif::NiBoundingVolume::Type::BASE_BV + if (node.mBounds.mType == Nif::NiBoundingVolume::Type::BASE_BV && (node.recType == Nif::RC_NiTriShape || node.recType == Nif::RC_NiTriStrips || node.recType == Nif::RC_BSLODTriShape)) {