/* -*-c++-*- * Copyright (C) 2008 Cedric Pinson * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #ifndef OSGANIMATION_VERTEX_INFLUENCE #define OSGANIMATION_VERTEX_INFLUENCE 1 #include #include #include #include #include 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;} }; // first is vertex index, and second the weight struct IndexWeight: public std::pair { IndexWeight( 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::vector IndexWeightList; 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 { public: META_Object(osgAnimation, VertexInfluenceMap); VertexInfluenceMap() {} VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop): std::map(org), osg::Object(org, copyop) {} ///normalize per vertex weights given numvert of the attached mesh void normalize(unsigned int numvert); ///remove weakest influences in order to fit targetted numbonepervertex void cullInfluenceCountPerVertex(unsigned int maxnumbonepervertex, float minweight=0, bool renormalize=true); //compute PerVertexInfluenceList void computePerVertexInfluenceList(std::vector& perVertexInfluenceList, unsigned int numvert)const; /// map a set of boneinfluence to a list of vertex indices sharing this set class VertexGroup: public std::pair { public: inline const BoneWeightList& getBoneWeights()const { return first; } inline void setBoneWeights( BoneWeightList& o ) { first=o; } inline IndexList& vertIDs() { return second; } }; /// compute the minimal VertexGroup Set in which vertices shares the same influence set void computeMinimalVertexGroupList(std::vector&uniqVertexGroupList, unsigned int numvert)const; }; } #endif