RedBakeSpineIO.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. //
  2. // RedBakeSpineIO.cpp
  3. // cocos2d_libs
  4. //
  5. // Created by ZhengSong on 2023/2/16.
  6. //
  7. #include "RedBakeSpineIO.h"
  8. #include <fstream>
  9. namespace spine {
  10. const static std::string REDSPINEBAKE_EXTENSION = ".rb";
  11. RedBakeSpineIO::RedBakeSpineIO() {
  12. }
  13. RedBakeSpineIO::~RedBakeSpineIO() {
  14. }
  15. static RedBakeSpineIO* _instance = nullptr;
  16. RedBakeSpineIO* RedBakeSpineIO::getInstance() {
  17. if(_instance == nullptr) {
  18. _instance = new RedBakeSpineIO();
  19. }
  20. return _instance;
  21. }
  22. void RedBakeSpineIO::write(const std::string& filePath, const std::unordered_map<std::string, RedAnimationBakeModel*>& datas) {
  23. if(datas.empty()) {
  24. CCASSERT(false, "没有数据");
  25. return;
  26. }
  27. std::ofstream outFile(filePath, std::ios::out | std::ios::binary);
  28. ::RedSpineBakeProto::BakeDataIndex dataIndex_pb;
  29. google::protobuf::Map<std::string, ::RedSpineBakeProto::DataInfo>* bakeDataIdx_pb = dataIndex_pb.mutable_dataindex();
  30. uint64_t currentOffset = 0;
  31. for(auto iter = datas.begin(); iter != datas.end(); iter++) {
  32. const std::string& animName = iter->first;
  33. RedAnimationBakeModel* bakeModel = iter->second;
  34. if(bakeModel == nullptr) {
  35. CCASSERT(false, "spine还没有烘培完");
  36. return;
  37. }
  38. ::RedSpineBakeProto::RedAnimationBakeModel bakeModel_pb;
  39. _writeAnimationBakeModel(bakeModel, bakeModel_pb);
  40. std::string serializedModel;
  41. bakeModel_pb.SerializeToString(&serializedModel);
  42. // 计算每个数据的长度,并保存位置信息
  43. ::RedSpineBakeProto::DataInfo dataInfo_pb;
  44. dataInfo_pb.set_offset(currentOffset);
  45. dataInfo_pb.set_length(serializedModel.size());
  46. (*bakeDataIdx_pb)[animName] = dataInfo_pb;
  47. //把烘培的数据写入到指定路径
  48. outFile.write(serializedModel.c_str(), dataInfo_pb.length());
  49. currentOffset += dataInfo_pb.length();
  50. }
  51. //烘培数据的索引文件写入到指定路径
  52. string outIndex;
  53. dataIndex_pb.SerializeToString(&outIndex);
  54. outFile.write(outIndex.c_str(), outIndex.size());
  55. uint32_t idxOffset = currentOffset;
  56. uint32_t outIndexSize = outIndex.size();
  57. // 将两个32位整数写入文件
  58. outFile.write(reinterpret_cast<const char*>(&idxOffset), sizeof(uint32_t));
  59. outFile.write(reinterpret_cast<const char*>(&outIndexSize), sizeof(uint32_t));
  60. // 检查是否写入成功
  61. if (!outFile) {
  62. ///写入失败
  63. }
  64. outFile.close();
  65. }
  66. void RedBakeSpineIO::_writeAnimationBakeModel(RedAnimationBakeModel* model, ::RedSpineBakeProto::RedAnimationBakeModel& model_pb) {
  67. //fileName
  68. const std::string& fileName = model->getFileName();
  69. model_pb.set_filename(fileName);
  70. //animateName
  71. const std::string& animateName = model->getAimationName();
  72. model_pb.set_animatename(animateName);
  73. //boneAttach
  74. ::google::protobuf::Map< std::string, ::RedSpineBakeProto::Vec2Array >* boneAttachs_pb = model_pb.mutable_boneattachs();
  75. const std::map<std::string,std::vector<Point>>& boneAttachs = model->getBoneAttachs();
  76. for(auto iter = boneAttachs.begin(); iter != boneAttachs.end(); iter++) {
  77. const std::string& boneAttachName = iter->first;
  78. const std::vector<Point>& posArray = iter->second;
  79. ::RedSpineBakeProto::Vec2Array posArray_pb;
  80. for(int i = 0; i < posArray.size(); ++i) {
  81. const Point& pos = posArray.at(i);
  82. ::RedSpineBakeProto::Vec2* pos_pb = posArray_pb.add_arr();
  83. pos_pb->set_x(pos.x);
  84. pos_pb->set_y(pos.y);
  85. }
  86. (*boneAttachs_pb)[boneAttachName] = posArray_pb;
  87. }
  88. //slotArr
  89. ::google::protobuf::Map<::google::protobuf::int32, ::RedSpineBakeProto::RedSlotBakeModel >* slotArr_pb = model_pb.mutable_slotarr();
  90. const std::map<int,RedSlotBakeModel*>& slotArr = model->getSlotArr();
  91. RedSlotBakeModel* slotModel = nullptr;
  92. for(auto iter : slotArr) {
  93. int slotIdx = iter.first;
  94. slotModel = iter.second;
  95. ::RedSpineBakeProto::RedSlotBakeModel slotModel_pb;
  96. _writeSlotBakeModel(slotModel, slotModel_pb);
  97. (*slotArr_pb)[slotIdx] = slotModel_pb;
  98. }
  99. //drawOrderArr
  100. ::RedSpineBakeProto::DrawOrderArray* drawOrderArray_pb = model_pb.mutable_draworderarr();
  101. const std::vector<std::vector<int>>& drawOrderArray = model->getDrawOrderArr();
  102. for(int i = 0; i < drawOrderArray.size(); ++i) {
  103. ::RedSpineBakeProto::DrawOrderArray_DrawOrders* container = drawOrderArray_pb->add_container();
  104. const std::vector<int>& arr = drawOrderArray.at(i);
  105. for(int j = 0; j < arr.size(); ++j) {
  106. int order = arr.at(j);
  107. container->add_draworder(order);
  108. }
  109. }
  110. //drawOrderArrIndex
  111. const std::vector<DrawOrderMD>& drawOrderArrIndex = model->getDrawOrderArrIndex();
  112. for(int i = 0; i < drawOrderArrIndex.size(); ++i) {
  113. const DrawOrderMD& drawOrderMD = drawOrderArrIndex.at(i);
  114. ::RedSpineBakeProto::DrawOrderMD* drawOrderMD_pb = model_pb.add_draworderarrindex();
  115. drawOrderMD_pb->set_frame(drawOrderMD.frame);
  116. drawOrderMD_pb->set_arrindex(drawOrderMD.arrIndex);
  117. }
  118. //eventArr
  119. const std::vector<EventMD>& eventArr = model->getEventArr();
  120. for(int i = 0; i < eventArr.size(); ++i){
  121. const EventMD& eventMD = eventArr.at(i);
  122. ::RedSpineBakeProto::EventMD* eventMD_pb = model_pb.add_eventarr();
  123. eventMD_pb->set_frame(eventMD.frame);
  124. for(int j = 0; j < eventMD.eventNames.size(); ++j){
  125. std::string eventName = eventMD.eventNames.at(j);
  126. eventMD_pb->add_eventname(eventName);
  127. }
  128. }
  129. //totalBakeFrame
  130. int totalBakeFrame = model->getTotalBakeFrame();
  131. model_pb.set_totalbakeframe(totalBakeFrame);
  132. //边界
  133. int maxXPos = model->getMaxXPos();
  134. int maxYPos = model->getMaxYPos();
  135. int minXPos = model->getMinXPos();
  136. int minYPos = model->getMinYPos();
  137. model_pb.set_maxxpos(maxXPos);
  138. model_pb.set_maxypos(maxYPos);
  139. model_pb.set_minxpos(minXPos);
  140. model_pb.set_minypos(minYPos);
  141. const Vec2& leftBottomPos = model->getLeftBottom();
  142. const Vec2& rightTopPos = model->getRightTopPos();
  143. const Vec2& leftBottomSubSizePos = model->getLeftBottomSubSizePos();
  144. const Vec2& rightTopSubSizePos = model->getRightTopSubSizePos();
  145. model_pb.mutable_leftbottompos()->set_x(leftBottomPos.x);
  146. model_pb.mutable_leftbottompos()->set_y(leftBottomPos.y);
  147. model_pb.mutable_righttoppos()->set_x(rightTopPos.x);
  148. model_pb.mutable_righttoppos()->set_y(rightTopPos.y);
  149. model_pb.mutable_leftbottomsubsizepos()->set_x(leftBottomSubSizePos.x);
  150. model_pb.mutable_leftbottomsubsizepos()->set_y(leftBottomSubSizePos.y);
  151. model_pb.mutable_righttopsubsizepos()->set_x(rightTopSubSizePos.x);
  152. model_pb.mutable_righttopsubsizepos()->set_y(rightTopSubSizePos.y);
  153. //当前帧率
  154. int currentFrameRate = model->getCurrentFrameRate();
  155. model_pb.set_currentframerate(currentFrameRate);
  156. //lastDrawOverTime
  157. float lastDrawOverTime = model->getLastDrawOverTime();
  158. model_pb.set_lastdrawovertime(lastDrawOverTime);
  159. }
  160. void RedBakeSpineIO::_writeSlotBakeModel(RedSlotBakeModel* model, ::RedSpineBakeProto::RedSlotBakeModel& model_pb) {
  161. //slotName
  162. model_pb.set_slotname(model->getSlotName());
  163. //slotIndex
  164. int slotIndex = model->getSlotIndex();
  165. model_pb.set_slotindex(slotIndex);
  166. //posarray
  167. const std::vector<std::vector<BAKE_POS_INT>>& posArray = model->getPosArray();
  168. ::RedSpineBakeProto::PosArray* bakePosArray = model_pb.mutable_posarray();
  169. for(int i = 0; i < posArray.size(); i++) {
  170. const vector<BAKE_POS_INT>& arr = posArray.at(i);
  171. ::RedSpineBakeProto::PosArray_BakePosArray* container = bakePosArray->add_container();
  172. for(int j = 0; j < arr.size(); j++) {
  173. const BAKE_POS_INT& bpi = arr.at(j);
  174. ::RedSpineBakeProto::Vec2* bakePos = container->add_pos();
  175. bakePos->set_x(bpi.xPos);
  176. bakePos->set_y(bpi.yPos);
  177. }
  178. }
  179. //blendFuncArray
  180. const std::vector<BlendFunc>& blendFuncArray = model->getBlendFuncArray();
  181. for(int i = 0; i < blendFuncArray.size(); i++) {
  182. const BlendFunc& blend = blendFuncArray.at(i);
  183. ::RedSpineBakeProto::BlendFunc* bakeBlend = model_pb.add_blendfuncarray();
  184. bakeBlend->set_src(blend.src);
  185. bakeBlend->set_dst(blend.dst);
  186. }
  187. //colorArray
  188. const std::vector<Color3B>& colorArray = model->getColorArray();
  189. for(int i = 0; i < colorArray.size(); i++) {
  190. const Color3B& color = colorArray.at(i);
  191. ::RedSpineBakeProto::Color3B* bakeColor = model_pb.add_colorarray();
  192. bakeColor->set_r(color.r);
  193. bakeColor->set_g(color.g);
  194. bakeColor->set_b(color.b);
  195. }
  196. //alphaArray
  197. const std::vector<GLubyte>& alphaArray = model->getAlphaArray();
  198. for(int i = 0; i < alphaArray.size(); i++) {
  199. GLubyte alpha = alphaArray.at(i);
  200. model_pb.add_alphaarray(alpha);
  201. }
  202. //uvArray
  203. const std::vector<std::vector<Tex2F>>& uvArray = model->getUvArray();
  204. ::RedSpineBakeProto::UVArray* bakeUvArray = model_pb.mutable_uvarray();
  205. for(int i = 0; i < uvArray.size(); i++) {
  206. ::RedSpineBakeProto::UVArray_TexArray* texArray= bakeUvArray->add_container();
  207. const std::vector<Tex2F>& arr = uvArray.at(i);
  208. for(int j = 0; j < arr.size(); j++) {
  209. const Tex2F& tex = arr.at(j);
  210. ::RedSpineBakeProto::Tex2F* bakeTex = texArray->add_texes();
  211. bakeTex->set_u(tex.u);
  212. bakeTex->set_v(tex.v);
  213. }
  214. }
  215. //indicesArray
  216. const std::vector<std::vector<unsigned short>>& indicesArray = model->getIndicesArray();
  217. ::RedSpineBakeProto::IndicesArray*bakeIndicesArray = model_pb.mutable_indicesarray();
  218. for(int i = 0; i < indicesArray.size(); i++) {
  219. const std::vector<unsigned short>& array = indicesArray.at(i);
  220. ::RedSpineBakeProto::IndicesArray_Indices* bakeIndices = bakeIndicesArray->add_container();
  221. for(int j = 0; j < array.size(); j++) {
  222. unsigned short indice = array.at(j);
  223. bakeIndices->add_indices(indice);
  224. }
  225. }
  226. //frameChangeArr
  227. const std::vector<GLubyte>& frameChangeArr = model->getFrameChangeArr();
  228. for(int i = 0; i < frameChangeArr.size(); i++) {
  229. GLubyte frameChangeValue = frameChangeArr.at(i);
  230. model_pb.add_framechangearr(frameChangeValue);
  231. }
  232. //pos
  233. int maxXPos = model->getMaxXPos();
  234. int maxYPos = model->getMaxYPos();
  235. int minXPos = model->getMinXPos();
  236. int minYPos = model->getMinYPos();
  237. model_pb.set_maxxpos(maxXPos);
  238. model_pb.set_maxypos(maxYPos);
  239. model_pb.set_minxpos(minXPos);
  240. model_pb.set_minypos(minYPos);
  241. //textureArray
  242. const std::vector<cocos2d::Texture2D*>& textureArray = model->getTextureArray();
  243. for (int i = 0; i < textureArray.size(); i++) {
  244. Texture2D* tex = textureArray.at(i);
  245. std::string fullPath = tex->getPath();
  246. size_t lastPos = fullPath.find_last_of('/');
  247. std::string fileName = fullPath.substr(lastPos + 1, fullPath.size() - lastPos);
  248. model_pb.add_texfilenamearr(fileName);
  249. }
  250. }
  251. void RedBakeSpineIO::readAnimationBakeModel(const ::RedSpineBakeProto::RedAnimationBakeModel& model_pb, RedAnimationBakeModel* model, const std::string& filePath) {
  252. _readAnimationBakeModel(model_pb, model, filePath);
  253. }
  254. void RedBakeSpineIO::_readAnimationBakeModel(const ::RedSpineBakeProto::RedAnimationBakeModel& model_pb, RedAnimationBakeModel* model, const std::string& filePath) {
  255. //fileName
  256. const std::string& fileName = model_pb.filename();
  257. model->setFileName(fileName);
  258. //animateName
  259. const std::string& animateName = model_pb.animatename();
  260. model->setAimationName(animateName);
  261. //boneAttach
  262. std::map<std::string, std::vector<Point>> boneAttachs;
  263. const ::google::protobuf::Map<std::string, ::RedSpineBakeProto::Vec2Array>& boneattachs_pb = model_pb.boneattachs();
  264. for(auto iter = boneattachs_pb.begin(); iter != boneattachs_pb.end(); ++ iter) {
  265. const string& boneattachName = iter->first;
  266. const ::RedSpineBakeProto::Vec2Array& posArray_pb = iter->second;
  267. std::vector<Point> posArray;
  268. for (int i = 0; i < posArray_pb.arr_size(); ++i) {
  269. const ::RedSpineBakeProto::Vec2& pos_pb = posArray_pb.arr(i);
  270. Point pos;
  271. pos.x = pos_pb.x();
  272. pos.y = pos_pb.y();
  273. posArray.push_back(pos);
  274. }
  275. boneAttachs[boneattachName] = posArray;
  276. }
  277. model->setBoneAttachs(boneAttachs);
  278. //totalBakeFrame
  279. int totalBakeFrame = model_pb.totalbakeframe();
  280. model->setTotalBakeFrame(totalBakeFrame);
  281. //slotArr
  282. std::map<int, RedSlotBakeModel *> slotArr;
  283. const ::google::protobuf::Map<::google::protobuf::int32, ::RedSpineBakeProto::RedSlotBakeModel>& slotArr_pb = model_pb.slotarr();
  284. for(auto iter = slotArr_pb.begin(); iter != slotArr_pb.end(); ++iter) {
  285. int slotIdx = iter->first;
  286. const ::RedSpineBakeProto::RedSlotBakeModel& slotModel_pb = iter->second;
  287. RedSlotBakeModel* slotModel = new RedSlotBakeModel(slotModel_pb.slotname(), slotModel_pb.slotindex());
  288. _readSlotBakeModel(slotModel_pb, slotModel, filePath, nullptr);
  289. slotArr[slotIdx] = slotModel;
  290. }
  291. model->setSlotArr(slotArr);
  292. //drawOrderArr
  293. std::vector<std::vector<int>> drawOrderArr;
  294. const ::RedSpineBakeProto::DrawOrderArray& drawOrderArray_pb = model_pb.draworderarr();
  295. for(int i = 0; i < drawOrderArray_pb.container_size(); ++i) {
  296. const ::RedSpineBakeProto::DrawOrderArray_DrawOrders& drawOrders_pb = drawOrderArray_pb.container(i);
  297. int draworderSize = drawOrders_pb.draworder_size();
  298. std::vector<int> drawOrders;
  299. drawOrders.reserve(draworderSize);
  300. for(int j = 0; j < draworderSize; ++j) {
  301. int order = drawOrders_pb.draworder(j);
  302. drawOrders.push_back(order);
  303. }
  304. drawOrderArr.push_back(drawOrders);
  305. }
  306. model->setDrawOrderArr(drawOrderArr);
  307. //drawOrderArrIndex
  308. int drawOrderArrIndexSize = model_pb.draworderarrindex().size();
  309. std::vector<DrawOrderMD> drawOrderArrIndex;
  310. drawOrderArrIndex.reserve(drawOrderArrIndexSize);
  311. for(int i = 0; i < drawOrderArrIndexSize; i++) {
  312. const ::RedSpineBakeProto::DrawOrderMD& drawOrderMD_pb = model_pb.draworderarrindex(i);
  313. DrawOrderMD drawOrderMD;
  314. drawOrderMD.frame = drawOrderMD_pb.frame();
  315. drawOrderMD.arrIndex = drawOrderMD_pb.arrindex();
  316. drawOrderArrIndex.push_back(drawOrderMD);
  317. }
  318. model->setDrawOrderArrIndex(drawOrderArrIndex);
  319. //eventArr
  320. int eventArrSize = model_pb.eventarr().size();
  321. std::vector<EventMD> eventArr;
  322. eventArr.reserve(eventArrSize);
  323. for(int i = 0; i < eventArrSize; i++) {
  324. const ::RedSpineBakeProto::EventMD& eventMD_pb = model_pb.eventarr(i);
  325. EventMD eventMD;
  326. eventMD.frame = eventMD_pb.frame();
  327. int eventNamesSize = eventMD_pb.eventname_size();
  328. eventMD.eventNames.reserve(eventNamesSize);
  329. for(int j = 0; j < eventNamesSize; ++j) {
  330. std::string eventName = eventMD_pb.eventname(j);
  331. eventMD.eventNames.push_back(eventName);
  332. }
  333. eventArr.push_back(eventMD);
  334. }
  335. model->setEventArr(eventArr);
  336. //帧率
  337. int rate = model_pb.currentframerate();
  338. model->setCurrentFrameRate(rate);
  339. //lastDrawOverTime
  340. float lastDrawOverTime = model_pb.lastdrawovertime();
  341. model->setLastDrawOverTime(lastDrawOverTime);
  342. }
  343. void RedBakeSpineIO::_readSlotBakeModel(const ::RedSpineBakeProto::RedSlotBakeModel& model_pb, RedSlotBakeModel* model, const std::string& filePath, const std::function<void()>& finishCb) {
  344. std::string slotName = model_pb.slotname();
  345. model->setSlotName(slotName);
  346. int slotIndex = model_pb.slotindex();
  347. model->setSlotIndex(slotIndex);
  348. //posarray
  349. {
  350. const ::RedSpineBakeProto::PosArray& bakePosArray = model_pb.posarray();
  351. int posArraySize = bakePosArray.container_size();
  352. for(int i = 0; i < posArraySize; i++) {
  353. const ::RedSpineBakeProto::PosArray_BakePosArray& container = bakePosArray.container(i);
  354. int containerSize = container.pos_size();
  355. std::vector<BAKE_POS_INT> posArray;
  356. posArray.reserve(containerSize);//预设内存
  357. for (int j = 0; j < containerSize; j++) {
  358. const ::RedSpineBakeProto::Vec2& bakePos = container.pos(j);
  359. BAKE_POS_INT pos;
  360. pos.xPos = bakePos.x();
  361. pos.yPos = bakePos.y();
  362. posArray.push_back(pos);
  363. }
  364. model->addPosArray(posArray);
  365. }
  366. }
  367. //blendFuncArray
  368. {
  369. int blendFuncArraySize = model_pb.blendfuncarray_size();
  370. for(int i = 0; i < blendFuncArraySize; i++) {
  371. const ::RedSpineBakeProto::BlendFunc& bakeBlend = model_pb.blendfuncarray(i);
  372. BlendFunc blend;
  373. blend.src = bakeBlend.src();
  374. blend.dst = bakeBlend.dst();
  375. model->addBlendFuncToArray(blend);
  376. }
  377. }
  378. //colorArray
  379. {
  380. int colorArraySize = model_pb.colorarray_size();
  381. for(int i = 0; i < colorArraySize; i++) {
  382. const ::RedSpineBakeProto::Color3B& bakeColor = model_pb.colorarray(i);
  383. Color3B color;
  384. color.r = bakeColor.r();
  385. color.g = bakeColor.g();
  386. color.b = bakeColor.b();
  387. model->addColorToArray(color);
  388. }
  389. }
  390. //alphaArray
  391. {
  392. int alphaArraySize = model_pb.alphaarray_size();
  393. for(int i = 0; i < alphaArraySize; i++) {
  394. ::google::protobuf::uint32 bakeAlpha = model_pb.alphaarray(i);
  395. model->addAlphaToArray(bakeAlpha);
  396. }
  397. }
  398. //uvArray
  399. {
  400. const ::RedSpineBakeProto::UVArray& bakeUVArray = model_pb.uvarray();
  401. int containerSize = bakeUVArray.container_size();
  402. for(int i = 0; i < containerSize; i++) {
  403. const ::RedSpineBakeProto::UVArray_TexArray& container = bakeUVArray.container(i);
  404. int texesSize = container.texes_size();
  405. std::vector<Tex2F> uvArray;
  406. uvArray.reserve(texesSize);//预设内存
  407. for(int j = 0; j < texesSize; j++) {
  408. const ::RedSpineBakeProto::Tex2F& bakeTex = container.texes(j);
  409. Tex2F tex;
  410. tex.u = bakeTex.u();
  411. tex.v = bakeTex.v();
  412. uvArray.push_back(tex);
  413. }
  414. model->addUvArray(uvArray);
  415. }
  416. }
  417. //indicesArray
  418. {
  419. const ::RedSpineBakeProto::IndicesArray& bakeIndices = model_pb.indicesarray();
  420. int containerSize = bakeIndices.container_size();
  421. for(int i = 0; i < containerSize; i++) {
  422. const ::RedSpineBakeProto::IndicesArray_Indices& container = bakeIndices.container(i);
  423. int indicesSize = container.indices_size();
  424. std::vector<unsigned short> indicesArray;
  425. indicesArray.reserve(indicesSize);//预设内存
  426. for(int j = 0; j < indicesSize; j++) {
  427. ::google::protobuf::uint32 indices = container.indices(j);
  428. indicesArray.push_back(indices);
  429. }
  430. model->addIndicesArray(indicesArray);
  431. }
  432. }
  433. //frameChangeArr
  434. {
  435. int frameChangeArrSize = model_pb.framechangearr_size();
  436. for(int i = 0; i < frameChangeArrSize; i++) {
  437. ::google::protobuf::uint32 frame = model_pb.framechangearr(i);
  438. model->addFrameChangeToArr(frame);
  439. }
  440. }
  441. //bounds
  442. {
  443. int maxXPos = model_pb.maxxpos();
  444. int maxYPos = model_pb.maxypos();
  445. int minXPos = model_pb.minxpos();
  446. int minYPos = model_pb.minypos();
  447. model->setMaxXPos(maxXPos);
  448. model->setMaxYPos(maxYPos);
  449. model->setMinXPos(minXPos);
  450. model->setMinYPos(minYPos);
  451. }
  452. //textureArray
  453. {
  454. ///会在外部指定使用的图片!!!
  455. // auto loadTexture = [=](){
  456. // int textureArraySize = model_pb.texfilenamearr_size();
  457. // for(int i = 0; i < textureArraySize; i++) {
  458. // const std::string& fileName = model_pb.texfilenamearr(i);
  459. // Texture2D* tex2d = Director::getInstance()->getTextureCache()->addImage(filePath+fileName);
  460. // if(tex2d == nullptr) {
  461. // CCASSERT(false, "文件路径不对");
  462. // }
  463. // model->addTextureToArray(tex2d);
  464. // }
  465. // if(finishCb) {
  466. // finishCb();
  467. // }
  468. // };
  469. // loadTexture();
  470. if(finishCb) {
  471. finishCb();
  472. }
  473. }
  474. model->initBakeFrameInfos();
  475. }
  476. } //namespace