RigTransformHardware 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* -*-c++-*-
  2. * Copyright (C) 2009 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_RIG_TRANSFORM_HARDWARE
  16. #define OSGANIMATION_RIG_TRANSFORM_HARDWARE 1
  17. #include <osgAnimation/Export>
  18. #include <osgAnimation/RigTransform>
  19. #include <osgAnimation/VertexInfluence>
  20. #include <osgAnimation/Bone>
  21. #include <osg/Matrix>
  22. #include <osg/Array>
  23. #define RIGTRANSHW_DEFAULT_FIRST_VERTATTRIB_TARGETTED 11
  24. namespace osgAnimation
  25. {
  26. class RigGeometry;
  27. /// This class manage format for hardware skinning
  28. class OSGANIMATION_EXPORT RigTransformHardware : public RigTransform
  29. {
  30. public:
  31. RigTransformHardware();
  32. RigTransformHardware(const RigTransformHardware& rth, const osg::CopyOp& copyop);
  33. META_Object(osgAnimation,RigTransformHardware);
  34. typedef std::vector<osg::ref_ptr<osg::Vec4Array> > BoneWeightAttribList;
  35. typedef std::vector<osg::ref_ptr<Bone> > BonePalette;
  36. typedef std::map<std::string, unsigned int> BoneNamePaletteIndex;
  37. typedef std::vector<osg::Matrix> MatrixPalette;
  38. ///set the first Vertex Attribute Array index of the rig generated by this technic (default:11)
  39. void setFirstVertexAttributeTarget(unsigned int i) { _minAttribIndex=i; }
  40. unsigned int getFirstVertexAttributeTarget()const { return _minAttribIndex; }
  41. void setShader(osg::Shader* shader) { _shader = shader; }
  42. const osg::Shader* getShader() const { return _shader.get(); }
  43. osg::Shader* getShader() { return _shader.get(); }
  44. osg::Vec4Array* getVertexAttrib(unsigned int index);
  45. unsigned int getNumVertexAttrib() const { return _boneWeightAttribArrays.size(); }
  46. const unsigned int &getNumBonesPerVertex() const { return _bonesPerVertex; }
  47. const unsigned int &getNumVertexes() const { return _nbVertices; }
  48. const BoneNamePaletteIndex& getBoneNameToPalette() { return _boneNameToPalette; }
  49. const BonePalette& getBonePalette() { return _bonePalette; }
  50. osg::Uniform* getMatrixPaletteUniform() { return _uniformMatrixPalette.get(); }
  51. void computeMatrixPaletteUniform(const osg::Matrix& transformFromSkeletonToGeometry, const osg::Matrix& invTransformFromSkeletonToGeometry);
  52. // update rig if needed
  53. virtual void operator()(RigGeometry&);
  54. // init/reset animations data
  55. virtual bool prepareData(RigGeometry& );
  56. protected:
  57. unsigned int _bonesPerVertex;
  58. unsigned int _nbVertices;
  59. BonePalette _bonePalette;
  60. BoneNamePaletteIndex _boneNameToPalette;
  61. BoneWeightAttribList _boneWeightAttribArrays;
  62. osg::ref_ptr<osg::Uniform> _uniformMatrixPalette;
  63. osg::ref_ptr<osg::Shader> _shader;
  64. bool _needInit;
  65. unsigned int _minAttribIndex;
  66. bool buildPalette(const BoneMap& boneMap,const RigGeometry& rig);
  67. //on first update
  68. virtual bool init(RigGeometry& );
  69. std::vector<IndexWeightList> _perVertexInfluences;
  70. };
  71. }
  72. #endif