diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 25aa0fce44..5137f4309e 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -46,8 +46,7 @@ namespace Nif } } - nif->read(mCenter); - nif->read(mRadius); + nif->read(mBoundingSphere); bool hasColors; nif->read(hasColors); @@ -373,7 +372,7 @@ namespace Nif nif->read(bi.mTransform.rotation); nif->read(bi.mTransform.pos); nif->read(bi.mTransform.scale); - bi.mBoundSphere = osg::BoundingSpheref(nif->get(), nif->get()); + nif->read(bi.mBoundSphere); uint16_t numVertices; nif->read(numVertices); @@ -574,8 +573,7 @@ namespace Nif void BSMultiBoundSphere::read(NIFStream* nif) { - nif->read(mCenter); - nif->read(mRadius); + nif->read(mSphere); } } // Namespace diff --git a/components/nif/data.hpp b/components/nif/data.hpp index 025a2d524e..847d568ba0 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -51,8 +51,7 @@ namespace Nif uint16_t mDataFlags{ 0 }; uint32_t mMaterialHash; std::vector mNormals, mTangents, mBitangents; - osg::Vec3f mCenter; - float mRadius; + osg::BoundingSpheref mBoundingSphere; std::vector mColors; std::vector> mUVList; uint16_t mConsistencyType; @@ -402,8 +401,7 @@ namespace Nif struct BSMultiBoundSphere : public BSMultiBoundData { - osg::Vec3f mCenter; - float mRadius; + osg::BoundingSpheref mSphere; void read(NIFStream* nif) override; }; diff --git a/components/nif/nifstream.cpp b/components/nif/nifstream.cpp index db7528b2d0..c666a5edab 100644 --- a/components/nif/nifstream.cpp +++ b/components/nif/nifstream.cpp @@ -122,6 +122,13 @@ namespace Nif quat.z() = data[3]; } + template <> + void NIFStream::read(osg::BoundingSpheref& sphere) + { + read(sphere.center()); + read(sphere.radius()); + } + template <> void NIFStream::read(Transformation& t) { @@ -178,6 +185,12 @@ namespace Nif readRange(*this, dest, size); } + template <> + void NIFStream::read(osg::BoundingSpheref* dest, size_t size) + { + readRange(*this, dest, size); + } + template <> void NIFStream::read(Transformation* dest, size_t size) { diff --git a/components/nif/nifstream.hpp b/components/nif/nifstream.hpp index 58b160fcca..217d924059 100644 --- a/components/nif/nifstream.hpp +++ b/components/nif/nifstream.hpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -174,6 +175,8 @@ namespace Nif template <> void NIFStream::read(osg::Quat& quat); template <> + void NIFStream::read(osg::BoundingSpheref& sphere); + template <> void NIFStream::read(Transformation& t); template <> void NIFStream::read(bool& data); @@ -191,6 +194,8 @@ namespace Nif template <> void NIFStream::read(osg::Quat* dest, size_t size); template <> + void NIFStream::read(osg::BoundingSpheref* dest, size_t size); + template <> void NIFStream::read(Transformation* dest, size_t size); template <> void NIFStream::read(bool* dest, size_t size); diff --git a/components/nif/node.cpp b/components/nif/node.cpp index a2ae77830a..6028ac253f 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -19,7 +19,7 @@ namespace Nif break; case SPHERE_BV: { - sphere.read(nif); + nif->read(sphere); break; } case BOX_BV: @@ -336,7 +336,7 @@ namespace Nif void BSTriShape::read(NIFStream* nif) { Node::read(nif); - mBoundingSphere.read(nif); + nif->read(mBoundingSphere); if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_F76) { @@ -412,12 +412,6 @@ namespace Nif mFlags = (data & 0xFFF00000000000) >> 0x2C; } - void NiBoundingVolume::NiSphereBV::read(NIFStream* nif) - { - nif->read(center); - nif->read(radius); - } - void BSVertexData::read(NIFStream* nif, uint16_t flags) { uint16_t vertexFlag = flags & BSVertexDesc::VertexAttribute::Vertex; diff --git a/components/nif/node.hpp b/components/nif/node.hpp index dacaa1e823..2d8021eb49 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -26,13 +26,6 @@ namespace Nif HALFSPACE_BV = 5 }; - struct NiSphereBV - { - osg::Vec3f center; - float radius{ 0.f }; - void read(NIFStream* nif); - }; - struct NiBoxBV { osg::Vec3f center; @@ -59,7 +52,7 @@ namespace Nif }; unsigned int type; - NiSphereBV sphere; + osg::BoundingSpheref sphere; NiBoxBV box; NiCapsuleBV capsule; NiLozengeBV lozenge; @@ -355,7 +348,7 @@ namespace Nif struct BSTriShape : Node { - NiBoundingVolume::NiSphereBV mBoundingSphere; + osg::BoundingSpheref mBoundingSphere; std::array mBoundMinMax; NiSkinInstancePtr mSkin; diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index acc1c2d054..d1563df63c 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1173,7 +1173,7 @@ namespace NifOsg } // radius may be used to force a larger bounding box - box.expandBy(osg::BoundingSphere(osg::Vec3(0, 0, 0), particledata->mRadius)); + box.expandBy(osg::BoundingSphere(osg::Vec3(0, 0, 0), particledata->mBoundingSphere.radius())); partsys->setInitialBound(box); }