From 8fad310ce12cfb0a602e3c2ca129cfe6620e307d Mon Sep 17 00:00:00 2001 From: Julien Valentin Date: Wed, 30 Aug 2017 15:13:54 +0200 Subject: [PATCH] readd VertexInfluence whenever it's bad named and kinda useless --- .../osganimationskinning/osganimationskinning.cpp | 4 +++- include/osgAnimation/VertexInfluence | 15 +++++++++++++-- src/osgAnimation/VertexInfluence.cpp | 6 ++++-- src/osgPlugins/gles/AABBonBoneVisitor.cpp | 2 +- src/osgPlugins/gles/MostInfluencedGeometryByBone | 4 ++-- .../osgAnimation/ReaderWriter.cpp | 13 +++++++------ .../serializers/osgAnimation/RigGeometry.cpp | 8 ++++---- 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/examples/osganimationskinning/osganimationskinning.cpp b/examples/osganimationskinning/osganimationskinning.cpp index 340868460..485276e03 100644 --- a/examples/osganimationskinning/osganimationskinning.cpp +++ b/examples/osganimationskinning/osganimationskinning.cpp @@ -135,7 +135,9 @@ void initVertexMap(osgAnimation::Bone* b0, osg::Vec3Array* array) { osgAnimation::VertexInfluenceMap* vim = new osgAnimation::VertexInfluenceMap; - + (*vim)[b0->getName()].setName(b0->getName()); + (*vim)[b1->getName()].setName(b1->getName()); + (*vim)[b2->getName()].setName(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 09bdf4c6b..94c12b0e4 100644 --- a/include/osgAnimation/VertexInfluence +++ b/include/osgAnimation/VertexInfluence @@ -46,15 +46,26 @@ namespace osgAnimation typedef std::vector BoneWeightList; typedef std::vector IndexList; + //Bone influence list + class OSGANIMATION_EXPORT VertexInfluence : public IndexWeightList + { + public: + const std::string& getName() const { return _name;} + void setName(const std::string& name) { _name = name;} - class VertexInfluenceMap : public std::map , public osg::Object + protected: + // the name is the bone to link to + std::string _name; + }; + + 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/VertexInfluence.cpp b/src/osgAnimation/VertexInfluence.cpp index 4dc433ff2..2fffc7559 100644 --- a/src/osgAnimation/VertexInfluence.cpp +++ b/src/osgAnimation/VertexInfluence.cpp @@ -89,14 +89,16 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert if(sum>1e-4){ sum=1.0f/sum; for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) { - IndexWeightList & inf= (*this)[bwit->getBoneName()]; + VertexInfluence & inf= (*this)[bwit->getBoneName()]; inf.push_back(IndexWeight(mapit->first, bwit->getWeight()*sum)); + inf.setName(bwit->getBoneName()); } } }else{ for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) { - IndexWeightList & inf= (*this)[bwit->getBoneName()]; + VertexInfluence & inf= (*this)[bwit->getBoneName()]; inf.push_back(IndexWeight(mapit->first,bwit->getWeight())); + inf.setName(bwit->getBoneName()); } } diff --git a/src/osgPlugins/gles/AABBonBoneVisitor.cpp b/src/osgPlugins/gles/AABBonBoneVisitor.cpp index ec0bc7e46..0ea5302f7 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::IndexWeightList vxtInf = (*itMap).second; + osgAnimation::VertexInfluence 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 000b9930f..024d87ddb 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::IndexWeightList& vertexInfluence = (*vertexInfluencePair).second; + const osgAnimation::VertexInfluence& vertexInfluence = (*vertexInfluencePair).second; - for(osgAnimation::IndexWeightList::const_iterator vertexIndexWeight = vertexInfluence.begin(); vertexIndexWeight != vertexInfluence.end(); ++vertexIndexWeight) { + for(osgAnimation::VertexInfluence::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 57796375b..4dbf949dc 100644 --- a/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp +++ b/src/osgWrappers/deprecated-dotosg/osgAnimation/ReaderWriter.cpp @@ -804,16 +804,17 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr) for (int i = 0; i < nbGroups; i++) { int nbVertexes = 0; - std::string bonename; + std::string name; if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {")) { - bonename = fr[1].getStr(); + name = fr[1].getStr(); fr[2].getInt(nbVertexes); fr += 4; iteratorAdvanced = true; } - osgAnimation::IndexWeightList vi; + osgAnimation::VertexInfluence vi; + vi.setName(name); vi.reserve(nbVertexes); for (int j = 0; j < nbVertexes; j++) { @@ -832,7 +833,7 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr) { fr+=1; } - (*vmap)[bonename] = vi; + (*vmap)[name] = vi; } if (!vmap->empty()) geom.setInfluenceMap(vmap.get()); @@ -862,8 +863,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::IndexWeightList& vi = it->second; - for (osgAnimation::IndexWeightList::const_iterator itv = vi.begin(); itv != vi.end(); itv++) + const osgAnimation::VertexInfluence& vi = it->second; + for (osgAnimation::VertexInfluence::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 1403bd648..2ea4b9551 100644 --- a/src/osgWrappers/serializers/osgAnimation/RigGeometry.cpp +++ b/src/osgWrappers/serializers/osgAnimation/RigGeometry.cpp @@ -19,8 +19,8 @@ static bool readInfluenceMap( osgDB::InputStream& is, osgAnimation::RigGeometry& is >> is.PROPERTY("VertexInfluence"); is.readWrappedString(bonename); viSize = is.readSize(); is >> is.BEGIN_BRACKET; - - osgAnimation::IndexWeightList vi; + osgAnimation::VertexInfluence vi; + vi.setName( bonename ); vi.reserve( viSize ); for ( unsigned int j=0; jend(); ++itr ) { std::string name = itr->first; - const osgAnimation::IndexWeightList& vi = itr->second; + const osgAnimation::VertexInfluence& 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::IndexWeightList::const_iterator vitr=vi.begin(); + for ( osgAnimation::VertexInfluence::const_iterator vitr=vi.begin(); vitr != vi.end(); ++vitr ) { os << vitr->first << vitr->second << std::endl;