From 695932d2dbb2e2d1dbc731b316f529ec3706e4c7 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Wed, 18 Sep 2024 22:49:14 +0300 Subject: [PATCH] Parse BSDistantObjectInstancedNode --- components/nif/niffile.cpp | 2 ++ components/nif/node.cpp | 39 ++++++++++++++++++++++++++++++++++++++ components/nif/node.hpp | 32 +++++++++++++++++++++++++++++++ components/nif/record.hpp | 1 + 4 files changed, 74 insertions(+) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index bdf417d957..113e43e185 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -71,6 +71,8 @@ namespace Nif { "BSBlastNode", &construct }, { "BSDamageStage", &construct }, { "BSDebrisNode", &construct }, + { "BSDistantObjectInstancedNode", + &construct }, { "BSFadeNode", &construct }, { "BSLeafAnimNode", &construct }, { "BSMasterParticleSystem", &construct }, diff --git a/components/nif/node.cpp b/components/nif/node.cpp index b91f143d00..c2655a3e9c 100644 --- a/components/nif/node.cpp +++ b/components/nif/node.cpp @@ -742,4 +742,43 @@ namespace Nif nif->read(mCurrent); } + void BSResourceID::read(NIFStream* nif) + { + nif->read(mFileHash); + nif->readArray(mExtension); + nif->read(mDirectoryHash); + } + + void BSDistantObjectInstance::read(NIFStream* nif) + { + mResourceID.read(nif); + nif->skip(12 * nif->get()); // Unknown data + mTransforms.resize(nif->get()); + for (osg::Matrixf& transform : mTransforms) + { + std::array mat; + nif->readArray(mat); + transform.set(mat.data()); + } + } + + void BSShaderTextureArray::read(NIFStream* nif) + { + nif->skip(1); // Unknown + mTextureArrays.resize(nif->get()); + for (std::vector& textureArray : mTextureArrays) + nif->getSizedStrings(textureArray, nif->get()); + } + + void BSDistantObjectInstancedNode::read(NIFStream* nif) + { + BSMultiBoundNode::read(nif); + + mInstances.resize(nif->get()); + for (BSDistantObjectInstance& instance : mInstances) + instance.read(nif); + for (BSShaderTextureArray& textureArray : mShaderTextureArrays) + textureArray.read(nif); + } + } diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 32746f7a9f..e9306fa83f 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -494,5 +494,37 @@ namespace Nif void read(NIFStream* nif) override; }; + struct BSResourceID + { + uint32_t mFileHash; + std::array mExtension; + uint32_t mDirectoryHash; + + void read(NIFStream* nif); + }; + + struct BSDistantObjectInstance + { + BSResourceID mResourceID; + std::vector mTransforms; + + void read(NIFStream* nif); + }; + + struct BSShaderTextureArray + { + std::vector> mTextureArrays; + + void read(NIFStream* nif); + }; + + struct BSDistantObjectInstancedNode : BSMultiBoundNode + { + std::vector mInstances; + std::array mShaderTextureArrays; + + void read(NIFStream* nif) override; + }; + } #endif diff --git a/components/nif/record.hpp b/components/nif/record.hpp index fb52daa63f..3be7609c97 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -89,6 +89,7 @@ namespace Nif RC_BSDynamicTriShape, RC_BSDismemberSkinInstance, RC_BSDistantObjectExtraData, + RC_BSDistantObjectInstancedNode, RC_BSDistantObjectLargeRefExtraData, RC_BSEffectShaderProperty, RC_BSEffectShaderPropertyColorController,