This commit is contained in:
Julien Valentin 2017-08-29 00:09:38 +02:00
parent 4a626cea20
commit 9856cecb71
2 changed files with 25 additions and 17 deletions

View File

@ -42,9 +42,19 @@ namespace osgAnimation
inline const float &getWeight()const{return second;}
inline void setWeight(float i){second=i;}
};
typedef std::vector<IndexWeight> IndexWeightList;
typedef std::vector<BoneWeight> BoneWeightList;
typedef std::vector<unsigned int> IndexList;
typedef std::vector<IndexWeight> 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<BoneWeightList, IndexList>
{
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;}

View File

@ -46,17 +46,15 @@ struct SortByNameAndWeight : public std::less<RigTransformSoftware::BonePtrWeigh
return true;
else if (b0.getBoneName() > b1.getBoneName())
return false;
if (b0.getWeight() < b1.getWeight())
return true;
return false;
return (b0.getWeight() < b1.getWeight());
}
};
typedef std::vector<RigTransformSoftware::BonePtrWeight> BoneWeightList;
typedef std::vector<RigTransformSoftware::BonePtrWeight> BonePtrWeightList;
struct SortByBoneWeightList : public std::less<BoneWeightList>
struct SortByBoneWeightList : public std::less<BonePtrWeightList>
{
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<BoneWeightList>
void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const RigGeometry&rig ){
///1 Create Index2Vec<BoneWeight>
std::vector<BoneWeightList> _vertex2Bones;
std::vector<BonePtrWeightList> _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<BoneWeightList>::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it, ++vertexID)
for (std::vector<BonePtrWeightList>::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<BoneWeightList, VertexGroup, SortByBoneWeightList> UnifyBoneGroup;
typedef std::map<BonePtrWeightList, VertexGroup, SortByBoneWeightList> UnifyBoneGroup;
UnifyBoneGroup unifyBuffer;
vertexID=0;
for (std::vector<BoneWeightList>::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it,++vertexID)
for (std::vector<BonePtrWeightList>::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<BoneWeight> as key to differentiate group