RedAnimationBakeModel.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // RedSpineBakeModel.hpp
  3. // empty2dx-desktop
  4. //
  5. // Created by Liang zhong on 2022/11/5.
  6. //
  7. #ifndef RedAnimationBakeModel_h
  8. #define RedAnimationBakeModel_h
  9. #include <stdio.h>
  10. #include "cocos2d.h"
  11. #include "RedSlotBakeModel.h"
  12. #include <spine/spine.h>
  13. struct DrawOrderMD {
  14. int frame;
  15. int arrIndex;
  16. };
  17. struct EventMD{
  18. int frame;
  19. std::vector<std::string> eventNames;
  20. };
  21. class RedAnimationBakeModel
  22. {
  23. public:
  24. RedAnimationBakeModel();
  25. virtual ~RedAnimationBakeModel();
  26. RedAnimationBakeModel(const std::string aFileName,const std::string& aAnimateName);
  27. RedSlotBakeModel* getSlotFromKey(int akey);//快速查询
  28. RedSlotBakeModel* findSlotFromKey(int akey);//慢速查询,在绘制的时候千万别用,主要用来mix的时候判断合法性的
  29. RedSlotBakeModel* getSlotByDrawOrder(int aIndex,int aFrameNum,int &aCurrentDrawOrderIndex);
  30. void handleEventByFrame(Node* target, std::function<void(std::string)> cb); //处理当前帧的事件 目前只是wwise事件
  31. void addSlotByName(RedSlotBakeModel *aSlot);
  32. virtual int getSlotCount();
  33. const std::vector<int>& getAllSlotKey();
  34. void setFileName(const std::string& aFileName);
  35. const std::string& getFileName();
  36. int getTotalBakeFrame();
  37. void setTotalBakeFrame(int atotalBakeFrame);
  38. void setLastDrawOverTime(float aLastDrawOverTime);
  39. float getLastDrawOverTime();
  40. void setCurrentFrameRate(int aRate);
  41. int getCurrentFrameRate();
  42. void setAimationName(const std::string& animName);
  43. const std::string& getAimationName();
  44. virtual bool isMixAnimation();
  45. //bounds
  46. void setMaxXPos(int aMaxXPos);
  47. int getMaxXPos();
  48. void setMaxYPos(int aMaxYPos);
  49. int getMaxYPos();
  50. void setMinXPos(int aMinXPos);
  51. int getMinXPos();
  52. void setMinYPos(int aMinYPos);
  53. int getMinYPos();
  54. void setLeftBottom(const Vec2& pos);
  55. const Vec2& getLeftBottom();
  56. void setRightTopPos(const Vec2& pos);
  57. const Vec2& getRightTopPos();
  58. void setLeftBottomSubSizePos(const Vec2& pos);
  59. const Vec2& getLeftBottomSubSizePos();
  60. void setRightTopSubSizePos(const Vec2& pos);
  61. const Vec2& getRightTopSubSizePos();
  62. //SlotArr
  63. void setSlotArr(const std::map<int,RedSlotBakeModel*>& aSlotArr);
  64. const std::map<int,RedSlotBakeModel*>& getSlotArr();
  65. //DrawOrderArr
  66. void setDrawOrderArr(std::vector<std::vector<int>>& aDrawOrderArr);
  67. const std::vector<std::vector<int>>& getDrawOrderArr();
  68. //DrawOrderArrIndex
  69. void setDrawOrderArrIndex(const std::vector<DrawOrderMD>& aDrawOrderArrIndex);
  70. const std::vector<DrawOrderMD>& getDrawOrderArrIndex();
  71. //EventArr
  72. void setEventArr(const std::vector<EventMD>& aEventArr);
  73. const std::vector<EventMD>& getEventArr();
  74. //boneAttachs
  75. void setBoneAttachs(std::map<std::string,std::vector<Point>>& aBoneAttachs);
  76. const std::map<std::string,std::vector<Point>>& getBoneAttachs();
  77. std::vector<std::string> getAllgetBoneAttachs();
  78. //bake时候专用的
  79. void setBeginLastDraw();
  80. bool isBeginLastDraw();
  81. void setBakeFinish(float alastDrawOverTime);
  82. bool isBakeFinish();
  83. void drawOneFrame();
  84. void updateDrawOrder(spine::Vector<spine::Slot *> &aDrawList);
  85. void addEventData(std::string eventName);//增加一个需要被记录的事件
  86. void addboneAttachNames(std::string aName);//增加一个需要被记录的外接连动bone的名字
  87. const std::vector<std::string>& getAllboneAttachNames();
  88. void bakeAModePointBeginPos(std::string aName,Point aPoint);
  89. void bakeAModePoint(std::string aName,Point aPoint);
  90. virtual const Point& getABakeModePoint(std::string aName,int aFrame);
  91. const Point& getABakeModePoint(int aIndex,int aFrame);
  92. int getBoneAttachsSearchIndex(std::string aKey);//获取指定Key的BoneAttachs在数组的什么位置
  93. protected:
  94. bool isSpineBakeFinish = false;
  95. bool beginLastDraw = false; //update会先于draw调用,最后一个update后还有一个draw需要记录下来。
  96. std::vector<std::string> boneAttachNames;//所有需要被记录的外接bone的名字
  97. std::map<std::string,Point> boneAttachsBeginPos;//所有需要被记录的外接bone的初始位置
  98. std::vector<RedSlotBakeModel *> slotArrVector; //提高查询性能专用,slotArr的Vector版
  99. int slotArrSize = 0; //提高查询性能专用,减少slotArr.size的调用
  100. int drawOrderArrIndexSize = 0;
  101. std::vector<std::vector<Point>> boneAttachsVector;//记录外接连动BakeNode的位子偏移,因为我们是用bone来代替外接模块的联动,加快性能用
  102. //*******************************************需要protolBuffer存**************************************
  103. std::string fileName;
  104. std::string animateName;
  105. std::map<std::string,std::vector<Point>> boneAttachs;//记录外接连动BakeNode的位子偏移,因为我们是用bone来代替外接模块的联动
  106. std::map<int,RedSlotBakeModel *> slotArr;//记录所有Slot
  107. std::vector<std::vector<int>> drawOrderArr;//记录slot所有Draworder变化
  108. std::vector<DrawOrderMD> drawOrderArrIndex; //记录哪帧Draworder发生了变化
  109. std::vector<EventMD> eventArr; //记录哪帧有事件信息 主要用来播放wwise事件的
  110. int totalBakeFrame = 0;
  111. float lastDrawOverTime = 0.0; //最后一个draw的实际长度,因为烘培的帧率和spine帧率不一定相等,所以最后一帧不一定能对齐
  112. int maxXPos = 0;
  113. int maxYPos = 0;
  114. int minXPos = 0;
  115. int minYPos = 0;
  116. cocos2d::Vec2 leftBottom;
  117. cocos2d::Vec2 rightTopPos;
  118. cocos2d::Vec2 leftBottomSubSizePos; //方便出屏幕判断,预先将leftBottom里面去加上Size,因为leftBottom出界需要判断自己右上角,减少之后的计算
  119. cocos2d::Vec2 rightTopSubSizePos; //方便出屏幕判断,预先将Rightop里面去减去Size,因为Righttop出界需要判断自己左下角,减少之后的计算
  120. int currentFrameRate = 30; //当前帧率,默认30
  121. //***********************************************************************************************
  122. };
  123. #endif /* RedSpineBakeModel_h */