diff --git a/components/sceneutil/skeleton.cpp b/components/sceneutil/skeleton.cpp index 9f646ade5c..5c8449a50d 100644 --- a/components/sceneutil/skeleton.cpp +++ b/components/sceneutil/skeleton.cpp @@ -5,6 +5,8 @@ #include #include +#include + namespace SceneUtil { @@ -75,23 +77,16 @@ Bone* Skeleton::getBone(const std::string &name) Bone* bone = mRootBone.get(); for (osg::MatrixTransform* matrixTransform : found->second) { - Bone* child = nullptr; - for (unsigned int i=0; imChildren.size(); ++i) - { - if (bone->mChildren[i]->mNode == matrixTransform) - { - child = bone->mChildren[i]; - break; - } - } + const auto it = std::find_if(bone->mChildren.begin(), bone->mChildren.end(), + [&] (const auto& v) { return v->mNode == matrixTransform; }); - if (!child) + if (it == bone->mChildren.end()) { - child = new Bone; - bone->mChildren.push_back(child); + bone = bone->mChildren.emplace_back(std::make_unique()).get(); mNeedToUpdateBoneMatrices = true; } - bone = child; + else + bone = it->get(); bone->mNode = matrixTransform; } @@ -110,8 +105,8 @@ void Skeleton::updateBoneMatrices(unsigned int traversalNumber) { if (mRootBone.get()) { - for (unsigned int i=0; imChildren.size(); ++i) - mRootBone->mChildren[i]->update(nullptr); + for (const auto& child : mRootBone->mChildren) + child->update(nullptr); } mNeedToUpdateBoneMatrices = false; @@ -165,13 +160,6 @@ Bone::Bone() { } -Bone::~Bone() -{ - for (unsigned int i=0; igetMatrix(); - for (unsigned int i=0; iupdate(&mMatrixInSkeletonSpace); - } + for (const auto& child : mChildren) + child->update(&mMatrixInSkeletonSpace); } } diff --git a/components/sceneutil/skeleton.hpp b/components/sceneutil/skeleton.hpp index 10f4640249..7ca4887999 100644 --- a/components/sceneutil/skeleton.hpp +++ b/components/sceneutil/skeleton.hpp @@ -15,20 +15,15 @@ namespace SceneUtil { public: Bone(); - ~Bone(); osg::Matrixf mMatrixInSkeletonSpace; osg::MatrixTransform* mNode; - std::vector mChildren; + std::vector> mChildren; /// Update the skeleton-space matrix of this bone and all its children. void update(const osg::Matrixf* parentMatrixInSkeletonSpace); - - private: - Bone(const Bone&); - void operator=(const Bone&); }; /// @brief Handles the bone matrices for any number of child RigGeometries.