mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 14:09:39 +00:00
RigGeometry optimization: vector iteration is more cheap than map iteration
This commit is contained in:
parent
88edc1a120
commit
254f01b89d
3 changed files with 21 additions and 16 deletions
|
@ -1098,7 +1098,7 @@ namespace NifOsg
|
|||
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);
|
||||
|
||||
|
|
|
@ -136,20 +136,21 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
|
|||
|
||||
typedef std::map<unsigned short, std::vector<BoneWeight> > Vertex2BoneMap;
|
||||
Vertex2BoneMap vertex2BoneMap;
|
||||
for (std::map<std::string, BoneInfluence>::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;
|
||||
mBoneSphereVector.emplace_back(bone, influencePair.second.mBoundSphere);
|
||||
|
||||
const BoneInfluence& bi = it->second;
|
||||
const BoneInfluence& bi = influencePair.second;
|
||||
|
||||
const std::map<unsigned short, float>& weights = it->second.mWeights;
|
||||
const std::map<unsigned short, float>& weights = influencePair.second.mWeights;
|
||||
for (std::map<unsigned short, float>::const_iterator weightIt = weights.begin(); weightIt != weights.end(); ++weightIt)
|
||||
{
|
||||
std::vector<BoneWeight>& vec = vertex2BoneMap[weightIt->first];
|
||||
|
@ -160,11 +161,14 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
|
|||
}
|
||||
}
|
||||
|
||||
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 +205,7 @@ void RigGeometry::cull(osg::NodeVisitor* nv)
|
|||
osg::Vec3Array* normalDst = static_cast<osg::Vec3Array*>(geom.getNormalArray());
|
||||
osg::Vec4Array* tangentDst = static_cast<osg::Vec4Array*>(geom.getTexCoordArray(7));
|
||||
|
||||
for (auto &pair : mBone2VertexMap)
|
||||
for (auto &pair : mBone2VertexVector)
|
||||
{
|
||||
osg::Matrixf resultMat (0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
|
@ -263,10 +267,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
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace SceneUtil
|
|||
|
||||
struct InfluenceMap : public osg::Referenced
|
||||
{
|
||||
std::map<std::string, BoneInfluence> mMap;
|
||||
std::vector<std::pair<std::string, BoneInfluence>> mData;
|
||||
};
|
||||
|
||||
void setInfluenceMap(osg::ref_ptr<InfluenceMap> influenceMap);
|
||||
|
@ -73,12 +73,13 @@ namespace SceneUtil
|
|||
typedef std::vector<unsigned short> VertexList;
|
||||
|
||||
typedef std::map<std::vector<BoneWeight>, VertexList> Bone2VertexMap;
|
||||
typedef std::vector<std::pair<std::vector<BoneWeight>, VertexList>> Bone2VertexVector;
|
||||
|
||||
Bone2VertexMap mBone2VertexMap;
|
||||
Bone2VertexVector mBone2VertexVector;
|
||||
|
||||
typedef std::map<Bone*, osg::BoundingSpheref> BoneSphereMap;
|
||||
typedef std::vector<std::pair<Bone*, osg::BoundingSpheref>> BoneSphereVector;
|
||||
|
||||
BoneSphereMap mBoneSphereMap;
|
||||
BoneSphereVector mBoneSphereVector;
|
||||
|
||||
unsigned int mLastFrameNumber;
|
||||
bool mBoundsFirstFrame;
|
||||
|
|
Loading…
Reference in a new issue