From 3e8a9d1de4d3cc99df6aa87930587c60c382e13a Mon Sep 17 00:00:00 2001 From: Alexei Dobrohotov Date: Sun, 21 May 2023 18:15:27 +0300 Subject: [PATCH 1/3] Read BSTreeNode, handle as NiNode --- components/nif/niffile.cpp | 1 + components/nif/node.cpp | 14 ++++++++++++++ components/nif/node.hpp | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index 1a1a101605..c9f04dcd88 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -138,6 +138,7 @@ namespace Nif { "NiTransformData", &construct }, { "BSFadeNode", &construct }, { "BSLeafAnimNode", &construct }, + { "BSTreeNode", &construct }, { "bhkBlendController", &construct }, { "NiFloatInterpolator", &construct }, { "NiBoolInterpolator", &construct }, diff --git a/components/nif/node.cpp b/components/nif/node.cpp index 7727e99d84..1960bf3fbc 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -306,4 +306,18 @@ namespace Nif for (auto& object : mObjects) object.second.post(nif); } + + void BSTreeNode::read(NIFStream* nif) + { + NiNode::read(nif); + readRecordList(nif, mBones1); + readRecordList(nif, mBones2); + } + + void BSTreeNode::post(Reader& nif) + { + NiNode::post(nif); + postRecordList(nif, mBones1); + postRecordList(nif, mBones2); + } } diff --git a/components/nif/node.hpp b/components/nif/node.hpp index baee1fec66..d9274be6df 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -284,5 +284,12 @@ namespace Nif void post(Reader& nif) override; }; + struct BSTreeNode : NiNode + { + NodeList mBones1, mBones2; + void read(NIFStream* nif) override; + void post(Reader& nif) override; + }; + } // Namespace #endif From 1b5e9042859c76aef5c397f553434ad8e515148d Mon Sep 17 00:00:00 2001 From: Alexei Dobrohotov Date: Mon, 22 May 2023 22:28:05 +0300 Subject: [PATCH 2/3] Read BSMultiBound et al. --- components/nif/data.cpp | 23 +++++++++++++++++++++++ components/nif/data.hpp | 30 ++++++++++++++++++++++++++++++ components/nif/niffile.cpp | 4 ++++ components/nif/niffile.hpp | 1 + components/nif/node.cpp | 14 ++++++++++++++ components/nif/node.hpp | 9 +++++++++ components/nif/record.hpp | 3 +++ components/nif/recordptr.hpp | 4 ++++ 8 files changed, 88 insertions(+) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index fac41518c9..fd94c5753a 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -484,4 +484,27 @@ namespace Nif mKeyList->read(nif); } + void BSMultiBound::read(NIFStream* nif) + { + mData.read(nif); + } + + void BSMultiBound::post(Reader& nif) + { + mData.post(nif); + } + + void BSMultiBoundOBB::read(NIFStream* nif) + { + mCenter = nif->getVector3(); + mSize = nif->getVector3(); + mRotation = nif->getMatrix3(); + } + + void BSMultiBoundSphere::read(NIFStream* nif) + { + mCenter = nif->getVector3(); + mRadius = nif->getFloat(); + } + } // Namespace diff --git a/components/nif/data.hpp b/components/nif/data.hpp index bac47a87f5..96e8441639 100644 --- a/components/nif/data.hpp +++ b/components/nif/data.hpp @@ -288,5 +288,35 @@ namespace Nif void read(NIFStream* nif) override; }; + struct BSMultiBound : public Record + { + BSMultiBoundDataPtr mData; + + void read(NIFStream* nif) override; + void post(Reader& nif) override; + }; + + // Abstract + struct BSMultiBoundData : public Record + { + }; + + struct BSMultiBoundOBB : public BSMultiBoundData + { + osg::Vec3f mCenter; + osg::Vec3f mSize; + Nif::Matrix3 mRotation; + + void read(NIFStream* nif) override; + }; + + struct BSMultiBoundSphere : public BSMultiBoundData + { + osg::Vec3f mCenter; + float mRadius; + + void read(NIFStream* nif) override; + }; + } // Namespace #endif diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index c9f04dcd88..6240c08655 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -139,6 +139,7 @@ namespace Nif { "BSFadeNode", &construct }, { "BSLeafAnimNode", &construct }, { "BSTreeNode", &construct }, + { "BSMultiBoundNode", &construct }, { "bhkBlendController", &construct }, { "NiFloatInterpolator", &construct }, { "NiBoolInterpolator", &construct }, @@ -186,6 +187,9 @@ namespace Nif &construct }, { "bhkCompressedMeshShape", &construct }, { "bhkCompressedMeshShapeData", &construct }, + { "BSMultiBound", &construct }, + { "BSMultiBoundOBB", &construct }, + { "BSMultiBoundSphere", &construct }, }; } diff --git a/components/nif/niffile.hpp b/components/nif/niffile.hpp index f2adb698d0..96534df2d3 100644 --- a/components/nif/niffile.hpp +++ b/components/nif/niffile.hpp @@ -27,6 +27,7 @@ namespace Nif enum BethVersion { BETHVER_FO3 = 34, // Fallout 3 + BETHVER_SKY = 83, // Skyrim BETHVER_FO4 = 130 // Fallout 4 }; diff --git a/components/nif/node.cpp b/components/nif/node.cpp index 1960bf3fbc..0ec1b8ab33 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -320,4 +320,18 @@ namespace Nif postRecordList(nif, mBones1); postRecordList(nif, mBones2); } + + void BSMultiBoundNode::read(NIFStream* nif) + { + NiNode::read(nif); + mMultiBound.read(nif); + if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_SKY) + mType = nif->getUInt(); + } + + void BSMultiBoundNode::post(Reader& nif) + { + NiNode::post(nif); + mMultiBound.post(nif); + } } diff --git a/components/nif/node.hpp b/components/nif/node.hpp index d9274be6df..8b572a8e7d 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -291,5 +291,14 @@ namespace Nif void post(Reader& nif) override; }; + struct BSMultiBoundNode : NiNode + { + BSMultiBoundPtr mMultiBound; + unsigned int mType{ 0 }; + + void read(NIFStream* nif) override; + void post(Reader& nif) override; + }; + } // Namespace #endif diff --git a/components/nif/record.hpp b/components/nif/record.hpp index 0a4cf3a8b0..afd23ac21c 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -159,6 +159,9 @@ namespace Nif RC_NiBlendTransformInterpolator, RC_bhkCompressedMeshShape, RC_bhkCompressedMeshShapeData, + RC_BSMultiBound, + RC_BSMultiBoundOBB, + RC_BSMultiBoundSphere, }; /// Base class for all records diff --git a/components/nif/recordptr.hpp b/components/nif/recordptr.hpp index bf5c8a9ba2..7025063213 100644 --- a/components/nif/recordptr.hpp +++ b/components/nif/recordptr.hpp @@ -146,6 +146,8 @@ namespace Nif struct NiDefaultAVObjectPalette; struct NiControllerSequence; struct bhkCompressedMeshShapeData; + struct BSMultiBound; + struct BSMultiBoundData; using NodePtr = RecordPtrT; using ExtraPtr = RecordPtrT; @@ -181,6 +183,8 @@ namespace Nif using NiBlendInterpolatorPtr = RecordPtrT; using NiDefaultAVObjectPalettePtr = RecordPtrT; using bhkCompressedMeshShapeDataPtr = RecordPtrT; + using BSMultiBoundPtr = RecordPtrT; + using BSMultiBoundDataPtr = RecordPtrT; using NodeList = RecordListT; using PropertyList = RecordListT; From a983977e6afd7f9dca73b05bec843873357ba4e0 Mon Sep 17 00:00:00 2001 From: Alexei Dobrohotov Date: Tue, 23 May 2023 00:58:59 +0300 Subject: [PATCH 3/3] Fix NiSkinData loading for >4.2.1.0 --- components/nif/data.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index fd94c5753a..54fdea6f8c 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -338,9 +338,9 @@ namespace Nif && nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 0)) partitions.read(nif); - // Has vertex weights flag - if (nif->getVersion() > NIFStream::generateVersion(4, 2, 1, 0) && !nif->getBoolean()) - return; + bool hasVertexWeights = true; + if (nif->getVersion() > NIFStream::generateVersion(4, 2, 1, 0)) + hasVertexWeights = nif->getBoolean(); bones.resize(boneNum); for (BoneInfo& bi : bones) @@ -351,8 +351,12 @@ namespace Nif bi.boundSphereCenter = nif->getVector3(); bi.boundSphereRadius = nif->getFloat(); - // Number of vertex weights - bi.weights.resize(nif->getUShort()); + size_t numVertices = nif->getUShort(); + + if (!hasVertexWeights) + continue; + + bi.weights.resize(numVertices); for (size_t j = 0; j < bi.weights.size(); j++) { bi.weights[j].vertex = nif->getUShort();