ASEParser.cpp 51 KB

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