From a923e311f5e771e5acf98c4721e1ab9e90bcde04 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Sun, 1 Dec 2024 02:00:12 +0300 Subject: [PATCH] Give NiLightColorController its own struct --- components/nif/controller.cpp | 22 +++++++++++++++++++++- components/nif/controller.hpp | 15 +++++++++++++++ components/nif/niffile.cpp | 3 +-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/components/nif/controller.cpp b/components/nif/controller.cpp index 930ce4fa0d..7e9b6b917e 100644 --- a/components/nif/controller.cpp +++ b/components/nif/controller.cpp @@ -231,12 +231,32 @@ namespace Nif mCollider.post(nif); } + void NiLightColorController::read(NIFStream* nif) + { + NiPoint3InterpController::read(nif); + + if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) + mMode = static_cast(nif->get()); + else + mMode = static_cast((mFlags >> 4) & 1); + + if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 103)) + mData.read(nif); + } + + void NiLightColorController::post(Reader& nif) + { + NiPoint3InterpController::post(nif); + + mData.post(nif); + } + void NiMaterialColorController::read(NIFStream* nif) { NiPoint3InterpController::read(nif); if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0)) - mTargetColor = static_cast(nif->get() & 3); + mTargetColor = static_cast(nif->get()); else mTargetColor = static_cast((mFlags >> 4) & 3); diff --git a/components/nif/controller.hpp b/components/nif/controller.hpp index d4aae6ed5d..2226a6e9df 100644 --- a/components/nif/controller.hpp +++ b/components/nif/controller.hpp @@ -161,6 +161,21 @@ namespace Nif }; using NiBSPArrayController = NiParticleSystemController; + struct NiLightColorController : public NiPoint3InterpController + { + enum class Mode + { + DiffuseSpecular = 0, + Ambient = 1, + }; + + NiPosDataPtr mData; + Mode mMode = Mode::DiffuseSpecular; + + void read(NIFStream* nif) override; + void post(Reader& nif) override; + }; + struct NiMaterialColorController : public NiPoint3InterpController { enum class TargetColor diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index 420765262e..02b110a5a6 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -112,8 +112,7 @@ namespace Nif { "NiGeomMorpherController", &construct }, { "NiKeyframeController", &construct }, { "NiLookAtController", &construct }, - // FIXME: NiLightColorController should have its own struct - { "NiLightColorController", &construct }, + { "NiLightColorController", &construct }, { "NiMaterialColorController", &construct }, { "NiPathController", &construct }, { "NiRollController", &construct },