Modernize particle modifiers

macos_ci_fix
Alexei Kotov 1 year ago
parent 2cd17830d3
commit 1d05aa2e37

@ -55,56 +55,59 @@ namespace Nif
void NiParticleModifier::read(NIFStream* nif) void NiParticleModifier::read(NIFStream* nif)
{ {
next.read(nif); mNext.read(nif);
controller.read(nif); if (nif->getVersion() >= NIFStream::generateVersion(3, 3, 0, 13))
mController.read(nif);
} }
void NiParticleModifier::post(Reader& nif) void NiParticleModifier::post(Reader& nif)
{ {
next.post(nif); mNext.post(nif);
controller.post(nif); mController.post(nif);
} }
void NiParticleGrowFade::read(NIFStream* nif) void NiParticleGrowFade::read(NIFStream* nif)
{ {
NiParticleModifier::read(nif); NiParticleModifier::read(nif);
growTime = nif->getFloat(); nif->read(mGrowTime);
fadeTime = nif->getFloat(); nif->read(mFadeTime);
} }
void NiParticleColorModifier::read(NIFStream* nif) void NiParticleColorModifier::read(NIFStream* nif)
{ {
NiParticleModifier::read(nif); NiParticleModifier::read(nif);
data.read(nif);
mData.read(nif);
} }
void NiParticleColorModifier::post(Reader& nif) void NiParticleColorModifier::post(Reader& nif)
{ {
NiParticleModifier::post(nif); NiParticleModifier::post(nif);
data.post(nif);
mData.post(nif);
} }
void NiGravity::read(NIFStream* nif) void NiGravity::read(NIFStream* nif)
{ {
NiParticleModifier::read(nif); NiParticleModifier::read(nif);
mDecay = nif->getFloat(); if (nif->getVersion() >= NIFStream::generateVersion(3, 3, 0, 13))
mForce = nif->getFloat(); nif->read(mDecay);
mType = nif->getUInt(); nif->read(mForce);
mPosition = nif->getVector3(); mType = static_cast<ForceType>(nif->get<uint32_t>());
mDirection = nif->getVector3(); nif->read(mPosition);
nif->read(mDirection);
} }
void NiParticleCollider::read(NIFStream* nif) void NiParticleCollider::read(NIFStream* nif)
{ {
NiParticleModifier::read(nif); NiParticleModifier::read(nif);
mBounceFactor = nif->getFloat(); nif->read(mBounceFactor);
if (nif->getVersion() >= NIFStream::generateVersion(4, 2, 0, 2)) if (nif->getVersion() >= NIFStream::generateVersion(4, 2, 0, 2))
{ {
// Unused in NifSkope. Need to figure out what these do. nif->read(mSpawnOnCollision);
/*bool mSpawnOnCollision = */ nif->getBoolean(); nif->read(mDieOnCollision);
/*bool mDieOnCollision = */ nif->getBoolean();
} }
} }
@ -112,29 +115,28 @@ namespace Nif
{ {
NiParticleCollider::read(nif); NiParticleCollider::read(nif);
mExtents = nif->getVector2(); nif->read(mExtents);
mPosition = nif->getVector3(); nif->read(mPosition);
mXVector = nif->getVector3(); nif->read(mXVector);
mYVector = nif->getVector3(); nif->read(mYVector);
mPlaneNormal = nif->getVector3(); nif->read(mPlaneNormal);
mPlaneDistance = nif->getFloat(); nif->read(mPlaneDistance);
} }
void NiParticleRotation::read(NIFStream* nif) void NiSphericalCollider::read(NIFStream* nif)
{ {
NiParticleModifier::read(nif); NiParticleCollider::read(nif);
/* bool mRandomInitialAxis = */ nif->getChar(); nif->read(mRadius);
/* osg::Vec3f mInitialAxis = */ nif->getVector3(); nif->read(mCenter);
/* float mRotationSpeed = */ nif->getFloat();
} }
void NiSphericalCollider::read(NIFStream* nif) void NiParticleRotation::read(NIFStream* nif)
{ {
NiParticleCollider::read(nif); NiParticleModifier::read(nif);
mRadius = nif->getFloat(); nif->read(mRandomInitialAxis);
mCenter = nif->getVector3(); nif->read(mInitialAxis);
nif->read(mRotationSpeed);
} }
} }

