remove utility classes BoneWeight and IndexWeight in order to avoid unnecessary symbols

(but decrease a bit clarity of the code)
This commit is contained in:
Julien Valentin 2017-09-01 16:23:49 +02:00
parent 8b74b04de0
commit 0d02dfbbbd
4 changed files with 28 additions and 41 deletions

View File

@ -25,26 +25,14 @@
namespace osgAnimation namespace osgAnimation
{ {
// first is bonename, and second the weight // first is bonename, and second the weight
struct BoneWeight: public std::pair<std::string, float> typedef std::pair<std::string, float> BoneWeight;
{
BoneWeight( std::string f,float s):
std::pair<std::string,float>(f,s){}
inline const std::string& getBoneName()const{return first;}
inline void setBoneName(const std::string&s){first=s;}
inline const float &getWeight()const{return second;}
inline void setWeight(float i){second=i;}
};
// first is vertex index, and second the weight // first is vertex index, and second the weight
struct VertexIndexWeight: public std::pair<unsigned int, float> typedef std::pair<unsigned int, float> VertexIndexWeight;
{ // list of IndexWeight
VertexIndexWeight( unsigned int f = 0xffffffff,float s = 0.0f): std::pair<unsigned int,float>(f,s){}
inline const unsigned int& getIndex()const{return first;}
inline void setIndex(unsigned int i){first=i;}
inline const float &getWeight()const{return second;}
inline void setWeight(float i){second=i;}
};
typedef std::vector<VertexIndexWeight> IndexWeightList; typedef std::vector<VertexIndexWeight> IndexWeightList;
// list of IndexWeight
typedef std::vector<BoneWeight> BoneWeightList; typedef std::vector<BoneWeight> BoneWeightList;
// list of Index
typedef std::vector<unsigned int> IndexList; typedef std::vector<unsigned int> IndexList;
//Bone influence list //Bone influence list

View File

@ -127,9 +127,9 @@ unsigned int createVertexAttribList(const PerVertexInfList & perVertexInfluences
boneIndexInList = j*2 + b; boneIndexInList = j*2 + b;
if (boneIndexInList < (*vertinfit).size()) if (boneIndexInList < (*vertinfit).size())
{ {
float boneIndex = static_cast<float>((*vertinfit)[boneIndexInList].getIndex()); float boneIndex = static_cast<float>((*vertinfit)[boneIndexInList].first);
///normalization here ///normalization here
float boneWeight = (*vertinfit)[boneIndexInList].getWeight()*sum; float boneWeight = (*vertinfit)[boneIndexInList].second*sum;
dest[0 + boneIndexInVec4] = boneIndex; dest[0 + boneIndexInVec4] = boneIndex;
dest[1 + boneIndexInVec4] = boneWeight; dest[1 + boneIndexInVec4] = boneWeight;
} }
@ -233,8 +233,8 @@ bool RigTransformHardware::buildPalette(const BoneMap&boneMap,const RigGeometry&
for(IndexWeightList::const_iterator infit = boneinflist.begin(); infit!=boneinflist.end(); ++infit) for(IndexWeightList::const_iterator infit = boneinflist.begin(); infit!=boneinflist.end(); ++infit)
{ {
const VertexIndexWeight& iw = *infit; const VertexIndexWeight& iw = *infit;
const unsigned int &index = iw.getIndex(); const unsigned int &index = iw.first;
const float &weight = iw.getWeight(); const float &weight = iw.second;
IndexWeightList & iwlist = perVertexInfluences[index]; IndexWeightList & iwlist = perVertexInfluences[index];
if(fabs(weight) > 1e-4) // don't use bone with weight too small if(fabs(weight) > 1e-4) // don't use bone with weight too small
@ -327,14 +327,13 @@ bool RigTransformHardware::init(RigGeometry& rig)
OSG_INFO << "Shader " << str << std::endl; OSG_INFO << "Shader " << str << std::endl;
} }
unsigned int attribIndex = _minAttribIndex;
unsigned int nbAttribs = getNumVertexAttrib(); unsigned int nbAttribs = getNumVertexAttrib();
for (unsigned int i = 0; i < nbAttribs; i++) for (unsigned int i = 0; i < nbAttribs; i++)
{ {
std::stringstream ss; std::stringstream ss;
ss << "boneWeight" << i; ss << "boneWeight" << i;
program->addBindAttribLocation(ss.str(), attribIndex + i); program->addBindAttribLocation(ss.str(), _minAttribIndex + i);
rig.setVertexAttribArray(attribIndex + i, getVertexAttrib(i)); rig.setVertexAttribArray(_minAttribIndex + i, getVertexAttrib(i));
OSG_INFO << "set vertex attrib " << ss.str() << std::endl; OSG_INFO << "set vertex attrib " << ss.str() << std::endl;
} }

View File

@ -68,8 +68,8 @@ void RigTransformSoftware::buildMinimumUpdateSet( const BoneMap&boneMap, const R
for(IndexWeightList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit) for(IndexWeightList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit)
{ {
const VertexIndexWeight &iw = *infit; const VertexIndexWeight &iw = *infit;
const unsigned int &index = iw.getIndex(); const unsigned int &index = iw.first;
float weight = iw.getWeight(); float weight = iw.second;
perVertexInfluences[index].push_back(BonePtrWeight(bone, weight)); perVertexInfluences[index].push_back(BonePtrWeight(bone, weight));
} }
} }

View File

@ -25,9 +25,9 @@ struct invweight_ordered
{ {
inline bool operator() (const BoneWeight& bw1, const BoneWeight& bw2) inline bool operator() (const BoneWeight& bw1, const BoneWeight& bw2)
{ {
if (bw1.getWeight() > bw2.getWeight())return true; if (bw1.second > bw2.second)return true;
if (bw1.getWeight() < bw2.getWeight())return false; if (bw1.second < bw2.second)return false;
return(bw1.getBoneName()<bw2.getBoneName()); return(bw1.first<bw2.first);
} }
}; };
@ -86,20 +86,20 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert
while(bwset.size()>newsize)bwset.erase(*bwset.rbegin()); while(bwset.size()>newsize)bwset.erase(*bwset.rbegin());
if(renormalize){ if(renormalize){
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit)
sum+=bwit->getWeight(); sum+=bwit->second;
if(sum>1e-4){ if(sum>1e-4){
sum=1.0f/sum; sum=1.0f/sum;
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) { for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
VertexInfluence & inf= (*this)[bwit->getBoneName()]; VertexInfluence & inf= (*this)[bwit->first];
inf.push_back(VertexIndexWeight(mapit->first, bwit->getWeight()*sum)); inf.push_back(VertexIndexWeight(mapit->first, bwit->second*sum));
inf.setName(bwit->getBoneName()); inf.setName(bwit->first);
} }
} }
}else{ }else{
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) { for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
VertexInfluence & inf= (*this)[bwit->getBoneName()]; VertexInfluence & inf= (*this)[bwit->first];
inf.push_back(VertexIndexWeight(mapit->first,bwit->getWeight())); inf.push_back(VertexIndexWeight(mapit->first,bwit->second));
inf.setName(bwit->getBoneName()); inf.setName(bwit->first);
} }
} }
@ -120,8 +120,8 @@ void VertexInfluenceMap::computePerVertexInfluenceList(std::vector<BoneWeightLis
for(IndexWeightList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit) for(IndexWeightList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit)
{ {
const VertexIndexWeight &iw = *infit; const VertexIndexWeight &iw = *infit;
const unsigned int &index = iw.getIndex(); const unsigned int &index = iw.first;
float weight = iw.getWeight(); const float &weight = iw.second;
vertex2Bones[index].push_back(BoneWeight(it->first, weight));; vertex2Bones[index].push_back(BoneWeight(it->first, weight));;
} }
} }
@ -133,11 +133,11 @@ struct SortByNameAndWeight : public std::less<BoneWeight>
bool operator()(const BoneWeight& b0, bool operator()(const BoneWeight& b0,
const BoneWeight& b1) const const BoneWeight& b1) const
{ {
if (b0.getBoneName() < b1.getBoneName()) if (b0.first < b1.first)
return true; return true;
else if (b0.getBoneName() > b1.getBoneName()) else if (b0.first> b1.first)
return false; return false;
return (b0.getWeight() < b1.getWeight()); return (b0.second < b1.second);
} }
}; };