123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- // RedSpineBakeModel.hpp
- // empty2dx-desktop
- //
- // Created by Liang zhong on 2022/11/5.
- //
- #ifndef RedAnimationBakeModel_h
- #define RedAnimationBakeModel_h
- #include <stdio.h>
- #include "cocos2d.h"
- #include "RedSlotBakeModel.h"
- #include <spine/spine.h>
- struct DrawOrderMD {
- int frame;
- int arrIndex;
- };
- struct EventMD{
- int frame;
- std::vector<std::string> eventNames;
- };
- class RedAnimationBakeModel
- {
- public:
- RedAnimationBakeModel();
- virtual ~RedAnimationBakeModel();
- RedAnimationBakeModel(const std::string aFileName,const std::string& aAnimateName);
- RedSlotBakeModel* getSlotFromKey(int akey);//快速查询
- RedSlotBakeModel* findSlotFromKey(int akey);//慢速查询,在绘制的时候千万别用,主要用来mix的时候判断合法性的
- RedSlotBakeModel* getSlotByDrawOrder(int aIndex,int aFrameNum,int &aCurrentDrawOrderIndex);
- void handleEventByFrame(Node* target, std::function<void(std::string)> cb); //处理当前帧的事件 目前只是wwise事件
-
- void addSlotByName(RedSlotBakeModel *aSlot);
- virtual int getSlotCount();
- const std::vector<int>& getAllSlotKey();
-
- void setFileName(const std::string& aFileName);
- const std::string& getFileName();
-
- int getTotalBakeFrame();
- void setTotalBakeFrame(int atotalBakeFrame);
-
- void setLastDrawOverTime(float aLastDrawOverTime);
- float getLastDrawOverTime();
-
- void setCurrentFrameRate(int aRate);
- int getCurrentFrameRate();
-
- void setAimationName(const std::string& animName);
- const std::string& getAimationName();
-
- virtual bool isMixAnimation();
-
- //bounds
- void setMaxXPos(int aMaxXPos);
- int getMaxXPos();
- void setMaxYPos(int aMaxYPos);
- int getMaxYPos();
- void setMinXPos(int aMinXPos);
- int getMinXPos();
- void setMinYPos(int aMinYPos);
- int getMinYPos();
-
- void setLeftBottom(const Vec2& pos);
- const Vec2& getLeftBottom();
- void setRightTopPos(const Vec2& pos);
- const Vec2& getRightTopPos();
-
- void setLeftBottomSubSizePos(const Vec2& pos);
- const Vec2& getLeftBottomSubSizePos();
- void setRightTopSubSizePos(const Vec2& pos);
- const Vec2& getRightTopSubSizePos();
- //SlotArr
- void setSlotArr(const std::map<int,RedSlotBakeModel*>& aSlotArr);
- const std::map<int,RedSlotBakeModel*>& getSlotArr();
- //DrawOrderArr
- void setDrawOrderArr(std::vector<std::vector<int>>& aDrawOrderArr);
- const std::vector<std::vector<int>>& getDrawOrderArr();
- //DrawOrderArrIndex
- void setDrawOrderArrIndex(const std::vector<DrawOrderMD>& aDrawOrderArrIndex);
- const std::vector<DrawOrderMD>& getDrawOrderArrIndex();
- //EventArr
- void setEventArr(const std::vector<EventMD>& aEventArr);
- const std::vector<EventMD>& getEventArr();
-
- //boneAttachs
- void setBoneAttachs(std::map<std::string,std::vector<Point>>& aBoneAttachs);
- const std::map<std::string,std::vector<Point>>& getBoneAttachs();
- std::vector<std::string> getAllgetBoneAttachs();
- //bake时候专用的
- void setBeginLastDraw();
- bool isBeginLastDraw();
- void setBakeFinish(float alastDrawOverTime);
- bool isBakeFinish();
- void drawOneFrame();
- void updateDrawOrder(spine::Vector<spine::Slot *> &aDrawList);
- void addEventData(std::string eventName);//增加一个需要被记录的事件
- void addboneAttachNames(std::string aName);//增加一个需要被记录的外接连动bone的名字
- const std::vector<std::string>& getAllboneAttachNames();
- void bakeAModePointBeginPos(std::string aName,Point aPoint);
- void bakeAModePoint(std::string aName,Point aPoint);
-
- virtual const Point& getABakeModePoint(std::string aName,int aFrame);
- const Point& getABakeModePoint(int aIndex,int aFrame);
- int getBoneAttachsSearchIndex(std::string aKey);//获取指定Key的BoneAttachs在数组的什么位置
-
- protected:
- bool isSpineBakeFinish = false;
- bool beginLastDraw = false; //update会先于draw调用,最后一个update后还有一个draw需要记录下来。
- std::vector<std::string> boneAttachNames;//所有需要被记录的外接bone的名字
- std::map<std::string,Point> boneAttachsBeginPos;//所有需要被记录的外接bone的初始位置
-
- std::vector<RedSlotBakeModel *> slotArrVector; //提高查询性能专用,slotArr的Vector版
- int slotArrSize = 0; //提高查询性能专用,减少slotArr.size的调用
- int drawOrderArrIndexSize = 0;
- std::vector<std::vector<Point>> boneAttachsVector;//记录外接连动BakeNode的位子偏移,因为我们是用bone来代替外接模块的联动,加快性能用
-
- //*******************************************需要protolBuffer存**************************************
- std::string fileName;
- std::string animateName;
-
- std::map<std::string,std::vector<Point>> boneAttachs;//记录外接连动BakeNode的位子偏移,因为我们是用bone来代替外接模块的联动
-
- std::map<int,RedSlotBakeModel *> slotArr;//记录所有Slot
- std::vector<std::vector<int>> drawOrderArr;//记录slot所有Draworder变化
- std::vector<DrawOrderMD> drawOrderArrIndex; //记录哪帧Draworder发生了变化
- std::vector<EventMD> eventArr; //记录哪帧有事件信息 主要用来播放wwise事件的
-
- int totalBakeFrame = 0;
- float lastDrawOverTime = 0.0; //最后一个draw的实际长度,因为烘培的帧率和spine帧率不一定相等,所以最后一帧不一定能对齐
-
- int maxXPos = 0;
- int maxYPos = 0;
- int minXPos = 0;
- int minYPos = 0;
-
- cocos2d::Vec2 leftBottom;
- cocos2d::Vec2 rightTopPos;
- cocos2d::Vec2 leftBottomSubSizePos; //方便出屏幕判断,预先将leftBottom里面去加上Size,因为leftBottom出界需要判断自己右上角,减少之后的计算
- cocos2d::Vec2 rightTopSubSizePos; //方便出屏幕判断,预先将Rightop里面去减去Size,因为Righttop出界需要判断自己左下角,减少之后的计算
- int currentFrameRate = 30; //当前帧率,默认30
- //***********************************************************************************************
- };
- #endif /* RedSpineBakeModel_h */
|