From 7f9f9a32d27c9f96a53dff0ae03b529661177712 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 1 Jun 2015 16:25:15 +0200 Subject: [PATCH] InitWorldSpaceParticles fix --- apps/openmw/mwrender/creatureanimation.cpp | 9 +++++---- apps/openmw/mwrender/effectmanager.cpp | 1 + apps/openmw/mwrender/npcanimation.cpp | 1 + components/resource/scenemanager.cpp | 14 +++++++++++--- components/resource/scenemanager.hpp | 3 +++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 0dd647c9c..9d1fccdb2 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -107,12 +107,13 @@ void CreatureWeaponAnimation::updatePart(PartHolderPtr& scene, int slot) bonename = "Shield Bone"; osg::ref_ptr node = mResourceSystem->getSceneManager()->createInstance(item.getClass().getModel(item)); - SceneUtil::attach(node, mObjectRoot, bonename, bonename); + osg::ref_ptr attached = SceneUtil::attach(node, mObjectRoot, bonename, bonename); + mResourceSystem->getSceneManager()->notifyAttached(attached); - scene.reset(new PartHolder(node)); + scene.reset(new PartHolder(attached)); if (!item.getClass().getEnchantment(item).empty()) - addGlow(node, getEnchantmentColor(item)); + addGlow(attached, getEnchantmentColor(item)); // Crossbows start out with a bolt attached // FIXME: code duplicated from NpcAnimation @@ -137,7 +138,7 @@ void CreatureWeaponAnimation::updatePart(PartHolderPtr& scene, int slot) source.reset(new NullAnimationTime); SceneUtil::AssignControllerSourcesVisitor assignVisitor(source); - node->accept(assignVisitor); + attached->accept(assignVisitor); } void CreatureWeaponAnimation::attachArrow() diff --git a/apps/openmw/mwrender/effectmanager.cpp b/apps/openmw/mwrender/effectmanager.cpp index 42a63fc68..c4e457a1f 100644 --- a/apps/openmw/mwrender/effectmanager.cpp +++ b/apps/openmw/mwrender/effectmanager.cpp @@ -49,6 +49,7 @@ void EffectManager::addEffect(const std::string &model, const std::string& textu overrideTexture(textureOverride, mResourceSystem, node); mParentNode->addChild(trans); + mResourceSystem->getSceneManager()->notifyAttached(node); mEffects[trans] = effect; } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 0bbec707f..da44d7f20 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -628,6 +628,7 @@ PartHolderPtr NpcAnimation::insertBoundedPart(const std::string& model, const st { osg::ref_ptr instance = mResourceSystem->getSceneManager()->createInstance(model); osg::ref_ptr attached = SceneUtil::attach(instance, mObjectRoot, bonefilter, bonename); + mResourceSystem->getSceneManager()->notifyAttached(attached); if (enchantedGlow) addGlow(attached, *glowColor); diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 5c3d9f151..8de08bd9d 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -52,7 +52,10 @@ namespace void transformInitialParticles(osgParticle::ParticleSystem* partsys, osg::Node* node) { - osg::Matrix worldMat = node->getWorldMatrices()[0]; + osg::MatrixList mats = node->getWorldMatrices(); + if (mats.empty()) + return; + osg::Matrix worldMat = mats[0]; worldMat.orthoNormalize(worldMat); // scale is already applied on the particle node for (int i=0; inumParticles(); ++i) { @@ -140,8 +143,7 @@ namespace Resource void SceneManager::attachTo(osg::Node *instance, osg::Group *parentNode) const { parentNode->addChild(instance); - InitWorldSpaceParticlesVisitor visitor; - instance->accept(visitor); + notifyAttached(instance); } void SceneManager::releaseGLObjects(osg::State *state) @@ -157,6 +159,12 @@ namespace Resource mIncrementalCompileOperation = ico; } + void SceneManager::notifyAttached(osg::Node *node) const + { + InitWorldSpaceParticlesVisitor visitor; + node->accept(visitor); + } + const VFS::Manager* SceneManager::getVFS() const { return mVFS; diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index 625c1cd5e..f4ca0dea2 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -64,6 +64,9 @@ namespace Resource /// Set up an IncrementalCompileOperation for background compiling of loaded scenes. void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico); + /// @note If you used SceneManager::attachTo, this was called automatically. + void notifyAttached(osg::Node* node) const; + const VFS::Manager* getVFS() const; Resource::TextureManager* getTextureManager();