Make better use of osg::BoundingSpheref in the NIF loader

macos_ci_fix
Alexei Kotov 1 year ago
parent 0154bb78df
commit fd3b24e2e6

@ -46,8 +46,7 @@ namespace Nif
} }
} }
nif->read(mCenter); nif->read(mBoundingSphere);
nif->read(mRadius);
bool hasColors; bool hasColors;
nif->read(hasColors); nif->read(hasColors);
@ -373,7 +372,7 @@ namespace Nif
nif->read(bi.mTransform.rotation); nif->read(bi.mTransform.rotation);
nif->read(bi.mTransform.pos); nif->read(bi.mTransform.pos);
nif->read(bi.mTransform.scale); nif->read(bi.mTransform.scale);
bi.mBoundSphere = osg::BoundingSpheref(nif->get<osg::Vec3f>(), nif->get<float>()); nif->read(bi.mBoundSphere);
uint16_t numVertices; uint16_t numVertices;
nif->read(numVertices); nif->read(numVertices);
@ -574,8 +573,7 @@ namespace Nif
void BSMultiBoundSphere::read(NIFStream* nif) void BSMultiBoundSphere::read(NIFStream* nif)
{ {
nif->read(mCenter); nif->read(mSphere);
nif->read(mRadius);
} }
} // Namespace } // Namespace

@ -51,8 +51,7 @@ namespace Nif
uint16_t mDataFlags{ 0 }; uint16_t mDataFlags{ 0 };
uint32_t mMaterialHash; uint32_t mMaterialHash;
std::vector<osg::Vec3f> mNormals, mTangents, mBitangents; std::vector<osg::Vec3f> mNormals, mTangents, mBitangents;
osg::Vec3f mCenter; osg::BoundingSpheref mBoundingSphere;
float mRadius;
std::vector<osg::Vec4f> mColors; std::vector<osg::Vec4f> mColors;
std::vector<std::vector<osg::Vec2f>> mUVList; std::vector<std::vector<osg::Vec2f>> mUVList;
uint16_t mConsistencyType; uint16_t mConsistencyType;
@ -402,8 +401,7 @@ namespace Nif
struct BSMultiBoundSphere : public BSMultiBoundData struct BSMultiBoundSphere : public BSMultiBoundData
{ {
osg::Vec3f mCenter; osg::BoundingSpheref mSphere;
float mRadius;
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
}; };

@ -122,6 +122,13 @@ namespace Nif
quat.z() = data[3]; quat.z() = data[3];
} }
template <>
void NIFStream::read<osg::BoundingSpheref>(osg::BoundingSpheref& sphere)
{
read(sphere.center());
read(sphere.radius());
}
template <> template <>
void NIFStream::read<Transformation>(Transformation& t) void NIFStream::read<Transformation>(Transformation& t)
{ {
@ -178,6 +185,12 @@ namespace Nif
readRange(*this, dest, size); readRange(*this, dest, size);
} }
template <>
void NIFStream::read<osg::BoundingSpheref>(osg::BoundingSpheref* dest, size_t size)
{
readRange(*this, dest, size);
}
template <> template <>
void NIFStream::read<Transformation>(Transformation* dest, size_t size) void NIFStream::read<Transformation>(Transformation* dest, size_t size)
{ {

@ -15,6 +15,7 @@
#include <components/misc/endianness.hpp> #include <components/misc/endianness.hpp>
#include <components/misc/float16.hpp> #include <components/misc/float16.hpp>
#include <osg/BoundingSphere>
#include <osg/Quat> #include <osg/Quat>
#include <osg/Vec3f> #include <osg/Vec3f>
#include <osg/Vec4f> #include <osg/Vec4f>
@ -174,6 +175,8 @@ namespace Nif
template <> template <>
void NIFStream::read<osg::Quat>(osg::Quat& quat); void NIFStream::read<osg::Quat>(osg::Quat& quat);
template <> template <>
void NIFStream::read<osg::BoundingSpheref>(osg::BoundingSpheref& sphere);
template <>
void NIFStream::read<Transformation>(Transformation& t); void NIFStream::read<Transformation>(Transformation& t);
template <> template <>
void NIFStream::read<bool>(bool& data); void NIFStream::read<bool>(bool& data);
@ -191,6 +194,8 @@ namespace Nif
template <> template <>
void NIFStream::read<osg::Quat>(osg::Quat* dest, size_t size); void NIFStream::read<osg::Quat>(osg::Quat* dest, size_t size);
template <> template <>
void NIFStream::read<osg::BoundingSpheref>(osg::BoundingSpheref* dest, size_t size);
template <>
void NIFStream::read<Transformation>(Transformation* dest, size_t size); void NIFStream::read<Transformation>(Transformation* dest, size_t size);
template <> template <>
void NIFStream::read<bool>(bool* dest, size_t size); void NIFStream::read<bool>(bool* dest, size_t size);

@ -19,7 +19,7 @@ namespace Nif
break; break;
case SPHERE_BV: case SPHERE_BV:
{ {
sphere.read(nif); nif->read(sphere);
break; break;
} }
case BOX_BV: case BOX_BV:
@ -336,7 +336,7 @@ namespace Nif
void BSTriShape::read(NIFStream* nif) void BSTriShape::read(NIFStream* nif)
{ {
Node::read(nif); Node::read(nif);
mBoundingSphere.read(nif); nif->read(mBoundingSphere);
if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_F76) if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_F76)
{ {
@ -412,12 +412,6 @@ namespace Nif
mFlags = (data & 0xFFF00000000000) >> 0x2C; mFlags = (data & 0xFFF00000000000) >> 0x2C;
} }
void NiBoundingVolume::NiSphereBV::read(NIFStream* nif)
{
nif->read(center);
nif->read(radius);
}
void BSVertexData::read(NIFStream* nif, uint16_t flags) void BSVertexData::read(NIFStream* nif, uint16_t flags)
{ {
uint16_t vertexFlag = flags & BSVertexDesc::VertexAttribute::Vertex; uint16_t vertexFlag = flags & BSVertexDesc::VertexAttribute::Vertex;

@ -26,13 +26,6 @@ namespace Nif
HALFSPACE_BV = 5 HALFSPACE_BV = 5
}; };
struct NiSphereBV
{
osg::Vec3f center;
float radius{ 0.f };
void read(NIFStream* nif);
};
struct NiBoxBV struct NiBoxBV
{ {
osg::Vec3f center; osg::Vec3f center;
@ -59,7 +52,7 @@ namespace Nif
}; };
unsigned int type; unsigned int type;
NiSphereBV sphere; osg::BoundingSpheref sphere;
NiBoxBV box; NiBoxBV box;
NiCapsuleBV capsule; NiCapsuleBV capsule;
NiLozengeBV lozenge; NiLozengeBV lozenge;
@ -355,7 +348,7 @@ namespace Nif
struct BSTriShape : Node struct BSTriShape : Node
{ {
NiBoundingVolume::NiSphereBV mBoundingSphere; osg::BoundingSpheref mBoundingSphere;
std::array<float, 6> mBoundMinMax; std::array<float, 6> mBoundMinMax;
NiSkinInstancePtr mSkin; NiSkinInstancePtr mSkin;

@ -1173,7 +1173,7 @@ namespace NifOsg
} }
// radius may be used to force a larger bounding box // 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); partsys->setInitialBound(box);
} }

Loading…
Cancel
Save