VertexInfluence 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #ifndef OSGANIMATION_VERTEX_INFLUENCE
  16. #define OSGANIMATION_VERTEX_INFLUENCE 1
  17. #include <osg/Object>
  18. #include <osgAnimation/Export>
  19. #include <map>
  20. #include <vector>
  21. #include <string>
  22. namespace osgAnimation
  23. {
  24. class Skeleton;
  25. // first is bonename, and second the weight
  26. typedef std::pair<std::string, float> BoneWeight;
  27. // first is vertex index, and second the weight
  28. typedef std::pair<unsigned int, float> VertexIndexWeight;
  29. // list of IndexWeight
  30. typedef std::vector<VertexIndexWeight> IndexWeightList;
  31. // list of IndexWeight
  32. typedef std::vector<BoneWeight> BoneWeightList;
  33. // list of Index
  34. typedef std::vector<unsigned int> IndexList;
  35. //Bone influence list
  36. class OSGANIMATION_EXPORT VertexInfluence : public IndexWeightList
  37. {
  38. public:
  39. const std::string& getName() const { return _name; }
  40. void setName(const std::string& name) { _name = name; }
  41. protected:
  42. // the name is the bone to link to
  43. std::string _name;
  44. };
  45. class VertexInfluenceMap : public std::map<std::string, VertexInfluence>, public osg::Object
  46. {
  47. public:
  48. META_Object(osgAnimation, VertexInfluenceMap);
  49. VertexInfluenceMap() {}
  50. VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop):
  51. std::map<std::string, VertexInfluence>(org),
  52. osg::Object(org, copyop) {}
  53. ///normalize per vertex weights given numvert of the attached mesh
  54. void normalize(unsigned int numvert);
  55. ///remove weakest influences in order to fit targeted numbonepervertex
  56. void cullInfluenceCountPerVertex(unsigned int maxnumbonepervertex, float minweight=0, bool renormalize=true);
  57. //compute PerVertexInfluenceList
  58. void computePerVertexInfluenceList(std::vector<BoneWeightList>& perVertexInfluenceList, unsigned int numvert) const;
  59. /// map a set of boneinfluence to a list of vertex indices sharing this set
  60. class VertexGroup: public std::pair<BoneWeightList, IndexList>
  61. {
  62. public:
  63. inline const BoneWeightList& getBoneWeights() const { return first; }
  64. inline void setBoneWeights( BoneWeightList& o ) { first=o; }
  65. inline IndexList& vertIDs() { return second; }
  66. };
  67. /// compute the minimal VertexGroup Set in which vertices shares the same influence set
  68. void computeMinimalVertexGroupList(std::vector<VertexGroup>&uniqVertexGroupList, unsigned int numvert) const;
  69. //Experimental removal of unexpressed bone from the skeleton
  70. void removeUnexpressedBones(Skeleton &skel) const;
  71. };
  72. }
  73. #endif