From 04d3f6a42d13a600fe62bd08b9b92dcd8eea2a76 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 14 Sep 2023 02:20:18 +0300 Subject: [PATCH] Update NiPathController Support 10.1.0.0+ NiPathController loading --- components/nif/controller.cpp | 21 +++++++++++++-------- components/nif/controller.hpp | 26 ++++++++++++++------------ components/nifosg/controller.cpp | 6 +++--- components/nifosg/nifloader.cpp | 2 +- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/components/nif/controller.cpp b/components/nif/controller.cpp index 84c43bafcf..d9e6d657d7 100644 --- a/components/nif/controller.cpp +++ b/components/nif/controller.cpp @@ -267,20 +267,25 @@ namespace Nif { Controller::read(nif); - bankDir = nif->getInt(); - maxBankAngle = nif->getFloat(); - smoothing = nif->getFloat(); - nif->read(followAxis); - posData.read(nif); - floatData.read(nif); + if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) + nif->read(mPathFlags); + else + mPathFlags = (flags >> 16); + + nif->read(mBankDirection); + nif->read(mMaxBankAngle); + nif->read(mSmoothing); + nif->read(mFollowAxis); + mPathData.read(nif); + mPercentData.read(nif); } void NiPathController::post(Reader& nif) { Controller::post(nif); - posData.post(nif); - floatData.post(nif); + mPathData.post(nif); + mPercentData.post(nif); } void NiUVController::read(NIFStream* nif) diff --git a/components/nif/controller.hpp b/components/nif/controller.hpp index 87bfe615a0..046ddc2e5c 100644 --- a/components/nif/controller.hpp +++ b/components/nif/controller.hpp @@ -174,22 +174,24 @@ namespace Nif struct NiPathController : public Controller { - NiPosDataPtr posData; - NiFloatDataPtr floatData; - enum Flags { - Flag_OpenCurve = 0x020, - Flag_AllowFlip = 0x040, - Flag_Bank = 0x080, - Flag_ConstVelocity = 0x100, - Flag_Follow = 0x200, - Flag_FlipFollowAxis = 0x400 + Flag_CVDataNeedsUpdate = 0x01, + Flag_OpenCurve = 0x02, + Flag_AllowFlip = 0x04, + Flag_Bank = 0x08, + Flag_ConstVelocity = 0x10, + Flag_Follow = 0x20, + Flag_FlipFollowAxis = 0x40, }; - int bankDir; - float maxBankAngle, smoothing; - uint16_t followAxis; + uint16_t mPathFlags; + int32_t mBankDirection; + float mMaxBankAngle; + float mSmoothing; + uint16_t mFollowAxis; + NiPosDataPtr mPathData; + NiFloatDataPtr mPercentData; void read(NIFStream* nif) override; void post(Reader& nif) override; diff --git a/components/nifosg/controller.cpp b/components/nifosg/controller.cpp index d424d7f56b..3d83c63721 100644 --- a/components/nifosg/controller.cpp +++ b/components/nifosg/controller.cpp @@ -598,9 +598,9 @@ namespace NifOsg } PathController::PathController(const Nif::NiPathController* ctrl) - : mPath(ctrl->posData->mKeyList, osg::Vec3f()) - , mPercent(ctrl->floatData->mKeyList, 1.f) - , mFlags(ctrl->flags) + : mPath(ctrl->mPathData->mKeyList, osg::Vec3f()) + , mPercent(ctrl->mPercentData->mKeyList, 1.f) + , mFlags(ctrl->mPathFlags) { } diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 76dfd7a315..96740b8dd3 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -907,7 +907,7 @@ namespace NifOsg else if (ctrl->recType == Nif::RC_NiPathController) { const Nif::NiPathController* path = static_cast(ctrl.getPtr()); - if (path->posData.empty() || path->floatData.empty()) + if (path->mPathData.empty() || path->mPercentData.empty()) continue; osg::ref_ptr callback(new PathController(path)); setupController(path, callback, animflags);