diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index c049fa62e..04b3d0e9a 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -10,6 +10,7 @@ #include #include +#include #include @@ -47,6 +48,44 @@ namespace { + /// Removes all particle systems and related nodes in a subgraph. + class RemoveParticlesVisitor : public osg::NodeVisitor + { + public: + RemoveParticlesVisitor() + : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) + { } + + virtual void apply(osg::Node &node) + { + if (dynamic_cast(&node)) + mToRemove.push_back(&node); + + traverse(node); + } + + virtual void apply(osg::Drawable& drw) + { + if (osgParticle::ParticleSystem* partsys = dynamic_cast(&drw)) + mToRemove.push_back(partsys); + } + + void remove() + { + for (std::vector >::iterator it = mToRemove.begin(); it != mToRemove.end(); ++it) + { + // FIXME: a Drawable might have more than one parent + osg::Node* node = *it; + if (node->getNumParents()) + node->getParent(0)->removeChild(node); + } + mToRemove.clear(); + } + + private: + std::vector > mToRemove; + }; + class GlowUpdater : public SceneUtil::StateSetUpdater { public: @@ -1439,6 +1478,13 @@ namespace MWRender } if (ptr.getTypeName() == typeid(ESM::Light).name() && allowLight) addExtraLight(getOrCreateObjectRoot(), ptr.get()->mBase); + + if (!allowLight) + { + RemoveParticlesVisitor visitor; + mObjectRoot->accept(visitor); + visitor.remove(); + } } Animation::AnimState::~AnimState() diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index e40863622..2408d1ba0 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -5,12 +5,6 @@ #include #include -#include -#include - -#include - -#include #include #include @@ -22,49 +16,6 @@ #include "creatureanimation.hpp" #include "vismask.hpp" -namespace -{ - - /// Removes all particle systems and related nodes in a subgraph. - class RemoveParticlesVisitor : public osg::NodeVisitor - { - public: - RemoveParticlesVisitor() - : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) - { } - - virtual void apply(osg::Node &node) - { - if (dynamic_cast(&node)) - mToRemove.push_back(&node); - - traverse(node); - } - - virtual void apply(osg::Drawable& drw) - { - if (osgParticle::ParticleSystem* partsys = dynamic_cast(&drw)) - mToRemove.push_back(partsys); - } - - void remove() - { - for (std::vector >::iterator it = mToRemove.begin(); it != mToRemove.end(); ++it) - { - // FIXME: a Drawable might have more than one parent - osg::Node* node = *it; - if (node->getNumParents()) - node->getParent(0)->removeChild(node); - } - mToRemove.clear(); - } - - private: - std::vector > mToRemove; - }; - -} - namespace MWRender { @@ -124,13 +75,6 @@ void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool std::auto_ptr anim (new ObjectAnimation(ptr, mesh, mResourceSystem, animated, allowLight)); - if (!allowLight) - { - RemoveParticlesVisitor visitor; - anim->getObjectRoot()->accept(visitor); - visitor.remove(); - } - mObjects.insert(std::make_pair(ptr, anim.release())); }