diff --git a/include/osgAnimation/VertexInfluence b/include/osgAnimation/VertexInfluence index ff0403134..317a45e87 100644 --- a/include/osgAnimation/VertexInfluence +++ b/include/osgAnimation/VertexInfluence @@ -42,9 +42,19 @@ namespace osgAnimation inline const float &getWeight()const{return second;} inline void setWeight(float i){second=i;} }; + typedef std::vector IndexWeightList; + typedef std::vector BoneWeightList; + typedef std::vector IndexList; - typedef std::vector VertexList; - class OSGANIMATION_EXPORT BoneInfluenceList : public VertexList + /// map a set of boneinfluence to a list of vertex indices sharing this set + class VertexGroup: public std::pair + { + public: + inline const BoneWeightList& getBoneWeights()const { return first; } + inline void setBoneWeights(BoneWeightList&o) { first=o; } + inline IndexList& vertIDs() { return second; } + }; + class OSGANIMATION_EXPORT BoneInfluenceList : public IndexWeightList { public: const std::string& getBoneName() const { return _name;} diff --git a/src/osgAnimation/RigTransformSoftware.cpp b/src/osgAnimation/RigTransformSoftware.cpp index 31de573b3..d7d1515df 100644 --- a/src/osgAnimation/RigTransformSoftware.cpp +++ b/src/osgAnimation/RigTransformSoftware.cpp @@ -46,17 +46,15 @@ struct SortByNameAndWeight : public std::less b1.getBoneName()) return false; - if (b0.getWeight() < b1.getWeight()) - return true; - return false; + return (b0.getWeight() < b1.getWeight()); } }; -typedef std::vector BoneWeightList; +typedef std::vector BonePtrWeightList; -struct SortByBoneWeightList : public std::less +struct SortByBoneWeightList : public std::less { - bool operator()(const BoneWeightList& b0, - const BoneWeightList& b1) const + bool operator()(const BonePtrWeightList& b0, + const BonePtrWeightList& b1) const { if (b0.size() < b1.size()) return true; @@ -78,7 +76,7 @@ struct SortByBoneWeightList : public std::less void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const RigGeometry&rig ){ ///1 Create Index2Vec - std::vector _vertex2Bones; + std::vector _vertex2Bones; _vertex2Bones.resize(rig.getSourceGeometry()->getVertexArray()->getNumElements()); const VertexInfluenceMap *_vertexInfluenceMap=rig.getInfluenceMap(); @@ -112,11 +110,11 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig // normalize _vertex2Bones weight per vertex unsigned vertexID=0; - for (std::vector::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it, ++vertexID) + for (std::vector::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it, ++vertexID) { - BoneWeightList& bones = *it; + BonePtrWeightList& bones = *it; float sum = 0; - for(BoneWeightList::iterator bwit=bones.begin();bwit!=bones.end();++bwit) + for(BonePtrWeightList::iterator bwit=bones.begin();bwit!=bones.end();++bwit) sum += bwit->getWeight(); if (sum < 1e-4) { @@ -125,7 +123,7 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig else { float mult = 1.0/sum; - for(BoneWeightList::iterator bwit=bones.begin();bwit!=bones.end();++bwit) + for(BonePtrWeightList::iterator bwit=bones.begin();bwit!=bones.end();++bwit) bwit->setWeight(bwit->getWeight() * mult); } } @@ -134,12 +132,12 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig ///in order to minimize weighted matrices computation on update _uniqInfluenceSet2VertIDList.clear(); - typedef std::map UnifyBoneGroup; + typedef std::map UnifyBoneGroup; UnifyBoneGroup unifyBuffer; vertexID=0; - for (std::vector::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it,++vertexID) + for (std::vector::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it,++vertexID) { - BoneWeightList& bones = *it; + BonePtrWeightList& bones = *it; // sort the vector to have a consistent key std::sort(bones.begin(), bones.end(), SortByNameAndWeight() ); // we use the vector as key to differentiate group