diff --git a/include/osgAnimation/VertexInfluence b/include/osgAnimation/VertexInfluence index bff9a11d9..2ddd39ebe 100644 --- a/include/osgAnimation/VertexInfluence +++ b/include/osgAnimation/VertexInfluence @@ -25,26 +25,14 @@ namespace osgAnimation { // first is bonename, and second the weight - struct BoneWeight: public std::pair - { - BoneWeight( std::string f,float s): - std::pair(f,s){} - inline const std::string& getBoneName()const{return first;} - inline void setBoneName(const std::string&s){first=s;} - inline const float &getWeight()const{return second;} - inline void setWeight(float i){second=i;} - }; + typedef std::pair BoneWeight; // first is vertex index, and second the weight - struct VertexIndexWeight: public std::pair - { - VertexIndexWeight( unsigned int f = 0xffffffff,float s = 0.0f): std::pair(f,s){} - inline const unsigned int& getIndex()const{return first;} - inline void setIndex(unsigned int i){first=i;} - inline const float &getWeight()const{return second;} - inline void setWeight(float i){second=i;} - }; + typedef std::pair VertexIndexWeight; + // list of IndexWeight typedef std::vector IndexWeightList; + // list of IndexWeight typedef std::vector BoneWeightList; + // list of Index typedef std::vector IndexList; //Bone influence list diff --git a/src/osgAnimation/RigTransformHardware.cpp b/src/osgAnimation/RigTransformHardware.cpp index e474cde00..c34ec2831 100644 --- a/src/osgAnimation/RigTransformHardware.cpp +++ b/src/osgAnimation/RigTransformHardware.cpp @@ -127,9 +127,9 @@ unsigned int createVertexAttribList(const PerVertexInfList & perVertexInfluences boneIndexInList = j*2 + b; if (boneIndexInList < (*vertinfit).size()) { - float boneIndex = static_cast((*vertinfit)[boneIndexInList].getIndex()); + float boneIndex = static_cast((*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; } diff --git a/src/osgAnimation/RigTransformSoftware.cpp b/src/osgAnimation/RigTransformSoftware.cpp index 4d8be913c..ccb1a0a11 100644 --- a/src/osgAnimation/RigTransformSoftware.cpp +++ b/src/osgAnimation/RigTransformSoftware.cpp @@ -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)); } } diff --git a/src/osgAnimation/VertexInfluence.cpp b/src/osgAnimation/VertexInfluence.cpp index ee42b53c4..3c2c50c42 100644 --- a/src/osgAnimation/VertexInfluence.cpp +++ b/src/osgAnimation/VertexInfluence.cpp @@ -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.second)return true; + if (bw1.second < bw2.second)return false; + return(bw1.firstnewsize)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::vectorfirst, weight));; } } @@ -133,11 +133,11 @@ struct SortByNameAndWeight : public std::less 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); } };