mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-12 07:06:44 +00:00
Simplify iteration over Bone::mChildren
This commit is contained in:
parent
e4f599575e
commit
0e12d331f9
1 changed files with 12 additions and 20 deletions
|
@ -5,6 +5,8 @@
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/misc/stringops.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace SceneUtil
|
namespace SceneUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -75,24 +77,16 @@ Bone* Skeleton::getBone(const std::string &name)
|
||||||
Bone* bone = mRootBone.get();
|
Bone* bone = mRootBone.get();
|
||||||
for (osg::MatrixTransform* matrixTransform : found->second)
|
for (osg::MatrixTransform* matrixTransform : found->second)
|
||||||
{
|
{
|
||||||
Bone* child = nullptr;
|
const auto it = std::find_if(bone->mChildren.begin(), bone->mChildren.end(),
|
||||||
for (unsigned int i=0; i<bone->mChildren.size(); ++i)
|
[&] (const auto& v) { return v->mNode == matrixTransform; });
|
||||||
{
|
|
||||||
if (bone->mChildren[i]->mNode == matrixTransform)
|
|
||||||
{
|
|
||||||
child = bone->mChildren[i].get();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child == nullptr)
|
if (it == bone->mChildren.end())
|
||||||
{
|
{
|
||||||
auto childBone = std::make_unique<Bone>();
|
bone = bone->mChildren.emplace_back(std::make_unique<Bone>()).get();
|
||||||
child = childBone.get();
|
|
||||||
bone->mChildren.push_back(std::move(childBone));
|
|
||||||
mNeedToUpdateBoneMatrices = true;
|
mNeedToUpdateBoneMatrices = true;
|
||||||
}
|
}
|
||||||
bone = child;
|
else
|
||||||
|
bone = it->get();
|
||||||
|
|
||||||
bone->mNode = matrixTransform;
|
bone->mNode = matrixTransform;
|
||||||
}
|
}
|
||||||
|
@ -111,8 +105,8 @@ void Skeleton::updateBoneMatrices(unsigned int traversalNumber)
|
||||||
{
|
{
|
||||||
if (mRootBone.get())
|
if (mRootBone.get())
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<mRootBone->mChildren.size(); ++i)
|
for (const auto& child : mRootBone->mChildren)
|
||||||
mRootBone->mChildren[i]->update(nullptr);
|
child->update(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
mNeedToUpdateBoneMatrices = false;
|
mNeedToUpdateBoneMatrices = false;
|
||||||
|
@ -178,10 +172,8 @@ void Bone::update(const osg::Matrixf* parentMatrixInSkeletonSpace)
|
||||||
else
|
else
|
||||||
mMatrixInSkeletonSpace = mNode->getMatrix();
|
mMatrixInSkeletonSpace = mNode->getMatrix();
|
||||||
|
|
||||||
for (unsigned int i=0; i<mChildren.size(); ++i)
|
for (const auto& child : mChildren)
|
||||||
{
|
child->update(&mMatrixInSkeletonSpace);
|
||||||
mChildren[i]->update(&mMatrixInSkeletonSpace);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue