cleanup
This commit is contained in:
parent
4a626cea20
commit
9856cecb71
@ -42,9 +42,19 @@ namespace osgAnimation
|
|||||||
inline const float &getWeight()const{return second;}
|
inline const float &getWeight()const{return second;}
|
||||||
inline void setWeight(float i){second=i;}
|
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;
|
/// map a set of boneinfluence to a list of vertex indices sharing this set
|
||||||
class OSGANIMATION_EXPORT BoneInfluenceList : public VertexList
|
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:
|
public:
|
||||||
const std::string& getBoneName() const { return _name;}
|
const std::string& getBoneName() const { return _name;}
|
||||||
|
@ -46,17 +46,15 @@ struct SortByNameAndWeight : public std::less<RigTransformSoftware::BonePtrWeigh
|
|||||||
return true;
|
return true;
|
||||||
else if (b0.getBoneName() > b1.getBoneName())
|
else if (b0.getBoneName() > b1.getBoneName())
|
||||||
return false;
|
return false;
|
||||||
if (b0.getWeight() < b1.getWeight())
|
return (b0.getWeight() < b1.getWeight());
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
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,
|
bool operator()(const BonePtrWeightList& b0,
|
||||||
const BoneWeightList& b1) const
|
const BonePtrWeightList& b1) const
|
||||||
{
|
{
|
||||||
if (b0.size() < b1.size())
|
if (b0.size() < b1.size())
|
||||||
return true;
|
return true;
|
||||||
@ -78,7 +76,7 @@ struct SortByBoneWeightList : public std::less<BoneWeightList>
|
|||||||
void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const RigGeometry&rig ){
|
void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const RigGeometry&rig ){
|
||||||
|
|
||||||
///1 Create Index2Vec<BoneWeight>
|
///1 Create Index2Vec<BoneWeight>
|
||||||
std::vector<BoneWeightList> _vertex2Bones;
|
std::vector<BonePtrWeightList> _vertex2Bones;
|
||||||
_vertex2Bones.resize(rig.getSourceGeometry()->getVertexArray()->getNumElements());
|
_vertex2Bones.resize(rig.getSourceGeometry()->getVertexArray()->getNumElements());
|
||||||
|
|
||||||
const VertexInfluenceMap *_vertexInfluenceMap=rig.getInfluenceMap();
|
const VertexInfluenceMap *_vertexInfluenceMap=rig.getInfluenceMap();
|
||||||
@ -112,11 +110,11 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig
|
|||||||
|
|
||||||
// normalize _vertex2Bones weight per vertex
|
// normalize _vertex2Bones weight per vertex
|
||||||
unsigned vertexID=0;
|
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;
|
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();
|
sum += bwit->getWeight();
|
||||||
if (sum < 1e-4)
|
if (sum < 1e-4)
|
||||||
{
|
{
|
||||||
@ -125,7 +123,7 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
float mult = 1.0/sum;
|
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);
|
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
|
///in order to minimize weighted matrices computation on update
|
||||||
_uniqInfluenceSet2VertIDList.clear();
|
_uniqInfluenceSet2VertIDList.clear();
|
||||||
|
|
||||||
typedef std::map<BoneWeightList, VertexGroup, SortByBoneWeightList> UnifyBoneGroup;
|
typedef std::map<BonePtrWeightList, VertexGroup, SortByBoneWeightList> UnifyBoneGroup;
|
||||||
UnifyBoneGroup unifyBuffer;
|
UnifyBoneGroup unifyBuffer;
|
||||||
vertexID=0;
|
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
|
// sort the vector to have a consistent key
|
||||||
std::sort(bones.begin(), bones.end(), SortByNameAndWeight() );
|
std::sort(bones.begin(), bones.end(), SortByNameAndWeight() );
|
||||||
// we use the vector<BoneWeight> as key to differentiate group
|
// we use the vector<BoneWeight> as key to differentiate group
|
||||||
|
Loading…
Reference in New Issue
Block a user