This commit is contained in:
Julien Valentin 2017-08-29 17:24:35 +02:00
parent 186691a9db
commit ce6a316bde
2 changed files with 18 additions and 47 deletions

View File

@ -40,17 +40,23 @@ namespace osgAnimation
//to call when a skeleton is reacheable from the rig to prepare technic data //to call when a skeleton is reacheable from the rig to prepare technic data
virtual bool prepareData(RigGeometry&); virtual bool prepareData(RigGeometry&);
class BonePtrWeight: public BoneWeight class BonePtrWeight: std::pair< osg::observer_ptr< Bone >, float>
{ {
public: public:
BonePtrWeight(const std::string& name, float weight, Bone *bptr=0) :BoneWeight(name,weight), _boneptr(bptr) {} BonePtrWeight(Bone*bone, float weight) :std::pair< osg::observer_ptr< Bone >, float>(bone,weight) {}
BonePtrWeight(const BonePtrWeight &bw2) : BoneWeight(bw2), _boneptr(bw2._boneptr) {} BonePtrWeight(const BonePtrWeight &bw2) : std::pair< osg::observer_ptr< Bone >, float>(bw2.first.get(),bw2.getWeight()) {}
const Bone * getBonePtr()const{return _boneptr.get();} inline const Bone * getBonePtr() const {return first.get();}
void setBonePtr(Bone*b){_boneptr=b;} inline void setBonePtr(Bone*b){first=b;}
inline const float & getWeight() const {return second;}
protected: inline void setWeight(float b) {second=b;}
osg::observer_ptr< Bone > _boneptr; inline bool operator<(const BonePtrWeight &b1) const{
if (getBonePtr() < b1.getBonePtr())
return true;
else if (getBonePtr() > b1.getBonePtr())
return false;
return (getWeight() < b1.getWeight());
}
}; };
typedef std::vector<BonePtrWeight> BonePtrWeightList; typedef std::vector<BonePtrWeight> BonePtrWeightList;

View File

@ -36,43 +36,8 @@ RigTransformSoftware::RigTransformSoftware(const RigTransformSoftware& rts,const
} }
// sort by name and weight
struct SortByNameAndWeight : public std::less<RigTransformSoftware::BonePtrWeight>
{
bool operator()(const RigTransformSoftware::BonePtrWeight& b0,
const RigTransformSoftware::BonePtrWeight& b1) const
{
if (b0.getBoneName() < b1.getBoneName())
return true;
else if (b0.getBoneName() > b1.getBoneName())
return false;
return (b0.getWeight() < b1.getWeight());
}
};
typedef std::vector<RigTransformSoftware::BonePtrWeight> BonePtrWeightList; typedef std::vector<RigTransformSoftware::BonePtrWeight> BonePtrWeightList;
struct SortByBoneWeightList : public std::less<BonePtrWeightList>
{
bool operator()(const BonePtrWeightList& b0,
const BonePtrWeightList& b1) const
{
if (b0.size() < b1.size())
return true;
else if (b0.size() > b1.size())
return false;
int size = b0.size();
for (int i = 0; i < size; i++)
{
if (SortByNameAndWeight()(b0[i], b1[i]))
return true;
else if (SortByNameAndWeight()(b1[i], b0[i]))
return false;
}
return false;
}
};
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>
@ -104,7 +69,7 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig
const unsigned int &index = iw.getIndex(); const unsigned int &index = iw.getIndex();
float weight = iw.getWeight(); float weight = iw.getWeight();
_vertex2Bones[index].push_back(BonePtrWeight(inflist.getBoneName(), weight,bone)); _vertex2Bones[index].push_back(BonePtrWeight(bone, weight));
} }
} }
@ -132,15 +97,15 @@ 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<BonePtrWeightList, VertexGroup, SortByBoneWeightList> UnifyBoneGroup; typedef std::map<BonePtrWeightList, VertexGroup> UnifyBoneGroup;
UnifyBoneGroup unifyBuffer; UnifyBoneGroup unifyBuffer;
vertexID=0; vertexID=0;
; ;
for (std::vector<BonePtrWeightList>::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it,++vertexID) for (std::vector<BonePtrWeightList>::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it,++vertexID)
{ {
BonePtrWeightList 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() );
// we use the vector<BoneWeight> as key to differentiate group // we use the vector<BoneWeight> as key to differentiate group
UnifyBoneGroup::iterator result = unifyBuffer.find(bones); UnifyBoneGroup::iterator result = unifyBuffer.find(bones);
if (result != unifyBuffer.end()) if (result != unifyBuffer.end())