refactor: remove totally VertexInfluence (renamed BoneInfluenceList) everywhere

This commit is contained in:
Julien Valentin
2017-08-30 11:12:17 +02:00
parent fae9729560
commit fe99b568a0
9 changed files with 53 additions and 72 deletions

View File

@@ -280,8 +280,9 @@ bool RigTransformHardware::buildPalette(BoneMap&boneMap ,RigGeometry&rig) {
mapit != vertexInfluenceMap->end();
++mapit)
{
const BoneInfluenceList& boneinflist = mapit->second;
for(BoneInfluenceList::const_iterator infit = boneinflist.begin(); infit!=boneinflist.end(); ++infit)
const IndexWeightList& boneinflist = mapit->second;
const std::string& bonename = mapit->first;
for(IndexWeightList::const_iterator infit = boneinflist.begin(); infit!=boneinflist.end(); ++infit)
{
const IndexWeight& iw = *infit;
const unsigned int &index = iw.getIndex();
@@ -289,30 +290,24 @@ bool RigTransformHardware::buildPalette(BoneMap&boneMap ,RigGeometry&rig) {
FloatInt &sum=sums[index];
if (boneinflist.getBoneName().empty()) {
OSG_WARN << "VertexInfluenceSet::buildVertex2BoneList warning vertex " << index << " is not assigned to a bone" << std::endl;
}
//_vertex2Bones[index].push_back(VertexInfluenceSet::BoneWeight(vi.getName(), weight));;
if(fabs(weight) > 1e-4) // don't use bone with weight too small
{
if ((boneName2PaletteIndex= _boneNameToPalette.find(boneinflist.getBoneName())) != _boneNameToPalette.end())
if ((boneName2PaletteIndex= _boneNameToPalette.find(bonename)) != _boneNameToPalette.end())
{
boneNameCountMap[boneinflist.getBoneName()]++;
boneNameCountMap[bonename]++;
vertexIndexWeight[index].push_back(IndexWeight(boneName2PaletteIndex->second,weight));
}
else
{
BoneMap::const_iterator bonebyname;
if ((bonebyname=boneMap.find(boneinflist.getBoneName())) == boneMap.end())
if ((bonebyname=boneMap.find(bonename)) == boneMap.end())
{
OSG_WARN << "RigTransformHardware::createPalette can't find bone " << boneinflist.getBoneName() << "in skeleton bonemap: skip this influence" << std::endl;
OSG_WARN << "RigTransformHardware::createPalette can't find bone " << bonename << "in skeleton bonemap: skip this influence" << std::endl;
continue;
}
boneNameCountMap[boneinflist.getBoneName()] = 1; // for stats
boneNameCountMap[bonename] = 1; // for stats
_boneNameToPalette[boneinflist.getBoneName()] = _bonePalette.size() ;
_boneNameToPalette[bonename] = _bonePalette.size() ;
vertexIndexWeight[index].push_back(IndexWeight(_bonePalette.size(),weight));
_bonePalette.push_back(bonebyname->second);
sum.first+=weight;
@@ -321,7 +316,7 @@ bool RigTransformHardware::buildPalette(BoneMap&boneMap ,RigGeometry&rig) {
}
else
{
OSG_WARN << "RigTransformHardware::createPalette Bone " << boneinflist.getBoneName() << " has a weight " << weight << " for vertex " << index << " this bone will not be in the palette" << std::endl;
OSG_WARN << "RigTransformHardware::createPalette Bone " << bonename << " has a weight " << weight << " for vertex " << index << " this bone will not be in the palette" << std::endl;
}
maxBonePerVertex = osg::maximum(maxBonePerVertex, sum.second);

View File

@@ -49,21 +49,23 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig
it != _vertexInfluenceMap->end();
++it)
{
const BoneInfluenceList& inflist = it->second;
if (inflist.getBoneName().empty()) {
OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone BoneInfluenceList" << std::endl;
const IndexWeightList& inflist = it->second;
const std::string& bonename = it->first;
if (bonename.empty()) {
OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone IndexWeightList" << std::endl;
}
BoneMap::const_iterator bmit = boneMap.find(inflist.getBoneName());
BoneMap::const_iterator bmit = boneMap.find(bonename);
if (bmit == boneMap.end() )
{
if (_invalidInfluence.find(inflist.getBoneName()) != _invalidInfluence.end()) {
_invalidInfluence[inflist.getBoneName()] = true;
OSG_WARN << "RigTransformSoftware Bone " << inflist.getBoneName() << " not found, skip the influence group " << std::endl;
if (_invalidInfluence.find(bonename) != _invalidInfluence.end()) {
_invalidInfluence[bonename] = true;
OSG_WARN << "RigTransformSoftware Bone " << bonename << " not found, skip the influence group " << std::endl;
}
continue;
}
Bone* bone = bmit->second.get();
for(BoneInfluenceList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit)
for(IndexWeightList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit)
{
const IndexWeight &iw = *infit;
const unsigned int &index = iw.getIndex();

View File

@@ -36,8 +36,8 @@ void VertexInfluenceMap::normalize(unsigned int numvert) {
std::vector<PerVertWeights > localstore;
localstore.resize(numvert);
for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit) {
BoneInfluenceList &curvecinf=mapit->second;
for(BoneInfluenceList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
IndexWeightList &curvecinf=mapit->second;
for(IndexWeightList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
IndexWeight& inf=*curinf;
localstore[inf.first].first+=inf.second;
localstore[inf.first].second.push_back(&inf.second);
@@ -65,14 +65,16 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert
typedef std::set<BoneWeight,invweight_ordered > BoneWeightOrdered;
std::map<int,BoneWeightOrdered > tempVec2Bones;
for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit) {
BoneInfluenceList &curvecinf=mapit->second;
for(BoneInfluenceList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit)
{
const std::string& bonename=mapit->first;
IndexWeightList &curvecinf=mapit->second;
for(IndexWeightList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
IndexWeight& inf=*curinf;
if( curvecinf.getBoneName().empty()) {
if( bonename.empty()) {
OSG_WARN << "VertexInfluenceSet::buildVertex2BoneList warning vertex " << inf.first << " is not assigned to a bone" << std::endl;
}
else if(inf.second>minweight)tempVec2Bones[inf.first].insert(BoneWeight(curvecinf.getBoneName(), inf.second));
else if(inf.second>minweight)tempVec2Bones[inf.first].insert(BoneWeight(bonename, inf.second));
}
}
this->clear();
@@ -87,15 +89,13 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert
if(sum>1e-4){
sum=1.0f/sum;
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
BoneInfluenceList & inf= (*this)[bwit->getBoneName()];
inf.setBoneName(bwit->getBoneName());
IndexWeightList & inf= (*this)[bwit->getBoneName()];
inf.push_back(IndexWeight(mapit->first, bwit->getWeight()*sum));
}
}
}else{
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
BoneInfluenceList & inf= (*this)[bwit->getBoneName()];
inf.setBoneName(bwit->getBoneName());
IndexWeightList & inf= (*this)[bwit->getBoneName()];
inf.push_back(IndexWeight(mapit->first,bwit->getWeight()));
}
@@ -110,17 +110,17 @@ void VertexInfluenceMap::computePerVertexInfluenceList(std::vector<BoneWeightLis
it != end();
++it)
{
const BoneInfluenceList& inflist = it->second;
if (inflist.getBoneName().empty()) {
OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone BoneInfluenceList" << std::endl;
const IndexWeightList& inflist = it->second;
if (it->first.empty()) {
OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone IndexWeightList" << std::endl;
}
for(BoneInfluenceList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit)
for(IndexWeightList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit)
{
const IndexWeight &iw = *infit;
const unsigned int &index = iw.getIndex();
float weight = iw.getWeight();
vertex2Bones[index].push_back(BoneWeight(inflist.getBoneName(), weight));;
vertex2Bones[index].push_back(BoneWeight(it->first, weight));;
}
}
}