From 091fcd837ed8df652d8384ca6d100bb686087cc8 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Wed, 8 Feb 2023 23:13:36 +0300 Subject: [PATCH] Read all the NiBlendInterpolator record types --- components/nif/controller.cpp | 38 ++++++++++++++++++++++++++++++++++- components/nif/controller.hpp | 27 +++++++++++++++++++++++++ components/nif/niffile.cpp | 5 +++++ components/nif/record.hpp | 4 ++++ components/nif/recordptr.hpp | 2 ++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/components/nif/controller.cpp b/components/nif/controller.cpp index 47d1cbed8d..dd4261edd7 100644 --- a/components/nif/controller.cpp +++ b/components/nif/controller.cpp @@ -43,7 +43,7 @@ namespace Nif if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 110)) { - nif->skip(4); // NiBlendInterpolator link + mBlendInterpolator.read(nif); mBlendIndex = nif->getUShort(); } if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 106) && nif->getBethVersion() > 0) @@ -73,6 +73,7 @@ namespace Nif { mInterpolator.post(nif); mController.post(nif); + mBlendInterpolator.post(nif); mStringPalette.post(nif); // TODO: probably should fill the strings with string palette contents here } @@ -595,4 +596,39 @@ namespace Nif { mInterpolator.post(nif); } + + void NiBlendBoolInterpolator::read(NIFStream* nif) + { + NiBlendInterpolator::read(nif); + mValue = nif->getChar() != 0; + } + + void NiBlendFloatInterpolator::read(NIFStream* nif) + { + NiBlendInterpolator::read(nif); + mValue = nif->getFloat(); + } + + void NiBlendPoint3Interpolator::read(NIFStream* nif) + { + NiBlendInterpolator::read(nif); + mValue = nif->getVector3(); + } + + void NiBlendTransformInterpolator::read(NIFStream* nif) + { + NiBlendInterpolator::read(nif); + if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 109)) + { + mPosValue = nif->getVector3(); + mRotValue = nif->getQuaternion(); + mScaleValue = nif->getFloat(); + if (!nif->getBoolean()) + mPosValue = osg::Vec3f(); + if (!nif->getBoolean()) + mRotValue = osg::Quat(); + if (!nif->getBoolean()) + mScaleValue = 1.f; + } + } } diff --git a/components/nif/controller.hpp b/components/nif/controller.hpp index d5b8fad4d3..ff90f55dee 100644 --- a/components/nif/controller.hpp +++ b/components/nif/controller.hpp @@ -34,6 +34,7 @@ namespace Nif std::string mTargetName; NiInterpolatorPtr mInterpolator; ControllerPtr mController; + NiBlendInterpolatorPtr mBlendInterpolator; unsigned short mBlendIndex; unsigned char mPriority; NiStringPalettePtr mStringPalette; @@ -376,5 +377,31 @@ namespace Nif void post(Reader& nif) override; }; + struct NiBlendBoolInterpolator : public NiBlendInterpolator + { + char mValue; + void read(NIFStream* nif) override; + }; + + struct NiBlendFloatInterpolator : public NiBlendInterpolator + { + float mValue; + void read(NIFStream* nif) override; + }; + + struct NiBlendPoint3Interpolator : public NiBlendInterpolator + { + osg::Vec3f mValue; + void read(NIFStream* nif) override; + }; + + struct NiBlendTransformInterpolator : public NiBlendInterpolator + { + osg::Vec3f mPosValue; + osg::Quat mRotValue; + float mScaleValue; + void read(NIFStream* nif) override; + }; + } // Namespace #endif diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index fb3d92ff4f..ac5f3dfddc 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -175,6 +175,11 @@ namespace Nif { "NiSequence", &construct }, { "NiControllerSequence", &construct }, { "NiDefaultAVObjectPalette", &construct }, + { "NiBlendBoolInterpolator", &construct }, + { "NiBlendFloatInterpolator", &construct }, + { "NiBlendPoint3Interpolator", &construct }, + { "NiBlendTransformInterpolator", + &construct }, }; } diff --git a/components/nif/record.hpp b/components/nif/record.hpp index 558066b8c6..bc2fa41409 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -152,6 +152,10 @@ namespace Nif RC_NiSequence, RC_NiControllerSequence, RC_NiDefaultAVObjectPalette, + RC_NiBlendBoolInterpolator, + RC_NiBlendFloatInterpolator, + RC_NiBlendPoint3Interpolator, + RC_NiBlendTransformInterpolator, }; /// Base class for all records diff --git a/components/nif/recordptr.hpp b/components/nif/recordptr.hpp index cb85763a22..b7ad9d3dbb 100644 --- a/components/nif/recordptr.hpp +++ b/components/nif/recordptr.hpp @@ -142,6 +142,7 @@ namespace Nif struct NiInterpolator; struct NiStringPalette; struct NiControllerManager; + struct NiBlendInterpolator; using NodePtr = RecordPtrT; using ExtraPtr = RecordPtrT; @@ -174,6 +175,7 @@ namespace Nif using NiInterpolatorPtr = RecordPtrT; using NiStringPalettePtr = RecordPtrT; using NiControllerManagerPtr = RecordPtrT; + using NiBlendInterpolatorPtr = RecordPtrT; using NodeList = RecordListT; using PropertyList = RecordListT;