2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
3 * Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
5 * This library is open source and may be redistributed and/or modified under
6 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
7 * (at your option) any later version. The full license is in LICENSE file
8 * included with this distribution, and on the openscenegraph.org website.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * OpenSceneGraph Public License for more details.
16#ifndef OSGANIMATION_VERTEX_INFLUENCE
17#define OSGANIMATION_VERTEX_INFLUENCE 1
20#include <osgAnimation/Export>
29 // first is bonename, and second the weight
30 typedef std::pair<std::string, float> BoneWeight;
31 // first is vertex index, and second the weight
32 typedef std::pair<unsigned int, float> VertexIndexWeight;
33 // list of IndexWeight
34 typedef std::vector<VertexIndexWeight> IndexWeightList;
35 // list of IndexWeight
36 typedef std::vector<BoneWeight> BoneWeightList;
38 typedef std::vector<unsigned int> IndexList;
41 class OSGANIMATION_EXPORT VertexInfluence : public IndexWeightList
44 const std::string& getName() const { return _name; }
45 void setName(const std::string& name) { _name = name; }
47 // the name is the bone to link to
51 class VertexInfluenceMap : public std::map<std::string, VertexInfluence>, public osg::Object
54 META_Object(osgAnimation, VertexInfluenceMap);
56 VertexInfluenceMap() {}
57 VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop):
58 std::map<std::string, VertexInfluence>(org),
59 osg::Object(org, copyop) {}
61 ///normalize per vertex weights given numvert of the attached mesh
62 void normalize(unsigned int numvert);
64 ///remove weakest influences in order to fit targeted numbonepervertex
65 void cullInfluenceCountPerVertex(unsigned int maxnumbonepervertex, float minweight=0, bool renormalize=true);
67 //compute PerVertexInfluenceList
68 void computePerVertexInfluenceList(std::vector<BoneWeightList>& perVertexInfluenceList, unsigned int numvert) const;
70 /// map a set of boneinfluence to a list of vertex indices sharing this set
71 class VertexGroup: public std::pair<BoneWeightList, IndexList>
74 inline const BoneWeightList& getBoneWeights() const { return first; }
75 inline void setBoneWeights( BoneWeightList& o ) { first=o; }
76 inline IndexList& vertIDs() { return second; }
79 /// compute the minimal VertexGroup Set in which vertices shares the same influence set
80 void computeMinimalVertexGroupList(std::vector<VertexGroup>&uniqVertexGroupList, unsigned int numvert) const;
82 //Experimental removal of unexpressed bone from the skeleton
83 void removeUnexpressedBones(Skeleton &skel) const;