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

@@ -127,9 +127,9 @@ unsigned int createVertexAttribList(const PerVertexInfList & perVertexInfluences
boneIndexInList = j*2 + b;
if (boneIndexInList < (*vertinfit).size())
{
float boneIndex = static_cast<float>((*vertinfit)[boneIndexInList].getIndex());
float boneIndex = static_cast<float>((*vertinfit)[boneIndexInList].first);
///normalization here
float boneWeight = (*vertinfit)[boneIndexInList].getWeight()*sum;
float boneWeight = (*vertinfit)[boneIndexInList].second*sum;
dest[0 + boneIndexInVec4] = boneIndex;
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)
{
const VertexIndexWeight& iw = *infit;
const unsigned int &index = iw.getIndex();
const float &weight = iw.getWeight();
const unsigned int &index = iw.first;
const float &weight = iw.second;
IndexWeightList & iwlist = perVertexInfluences[index];
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;
}
unsigned int attribIndex = _minAttribIndex;
unsigned int nbAttribs = getNumVertexAttrib();
for (unsigned int i = 0; i < nbAttribs; i++)
{
std::stringstream ss;
ss << "boneWeight" << i;
program->addBindAttribLocation(ss.str(), attribIndex + i);
rig.setVertexAttribArray(attribIndex + i, getVertexAttrib(i));
program->addBindAttribLocation(ss.str(), _minAttribIndex + i);
rig.setVertexAttribArray(_minAttribIndex + i, getVertexAttrib(i));
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)
{
const VertexIndexWeight &iw = *infit;
const unsigned int &index = iw.getIndex();
float weight = iw.getWeight();
const unsigned int &index = iw.first;
float weight = iw.second;
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)
{
if (bw1.getWeight() > bw2.getWeight())return true;
if (bw1.getWeight() < bw2.getWeight())return false;
return(bw1.getBoneName()<bw2.getBoneName());
if (bw1.second > bw2.second)return true;
if (bw1.second < bw2.second)return false;
return(bw1.first<bw2.first);
}
};
@@ -86,20 +86,20 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert
while(bwset.size()>newsize)bwset.erase(*bwset.rbegin());
if(renormalize){
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit)
sum+=bwit->getWeight();
sum+=bwit->second;
if(sum>1e-4){
sum=1.0f/sum;
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
VertexInfluence & inf= (*this)[bwit->getBoneName()];
inf.push_back(VertexIndexWeight(mapit->first, bwit->getWeight()*sum));
inf.setName(bwit->getBoneName());
VertexInfluence & inf= (*this)[bwit->first];
inf.push_back(VertexIndexWeight(mapit->first, bwit->second*sum));
inf.setName(bwit->first);
}
}
}else{
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
VertexInfluence & inf= (*this)[bwit->getBoneName()];
inf.push_back(VertexIndexWeight(mapit->first,bwit->getWeight()));
inf.setName(bwit->getBoneName());
VertexInfluence & inf= (*this)[bwit->first];
inf.push_back(VertexIndexWeight(mapit->first,bwit->second));
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)
{
const VertexIndexWeight &iw = *infit;
const unsigned int &index = iw.getIndex();
float weight = iw.getWeight();
const unsigned int &index = iw.first;
const float &weight = iw.second;
vertex2Bones[index].push_back(BoneWeight(it->first, weight));;
}
}
@@ -133,11 +133,11 @@ struct SortByNameAndWeight : public std::less<BoneWeight>
bool operator()(const BoneWeight& b0,
const BoneWeight& b1) const
{
if (b0.getBoneName() < b1.getBoneName())
if (b0.first < b1.first)
return true;
else if (b0.getBoneName() > b1.getBoneName())
else if (b0.first> b1.first)
return false;
return (b0.getWeight() < b1.getWeight());
return (b0.second < b1.second);
}
};