diff --git a/components/sceneutil/skeleton.cpp b/components/sceneutil/skeleton.cpp index 40f524e0a2..c465333fb4 100644 --- a/components/sceneutil/skeleton.cpp +++ b/components/sceneutil/skeleton.cpp @@ -1,6 +1,5 @@ #include "skeleton.hpp" -#include #include #include @@ -12,24 +11,24 @@ namespace SceneUtil class InitBoneCacheVisitor : public osg::NodeVisitor { public: - InitBoneCacheVisitor(std::map >& cache) + typedef std::vector TransformPath; + InitBoneCacheVisitor(std::unordered_map& cache) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) , mCache(cache) { } - void apply(osg::Transform &node) override + void apply(osg::MatrixTransform &node) override { - osg::MatrixTransform* bone = node.asMatrixTransform(); - if (!bone) - return; - - mCache[Misc::StringUtils::lowerCase(bone->getName())] = std::make_pair(getNodePath(), bone); - + mPath.push_back(&node); + mCache[Misc::StringUtils::lowerCase(node.getName())] = mPath; traverse(node); + mPath.pop_back(); } + private: - std::map >& mCache; + TransformPath mPath; + std::unordered_map& mCache; }; Skeleton::Skeleton() @@ -73,18 +72,13 @@ Bone* Skeleton::getBone(const std::string &name) mRootBone.reset(new Bone); } - const osg::NodePath& path = found->second.first; Bone* bone = mRootBone.get(); - for (osg::NodePath::const_iterator it = path.begin(); it != path.end(); ++it) + for (osg::MatrixTransform* matrixTransform : found->second) { - osg::MatrixTransform* matrixTransform = dynamic_cast(*it); - if (!matrixTransform) - continue; - Bone* child = nullptr; for (unsigned int i=0; imChildren.size(); ++i) { - if (bone->mChildren[i]->mNode == *it) + if (bone->mChildren[i]->mNode == matrixTransform) { child = bone->mChildren[i]; break; diff --git a/components/sceneutil/skeleton.hpp b/components/sceneutil/skeleton.hpp index 22988dfd5f..10f4640249 100644 --- a/components/sceneutil/skeleton.hpp +++ b/components/sceneutil/skeleton.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace SceneUtil { @@ -72,7 +73,7 @@ namespace SceneUtil // As far as the scene graph goes we support multiple root bones. std::unique_ptr mRootBone; - typedef std::map > BoneCache; + typedef std::unordered_map > BoneCache; BoneCache mBoneCache; bool mBoneCacheInit;