ASEParser.cpp 53 KB

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