@ -85,8 +85,8 @@ namespace Nif
struct NiParticleModifier : public Record struct NiParticleModifier : public Record
{ {
NiParticleModifierPtr next; NiParticleModifierPtr mNext;
ControllerPtr controller; ControllerPtr mController;
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
void post(Reader& nif) override; void post(Reader& nif) override;
@ -94,15 +94,15 @@ namespace Nif
struct NiParticleGrowFade : public NiParticleModifier struct NiParticleGrowFade : public NiParticleModifier
{ {
float growTime; float mGrowTime;
float fadeTime; float mFadeTime;
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
}; };
struct NiParticleColorModifier : public NiParticleModifier struct NiParticleColorModifier : public NiParticleModifier
{ {
NiColorDataPtr data; NiColorDataPtr mData;
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
void post(Reader& nif) override; void post(Reader& nif) override;
@ -110,12 +110,15 @@ namespace Nif
struct NiGravity : public NiParticleModifier struct NiGravity : public NiParticleModifier
{ {
enum class ForceType : uint32_t
{
Wind = 0, // Fixed direction
Point = 1, // Fixed origin
};
float mDecay{ 0.f };
float mForce; float mForce;
/* 0 - Wind (fixed direction) ForceType mType;
* 1 - Point (fixed origin)
*/
int mType;
float mDecay;
osg::Vec3f mPosition; osg::Vec3f mPosition;
osg::Vec3f mDirection; osg::Vec3f mDirection;
@ -125,6 +128,9 @@ namespace Nif
struct NiParticleCollider : public NiParticleModifier struct NiParticleCollider : public NiParticleModifier
{ {
float mBounceFactor; float mBounceFactor;
bool mSpawnOnCollision{ false };
bool mDieOnCollision{ false };
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
}; };
@ -150,6 +156,10 @@ namespace Nif
struct NiParticleRotation : public NiParticleModifier struct NiParticleRotation : public NiParticleModifier
{ {
uint8_t mRandomInitialAxis;
osg::Vec3f mInitialAxis;
float mRotationSpeed;
void read(NIFStream* nif) override; void read(NIFStream* nif) override;
}; };

@ -1067,12 +1067,12 @@ namespace NifOsg
attachTo->addChild(program); attachTo->addChild(program);
program->setParticleSystem(partsys); program->setParticleSystem(partsys);
program->setReferenceFrame(rf); program->setReferenceFrame(rf);
for (; !affectors.empty(); affectors = affectors->next) for (; !affectors.empty(); affectors = affectors->mNext)
{ {
if (affectors->recType == Nif::RC_NiParticleGrowFade) if (affectors->recType == Nif::RC_NiParticleGrowFade)
{ {
const Nif::NiParticleGrowFade* gf = static_cast<const Nif::NiParticleGrowFade*>(affectors.getPtr()); const Nif::NiParticleGrowFade* gf = static_cast<const Nif::NiParticleGrowFade*>(affectors.getPtr());
program->addOperator(new GrowFadeAffector(gf->growTime, gf->fadeTime)); program->addOperator(new GrowFadeAffector(gf->mGrowTime, gf->mFadeTime));
} }
else if (affectors->recType == Nif::RC_NiGravity) else if (affectors->recType == Nif::RC_NiGravity)
{ {
@ -1083,9 +1083,9 @@ namespace NifOsg
{ {
const Nif::NiParticleColorModifier* cl const Nif::NiParticleColorModifier* cl
= static_cast<const Nif::NiParticleColorModifier*>(affectors.getPtr()); = static_cast<const Nif::NiParticleColorModifier*>(affectors.getPtr());
if (cl->data.empty()) if (cl->mData.empty())
continue; continue;
const Nif::NiColorData* clrdata = cl->data.getPtr(); const Nif::NiColorData* clrdata = cl->mData.getPtr();
program->addOperator(new ParticleColorAffector(clrdata)); program->addOperator(new ParticleColorAffector(clrdata));
} }
else if (affectors->recType == Nif::RC_NiParticleRotation) else if (affectors->recType == Nif::RC_NiParticleRotation)
@ -1095,7 +1095,7 @@ namespace NifOsg
else else
Log(Debug::Info) << "Unhandled particle modifier " << affectors->recName << " in " << mFilename; Log(Debug::Info) << "Unhandled particle modifier " << affectors->recName << " in " << mFilename;
} }
for (; !colliders.empty(); colliders = colliders->next) for (; !colliders.empty(); colliders = colliders->mNext)
{ {
if (colliders->recType == Nif::RC_NiPlanarCollider) if (colliders->recType == Nif::RC_NiPlanarCollider)
{ {

@ -281,20 +281,13 @@ namespace NifOsg
GravityAffector::GravityAffector(const Nif::NiGravity* gravity) GravityAffector::GravityAffector(const Nif::NiGravity* gravity)
: mForce(gravity->mForce) : mForce(gravity->mForce)
, mType(static_cast<ForceType>(gravity->mType)) , mType(gravity->mType)
, mPosition(gravity->mPosition) , mPosition(gravity->mPosition)
, mDirection(gravity->mDirection) , mDirection(gravity->mDirection)
, mDecay(gravity->mDecay) , mDecay(gravity->mDecay)
{ {
} }
GravityAffector::GravityAffector()
: mForce(0)
, mType(Type_Wind)
, mDecay(0.f)
{
}
GravityAffector::GravityAffector(const GravityAffector& copy, const osg::CopyOp& copyop) GravityAffector::GravityAffector(const GravityAffector& copy, const osg::CopyOp& copyop)
: osgParticle::Operator(copy, copyop) : osgParticle::Operator(copy, copyop)
{ {
@ -311,8 +304,8 @@ namespace NifOsg
{ {
bool absolute = (program->getReferenceFrame() == osgParticle::ParticleProcessor::ABSOLUTE_RF); bool absolute = (program->getReferenceFrame() == osgParticle::ParticleProcessor::ABSOLUTE_RF);
if (mType == Type_Point // We don't need the position for Wind gravity, except if decay is being applied
|| mDecay != 0.f) // we don't need the position for Wind gravity, except if decay is being applied if (mType == Nif::NiGravity::ForceType::Point || mDecay != 0.f)
mCachedWorldPosition = absolute ? program->transformLocalToWorld(mPosition) : mPosition; mCachedWorldPosition = absolute ? program->transformLocalToWorld(mPosition) : mPosition;
mCachedWorldDirection = absolute ? program->rotateLocalToWorld(mDirection) : mDirection; mCachedWorldDirection = absolute ? program->rotateLocalToWorld(mDirection) : mDirection;
@ -324,7 +317,7 @@ namespace NifOsg
const float magic = 1.6f; const float magic = 1.6f;
switch (mType) switch (mType)
{ {
case Type_Wind: case Nif::NiGravity::ForceType::Wind:
{ {
float decayFactor = 1.f; float decayFactor = 1.f;
if (mDecay != 0.f) if (mDecay != 0.f)
@ -338,7 +331,7 @@ namespace NifOsg
break; break;
} }
case Type_Point: case Nif::NiGravity::ForceType::Point:
{ {
osg::Vec3f diff = mCachedWorldPosition - particle->getPosition(); osg::Vec3f diff = mCachedWorldPosition - particle->getPosition();

@ -10,15 +10,14 @@
#include <osgParticle/Placer> #include <osgParticle/Placer>
#include <osgParticle/Shooter> #include <osgParticle/Shooter>
#include <components/nif/controlled.hpp> // NiGravity::ForceType
#include <components/sceneutil/nodecallback.hpp> #include <components/sceneutil/nodecallback.hpp>
#include "controller.hpp" // ValueInterpolator #include "controller.hpp" // ValueInterpolator
namespace Nif namespace Nif
{ {
struct NiGravity;
struct NiPlanarCollider;
struct NiSphericalCollider;
struct NiColorData; struct NiColorData;
} }
@ -180,7 +179,7 @@ namespace NifOsg
{ {
public: public:
GravityAffector(const Nif::NiGravity* gravity); GravityAffector(const Nif::NiGravity* gravity);
GravityAffector(); GravityAffector() = default;
GravityAffector(const GravityAffector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); GravityAffector(const GravityAffector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
GravityAffector& operator=(const GravityAffector&) = delete; GravityAffector& operator=(const GravityAffector&) = delete;
@ -191,16 +190,11 @@ namespace NifOsg
void beginOperate(osgParticle::Program*) override; void beginOperate(osgParticle::Program*) override;
private: private:
float mForce; float mForce{ 0.f };
enum ForceType Nif::NiGravity::ForceType mType{ Nif::NiGravity::ForceType::Wind };
{
Type_Wind,
Type_Point
};
ForceType mType;
osg::Vec3f mPosition; osg::Vec3f mPosition;
osg::Vec3f mDirection; osg::Vec3f mDirection;
float mDecay; float mDecay{ 0.f };
osg::Vec3f mCachedWorldPosition; osg::Vec3f mCachedWorldPosition;
osg::Vec3f mCachedWorldDirection; osg::Vec3f mCachedWorldDirection;
}; };

Loading…
Cancel
Save