ASEParser.cpp 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  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 "AssimpPCH.h"
  36. // internal headers
  37. #include "TextureTransform.h"
  38. #include "ASELoader.h"
  39. #include "MaterialSystem.h"
  40. #include "fast_atof.h"
  41. using namespace Assimp;
  42. using namespace Assimp::ASE;
  43. #if (defined BLUBB)
  44. # undef BLUBB
  45. #endif
  46. #define BLUBB(_message_) \
  47. {LogError(_message_);return;}
  48. // ------------------------------------------------------------------------------------------------
  49. #define AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth) \
  50. else if ('{' == *m_szFile)iDepth++; \
  51. else if ('}' == *m_szFile) \
  52. { \
  53. if (0 == --iDepth) \
  54. { \
  55. ++m_szFile; \
  56. SkipToNextToken(); \
  57. return; \
  58. } \
  59. } \
  60. else if ('\0' == *m_szFile) \
  61. { \
  62. return; \
  63. } \
  64. if(IsLineEnd(*m_szFile) && !bLastWasEndLine) \
  65. { \
  66. ++iLineNumber; \
  67. bLastWasEndLine = true; \
  68. } else bLastWasEndLine = false; \
  69. ++m_szFile;
  70. // ------------------------------------------------------------------------------------------------
  71. #define AI_ASE_HANDLE_SECTION(iDepth, level, msg) \
  72. if ('{' == *m_szFile)iDepth++; \
  73. else if ('}' == *m_szFile) \
  74. { \
  75. if (0 == --iDepth) \
  76. { \
  77. ++m_szFile; \
  78. SkipToNextToken(); \
  79. return; \
  80. } \
  81. } \
  82. else if ('\0' == *m_szFile) \
  83. { \
  84. LogError("Encountered unexpected EOL while parsing a " msg \
  85. " chunk (Level " level ")"); \
  86. } \
  87. if(IsLineEnd(*m_szFile) && !bLastWasEndLine) \
  88. { \
  89. ++iLineNumber; \
  90. bLastWasEndLine = true; \
  91. } else bLastWasEndLine = false; \
  92. ++m_szFile;
  93. #ifdef _MSC_VER
  94. # define sprintf sprintf_s
  95. #endif
  96. // ------------------------------------------------------------------------------------------------
  97. Parser::Parser (const char* szFile)
  98. {
  99. ai_assert(NULL != szFile);
  100. m_szFile = szFile;
  101. // makre sure that the color values are invalid
  102. m_clrBackground.r = std::numeric_limits<float>::quiet_NaN();
  103. m_clrAmbient.r = std::numeric_limits<float>::quiet_NaN();
  104. iLineNumber = 0;
  105. iFirstFrame = 0;
  106. iLastFrame = 0;
  107. iFrameSpeed = 30; // use 30 as default value for this property
  108. iTicksPerFrame = 1; // use 1 as default value for this property
  109. bLastWasEndLine = false; // need to handle \r\n seqs due to binary file mapping
  110. }
  111. // ------------------------------------------------------------------------------------------------
  112. void Parser::LogWarning(const char* szWarn)
  113. {
  114. ai_assert(NULL != szWarn);
  115. char szTemp[1024];
  116. #if _MSC_VER >= 1400
  117. sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
  118. #else
  119. snprintf(szTemp,1024,"Line %i: %s",iLineNumber,szWarn);
  120. #endif
  121. // output the warning to the logger ...
  122. DefaultLogger::get()->warn(szTemp);
  123. }
  124. // ------------------------------------------------------------------------------------------------
  125. void Parser::LogInfo(const char* szWarn)
  126. {
  127. ai_assert(NULL != szWarn);
  128. char szTemp[1024];
  129. #if _MSC_VER >= 1400
  130. sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
  131. #else
  132. snprintf(szTemp,1024,"Line %i: %s",iLineNumber,szWarn);
  133. #endif
  134. // output the information to the logger ...
  135. DefaultLogger::get()->info(szTemp);
  136. }
  137. // ------------------------------------------------------------------------------------------------
  138. void Parser::LogError(const char* szWarn)
  139. {
  140. ai_assert(NULL != szWarn);
  141. char szTemp[1024];
  142. #if _MSC_VER >= 1400
  143. sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
  144. #else
  145. snprintf(szTemp,1024,"Line %i: %s",iLineNumber,szWarn);
  146. #endif
  147. // throw an exception
  148. throw new ImportErrorException(szTemp);
  149. }
  150. // ------------------------------------------------------------------------------------------------
  151. bool Parser::SkipToNextToken()
  152. {
  153. while (true)
  154. {
  155. char me = *m_szFile;
  156. // increase the line number counter if necessary
  157. if (IsLineEnd(me) && !bLastWasEndLine)
  158. {
  159. ++iLineNumber;
  160. bLastWasEndLine = true;
  161. }
  162. else bLastWasEndLine = false;
  163. if ('*' == me || '}' == me || '{' == me)return true;
  164. if ('\0' == me)return false;
  165. ++m_szFile;
  166. }
  167. }
  168. // ------------------------------------------------------------------------------------------------
  169. bool Parser::SkipSection()
  170. {
  171. // must handle subsections ...
  172. int iCnt = 0;
  173. while (true)
  174. {
  175. if ('}' == *m_szFile)
  176. {
  177. --iCnt;
  178. if (0 == iCnt)
  179. {
  180. // go to the next valid token ...
  181. ++m_szFile;
  182. SkipToNextToken();
  183. return true;
  184. }
  185. }
  186. else if ('{' == *m_szFile)
  187. {
  188. ++iCnt;
  189. }
  190. else if ('\0' == *m_szFile)
  191. {
  192. LogWarning("Unable to parse block: Unexpected EOF, closing bracket \'}\' was expected [#1]");
  193. return false;
  194. }
  195. else if(IsLineEnd(*m_szFile))++iLineNumber;
  196. ++m_szFile;
  197. }
  198. }
  199. // ------------------------------------------------------------------------------------------------
  200. void Parser::Parse()
  201. {
  202. int iDepth = 0;
  203. while (true)
  204. {
  205. if ('*' == *m_szFile)
  206. {
  207. ++m_szFile;
  208. // version should be 200. Validate this ...
  209. if (TokenMatch(m_szFile,"3DSMAX_ASCIIEXPORT",18))
  210. {
  211. unsigned int iVersion;
  212. ParseLV4MeshLong(iVersion);
  213. if (iVersion > 200)
  214. {
  215. LogWarning("Unknown file format version: *3DSMAX_ASCIIEXPORT should \
  216. be <=200. Continuing happily ...");
  217. }
  218. continue;
  219. }
  220. // main scene information
  221. if (TokenMatch(m_szFile,"SCENE",5))
  222. {
  223. ParseLV1SceneBlock();
  224. continue;
  225. }
  226. // "group" - no implementation yet, in facte
  227. // we're just ignoring them for the moment
  228. if (TokenMatch(m_szFile,"GROUP",5))
  229. {
  230. Parse();
  231. continue;
  232. }
  233. // material list
  234. if (TokenMatch(m_szFile,"MATERIAL_LIST",13))
  235. {
  236. ParseLV1MaterialListBlock();
  237. continue;
  238. }
  239. // geometric object (mesh)
  240. if (TokenMatch(m_szFile,"GEOMOBJECT",10))
  241. {
  242. m_vMeshes.push_back(Mesh());
  243. ParseLV1ObjectBlock(m_vMeshes.back());
  244. continue;
  245. }
  246. // helper object = dummy in the hierarchy
  247. if (TokenMatch(m_szFile,"HELPEROBJECT",12))
  248. {
  249. m_vDummies.push_back(Dummy());
  250. ParseLV1ObjectBlock(m_vDummies.back());
  251. continue;
  252. }
  253. // light object
  254. if (TokenMatch(m_szFile,"LIGHTOBJECT",11))
  255. {
  256. m_vLights.push_back(Light());
  257. ParseLV1ObjectBlock(m_vLights.back());
  258. continue;
  259. }
  260. // camera object
  261. if (TokenMatch(m_szFile,"CAMERAOBJECT",12))
  262. {
  263. m_vCameras.push_back(Camera());
  264. ParseLV1ObjectBlock(m_vCameras.back());
  265. continue;
  266. }
  267. // comment - print it on the console
  268. if (TokenMatch(m_szFile,"COMMENT",7))
  269. {
  270. std::string out = "<unknown>";
  271. ParseString(out,"*COMMENT");
  272. LogInfo(("Comment: " + out).c_str());
  273. continue;
  274. }
  275. }
  276. AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
  277. }
  278. return;
  279. }
  280. // ------------------------------------------------------------------------------------------------
  281. void Parser::ParseLV1SceneBlock()
  282. {
  283. int iDepth = 0;
  284. while (true)
  285. {
  286. if ('*' == *m_szFile)
  287. {
  288. ++m_szFile;
  289. if (TokenMatch(m_szFile,"SCENE_BACKGROUND_STATIC",23))
  290. {
  291. // parse a color triple and assume it is really the bg color
  292. ParseLV4MeshFloatTriple( &m_clrBackground.r );
  293. continue;
  294. }
  295. if (TokenMatch(m_szFile,"SCENE_AMBIENT_STATIC",20))
  296. {
  297. // parse a color triple and assume it is really the bg color
  298. ParseLV4MeshFloatTriple( &m_clrAmbient.r );
  299. continue;
  300. }
  301. if (TokenMatch(m_szFile,"SCENE_FIRSTFRAME",16))
  302. {
  303. ParseLV4MeshLong(iFirstFrame);
  304. continue;
  305. }
  306. if (TokenMatch(m_szFile,"SCENE_LASTFRAME",15))
  307. {
  308. ParseLV4MeshLong(iLastFrame);
  309. continue;
  310. }
  311. if (TokenMatch(m_szFile,"SCENE_FRAMESPEED",16))
  312. {
  313. ParseLV4MeshLong(iFrameSpeed);
  314. continue;
  315. }
  316. if (TokenMatch(m_szFile,"SCENE_TICKSPERFRAME",19))
  317. {
  318. ParseLV4MeshLong(iTicksPerFrame);
  319. continue;
  320. }
  321. }
  322. AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
  323. }
  324. }
  325. // ------------------------------------------------------------------------------------------------
  326. void Parser::ParseLV1MaterialListBlock()
  327. {
  328. int iDepth = 0;
  329. unsigned int iMaterialCount = 0;
  330. unsigned int iOldMaterialCount = (unsigned int)m_vMaterials.size();
  331. while (true)
  332. {
  333. if ('*' == *m_szFile)
  334. {
  335. ++m_szFile;
  336. if (TokenMatch(m_szFile,"MATERIAL_COUNT",14))
  337. {
  338. ParseLV4MeshLong(iMaterialCount);
  339. // now allocate enough storage to hold all materials
  340. m_vMaterials.resize(iOldMaterialCount+iMaterialCount);
  341. continue;
  342. }
  343. if (TokenMatch(m_szFile,"MATERIAL",8))
  344. {
  345. unsigned int iIndex = 0;
  346. ParseLV4MeshLong(iIndex);
  347. if (iIndex >= iMaterialCount)
  348. {
  349. LogWarning("Out of range: material index is too large");
  350. iIndex = iMaterialCount-1;
  351. }
  352. // get a reference to the material
  353. Material& sMat = m_vMaterials[iIndex+iOldMaterialCount];
  354. // parse the material block
  355. ParseLV2MaterialBlock(sMat);
  356. continue;
  357. }
  358. }
  359. AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
  360. }
  361. }
  362. // ------------------------------------------------------------------------------------------------
  363. void Parser::ParseLV2MaterialBlock(ASE::Material& mat)
  364. {
  365. int iDepth = 0;
  366. unsigned int iNumSubMaterials = 0;
  367. while (true)
  368. {
  369. if ('*' == *m_szFile)
  370. {
  371. ++m_szFile;
  372. if (TokenMatch(m_szFile,"MATERIAL_NAME",13))
  373. {
  374. if (!ParseString(mat.mName,"*MATERIAL_NAME"))
  375. SkipToNextToken();
  376. continue;
  377. }
  378. // ambient material color
  379. if (TokenMatch(m_szFile,"MATERIAL_AMBIENT",16))
  380. {
  381. ParseLV4MeshFloatTriple(&mat.mAmbient.r);
  382. continue;
  383. }
  384. // diffuse material color
  385. if (TokenMatch(m_szFile,"MATERIAL_DIFFUSE",16) )
  386. {
  387. ParseLV4MeshFloatTriple(&mat.mDiffuse.r);
  388. continue;
  389. }
  390. // specular material color
  391. if (TokenMatch(m_szFile,"MATERIAL_SPECULAR",17))
  392. {
  393. ParseLV4MeshFloatTriple(&mat.mSpecular.r);
  394. continue;
  395. }
  396. // material shading type
  397. if (TokenMatch(m_szFile,"MATERIAL_SHADING",16))
  398. {
  399. if (TokenMatch(m_szFile,"Blinn",5))
  400. {
  401. mat.mShading = Discreet3DS::Blinn;
  402. }
  403. else if (TokenMatch(m_szFile,"Phong",5))
  404. {
  405. mat.mShading = Discreet3DS::Phong;
  406. }
  407. else if (TokenMatch(m_szFile,"Flat",4))
  408. {
  409. mat.mShading = Discreet3DS::Flat;
  410. }
  411. else if (TokenMatch(m_szFile,"Wire",4))
  412. {
  413. mat.mShading = Discreet3DS::Wire;
  414. }
  415. else
  416. {
  417. // assume gouraud shading
  418. mat.mShading = Discreet3DS::Gouraud;
  419. SkipToNextToken();
  420. }
  421. continue;
  422. }
  423. // material transparency
  424. if (TokenMatch(m_szFile,"MATERIAL_TRANSPARENCY",21))
  425. {
  426. ParseLV4MeshFloat(mat.mTransparency);
  427. mat.mTransparency = 1.0f - mat.mTransparency;continue;
  428. }
  429. // material self illumination
  430. if (TokenMatch(m_szFile,"MATERIAL_SELFILLUM",18))
  431. {
  432. float f = 0.0f;
  433. ParseLV4MeshFloat(f);
  434. mat.mEmissive.r = f;
  435. mat.mEmissive.g = f;
  436. mat.mEmissive.b = f;
  437. continue;
  438. }
  439. // material shininess
  440. if (TokenMatch(m_szFile,"MATERIAL_SHINE",14) )
  441. {
  442. ParseLV4MeshFloat(mat.mSpecularExponent);
  443. mat.mSpecularExponent *= 15;
  444. continue;
  445. }
  446. // material shininess strength
  447. if (TokenMatch(m_szFile,"MATERIAL_SHINESTRENGTH",22))
  448. {
  449. ParseLV4MeshFloat(mat.mShininessStrength);
  450. continue;
  451. }
  452. // diffuse color map
  453. if (TokenMatch(m_szFile,"MAP_DIFFUSE",11))
  454. {
  455. // parse the texture block
  456. ParseLV3MapBlock(mat.sTexDiffuse);
  457. continue;
  458. }
  459. // ambient color map
  460. if (TokenMatch(m_szFile,"MAP_AMBIENT",11))
  461. {
  462. // parse the texture block
  463. ParseLV3MapBlock(mat.sTexAmbient);
  464. continue;
  465. }
  466. // specular color map
  467. if (TokenMatch(m_szFile,"MAP_SPECULAR",12))
  468. {
  469. // parse the texture block
  470. ParseLV3MapBlock(mat.sTexSpecular);
  471. continue;
  472. }
  473. // opacity map
  474. if (TokenMatch(m_szFile,"MAP_OPACITY",11))
  475. {
  476. // parse the texture block
  477. ParseLV3MapBlock(mat.sTexOpacity);
  478. continue;
  479. }
  480. // emissive map
  481. if (TokenMatch(m_szFile,"MAP_SELFILLUM",13))
  482. {
  483. // parse the texture block
  484. ParseLV3MapBlock(mat.sTexEmissive);
  485. continue;
  486. }
  487. // bump map
  488. if (TokenMatch(m_szFile,"MAP_BUMP",8))
  489. {
  490. // parse the texture block
  491. ParseLV3MapBlock(mat.sTexBump);
  492. }
  493. // specular/shininess map
  494. if (TokenMatch(m_szFile,"MAP_SHINESTRENGTH",17))
  495. {
  496. // parse the texture block
  497. ParseLV3MapBlock(mat.sTexShininess);
  498. continue;
  499. }
  500. // number of submaterials
  501. if (TokenMatch(m_szFile,"NUMSUBMTLS",10))
  502. {
  503. ParseLV4MeshLong(iNumSubMaterials);
  504. // allocate enough storage
  505. mat.avSubMaterials.resize(iNumSubMaterials);
  506. }
  507. // submaterial chunks
  508. if (TokenMatch(m_szFile,"SUBMATERIAL",11))
  509. {
  510. unsigned int iIndex = 0;
  511. ParseLV4MeshLong(iIndex);
  512. if (iIndex >= iNumSubMaterials)
  513. {
  514. LogWarning("Out of range: submaterial index is too large");
  515. iIndex = iNumSubMaterials-1;
  516. }
  517. // get a reference to the material
  518. Material& sMat = mat.avSubMaterials[iIndex];
  519. // parse the material block
  520. ParseLV2MaterialBlock(sMat);
  521. continue;
  522. }
  523. }
  524. AI_ASE_HANDLE_SECTION(iDepth,"2","*MATERIAL");
  525. }
  526. }
  527. // ------------------------------------------------------------------------------------------------
  528. void Parser::ParseLV3MapBlock(Texture& map)
  529. {
  530. int iDepth = 0;
  531. // *BITMAP should not be there if *MAP_CLASS is not BITMAP,
  532. // but we need to expect that case ... if the path is
  533. // empty the texture won't be used later.
  534. bool parsePath = true;
  535. while (true)
  536. {
  537. if ('*' == *m_szFile)
  538. {
  539. ++m_szFile;
  540. // type of map
  541. if (TokenMatch(m_szFile,"MAP_CLASS" ,9))
  542. {
  543. std::string temp;
  544. if(!ParseString(temp,"*MAP_CLASS"))
  545. SkipToNextToken();
  546. if (temp != "Bitmap")
  547. parsePath = false;
  548. continue;
  549. }
  550. // path to the texture
  551. if (parsePath && TokenMatch(m_szFile,"BITMAP" ,6))
  552. {
  553. if(!ParseString(map.mMapName,"*BITMAP"))
  554. SkipToNextToken();
  555. continue;
  556. }
  557. // offset on the u axis
  558. if (TokenMatch(m_szFile,"UVW_U_OFFSET" ,12))
  559. {
  560. ParseLV4MeshFloat(map.mOffsetU);
  561. continue;
  562. }
  563. // offset on the v axis
  564. if (TokenMatch(m_szFile,"UVW_V_OFFSET" ,12))
  565. {
  566. ParseLV4MeshFloat(map.mOffsetV);
  567. continue;
  568. }
  569. // tiling on the u axis
  570. if (TokenMatch(m_szFile,"UVW_U_TILING" ,12))
  571. {
  572. ParseLV4MeshFloat(map.mScaleU);
  573. continue;
  574. }
  575. // tiling on the v axis
  576. if (TokenMatch(m_szFile,"UVW_V_TILING" ,12))
  577. {
  578. ParseLV4MeshFloat(map.mScaleV);
  579. continue;
  580. }
  581. // rotation around the z-axis
  582. if (TokenMatch(m_szFile,"UVW_ANGLE" ,9))
  583. {
  584. ParseLV4MeshFloat(map.mRotation);
  585. continue;
  586. }
  587. // map blending factor
  588. if (TokenMatch(m_szFile,"MAP_AMOUNT" ,10))
  589. {
  590. ParseLV4MeshFloat(map.mTextureBlend);
  591. continue;
  592. }
  593. }
  594. AI_ASE_HANDLE_SECTION(iDepth,"3","*MAP_XXXXXX");
  595. }
  596. return;
  597. }
  598. // ------------------------------------------------------------------------------------------------
  599. bool Parser::ParseString(std::string& out,const char* szName)
  600. {
  601. char szBuffer[1024];
  602. if (!SkipSpaces(&m_szFile))
  603. {
  604. sprintf(szBuffer,"Unable to parse %s block: Unexpected EOL",szName);
  605. LogWarning(szBuffer);
  606. return false;
  607. }
  608. // there must be "
  609. if ('\"' != *m_szFile)
  610. {
  611. sprintf(szBuffer,"Unable to parse %s block: Strings are expected "
  612. "to be enclosed in double quotation marks",szName);
  613. LogWarning(szBuffer);
  614. return false;
  615. }
  616. ++m_szFile;
  617. const char* sz = m_szFile;
  618. while (true)
  619. {
  620. if ('\"' == *sz)break;
  621. else if ('\0' == sz)
  622. {
  623. sprintf(szBuffer,"Unable to parse %s block: Strings are expected to be "
  624. "enclosed in double quotation marks but EOF was reached before a closing "
  625. "quotation mark was found",szName);
  626. LogWarning(szBuffer);
  627. return false;
  628. }
  629. sz++;
  630. }
  631. out = std::string(m_szFile,(uintptr_t)sz-(uintptr_t)m_szFile);
  632. m_szFile = sz;
  633. return true;
  634. }
  635. // ------------------------------------------------------------------------------------------------
  636. void Parser::ParseLV1ObjectBlock(ASE::BaseNode& node)
  637. {
  638. int iDepth = 0;
  639. while (true)
  640. {
  641. if ('*' == *m_szFile)
  642. {
  643. ++m_szFile;
  644. // first process common tokens such as node name and transform
  645. // name of the mesh/node
  646. if (TokenMatch(m_szFile,"NODE_NAME" ,9))
  647. {
  648. if(!ParseString(node.mName,"*NODE_NAME"))
  649. SkipToNextToken();
  650. continue;
  651. }
  652. // name of the parent of the node
  653. if (TokenMatch(m_szFile,"NODE_PARENT" ,11) )
  654. {
  655. if(!ParseString(node.mParent,"*NODE_PARENT"))
  656. SkipToNextToken();
  657. continue;
  658. }
  659. // transformation matrix of the node
  660. if (TokenMatch(m_szFile,"NODE_TM" ,7))
  661. {
  662. ParseLV2NodeTransformBlock(node);
  663. continue;
  664. }
  665. // animation data of the node
  666. if (TokenMatch(m_szFile,"TM_ANIMATION" ,12))
  667. {
  668. ParseLV2AnimationBlock(node);
  669. continue;
  670. }
  671. if (node.mType == BaseNode::Light)
  672. {
  673. // light settings
  674. if (TokenMatch(m_szFile,"LIGHT_SETTINGS" ,14))
  675. {
  676. ParseLV2LightSettingsBlock((ASE::Light&)node);
  677. continue;
  678. }
  679. // type of the light source
  680. if (TokenMatch(m_szFile,"LIGHT_TYPE" ,10))
  681. {
  682. if (!ASSIMP_strincmp("omni",m_szFile,4))
  683. {
  684. ((ASE::Light&)node).mLightType = ASE::Light::OMNI;
  685. }
  686. else if (!ASSIMP_strincmp("target",m_szFile,6))
  687. {
  688. ((ASE::Light&)node).mLightType = ASE::Light::TARGET;
  689. }
  690. else if (!ASSIMP_strincmp("free",m_szFile,4))
  691. {
  692. ((ASE::Light&)node).mLightType = ASE::Light::FREE;
  693. }
  694. else if (!ASSIMP_strincmp("directional",m_szFile,11))
  695. {
  696. ((ASE::Light&)node).mLightType = ASE::Light::DIRECTIONAL;
  697. }
  698. else
  699. {
  700. // TODO: use std::string as parameter for LogWarning
  701. LogWarning("Unknown kind of light source");
  702. }
  703. continue;
  704. }
  705. }
  706. else if (node.mType == BaseNode::Camera)
  707. {
  708. // Camera settings
  709. if (TokenMatch(m_szFile,"CAMERA_SETTINGS" ,15))
  710. {
  711. ParseLV2CameraSettingsBlock((ASE::Camera&)node);
  712. continue;
  713. }
  714. }
  715. else if (node.mType == BaseNode::Mesh)
  716. {
  717. // mesh data
  718. if (TokenMatch(m_szFile,"MESH" ,4))
  719. {
  720. ParseLV2MeshBlock((ASE::Mesh&)node);
  721. continue;
  722. }
  723. // mesh material index
  724. if (TokenMatch(m_szFile,"MATERIAL_REF" ,12))
  725. {
  726. ParseLV4MeshLong(((ASE::Mesh&)node).iMaterialIndex);
  727. continue;
  728. }
  729. }
  730. }
  731. AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
  732. }
  733. return;
  734. }
  735. // ------------------------------------------------------------------------------------------------
  736. void Parser::ParseLV2CameraSettingsBlock(ASE::Camera& camera)
  737. {
  738. int iDepth = 0;
  739. while (true)
  740. {
  741. if ('*' == *m_szFile)
  742. {
  743. ++m_szFile;
  744. if (TokenMatch(m_szFile,"CAMERA_NEAR" ,11))
  745. {
  746. ParseLV4MeshFloat(camera.mNear);
  747. continue;
  748. }
  749. if (TokenMatch(m_szFile,"CAMERA_FAR" ,10))
  750. {
  751. ParseLV4MeshFloat(camera.mFar);
  752. continue;
  753. }
  754. if (TokenMatch(m_szFile,"CAMERA_FOV" ,10))
  755. {
  756. ParseLV4MeshFloat(camera.mFOV);
  757. continue;
  758. }
  759. }
  760. AI_ASE_HANDLE_SECTION(iDepth,"2","CAMERA_SETTINGS");
  761. }
  762. return;
  763. }
  764. // ------------------------------------------------------------------------------------------------
  765. void Parser::ParseLV2LightSettingsBlock(ASE::Light& light)
  766. {
  767. int iDepth = 0;
  768. while (true)
  769. {
  770. if ('*' == *m_szFile)
  771. {
  772. ++m_szFile;
  773. if (TokenMatch(m_szFile,"LIGHT_COLOR" ,11))
  774. {
  775. ParseLV4MeshFloatTriple(&light.mColor.r);
  776. continue;
  777. }
  778. if (TokenMatch(m_szFile,"LIGHT_INTENS" ,12))
  779. {
  780. ParseLV4MeshFloat(light.mIntensity);
  781. continue;
  782. }
  783. if (TokenMatch(m_szFile,"LIGHT_HOTSPOT" ,13))
  784. {
  785. ParseLV4MeshFloat(light.mAngle);
  786. continue;
  787. }
  788. if (TokenMatch(m_szFile,"LIGHT_FALLOFF" ,13))
  789. {
  790. ParseLV4MeshFloat(light.mFalloff);
  791. continue;
  792. }
  793. }
  794. AI_ASE_HANDLE_SECTION(iDepth,"2","LIGHT_SETTINGS");
  795. }
  796. return;
  797. }
  798. // ------------------------------------------------------------------------------------------------
  799. void Parser::ParseLV2AnimationBlock(ASE::BaseNode& mesh)
  800. {
  801. int iDepth = 0;
  802. ASE::Animation* anim = &mesh.mAnim;
  803. while (true)
  804. {
  805. if ('*' == *m_szFile)
  806. {
  807. ++m_szFile;
  808. if (TokenMatch(m_szFile,"NODE_NAME" ,9))
  809. {
  810. std::string temp;
  811. if(!ParseString(temp,"*NODE_NAME"))
  812. SkipToNextToken();
  813. // If the name of the node contains .target it
  814. // represents an animated camera or spot light
  815. // target.
  816. if (std::string::npos != temp.find(".Target"))
  817. {
  818. if (mesh.mType != BaseNode::Camera &&
  819. (mesh.mType != BaseNode::Light ||
  820. ((ASE::Light&)mesh).mLightType != ASE::Light::TARGET))
  821. { /* it is not absolutely sure we know the type of the light source yet */
  822. DefaultLogger::get()->error("ASE: Found target animation channel "
  823. "but the node is neither a camera nor a spot light");
  824. anim = NULL;
  825. }
  826. else anim = &mesh.mTargetAnim;
  827. }
  828. continue;
  829. }
  830. // position keyframes
  831. if (TokenMatch(m_szFile,"CONTROL_POS_TRACK" ,17) ||
  832. TokenMatch(m_szFile,"CONTROL_POS_BEZIER" ,18) ||
  833. TokenMatch(m_szFile,"CONTROL_POS_TCB" ,15))
  834. {
  835. if (!anim)SkipSection();
  836. else ParseLV3PosAnimationBlock(*anim);
  837. continue;
  838. }
  839. // scaling keyframes
  840. if (TokenMatch(m_szFile,"CONTROL_SCALE_TRACK" ,19) ||
  841. TokenMatch(m_szFile,"CONTROL_SCALE_BEZIER" ,20) ||
  842. TokenMatch(m_szFile,"CONTROL_SCALE_TCB" ,17))
  843. {
  844. if (!anim || anim == &mesh.mTargetAnim)
  845. {
  846. // Target animation channels may have no rotation channels
  847. DefaultLogger::get()->error("ASE: Ignoring scaling channel in target animation");
  848. SkipSection();
  849. }
  850. else ParseLV3ScaleAnimationBlock(*anim);
  851. continue;
  852. }
  853. // rotation keyframes
  854. if (TokenMatch(m_szFile,"CONTROL_ROT_TRACK" ,17) ||
  855. TokenMatch(m_szFile,"CONTROL_ROT_BEZIER" ,18) ||
  856. TokenMatch(m_szFile,"CONTROL_ROT_TCB" ,15))
  857. {
  858. if (!anim || anim == &mesh.mTargetAnim)
  859. {
  860. // Target animation channels may have no rotation channels
  861. DefaultLogger::get()->error("ASE: Ignoring rotation channel in target animation");
  862. SkipSection();
  863. }
  864. else ParseLV3RotAnimationBlock(*anim);
  865. continue;
  866. }
  867. }
  868. AI_ASE_HANDLE_SECTION(iDepth,"2","TM_ANIMATION");
  869. }
  870. }
  871. // ------------------------------------------------------------------------------------------------
  872. void Parser::ParseLV3ScaleAnimationBlock(ASE::Animation& anim)
  873. {
  874. int iDepth = 0;
  875. unsigned int iIndex;
  876. while (true)
  877. {
  878. if ('*' == *m_szFile)
  879. {
  880. ++m_szFile;
  881. bool b = false;
  882. // For the moment we're just reading the three floats -
  883. // we ignore the ádditional information for bezier's and TCBs
  884. // simple scaling keyframe
  885. if (TokenMatch(m_szFile,"CONTROL_SCALE_SAMPLE" ,20))
  886. {
  887. b = true;
  888. anim.mScalingType = ASE::Animation::TRACK;
  889. }
  890. // Bezier scaling keyframe
  891. if (TokenMatch(m_szFile,"CONTROL_BEZIER_SCALE_KEY" ,24))
  892. {
  893. b = true;
  894. anim.mScalingType = ASE::Animation::BEZIER;
  895. }
  896. // TCB scaling keyframe
  897. if (TokenMatch(m_szFile,"CONTROL_TCB_SCALE_KEY" ,21))
  898. {
  899. b = true;
  900. anim.mScalingType = ASE::Animation::TCB;
  901. }
  902. if (b)
  903. {
  904. anim.akeyScaling.push_back(aiVectorKey());
  905. aiVectorKey& key = anim.akeyScaling.back();
  906. ParseLV4MeshFloatTriple(&key.mValue.x,iIndex);
  907. key.mTime = (double)iIndex;
  908. }
  909. }
  910. AI_ASE_HANDLE_SECTION(iDepth,"3","*CONTROL_POS_TRACK");
  911. }
  912. }
  913. // ------------------------------------------------------------------------------------------------
  914. void Parser::ParseLV3PosAnimationBlock(ASE::Animation& anim)
  915. {
  916. int iDepth = 0;
  917. unsigned int iIndex;
  918. while (true)
  919. {
  920. if ('*' == *m_szFile)
  921. {
  922. ++m_szFile;
  923. bool b = false;
  924. // For the moment we're just reading the three floats -
  925. // we ignore the ádditional information for bezier's and TCBs
  926. // simple scaling keyframe
  927. if (TokenMatch(m_szFile,"CONTROL_POS_SAMPLE" ,18))
  928. {
  929. b = true;
  930. anim.mPositionType = ASE::Animation::TRACK;
  931. }
  932. // Bezier scaling keyframe
  933. if (TokenMatch(m_szFile,"CONTROL_BEZIER_POS_KEY" ,22))
  934. {
  935. b = true;
  936. anim.mPositionType = ASE::Animation::BEZIER;
  937. }
  938. // TCB scaling keyframe
  939. if (TokenMatch(m_szFile,"CONTROL_TCB_POS_KEY" ,19))
  940. {
  941. b = true;
  942. anim.mPositionType = ASE::Animation::TCB;
  943. }
  944. if (b)
  945. {
  946. anim.akeyPositions.push_back(aiVectorKey());
  947. aiVectorKey& key = anim.akeyPositions.back();
  948. ParseLV4MeshFloatTriple(&key.mValue.x,iIndex);
  949. key.mTime = (double)iIndex;
  950. }
  951. }
  952. AI_ASE_HANDLE_SECTION(iDepth,"3","*CONTROL_POS_TRACK");
  953. }
  954. }
  955. // ------------------------------------------------------------------------------------------------
  956. void Parser::ParseLV3RotAnimationBlock(ASE::Animation& anim)
  957. {
  958. int iDepth = 0;
  959. unsigned int iIndex;
  960. while (true)
  961. {
  962. if ('*' == *m_szFile)
  963. {
  964. ++m_szFile;
  965. bool b = false;
  966. // For the moment we're just reading the floats -
  967. // we ignore the ádditional information for bezier's and TCBs
  968. // simple scaling keyframe
  969. if (TokenMatch(m_szFile,"CONTROL_ROT_SAMPLE" ,18))
  970. {
  971. b = true;
  972. anim.mRotationType = ASE::Animation::TRACK;
  973. }
  974. // Bezier scaling keyframe
  975. if (TokenMatch(m_szFile,"CONTROL_BEZIER_ROT_KEY" ,22))
  976. {
  977. b = true;
  978. anim.mRotationType = ASE::Animation::BEZIER;
  979. }
  980. // TCB scaling keyframe
  981. if (TokenMatch(m_szFile,"CONTROL_TCB_ROT_KEY" ,19))
  982. {
  983. b = true;
  984. anim.mRotationType = ASE::Animation::TCB;
  985. }
  986. if (b)
  987. {
  988. anim.akeyRotations.push_back(aiQuatKey());
  989. aiQuatKey& key = anim.akeyRotations.back();
  990. aiVector3D v;float f;
  991. ParseLV4MeshFloatTriple(&v.x,iIndex);
  992. ParseLV4MeshFloat(f);
  993. key.mTime = (double)iIndex;
  994. key.mValue = aiQuaternion(v,f);
  995. }
  996. }
  997. AI_ASE_HANDLE_SECTION(iDepth,"3","*CONTROL_ROT_TRACK");
  998. }
  999. }
  1000. // ------------------------------------------------------------------------------------------------
  1001. void Parser::ParseLV2NodeTransformBlock(ASE::BaseNode& mesh)
  1002. {
  1003. int iDepth = 0;
  1004. int mode = 0;
  1005. while (true)
  1006. {
  1007. if ('*' == *m_szFile)
  1008. {
  1009. ++m_szFile;
  1010. // name of the node
  1011. if (TokenMatch(m_szFile,"NODE_NAME" ,9))
  1012. {
  1013. std::string temp;
  1014. if(!ParseString(temp,"*NODE_NAME"))
  1015. SkipToNextToken();
  1016. std::string::size_type s;
  1017. if (temp == mesh.mName)
  1018. {
  1019. mode = 1;
  1020. }
  1021. else if (std::string::npos != (s = temp.find(".Target")) &&
  1022. mesh.mName == temp.substr(0,s))
  1023. {
  1024. // This should be either a target light or a target camera
  1025. if ( mesh.mType == BaseNode::Light && ((ASE::Light&)mesh) .mLightType == ASE::Light::TARGET ||
  1026. mesh.mType == BaseNode::Camera && ((ASE::Camera&)mesh).mCameraType == ASE::Camera::TARGET)
  1027. {
  1028. mode = 2;
  1029. }
  1030. else DefaultLogger::get()->error("ASE: Ignoring target transform, "
  1031. "this is no spot light or target camera");
  1032. }
  1033. else
  1034. {
  1035. DefaultLogger::get()->error("ASE: Unknown node transformation: " + temp);
  1036. // mode = 0
  1037. }
  1038. continue;
  1039. }
  1040. if (mode)
  1041. {
  1042. // fourth row of the transformation matrix - and also the
  1043. // only information here that is interesting for targets
  1044. if (TokenMatch(m_szFile,"TM_ROW3" ,7))
  1045. {
  1046. ParseLV4MeshFloatTriple((mode == 1 ? mesh.mTransform[3] : &mesh.mTargetPosition.x));
  1047. continue;
  1048. }
  1049. if (mode == 1)
  1050. {
  1051. // first row of the transformation matrix
  1052. if (TokenMatch(m_szFile,"TM_ROW0" ,7))
  1053. {
  1054. ParseLV4MeshFloatTriple(mesh.mTransform[0]);
  1055. continue;
  1056. }
  1057. // second row of the transformation matrix
  1058. if (TokenMatch(m_szFile,"TM_ROW1" ,7))
  1059. {
  1060. ParseLV4MeshFloatTriple(mesh.mTransform[1]);
  1061. continue;
  1062. }
  1063. // third row of the transformation matrix
  1064. if (TokenMatch(m_szFile,"TM_ROW2" ,7))
  1065. {
  1066. ParseLV4MeshFloatTriple(mesh.mTransform[2]);
  1067. continue;
  1068. }
  1069. // inherited position axes
  1070. if (TokenMatch(m_szFile,"INHERIT_POS" ,11))
  1071. {
  1072. unsigned int aiVal[3];
  1073. ParseLV4MeshLongTriple(aiVal);
  1074. for (unsigned int i = 0; i < 3;++i)
  1075. mesh.inherit.abInheritPosition[i] = aiVal[i] != 0;
  1076. continue;
  1077. }
  1078. // inherited rotation axes
  1079. if (TokenMatch(m_szFile,"INHERIT_ROT" ,11))
  1080. {
  1081. unsigned int aiVal[3];
  1082. ParseLV4MeshLongTriple(aiVal);
  1083. for (unsigned int i = 0; i < 3;++i)
  1084. mesh.inherit.abInheritRotation[i] = aiVal[i] != 0;
  1085. continue;
  1086. }
  1087. // inherited scaling axes
  1088. if (TokenMatch(m_szFile,"INHERIT_SCL" ,11))
  1089. {
  1090. unsigned int aiVal[3];
  1091. ParseLV4MeshLongTriple(aiVal);
  1092. for (unsigned int i = 0; i < 3;++i)
  1093. mesh.inherit.abInheritScaling[i] = aiVal[i] != 0;
  1094. continue;
  1095. }
  1096. }
  1097. }
  1098. }
  1099. AI_ASE_HANDLE_SECTION(iDepth,"2","*NODE_TM");
  1100. }
  1101. return;
  1102. }
  1103. // ------------------------------------------------------------------------------------------------
  1104. void Parser::ParseLV2MeshBlock(ASE::Mesh& mesh)
  1105. {
  1106. unsigned int iNumVertices = 0;
  1107. unsigned int iNumFaces = 0;
  1108. unsigned int iNumTVertices = 0;
  1109. unsigned int iNumTFaces = 0;
  1110. unsigned int iNumCVertices = 0;
  1111. unsigned int iNumCFaces = 0;
  1112. int iDepth = 0;
  1113. while (true)
  1114. {
  1115. if ('*' == *m_szFile)
  1116. {
  1117. ++m_szFile;
  1118. // Number of vertices in the mesh
  1119. if (TokenMatch(m_szFile,"MESH_NUMVERTEX" ,14))
  1120. {
  1121. ParseLV4MeshLong(iNumVertices);
  1122. continue;
  1123. }
  1124. // Number of texture coordinates in the mesh
  1125. if (TokenMatch(m_szFile,"MESH_NUMTVERTEX" ,15))
  1126. {
  1127. ParseLV4MeshLong(iNumTVertices);
  1128. continue;
  1129. }
  1130. // Number of vertex colors in the mesh
  1131. if (TokenMatch(m_szFile,"MESH_NUMCVERTEX" ,14))
  1132. {
  1133. ParseLV4MeshLong(iNumCVertices);
  1134. continue;
  1135. }
  1136. // Number of regular faces in the mesh
  1137. if (TokenMatch(m_szFile,"MESH_NUMFACES" ,13))
  1138. {
  1139. ParseLV4MeshLong(iNumFaces);
  1140. continue;
  1141. }
  1142. // Number of UVWed faces in the mesh
  1143. if (TokenMatch(m_szFile,"MESH_NUMTVFACES" ,15))
  1144. {
  1145. ParseLV4MeshLong(iNumTFaces);
  1146. continue;
  1147. }
  1148. // Number of colored faces in the mesh
  1149. if (TokenMatch(m_szFile,"MESH_NUMCVFACES" ,15))
  1150. {
  1151. ParseLV4MeshLong(iNumCFaces);
  1152. continue;
  1153. }
  1154. // mesh vertex list block
  1155. if (TokenMatch(m_szFile,"MESH_VERTEX_LIST" ,16))
  1156. {
  1157. ParseLV3MeshVertexListBlock(iNumVertices,mesh);
  1158. continue;
  1159. }
  1160. // mesh face list block
  1161. if (TokenMatch(m_szFile,"MESH_FACE_LIST" ,14))
  1162. {
  1163. ParseLV3MeshFaceListBlock(iNumFaces,mesh);
  1164. continue;
  1165. }
  1166. // mesh texture vertex list block
  1167. if (TokenMatch(m_szFile,"MESH_TVERTLIST" ,14))
  1168. {
  1169. ParseLV3MeshTListBlock(iNumTVertices,mesh);
  1170. continue;
  1171. }
  1172. // mesh texture face block
  1173. if (TokenMatch(m_szFile,"MESH_TFACELIST" ,14))
  1174. {
  1175. ParseLV3MeshTFaceListBlock(iNumTFaces,mesh);
  1176. continue;
  1177. }
  1178. // mesh color vertex list block
  1179. if (TokenMatch(m_szFile,"MESH_CVERTLIST" ,14))
  1180. {
  1181. ParseLV3MeshCListBlock(iNumCVertices,mesh);
  1182. continue;
  1183. }
  1184. // mesh color face block
  1185. if (TokenMatch(m_szFile,"MESH_CFACELIST" ,14))
  1186. {
  1187. ParseLV3MeshCFaceListBlock(iNumCFaces,mesh);
  1188. continue;
  1189. }
  1190. // mesh normals
  1191. if (TokenMatch(m_szFile,"MESH_NORMALS" ,12))
  1192. {
  1193. ParseLV3MeshNormalListBlock(mesh);
  1194. continue;
  1195. }
  1196. // another mesh UV channel ...
  1197. if (TokenMatch(m_szFile,"MESH_MAPPINGCHANNEL" ,19))
  1198. {
  1199. unsigned int iIndex = 0;
  1200. ParseLV4MeshLong(iIndex);
  1201. if (iIndex < 2)
  1202. {
  1203. LogWarning("Mapping channel has an invalid index. Skipping UV channel");
  1204. // skip it ...
  1205. SkipSection();
  1206. }
  1207. if (iIndex > AI_MAX_NUMBER_OF_TEXTURECOORDS)
  1208. {
  1209. LogWarning("Too many UV channels specified. Skipping channel ..");
  1210. // skip it ...
  1211. SkipSection();
  1212. }
  1213. else
  1214. {
  1215. // parse the mapping channel
  1216. ParseLV3MappingChannel(iIndex-1,mesh);
  1217. }
  1218. continue;
  1219. }
  1220. // mesh animation keyframe. Not supported
  1221. if (TokenMatch(m_szFile,"MESH_ANIMATION" ,14))
  1222. {
  1223. LogWarning("Found *MESH_ANIMATION element in ASE/ASK file. "
  1224. "Keyframe animation is not supported by Assimp, this element "
  1225. "will be ignored");
  1226. //SkipSection();
  1227. continue;
  1228. }
  1229. if (TokenMatch(m_szFile,"MESH_WEIGHTS" ,12))
  1230. {
  1231. ParseLV3MeshWeightsBlock(mesh);continue;
  1232. }
  1233. }
  1234. AI_ASE_HANDLE_SECTION(iDepth,"2","*MESH");
  1235. }
  1236. return;
  1237. }
  1238. // ------------------------------------------------------------------------------------------------
  1239. void Parser::ParseLV3MeshWeightsBlock(ASE::Mesh& mesh)
  1240. {
  1241. unsigned int iNumVertices = 0;
  1242. unsigned int iNumBones = 0;
  1243. int iDepth = 0;
  1244. while (true)
  1245. {
  1246. if ('*' == *m_szFile)
  1247. {
  1248. ++m_szFile;
  1249. // Number of bone vertices ...
  1250. if (TokenMatch(m_szFile,"MESH_NUMVERTEX" ,14))
  1251. {
  1252. ParseLV4MeshLong(iNumVertices);
  1253. continue;
  1254. }
  1255. // Number of bones
  1256. if (TokenMatch(m_szFile,"MESH_NUMBONE" ,11))
  1257. {
  1258. ParseLV4MeshLong(iNumBones);
  1259. continue;
  1260. }
  1261. // parse the list of bones
  1262. if (TokenMatch(m_szFile,"MESH_BONE_LIST" ,14))
  1263. {
  1264. ParseLV4MeshBones(iNumBones,mesh);
  1265. continue;
  1266. }
  1267. // parse the list of bones vertices
  1268. if (TokenMatch(m_szFile,"MESH_BONE_VERTEX_LIST" ,21) )
  1269. {
  1270. ParseLV4MeshBonesVertices(iNumVertices,mesh);
  1271. continue;
  1272. }
  1273. }
  1274. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_WEIGHTS");
  1275. }
  1276. return;
  1277. }
  1278. // ------------------------------------------------------------------------------------------------
  1279. void Parser::ParseLV4MeshBones(unsigned int iNumBones,ASE::Mesh& mesh)
  1280. {
  1281. mesh.mBones.resize(iNumBones);
  1282. int iDepth = 0;
  1283. while (true)
  1284. {
  1285. if ('*' == *m_szFile)
  1286. {
  1287. ++m_szFile;
  1288. // Mesh bone with name ...
  1289. if (TokenMatch(m_szFile,"MESH_BONE_NAME" ,16))
  1290. {
  1291. // parse an index ...
  1292. if(SkipSpaces(&m_szFile))
  1293. {
  1294. unsigned int iIndex = strtol10(m_szFile,&m_szFile);
  1295. if (iIndex >= iNumBones)
  1296. {
  1297. continue;
  1298. LogWarning("Bone index is out of bounds");
  1299. }
  1300. if (!ParseString(mesh.mBones[iIndex].mName,"*MESH_BONE_NAME"))
  1301. SkipToNextToken();
  1302. continue;
  1303. }
  1304. }
  1305. }
  1306. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_BONE_LIST");
  1307. }
  1308. }
  1309. // ------------------------------------------------------------------------------------------------
  1310. void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices,ASE::Mesh& mesh)
  1311. {
  1312. mesh.mBoneVertices.resize(iNumVertices);
  1313. int iDepth = 0;
  1314. while (true)
  1315. {
  1316. if ('*' == *m_szFile)
  1317. {
  1318. ++m_szFile;
  1319. // Mesh bone vertex
  1320. if (TokenMatch(m_szFile,"MESH_BONE_VERTEX" ,16))
  1321. {
  1322. // read the vertex index
  1323. unsigned int iIndex = strtol10(m_szFile,&m_szFile);
  1324. if (iIndex >= mesh.mPositions.size())
  1325. {
  1326. iIndex = (unsigned int)mesh.mPositions.size()-1;
  1327. LogWarning("Bone vertex index is out of bounds. Using the largest valid "
  1328. "bone vertex index instead");
  1329. }
  1330. // --- ignored
  1331. float afVert[3];
  1332. ParseLV4MeshFloatTriple(afVert);
  1333. std::pair<int,float> pairOut;
  1334. while (true)
  1335. {
  1336. // first parse the bone index ...
  1337. if (!SkipSpaces(&m_szFile))break;
  1338. pairOut.first = strtol10(m_szFile,&m_szFile);
  1339. // then parse the vertex weight
  1340. if (!SkipSpaces(&m_szFile))break;
  1341. m_szFile = fast_atof_move(m_szFile,pairOut.second);
  1342. // -1 designates unused entries
  1343. if (-1 != pairOut.first)
  1344. {
  1345. mesh.mBoneVertices[iIndex].mBoneWeights.push_back(pairOut);
  1346. }
  1347. }
  1348. continue;
  1349. }
  1350. }
  1351. AI_ASE_HANDLE_SECTION(iDepth,"4","*MESH_BONE_VERTEX");
  1352. }
  1353. return;
  1354. }
  1355. // ------------------------------------------------------------------------------------------------
  1356. void Parser::ParseLV3MeshVertexListBlock(
  1357. unsigned int iNumVertices, ASE::Mesh& mesh)
  1358. {
  1359. // allocate enough storage in the array
  1360. mesh.mPositions.resize(iNumVertices);
  1361. int iDepth = 0;
  1362. while (true)
  1363. {
  1364. if ('*' == *m_szFile)
  1365. {
  1366. ++m_szFile;
  1367. // Vertex entry
  1368. if (TokenMatch(m_szFile,"MESH_VERTEX" ,11))
  1369. {
  1370. aiVector3D vTemp;
  1371. unsigned int iIndex;
  1372. ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
  1373. if (iIndex >= iNumVertices)
  1374. {
  1375. LogWarning("Invalid vertex index. It will be ignored");
  1376. }
  1377. else mesh.mPositions[iIndex] = vTemp;
  1378. continue;
  1379. }
  1380. }
  1381. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_VERTEX_LIST");
  1382. }
  1383. return;
  1384. }
  1385. // ------------------------------------------------------------------------------------------------
  1386. void Parser::ParseLV3MeshFaceListBlock(unsigned int iNumFaces, ASE::Mesh& mesh)
  1387. {
  1388. // allocate enough storage in the face array
  1389. mesh.mFaces.resize(iNumFaces);
  1390. int iDepth = 0;
  1391. while (true)
  1392. {
  1393. if ('*' == *m_szFile)
  1394. {
  1395. ++m_szFile;
  1396. // Face entry
  1397. if (TokenMatch(m_szFile,"MESH_FACE" ,9))
  1398. {
  1399. ASE::Face mFace;
  1400. ParseLV4MeshFace(mFace);
  1401. if (mFace.iFace >= iNumFaces)
  1402. {
  1403. LogWarning("Face has an invalid index. It will be ignored");
  1404. }
  1405. else mesh.mFaces[mFace.iFace] = mFace;
  1406. continue;
  1407. }
  1408. }
  1409. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_FACE_LIST");
  1410. }
  1411. return;
  1412. }
  1413. // ------------------------------------------------------------------------------------------------
  1414. void Parser::ParseLV3MeshTListBlock(unsigned int iNumVertices,
  1415. ASE::Mesh& mesh, unsigned int iChannel)
  1416. {
  1417. // allocate enough storage in the array
  1418. mesh.amTexCoords[iChannel].resize(iNumVertices);
  1419. int iDepth = 0;
  1420. while (true)
  1421. {
  1422. if ('*' == *m_szFile)
  1423. {
  1424. ++m_szFile;
  1425. // Vertex entry
  1426. if (TokenMatch(m_szFile,"MESH_TVERT" ,10))
  1427. {
  1428. aiVector3D vTemp;
  1429. unsigned int iIndex;
  1430. ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
  1431. if (iIndex >= iNumVertices)
  1432. {
  1433. LogWarning("Tvertex has an invalid index. It will be ignored");
  1434. }
  1435. else mesh.amTexCoords[iChannel][iIndex] = vTemp;
  1436. if (0.0f != vTemp.z)
  1437. {
  1438. // we need 3 coordinate channels
  1439. mesh.mNumUVComponents[iChannel] = 3;
  1440. }
  1441. continue;
  1442. }
  1443. }
  1444. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_TVERT_LIST");
  1445. }
  1446. return;
  1447. }
  1448. // ------------------------------------------------------------------------------------------------
  1449. void Parser::ParseLV3MeshTFaceListBlock(unsigned int iNumFaces,
  1450. ASE::Mesh& mesh, unsigned int iChannel)
  1451. {
  1452. int iDepth = 0;
  1453. while (true)
  1454. {
  1455. if ('*' == *m_szFile)
  1456. {
  1457. ++m_szFile;
  1458. // Face entry
  1459. if (TokenMatch(m_szFile,"MESH_TFACE" ,10))
  1460. {
  1461. unsigned int aiValues[3];
  1462. unsigned int iIndex = 0;
  1463. ParseLV4MeshLongTriple(aiValues,iIndex);
  1464. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
  1465. {
  1466. LogWarning("UV-Face has an invalid index. It will be ignored");
  1467. }
  1468. else
  1469. {
  1470. // copy UV indices
  1471. mesh.mFaces[iIndex].amUVIndices[iChannel][0] = aiValues[0];
  1472. mesh.mFaces[iIndex].amUVIndices[iChannel][1] = aiValues[1];
  1473. mesh.mFaces[iIndex].amUVIndices[iChannel][2] = aiValues[2];
  1474. }
  1475. continue;
  1476. }
  1477. }
  1478. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_TFACE_LIST");
  1479. }
  1480. return;
  1481. }
  1482. // ------------------------------------------------------------------------------------------------
  1483. void Parser::ParseLV3MappingChannel(unsigned int iChannel, ASE::Mesh& mesh)
  1484. {
  1485. unsigned int iNumTVertices = 0;
  1486. unsigned int iNumTFaces = 0;
  1487. int iDepth = 0;
  1488. while (true)
  1489. {
  1490. if ('*' == *m_szFile)
  1491. {
  1492. ++m_szFile;
  1493. // Number of texture coordinates in the mesh
  1494. if (TokenMatch(m_szFile,"MESH_NUMTVERTEX" ,15))
  1495. {
  1496. ParseLV4MeshLong(iNumTVertices);
  1497. continue;
  1498. }
  1499. // Number of UVWed faces in the mesh
  1500. if (TokenMatch(m_szFile,"MESH_NUMTVFACES" ,15))
  1501. {
  1502. ParseLV4MeshLong(iNumTFaces);
  1503. continue;
  1504. }
  1505. // mesh texture vertex list block
  1506. if (TokenMatch(m_szFile,"MESH_TVERTLIST" ,14))
  1507. {
  1508. ParseLV3MeshTListBlock(iNumTVertices,mesh,iChannel);
  1509. continue;
  1510. }
  1511. // mesh texture face block
  1512. if (TokenMatch(m_szFile,"MESH_TFACELIST" ,14))
  1513. {
  1514. ParseLV3MeshTFaceListBlock(iNumTFaces,mesh, iChannel);
  1515. continue;
  1516. }
  1517. }
  1518. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_MAPPING_CHANNEL");
  1519. }
  1520. return;
  1521. }
  1522. // ------------------------------------------------------------------------------------------------
  1523. void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh& mesh)
  1524. {
  1525. // allocate enough storage in the array
  1526. mesh.mVertexColors.resize(iNumVertices);
  1527. int iDepth = 0;
  1528. while (true)
  1529. {
  1530. if ('*' == *m_szFile)
  1531. {
  1532. ++m_szFile;
  1533. // Vertex entry
  1534. if (TokenMatch(m_szFile,"MESH_VERTCOL" ,12))
  1535. {
  1536. aiColor4D vTemp;
  1537. vTemp.a = 1.0f;
  1538. unsigned int iIndex;
  1539. ParseLV4MeshFloatTriple(&vTemp.r,iIndex);
  1540. if (iIndex >= iNumVertices)
  1541. {
  1542. LogWarning("Vertex color has an invalid index. It will be ignored");
  1543. }
  1544. else mesh.mVertexColors[iIndex] = vTemp;
  1545. continue;
  1546. }
  1547. }
  1548. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_CVERTEX_LIST");
  1549. }
  1550. return;
  1551. }
  1552. // ------------------------------------------------------------------------------------------------
  1553. void Parser::ParseLV3MeshCFaceListBlock(unsigned int iNumFaces, ASE::Mesh& mesh)
  1554. {
  1555. int iDepth = 0;
  1556. while (true)
  1557. {
  1558. if ('*' == *m_szFile)
  1559. {
  1560. ++m_szFile;
  1561. // Face entry
  1562. if (TokenMatch(m_szFile,"MESH_CFACE" ,11))
  1563. {
  1564. unsigned int aiValues[3];
  1565. unsigned int iIndex = 0;
  1566. ParseLV4MeshLongTriple(aiValues,iIndex);
  1567. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
  1568. {
  1569. LogWarning("UV-Face has an invalid index. It will be ignored");
  1570. }
  1571. else
  1572. {
  1573. // copy color indices
  1574. mesh.mFaces[iIndex].mColorIndices[0] = aiValues[0];
  1575. mesh.mFaces[iIndex].mColorIndices[1] = aiValues[1];
  1576. mesh.mFaces[iIndex].mColorIndices[2] = aiValues[2];
  1577. }
  1578. continue;
  1579. }
  1580. }
  1581. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_CFACE_LIST");
  1582. }
  1583. return;
  1584. }
  1585. // ------------------------------------------------------------------------------------------------
  1586. void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh& sMesh)
  1587. {
  1588. // allocate enough storage for the normals
  1589. sMesh.mNormals.resize(sMesh.mFaces.size()*3,aiVector3D( 0.f, 0.f, 0.f ));
  1590. int iDepth = 0;
  1591. unsigned int iIndex = 0, faceIdx = 0xffffffff;
  1592. // just smooth both vertex and face normals together, so it will still
  1593. // work if one one of the two is missing ...
  1594. while (true)
  1595. {
  1596. if ('*' == *m_szFile)
  1597. {
  1598. ++m_szFile;
  1599. if (0xffffffff != faceIdx && TokenMatch(m_szFile,"MESH_VERTEXNORMAL",17))
  1600. {
  1601. aiVector3D vNormal;
  1602. ParseLV4MeshFloatTriple(&vNormal.x,iIndex);
  1603. if (iIndex == sMesh.mFaces[faceIdx].mIndices[0])
  1604. {
  1605. iIndex = 0;
  1606. }
  1607. else if (iIndex != sMesh.mFaces[faceIdx].mIndices[1])
  1608. {
  1609. iIndex = 1;
  1610. }
  1611. else if (iIndex != sMesh.mFaces[faceIdx].mIndices[2])
  1612. {
  1613. iIndex = 2;
  1614. }
  1615. else
  1616. {
  1617. LogWarning("Normal index doesn't fit to face index");
  1618. continue;
  1619. }
  1620. // We'll renormalized later
  1621. sMesh.mNormals[faceIdx*3 + iIndex] += vNormal;
  1622. continue;
  1623. }
  1624. if (TokenMatch(m_szFile,"MESH_FACENORMAL",15))
  1625. {
  1626. aiVector3D vNormal;
  1627. ParseLV4MeshFloatTriple(&vNormal.x,faceIdx);
  1628. if (iIndex >= sMesh.mFaces.size())
  1629. {
  1630. LogWarning("Face normal index is too large");
  1631. faceIdx = 0xffffffff;
  1632. continue;
  1633. }
  1634. sMesh.mNormals[faceIdx*3] += vNormal;
  1635. sMesh.mNormals[faceIdx*3 +1] += vNormal;
  1636. sMesh.mNormals[faceIdx*3 +2] += vNormal;
  1637. continue;
  1638. }
  1639. }
  1640. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_NORMALS");
  1641. }
  1642. return;
  1643. }
  1644. // ------------------------------------------------------------------------------------------------
  1645. void Parser::ParseLV4MeshFace(ASE::Face& out)
  1646. {
  1647. // skip spaces and tabs
  1648. if(!SkipSpaces(&m_szFile))
  1649. {
  1650. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]");
  1651. SkipToNextToken();
  1652. return;
  1653. }
  1654. // parse the face index
  1655. out.iFace = strtol10(m_szFile,&m_szFile);
  1656. // next character should be ':'
  1657. if(!SkipSpaces(&m_szFile))
  1658. {
  1659. // FIX: there are some ASE files which haven't got : here ....
  1660. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]");
  1661. SkipToNextToken();
  1662. return;
  1663. }
  1664. // FIX: there are some ASE files which haven't got : here ....
  1665. if(':' == *m_szFile)++m_szFile;
  1666. // parse all mesh indices
  1667. for (unsigned int i = 0; i < 3;++i)
  1668. {
  1669. unsigned int iIndex = 0;
  1670. if(!SkipSpaces(&m_szFile))
  1671. {
  1672. // LOG
  1673. __EARTHQUAKE_XXL:
  1674. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
  1675. "A,B or C expected [#3]");
  1676. SkipToNextToken();
  1677. return;
  1678. }
  1679. switch (*m_szFile)
  1680. {
  1681. case 'A':
  1682. case 'a':
  1683. break;
  1684. case 'B':
  1685. case 'b':
  1686. iIndex = 1;
  1687. break;
  1688. case 'C':
  1689. case 'c':
  1690. iIndex = 2;
  1691. break;
  1692. default: goto __EARTHQUAKE_XXL;
  1693. };
  1694. ++m_szFile;
  1695. // next character should be ':'
  1696. if(!SkipSpaces(&m_szFile) || ':' != *m_szFile)
  1697. {
  1698. LogWarning("Unable to parse *MESH_FACE Element: "
  1699. "Unexpected EOL. \':\' expected [#2]");
  1700. SkipToNextToken();
  1701. return;
  1702. }
  1703. ++m_szFile;
  1704. if(!SkipSpaces(&m_szFile))
  1705. {
  1706. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
  1707. "Vertex index ecpected [#4]");
  1708. SkipToNextToken();
  1709. return;
  1710. }
  1711. out.mIndices[iIndex] = strtol10(m_szFile,&m_szFile);
  1712. }
  1713. // now we need to skip the AB, BC, CA blocks.
  1714. while (true)
  1715. {
  1716. if ('*' == *m_szFile)break;
  1717. if (IsLineEnd(*m_szFile))
  1718. {
  1719. //iLineNumber++;
  1720. return;
  1721. }
  1722. m_szFile++;
  1723. }
  1724. // parse the smoothing group of the face
  1725. if (TokenMatch(m_szFile,"*MESH_SMOOTHING",15))
  1726. {
  1727. if(!SkipSpaces(&m_szFile))
  1728. {
  1729. LogWarning("Unable to parse *MESH_SMOOTHING Element: "
  1730. "Unexpected EOL. Smoothing group(s) expected [#5]");
  1731. SkipToNextToken();
  1732. return;
  1733. }
  1734. // parse smoothing groups until we don_t anymore see commas
  1735. // FIX: There needn't always be a value, sad but true
  1736. while (true)
  1737. {
  1738. if (*m_szFile < '9' && *m_szFile >= '0')
  1739. {
  1740. out.iSmoothGroup |= (1 << strtol10(m_szFile,&m_szFile));
  1741. }
  1742. SkipSpaces(&m_szFile);
  1743. if (',' != *m_szFile)
  1744. {
  1745. break;
  1746. }
  1747. ++m_szFile;
  1748. SkipSpaces(&m_szFile);
  1749. }
  1750. }
  1751. // *MESH_MTLID is optional, too
  1752. while (true)
  1753. {
  1754. if ('*' == *m_szFile)break;
  1755. if (IsLineEnd(*m_szFile))
  1756. {
  1757. return;
  1758. }
  1759. m_szFile++;
  1760. }
  1761. if (TokenMatch(m_szFile,"*MESH_MTLID",11))
  1762. {
  1763. if(!SkipSpaces(&m_szFile))
  1764. {
  1765. LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. "
  1766. "Material index expected [#6]");
  1767. SkipToNextToken();
  1768. return;
  1769. }
  1770. out.iMaterial = strtol10(m_szFile,&m_szFile);
  1771. }
  1772. return;
  1773. }
  1774. // ------------------------------------------------------------------------------------------------
  1775. void Parser::ParseLV4MeshLongTriple(unsigned int* apOut)
  1776. {
  1777. ai_assert(NULL != apOut);
  1778. for (unsigned int i = 0; i < 3;++i)
  1779. ParseLV4MeshLong(apOut[i]);
  1780. }
  1781. // ------------------------------------------------------------------------------------------------
  1782. void Parser::ParseLV4MeshLongTriple(unsigned int* apOut, unsigned int& rIndexOut)
  1783. {
  1784. ai_assert(NULL != apOut);
  1785. // parse the index
  1786. ParseLV4MeshLong(rIndexOut);
  1787. // parse the three others
  1788. ParseLV4MeshLongTriple(apOut);
  1789. }
  1790. // ------------------------------------------------------------------------------------------------
  1791. void Parser::ParseLV4MeshFloatTriple(float* apOut, unsigned int& rIndexOut)
  1792. {
  1793. ai_assert(NULL != apOut);
  1794. // parse the index
  1795. ParseLV4MeshLong(rIndexOut);
  1796. // parse the three others
  1797. ParseLV4MeshFloatTriple(apOut);
  1798. }
  1799. // ------------------------------------------------------------------------------------------------
  1800. void Parser::ParseLV4MeshFloatTriple(float* apOut)
  1801. {
  1802. ai_assert(NULL != apOut);
  1803. for (unsigned int i = 0; i < 3;++i)
  1804. ParseLV4MeshFloat(apOut[i]);
  1805. }
  1806. // ------------------------------------------------------------------------------------------------
  1807. void Parser::ParseLV4MeshFloat(float& fOut)
  1808. {
  1809. // skip spaces and tabs
  1810. if(!SkipSpaces(&m_szFile))
  1811. {
  1812. // LOG
  1813. LogWarning("Unable to parse float: unexpected EOL [#1]");
  1814. fOut = 0.0f;
  1815. ++iLineNumber;
  1816. return;
  1817. }
  1818. // parse the first float
  1819. m_szFile = fast_atof_move(m_szFile,fOut);
  1820. }
  1821. // ------------------------------------------------------------------------------------------------
  1822. void Parser::ParseLV4MeshLong(unsigned int& iOut)
  1823. {
  1824. // skip spaces and tabs
  1825. if(!SkipSpaces(&m_szFile))
  1826. {
  1827. // LOG
  1828. LogWarning("Unable to parse long: unexpected EOL [#1]");
  1829. iOut = 0;
  1830. ++iLineNumber;
  1831. return;
  1832. }
  1833. // parse the value
  1834. iOut = strtol10(m_szFile,&m_szFile);
  1835. }