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

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

@ -1067,12 +1067,12 @@ namespace NifOsg
attachTo->addChild(program);
program->setParticleSystem(partsys);
program->setReferenceFrame(rf);
for (; !affectors.empty(); affectors = affectors->next)
for (; !affectors.empty(); affectors = affectors->mNext)
{
if (affectors->recType == Nif::RC_NiParticleGrowFade)
{
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)
{
@ -1083,9 +1083,9 @@ namespace NifOsg
{
const Nif::NiParticleColorModifier* cl
= static_cast<const Nif::NiParticleColorModifier*>(affectors.getPtr());
if (cl->data.empty())
if (cl->mData.empty())
continue;
const Nif::NiColorData* clrdata = cl->data.getPtr();
const Nif::NiColorData* clrdata = cl->mData.getPtr();
program->addOperator(new ParticleColorAffector(clrdata));
}
else if (affectors->recType == Nif::RC_NiParticleRotation)
@ -1095,7 +1095,7 @@ namespace NifOsg
else
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)
{

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

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

Loading…
Cancel
Save