From e7cc76bba2457d11aaec3af494fb98f11eeac041 Mon Sep 17 00:00:00 2001 From: Alexei Dobrohotov Date: Sat, 13 Nov 2021 19:23:37 +0300 Subject: [PATCH] Load bhkMoppBvTreeShape --- components/nif/niffile.cpp | 1 + components/nif/physics.cpp | 29 +++++++++++++++++++++++++++++ components/nif/physics.hpp | 24 ++++++++++++++++++++++++ components/nif/record.hpp | 3 ++- 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index dbe455fbd4..1bd4821395 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -143,6 +143,7 @@ static std::map makeFactory() factory["bhkCollisionObject"] = {&construct , RC_bhkCollisionObject }; factory["BSDismemberSkinInstance"] = {&construct , RC_BSDismemberSkinInstance }; factory["NiControllerManager"] = {&construct , RC_NiControllerManager }; + factory["bhkMoppBvTreeShape"] = {&construct , RC_bhkMoppBvTreeShape }; return factory; } diff --git a/components/nif/physics.cpp b/components/nif/physics.cpp index ba78f7a9cd..3c43c160cd 100644 --- a/components/nif/physics.cpp +++ b/components/nif/physics.cpp @@ -42,6 +42,17 @@ namespace Nif mHavokMaterial.read(nif); } + void hkpMoppCode::read(NIFStream *nif) + { + unsigned int size = nif->getUInt(); + if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0)) + mOffset = nif->getVector4(); + if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO3) + nif->getChar(); // MOPP data build type + if (size) + nif->getChars(mData, size); + } + void bhkEntityCInfo::read(NIFStream *nif) { mResponseType = static_cast(nif->getChar()); @@ -78,4 +89,22 @@ namespace Nif mInfo.read(nif); } + void bhkBvTreeShape::read(NIFStream *nif) + { + mShape.read(nif); + } + + void bhkBvTreeShape::post(NIFFile *nif) + { + mShape.post(nif); + } + + void bhkMoppBvTreeShape::read(NIFStream *nif) + { + bhkBvTreeShape::read(nif); + nif->skip(12); // Unused + mScale = nif->getFloat(); + mMopp.read(nif); + } + } // Namespace \ No newline at end of file diff --git a/components/nif/physics.hpp b/components/nif/physics.hpp index dc365cf099..190cb42b1d 100644 --- a/components/nif/physics.hpp +++ b/components/nif/physics.hpp @@ -70,6 +70,13 @@ struct bhkEntityCInfo void read(NIFStream *nif); } +struct hkpMoppCode +{ + osg::Vec4f mOffset; + std::vector mData; + void read(NIFStream *nif); +}; + /// Record types // Abstract Bethesda Havok object @@ -131,5 +138,22 @@ struct bhkEntity : public bhkWorldObject void read(NIFStream *nif) override; }; +// Bethesda extension of hkpBvTreeShape +// hkpBvTreeShape adds a bounding volume tree to an hkpShapeCollection +struct bhkBvTreeShape : public bhkShape +{ + bhkShapePtr mShape; + void read(NIFStream *nif) override; + void post(NIFFile *nif) override; +}; + +// bhkBvTreeShape with Havok MOPP code +struct bhkMoppBvTreeShape : public bhkBvTreeShape +{ + float mScale; + hkpMoppCode mMopp; + void read(NIFStream *nif) override; +}; + } // Namespace #endif \ No newline at end of file diff --git a/components/nif/record.hpp b/components/nif/record.hpp index 0b9b2dc998..47ce14969f 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -130,7 +130,8 @@ enum RecordType RC_NiCollisionObject, RC_bhkCollisionObject, RC_BSDismemberSkinInstance, - RC_NiControllerManager + RC_NiControllerManager, + RC_bhkMoppBvTreeShape }; /// Base class for all records