openscenegraph
VertexInfluence
Go to the documentation of this file.
1/* -*-c++-*-
2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
3 * Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
4 *
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.
9 *
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.
14*/
15
16#ifndef OSGANIMATION_VERTEX_INFLUENCE
17#define OSGANIMATION_VERTEX_INFLUENCE 1
18
19#include <osg/Object>
20#include <osgAnimation/Export>
21#include <map>
22#include <vector>
23#include <string>
24
25namespace osgAnimation
26{
27 class Skeleton;
28
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;
37 // list of Index
38 typedef std::vector<unsigned int> IndexList;
39
40 //Bone influence list
41 class OSGANIMATION_EXPORT VertexInfluence : public IndexWeightList
42 {
43 public:
44 const std::string& getName() const { return _name; }
45 void setName(const std::string& name) { _name = name; }
46 protected:
47 // the name is the bone to link to
48 std::string _name;
49 };
50
51 class VertexInfluenceMap : public std::map<std::string, VertexInfluence>, public osg::Object
52 {
53 public:
54 META_Object(osgAnimation, VertexInfluenceMap);
55
56 VertexInfluenceMap() {}
57 VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop):
58 std::map<std::string, VertexInfluence>(org),
59 osg::Object(org, copyop) {}
60
61 ///normalize per vertex weights given numvert of the attached mesh
62 void normalize(unsigned int numvert);
63
64 ///remove weakest influences in order to fit targeted numbonepervertex
65 void cullInfluenceCountPerVertex(unsigned int maxnumbonepervertex, float minweight=0, bool renormalize=true);
66
67 //compute PerVertexInfluenceList
68 void computePerVertexInfluenceList(std::vector<BoneWeightList>& perVertexInfluenceList, unsigned int numvert) const;
69
70 /// map a set of boneinfluence to a list of vertex indices sharing this set
71 class VertexGroup: public std::pair<BoneWeightList, IndexList>
72 {
73 public:
74 inline const BoneWeightList& getBoneWeights() const { return first; }
75 inline void setBoneWeights( BoneWeightList& o ) { first=o; }
76 inline IndexList& vertIDs() { return second; }
77 };
78
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;
81
82 //Experimental removal of unexpressed bone from the skeleton
83 void removeUnexpressedBones(Skeleton &skel) const;
84 };
85}
86
87#endif