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
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:
55
58 std::map<std::string, VertexInfluence>(org),
59 osg::Object(org, copyop) {}
60
62 void normalize(unsigned int numvert);
63
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
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
80 void computeMinimalVertexGroupList(std::vector<VertexGroup>&uniqVertexGroupList, unsigned int numvert) const;
81
82 //Experimental removal of unexpressed bone from the skeleton
84 };
85}
86
87#endif
Definition Skeleton:26
map a set of boneinfluence to a list of vertex indices sharing this set
Definition VertexInfluence:72
IndexList & vertIDs()
Definition VertexInfluence:76
const BoneWeightList & getBoneWeights() const
Definition VertexInfluence:74
void setBoneWeights(BoneWeightList &o)
Definition VertexInfluence:75
Definition VertexInfluence:52
void cullInfluenceCountPerVertex(unsigned int maxnumbonepervertex, float minweight=0, bool renormalize=true)
remove weakest influences in order to fit targeted numbonepervertex
VertexInfluenceMap()
Definition VertexInfluence:56
VertexInfluenceMap(const osgAnimation::VertexInfluenceMap &org, const osg::CopyOp &copyop)
Definition VertexInfluence:57
void removeUnexpressedBones(Skeleton &skel) const
void computeMinimalVertexGroupList(std::vector< VertexGroup > &uniqVertexGroupList, unsigned int numvert) const
compute the minimal VertexGroup Set in which vertices shares the same influence set
void normalize(unsigned int numvert)
normalize per vertex weights given numvert of the attached mesh
META_Object(osgAnimation, VertexInfluenceMap)
void computePerVertexInfluenceList(std::vector< BoneWeightList > &perVertexInfluenceList, unsigned int numvert) const
Definition VertexInfluence:42
std::string _name
Definition VertexInfluence:48
const std::string & getName() const
Definition VertexInfluence:44
void setName(const std::string &name)
Definition VertexInfluence:45
Definition CopyOp:41
Definition Object:61
Object()
Definition Object:69
Definition Action:34
std::vector< VertexIndexWeight > IndexWeightList
Definition VertexInfluence:34
std::vector< BoneWeight > BoneWeightList
Definition VertexInfluence:36
std::pair< std::string, float > BoneWeight
Definition VertexInfluence:30
std::pair< unsigned int, float > VertexIndexWeight
Definition VertexInfluence:32
std::vector< unsigned int > IndexList
Definition VertexInfluence:38
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSGANIMATION_EXPORT
Definition osgAnimation/Export:40