readd VertexInfluence whenever it's bad named and kinda useless

This commit is contained in:
Julien Valentin 2017-08-30 15:13:54 +02:00
parent 6d1193ee70
commit 8fad310ce1
7 changed files with 34 additions and 18 deletions

View File

@ -135,7 +135,9 @@ void initVertexMap(osgAnimation::Bone* b0,
osg::Vec3Array* array) osg::Vec3Array* array)
{ {
osgAnimation::VertexInfluenceMap* vim = new osgAnimation::VertexInfluenceMap; 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++) for (int i = 0; i < (int)array->size(); i++)
{ {
float val = (*array)[i][0]; float val = (*array)[i][0];

View File

@ -46,15 +46,26 @@ namespace osgAnimation
typedef std::vector<BoneWeight> BoneWeightList; typedef std::vector<BoneWeight> BoneWeightList;
typedef std::vector<unsigned int> IndexList; typedef std::vector<unsigned int> 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<std::string, IndexWeightList> , public osg::Object protected:
// the name is the bone to link to
std::string _name;
};
class VertexInfluenceMap : public std::map<std::string, VertexInfluence> , public osg::Object
{ {
public: public:
META_Object(osgAnimation, VertexInfluenceMap); META_Object(osgAnimation, VertexInfluenceMap);
VertexInfluenceMap() {} VertexInfluenceMap() {}
VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop): VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop):
std::map<std::string, IndexWeightList>(org), std::map<std::string, VertexInfluence>(org),
osg::Object(org, copyop) osg::Object(org, copyop)
{} {}
///normalize per vertex weights given numvert of the attached mesh ///normalize per vertex weights given numvert of the attached mesh

View File

@ -89,14 +89,16 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert
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) {
IndexWeightList & inf= (*this)[bwit->getBoneName()]; VertexInfluence & inf= (*this)[bwit->getBoneName()];
inf.push_back(IndexWeight(mapit->first, bwit->getWeight()*sum)); inf.push_back(IndexWeight(mapit->first, bwit->getWeight()*sum));
inf.setName(bwit->getBoneName());
} }
} }
}else{ }else{
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) { 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.push_back(IndexWeight(mapit->first,bwit->getWeight()));
inf.setName(bwit->getBoneName());
} }
} }

View File

@ -51,7 +51,7 @@ void ComputeAABBOnBoneVisitor::computeBoundingBoxOnBones() {
osg::Vec3Array *vertices = dynamic_cast<osg::Vec3Array*>(rigGeometry->getVertexArray()); osg::Vec3Array *vertices = dynamic_cast<osg::Vec3Array*>(rigGeometry->getVertexArray());
if(!vertices) continue; if(!vertices) continue;
osgAnimation::IndexWeightList vxtInf = (*itMap).second; osgAnimation::VertexInfluence vxtInf = (*itMap).second;
//Expand the boundingBox with each vertex //Expand the boundingBox with each vertex
for(unsigned int j = 0; j < vxtInf.size(); j++) { for(unsigned int j = 0; j < vxtInf.size(); j++) {

View File

@ -200,9 +200,9 @@ protected:
BoneNameBoneMap::iterator bone_it = boneMap.find(vertexInfluencePair->first); BoneNameBoneMap::iterator bone_it = boneMap.find(vertexInfluencePair->first);
if(bone_it == boneMap.end()) continue; if(bone_it == boneMap.end()) continue;
osg::ref_ptr<osgAnimation::Bone> bone = bone_it->second; osg::ref_ptr<osgAnimation::Bone> 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); rigGeometryInfluenceByBoneMap[bone.get()][*rigGeometry].addWeight((*vertexIndexWeight).second);
} }
} }

View File

@ -804,16 +804,17 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr)
for (int i = 0; i < nbGroups; i++) for (int i = 0; i < nbGroups; i++)
{ {
int nbVertexes = 0; int nbVertexes = 0;
std::string bonename; std::string name;
if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {")) if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {"))
{ {
bonename = fr[1].getStr(); name = fr[1].getStr();
fr[2].getInt(nbVertexes); fr[2].getInt(nbVertexes);
fr += 4; fr += 4;
iteratorAdvanced = true; iteratorAdvanced = true;
} }
osgAnimation::IndexWeightList vi; osgAnimation::VertexInfluence vi;
vi.setName(name);
vi.reserve(nbVertexes); vi.reserve(nbVertexes);
for (int j = 0; j < nbVertexes; j++) for (int j = 0; j < nbVertexes; j++)
{ {
@ -832,7 +833,7 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr)
{ {
fr+=1; fr+=1;
} }
(*vmap)[bonename] = vi; (*vmap)[name] = vi;
} }
if (!vmap->empty()) if (!vmap->empty())
geom.setInfluenceMap(vmap.get()); geom.setInfluenceMap(vmap.get());
@ -862,8 +863,8 @@ bool RigGeometry_writeLocalData(const Object& obj, Output& fw)
name = "Empty"; name = "Empty";
fw.indent() << "osgAnimation::VertexInfluence \"" << name << "\" " << it->second.size() << " {" << std::endl; fw.indent() << "osgAnimation::VertexInfluence \"" << name << "\" " << it->second.size() << " {" << std::endl;
fw.moveIn(); fw.moveIn();
const osgAnimation::IndexWeightList& vi = it->second; const osgAnimation::VertexInfluence& vi = it->second;
for (osgAnimation::IndexWeightList::const_iterator itv = vi.begin(); itv != vi.end(); itv++) for (osgAnimation::VertexInfluence::const_iterator itv = vi.begin(); itv != vi.end(); itv++)
{ {
fw.indent() << itv->first << " " << itv->second << std::endl; fw.indent() << itv->first << " " << itv->second << std::endl;
} }

View File

@ -19,8 +19,8 @@ static bool readInfluenceMap( osgDB::InputStream& is, osgAnimation::RigGeometry&
is >> is.PROPERTY("VertexInfluence"); is >> is.PROPERTY("VertexInfluence");
is.readWrappedString(bonename); is.readWrappedString(bonename);
viSize = is.readSize(); is >> is.BEGIN_BRACKET; viSize = is.readSize(); is >> is.BEGIN_BRACKET;
osgAnimation::VertexInfluence vi;
osgAnimation::IndexWeightList vi; vi.setName( bonename );
vi.reserve( viSize ); vi.reserve( viSize );
for ( unsigned int j=0; j<viSize; ++j ) for ( unsigned int j=0; j<viSize; ++j )
{ {
@ -46,14 +46,14 @@ static bool writeInfluenceMap( osgDB::OutputStream& os, const osgAnimation::RigG
itr!=map->end(); ++itr ) itr!=map->end(); ++itr )
{ {
std::string name = itr->first; std::string name = itr->first;
const osgAnimation::IndexWeightList& vi = itr->second; const osgAnimation::VertexInfluence& vi = itr->second;
if ( name.empty() ) name = "Empty"; if ( name.empty() ) name = "Empty";
os << os.PROPERTY("VertexInfluence"); os << os.PROPERTY("VertexInfluence");
os.writeWrappedString(name); os.writeWrappedString(name);
os.writeSize(vi.size()) ; os << os.BEGIN_BRACKET << std::endl; 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 ) vitr != vi.end(); ++vitr )
{ {
os << vitr->first << vitr->second << std::endl; os << vitr->first << vitr->second << std::endl;