1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 12:32:36 +00:00
OpenMW/components/nif/controller.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

424 lines
11 KiB
C++
Raw Normal View History

#ifndef OPENMW_COMPONENTS_NIF_CONTROLLER_HPP
#define OPENMW_COMPONENTS_NIF_CONTROLLER_HPP
2010-01-07 19:52:11 +01:00
#include "base.hpp"
#include "niftypes.hpp"
2023-07-15 04:17:43 +03:00
#include "property.hpp"
2010-01-07 19:52:11 +01:00
namespace Nif
{
2023-02-08 00:26:40 +03:00
struct ControlledBlock
{
std::string mTargetName;
NiInterpolatorPtr mInterpolator;
ControllerPtr mController;
NiBlendInterpolatorPtr mBlendInterpolator;
uint16_t mBlendIndex;
uint8_t mPriority;
2023-02-08 00:26:40 +03:00
NiStringPalettePtr mStringPalette;
uint32_t mNodeNameOffset;
uint32_t mPropertyTypeOffset;
uint32_t mControllerTypeOffset;
uint32_t mControllerIdOffset;
uint32_t mInterpolatorIdOffset;
2023-02-08 00:26:40 +03:00
std::string mNodeName;
std::string mPropertyType;
std::string mControllerType;
std::string mControllerId;
std::string mInterpolatorId;
void read(NIFStream* nif);
void post(Reader& nif);
};
// Gamebryo KF root node record type (pre-10.0)
struct NiSequence : public Record
{
std::string mName;
std::string mAccumRootName;
ExtraPtr mTextKeys;
uint32_t mArrayGrowBy;
2023-02-08 00:26:40 +03:00
std::vector<ControlledBlock> mControlledBlocks;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
};
// Gamebryo KF root node record type (10.0+)
struct NiControllerSequence : public NiSequence
{
float mWeight{ 1.f };
Controller::ExtrapolationMode mExtrapolationMode{ Controller::ExtrapolationMode::Constant };
float mFrequency{ 1.f };
float mPhase{ 1.f };
float mStartTime, mStopTime;
bool mPlayBackwards{ false };
NiControllerManagerPtr mManager;
NiStringPalettePtr mStringPalette;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
};
2022-09-15 00:58:10 +03:00
// Base class for controllers that use NiInterpolators to animate objects.
struct NiInterpController : public Controller
{
// Usually one of the flags.
bool mManagerControlled{ false };
void read(NIFStream* nif) override;
};
// Base class for controllers that use one NiInterpolator.
struct NiSingleInterpController : public NiInterpController
{
NiInterpolatorPtr mInterpolator;
2020-12-16 01:06:05 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2022-06-22 00:43:16 +03:00
};
2013-04-04 01:26:57 -07:00
// Base class for controllers that use a NiFloatInterpolator to animate their target.
struct NiFloatInterpController : public NiSingleInterpController
{
};
2013-04-03 20:56:35 -07:00
// Ditto for NiBoolInterpolator.
struct NiBoolInterpController : public NiSingleInterpController
{
};
2013-04-03 20:56:35 -07:00
// Ditto for NiPoint3Interpolator.
struct NiPoint3InterpController : public NiSingleInterpController
2022-09-22 21:26:05 +03:00
{
2013-04-03 20:56:35 -07:00
};
2013-04-04 01:26:57 -07:00
struct NiParticleSystemController : public Controller
2022-09-22 21:26:05 +03:00
{
2022-06-22 00:43:16 +03:00
enum BSPArrayController
2022-09-22 21:26:05 +03:00
{
2022-06-22 00:43:16 +03:00
BSPArrayController_AtNode = 0x8,
BSPArrayController_AtVertex = 0x10
2022-09-22 21:26:05 +03:00
};
2013-04-04 01:26:57 -07:00
struct Particle
2022-09-22 21:26:05 +03:00
{
2015-02-17 17:08:55 +01:00
osg::Vec3f velocity;
2013-04-04 01:26:57 -07:00
float lifetime;
float lifespan;
float timestamp;
2020-12-13 02:46:33 +03:00
unsigned short vertex;
2022-09-22 21:26:05 +03:00
};
2013-04-03 20:56:35 -07:00
float velocity;
float velocityRandom;
2022-09-22 21:26:05 +03:00
2013-04-03 20:56:35 -07:00
float verticalDir; // 0=up, pi/2=horizontal, pi=down
float verticalAngle;
float horizontalDir;
float horizontalAngle;
2022-09-22 21:26:05 +03:00
2013-04-04 01:26:57 -07:00
osg::Vec4f color;
2013-04-03 20:56:35 -07:00
float size;
float startTime;
2013-04-04 01:26:57 -07:00
float stopTime;
2022-09-22 21:26:05 +03:00
2013-04-03 20:56:35 -07:00
float emitRate;
float lifetime;
float lifetimeRandom;
enum EmitFlags
2022-09-22 21:26:05 +03:00
{
EmitFlag_NoAutoAdjust = 0x1 // If this flag is set, we use the emitRate value. Otherwise,
// we calculate an emit rate so that the maximum number of particles
// in the system (numParticles) is never exceeded.
2022-09-22 21:26:05 +03:00
};
int emitFlags;
2013-04-03 20:56:35 -07:00
osg::Vec3f offsetRandom;
2022-06-22 00:43:16 +03:00
NiAVObjectPtr emitter;
2010-01-07 19:52:11 +01:00
int numParticles;
int activeCount;
std::vector<Particle> particles;
NiParticleModifierPtr affectors;
NiParticleModifierPtr colliders;
2010-01-07 19:52:11 +01:00
2020-12-16 01:06:05 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
bool noAutoAdjust() const { return emitFlags & EmitFlag_NoAutoAdjust; }
bool emitAtVertex() const { return flags & BSPArrayController_AtVertex; }
};
2020-02-02 17:08:17 +03:00
using NiBSPArrayController = NiParticleSystemController;
struct NiMaterialColorController : public NiPoint3InterpController
2022-09-22 21:26:05 +03:00
{
2023-09-13 23:30:13 +03:00
enum class TargetColor
{
Ambient = 0,
Diffuse = 1,
Specular = 2,
Emissive = 3,
};
NiPosDataPtr mData;
2023-09-13 23:30:13 +03:00
TargetColor mTargetColor;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2010-01-07 19:52:11 +01:00
};
2020-12-16 01:06:05 +03:00
struct NiPathController : public Controller
{
NiPosDataPtr posData;
NiFloatDataPtr floatData;
2022-09-22 21:26:05 +03:00
enum Flags
2022-09-22 21:26:05 +03:00
{
Flag_OpenCurve = 0x020,
Flag_AllowFlip = 0x040,
Flag_Bank = 0x080,
Flag_ConstVelocity = 0x100,
Flag_Follow = 0x200,
Flag_FlipFollowAxis = 0x400
};
2022-09-22 21:26:05 +03:00
int bankDir;
float maxBankAngle, smoothing;
uint16_t followAxis;
2022-09-22 21:26:05 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2022-09-22 21:26:05 +03:00
};
struct NiLookAtController : public Controller
2022-09-22 21:26:05 +03:00
{
enum Flags
{
Flag_Flip = 0x1,
Flag_LookYAxis = 0x2,
Flag_LookZAxis = 0x4,
};
uint16_t mLookAtFlags{ 0 };
NiAVObjectPtr mLookAt;
2020-12-16 01:06:05 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2019-10-05 15:02:42 +03:00
};
2010-01-07 19:52:11 +01:00
struct NiUVController : public Controller
2022-09-22 21:26:05 +03:00
{
NiUVDataPtr data;
2010-01-07 19:52:11 +01:00
unsigned int uvSet;
2022-09-15 00:58:10 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2022-09-15 00:58:10 +03:00
};
struct NiKeyframeController : public NiSingleInterpController
2022-09-22 21:26:05 +03:00
{
NiKeyframeDataPtr mData;
2010-01-07 19:52:11 +01:00
2022-09-15 00:58:10 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2022-09-02 05:55:07 +03:00
};
struct NiMultiTargetTransformController : public NiInterpController
2022-09-22 21:26:05 +03:00
{
NiAVObjectList mExtraTargets;
2022-09-02 05:55:07 +03:00
2022-09-15 00:58:10 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2022-09-15 00:58:10 +03:00
};
struct NiAlphaController : public NiFloatInterpController
2022-09-22 21:26:05 +03:00
{
NiFloatDataPtr mData;
2010-01-07 19:52:11 +01:00
2022-09-15 00:58:10 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2022-09-15 00:58:10 +03:00
};
struct NiRollController : public NiSingleInterpController
2022-09-22 21:26:05 +03:00
{
2022-09-15 00:58:10 +03:00
NiFloatDataPtr mData;
2022-09-15 00:58:10 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
};
2022-09-15 00:58:10 +03:00
struct NiGeomMorpherController : public NiInterpController
2022-09-22 21:26:05 +03:00
{
bool mUpdateNormals{ false };
bool mAlwaysActive{ false };
NiMorphDataPtr mData;
NiInterpolatorList mInterpolators;
std::vector<float> mWeights;
2022-09-22 21:26:05 +03:00
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2010-01-07 19:52:11 +01:00
};
2022-09-15 00:58:10 +03:00
struct NiVisController : public NiBoolInterpController
2010-01-07 19:52:11 +01:00
{
2022-09-15 00:58:10 +03:00
NiVisDataPtr mData;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2010-01-07 19:52:11 +01:00
};
2022-09-15 00:58:10 +03:00
struct NiFlipController : public NiFloatInterpController
2013-04-19 15:07:08 -07:00
{
NiTexturingProperty::TextureType mTexSlot;
2013-04-19 15:07:08 -07:00
float mDelta; // Time between two flips. delta = (start_time - stop_time) / num_sources
NiSourceTextureList mSources;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
2013-04-19 15:07:08 -07:00
};
2023-07-15 04:17:43 +03:00
struct NiTextureTransformController : public NiFloatInterpController
{
bool mShaderMap;
NiTexturingProperty::TextureType mTexSlot;
uint32_t mTransformMember;
2023-07-15 04:17:43 +03:00
NiFloatDataPtr mData;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
};
struct bhkBlendController : public Controller
{
void read(NIFStream* nif) override;
};
struct BSEffectShaderPropertyFloatController : public NiFloatInterpController
{
uint32_t mControlledVariable;
void read(NIFStream* nif) override;
};
struct BSEffectShaderPropertyColorController : public NiPoint3InterpController
{
uint32_t mControlledColor;
void read(NIFStream* nif) override;
};
2021-11-10 19:42:55 +03:00
struct NiControllerManager : public Controller
{
bool mCumulative;
2023-02-08 23:35:22 +03:00
NiControllerSequenceList mSequences;
NiDefaultAVObjectPalettePtr mObjectPalette;
2021-11-10 19:42:55 +03:00
void read(NIFStream* nif) override;
2023-02-08 23:35:22 +03:00
void post(Reader& nif) override;
2021-11-10 19:42:55 +03:00
};
// Abstract
2022-09-15 00:58:10 +03:00
struct NiInterpolator : public Record
{
};
2023-09-14 00:15:02 +03:00
template<class T, class DataPtr>
struct TypedNiInterpolator : public NiInterpolator
{
2023-09-14 00:15:02 +03:00
T mDefaultValue;
DataPtr mData;
2023-09-14 00:15:02 +03:00
void read(NIFStream* nif) override
{
nif->read(mDefaultValue);
mData.read(nif);
}
2023-09-14 00:15:02 +03:00
void post(Reader& nif) override
{
mData.post(nif);
}
};
2023-09-14 00:15:02 +03:00
using NiPoint3Interpolator = TypedNiInterpolator<osg::Vec3f, NiPosDataPtr>;
using NiBoolInterpolator = TypedNiInterpolator<bool, NiBoolDataPtr>;
using NiFloatInterpolator = TypedNiInterpolator<float, NiFloatDataPtr>;
using NiTransformInterpolator = TypedNiInterpolator<NiQuatTransform, NiKeyframeDataPtr>;
using NiColorInterpolator = TypedNiInterpolator<osg::Vec4f, NiColorDataPtr>;
2023-02-08 22:58:47 +03:00
// Abstract
struct NiBlendInterpolator : public NiInterpolator
{
enum Flags
{
Flag_ManagerControlled = 0x1,
Flag_OnlyUseHighestWeight = 0x2,
};
2023-02-08 22:58:47 +03:00
struct Item
{
NiInterpolatorPtr mInterpolator;
float mWeight, mNormalizedWeight;
int32_t mPriority;
2023-02-08 22:58:47 +03:00
float mEaseSpinner;
void read(NIFStream* nif);
void post(Reader& nif);
};
uint8_t mFlags{ 0 };
uint16_t mArrayGrowBy{ 0 };
2023-02-08 22:58:47 +03:00
float mWeightThreshold;
uint16_t mInterpCount;
uint16_t mSingleIndex;
int32_t mHighPriority, mNextHighPriority;
2023-02-08 22:58:47 +03:00
float mSingleTime;
float mHighWeightsSum, mNextHighWeightsSum;
float mHighEaseSpinner;
std::vector<Item> mItems;
NiInterpolatorPtr mSingleInterpolator;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
};
template <typename T>
struct TypedNiBlendInterpolator : public NiBlendInterpolator
{
T mValue;
void read(NIFStream* nif) override
{
NiBlendInterpolator::read(nif);
nif->read(mValue);
}
};
template <>
struct TypedNiBlendInterpolator<NiQuatTransform> : public NiBlendInterpolator
{
NiQuatTransform mValue;
void read(NIFStream* nif) override
{
NiBlendInterpolator::read(nif);
if (nif->getVersion() <= NIFStream::generateVersion(10, 1, 0, 109))
nif->read(mValue);
}
};
using NiBlendBoolInterpolator = TypedNiBlendInterpolator<uint8_t>;
using NiBlendFloatInterpolator = TypedNiBlendInterpolator<float>;
using NiBlendPoint3Interpolator = TypedNiBlendInterpolator<osg::Vec3f>;
using NiBlendTransformInterpolator = TypedNiBlendInterpolator<NiQuatTransform>;
}
2010-01-07 19:52:11 +01:00
#endif