diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index eb20b77021..29e6ff4f44 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1092,13 +1092,12 @@ namespace NifOsg const std::vector &weights = data->bones[i].weights; for(size_t j = 0;j < weights.size();j++) { - std::pair indexWeight = std::make_pair(weights[j].vertex, weights[j].weight); - influence.mWeights.insert(indexWeight); + influence.mWeights.emplace_back(weights[j].vertex, weights[j].weight); } influence.mInvBindMatrix = data->bones[i].trafo.toMatrix(); influence.mBoundSphere = osg::BoundingSpheref(data->bones[i].boundSphereCenter, data->bones[i].boundSphereRadius); - map->mMap.insert(std::make_pair(boneName, influence)); + map->mData.emplace_back(boneName, influence); } rig->setInfluenceMap(map); diff --git a/components/sceneutil/riggeometry.cpp b/components/sceneutil/riggeometry.cpp index b086cf6288..4b550b69c1 100644 --- a/components/sceneutil/riggeometry.cpp +++ b/components/sceneutil/riggeometry.cpp @@ -136,35 +136,35 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv) typedef std::map > Vertex2BoneMap; Vertex2BoneMap vertex2BoneMap; - for (std::map::const_iterator it = mInfluenceMap->mMap.begin(); it != mInfluenceMap->mMap.end(); ++it) + mBoneSphereVector.clear(); + for (auto& influencePair : mInfluenceMap->mData) { - Bone* bone = mSkeleton->getBone(it->first); + Bone* bone = mSkeleton->getBone(influencePair.first); if (!bone) { - Log(Debug::Error) << "Error: RigGeometry did not find bone " << it->first ; + Log(Debug::Error) << "Error: RigGeometry did not find bone " << influencePair.first; continue; } - mBoneSphereMap[bone] = it->second.mBoundSphere; + const BoneInfluence& bi = influencePair.second; + mBoneSphereVector.emplace_back(bone, bi.mBoundSphere); - const BoneInfluence& bi = it->second; - - const std::map& weights = it->second.mWeights; - for (std::map::const_iterator weightIt = weights.begin(); weightIt != weights.end(); ++weightIt) + for (auto& weightPair: bi.mWeights) { - std::vector& vec = vertex2BoneMap[weightIt->first]; + std::vector& vec = vertex2BoneMap[weightPair.first]; - BoneWeight b = std::make_pair(std::make_pair(bone, bi.mInvBindMatrix), weightIt->second); - - vec.push_back(b); + vec.emplace_back(std::make_pair(bone, bi.mInvBindMatrix), weightPair.second); } } + Bone2VertexMap bone2VertexMap; for (Vertex2BoneMap::iterator it = vertex2BoneMap.begin(); it != vertex2BoneMap.end(); ++it) { - mBone2VertexMap[it->second].push_back(it->first); + bone2VertexMap[it->second].push_back(it->first); } + mBone2VertexVector.assign(bone2VertexMap.begin(), bone2VertexMap.end()); + return true; } @@ -201,7 +201,7 @@ void RigGeometry::cull(osg::NodeVisitor* nv) osg::Vec3Array* normalDst = static_cast(geom.getNormalArray()); osg::Vec4Array* tangentDst = static_cast(geom.getTexCoordArray(7)); - for (auto &pair : mBone2VertexMap) + for (auto &pair : mBone2VertexVector) { osg::Matrixf resultMat (0, 0, 0, 0, 0, 0, 0, 0, @@ -263,10 +263,10 @@ void RigGeometry::updateBounds(osg::NodeVisitor *nv) updateGeomToSkelMatrix(nv->getNodePath()); osg::BoundingBox box; - for (BoneSphereMap::const_iterator it = mBoneSphereMap.begin(); it != mBoneSphereMap.end(); ++it) + for (auto& boundPair : mBoneSphereVector) { - Bone* bone = it->first; - osg::BoundingSpheref bs = it->second; + Bone* bone = boundPair.first; + osg::BoundingSpheref bs = boundPair.second; if (mGeomToSkelMatrix) transformBoundingSphere(bone->mMatrixInSkeletonSpace * (*mGeomToSkelMatrix), bs); else diff --git a/components/sceneutil/riggeometry.hpp b/components/sceneutil/riggeometry.hpp index 60b3edc9d8..5dd05507ca 100644 --- a/components/sceneutil/riggeometry.hpp +++ b/components/sceneutil/riggeometry.hpp @@ -31,12 +31,12 @@ namespace SceneUtil osg::Matrixf mInvBindMatrix; osg::BoundingSpheref mBoundSphere; // - std::map mWeights; + std::vector> mWeights; }; struct InfluenceMap : public osg::Referenced { - std::map mMap; + std::vector> mData; }; void setInfluenceMap(osg::ref_ptr influenceMap); @@ -73,12 +73,13 @@ namespace SceneUtil typedef std::vector VertexList; typedef std::map, VertexList> Bone2VertexMap; + typedef std::vector, VertexList>> Bone2VertexVector; - Bone2VertexMap mBone2VertexMap; + Bone2VertexVector mBone2VertexVector; - typedef std::map BoneSphereMap; + typedef std::vector> BoneSphereVector; - BoneSphereMap mBoneSphereMap; + BoneSphereVector mBoneSphereVector; unsigned int mLastFrameNumber; bool mBoundsFirstFrame;