CCSkeletonNode.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /****************************************************************************
  2. Copyright (c) 2015-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CCSKELETONNODE_H__
  21. #define __CCSKELETONNODE_H__
  22. #include "editor-support/cocostudio/ActionTimeline/CCTimelineMacro.h"
  23. #include "renderer/CCRenderer.h"
  24. #include "editor-support/cocostudio/CocosStudioExport.h"
  25. #include "base/CCMap.h"
  26. #include "editor-support/cocostudio/ActionTimeline/CCBoneNode.h"
  27. NS_TIMELINE_BEGIN
  28. class CC_STUDIO_DLL SkeletonNode : public BoneNode
  29. {
  30. friend class BoneNode;
  31. public:
  32. static SkeletonNode* create();
  33. /**
  34. *get bonenode in skeleton node by bone name
  35. */
  36. BoneNode* getBoneNode(const std::string& boneName);
  37. /**
  38. *get All bones in this skeleton, <bone's name, BoneNode>
  39. */
  40. const cocos2d::Map<std::string, BoneNode*>& getAllSubBonesMap() const;
  41. /**
  42. *@brief: change displays
  43. *@param: boneSkinNameMap, map <name of bone, name of skin to display which added to bone>
  44. */
  45. void changeSkins(const std::map<std::string, std::string>& boneSkinNameMap);
  46. /**
  47. *@brief: change displays
  48. *@param: skinGroupName have
  49. */
  50. void changeSkins(const std::string& skinGroupName);
  51. /**
  52. *@brief: add a boneSkinNameMap as a SkinGroup named groupName
  53. *@param: groupName, key
  54. *@param: boneSkinNameMap, map <name of bone, name of skin to display which added to bone>
  55. */
  56. void addSkinGroup(std::string groupName, std::map<std::string, std::string> boneSkinNameMap);
  57. cocos2d::Rect getBoundingBox() const override;
  58. CC_CONSTRUCTOR_ACCESS:
  59. SkeletonNode();
  60. virtual ~SkeletonNode();
  61. virtual bool init() override;
  62. protected:
  63. virtual void updateVertices() override;
  64. virtual void updateColor() override;
  65. virtual void visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags) override;
  66. virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
  67. virtual void onDraw(const cocos2d::Mat4 &transform, uint32_t flags) override;
  68. protected:
  69. cocos2d::Map<std::string, BoneNode*> _subBonesMap;
  70. private:
  71. cocos2d::Vec2 _squareVertices[8];
  72. cocos2d::Color4F _squareColors[8];
  73. cocos2d::Vec3 _noMVPVertices[8];
  74. std::map<std::string, std::map<std::string, std::string> > _skinGroupMap; // map< suit name, map< bone name, skin name> >
  75. CC_DISALLOW_COPY_AND_ASSIGN(SkeletonNode);
  76. void checkSubBonesDirty();
  77. // for draw skins as ordered bones' local z
  78. cocos2d::Vector<BoneNode*> _subOrderedAllBones;
  79. void updateOrderedAllbones();
  80. void sortOrderedAllBones();
  81. // for batch draw sub bones
  82. bool _subBonesDirty;
  83. bool _subBonesOrderDirty;
  84. std::vector<cocos2d::Vec3> _batchedBoneVetices;
  85. std::vector<cocos2d::Color4F> _batchedBoneColors;
  86. int _batchedVeticesCount;
  87. cocos2d::CustomCommand _batchBoneCommand;
  88. void batchDrawAllSubBones(const cocos2d::Mat4 &transform);
  89. };
  90. NS_TIMELINE_END
  91. #endif //__CCSKELETONNODE_H__