From c8307ad397413b82f08cdad20ec42a656e773e81 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 21 Sep 2023 13:09:33 +0300 Subject: [PATCH] Read particle system modifier controllers --- components/nif/niffile.cpp | 28 +++++++++++++++++++++++- components/nif/particle.cpp | 25 +++++++++++++++++++++ components/nif/particle.hpp | 42 ++++++++++++++++++++++++++++++++++++ components/nif/record.hpp | 22 ++++++++++++++++++- components/nif/recordptr.hpp | 2 ++ 5 files changed, 117 insertions(+), 2 deletions(-) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index fe59bb8b9d..62516c1df7 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -276,7 +276,33 @@ namespace Nif { "NiParticleGrowFade", &construct }, { "NiParticleRotation", &construct }, - // Modifier data, Gamebryo + // Modifier controllers, Gamebryo + { "NiPSysAirFieldAirFrictionCtlr", &construct }, + { "NiPSysAirFieldInheritVelocityCtlr", + &construct }, + { "NiPSysAirFieldSpreadCtlr", &construct }, + { "NiPSysEmitterCtlr", &construct }, + { "NiPSysEmitterDeclinationCtlr", &construct }, + { "NiPSysEmitterDeclinationVarCtlr", + &construct }, + { "NiPSysEmitterInitialRadiusCtlr", + &construct }, + { "NiPSysEmitterLifeSpanCtlr", &construct }, + { "NiPSysEmitterPlanarAngleCtlr", &construct }, + { "NiPSysEmitterPlanarAngleVarCtlr", + &construct }, + { "NiPSysEmitterSpeedCtlr", &construct }, + { "NiPSysFieldAttenuationCtlr", &construct }, + { "NiPSysFieldMagnitudeCtlr", &construct }, + { "NiPSysFieldMaxDistanceCtlr", &construct }, + { "NiPSysGravityStrengthCtlr", &construct }, + { "NiPSysInitialRotSpeedCtlr", &construct }, + { "NiPSysInitialRotSpeedVarCtlr", &construct }, + { "NiPSysInitialRotAngleCtlr", &construct }, + { "NiPSysInitialRotAngleVarCtlr", &construct }, + { "NiPSysModifierActiveCtlr", &construct }, + + // Modifier controller data, Gamebryo { "NiPSysEmitterCtlrData", &construct }, // Colliders, 4.0.0.2 diff --git a/components/nif/particle.cpp b/components/nif/particle.cpp index 14898abf94..389449ed77 100644 --- a/components/nif/particle.cpp +++ b/components/nif/particle.cpp @@ -175,6 +175,31 @@ namespace Nif } } + void NiPSysModifierCtlr::read(NIFStream* nif) + { + NiSingleInterpController::read(nif); + + nif->read(mModifierName); + } + + void NiPSysEmitterCtlr::read(NIFStream* nif) + { + NiPSysModifierCtlr::read(nif); + + if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 103)) + mData.read(nif); + else + mVisInterpolator.read(nif); + } + + void NiPSysEmitterCtlr::post(Reader& nif) + { + NiPSysModifierCtlr::post(nif); + + mData.post(nif); + mVisInterpolator.post(nif); + } + void NiPSysEmitterCtlrData::read(NIFStream* nif) { mFloatKeyList = std::make_shared(); diff --git a/components/nif/particle.hpp b/components/nif/particle.hpp index 084735a472..ffdb307bab 100644 --- a/components/nif/particle.hpp +++ b/components/nif/particle.hpp @@ -2,6 +2,7 @@ #define OPENMW_COMPONENTS_NIF_PARTICLE_HPP #include "base.hpp" +#include "controller.hpp" #include "data.hpp" namespace Nif @@ -123,6 +124,47 @@ namespace Nif void read(NIFStream* nif) override; }; + // Abstract + struct NiPSysModifierCtlr : NiSingleInterpController + { + std::string mModifierName; + + void read(NIFStream* nif) override; + }; + + template + struct TypedNiPSysModifierCtlr : NiPSysModifierCtlr + { + DataPtr mData; + + void read(NIFStream* nif) override + { + NiPSysModifierCtlr::read(nif); + + if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 103)) + mData.read(nif); + } + + void post(Reader& nif) override + { + NiPSysModifierCtlr::post(nif); + + mData.post(nif); + } + }; + + using NiPSysModifierBoolCtlr = TypedNiPSysModifierCtlr; + using NiPSysModifierFloatCtlr = TypedNiPSysModifierCtlr; + + struct NiPSysEmitterCtlr : NiPSysModifierCtlr + { + NiPSysEmitterCtlrDataPtr mData; + NiInterpolatorPtr mVisInterpolator; + + void read(NIFStream* nif) override; + void post(Reader& nif) override; + }; + struct NiPSysEmitterCtlrData : Record { FloatKeyMapPtr mFloatKeyList; diff --git a/components/nif/record.hpp b/components/nif/record.hpp index 3013bef8de..aa0dbf9f37 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -169,8 +169,28 @@ namespace Nif RC_NiPlanarCollider, RC_NiPoint3Interpolator, RC_NiPosData, - RC_NiPSysEmitterCtlrData, + RC_NiPSysAirFieldAirFrictionCtlr, + RC_NiPSysAirFieldInheritVelocityCtlr, + RC_NiPSysAirFieldSpreadCtlr, RC_NiPSysData, + RC_NiPSysEmitterCtlr, + RC_NiPSysEmitterCtlrData, + RC_NiPSysEmitterDeclinationCtlr, + RC_NiPSysEmitterDeclinationVarCtlr, + RC_NiPSysEmitterInitialRadiusCtlr, + RC_NiPSysEmitterLifeSpanCtlr, + RC_NiPSysEmitterPlanarAngleCtlr, + RC_NiPSysEmitterPlanarAngleVarCtlr, + RC_NiPSysEmitterSpeedCtlr, + RC_NiPSysFieldAttenuationCtlr, + RC_NiPSysFieldMagnitudeCtlr, + RC_NiPSysFieldMaxDistanceCtlr, + RC_NiPSysGravityStrengthCtlr, + RC_NiPSysInitialRotSpeedCtlr, + RC_NiPSysInitialRotSpeedVarCtlr, + RC_NiPSysInitialRotAngleCtlr, + RC_NiPSysInitialRotAngleVarCtlr, + RC_NiPSysModifierActiveCtlr, RC_NiRollController, RC_NiSequence, RC_NiSequenceStreamHelper, diff --git a/components/nif/recordptr.hpp b/components/nif/recordptr.hpp index 8598a88f0e..53b9c02a95 100644 --- a/components/nif/recordptr.hpp +++ b/components/nif/recordptr.hpp @@ -129,6 +129,7 @@ namespace Nif struct NiSourceTexture; struct NiPalette; struct NiParticleModifier; + struct NiPSysEmitterCtlrData; struct NiBoolData; struct NiSkinPartition; struct BSShaderTextureSet; @@ -170,6 +171,7 @@ namespace Nif using NiSourceTexturePtr = RecordPtrT; using NiPalettePtr = RecordPtrT; using NiParticleModifierPtr = RecordPtrT; + using NiPSysEmitterCtlrDataPtr = RecordPtrT; using NiBoolDataPtr = RecordPtrT; using NiSkinPartitionPtr = RecordPtrT; using BSShaderTextureSetPtr = RecordPtrT;