123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //
- // RedSlotBakeModel.hpp
- // empty2dx-desktop
- //
- // Created by Liang zhong on 2022/11/5.
- //
- #ifndef RedSlotBakeModel_h
- #define RedSlotBakeModel_h
- #include <stdio.h>
- #include "cocos2d.h"
- using namespace cocos2d;
- struct BAKE_POS_INT {
- short xPos;
- short yPos;
- };
- struct BKAE_FRAME_INFO {
- unsigned char texture;
- unsigned char blend;
- short color;
- short alpha;
- unsigned char uv;
- unsigned char indices;
- short vert;
- short skipFrameCount; //播放到当天跳过多少帧,主要是顶点偏移数组需要用这个来维护指针
- };
- struct BKAE_FRAME_PLAY {
- short texture;
- short blend;
- short color;
- short alpha;
- short uv;
- short indices;
- short vert;
- short skipFrameCount; //播放到当天跳过多少帧,主要是顶点偏移数组需要用这个来维护指针
- int vertMapIndex = -1;//用于记录在BakeNode中绘制时候存储的_VertArr的什么位置
- bool hasAttachNode; //记录是否有AttachNode
- bool hasOnceUpdate; //是否更新过一次,如果跟新过一次,很多不变数据就不需要更新了,比如color,uv等
- std::string slotName;
- Color4B currentFrameColor; //临时存储当前颜色
- std::vector<Tex2F>* currentFrameUV;//临时存储当前UV
- cocos2d::TrianglesCommand::Triangles triangles;//临时存储当前Triangles
- // 构造函数
- BKAE_FRAME_PLAY() :
- texture(0),
- blend(0),
- color(0),
- alpha(0),
- uv(0),
- indices(0),
- vert(0),
- vertMapIndex(-1),
- hasAttachNode(false),
- hasOnceUpdate(false),
- skipFrameCount(0),
- slotName(""),
- currentFrameColor(Color4B::WHITE),
- currentFrameUV(),
- triangles()
- {
- // 初始化 triangles 结构体的成员变量
- triangles.verts = nullptr;
- triangles.indices = nullptr;
- triangles.vertCount = 0;
- triangles.indexCount = 0;
- }
- };
- // 定义枚举类型color_set1
- enum frameType {frame_skip,frame_texture,frame_blend, frame_Color, frame_alpha, frame_uv, frame_indices,frame_vert};
- class RedSlotBakeModel
- {
- public:
- RedSlotBakeModel(std::string aSlotName,int aSlotIndex);
- void startBakeOneFrame();
- void bakeFrameSkip();
- void bakeFrameInfo(std::string& aAttachmentName,cocos2d::Texture2D* aTexture,BlendFunc aBlendFunc,cocos2d::TrianglesCommand::Triangles aTriangles);
-
- void finishBake();
- bool isBakeFinish();
- bool slotShoudBeDrawSlot();
-
- bool isUVChange(int aCurrentFrame);
- bool getFrameSkip(int aCurrentFrame);
- void setFrameSkip(int aCurrentFrame,BKAE_FRAME_PLAY& aFrameInfo);
- //纹理相关
- cocos2d::Texture2D* getTexture(int aCurrentFrame);
- //混合模式相关
- BlendFunc& getBlendFunc(int aCurrentFrame);
- //顶点相关
- void getTriangles(int aCurrentFrame,BKAE_FRAME_PLAY& aFrameInfo);
- void getTriangles(int aCurrentFrame,BKAE_FRAME_PLAY& aFrameInfo,const Point& offSet,float dis,V3F_C4B_T2F *beginVert,bool merge);
-
- void initBKAE_FRAME_PLAY(BKAE_FRAME_PLAY& aFrameInfo);
- const std::string& getSlotName();
- const int getSlotIndex();
- void setSlotName(const std::string& aSlotName);
- void setSlotIndex(int aSlotIndex);
-
- int getVertCount();
-
- int getMaxXPos();
- int getMaxYPos();
- int getMinXPos();
- int getMinYPos();
-
- void setMaxXPos(int pos);
- void setMaxYPos(int pos);
- void setMinXPos(int pos);
- void setMinYPos(int pos);
-
- const std::vector<std::vector<BAKE_POS_INT>>& getPosArray();
- void addPosArray(const std::vector<BAKE_POS_INT>& aPosArray);
-
- const std::vector<BlendFunc>& getBlendFuncArray();
- void addBlendFuncToArray(const BlendFunc& blendFunc);
-
- const std::vector<Color3B>& getColorArray();
- void addColorToArray(const Color3B& color);
-
- const std::vector<GLubyte>& getAlphaArray();
- void addAlphaToArray(GLubyte Alpha);
-
- const std::vector<std::vector<Tex2F>>& getUvArray();
- void addUvArray(const std::vector<Tex2F>& aUvArray);
-
- const std::vector<std::vector<unsigned short>>& getIndicesArray();
- void addIndicesArray(const std::vector<unsigned short>& aIndicesArray);
-
- const std::vector<GLubyte>& getFrameChangeArr();
- void addFrameChangeToArr(GLubyte aFrameChange);
-
- const std::vector<cocos2d::Texture2D*>& getTextureArray();
- void addTextureToArray(cocos2d::Texture2D* texture);
-
- void initBakeFrameInfos();
-
-
- private:
- bool shoudBeDrawSlot = true;//slot是否应该被绘制,如果纹理,顶点,颜色等数组都为空,这个slot其实没有绘制的必要
- bool isSpineBakeFinish = false;
- std::vector<BKAE_FRAME_INFO> bakeFrameInfos; //将frameChangeArr扩展成程序方便读取的数据
- int colorArraySize; //加快性能用,这样不需要反复计算Size,同时对于始终没变的东西不需要反复更新
- int alphaArraySize;
- int uvArraySize;
- int posArraySize;
- int blendFuncArraySize;
- int indicesArraySize;
- int textureArraySize;
-
-
- bool isPosArrayChangeOnlySlot = false; //true代表当前角色是仅有顶点位移,这个是绝大部分Slot
- cocos2d::Texture2D* firstTexture = nullptr;//isPosArrayChangeOnlySlot=true的时候,每次获取纹理就返回这个就好,这样性能高
- BlendFunc firstBlendFunc;//isPosArrayChangeOnlySlot=true的时候,每次获取纹理就返回这个就好,这样性能高
- //*******************************************需要protolBuffer存**************************************
- std::string slotName;
- int slotIndex = -1;
- std::vector<std::vector<BAKE_POS_INT>> posArray;//记录每个顶点的偏移
- std::vector<BlendFunc> blendFuncArray;//记录每个blend的变化
- std::vector<Color3B> colorArray;//记录每个Color的变化
- std::vector<GLubyte> alphaArray;//记录每个alpha的变化
- std::vector<std::vector<Tex2F>> uvArray;//记录每个UV的变化
- std::vector<std::vector<unsigned short>> indicesArray;//记录每个indices的变化
- std::vector<GLubyte> frameChangeArr; //记录每帧哪些属性发生了改变,运行时通过这个来移动每个数组的index指针
- int maxXPos = 0;
- int maxYPos = 0;
- int minXPos = 0;
- int minYPos = 0;
-
- std::vector<cocos2d::Texture2D*> textureArray;//记录每个纹理的变化
- //***********************************************************************************************
- std::string currentBakeAttachmentName = "";
- bool hasChangeAttachmentName = true;
-
-
-
-
- void _setTexture(cocos2d::Texture2D* aTexture);
- void _setBlendFunc(BlendFunc aBlendFunc);
- void _setTriangles(cocos2d::TrianglesCommand::Triangles aTriangles);
- bool _uvVectIsEqual(std::vector<Tex2F> a,std::vector<Tex2F> b);
- bool _indicesVectIsEqual(unsigned short *a,int aCount,std::vector<unsigned short> b);
- bool _vertVectIsEqual(std::vector<BAKE_POS_INT> &a,std::vector<BAKE_POS_INT> &b);
-
- };
- #endif /* RedSlotBakeModel_h */
|