Disable freezeOnCull for weather particles

openmw-37
scrawl 9 years ago
parent 5ca0ae5232
commit fd1ccd21ff

@ -1111,25 +1111,6 @@ namespace MWRender
attachTo->addChild(lightSource); attachTo->addChild(lightSource);
} }
class DisableFreezeOnCullVisitor : public osg::NodeVisitor
{
public:
DisableFreezeOnCullVisitor()
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
{
}
virtual void apply(osg::Geode &geode)
{
for (unsigned int i=0; i<geode.getNumDrawables(); ++i)
{
osg::Drawable* drw = geode.getDrawable(i);
if (osgParticle::ParticleSystem* partsys = dynamic_cast<osgParticle::ParticleSystem*>(drw))
partsys->setFreezeOnCull(false);
}
}
};
void Animation::addEffect (const std::string& model, int effectId, bool loop, const std::string& bonename, std::string texture) void Animation::addEffect (const std::string& model, int effectId, bool loop, const std::string& bonename, std::string texture)
{ {
if (!mObjectRoot.get()) if (!mObjectRoot.get())
@ -1163,7 +1144,7 @@ namespace MWRender
node->accept(findMaxLengthVisitor); node->accept(findMaxLengthVisitor);
// FreezeOnCull doesn't work so well with effect particles, that tend to have moving emitters // FreezeOnCull doesn't work so well with effect particles, that tend to have moving emitters
DisableFreezeOnCullVisitor disableFreezeOnCullVisitor; SceneUtil::DisableFreezeOnCullVisitor disableFreezeOnCullVisitor;
node->accept(disableFreezeOnCullVisitor); node->accept(disableFreezeOnCullVisitor);
params.mMaxControllerLength = findMaxLengthVisitor.getMaxLength(); params.mMaxControllerLength = findMaxLengthVisitor.getMaxLength();

@ -35,6 +35,7 @@
#include <components/sceneutil/util.hpp> #include <components/sceneutil/util.hpp>
#include <components/sceneutil/statesetupdater.hpp> #include <components/sceneutil/statesetupdater.hpp>
#include <components/sceneutil/controller.hpp> #include <components/sceneutil/controller.hpp>
#include <components/sceneutil/visitor.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
@ -1468,6 +1469,9 @@ void SkyManager::setWeather(const WeatherResult& weather)
AlphaFader::SetupVisitor alphaFaderSetupVisitor; AlphaFader::SetupVisitor alphaFaderSetupVisitor;
mParticleEffect->accept(alphaFaderSetupVisitor); mParticleEffect->accept(alphaFaderSetupVisitor);
mParticleFaders = alphaFaderSetupVisitor.getAlphaFaders(); mParticleFaders = alphaFaderSetupVisitor.getAlphaFaders();
SceneUtil::DisableFreezeOnCullVisitor disableFreezeOnCullVisitor;
mParticleEffect->accept(disableFreezeOnCullVisitor);
} }
} }

@ -0,0 +1,32 @@
#include "visitor.hpp"
#include <osg/Geode>
#include <osgParticle/ParticleSystem>
#include <components/misc/stringops.hpp>
namespace SceneUtil
{
void FindByNameVisitor::apply(osg::Group &group)
{
if (Misc::StringUtils::ciEqual(group.getName(), mNameToFind))
{
mFoundNode = &group;
return;
}
traverse(group);
}
void DisableFreezeOnCullVisitor::apply(osg::Geode &geode)
{
for (unsigned int i=0; i<geode.getNumDrawables(); ++i)
{
osg::Drawable* drw = geode.getDrawable(i);
if (osgParticle::ParticleSystem* partsys = dynamic_cast<osgParticle::ParticleSystem*>(drw))
partsys->setFreezeOnCull(false);
}
}
}

@ -3,12 +3,12 @@
#include <osg/NodeVisitor> #include <osg/NodeVisitor>
#include <components/misc/stringops.hpp>
// Commonly used scene graph visitors // Commonly used scene graph visitors
namespace SceneUtil namespace SceneUtil
{ {
// Find a Group by name, case-insensitive
// If not found, mFoundNode will be NULL
class FindByNameVisitor : public osg::NodeVisitor class FindByNameVisitor : public osg::NodeVisitor
{ {
public: public:
@ -19,20 +19,24 @@ namespace SceneUtil
{ {
} }
virtual void apply(osg::Group& group) virtual void apply(osg::Group& group);
{
if (Misc::StringUtils::ciEqual(group.getName(), mNameToFind))
{
mFoundNode = &group;
return;
}
traverse(group);
}
std::string mNameToFind; std::string mNameToFind;
osg::Group* mFoundNode; osg::Group* mFoundNode;
}; };
// Disable freezeOnCull for all visited particlesystems
class DisableFreezeOnCullVisitor : public osg::NodeVisitor
{
public:
DisableFreezeOnCullVisitor()
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
{
}
virtual void apply(osg::Geode &geode);
};
} }
#endif #endif

Loading…
Cancel
Save