ASEParser.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2008, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file Implementation of the ASE parser class */
  35. #include "ASELoader.h"
  36. #include "MaterialSystem.h"
  37. #include "../include/DefaultLogger.h"
  38. #include "fast_atof.h"
  39. #include "../include/IOStream.h"
  40. #include "../include/IOSystem.h"
  41. #include "../include/aiMesh.h"
  42. #include "../include/aiScene.h"
  43. #include "../include/aiAssert.h"
  44. #include <boost/scoped_ptr.hpp>
  45. using namespace Assimp;
  46. using namespace Assimp::ASE;
  47. #if (defined BLUBB)
  48. # undef BLUBB
  49. #endif
  50. #define BLUBB(_message_) \
  51. {this->LogError(_message_);return;}
  52. // ------------------------------------------------------------------------------------------------
  53. Parser::Parser (const char* szFile)
  54. {
  55. ai_assert(NULL != szFile);
  56. this->m_szFile = szFile;
  57. // makre sure that the color values are invalid
  58. this->m_clrBackground.r = std::numeric_limits<float>::quiet_NaN();
  59. this->m_clrAmbient.r = std::numeric_limits<float>::quiet_NaN();
  60. this->iLineNumber = 0;
  61. }
  62. // ------------------------------------------------------------------------------------------------
  63. void Parser::LogWarning(const char* szWarn)
  64. {
  65. ai_assert(NULL != szWarn);
  66. ai_assert(strlen(szWarn) < 950);
  67. char szTemp[1024];
  68. sprintf(szTemp,"Line %i: %s",this->iLineNumber,szWarn);
  69. // output the warning to the logger ...
  70. DefaultLogger::get()->warn(szTemp);
  71. }
  72. // ------------------------------------------------------------------------------------------------
  73. void Parser::LogError(const char* szWarn)
  74. {
  75. ai_assert(NULL != szWarn);
  76. ai_assert(strlen(szWarn) < 950);
  77. char szTemp[1024];
  78. sprintf(szTemp,"Line %i: %s",this->iLineNumber,szWarn);
  79. // throw an exception
  80. throw new ImportErrorException(szTemp);
  81. }
  82. // ------------------------------------------------------------------------------------------------
  83. bool Parser::SkipToNextToken()
  84. {
  85. while (true)
  86. {
  87. if ('*' == *this->m_szFile || '}' == *this->m_szFile || '{' == *this->m_szFile)return true;
  88. if ('\0' == *this->m_szFile)return false;
  89. ++this->m_szFile;
  90. }
  91. }
  92. // ------------------------------------------------------------------------------------------------
  93. bool Parser::SkipOpeningBracket()
  94. {
  95. if (!SkipSpaces(this->m_szFile,&this->m_szFile))return false;
  96. if ('{' != *this->m_szFile)
  97. {
  98. this->LogWarning("Unable to parse block: Unexpected character, \'{\' expected [#1]");
  99. return false;
  100. }
  101. this->SkipToNextToken();
  102. return true;
  103. }
  104. // ------------------------------------------------------------------------------------------------
  105. bool Parser::SkipSection()
  106. {
  107. // must handle subsections ...
  108. int iCnt = 0;
  109. while (true)
  110. {
  111. if ('}' == *this->m_szFile)
  112. {
  113. --iCnt;
  114. if (0 == iCnt)
  115. {
  116. // go to the next valid token ...
  117. ++this->m_szFile;
  118. this->SkipToNextToken();
  119. return true;
  120. }
  121. }
  122. else if ('{' == *this->m_szFile)
  123. {
  124. ++iCnt;
  125. }
  126. else if ('\0' == *this->m_szFile)
  127. {
  128. this->LogWarning("Unable to parse block: Unexpected EOF, closing bracket \'}\' was expected [#1]");
  129. return false;
  130. }
  131. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  132. ++this->m_szFile;
  133. }
  134. }
  135. // ------------------------------------------------------------------------------------------------
  136. void Parser::Parse()
  137. {
  138. int iDepth = 0;
  139. while (true)
  140. {
  141. if ('*' == *this->m_szFile)
  142. {
  143. // version should be 200. Validate this ...
  144. if (0 == strncmp(this->m_szFile,"*3DSMAX_ASCIIEXPORT",19) &&
  145. IsSpaceOrNewLine(*(this->m_szFile+19)))
  146. {
  147. this->m_szFile+=20;
  148. unsigned int iVersion;
  149. this->ParseLV4MeshLong(iVersion);
  150. if (200 != iVersion)
  151. {
  152. this->LogWarning("Unknown file format version: *3DSMAX_ASCIIEXPORT should \
  153. be 200. Continuing happily ...");
  154. }
  155. continue;
  156. }
  157. // main scene information
  158. if (0 == strncmp(this->m_szFile,"*SCENE",6) &&
  159. IsSpaceOrNewLine(*(this->m_szFile+6)))
  160. {
  161. this->m_szFile+=7;
  162. this->ParseLV1SceneBlock();
  163. continue;
  164. }
  165. // material list
  166. if (0 == strncmp(this->m_szFile,"*MATERIAL_LIST",14) &&
  167. IsSpaceOrNewLine(*(this->m_szFile+14)))
  168. {
  169. this->m_szFile+=15;
  170. this->ParseLV1MaterialListBlock();
  171. continue;
  172. }
  173. // geometric object (mesh)
  174. if (0 == strncmp(this->m_szFile,"*GEOMOBJECT",11) &&
  175. IsSpaceOrNewLine(*(this->m_szFile+11)))
  176. {
  177. this->m_szFile+=12;
  178. this->m_vMeshes.push_back(Mesh());
  179. this->ParseLV1GeometryObjectBlock(this->m_vMeshes.back());
  180. continue;
  181. }
  182. // ignore comments, lights and cameras
  183. }
  184. else if ('{' == *this->m_szFile)iDepth++;
  185. else if ('}' == *this->m_szFile)
  186. {
  187. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  188. }
  189. else if ('\0' == *this->m_szFile)
  190. {
  191. // END OF FILE ... why not?
  192. return;
  193. }
  194. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  195. ++this->m_szFile;
  196. }
  197. return;
  198. }
  199. // ------------------------------------------------------------------------------------------------
  200. void Parser::ParseLV1SceneBlock()
  201. {
  202. int iDepth = 0;
  203. while (true)
  204. {
  205. if ('*' == *this->m_szFile)
  206. {
  207. if (0 == strncmp(this->m_szFile,"*SCENE_BACKGROUND_STATIC",24) &&
  208. IsSpaceOrNewLine(*(this->m_szFile+24)))
  209. {
  210. this->m_szFile+=25;
  211. // parse a color triple and assume it is really the bg color
  212. this->ParseLV4MeshFloatTriple( &this->m_clrBackground.r );
  213. continue;
  214. }
  215. if (0 == strncmp(this->m_szFile,"*SCENE_AMBIENT_STATIC",21) &&
  216. IsSpaceOrNewLine(*(this->m_szFile+21)))
  217. {
  218. this->m_szFile+=22;
  219. // parse a color triple and assume it is really the bg color
  220. this->ParseLV4MeshFloatTriple( &this->m_clrAmbient.r );
  221. continue;
  222. }
  223. }
  224. else if ('{' == *this->m_szFile)iDepth++;
  225. else if ('}' == *this->m_szFile)
  226. {
  227. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  228. }
  229. else if ('\0' == *this->m_szFile)
  230. {
  231. // END OF FILE ... why not?
  232. return;
  233. }
  234. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  235. ++this->m_szFile;
  236. }
  237. return;
  238. }
  239. // ------------------------------------------------------------------------------------------------
  240. void Parser::ParseLV1MaterialListBlock()
  241. {
  242. int iDepth = 0;
  243. unsigned int iMaterialCount = 0;
  244. unsigned int iOldMaterialCount = this->m_vMaterials.size();
  245. while (true)
  246. {
  247. if ('*' == *this->m_szFile)
  248. {
  249. if (0 == strncmp(this->m_szFile,"*MATERIAL_COUNT",15) &&
  250. IsSpaceOrNewLine(*(this->m_szFile+15)))
  251. {
  252. this->m_szFile+=16;
  253. this->ParseLV4MeshLong(iMaterialCount);
  254. // now allocate enough storage to hold all materials
  255. this->m_vMaterials.resize(iOldMaterialCount+iMaterialCount);
  256. continue;
  257. }
  258. if (0 == strncmp(this->m_szFile,"*MATERIAL",9) &&
  259. IsSpaceOrNewLine(*(this->m_szFile+9)))
  260. {
  261. this->m_szFile+=10;
  262. unsigned int iIndex = 0;
  263. this->ParseLV4MeshLong(iIndex);
  264. if (iIndex >= iMaterialCount)
  265. {
  266. this->LogWarning("Out of range: material index is too large");
  267. iIndex = iMaterialCount-1;
  268. }
  269. // get a reference to the material
  270. Material& sMat = this->m_vMaterials[iIndex+iOldMaterialCount];
  271. // skip the '{'
  272. this->SkipOpeningBracket();
  273. // parse the material block
  274. this->ParseLV2MaterialBlock(sMat);
  275. continue;
  276. }
  277. }
  278. else if ('{' == *this->m_szFile)iDepth++;
  279. else if ('}' == *this->m_szFile)
  280. {
  281. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  282. }
  283. else if ('\0' == *this->m_szFile)
  284. {
  285. // END OF FILE ... why not?
  286. return;
  287. }
  288. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  289. ++this->m_szFile;
  290. }
  291. return;
  292. }
  293. // ------------------------------------------------------------------------------------------------
  294. void Parser::ParseLV2MaterialBlock(ASE::Material& mat)
  295. {
  296. int iDepth = 0;
  297. unsigned int iNumSubMaterials = 0;
  298. while (true)
  299. {
  300. if ('*' == *this->m_szFile)
  301. {
  302. if (0 == strncmp(this->m_szFile,"*MATERIAL_NAME",14) &&
  303. IsSpaceOrNewLine(*(this->m_szFile+14)))
  304. {
  305. this->m_szFile+=15;
  306. if (!this->ParseString(mat.mName,"*MATERIAL_NAME"))this->SkipToNextToken();
  307. continue;
  308. }
  309. // ambient material color
  310. if (0 == strncmp(this->m_szFile,"*MATERIAL_AMBIENT",17) &&
  311. IsSpaceOrNewLine(*(this->m_szFile+17)))
  312. {
  313. this->m_szFile+=18;
  314. this->ParseLV4MeshFloatTriple(&mat.mAmbient.r);continue;
  315. }
  316. // diffuse material color
  317. if (0 == strncmp(this->m_szFile,"*MATERIAL_DIFFUSE",17) &&
  318. IsSpaceOrNewLine(*(this->m_szFile+17)))
  319. {
  320. this->m_szFile+=18;
  321. this->ParseLV4MeshFloatTriple(&mat.mDiffuse.r);continue;
  322. }
  323. // specular material color
  324. if (0 == strncmp(this->m_szFile,"*MATERIAL_SPECULAR",18) &&
  325. IsSpaceOrNewLine(*(this->m_szFile+18)))
  326. {
  327. this->m_szFile+=19;
  328. this->ParseLV4MeshFloatTriple(&mat.mSpecular.r);continue;
  329. }
  330. // material shading type
  331. if (0 == strncmp(this->m_szFile,"*MATERIAL_SHADING",17) &&
  332. IsSpaceOrNewLine(*(this->m_szFile+17)))
  333. {
  334. this->m_szFile+=18;
  335. if (0 == strncmp(this->m_szFile,"Blinn",5) &&
  336. IsSpaceOrNewLine(*(this->m_szFile+5)))
  337. {
  338. mat.mShading = Dot3DSFile::Blinn;
  339. this->m_szFile+=6;
  340. }
  341. else if (0 == strncmp(this->m_szFile,"Phong",5) &&
  342. IsSpaceOrNewLine(*(this->m_szFile+5)))
  343. {
  344. mat.mShading = Dot3DSFile::Phong;
  345. this->m_szFile+=6;
  346. }
  347. else if (0 == strncmp(this->m_szFile,"Flat",4) &&
  348. IsSpaceOrNewLine(*(this->m_szFile+4)))
  349. {
  350. mat.mShading = Dot3DSFile::Flat;
  351. this->m_szFile+=5;
  352. }
  353. else if (0 == strncmp(this->m_szFile,"Wire",4) &&
  354. IsSpaceOrNewLine(*(this->m_szFile+4)))
  355. {
  356. mat.mShading = Dot3DSFile::Wire;
  357. this->m_szFile+=5;
  358. }
  359. else
  360. {
  361. // assume gouraud shading
  362. mat.mShading = Dot3DSFile::Gouraud;
  363. this->SkipToNextToken();
  364. }
  365. continue;
  366. }
  367. // material transparency
  368. if (0 == strncmp(this->m_szFile,"*MATERIAL_TRANSPARENCY",22) &&
  369. IsSpaceOrNewLine(*(this->m_szFile+22)))
  370. {
  371. this->m_szFile+=23;
  372. this->ParseLV4MeshFloat(mat.mTransparency);
  373. mat.mTransparency = 1.0f - mat.mTransparency;continue;
  374. }
  375. // material self illumination
  376. if (0 == strncmp(this->m_szFile,"*MATERIAL_SELFILLUM",19) &&
  377. IsSpaceOrNewLine(*(this->m_szFile+19)))
  378. {
  379. this->m_szFile+=20;
  380. float f = 0.0f;
  381. this->ParseLV4MeshFloat(f);
  382. mat.mEmissive.r = f;
  383. mat.mEmissive.g = f;
  384. mat.mEmissive.b = f;
  385. continue;
  386. }
  387. // material shininess
  388. if (0 == strncmp(this->m_szFile,"*MATERIAL_SHINE",15) &&
  389. IsSpaceOrNewLine(*(this->m_szFile+15)))
  390. {
  391. this->m_szFile+=16;
  392. this->ParseLV4MeshFloat(mat.mSpecularExponent);
  393. mat.mSpecularExponent *= 15;continue;
  394. }
  395. // material shininess strength
  396. if (0 == strncmp(this->m_szFile,"*MATERIAL_SHINESTRENGTH",23) &&
  397. IsSpaceOrNewLine(*(this->m_szFile+23)))
  398. {
  399. this->m_szFile+=24;
  400. this->ParseLV4MeshFloat(mat.mShininessStrength);continue;
  401. }
  402. // diffuse color map
  403. if (0 == strncmp(this->m_szFile,"*MAP_DIFFUSE",12) &&
  404. IsSpaceOrNewLine(*(this->m_szFile+12)))
  405. {
  406. this->m_szFile+=13;
  407. // skip the opening bracket
  408. this->SkipOpeningBracket();
  409. // parse the texture block
  410. this->ParseLV3MapBlock(mat.sTexDiffuse);continue;
  411. }
  412. // ambient color map
  413. if (0 == strncmp(this->m_szFile,"*MAP_AMBIENT",12) &&
  414. IsSpaceOrNewLine(*(this->m_szFile+12)))
  415. {
  416. this->m_szFile+=13;
  417. // skip the opening bracket
  418. this->SkipOpeningBracket();
  419. // parse the texture block
  420. this->ParseLV3MapBlock(mat.sTexAmbient);continue;
  421. }
  422. // specular color map
  423. if (0 == strncmp(this->m_szFile,"*MAP_SPECULAR",13) &&
  424. IsSpaceOrNewLine(*(this->m_szFile+13)))
  425. {
  426. this->m_szFile+=14;
  427. // skip the opening bracket
  428. this->SkipOpeningBracket();
  429. // parse the texture block
  430. this->ParseLV3MapBlock(mat.sTexSpecular);continue;
  431. }
  432. // opacity map
  433. if (0 == strncmp(this->m_szFile,"*MAP_OPACITY",12) &&
  434. IsSpaceOrNewLine(*(this->m_szFile+12)))
  435. {
  436. this->m_szFile+=13;
  437. // skip the opening bracket
  438. this->SkipOpeningBracket();
  439. // parse the texture block
  440. this->ParseLV3MapBlock(mat.sTexOpacity);continue;
  441. }
  442. // emissive map
  443. if (0 == strncmp(this->m_szFile,"*MAP_SELFILLUM",14) &&
  444. IsSpaceOrNewLine(*(this->m_szFile+14)))
  445. {
  446. this->m_szFile+=15;
  447. // skip the opening bracket
  448. this->SkipOpeningBracket();
  449. // parse the texture block
  450. this->ParseLV3MapBlock(mat.sTexEmissive);continue;
  451. }
  452. // bump map
  453. if (0 == strncmp(this->m_szFile,"*MAP_BUMP",9) &&
  454. IsSpaceOrNewLine(*(this->m_szFile+9)))
  455. {
  456. this->m_szFile+=10;
  457. // skip the opening bracket
  458. this->SkipOpeningBracket();
  459. // parse the texture block
  460. this->ParseLV3MapBlock(mat.sTexBump);
  461. }
  462. // specular/shininess map
  463. if (0 == strncmp(this->m_szFile,"*MAP_SHINE",10) &&
  464. IsSpaceOrNewLine(*(this->m_szFile+10)))
  465. {
  466. this->m_szFile+=11;
  467. // skip the opening bracket
  468. this->SkipOpeningBracket();
  469. // parse the texture block
  470. this->ParseLV3MapBlock(mat.sTexShininess);continue;
  471. }
  472. // number of submaterials
  473. if (0 == strncmp(this->m_szFile,"*NUMSUBMTLS",11) &&
  474. IsSpaceOrNewLine(*(this->m_szFile+11)))
  475. {
  476. this->m_szFile+=12;
  477. this->ParseLV4MeshLong(iNumSubMaterials);
  478. // allocate enough storage
  479. mat.avSubMaterials.resize(iNumSubMaterials);
  480. }
  481. // submaterial chunks
  482. if (0 == strncmp(this->m_szFile,"*SUBMATERIAL",12) &&
  483. IsSpaceOrNewLine(*(this->m_szFile+12)))
  484. {
  485. this->m_szFile+=13;
  486. unsigned int iIndex = 0;
  487. this->ParseLV4MeshLong(iIndex);
  488. if (iIndex >= iNumSubMaterials)
  489. {
  490. this->LogWarning("Out of range: submaterial index is too large");
  491. iIndex = iNumSubMaterials-1;
  492. }
  493. // get a reference to the material
  494. Material& sMat = mat.avSubMaterials[iIndex];
  495. // skip the '{'
  496. this->SkipOpeningBracket();
  497. // parse the material block
  498. this->ParseLV2MaterialBlock(sMat);
  499. continue;
  500. }
  501. }
  502. else if ('{' == *this->m_szFile)iDepth++;
  503. else if ('}' == *this->m_szFile)
  504. {
  505. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  506. }
  507. else if ('\0' == *this->m_szFile)
  508. {
  509. // END OF FILE ... this is a level2 block, this can't be
  510. BLUBB("Unable to finish parsing a lv2 material block. Unexpected EOF")
  511. }
  512. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  513. ++this->m_szFile;
  514. }
  515. return;
  516. }
  517. // ------------------------------------------------------------------------------------------------
  518. void Parser::ParseLV3MapBlock(Texture& map)
  519. {
  520. int iDepth = 0;
  521. unsigned int iNumSubMaterials = 0;
  522. while (true)
  523. {
  524. if ('*' == *this->m_szFile)
  525. {
  526. // path to the texture
  527. if (0 == strncmp(this->m_szFile,"*BITMAP" ,7) &&
  528. IsSpaceOrNewLine(*(this->m_szFile+7)))
  529. {
  530. this->m_szFile+=8;
  531. if(!this->ParseString(map.mMapName,"*BITMAP"))SkipToNextToken();
  532. continue;
  533. }
  534. // offset on the u axis
  535. if (0 == strncmp(this->m_szFile,"*UVW_U_OFFSET" ,13) &&
  536. IsSpaceOrNewLine(*(this->m_szFile+13)))
  537. {
  538. this->m_szFile+=14;
  539. this->ParseLV4MeshFloat(map.mOffsetU);continue;
  540. }
  541. // offset on the v axis
  542. if (0 == strncmp(this->m_szFile,"*UVW_V_OFFSET" ,13) &&
  543. IsSpaceOrNewLine(*(this->m_szFile+13)))
  544. {
  545. this->m_szFile+=14;
  546. this->ParseLV4MeshFloat(map.mOffsetV);continue;
  547. }
  548. // tiling on the u axis
  549. if (0 == strncmp(this->m_szFile,"*UVW_U_TILING" ,13) &&
  550. IsSpaceOrNewLine(*(this->m_szFile+13)))
  551. {
  552. this->m_szFile+=14;
  553. this->ParseLV4MeshFloat(map.mScaleU);continue;
  554. }
  555. // tiling on the v axis
  556. if (0 == strncmp(this->m_szFile,"*UVW_V_TILING" ,13) &&
  557. IsSpaceOrNewLine(*(this->m_szFile+13)))
  558. {
  559. this->m_szFile+=14;
  560. this->ParseLV4MeshFloat(map.mScaleV);continue;
  561. }
  562. // rotation around the z-axis
  563. if (0 == strncmp(this->m_szFile,"*UVW_ANGLE" ,10) &&
  564. IsSpaceOrNewLine(*(this->m_szFile+10)))
  565. {
  566. this->m_szFile+=11;
  567. this->ParseLV4MeshFloat(map.mRotation);continue;
  568. }
  569. // map blending factor
  570. if (0 == strncmp(this->m_szFile,"*MAP_AMOUNT" ,11) &&
  571. IsSpaceOrNewLine(*(this->m_szFile+11)))
  572. {
  573. this->m_szFile+=12;
  574. this->ParseLV4MeshFloat(map.mTextureBlend);continue;
  575. }
  576. }
  577. else if ('{' == *this->m_szFile)iDepth++;
  578. else if ('}' == *this->m_szFile)
  579. {
  580. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  581. }
  582. else if ('\0' == *this->m_szFile)
  583. {
  584. // END OF FILE ... this is a level3 block, this can't be
  585. BLUBB("Unable to finish parsing a lv3 map block. Unexpected EOF")
  586. }
  587. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  588. ++this->m_szFile;
  589. }
  590. return;
  591. }
  592. // ------------------------------------------------------------------------------------------------
  593. bool Parser::ParseString(std::string& out,const char* szName)
  594. {
  595. char szBuffer[1024];
  596. ai_assert(strlen(szName) < 750);
  597. // NOTE: The name could also be the texture in some cases
  598. // be prepared that this might occur ...
  599. if (!SkipSpaces(this->m_szFile,&this->m_szFile))
  600. {
  601. sprintf(szBuffer,"Unable to parse %s block: Unexpected EOL",szName);
  602. this->LogWarning(szBuffer);
  603. return false;
  604. }
  605. // there must be "
  606. if ('\"' != *this->m_szFile)
  607. {
  608. sprintf(szBuffer,"Unable to parse %s block: String is expected "
  609. "to be enclosed in double quotation marks",szName);
  610. this->LogWarning(szBuffer);
  611. return false;
  612. }
  613. ++this->m_szFile;
  614. const char* sz = this->m_szFile;
  615. while (true)
  616. {
  617. if ('\"' == *sz)break;
  618. else if ('\0' == sz)
  619. {
  620. sprintf(szBuffer,"Unable to parse %s block: String is expected to be "
  621. "enclosed in double quotation marks but EOF was reached before a closing "
  622. "quotation mark was found",szName);
  623. this->LogWarning(szBuffer);
  624. return false;
  625. }
  626. sz++;
  627. }
  628. out = std::string(this->m_szFile,(uintptr_t)sz-(uintptr_t)this->m_szFile);
  629. this->m_szFile = sz;
  630. return true;
  631. }
  632. // ------------------------------------------------------------------------------------------------
  633. void Parser::ParseLV1GeometryObjectBlock(ASE::Mesh& mesh)
  634. {
  635. int iDepth = 0;
  636. while (true)
  637. {
  638. if ('*' == *this->m_szFile)
  639. {
  640. // name of the mesh/node
  641. if (0 == strncmp(this->m_szFile,"*NODE_NAME" ,10) &&
  642. IsSpaceOrNewLine(*(this->m_szFile+10)))
  643. {
  644. this->m_szFile+=11;
  645. if(!this->ParseString(mesh.mName,"*NODE_NAME"))this->SkipToNextToken();
  646. continue;
  647. }
  648. // name of the parent of the node
  649. if (0 == strncmp(this->m_szFile,"*NODE_PARENT" ,12) &&
  650. IsSpaceOrNewLine(*(this->m_szFile+12)))
  651. {
  652. this->m_szFile+=13;
  653. if(!this->ParseString(mesh.mParent,"*NODE_PARENT"))this->SkipToNextToken();
  654. continue;
  655. }
  656. // transformation matrix of the node
  657. if (0 == strncmp(this->m_szFile,"*NODE_TM" ,8) &&
  658. IsSpaceOrNewLine(*(this->m_szFile+8)))
  659. {
  660. this->m_szFile+=9;
  661. this->ParseLV2NodeTransformBlock(mesh);continue;
  662. }
  663. // mesh data
  664. if (0 == strncmp(this->m_szFile,"*MESH" ,5) &&
  665. IsSpaceOrNewLine(*(this->m_szFile+5)))
  666. {
  667. this->m_szFile+=6;
  668. this->ParseLV2MeshBlock(mesh);continue;
  669. }
  670. // mesh material index
  671. if (0 == strncmp(this->m_szFile,"*MATERIAL_REF" ,13) &&
  672. IsSpaceOrNewLine(*(this->m_szFile+13)))
  673. {
  674. this->m_szFile+=14;
  675. this->ParseLV4MeshLong(mesh.iMaterialIndex);continue;
  676. }
  677. }
  678. else if ('{' == *this->m_szFile)iDepth++;
  679. else if ('}' == *this->m_szFile)
  680. {
  681. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  682. }
  683. else if ('\0' == *this->m_szFile)
  684. {
  685. // END OF FILE ... this is a level1 block, this can be
  686. return;
  687. }
  688. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  689. ++this->m_szFile;
  690. }
  691. return;
  692. }
  693. // ------------------------------------------------------------------------------------------------
  694. void Parser::ParseLV2NodeTransformBlock(ASE::Mesh& mesh)
  695. {
  696. int iDepth = 0;
  697. while (true)
  698. {
  699. if ('*' == *this->m_szFile)
  700. {
  701. // first row of the transformation matrix
  702. if (0 == strncmp(this->m_szFile,"*TM_ROW0" ,8) &&
  703. IsSpaceOrNewLine(*(this->m_szFile+8)))
  704. {
  705. this->m_szFile+=9;
  706. this->ParseLV4MeshFloatTriple(mesh.mTransform[0]);continue;
  707. }
  708. // second row of the transformation matrix
  709. if (0 == strncmp(this->m_szFile,"*TM_ROW1" ,8) &&
  710. IsSpaceOrNewLine(*(this->m_szFile+8)))
  711. {
  712. this->m_szFile+=9;
  713. this->ParseLV4MeshFloatTriple(mesh.mTransform[1]);continue;
  714. }
  715. // third row of the transformation matrix
  716. if (0 == strncmp(this->m_szFile,"*TM_ROW2" ,8) &&
  717. IsSpaceOrNewLine(*(this->m_szFile+8)))
  718. {
  719. this->m_szFile+=9;
  720. this->ParseLV4MeshFloatTriple(mesh.mTransform[2]);continue;
  721. }
  722. // fourth row of the transformation matrix
  723. if (0 == strncmp(this->m_szFile,"*TM_ROW3" ,8) &&
  724. IsSpaceOrNewLine(*(this->m_szFile+8)))
  725. {
  726. this->m_szFile+=9;
  727. this->ParseLV4MeshFloatTriple(mesh.mTransform[3]);continue;
  728. }
  729. }
  730. else if ('{' == *this->m_szFile)iDepth++;
  731. else if ('}' == *this->m_szFile)
  732. {
  733. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  734. }
  735. else if ('\0' == *this->m_szFile)
  736. {
  737. // END OF FILE ... this is a level2 block, this can't be
  738. BLUBB("Unable to finish parsing a lv2 node transform block. Unexpected EOF")
  739. }
  740. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  741. ++this->m_szFile;
  742. }
  743. return;
  744. }
  745. // ------------------------------------------------------------------------------------------------
  746. void Parser::ParseLV2MeshBlock(ASE::Mesh& mesh)
  747. {
  748. unsigned int iNumVertices = 0;
  749. unsigned int iNumFaces = 0;
  750. unsigned int iNumTVertices = 0;
  751. unsigned int iNumTFaces = 0;
  752. unsigned int iNumCVertices = 0;
  753. unsigned int iNumCFaces = 0;
  754. int iDepth = 0;
  755. while (true)
  756. {
  757. if ('*' == *this->m_szFile)
  758. {
  759. // Number of vertices in the mesh
  760. if (0 == strncmp(this->m_szFile,"*MESH_NUMVERTEX" ,15) &&
  761. IsSpaceOrNewLine(*(this->m_szFile+15)))
  762. {
  763. this->m_szFile+=16;
  764. this->ParseLV4MeshLong(iNumVertices);continue;
  765. }
  766. // Number of texture coordinates in the mesh
  767. if (0 == strncmp(this->m_szFile,"*MESH_NUMTVERTEX" ,16) &&
  768. IsSpaceOrNewLine(*(this->m_szFile+16)))
  769. {
  770. this->m_szFile+=17;
  771. this->ParseLV4MeshLong(iNumTVertices);continue;
  772. }
  773. // Number of vertex colors in the mesh
  774. if (0 == strncmp(this->m_szFile,"*MESH_NUMCVERTEX" ,16) &&
  775. IsSpaceOrNewLine(*(this->m_szFile+16)))
  776. {
  777. this->m_szFile+=17;
  778. this->ParseLV4MeshLong(iNumCVertices);continue;
  779. }
  780. // Number of regular faces in the mesh
  781. if (0 == strncmp(this->m_szFile,"*MESH_NUMFACES" ,14) &&
  782. IsSpaceOrNewLine(*(this->m_szFile+14)))
  783. {
  784. this->m_szFile+=15;
  785. this->ParseLV4MeshLong(iNumFaces);continue;
  786. // fix ...
  787. //mesh.mFaces.resize(iNumFaces);
  788. }
  789. // Number of UVWed faces in the mesh
  790. if (0 == strncmp(this->m_szFile,"*MESH_NUMTVFACES" ,16) &&
  791. IsSpaceOrNewLine(*(this->m_szFile+16)))
  792. {
  793. this->m_szFile+=17;
  794. this->ParseLV4MeshLong(iNumTFaces);continue;
  795. }
  796. // Number of colored faces in the mesh
  797. if (0 == strncmp(this->m_szFile,"*MESH_NUMCVFACES" ,16) &&
  798. IsSpaceOrNewLine(*(this->m_szFile+16)))
  799. {
  800. this->m_szFile+=17;
  801. this->ParseLV4MeshLong(iNumCFaces);continue;
  802. }
  803. // mesh vertex list block
  804. if (0 == strncmp(this->m_szFile,"*MESH_VERTEX_LIST" ,17) &&
  805. IsSpaceOrNewLine(*(this->m_szFile+17)))
  806. {
  807. this->m_szFile+=18;
  808. this->ParseLV3MeshVertexListBlock(iNumVertices,mesh);
  809. continue;
  810. }
  811. // mesh face list block
  812. if (0 == strncmp(this->m_szFile,"*MESH_FACE_LIST" ,15) &&
  813. IsSpaceOrNewLine(*(this->m_szFile+15)))
  814. {
  815. this->m_szFile+=16;
  816. this->SkipOpeningBracket();
  817. this->ParseLV3MeshFaceListBlock(iNumFaces,mesh);continue;
  818. }
  819. // mesh texture vertex list block
  820. if (0 == strncmp(this->m_szFile,"*MESH_TVERTLIST" ,15) &&
  821. IsSpaceOrNewLine(*(this->m_szFile+15)))
  822. {
  823. this->m_szFile+=16;
  824. this->SkipOpeningBracket();
  825. this->ParseLV3MeshTListBlock(iNumTVertices,mesh);continue;
  826. }
  827. // mesh texture face block
  828. if (0 == strncmp(this->m_szFile,"*MESH_TFACELIST" ,15) &&
  829. IsSpaceOrNewLine(*(this->m_szFile+15)))
  830. {
  831. this->m_szFile+=16;
  832. this->SkipOpeningBracket();
  833. this->ParseLV3MeshTFaceListBlock(iNumTFaces,mesh);continue;
  834. }
  835. // mesh color vertex list block
  836. if (0 == strncmp(this->m_szFile,"*MESH_CVERTLIST" ,15) &&
  837. IsSpaceOrNewLine(*(this->m_szFile+15)))
  838. {
  839. this->m_szFile+=16;
  840. this->SkipOpeningBracket();
  841. this->ParseLV3MeshCListBlock(iNumCVertices,mesh);continue;
  842. }
  843. // mesh color face block
  844. if (0 == strncmp(this->m_szFile,"*MESH_CFACELIST" ,15) &&
  845. IsSpaceOrNewLine(*(this->m_szFile+15)))
  846. {
  847. this->m_szFile+=16;
  848. this->SkipOpeningBracket();
  849. this->ParseLV3MeshCFaceListBlock(iNumCFaces,mesh);continue;
  850. }
  851. // another mesh UV channel ...
  852. if (0 == strncmp(this->m_szFile,"*MESH_MAPPINGCHANNEL" ,20) &&
  853. IsSpaceOrNewLine(*(this->m_szFile+20)))
  854. {
  855. this->m_szFile+=21;
  856. unsigned int iIndex = 0;
  857. this->ParseLV4MeshLong(iIndex);
  858. if (iIndex < 2)
  859. {
  860. this->LogWarning("Mapping channel has an invalid index. Skipping UV channel");
  861. // skip it ...
  862. this->SkipOpeningBracket();
  863. this->SkipSection();
  864. }
  865. if (iIndex > AI_MAX_NUMBER_OF_TEXTURECOORDS)
  866. {
  867. this->LogWarning("Too many UV channels specified. Skipping channel ..");
  868. // skip it ...
  869. this->SkipOpeningBracket();
  870. this->SkipSection();
  871. }
  872. else
  873. {
  874. // skip the '{'
  875. this->SkipOpeningBracket();
  876. // parse the mapping channel
  877. this->ParseLV3MappingChannel(iIndex-1,mesh);
  878. }
  879. continue;
  880. }
  881. // mesh animation keyframe. Not supported
  882. if (0 == strncmp(this->m_szFile,"*MESH_ANIMATION" ,15) &&
  883. IsSpaceOrNewLine(*(this->m_szFile+15)))
  884. {
  885. this->m_szFile+=16;
  886. this->LogWarning("Found *MESH_ANIMATION element in ASE/ASK file. "
  887. "Keyframe animation is not supported by Assimp, this element "
  888. "will be ignored");
  889. continue;
  890. }
  891. // mesh animation keyframe. Not supported
  892. if (0 == strncmp(this->m_szFile,"*MESH_WEIGHTS" ,13) &&
  893. IsSpaceOrNewLine(*(this->m_szFile+13)))
  894. {
  895. this->m_szFile+=14;
  896. this->ParseLV3MeshWeightsBlock(mesh);continue;
  897. }
  898. }
  899. else if ('{' == *this->m_szFile)iDepth++;
  900. else if ('}' == *this->m_szFile)
  901. {
  902. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  903. }
  904. else if ('\0' == *this->m_szFile)
  905. {
  906. // END OF FILE ... this is a level2 block, this can't be
  907. BLUBB("Unable to finish parsing a lv2 mesh block. Unexpected EOF")
  908. }
  909. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  910. ++this->m_szFile;
  911. }
  912. return;
  913. }
  914. // ------------------------------------------------------------------------------------------------
  915. void Parser::ParseLV3MeshWeightsBlock(ASE::Mesh& mesh)
  916. {
  917. unsigned int iNumVertices = 0;
  918. unsigned int iNumBones = 0;
  919. int iDepth = 0;
  920. while (true)
  921. {
  922. if ('*' == *this->m_szFile)
  923. {
  924. // Number of bone vertices ...
  925. if (0 == strncmp(this->m_szFile,"*MESH_NUMVERTEX" ,15) &&
  926. IsSpaceOrNewLine(*(this->m_szFile+15)))
  927. {
  928. this->m_szFile+=16;
  929. this->ParseLV4MeshLong(iNumVertices);continue;
  930. }
  931. // Number of bones
  932. if (0 == strncmp(this->m_szFile,"*MESH_NUMBONE" ,13) &&
  933. IsSpaceOrNewLine(*(this->m_szFile+13)))
  934. {
  935. this->m_szFile+=14;
  936. this->ParseLV4MeshLong(iNumBones);continue;
  937. }
  938. // parse the list of bones
  939. if (0 == strncmp(this->m_szFile,"*MESH_BONE_LIST" ,15) &&
  940. IsSpaceOrNewLine(*(this->m_szFile+15)))
  941. {
  942. this->m_szFile+=16;
  943. this->SkipOpeningBracket();
  944. this->ParseLV4MeshBones(iNumBones,mesh);continue;
  945. }
  946. // parse the list of bones vertices
  947. if (0 == strncmp(this->m_szFile,"*MESH_BONE_VERTEX_LIST" ,22) &&
  948. IsSpaceOrNewLine(*(this->m_szFile+22)))
  949. {
  950. this->m_szFile+=23;
  951. this->SkipOpeningBracket();
  952. this->ParseLV4MeshBonesVertices(iNumVertices,mesh);
  953. continue;
  954. }
  955. }
  956. else if ('{' == *this->m_szFile)iDepth++;
  957. else if ('}' == *this->m_szFile)
  958. {
  959. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  960. }
  961. else if ('\0' == *this->m_szFile)
  962. {
  963. // END OF FILE ... this is a level2 block, this can't be
  964. BLUBB("Unable to finish parsing a lv2 *MESH_WEIGHTS block. Unexpected EOF")
  965. }
  966. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  967. ++this->m_szFile;
  968. }
  969. return;
  970. }
  971. // ------------------------------------------------------------------------------------------------
  972. void Parser::ParseLV4MeshBones(unsigned int iNumBones,ASE::Mesh& mesh)
  973. {
  974. mesh.mBones.resize(iNumBones);
  975. int iDepth = 0;
  976. while (true)
  977. {
  978. if ('*' == *this->m_szFile)
  979. {
  980. // Mesh bone with name ...
  981. if (0 == strncmp(this->m_szFile,"*MESH_BONE_NAME" ,17) &&
  982. IsSpaceOrNewLine(*(this->m_szFile+17)))
  983. {
  984. this->m_szFile+=18;
  985. // parse an index ...
  986. if(SkipSpaces(this->m_szFile,&this->m_szFile))
  987. {
  988. unsigned int iIndex = strtol10(this->m_szFile,&this->m_szFile);
  989. if (iIndex >= iNumBones)
  990. {
  991. iIndex = iNumBones-1;
  992. this->LogWarning("Bone index is out of bounds. Using the largest valid "
  993. "bone index instead");
  994. }
  995. if (!this->ParseString(mesh.mBones[iIndex].mName,"*MESH_BONE_NAME"))
  996. this->SkipToNextToken();
  997. continue;
  998. }
  999. }
  1000. }
  1001. else if ('{' == *this->m_szFile)iDepth++;
  1002. else if ('}' == *this->m_szFile)
  1003. {
  1004. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1005. }
  1006. else if ('\0' == *this->m_szFile)
  1007. {
  1008. // END OF FILE ... this is a level4 block, this can't be
  1009. BLUBB("Unable to finish parsing a lv4 *MESH_BONE_LIST block. Unexpected EOF")
  1010. }
  1011. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1012. ++this->m_szFile;
  1013. }
  1014. }
  1015. // ------------------------------------------------------------------------------------------------
  1016. void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices,ASE::Mesh& mesh)
  1017. {
  1018. mesh.mBoneVertices.resize(iNumVertices);
  1019. int iDepth = 0;
  1020. while (true)
  1021. {
  1022. if ('*' == *this->m_szFile)
  1023. {
  1024. // Mesh bone vertex
  1025. if (0 == strncmp(this->m_szFile,"*MESH_BONE_VERTEX" ,17) &&
  1026. IsSpaceOrNewLine(*(this->m_szFile+17)))
  1027. {
  1028. this->m_szFile+=18;
  1029. // read the vertex index
  1030. unsigned int iIndex = strtol10(this->m_szFile,&this->m_szFile);
  1031. if (iIndex >= mesh.mPositions.size())
  1032. {
  1033. iIndex = mesh.mPositions.size()-1;
  1034. this->LogWarning("Bone vertex index is out of bounds. Using the largest valid "
  1035. "bone vertex index instead");
  1036. }
  1037. // now there there are 3 normal floats, the
  1038. // should be identical to the vertex positions
  1039. // contained in the *VERTEX_LIST block. Well, we check this
  1040. // in debug builds to be sure ;-)
  1041. float afVert[3];
  1042. this->ParseLV4MeshFloatTriple(afVert);
  1043. std::pair<int,float> pairOut;
  1044. while (true)
  1045. {
  1046. // first parse the bone index ...
  1047. if (!SkipSpaces(this->m_szFile,&this->m_szFile))break;
  1048. pairOut.first = strtol10(this->m_szFile,&this->m_szFile);
  1049. // then parse the vertex weight
  1050. if (!SkipSpaces(this->m_szFile,&this->m_szFile))break;
  1051. this->m_szFile = fast_atof_move(this->m_szFile,pairOut.second);
  1052. // -1 designates unused entries
  1053. if (-1 != pairOut.first)
  1054. {
  1055. mesh.mBoneVertices[iIndex].mBoneWeights.push_back(pairOut);
  1056. }
  1057. }
  1058. continue;
  1059. }
  1060. }
  1061. else if ('{' == *this->m_szFile)iDepth++;
  1062. else if ('}' == *this->m_szFile)
  1063. {
  1064. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1065. }
  1066. else if ('\0' == *this->m_szFile)
  1067. {
  1068. // END OF FILE ... this is a level4 block, this can't be
  1069. BLUBB("Unable to finish parsing a lv4 *MESH_BONE_VERTEX_LIST block. Unexpected EOF")
  1070. }
  1071. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1072. ++this->m_szFile;
  1073. }
  1074. return;
  1075. }
  1076. // ------------------------------------------------------------------------------------------------
  1077. void Parser::ParseLV3MeshVertexListBlock(
  1078. unsigned int iNumVertices, ASE::Mesh& mesh)
  1079. {
  1080. // allocate enough storage in the array
  1081. mesh.mPositions.resize(iNumVertices);
  1082. int iDepth = 0;
  1083. while (true)
  1084. {
  1085. if ('*' == *this->m_szFile)
  1086. {
  1087. // Vertex entry
  1088. if (0 == strncmp(this->m_szFile,"*MESH_VERTEX" ,12) &&
  1089. IsSpaceOrNewLine(*(this->m_szFile+12)))
  1090. {
  1091. this->m_szFile+=13;
  1092. aiVector3D vTemp;
  1093. unsigned int iIndex;
  1094. this->ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
  1095. if (iIndex >= iNumVertices)
  1096. {
  1097. this->LogWarning("Vertex has an invalid index. It will be ignored");
  1098. }
  1099. else mesh.mPositions[iIndex] = vTemp;
  1100. continue;
  1101. }
  1102. }
  1103. else if ('{' == *this->m_szFile)iDepth++;
  1104. else if ('}' == *this->m_szFile)
  1105. {
  1106. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1107. }
  1108. else if ('\0' == *this->m_szFile)
  1109. {
  1110. // END OF FILE ... this is a level3 block, this can't be
  1111. BLUBB("Unable to finish parsing a lv3 vertex list block. Unexpected EOF")
  1112. }
  1113. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1114. ++this->m_szFile;
  1115. }
  1116. return;
  1117. }
  1118. // ------------------------------------------------------------------------------------------------
  1119. void Parser::ParseLV3MeshFaceListBlock(unsigned int iNumFaces, ASE::Mesh& mesh)
  1120. {
  1121. // allocate enough storage in the face array
  1122. mesh.mFaces.resize(iNumFaces);
  1123. int iDepth = 0;
  1124. while (true)
  1125. {
  1126. if ('*' == *this->m_szFile)
  1127. {
  1128. // Face entry
  1129. if (0 == strncmp(this->m_szFile,"*MESH_FACE" ,10) &&
  1130. IsSpaceOrNewLine(*(this->m_szFile+10)))
  1131. {
  1132. this->m_szFile+=11;
  1133. ASE::Face mFace;
  1134. this->ParseLV4MeshFace(mFace);
  1135. if (mFace.iFace >= iNumFaces)
  1136. {
  1137. this->LogWarning("Face has an invalid index. It will be ignored");
  1138. }
  1139. else mesh.mFaces[mFace.iFace] = mFace;
  1140. continue;
  1141. }
  1142. }
  1143. else if ('{' == *this->m_szFile)iDepth++;
  1144. else if ('}' == *this->m_szFile)
  1145. {
  1146. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1147. }
  1148. else if ('\0' == *this->m_szFile)
  1149. {
  1150. // END OF FILE ... this is a level3 block, this can't be
  1151. BLUBB("Unable to finish parsing LV3 *MESH_FACE_LIST block. Unexpected EOF")
  1152. }
  1153. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1154. ++this->m_szFile;
  1155. }
  1156. return;
  1157. }
  1158. // ------------------------------------------------------------------------------------------------
  1159. void Parser::ParseLV3MeshTListBlock(unsigned int iNumVertices,
  1160. ASE::Mesh& mesh, unsigned int iChannel)
  1161. {
  1162. // allocate enough storage in the array
  1163. mesh.amTexCoords[iChannel].resize(iNumVertices);
  1164. int iDepth = 0;
  1165. while (true)
  1166. {
  1167. if ('*' == *this->m_szFile)
  1168. {
  1169. // Vertex entry
  1170. if (0 == strncmp(this->m_szFile,"*MESH_TVERT" ,11) &&
  1171. IsSpaceOrNewLine(*(this->m_szFile+11)))
  1172. {
  1173. this->m_szFile+=12;
  1174. aiVector3D vTemp;
  1175. unsigned int iIndex;
  1176. this->ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
  1177. if (iIndex >= iNumVertices)
  1178. {
  1179. this->LogWarning("Tvertex has an invalid index. It will be ignored");
  1180. }
  1181. else mesh.amTexCoords[iChannel][iIndex] = vTemp;
  1182. if (0.0f != vTemp.z)
  1183. {
  1184. // we need 3 coordinate channels
  1185. mesh.mNumUVComponents[iChannel] = 3;
  1186. }
  1187. continue;
  1188. }
  1189. }
  1190. else if ('{' == *this->m_szFile)iDepth++;
  1191. else if ('}' == *this->m_szFile)
  1192. {
  1193. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1194. }
  1195. else if ('\0' == *this->m_szFile)
  1196. {
  1197. // END OF FILE ... this is a level3 block, this can't be
  1198. BLUBB("Unable to finish parsing LV3 *MESH_VERTEX_LIST block. Unexpected EOF")
  1199. }
  1200. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1201. ++this->m_szFile;
  1202. }
  1203. return;
  1204. }
  1205. // ------------------------------------------------------------------------------------------------
  1206. void Parser::ParseLV3MeshTFaceListBlock(unsigned int iNumFaces,
  1207. ASE::Mesh& mesh, unsigned int iChannel)
  1208. {
  1209. int iDepth = 0;
  1210. while (true)
  1211. {
  1212. if ('*' == *this->m_szFile)
  1213. {
  1214. // Face entry
  1215. if (0 == strncmp(this->m_szFile,"*MESH_TFACE" ,12) &&
  1216. IsSpaceOrNewLine(*(this->m_szFile+12)))
  1217. {
  1218. this->m_szFile+=13;
  1219. unsigned int aiValues[3];
  1220. unsigned int iIndex = 0;
  1221. this->ParseLV4MeshLongTriple(aiValues,iIndex);
  1222. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
  1223. {
  1224. this->LogWarning("UV-Face has an invalid index. It will be ignored");
  1225. }
  1226. else
  1227. {
  1228. // copy UV indices
  1229. mesh.mFaces[iIndex].amUVIndices[iChannel][0] = aiValues[0];
  1230. mesh.mFaces[iIndex].amUVIndices[iChannel][1] = aiValues[1];
  1231. mesh.mFaces[iIndex].amUVIndices[iChannel][2] = aiValues[2];
  1232. }
  1233. continue;
  1234. }
  1235. }
  1236. else if ('{' == *this->m_szFile)iDepth++;
  1237. else if ('}' == *this->m_szFile)
  1238. {
  1239. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1240. }
  1241. else if ('\0' == *this->m_szFile)
  1242. {
  1243. // END OF FILE ... this is a level3 block, this can't be
  1244. BLUBB("Unable to finish parsing LV3 *MESH_TFACELIST block. Unexpected EOF")
  1245. }
  1246. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1247. ++this->m_szFile;
  1248. }
  1249. return;
  1250. }
  1251. // ------------------------------------------------------------------------------------------------
  1252. void Parser::ParseLV3MappingChannel(unsigned int iChannel, ASE::Mesh& mesh)
  1253. {
  1254. unsigned int iNumTVertices = 0;
  1255. unsigned int iNumTFaces = 0;
  1256. int iDepth = 0;
  1257. while (true)
  1258. {
  1259. if ('*' == *this->m_szFile)
  1260. {
  1261. // Number of texture coordinates in the mesh
  1262. if (0 == strncmp(this->m_szFile,"*MESH_NUMTVERTEX" ,16) &&
  1263. IsSpaceOrNewLine(*(this->m_szFile+16)))
  1264. {
  1265. this->m_szFile+=17;
  1266. this->ParseLV4MeshLong(iNumTVertices);continue;
  1267. }
  1268. // Number of UVWed faces in the mesh
  1269. if (0 == strncmp(this->m_szFile,"*MESH_NUMTVFACES" ,16) &&
  1270. IsSpaceOrNewLine(*(this->m_szFile+16)))
  1271. {
  1272. this->m_szFile+=17;
  1273. this->ParseLV4MeshLong(iNumTFaces);continue;
  1274. }
  1275. // mesh texture vertex list block
  1276. if (0 == strncmp(this->m_szFile,"*MESH_TVERTLIST" ,15) &&
  1277. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1278. {
  1279. this->m_szFile+=16;
  1280. this->SkipOpeningBracket();
  1281. this->ParseLV3MeshTListBlock(iNumTVertices,mesh,iChannel);
  1282. continue;
  1283. }
  1284. // mesh texture face block
  1285. if (0 == strncmp(this->m_szFile,"*MESH_TFACELIST" ,15) &&
  1286. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1287. {
  1288. this->m_szFile+=16;
  1289. this->SkipOpeningBracket();
  1290. this->ParseLV3MeshTFaceListBlock(iNumTFaces,mesh, iChannel);
  1291. continue;
  1292. }
  1293. }
  1294. else if ('{' == *this->m_szFile)iDepth++;
  1295. else if ('}' == *this->m_szFile)
  1296. {
  1297. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1298. }
  1299. else if ('\0' == *this->m_szFile)
  1300. {
  1301. // END OF FILE ... this is a level2 block, this can't be
  1302. BLUBB("Unable to finish parsing a LV3 *MESH_MAPPINGCHANNEL block. Unexpected EOF")
  1303. }
  1304. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1305. ++this->m_szFile;
  1306. }
  1307. return;
  1308. }
  1309. // ------------------------------------------------------------------------------------------------
  1310. void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh& mesh)
  1311. {
  1312. // allocate enough storage in the array
  1313. mesh.mVertexColors.resize(iNumVertices);
  1314. int iDepth = 0;
  1315. while (true)
  1316. {
  1317. if ('*' == *this->m_szFile)
  1318. {
  1319. // Vertex entry
  1320. if (0 == strncmp(this->m_szFile,"*MESH_VERTCOL" ,13) &&
  1321. IsSpaceOrNewLine(*(this->m_szFile+13)))
  1322. {
  1323. this->m_szFile+=14;
  1324. aiColor4D vTemp;
  1325. vTemp.a = 1.0f;
  1326. unsigned int iIndex;
  1327. this->ParseLV4MeshFloatTriple(&vTemp.r,iIndex);
  1328. if (iIndex >= iNumVertices)
  1329. {
  1330. this->LogWarning("Vertex color has an invalid index. It will be ignored");
  1331. }
  1332. else mesh.mVertexColors[iIndex] = vTemp;
  1333. continue;
  1334. }
  1335. }
  1336. if ('{' == *this->m_szFile)iDepth++;
  1337. else if ('}' == *this->m_szFile)
  1338. {
  1339. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1340. }
  1341. else if ('\0' == *this->m_szFile)
  1342. {
  1343. // END OF FILE ... this is a level3 block, this can't be
  1344. BLUBB("Unable to finish parsing LV3 *MESH_CVERTLIST block. Unexpected EOF")
  1345. }
  1346. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1347. ++this->m_szFile;
  1348. }
  1349. return;
  1350. }
  1351. // ------------------------------------------------------------------------------------------------
  1352. void Parser::ParseLV3MeshCFaceListBlock(unsigned int iNumFaces, ASE::Mesh& mesh)
  1353. {
  1354. int iDepth = 0;
  1355. while (true)
  1356. {
  1357. if ('*' == *this->m_szFile)
  1358. {
  1359. // Face entry
  1360. if (0 == strncmp(this->m_szFile,"*MESH_CFACE" ,12) &&
  1361. IsSpaceOrNewLine(*(this->m_szFile+12)))
  1362. {
  1363. this->m_szFile+=13;
  1364. unsigned int aiValues[3];
  1365. unsigned int iIndex = 0;
  1366. this->ParseLV4MeshLongTriple(aiValues,iIndex);
  1367. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
  1368. {
  1369. this->LogWarning("UV-Face has an invalid index. It will be ignored");
  1370. }
  1371. else
  1372. {
  1373. // copy color indices
  1374. mesh.mFaces[iIndex].mColorIndices[0] = aiValues[0];
  1375. mesh.mFaces[iIndex].mColorIndices[1] = aiValues[1];
  1376. mesh.mFaces[iIndex].mColorIndices[2] = aiValues[2];
  1377. }
  1378. continue;
  1379. }
  1380. }
  1381. else if ('{' == *this->m_szFile)iDepth++;
  1382. else if ('}' == *this->m_szFile)
  1383. {
  1384. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1385. }
  1386. else if ('\0' == *this->m_szFile)
  1387. {
  1388. // END OF FILE ... this is a level3 block, this can't be
  1389. BLUBB("Unable to finish parsing LV3 *MESH_CFACELIST block. Unexpected EOF")
  1390. }
  1391. else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
  1392. ++this->m_szFile;
  1393. }
  1394. return;
  1395. }
  1396. // ------------------------------------------------------------------------------------------------
  1397. void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh& sMesh)
  1398. {
  1399. // allocate enough storage for the normals
  1400. sMesh.mNormals.resize(sMesh.mPositions.size());
  1401. int iDepth = 0;
  1402. // we need the *MESH_VERTEXNORMAL blocks, ignore the face normals
  1403. // if there are only face normals we calculate them outselfes using the SGs
  1404. while (true)
  1405. {
  1406. if ('*' == *this->m_szFile)
  1407. {
  1408. if (0 == strncmp(this->m_szFile,"*MESH_VERTEXNORMAL",18) && IsSpaceOrNewLine(*(this->m_szFile+18)))
  1409. {
  1410. this->m_szFile += 19;
  1411. // parse a simple float triple
  1412. aiVector3D vNormal;
  1413. unsigned int iIndex = 0;
  1414. this->ParseLV4MeshFloatTriple(&vNormal.x,iIndex);
  1415. if (iIndex >= sMesh.mNormals.size())
  1416. {
  1417. this->LogWarning("Normal index is too large");
  1418. iIndex = sMesh.mNormals.size()-1;
  1419. }
  1420. // important: this->m_szFile might now point to '}' ...
  1421. sMesh.mNormals[iIndex] = vNormal;
  1422. continue;
  1423. }
  1424. }
  1425. else if ('{' == *this->m_szFile)iDepth++;
  1426. else if ('}' == *this->m_szFile)
  1427. {
  1428. if (0 == --iDepth){++this->m_szFile;this->SkipToNextToken();return;}
  1429. }
  1430. // seems we have reached the end of the file ...
  1431. else if ('\0' == *this->m_szFile)
  1432. {
  1433. BLUBB("Unable to parse *MESH_NORMALS Element: Unexpected EOL [#1]")
  1434. }
  1435. this->m_szFile++;
  1436. }
  1437. return;
  1438. }
  1439. // ------------------------------------------------------------------------------------------------
  1440. void Parser::ParseLV4MeshFace(ASE::Face& out)
  1441. {
  1442. // skip spaces and tabs
  1443. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1444. BLUBB("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]")
  1445. // parse the face index
  1446. out.iFace = strtol10(this->m_szFile,&this->m_szFile);
  1447. // next character should be ':'
  1448. if(!SkipSpaces(this->m_szFile,&this->m_szFile) || ':' != *this->m_szFile)
  1449. BLUBB("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]")
  1450. // parse all mesh indices
  1451. ++this->m_szFile;
  1452. for (unsigned int i = 0; i < 3;++i)
  1453. {
  1454. unsigned int iIndex = 0;
  1455. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1456. {
  1457. // LOG
  1458. __EARTHQUAKE_XXL:
  1459. BLUBB("Unable to parse *MESH_FACE Element: Unexpected EOL. A,B or C expected [#3]")
  1460. }
  1461. switch (*this->m_szFile)
  1462. {
  1463. case 'A':
  1464. case 'a':
  1465. break;
  1466. case 'B':
  1467. case 'b':
  1468. iIndex = 1;
  1469. break;
  1470. case 'C':
  1471. case 'c':
  1472. iIndex = 2;
  1473. break;
  1474. default: goto __EARTHQUAKE_XXL;
  1475. };
  1476. ++this->m_szFile;
  1477. // next character should be ':'
  1478. if(!SkipSpaces(this->m_szFile,&this->m_szFile) || ':' != *this->m_szFile)
  1479. BLUBB("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]")
  1480. ++this->m_szFile;
  1481. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1482. BLUBB("Unable to parse *MESH_FACE Element: Unexpected EOL. Vertex index ecpected [#4]")
  1483. out.mIndices[iIndex] = strtol10(this->m_szFile,&this->m_szFile);
  1484. }
  1485. // now we need to skip the AB, BC, CA blocks.
  1486. while (true)
  1487. {
  1488. if ('*' == *this->m_szFile)break;
  1489. if (IsLineEnd(*this->m_szFile))
  1490. {
  1491. //this->iLineNumber++;
  1492. return;
  1493. }
  1494. this->m_szFile++;
  1495. }
  1496. // parse the smoothing group of the face
  1497. if (0 == strncmp(this->m_szFile,"*MESH_SMOOTHING",15) && IsSpaceOrNewLine(*(this->m_szFile+15)))
  1498. {
  1499. this->m_szFile+=16;
  1500. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1501. BLUBB("Unable to parse *MESH_SMOOTHING Element: Unexpected EOL. Smoothing group(s) expected [#5]")
  1502. // parse smoothing groups until we don_t anymore see commas
  1503. // FIX: There needn't always be a value, sad but true
  1504. while (true)
  1505. {
  1506. if (*this->m_szFile < '9' && *this->m_szFile >= '0')
  1507. {
  1508. out.iSmoothGroup |= (1 << strtol10(this->m_szFile,&this->m_szFile));
  1509. }
  1510. SkipSpaces(this->m_szFile,&this->m_szFile);
  1511. if (',' != *this->m_szFile)
  1512. {
  1513. break;
  1514. }
  1515. ++this->m_szFile;
  1516. SkipSpaces(this->m_szFile,&this->m_szFile);
  1517. }
  1518. }
  1519. // *MESH_MTLID is optional, too
  1520. while (true)
  1521. {
  1522. if ('*' == *this->m_szFile)break;
  1523. if (IsLineEnd(*this->m_szFile))
  1524. {
  1525. //this->iLineNumber++;
  1526. return;
  1527. }
  1528. this->m_szFile++;
  1529. }
  1530. if (0 == strncmp(this->m_szFile,"*MESH_MTLID",11) && IsSpaceOrNewLine(*(this->m_szFile+11)))
  1531. {
  1532. this->m_szFile+=12;
  1533. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1534. BLUBB("Unable to parse *MESH_MTLID Element: Unexpected EOL. Material index expected [#6]")
  1535. out.iMaterial = strtol10(this->m_szFile,&this->m_szFile);
  1536. }
  1537. //this->SkipToNextToken();
  1538. return;
  1539. }
  1540. // ------------------------------------------------------------------------------------------------
  1541. void Parser::ParseLV4MeshLongTriple(unsigned int* apOut)
  1542. {
  1543. ai_assert(NULL != apOut);
  1544. // skip spaces and tabs
  1545. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1546. {
  1547. // LOG
  1548. this->LogWarning("Unable to parse indexable long triple: unexpected EOL [#1]");
  1549. ++this->iLineNumber;
  1550. apOut[0] = apOut[1] = apOut[2] = 0;
  1551. return;
  1552. }
  1553. apOut[0] = strtol10(this->m_szFile,&this->m_szFile);
  1554. // skip spaces and tabs
  1555. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1556. {
  1557. // LOG
  1558. this->LogWarning("Unable to parse indexable long triple: unexpected EOL [#2]");
  1559. ++this->iLineNumber;
  1560. apOut[1] = apOut[2] = 0;
  1561. return;
  1562. }
  1563. apOut[1] = strtol10(this->m_szFile,&this->m_szFile);
  1564. // skip spaces and tabs
  1565. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1566. {
  1567. // LOG
  1568. this->LogWarning("Unable to parse indexable long triple: unexpected EOL [#3]");
  1569. apOut[2] = 0;
  1570. ++this->iLineNumber;
  1571. return;
  1572. }
  1573. apOut[2] = strtol10(this->m_szFile,&this->m_szFile);
  1574. // go to the next valid sequence
  1575. //SkipSpacesAndLineEnd(this->m_szFile,&this->m_szFile);
  1576. }
  1577. // ------------------------------------------------------------------------------------------------
  1578. void Parser::ParseLV4MeshLongTriple(unsigned int* apOut, unsigned int& rIndexOut)
  1579. {
  1580. ai_assert(NULL != apOut);
  1581. // skip spaces and tabs
  1582. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1583. {
  1584. // LOG
  1585. this->LogWarning("Unable to parse indexable long triple: unexpected EOL [#4]");
  1586. rIndexOut = 0;
  1587. apOut[0] = apOut[1] = apOut[2] = 0;
  1588. ++this->iLineNumber;
  1589. return;
  1590. }
  1591. // parse the index
  1592. rIndexOut = strtol10(this->m_szFile,&this->m_szFile);
  1593. // parse the three others
  1594. this->ParseLV4MeshLongTriple(apOut);
  1595. return;
  1596. }
  1597. // ------------------------------------------------------------------------------------------------
  1598. void Parser::ParseLV4MeshFloatTriple(float* apOut, unsigned int& rIndexOut)
  1599. {
  1600. ai_assert(NULL != apOut);
  1601. // skip spaces and tabs
  1602. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1603. {
  1604. // LOG
  1605. this->LogWarning("Unable to parse indexable float triple: unexpected EOL [#1]");
  1606. rIndexOut = 0;
  1607. apOut[0] = apOut[1] = apOut[2] = 0.0f;
  1608. ++this->iLineNumber;
  1609. return;
  1610. }
  1611. // parse the index
  1612. rIndexOut = strtol10(this->m_szFile,&this->m_szFile);
  1613. // parse the three others
  1614. this->ParseLV4MeshFloatTriple(apOut);
  1615. return;
  1616. }
  1617. // ------------------------------------------------------------------------------------------------
  1618. void Parser::ParseLV4MeshFloatTriple(float* apOut)
  1619. {
  1620. ai_assert(NULL != apOut);
  1621. // skip spaces and tabs
  1622. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1623. {
  1624. // LOG
  1625. this->LogWarning("Unable to parse float triple: unexpected EOL [#5]");
  1626. apOut[0] = apOut[1] = apOut[2] = 0.0f;
  1627. ++this->iLineNumber;
  1628. return;
  1629. }
  1630. // parse the first float
  1631. this->m_szFile = fast_atof_move(this->m_szFile,apOut[0]);
  1632. // skip spaces and tabs
  1633. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1634. {
  1635. // LOG
  1636. this->LogWarning("Unable to parse float triple: unexpected EOL [#6]");
  1637. apOut[1] = apOut[2] = 0.0f;
  1638. ++this->iLineNumber;
  1639. return;
  1640. }
  1641. // parse the second float
  1642. this->m_szFile = fast_atof_move(this->m_szFile,apOut[1]);
  1643. // skip spaces and tabs
  1644. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1645. {
  1646. // LOG
  1647. this->LogWarning("Unable to parse float triple: unexpected EOL [#7]");
  1648. apOut[2] = 0.0f;
  1649. ++this->iLineNumber;
  1650. return;
  1651. }
  1652. // parse the third float
  1653. this->m_szFile = fast_atof_move(this->m_szFile,apOut[2]);
  1654. // go to the next valid sequence
  1655. //this->SkipToNextToken();
  1656. return;
  1657. }
  1658. // ------------------------------------------------------------------------------------------------
  1659. void Parser::ParseLV4MeshFloat(float& fOut)
  1660. {
  1661. // skip spaces and tabs
  1662. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1663. {
  1664. // LOG
  1665. this->LogWarning("Unable to parse float: unexpected EOL [#1]");
  1666. fOut = 0.0f;
  1667. ++this->iLineNumber;
  1668. return;
  1669. }
  1670. // parse the first float
  1671. this->m_szFile = fast_atof_move(this->m_szFile,fOut);
  1672. // go to the next valid sequence
  1673. //this->SkipToNextToken();
  1674. return;
  1675. }
  1676. // ------------------------------------------------------------------------------------------------
  1677. void Parser::ParseLV4MeshLong(unsigned int& iOut)
  1678. {
  1679. // skip spaces and tabs
  1680. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1681. {
  1682. // LOG
  1683. this->LogWarning("Unable to parse long: unexpected EOL [#1]");
  1684. iOut = 0;
  1685. ++this->iLineNumber;
  1686. return;
  1687. }
  1688. // parse the value
  1689. iOut = strtol10(this->m_szFile,&this->m_szFile);
  1690. // go to the next valid sequence
  1691. //this->SkipToNextToken();
  1692. return;
  1693. }