CCMeshSkin.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /****************************************************************************
  2. Copyright (c) 2014-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCMESHSKIN_H__
  22. #define __CCMESHSKIN_H__
  23. #include "3d/CCBundle3DData.h"
  24. #include "base/CCRef.h"
  25. #include "base/CCVector.h"
  26. #include "math/CCMath.h"
  27. NS_CC_BEGIN
  28. /**
  29. * @addtogroup _3d
  30. * @{
  31. */
  32. class Bone3D;
  33. class Skeleton3D;
  34. /**
  35. * @brief MeshSkin, A class maintain a collection of bones that affect Mesh vertex.
  36. * And it is responsible for computing matrix palettes that used by skin mesh rendering.
  37. * @js NA
  38. * @lua NA
  39. */
  40. class CC_DLL MeshSkin: public Ref
  41. {
  42. friend class Mesh;
  43. public:
  44. /**create a new meshskin if do not want to share meshskin*/
  45. static MeshSkin* create(Skeleton3D* skeleton, const std::string& filename, const std::string& name);
  46. static MeshSkin* create(Skeleton3D* skeleton, const std::vector<std::string>& boneNames, const std::vector<Mat4>& invBindPose);
  47. /**get total bone count, skin bone + node bone*/
  48. ssize_t getBoneCount() const;
  49. /**get bone*/
  50. Bone3D* getBoneByIndex(unsigned int index) const;
  51. Bone3D* getBoneByName(const std::string& id) const;
  52. /**get bone index*/
  53. int getBoneIndex(Bone3D* bone) const;
  54. /**compute matrix palette used by gpu skin*/
  55. Vec4* getMatrixPalette();
  56. /**getSkinBoneCount() * 3*/
  57. ssize_t getMatrixPaletteSize() const;
  58. /**get root bone of the skin*/
  59. Bone3D* getRootBone() const;
  60. CC_CONSTRUCTOR_ACCESS:
  61. MeshSkin();
  62. ~MeshSkin();
  63. /**remove all bones*/
  64. void removeAllBones();
  65. /**add skin bone*/
  66. void addSkinBone(Bone3D* bone);
  67. /** get inverse bind pose */
  68. const Mat4& getInvBindPose(const Bone3D* bone);
  69. protected:
  70. Vector<Bone3D*> _skinBones; // bones with skin
  71. std::vector<Mat4> _invBindPoses; //inverse bind pose of bone
  72. Bone3D* _rootBone;
  73. Skeleton3D* _skeleton; //skeleton the skin referred
  74. // Pointer to the array of palette matrices.
  75. // This array is passed to the vertex shader as a uniform.
  76. // Each 4x3 row-wise matrix is represented as 3 Vec4's.
  77. // The number of Vec4's is (_skinBones.size() * 3).
  78. Vec4* _matrixPalette;
  79. };
  80. // end of 3d group
  81. /// @}
  82. NS_CC_END
  83. #endif // __CCSKIN_H__