From fe99b568a0dc7dfdc3903a211ab636689fb88552 Mon Sep 17 00:00:00 2001 From: Julien Valentin Date: Wed, 30 Aug 2017 11:12:17 +0200 Subject: [PATCH] refactor: remove totally VertexInfluence (renamed BoneInfluenceList) everywhere --- .../osganimationskinning.cpp | 4 --- include/osgAnimation/VertexInfluence | 14 ++------ src/osgAnimation/RigTransformHardware.cpp | 25 ++++++--------- src/osgAnimation/RigTransformSoftware.cpp | 18 ++++++----- src/osgAnimation/VertexInfluence.cpp | 32 +++++++++---------- src/osgPlugins/gles/AABBonBoneVisitor.cpp | 2 +- .../gles/MostInfluencedGeometryByBone | 4 +-- .../osgAnimation/ReaderWriter.cpp | 13 ++++---- .../serializers/osgAnimation/RigGeometry.cpp | 13 ++++---- 9 files changed, 53 insertions(+), 72 deletions(-) diff --git a/examples/osganimationskinning/osganimationskinning.cpp b/examples/osganimationskinning/osganimationskinning.cpp index c28a2b15d..340868460 100644 --- a/examples/osganimationskinning/osganimationskinning.cpp +++ b/examples/osganimationskinning/osganimationskinning.cpp @@ -136,10 +136,6 @@ void initVertexMap(osgAnimation::Bone* b0, { osgAnimation::VertexInfluenceMap* vim = new osgAnimation::VertexInfluenceMap; - (*vim)[b0->getName()].setBoneName(b0->getName()); - (*vim)[b1->getName()].setBoneName(b1->getName()); - (*vim)[b2->getName()].setBoneName(b2->getName()); - for (int i = 0; i < (int)array->size(); i++) { float val = (*array)[i][0]; diff --git a/include/osgAnimation/VertexInfluence b/include/osgAnimation/VertexInfluence index 4bb42b105..09bdf4c6b 100644 --- a/include/osgAnimation/VertexInfluence +++ b/include/osgAnimation/VertexInfluence @@ -46,25 +46,15 @@ namespace osgAnimation typedef std::vector BoneWeightList; typedef std::vector IndexList; - class OSGANIMATION_EXPORT BoneInfluenceList : public IndexWeightList - { - public: - const std::string& getBoneName() const { return _name;} - void setBoneName(const std::string& name) { _name = name;} - protected: - // the name is the bone to link to - std::string _name; - }; - - class VertexInfluenceMap : public std::map , public osg::Object + class VertexInfluenceMap : public std::map , public osg::Object { public: META_Object(osgAnimation, VertexInfluenceMap); VertexInfluenceMap() {} VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop): - std::map(org), + std::map(org), osg::Object(org, copyop) {} ///normalize per vertex weights given numvert of the attached mesh diff --git a/src/osgAnimation/RigTransformHardware.cpp b/src/osgAnimation/RigTransformHardware.cpp index b4640df4c..bc7fc16d7 100644 --- a/src/osgAnimation/RigTransformHardware.cpp +++ b/src/osgAnimation/RigTransformHardware.cpp @@ -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); diff --git a/src/osgAnimation/RigTransformSoftware.cpp b/src/osgAnimation/RigTransformSoftware.cpp index 6e54b2cd6..c36b1aa5a 100644 --- a/src/osgAnimation/RigTransformSoftware.cpp +++ b/src/osgAnimation/RigTransformSoftware.cpp @@ -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(); diff --git a/src/osgAnimation/VertexInfluence.cpp b/src/osgAnimation/VertexInfluence.cpp index dabaca32f..4dc433ff2 100644 --- a/src/osgAnimation/VertexInfluence.cpp +++ b/src/osgAnimation/VertexInfluence.cpp @@ -36,8 +36,8 @@ void VertexInfluenceMap::normalize(unsigned int numvert) { std::vector 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 BoneWeightOrdered; std::map 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::vectorsecond; - 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));; } } } diff --git a/src/osgPlugins/gles/AABBonBoneVisitor.cpp b/src/osgPlugins/gles/AABBonBoneVisitor.cpp index 5b3fc99dd..ec0bc7e46 100644 --- a/src/osgPlugins/gles/AABBonBoneVisitor.cpp +++ b/src/osgPlugins/gles/AABBonBoneVisitor.cpp @@ -51,7 +51,7 @@ void ComputeAABBOnBoneVisitor::computeBoundingBoxOnBones() { osg::Vec3Array *vertices = dynamic_cast(rigGeometry->getVertexArray()); if(!vertices) continue; - osgAnimation::BoneInfluenceList vxtInf = (*itMap).second; + osgAnimation::IndexWeightList vxtInf = (*itMap).second; //Expand the boundingBox with each vertex for(unsigned int j = 0; j < vxtInf.size(); j++) { diff --git a/src/osgPlugins/gles/MostInfluencedGeometryByBone b/src/osgPlugins/gles/MostInfluencedGeometryByBone index a5e8c5e97..000b9930f 100644 --- a/src/osgPlugins/gles/MostInfluencedGeometryByBone +++ b/src/osgPlugins/gles/MostInfluencedGeometryByBone @@ -200,9 +200,9 @@ protected: BoneNameBoneMap::iterator bone_it = boneMap.find(vertexInfluencePair->first); if(bone_it == boneMap.end()) continue; osg::ref_ptr bone = bone_it->second; - const osgAnimation::BoneInfluenceList& vertexInfluence = (*vertexInfluencePair).second; + const osgAnimation::IndexWeightList& vertexInfluence = (*vertexInfluencePair).second; - for(osgAnimation::BoneInfluenceList::const_iterator vertexIndexWeight = vertexInfluence.begin(); vertexIndexWeight != vertexInfluence.end(); ++vertexIndexWeight) { + for(osgAnimation::IndexWeightList::const_iterator vertexIndexWeight = vertexInfluence.begin(); vertexIndexWeight != vertexInfluence.end(); ++vertexIndexWeight) { rigGeometryInfluenceByBoneMap[bone.get()][*rigGeometry].addWeight((*vertexIndexWeight).second); } } diff --git a/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp b/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp index b8813ae70..57796375b 100644 --- a/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp +++ b/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp @@ -804,17 +804,16 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr) for (int i = 0; i < nbGroups; i++) { int nbVertexes = 0; - std::string name; + std::string bonename; if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {")) { - name = fr[1].getStr(); + bonename = fr[1].getStr(); fr[2].getInt(nbVertexes); fr += 4; iteratorAdvanced = true; } - osgAnimation::BoneInfluenceList vi; - vi.setBoneName(name); + osgAnimation::IndexWeightList vi; vi.reserve(nbVertexes); for (int j = 0; j < nbVertexes; j++) { @@ -833,7 +832,7 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr) { fr+=1; } - (*vmap)[name] = vi; + (*vmap)[bonename] = vi; } if (!vmap->empty()) geom.setInfluenceMap(vmap.get()); @@ -863,8 +862,8 @@ bool RigGeometry_writeLocalData(const Object& obj, Output& fw) name = "Empty"; fw.indent() << "osgAnimation::VertexInfluence \"" << name << "\" " << it->second.size() << " {" << std::endl; fw.moveIn(); - const osgAnimation::BoneInfluenceList& vi = it->second; - for (osgAnimation::BoneInfluenceList::const_iterator itv = vi.begin(); itv != vi.end(); itv++) + const osgAnimation::IndexWeightList& vi = it->second; + for (osgAnimation::IndexWeightList::const_iterator itv = vi.begin(); itv != vi.end(); itv++) { fw.indent() << itv->first << " " << itv->second << std::endl; } diff --git a/src/osgWrappers/serializers/osgAnimation/RigGeometry.cpp b/src/osgWrappers/serializers/osgAnimation/RigGeometry.cpp index 0d88de08d..1403bd648 100644 --- a/src/osgWrappers/serializers/osgAnimation/RigGeometry.cpp +++ b/src/osgWrappers/serializers/osgAnimation/RigGeometry.cpp @@ -14,14 +14,13 @@ static bool readInfluenceMap( osgDB::InputStream& is, osgAnimation::RigGeometry& unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; for ( unsigned int i=0; i> is.PROPERTY("VertexInfluence"); - is.readWrappedString(name); + is.readWrappedString(bonename); viSize = is.readSize(); is >> is.BEGIN_BRACKET; - osgAnimation::BoneInfluenceList vi; - vi.setBoneName( name ); + osgAnimation::IndexWeightList vi; vi.reserve( viSize ); for ( unsigned int j=0; j> index >> weight; vi.push_back( osgAnimation::IndexWeight(index, weight) ); } - (*map)[name] = vi; + (*map)[bonename] = vi; is >> is.END_BRACKET; } is >> is.END_BRACKET; @@ -47,14 +46,14 @@ static bool writeInfluenceMap( osgDB::OutputStream& os, const osgAnimation::RigG itr!=map->end(); ++itr ) { std::string name = itr->first; - const osgAnimation::BoneInfluenceList& vi = itr->second; + const osgAnimation::IndexWeightList& vi = itr->second; if ( name.empty() ) name = "Empty"; os << os.PROPERTY("VertexInfluence"); os.writeWrappedString(name); os.writeSize(vi.size()) ; os << os.BEGIN_BRACKET << std::endl; - for ( osgAnimation::BoneInfluenceList::const_iterator vitr=vi.begin(); + for ( osgAnimation::IndexWeightList::const_iterator vitr=vi.begin(); vitr != vi.end(); ++vitr ) { os << vitr->first << vitr->second << std::endl;