RedSlotBakeModel.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. //
  2. // RedSlotBakeModel.cpp
  3. // empty2dx-desktop
  4. //
  5. // Created by Liang zhong on 2022/11/5.
  6. //
  7. #include "RedSlotBakeModel.h"
  8. static GLubyte byteMap[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
  9. RedSlotBakeModel::RedSlotBakeModel(std::string aSlotName,int aSlotIndex){
  10. slotName = aSlotName;
  11. slotIndex = aSlotIndex;
  12. }
  13. void RedSlotBakeModel::finishBake(){
  14. isSpineBakeFinish = true;
  15. if(textureArray.size()==0){
  16. //如果没有纹理就不需要被绘制了
  17. shoudBeDrawSlot = false;
  18. }else{
  19. }
  20. initBakeFrameInfos();
  21. }
  22. void RedSlotBakeModel::initBKAE_FRAME_PLAY(BKAE_FRAME_PLAY& aFrameInfo){
  23. aFrameInfo.slotName = slotName;
  24. aFrameInfo.texture = 0;
  25. aFrameInfo.blend = 0;
  26. aFrameInfo.alpha = 0;
  27. aFrameInfo.color = 0;
  28. aFrameInfo.indices = 0;
  29. aFrameInfo.uv = 0;
  30. aFrameInfo.vert = 0;
  31. aFrameInfo.skipFrameCount = 0;
  32. aFrameInfo.hasOnceUpdate = false;
  33. aFrameInfo.hasAttachNode = false;
  34. aFrameInfo.vertMapIndex = -1;
  35. if (colorArray.size()==0) {
  36. aFrameInfo.currentFrameColor = Color4B(255,255,255,255);
  37. }else{
  38. Color3B& color = colorArray.at(0);
  39. aFrameInfo.currentFrameColor.r = color.r;
  40. aFrameInfo.currentFrameColor.g = color.g;
  41. aFrameInfo.currentFrameColor.b = color.b;
  42. }
  43. if (alphaArray.size()!=0) {
  44. aFrameInfo.currentFrameColor.a = alphaArray.at(0);
  45. }
  46. if(uvArray.size()!=0){
  47. std::vector<Tex2F> &currentFrameUV = uvArray[0];
  48. aFrameInfo.currentFrameUV = &currentFrameUV;
  49. }
  50. if(indicesArray.size()!=0){
  51. std::vector<unsigned short>& indicesVect = indicesArray.at(0);
  52. aFrameInfo.triangles.indexCount = (int)indicesVect.size();
  53. aFrameInfo.triangles.indices = indicesVect.data();
  54. }
  55. aFrameInfo.triangles.vertCount = 0;
  56. if (aFrameInfo.triangles.verts!=nullptr) {
  57. delete[] aFrameInfo.triangles.verts;
  58. }
  59. aFrameInfo.triangles.verts = nullptr;
  60. }
  61. bool RedSlotBakeModel::isBakeFinish(){
  62. return isSpineBakeFinish;
  63. }
  64. bool RedSlotBakeModel::slotShoudBeDrawSlot(){
  65. return shoudBeDrawSlot;
  66. }
  67. void RedSlotBakeModel::initBakeFrameInfos(){
  68. for (int i =0; i<frameChangeArr.size(); i++) {
  69. BKAE_FRAME_INFO info = {0};
  70. BKAE_FRAME_INFO preInfo = {0};
  71. if (i>0) {
  72. preInfo = bakeFrameInfos[i-1];
  73. }
  74. GLubyte frameInit = frameChangeArr.at(i);
  75. GLubyte tmp1 = (frameInit>>frameType::frame_skip)&0x01;
  76. if (tmp1==0x01) {
  77. info.skipFrameCount = preInfo.skipFrameCount + 1;
  78. }else{
  79. info.skipFrameCount = preInfo.skipFrameCount;
  80. }
  81. tmp1 = (frameInit>>frameType::frame_texture)&0x01;
  82. if (tmp1==0x01) {
  83. info.texture = preInfo.texture + 1;
  84. }else{
  85. info.texture = preInfo.texture;
  86. }
  87. tmp1 = (frameInit>>frameType::frame_blend)&0x01;
  88. if (tmp1==0x01) {
  89. info.blend = preInfo.blend + 1;
  90. }else{
  91. info.blend = preInfo.blend;
  92. }
  93. tmp1 = (frameInit>>frameType::frame_Color)&0x01;
  94. if (tmp1==0x01) {
  95. info.color = preInfo.color + 1;
  96. }else{
  97. info.color = preInfo.color;
  98. }
  99. tmp1 = (frameInit>>frameType::frame_alpha)&0x01;
  100. if (tmp1==0x01) {
  101. info.alpha = preInfo.alpha + 1;
  102. }else{
  103. info.alpha = preInfo.alpha;
  104. }
  105. tmp1 = (frameInit>>frameType::frame_uv)&0x01;
  106. if (tmp1==0x01) {
  107. info.uv = preInfo.uv + 1;
  108. }else{
  109. info.uv = preInfo.uv;
  110. }
  111. tmp1 = (frameInit>>frameType::frame_indices)&0x01;
  112. if (tmp1==0x01) {
  113. info.indices = preInfo.indices + 1;
  114. }else{
  115. info.indices = preInfo.indices;
  116. }
  117. tmp1 = (frameInit>>frameType::frame_vert)&0x01;
  118. if (tmp1==0x01) {
  119. info.vert = preInfo.vert + 1;
  120. }else{
  121. info.vert = preInfo.vert;
  122. }
  123. bakeFrameInfos.push_back(info);
  124. }
  125. //加快性能用,这样不需要反复计算Size,同时对于始终没变的东西不需要反复更新
  126. colorArraySize = (int)colorArray.size();
  127. alphaArraySize = (int)alphaArray.size();
  128. uvArraySize = (int)uvArray.size();
  129. posArraySize = (int)posArray.size();
  130. blendFuncArraySize = (int)blendFuncArray.size();
  131. indicesArraySize = (int)indicesArray.size();
  132. textureArraySize = (int)textureArray.size();
  133. if (colorArraySize==1&&alphaArraySize==1&&uvArraySize==1&&blendFuncArraySize==1&&indicesArraySize==1) {
  134. isPosArrayChangeOnlySlot = true;
  135. }
  136. if(textureArraySize>0){
  137. firstTexture = textureArray[0];
  138. }
  139. if (blendFuncArraySize>0) {
  140. firstBlendFunc = blendFuncArray[0];
  141. }
  142. }
  143. bool RedSlotBakeModel::isUVChange(int aCurrentFrame){
  144. if (uvArraySize==1) {
  145. return false;
  146. }
  147. if (aCurrentFrame<2) {
  148. return false;
  149. }
  150. if (bakeFrameInfos[aCurrentFrame-2].uv!=bakeFrameInfos[aCurrentFrame-1].uv) {
  151. return true;
  152. }
  153. return false;
  154. }
  155. bool RedSlotBakeModel::getFrameSkip(int aCurrentFrame){
  156. GLubyte frameInit = frameChangeArr[aCurrentFrame-1];
  157. GLubyte tmp1 = (frameInit>>frameType::frame_skip)&0x01;
  158. if (tmp1==0x01) {
  159. return true;
  160. }
  161. return false;
  162. }
  163. void RedSlotBakeModel::setFrameSkip(int aCurrentFrame,BKAE_FRAME_PLAY& aFrameInfo){
  164. GLubyte frameInit = frameChangeArr.at(aCurrentFrame-1);
  165. GLubyte tmp1 = (frameInit>>frameType::frame_skip)&0x01;
  166. if (tmp1==0x01) {
  167. aFrameInfo.skipFrameCount = MIN(aFrameInfo.skipFrameCount+1, frameChangeArr.size()-1);
  168. }
  169. }
  170. cocos2d::Texture2D* RedSlotBakeModel::getTexture(int aCurrentFrame){
  171. if (textureArraySize) {
  172. return firstTexture;
  173. }
  174. cocos2d::Texture2D* aTexture = textureArray[bakeFrameInfos[aCurrentFrame-1].texture];
  175. return aTexture;
  176. }
  177. BlendFunc& RedSlotBakeModel::getBlendFunc(int aCurrentFrame){
  178. if (blendFuncArraySize==1) {
  179. return firstBlendFunc;
  180. }
  181. return blendFuncArray[bakeFrameInfos[aCurrentFrame-1].blend];
  182. }
  183. void RedSlotBakeModel::getTriangles(int aCurrentFrame,BKAE_FRAME_PLAY& aFrameInfo){
  184. BKAE_FRAME_INFO &bInfo = bakeFrameInfos[aCurrentFrame-1];
  185. //读取烘培的顶点偏移量
  186. std::vector<BAKE_POS_INT> &bpi_Arr = posArray[bInfo.vert];
  187. int bpiSize = (int)bpi_Arr.size();
  188. if (aFrameInfo.triangles.vertCount!=bpiSize) {
  189. if (aFrameInfo.triangles.verts != nullptr) {
  190. delete[] aFrameInfo.triangles.verts;
  191. }
  192. aFrameInfo.triangles.verts = new V3F_C4B_T2F[bpiSize];
  193. aFrameInfo.triangles.vertCount = bpiSize;//改这个地方,如果顶线数遍了,再申请数据
  194. aFrameInfo.hasOnceUpdate = false;
  195. }
  196. for (int aa = 0; aa<bpiSize; aa++) {
  197. V3F_C4B_T2F &tpv = aFrameInfo.triangles.verts[aa];
  198. BAKE_POS_INT &bpi = bpi_Arr[aa];
  199. tpv.vertices.x = bpi.xPos;
  200. tpv.vertices.y = bpi.yPos;
  201. }
  202. //如果uvArraySize只需要更新一次就好
  203. if (aFrameInfo.hasOnceUpdate==false||uvArraySize>1) {
  204. //读取烘培的UV
  205. std::vector<Tex2F> &currentFrameUV = uvArray[bInfo.uv];
  206. aFrameInfo.currentFrameUV = &currentFrameUV;
  207. // aFrameInfo.currentFrameUV = uvArray[bInfo.uv];
  208. for (int aa = 0; aa<bpiSize; aa++) {
  209. aFrameInfo.triangles.verts[aa].texCoords = (*aFrameInfo.currentFrameUV)[aa];
  210. }
  211. }
  212. if (aFrameInfo.hasOnceUpdate==false||indicesArraySize>1) {
  213. //读取烘培的Indices
  214. std::vector<unsigned short>& indicesVect = indicesArray[bInfo.indices];
  215. aFrameInfo.triangles.indexCount = (int)indicesVect.size();
  216. aFrameInfo.triangles.indices = indicesVect.data();
  217. }
  218. if (aFrameInfo.hasOnceUpdate==false||alphaArraySize>1||colorArraySize>1) {
  219. //读取烘培的Color
  220. Color3B& color = colorArray[bInfo.color];
  221. aFrameInfo.currentFrameColor.r = color.r;
  222. aFrameInfo.currentFrameColor.g = color.g;
  223. aFrameInfo.currentFrameColor.b = color.b;
  224. //读取烘培的Aphla
  225. aFrameInfo.currentFrameColor.a = alphaArray[bInfo.alpha];
  226. for (int aa = 0; aa<bpiSize; aa++) {
  227. aFrameInfo.triangles.verts[aa].colors = aFrameInfo.currentFrameColor;
  228. }
  229. }
  230. aFrameInfo.hasOnceUpdate = true;
  231. }
  232. void RedSlotBakeModel::startBakeOneFrame(){
  233. GLubyte frameInit = 0x00;
  234. if(frameChangeArr.size()==0){
  235. // frameInit = 0xFF;//第一帧所有都要变,除了下面这个frameSkip,如果需要变也应该由之后调用的bakeFrameSkip来调用
  236. GLubyte tt =~byteMap[frameType::frame_skip];
  237. frameInit = frameInit&tt;
  238. }
  239. frameChangeArr.push_back(frameInit);
  240. }
  241. void RedSlotBakeModel::bakeFrameSkip(){
  242. GLubyte& lastframe = frameChangeArr.at(frameChangeArr.size()-1);
  243. lastframe = lastframe|byteMap[frameType::frame_skip];
  244. }
  245. void RedSlotBakeModel::bakeFrameInfo(std::string& aAttachmentName,cocos2d::Texture2D* aTexture,BlendFunc aBlendFunc,cocos2d::TrianglesCommand::Triangles aTriangles){
  246. hasChangeAttachmentName = false;
  247. if(aAttachmentName!=currentBakeAttachmentName){
  248. hasChangeAttachmentName = true;
  249. currentBakeAttachmentName = aAttachmentName;
  250. }
  251. if (hasChangeAttachmentName) {
  252. _setTexture(aTexture);
  253. }
  254. _setBlendFunc(aBlendFunc);
  255. _setTriangles(aTriangles);
  256. }
  257. void RedSlotBakeModel::_setTexture(cocos2d::Texture2D* aTexture){
  258. if(aTexture == nullptr) {
  259. CCASSERT(false, "不要设置空纹理!");
  260. }
  261. if (textureArray.size()==0) {
  262. textureArray.push_back(aTexture);
  263. }else{
  264. cocos2d::Texture2D* lastTexture = textureArray.at(textureArray.size()-1);
  265. if (lastTexture!=aTexture) {
  266. textureArray.push_back(aTexture);
  267. GLubyte& lastframe = frameChangeArr.at(frameChangeArr.size()-1);
  268. lastframe = lastframe|byteMap[frameType::frame_texture];
  269. }
  270. }
  271. }
  272. void RedSlotBakeModel::_setBlendFunc(BlendFunc aBlendFunc){
  273. if (blendFuncArray.size()==0) {
  274. blendFuncArray.push_back(aBlendFunc);
  275. }else{
  276. BlendFunc lastBlend = blendFuncArray.at(blendFuncArray.size()-1);
  277. if (lastBlend!=aBlendFunc) {
  278. blendFuncArray.push_back(aBlendFunc);
  279. GLubyte& lastframe = frameChangeArr.at(frameChangeArr.size()-1);
  280. lastframe = lastframe|byteMap[frameType::frame_blend];
  281. }
  282. }
  283. }
  284. void RedSlotBakeModel::_setTriangles(cocos2d::TrianglesCommand::Triangles aTriangles){
  285. //烘培顶点位移
  286. std::vector<BAKE_POS_INT> posVect;
  287. for (int i = 0; i<aTriangles.vertCount; i++) {
  288. BAKE_POS_INT bp;
  289. bp.xPos = aTriangles.verts[i].vertices.x;
  290. bp.yPos = aTriangles.verts[i].vertices.y;
  291. maxXPos = MAX(maxXPos, bp.xPos);
  292. maxYPos = MAX(maxYPos, bp.yPos);
  293. minXPos = MIN(minXPos, bp.xPos);
  294. minYPos = MIN(minYPos, bp.yPos);
  295. posVect.push_back(bp);
  296. }
  297. if (posArray.size()==0) {
  298. posArray.push_back(posVect);
  299. }else{
  300. std::vector<BAKE_POS_INT> pre = posArray[posArray.size()-1];
  301. if (_vertVectIsEqual(posVect, pre)==false) {
  302. posArray.push_back(posVect);
  303. GLubyte& lastframe = frameChangeArr.at(frameChangeArr.size()-1);
  304. lastframe = lastframe|byteMap[frameType::frame_vert];
  305. }
  306. }
  307. //烘培颜色变化
  308. if (colorArray.size()==0) {
  309. Color4B colors = aTriangles.verts[0].colors;
  310. colorArray.push_back(Color3B(colors.r, colors.g, colors.b));
  311. }else{
  312. Color4B colors = aTriangles.verts[0].colors;
  313. Color3B currentColor = Color3B(colors.r, colors.g, colors.b);
  314. Color3B lastColor = colorArray.at(colorArray.size()-1);
  315. if (lastColor.r!=currentColor.r||lastColor.g!=currentColor.g||lastColor.b!=currentColor.b) {
  316. colorArray.push_back(currentColor);
  317. GLubyte& lastframe = frameChangeArr.at(frameChangeArr.size()-1);
  318. lastframe = lastframe|byteMap[frameType::frame_Color];
  319. }
  320. }
  321. //烘培alpha变化
  322. if (alphaArray.size()==0) {
  323. Color4B colors = aTriangles.verts[0].colors;
  324. alphaArray.push_back(colors.a);
  325. }else{
  326. GLubyte currentAlpha = aTriangles.verts[0].colors.a;
  327. GLubyte lastAlpha = alphaArray.at(alphaArray.size()-1);
  328. if (currentAlpha!=lastAlpha) {
  329. alphaArray.push_back(currentAlpha);
  330. GLubyte& lastframe = frameChangeArr.at(frameChangeArr.size()-1);
  331. lastframe = lastframe|byteMap[frameType::frame_alpha];
  332. }
  333. }
  334. if (hasChangeAttachmentName) {
  335. //UV和顶点的变化必然伴随AttachmentName变化
  336. //烘培UV变化
  337. std::vector<Tex2F> uvVect;
  338. for (int i = 0; i<aTriangles.vertCount; i++) {
  339. Tex2F bp = aTriangles.verts[i].texCoords;
  340. uvVect.push_back(bp);
  341. }
  342. if (uvArray.size()==0) {
  343. uvArray.push_back(uvVect);
  344. }else{
  345. std::vector<Tex2F> lastUV = uvArray.at(uvArray.size()-1);
  346. if (_uvVectIsEqual(uvVect, lastUV)==false) {
  347. uvArray.push_back(uvVect);
  348. GLubyte& lastframe = frameChangeArr.at(frameChangeArr.size()-1);
  349. lastframe = lastframe|byteMap[frameType::frame_uv];
  350. }
  351. }
  352. //烘培顶点顺序数组
  353. if (indicesArray.size()==0) {
  354. std::vector<unsigned short> indicesVect;
  355. for (int i = 0; i<aTriangles.indexCount; i++) {
  356. unsigned short ind = aTriangles.indices[i];
  357. indicesVect.push_back(ind);
  358. }
  359. indicesArray.push_back(indicesVect);
  360. }else{
  361. std::vector<unsigned short> lastIndices = indicesArray.at(indicesArray.size()-1);
  362. if (_indicesVectIsEqual(aTriangles.indices,aTriangles.indexCount, lastIndices)==false) {
  363. std::vector<unsigned short> indicesVect;
  364. for (int i = 0; i<aTriangles.indexCount; i++) {
  365. unsigned short ind = aTriangles.indices[i];
  366. indicesVect.push_back(ind);
  367. }
  368. indicesArray.push_back(indicesVect);
  369. GLubyte& lastframe = frameChangeArr.at(frameChangeArr.size()-1);
  370. lastframe = lastframe|byteMap[frameType::frame_indices];
  371. }
  372. }
  373. }
  374. }
  375. bool RedSlotBakeModel::_uvVectIsEqual(std::vector<Tex2F> a,std::vector<Tex2F> b){
  376. if (a.size()!=b.size()) {
  377. return false;
  378. }
  379. if (a.size()==0||b.size()==0) {
  380. if (a.size()==0&&b.size()==0) {
  381. return true;
  382. }
  383. return false;
  384. }
  385. Tex2F& a1 = a.at(0);
  386. Tex2F& b1 = b.at(0);
  387. if (a1.u!=b1.u||a1.v!=b1.v) {
  388. return false;
  389. }
  390. a1 = a.at(a.size()-1);
  391. b1 = b.at(b.size()-1);
  392. if (a1.u!=b1.u||a1.v!=b1.v) {
  393. return false;
  394. }
  395. a1 = a.at((int)(a.size()/2));
  396. b1 = b.at((int)(b.size()/2));
  397. if (a1.u!=b1.u||a1.v!=b1.v) {
  398. return false;
  399. }
  400. return true;
  401. }
  402. bool RedSlotBakeModel::_indicesVectIsEqual(unsigned short *a,int aCount,std::vector<unsigned short> b){
  403. if (aCount!=b.size()) {
  404. return false;
  405. }
  406. if (aCount==0||b.size()==0) {
  407. if (aCount==0&&b.size()==0) {
  408. return true;
  409. }
  410. return false;
  411. }
  412. short a1 = a[0];
  413. short b1 = b.at(0);
  414. if (a1!=b1||a1!=b1) {
  415. return false;
  416. }
  417. a1 = a[aCount-1];
  418. b1 = b.at(b.size()-1);
  419. if (a1!=b1||a1!=b1) {
  420. return false;
  421. }
  422. a1 = a[(int)(aCount/2)];
  423. b1 = b.at((int)(b.size()/2));
  424. if (a1!=b1||a1!=b1) {
  425. return false;
  426. }
  427. return true;
  428. }
  429. bool RedSlotBakeModel::_vertVectIsEqual(std::vector<BAKE_POS_INT> &a,std::vector<BAKE_POS_INT> &b){
  430. if (a.size()!=b.size()) {
  431. return false;
  432. }
  433. if (a.size()==0||b.size()==0) {
  434. if (a.size()==0&&b.size()==0) {
  435. return true;
  436. }
  437. return false;
  438. }
  439. for (int i = 0; i<a.size(); i++) {
  440. BAKE_POS_INT bpi_A = a.at(i);
  441. BAKE_POS_INT bpi_B = b.at(i);
  442. if (bpi_A.xPos!=bpi_B.xPos||bpi_A.yPos!=bpi_B.yPos) {
  443. return false;
  444. }
  445. }
  446. return true;
  447. }
  448. const std::string& RedSlotBakeModel::getSlotName(){
  449. return slotName;
  450. }
  451. const int RedSlotBakeModel::getSlotIndex(){
  452. return slotIndex;
  453. }
  454. void RedSlotBakeModel::setSlotName(const std::string& aSlotName){
  455. slotName = aSlotName;
  456. }
  457. void RedSlotBakeModel::setSlotIndex(int aSlotIndex){
  458. slotIndex = aSlotIndex;
  459. }
  460. int RedSlotBakeModel::getVertCount(){
  461. if (posArraySize>0) {
  462. return (int)posArray[0].size();
  463. }
  464. return 0;
  465. }
  466. int RedSlotBakeModel::getMaxXPos(){
  467. return maxXPos;
  468. }
  469. int RedSlotBakeModel::getMaxYPos(){
  470. return maxYPos;
  471. }
  472. int RedSlotBakeModel::getMinXPos(){
  473. return minXPos;
  474. }
  475. int RedSlotBakeModel::getMinYPos(){
  476. return minYPos;
  477. }
  478. void RedSlotBakeModel::setMaxXPos(int pos){
  479. maxXPos = pos;
  480. }
  481. void RedSlotBakeModel::setMaxYPos(int pos){
  482. maxYPos = pos;
  483. }
  484. void RedSlotBakeModel::setMinXPos(int pos){
  485. minXPos = pos;
  486. }
  487. void RedSlotBakeModel::setMinYPos(int pos){
  488. minYPos = pos;
  489. }
  490. const std::vector<std::vector<BAKE_POS_INT>>& RedSlotBakeModel::getPosArray(){
  491. return posArray;
  492. }
  493. void RedSlotBakeModel::addPosArray(const std::vector<BAKE_POS_INT>& aPosArray){
  494. posArray.push_back(aPosArray);
  495. }
  496. const std::vector<BlendFunc>& RedSlotBakeModel::getBlendFuncArray(){
  497. return blendFuncArray;
  498. }
  499. void RedSlotBakeModel::addBlendFuncToArray(const BlendFunc& blendFunc){
  500. blendFuncArray.push_back(blendFunc);
  501. }
  502. const std::vector<Color3B>& RedSlotBakeModel::getColorArray(){
  503. return colorArray;
  504. }
  505. void RedSlotBakeModel::addColorToArray(const Color3B& color){
  506. colorArray.push_back(color);
  507. }
  508. const std::vector<GLubyte>& RedSlotBakeModel::getAlphaArray(){
  509. return alphaArray;
  510. }
  511. void RedSlotBakeModel::addAlphaToArray(GLubyte Alpha) {
  512. alphaArray.push_back(Alpha);
  513. }
  514. const std::vector<std::vector<Tex2F>>& RedSlotBakeModel::getUvArray(){
  515. return uvArray;
  516. }
  517. void RedSlotBakeModel::addUvArray(const std::vector<Tex2F>& aUvArray){
  518. uvArray.push_back(aUvArray);
  519. }
  520. const std::vector<std::vector<unsigned short>>& RedSlotBakeModel::getIndicesArray(){
  521. return indicesArray;
  522. }
  523. void RedSlotBakeModel::addIndicesArray(const std::vector<unsigned short>& aIndicesArray){
  524. indicesArray.push_back(aIndicesArray);
  525. }
  526. const std::vector<GLubyte>& RedSlotBakeModel::getFrameChangeArr(){
  527. return frameChangeArr;
  528. }
  529. void RedSlotBakeModel::addFrameChangeToArr(GLubyte aFrameChange){
  530. frameChangeArr.push_back(aFrameChange);
  531. }
  532. const std::vector<cocos2d::Texture2D*>& RedSlotBakeModel::getTextureArray(){
  533. return textureArray;
  534. }
  535. void RedSlotBakeModel::addTextureToArray(cocos2d::Texture2D* texture){
  536. textureArray.push_back(texture);
  537. }
  538. void RedSlotBakeModel::getTriangles(int aCurrentFrame,BKAE_FRAME_PLAY& aFrameInfo,const Point& offSet,float dis,V3F_C4B_T2F *beginVert,bool merge){
  539. BKAE_FRAME_INFO &bInfo = bakeFrameInfos[aCurrentFrame-1];
  540. //读取烘培的顶点偏移量
  541. std::vector<BAKE_POS_INT> &bpi_Arr = posArray[bInfo.vert];
  542. int bpiSize = (int)bpi_Arr.size();
  543. aFrameInfo.triangles.vertCount = bpiSize;
  544. if (aCurrentFrame<2||dis==0) {
  545. for (int aa = 0; aa<bpiSize; aa++) {
  546. BAKE_POS_INT &bpi = bpi_Arr[aa];
  547. beginVert[aa].vertices.x = bpi.xPos+offSet.x;
  548. beginVert[aa].vertices.y = bpi.yPos+offSet.y;
  549. }
  550. }else{
  551. BKAE_FRAME_INFO &prebInfo = bakeFrameInfos[aCurrentFrame-2];
  552. if (prebInfo.vert!=bInfo.vert&&merge) {
  553. std::vector<BAKE_POS_INT> &preBpi_Arr = posArray[prebInfo.vert];
  554. for (int aa = 0; aa<bpiSize; aa++) {
  555. BAKE_POS_INT &bpi = bpi_Arr[aa];
  556. BAKE_POS_INT &prebpi = preBpi_Arr[aa];
  557. beginVert[aa].vertices.x = prebpi.xPos + dis*(bpi.xPos - prebpi.xPos)+offSet.x;
  558. beginVert[aa].vertices.y = prebpi.yPos + dis*(bpi.yPos - prebpi.yPos)+offSet.y;
  559. }
  560. }else{
  561. for (int aa = 0; aa<bpiSize; aa++) {
  562. BAKE_POS_INT &bpi = bpi_Arr[aa];
  563. beginVert[aa].vertices.x = bpi.xPos+offSet.x;
  564. beginVert[aa].vertices.y = bpi.yPos+offSet.y;
  565. }
  566. }
  567. }
  568. //如果uvArraySize只需要更新一次就好
  569. if (aFrameInfo.hasOnceUpdate==false||uvArraySize>1) {
  570. //读取烘培的UV
  571. std::vector<Tex2F> &currentFrameUV = uvArray[bInfo.uv];
  572. aFrameInfo.currentFrameUV = &currentFrameUV;
  573. // aFrameInfo.currentFrameUV = uvArray[bInfo.uv];
  574. for (int aa = 0; aa<bpiSize; aa++) {
  575. beginVert[aa].texCoords = (*aFrameInfo.currentFrameUV)[aa];
  576. }
  577. }
  578. if (aFrameInfo.hasOnceUpdate==false||indicesArraySize>1) {
  579. //读取烘培的Indices
  580. std::vector<unsigned short>& indicesVect = indicesArray[bInfo.indices];
  581. aFrameInfo.triangles.indexCount = (int)indicesVect.size();
  582. aFrameInfo.triangles.indices = indicesVect.data();
  583. }
  584. if (aFrameInfo.hasOnceUpdate==false||alphaArraySize>1||colorArraySize>1) {
  585. //读取烘培的Color
  586. Color3B& color = colorArray[bInfo.color];
  587. aFrameInfo.currentFrameColor.r = color.r;
  588. aFrameInfo.currentFrameColor.g = color.g;
  589. aFrameInfo.currentFrameColor.b = color.b;
  590. //读取烘培的Aphla
  591. aFrameInfo.currentFrameColor.a = alphaArray[bInfo.alpha];
  592. for (int aa = 0; aa<bpiSize; aa++) {
  593. beginVert[aa].colors = aFrameInfo.currentFrameColor;
  594. }
  595. }
  596. aFrameInfo.hasOnceUpdate = true;
  597. }