2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*-
|
2009-10-21 23:45:13 +08:00
|
|
|
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
|
2008-11-22 20:14:19 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2008-11-22 20:14:19 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2008-11-22 20:14:19 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-11-22 20:14:19 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2010-01-27 23:37:45 +08:00
|
|
|
#ifndef OSGANIMATION_VERTEX_INFLUENCE
|
|
|
|
#define OSGANIMATION_VERTEX_INFLUENCE 1
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osgAnimation/Export>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace osgAnimation
|
|
|
|
{
|
2017-08-28 20:23:15 +08:00
|
|
|
// first is bonename, and second the weight
|
|
|
|
struct BoneWeight: public std::pair<std::string, float>
|
|
|
|
{
|
|
|
|
BoneWeight( std::string f,float s):
|
|
|
|
std::pair<std::string,float>(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<unsigned int, float>
|
|
|
|
{
|
2017-08-28 21:27:46 +08:00
|
|
|
IndexWeight( unsigned int f = 0xffffffff,float s = 0.0f): std::pair<unsigned int,float>(f,s){}
|
2017-08-28 20:23:15 +08:00
|
|
|
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;}
|
|
|
|
};
|
2017-08-29 06:09:38 +08:00
|
|
|
typedef std::vector<IndexWeight> IndexWeightList;
|
|
|
|
typedef std::vector<BoneWeight> BoneWeightList;
|
|
|
|
typedef std::vector<unsigned int> IndexList;
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2017-08-29 06:09:38 +08:00
|
|
|
/// map a set of boneinfluence to a list of vertex indices sharing this set
|
|
|
|
class VertexGroup: public std::pair<BoneWeightList, IndexList>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
inline const BoneWeightList& getBoneWeights()const { return first; }
|
|
|
|
inline void setBoneWeights(BoneWeightList&o) { first=o; }
|
|
|
|
inline IndexList& vertIDs() { return second; }
|
|
|
|
};
|
|
|
|
class OSGANIMATION_EXPORT BoneInfluenceList : public IndexWeightList
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
public:
|
2017-08-28 20:23:15 +08:00
|
|
|
const std::string& getBoneName() const { return _name;}
|
|
|
|
void setBoneName(const std::string& name) { _name = name;}
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// the name is the bone to link to
|
|
|
|
std::string _name;
|
|
|
|
};
|
|
|
|
|
2017-08-27 08:14:12 +08:00
|
|
|
class VertexInfluenceMap : public std::map<std::string, BoneInfluenceList> , public osg::Object
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
META_Object(osgAnimation, VertexInfluenceMap);
|
|
|
|
|
|
|
|
VertexInfluenceMap() {}
|
2016-08-29 16:41:40 +08:00
|
|
|
VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop):
|
2017-08-27 08:14:12 +08:00
|
|
|
std::map<std::string, BoneInfluenceList>(org),
|
2016-08-29 16:41:40 +08:00
|
|
|
osg::Object(org, copyop)
|
|
|
|
{}
|
2017-08-29 00:42:22 +08:00
|
|
|
///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);
|
|
|
|
|
2008-11-22 20:14:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|