ASEParser.cpp 50 KB

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