From 795f6d77f2a2ebf510955468a8fca7ee7903c425 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 3 Dec 2015 20:06:00 +0100 Subject: [PATCH] Cache the Animation's Skeleton --- apps/openmw/mwrender/animation.cpp | 12 +++++++----- apps/openmw/mwrender/animation.hpp | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index d530c2c92..bc417dae2 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -311,6 +311,7 @@ namespace MWRender Animation::Animation(const MWWorld::Ptr &ptr, osg::ref_ptr parentNode, Resource::ResourceSystem* resourceSystem) : mInsert(parentNode) + , mSkeleton(NULL) , mPtr(ptr) , mResourceSystem(resourceSystem) , mAccumulate(1.f, 1.f, 0.f) @@ -338,10 +339,8 @@ namespace MWRender void Animation::setActive(bool active) { - if (SceneUtil::Skeleton* skel = dynamic_cast(mObjectRoot.get())) - { - skel->setActive(active); - } + if (mSkeleton) + mSkeleton->setActive(active); } void Animation::updatePtr(const MWWorld::Ptr &ptr) @@ -965,6 +964,7 @@ namespace MWRender mObjectRoot->getParent(0)->removeChild(mObjectRoot); } mObjectRoot = NULL; + mSkeleton = NULL; mNodeMap.clear(); mActiveControllers.clear(); @@ -976,9 +976,11 @@ namespace MWRender else { osg::ref_ptr newObjectRoot = mResourceSystem->getSceneManager()->createInstance(model); - if (!dynamic_cast(newObjectRoot.get())) + mSkeleton = dynamic_cast(newObjectRoot.get()); + if (!mSkeleton) { osg::ref_ptr skel = new SceneUtil::Skeleton; + mSkeleton = skel.get(); skel->addChild(newObjectRoot); newObjectRoot = skel; } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index b1c34576b..04df10a38 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -24,6 +24,7 @@ namespace NifOsg namespace SceneUtil { class LightSource; + class Skeleton; } namespace MWRender @@ -208,6 +209,7 @@ protected: osg::ref_ptr mInsert; osg::ref_ptr mObjectRoot; + SceneUtil::Skeleton* mSkeleton; // The node expected to accumulate movement during movement animations. osg::ref_ptr mAccumRoot;