diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 3426094c8..a12375a9b 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -274,7 +274,7 @@ public: void removeEffect (int effectId); void getLoopingEffects (std::vector& out); - void updatePtr(const MWWorld::Ptr &ptr); + virtual void updatePtr(const MWWorld::Ptr &ptr); bool hasAnimation(const std::string &anim); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 26f05e35f..2bb1b66fd 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -76,6 +76,11 @@ HeadAnimationTime::HeadAnimationTime(MWWorld::Ptr reference) resetBlinkTimer(); } +void HeadAnimationTime::updatePtr(const MWWorld::Ptr &updated) +{ + mReference = updated; +} + void HeadAnimationTime::setEnabled(bool enabled) { mEnabled = enabled; @@ -901,6 +906,12 @@ void NpcAnimation::setVampire(bool vampire) } } +void NpcAnimation::updatePtr(const MWWorld::Ptr &updated) +{ + Animation::updatePtr(updated); + mHeadAnimationTime->updatePtr(updated); +} + /* void NpcAnimation::setHeadPitch(Ogre::Radian pitch) { diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 0c91dfe6e..a58f0fdf3 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -34,6 +34,8 @@ private: public: HeadAnimationTime(MWWorld::Ptr reference); + void updatePtr(const MWWorld::Ptr& updated); + void update(float dt); void setEnabled(bool enabled); @@ -176,6 +178,8 @@ public: virtual void setAlpha(float alpha); virtual void setVampire(bool vampire); + + virtual void updatePtr(const MWWorld::Ptr& updated); }; } diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 17fbbe549..5face96a6 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -198,30 +198,33 @@ void Objects::removeCell(const MWWorld::CellStore* store) } } -void Objects::updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur) +void Objects::updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &cur) { - /* - Ogre::SceneNode *node; MWWorld::CellStore *newCell = cur.getCell(); + osg::Group* cellnode; if(mCellSceneNodes.find(newCell) == mCellSceneNodes.end()) { - node = mRootNode->createChildSceneNode(); - mCellSceneNodes[newCell] = node; + cellnode = new osg::Group; + mRootNode->addChild(cellnode); + mCellSceneNodes[newCell] = cellnode; } else { - node = mCellSceneNodes[newCell]; + cellnode = mCellSceneNodes[newCell]; } - node->addChild(cur.getRefData().getBaseNode()); + osg::Node* objectNode = cur.getRefData().getBaseNode(); + + if (objectNode->getNumParents()) + objectNode->getParent(0)->removeChild(objectNode); + cellnode->addChild(objectNode); PtrAnimationMap::iterator iter = mObjects.find(old); if(iter != mObjects.end()) { - ObjectAnimation *anim = iter->second; + Animation *anim = iter->second; mObjects.erase(iter); anim->updatePtr(cur); mObjects[cur] = anim; } - */ } Animation* Objects::getAnimation(const MWWorld::Ptr &ptr) diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index e920869b9..3e1af6087 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -72,7 +72,7 @@ public: void removeCell(const MWWorld::CellStore* store); /// Updates containing cell for object rendering data - void updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur); + void updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &cur); private: void operator = (const Objects&); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index c9bf22009..49e6ba06f 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -271,6 +271,11 @@ namespace MWRender ptr.getRefData().getBaseNode()->setScale(scale); } + void RenderingManager::updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &updated) + { + mObjects->updatePtr(old, updated); + } + void RenderingManager::spawnEffect(const std::string &model, const std::string &texture, const osg::Vec3f &worldPosition, float scale) { mEffectManager->addEffect(model, texture, worldPosition, scale); diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 0dc0fe571..7d902b854 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -62,6 +62,8 @@ namespace MWRender void addCell(const MWWorld::CellStore* store); void removeCell(const MWWorld::CellStore* store); + void updatePtr(const MWWorld::Ptr& old, const MWWorld::Ptr& updated); + // TODO rename to setRotation/setPosition/setScale, along with the World equivalents void rotateObject(const MWWorld::Ptr& ptr, const osg::Quat& rot); void moveObject(const MWWorld::Ptr& ptr, const osg::Vec3f& pos); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 1ee9586ae..32eb92d2a 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1181,7 +1181,7 @@ namespace MWWorld MWWorld::Ptr copy = ptr.getClass().copyToCell(ptr, *newCell, pos); - //mRendering->updateObjectCell(ptr, copy); + mRendering->updatePtr(ptr, copy); ptr.getRefData().setBaseNode(NULL); MWBase::Environment::get().getSoundManager()->updatePtr (ptr, copy); mPhysics->updatePtr(ptr, copy);