mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
Subclass ParticleSystem to support limit on the number of particles
This commit is contained in:
parent
2e11642273
commit
71782462b7
3 changed files with 46 additions and 1 deletions
|
@ -571,7 +571,7 @@ namespace NifOsg
|
|||
|
||||
void Loader::handleParticleSystem(const Nif::Node *nifNode, osg::Group *parentNode, int animflags, int particleflags)
|
||||
{
|
||||
osg::ref_ptr<osgParticle::ParticleSystem> partsys (new osgParticle::ParticleSystem);
|
||||
osg::ref_ptr<ParticleSystem> partsys (new ParticleSystem);
|
||||
partsys->setSortMode(osgParticle::ParticleSystem::SORT_BACK_TO_FRONT);
|
||||
|
||||
const Nif::NiAutoNormalParticlesData *particledata = NULL;
|
||||
|
@ -630,6 +630,8 @@ namespace NifOsg
|
|||
created->setSizeRange(osgParticle::rangef(size, size));
|
||||
}
|
||||
|
||||
partsys->setQuota(partctrl->numParticles);
|
||||
|
||||
partsys->getDefaultParticleTemplate().setSizeRange(osgParticle::rangef(partctrl->size, partctrl->size));
|
||||
partsys->getDefaultParticleTemplate().setColorRange(osgParticle::rangev4(osg::Vec4f(1.f,1.f,1.f,1.f), osg::Vec4f(1.f,1.f,1.f,1.f)));
|
||||
partsys->getDefaultParticleTemplate().setAlphaRange(osgParticle::rangef(1.f, 1.f));
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "particle.hpp"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include <components/nif/controlled.hpp>
|
||||
|
@ -9,6 +11,30 @@
|
|||
namespace NifOsg
|
||||
{
|
||||
|
||||
ParticleSystem::ParticleSystem()
|
||||
: osgParticle::ParticleSystem()
|
||||
, mQuota(std::numeric_limits<int>::max())
|
||||
{
|
||||
}
|
||||
|
||||
ParticleSystem::ParticleSystem(const ParticleSystem ©, const osg::CopyOp ©op)
|
||||
: osgParticle::ParticleSystem(copy, copyop)
|
||||
, mQuota(copy.mQuota)
|
||||
{
|
||||
}
|
||||
|
||||
void ParticleSystem::setQuota(int quota)
|
||||
{
|
||||
mQuota = quota;
|
||||
}
|
||||
|
||||
osgParticle::Particle* ParticleSystem::createParticle(const osgParticle::Particle *ptemplate)
|
||||
{
|
||||
if (numParticles()-numDeadParticles() < mQuota)
|
||||
return osgParticle::ParticleSystem::createParticle(ptemplate);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void InverseWorldMatrix::operator()(osg::Node *node, osg::NodeVisitor *nv)
|
||||
{
|
||||
if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
||||
|
|
|
@ -20,6 +20,23 @@ namespace Nif
|
|||
namespace NifOsg
|
||||
{
|
||||
|
||||
// Subclass ParticleSystem to support a limit on the number of active particles.
|
||||
class ParticleSystem : public osgParticle::ParticleSystem
|
||||
{
|
||||
public:
|
||||
ParticleSystem();
|
||||
ParticleSystem(const ParticleSystem& copy, const osg::CopyOp& copyop);
|
||||
|
||||
META_Object(NifOsg, NifOsg::ParticleSystem)
|
||||
|
||||
virtual osgParticle::Particle* createParticle(const osgParticle::Particle *ptemplate);
|
||||
|
||||
void setQuota(int quota);
|
||||
|
||||
private:
|
||||
int mQuota;
|
||||
};
|
||||
|
||||
// HACK: Particle doesn't allow setting the initial age, but we need this for loading the particle system state
|
||||
class ParticleAgeSetter : public osgParticle::Particle
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue