ASEParser.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  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. //mesh.mTransform.Transpose();
  751. }
  752. // mesh data
  753. if (0 == strncmp(this->m_szFile,"*MESH" ,5) &&
  754. IsSpaceOrNewLine(*(this->m_szFile+5)))
  755. {
  756. this->m_szFile+=6;
  757. this->ParseLV2MeshBlock(mesh);continue;
  758. }
  759. // mesh material index
  760. if (0 == strncmp(this->m_szFile,"*MATERIAL_REF" ,13) &&
  761. IsSpaceOrNewLine(*(this->m_szFile+13)))
  762. {
  763. this->m_szFile+=14;
  764. this->ParseLV4MeshLong(mesh.iMaterialIndex);continue;
  765. }
  766. // animation data of the node
  767. if (0 == strncmp(this->m_szFile,"*TM_ANIMATION" ,13) &&
  768. IsSpaceOrNewLine(*(this->m_szFile+13)))
  769. {
  770. this->m_szFile+=14;
  771. this->ParseLV2AnimationBlock(mesh);continue;
  772. }
  773. }
  774. AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
  775. }
  776. return;
  777. }
  778. // ------------------------------------------------------------------------------------------------
  779. void Parser::ParseLV2AnimationBlock(ASE::Mesh& mesh)
  780. {
  781. int iDepth = 0;
  782. while (true)
  783. {
  784. if ('*' == *this->m_szFile)
  785. {
  786. // position keyframes
  787. if (0 == strncmp(this->m_szFile,"*CONTROL_POS_TRACK" ,18) &&
  788. IsSpaceOrNewLine(*(this->m_szFile+18)))
  789. {
  790. this->m_szFile+=19;
  791. this->ParseLV3PosAnimationBlock(mesh);continue;
  792. }
  793. // rotation keyframes
  794. if (0 == strncmp(this->m_szFile,"*CONTROL_ROT_TRACK" ,18) &&
  795. IsSpaceOrNewLine(*(this->m_szFile+18)))
  796. {
  797. this->m_szFile+=19;
  798. this->ParseLV3RotAnimationBlock(mesh);continue;
  799. }
  800. }
  801. AI_ASE_HANDLE_SECTION(iDepth,"2","TM_ANIMATION");
  802. }
  803. }
  804. // ------------------------------------------------------------------------------------------------
  805. void Parser::ParseLV3PosAnimationBlock(ASE::Mesh& mesh)
  806. {
  807. int iDepth = 0;
  808. while (true)
  809. {
  810. if ('*' == *this->m_szFile)
  811. {
  812. // position keyframe
  813. if (0 == strncmp(this->m_szFile,"*CONTROL_POS_SAMPLE" ,19) &&
  814. IsSpaceOrNewLine(*(this->m_szFile+19)))
  815. {
  816. this->m_szFile+=20;
  817. unsigned int iIndex;
  818. mesh.mAnim.akeyPositions.push_back(aiVectorKey());
  819. aiVectorKey& key = mesh.mAnim.akeyPositions.back();
  820. this->ParseLV4MeshFloatTriple(&key.mValue.x,iIndex);
  821. key.mTime = (double)iIndex;
  822. }
  823. }
  824. AI_ASE_HANDLE_SECTION(iDepth,"3","*CONTROL_POS_TRACK");
  825. }
  826. }
  827. // ------------------------------------------------------------------------------------------------
  828. void Parser::ParseLV3RotAnimationBlock(ASE::Mesh& mesh)
  829. {
  830. int iDepth = 0;
  831. while (true)
  832. {
  833. if ('*' == *this->m_szFile)
  834. {
  835. // rotation keyframe
  836. if (0 == strncmp(this->m_szFile,"*CONTROL_ROT_SAMPLE" ,19) &&
  837. IsSpaceOrNewLine(*(this->m_szFile+19)))
  838. {
  839. this->m_szFile+=20;
  840. unsigned int iIndex;
  841. mesh.mAnim.akeyRotations.push_back(aiQuatKey());
  842. aiQuatKey& key = mesh.mAnim.akeyRotations.back();
  843. // first read the axis, then the angle in radians
  844. aiVector3D v;float f;
  845. this->ParseLV4MeshFloatTriple(&v.x,iIndex);
  846. this->ParseLV4MeshFloat(f);
  847. key.mTime = (double)iIndex;
  848. key.mValue = aiQuaternion(v,f);
  849. }
  850. }
  851. AI_ASE_HANDLE_SECTION(iDepth,"3","*CONTROL_ROT_TRACK");
  852. }
  853. }
  854. // ------------------------------------------------------------------------------------------------
  855. void Parser::ParseLV2NodeTransformBlock(ASE::Mesh& mesh)
  856. {
  857. int iDepth = 0;
  858. while (true)
  859. {
  860. if ('*' == *this->m_szFile)
  861. {
  862. // first row of the transformation matrix
  863. if (0 == strncmp(this->m_szFile,"*TM_ROW0" ,8) &&
  864. IsSpaceOrNewLine(*(this->m_szFile+8)))
  865. {
  866. this->m_szFile+=9;
  867. this->ParseLV4MeshFloatTriple(mesh.mTransform[0]);continue;
  868. }
  869. // second row of the transformation matrix
  870. if (0 == strncmp(this->m_szFile,"*TM_ROW1" ,8) &&
  871. IsSpaceOrNewLine(*(this->m_szFile+8)))
  872. {
  873. this->m_szFile+=9;
  874. this->ParseLV4MeshFloatTriple(mesh.mTransform[1]);continue;
  875. }
  876. // third row of the transformation matrix
  877. if (0 == strncmp(this->m_szFile,"*TM_ROW2" ,8) &&
  878. IsSpaceOrNewLine(*(this->m_szFile+8)))
  879. {
  880. this->m_szFile+=9;
  881. this->ParseLV4MeshFloatTriple(mesh.mTransform[2]);continue;
  882. }
  883. // fourth row of the transformation matrix
  884. if (0 == strncmp(this->m_szFile,"*TM_ROW3" ,8) &&
  885. IsSpaceOrNewLine(*(this->m_szFile+8)))
  886. {
  887. this->m_szFile+=9;
  888. this->ParseLV4MeshFloatTriple(mesh.mTransform[3]);continue;
  889. }
  890. // inherited position axes
  891. if (0 == strncmp(this->m_szFile,"*INHERIT_POS" ,12) &&
  892. IsSpaceOrNewLine(*(this->m_szFile+12)))
  893. {
  894. this->m_szFile+=13;
  895. unsigned int aiVal[3];
  896. this->ParseLV4MeshLongTriple(aiVal);
  897. for (unsigned int i = 0; i < 3;++i)
  898. mesh.inherit.abInheritPosition[i] = aiVal[i] != 0;
  899. continue;
  900. }
  901. // inherited rotation axes
  902. if (0 == strncmp(this->m_szFile,"*INHERIT_ROT" ,12) &&
  903. IsSpaceOrNewLine(*(this->m_szFile+12)))
  904. {
  905. this->m_szFile+=13;
  906. unsigned int aiVal[3];
  907. this->ParseLV4MeshLongTriple(aiVal);
  908. for (unsigned int i = 0; i < 3;++i)
  909. mesh.inherit.abInheritRotation[i] = aiVal[i] != 0;
  910. continue;
  911. }
  912. // inherited scaling axes
  913. if (0 == strncmp(this->m_szFile,"*INHERIT_SCL" ,12) &&
  914. IsSpaceOrNewLine(*(this->m_szFile+12)))
  915. {
  916. this->m_szFile+=13;
  917. unsigned int aiVal[3];
  918. this->ParseLV4MeshLongTriple(aiVal);
  919. for (unsigned int i = 0; i < 3;++i)
  920. mesh.inherit.abInheritScaling[i] = aiVal[i] != 0;
  921. continue;
  922. }
  923. }
  924. AI_ASE_HANDLE_SECTION(iDepth,"2","*NODE_TM");
  925. }
  926. return;
  927. }
  928. // ------------------------------------------------------------------------------------------------
  929. void Parser::ParseLV2MeshBlock(ASE::Mesh& mesh)
  930. {
  931. unsigned int iNumVertices = 0;
  932. unsigned int iNumFaces = 0;
  933. unsigned int iNumTVertices = 0;
  934. unsigned int iNumTFaces = 0;
  935. unsigned int iNumCVertices = 0;
  936. unsigned int iNumCFaces = 0;
  937. int iDepth = 0;
  938. while (true)
  939. {
  940. if ('*' == *this->m_szFile)
  941. {
  942. // Number of vertices in the mesh
  943. if (0 == strncmp(this->m_szFile,"*MESH_NUMVERTEX" ,15) &&
  944. IsSpaceOrNewLine(*(this->m_szFile+15)))
  945. {
  946. this->m_szFile+=16;
  947. this->ParseLV4MeshLong(iNumVertices);continue;
  948. }
  949. // Number of texture coordinates in the mesh
  950. if (0 == strncmp(this->m_szFile,"*MESH_NUMTVERTEX" ,16) &&
  951. IsSpaceOrNewLine(*(this->m_szFile+16)))
  952. {
  953. this->m_szFile+=17;
  954. this->ParseLV4MeshLong(iNumTVertices);continue;
  955. }
  956. // Number of vertex colors in the mesh
  957. if (0 == strncmp(this->m_szFile,"*MESH_NUMCVERTEX" ,16) &&
  958. IsSpaceOrNewLine(*(this->m_szFile+16)))
  959. {
  960. this->m_szFile+=17;
  961. this->ParseLV4MeshLong(iNumCVertices);continue;
  962. }
  963. // Number of regular faces in the mesh
  964. if (0 == strncmp(this->m_szFile,"*MESH_NUMFACES" ,14) &&
  965. IsSpaceOrNewLine(*(this->m_szFile+14)))
  966. {
  967. this->m_szFile+=15;
  968. this->ParseLV4MeshLong(iNumFaces);continue;
  969. // fix ...
  970. //mesh.mFaces.resize(iNumFaces);
  971. }
  972. // Number of UVWed faces in the mesh
  973. if (0 == strncmp(this->m_szFile,"*MESH_NUMTVFACES" ,16) &&
  974. IsSpaceOrNewLine(*(this->m_szFile+16)))
  975. {
  976. this->m_szFile+=17;
  977. this->ParseLV4MeshLong(iNumTFaces);continue;
  978. }
  979. // Number of colored faces in the mesh
  980. if (0 == strncmp(this->m_szFile,"*MESH_NUMCVFACES" ,16) &&
  981. IsSpaceOrNewLine(*(this->m_szFile+16)))
  982. {
  983. this->m_szFile+=17;
  984. this->ParseLV4MeshLong(iNumCFaces);continue;
  985. }
  986. // mesh vertex list block
  987. if (0 == strncmp(this->m_szFile,"*MESH_VERTEX_LIST" ,17) &&
  988. IsSpaceOrNewLine(*(this->m_szFile+17)))
  989. {
  990. this->m_szFile+=18;
  991. this->ParseLV3MeshVertexListBlock(iNumVertices,mesh);
  992. continue;
  993. }
  994. // mesh face list block
  995. if (0 == strncmp(this->m_szFile,"*MESH_FACE_LIST" ,15) &&
  996. IsSpaceOrNewLine(*(this->m_szFile+15)))
  997. {
  998. this->m_szFile+=16;
  999. this->SkipOpeningBracket();
  1000. this->ParseLV3MeshFaceListBlock(iNumFaces,mesh);continue;
  1001. }
  1002. // mesh texture vertex list block
  1003. if (0 == strncmp(this->m_szFile,"*MESH_TVERTLIST" ,15) &&
  1004. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1005. {
  1006. this->m_szFile+=16;
  1007. this->SkipOpeningBracket();
  1008. this->ParseLV3MeshTListBlock(iNumTVertices,mesh);continue;
  1009. }
  1010. // mesh texture face block
  1011. if (0 == strncmp(this->m_szFile,"*MESH_TFACELIST" ,15) &&
  1012. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1013. {
  1014. this->m_szFile+=16;
  1015. this->SkipOpeningBracket();
  1016. this->ParseLV3MeshTFaceListBlock(iNumTFaces,mesh);continue;
  1017. }
  1018. // mesh color vertex list block
  1019. if (0 == strncmp(this->m_szFile,"*MESH_CVERTLIST" ,15) &&
  1020. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1021. {
  1022. this->m_szFile+=16;
  1023. this->SkipOpeningBracket();
  1024. this->ParseLV3MeshCListBlock(iNumCVertices,mesh);continue;
  1025. }
  1026. // mesh color face block
  1027. if (0 == strncmp(this->m_szFile,"*MESH_CFACELIST" ,15) &&
  1028. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1029. {
  1030. this->m_szFile+=16;
  1031. this->SkipOpeningBracket();
  1032. this->ParseLV3MeshCFaceListBlock(iNumCFaces,mesh);continue;
  1033. }
  1034. // another mesh UV channel ...
  1035. if (0 == strncmp(this->m_szFile,"*MESH_MAPPINGCHANNEL" ,20) &&
  1036. IsSpaceOrNewLine(*(this->m_szFile+20)))
  1037. {
  1038. this->m_szFile+=21;
  1039. unsigned int iIndex = 0;
  1040. this->ParseLV4MeshLong(iIndex);
  1041. if (iIndex < 2)
  1042. {
  1043. this->LogWarning("Mapping channel has an invalid index. Skipping UV channel");
  1044. // skip it ...
  1045. this->SkipOpeningBracket();
  1046. this->SkipSection();
  1047. }
  1048. if (iIndex > AI_MAX_NUMBER_OF_TEXTURECOORDS)
  1049. {
  1050. this->LogWarning("Too many UV channels specified. Skipping channel ..");
  1051. // skip it ...
  1052. this->SkipOpeningBracket();
  1053. this->SkipSection();
  1054. }
  1055. else
  1056. {
  1057. // skip the '{'
  1058. this->SkipOpeningBracket();
  1059. // parse the mapping channel
  1060. this->ParseLV3MappingChannel(iIndex-1,mesh);
  1061. }
  1062. continue;
  1063. }
  1064. // mesh animation keyframe. Not supported
  1065. if (0 == strncmp(this->m_szFile,"*MESH_ANIMATION" ,15) &&
  1066. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1067. {
  1068. this->m_szFile+=16;
  1069. this->LogWarning("Found *MESH_ANIMATION element in ASE/ASK file. "
  1070. "Keyframe animation is not supported by Assimp, this element "
  1071. "will be ignored");
  1072. //this->SkipSection();
  1073. continue;
  1074. }
  1075. // mesh animation keyframe. Not supported
  1076. if (0 == strncmp(this->m_szFile,"*MESH_WEIGHTS" ,13) &&
  1077. IsSpaceOrNewLine(*(this->m_szFile+13)))
  1078. {
  1079. this->m_szFile+=14;
  1080. this->ParseLV3MeshWeightsBlock(mesh);continue;
  1081. }
  1082. }
  1083. AI_ASE_HANDLE_SECTION(iDepth,"2","*MESH");
  1084. }
  1085. return;
  1086. }
  1087. // ------------------------------------------------------------------------------------------------
  1088. void Parser::ParseLV3MeshWeightsBlock(ASE::Mesh& mesh)
  1089. {
  1090. unsigned int iNumVertices = 0;
  1091. unsigned int iNumBones = 0;
  1092. int iDepth = 0;
  1093. while (true)
  1094. {
  1095. if ('*' == *this->m_szFile)
  1096. {
  1097. // Number of bone vertices ...
  1098. if (0 == strncmp(this->m_szFile,"*MESH_NUMVERTEX" ,15) &&
  1099. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1100. {
  1101. this->m_szFile+=16;
  1102. this->ParseLV4MeshLong(iNumVertices);continue;
  1103. }
  1104. // Number of bones
  1105. if (0 == strncmp(this->m_szFile,"*MESH_NUMBONE" ,13) &&
  1106. IsSpaceOrNewLine(*(this->m_szFile+13)))
  1107. {
  1108. this->m_szFile+=14;
  1109. this->ParseLV4MeshLong(iNumBones);continue;
  1110. }
  1111. // parse the list of bones
  1112. if (0 == strncmp(this->m_szFile,"*MESH_BONE_LIST" ,15) &&
  1113. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1114. {
  1115. this->m_szFile+=16;
  1116. this->SkipOpeningBracket();
  1117. this->ParseLV4MeshBones(iNumBones,mesh);continue;
  1118. }
  1119. // parse the list of bones vertices
  1120. if (0 == strncmp(this->m_szFile,"*MESH_BONE_VERTEX_LIST" ,22) &&
  1121. IsSpaceOrNewLine(*(this->m_szFile+22)))
  1122. {
  1123. this->m_szFile+=23;
  1124. this->SkipOpeningBracket();
  1125. this->ParseLV4MeshBonesVertices(iNumVertices,mesh);
  1126. continue;
  1127. }
  1128. }
  1129. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_WEIGHTS");
  1130. }
  1131. return;
  1132. }
  1133. // ------------------------------------------------------------------------------------------------
  1134. void Parser::ParseLV4MeshBones(unsigned int iNumBones,ASE::Mesh& mesh)
  1135. {
  1136. mesh.mBones.resize(iNumBones);
  1137. int iDepth = 0;
  1138. while (true)
  1139. {
  1140. if ('*' == *this->m_szFile)
  1141. {
  1142. // Mesh bone with name ...
  1143. if (0 == strncmp(this->m_szFile,"*MESH_BONE_NAME" ,17) &&
  1144. IsSpaceOrNewLine(*(this->m_szFile+17)))
  1145. {
  1146. this->m_szFile+=18;
  1147. // parse an index ...
  1148. if(SkipSpaces(this->m_szFile,&this->m_szFile))
  1149. {
  1150. unsigned int iIndex = strtol10(this->m_szFile,&this->m_szFile);
  1151. if (iIndex >= iNumBones)
  1152. {
  1153. iIndex = iNumBones-1;
  1154. this->LogWarning("Bone index is out of bounds. Using the largest valid "
  1155. "bone index instead");
  1156. }
  1157. if (!this->ParseString(mesh.mBones[iIndex].mName,"*MESH_BONE_NAME"))
  1158. this->SkipToNextToken();
  1159. continue;
  1160. }
  1161. }
  1162. }
  1163. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_BONE_LIST");
  1164. }
  1165. }
  1166. // ------------------------------------------------------------------------------------------------
  1167. void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices,ASE::Mesh& mesh)
  1168. {
  1169. mesh.mBoneVertices.resize(iNumVertices);
  1170. int iDepth = 0;
  1171. while (true)
  1172. {
  1173. if ('*' == *this->m_szFile)
  1174. {
  1175. // Mesh bone vertex
  1176. if (0 == strncmp(this->m_szFile,"*MESH_BONE_VERTEX" ,17) &&
  1177. IsSpaceOrNewLine(*(this->m_szFile+17)))
  1178. {
  1179. this->m_szFile+=18;
  1180. // read the vertex index
  1181. unsigned int iIndex = strtol10(this->m_szFile,&this->m_szFile);
  1182. if (iIndex >= mesh.mPositions.size())
  1183. {
  1184. iIndex = (unsigned int)mesh.mPositions.size()-1;
  1185. this->LogWarning("Bone vertex index is out of bounds. Using the largest valid "
  1186. "bone vertex index instead");
  1187. }
  1188. // now there there are 3 normal floats, the
  1189. // should be identical to the vertex positions
  1190. // contained in the *VERTEX_LIST block. Well, we check this
  1191. // in debug builds to be sure ;-)
  1192. float afVert[3];
  1193. this->ParseLV4MeshFloatTriple(afVert);
  1194. std::pair<int,float> pairOut;
  1195. while (true)
  1196. {
  1197. // first parse the bone index ...
  1198. if (!SkipSpaces(this->m_szFile,&this->m_szFile))break;
  1199. pairOut.first = strtol10(this->m_szFile,&this->m_szFile);
  1200. // then parse the vertex weight
  1201. if (!SkipSpaces(this->m_szFile,&this->m_szFile))break;
  1202. this->m_szFile = fast_atof_move(this->m_szFile,pairOut.second);
  1203. // -1 designates unused entries
  1204. if (-1 != pairOut.first)
  1205. {
  1206. mesh.mBoneVertices[iIndex].mBoneWeights.push_back(pairOut);
  1207. }
  1208. }
  1209. continue;
  1210. }
  1211. }
  1212. AI_ASE_HANDLE_SECTION(iDepth,"4","*MESH_BONE_VERTEX");
  1213. }
  1214. return;
  1215. }
  1216. // ------------------------------------------------------------------------------------------------
  1217. void Parser::ParseLV3MeshVertexListBlock(
  1218. unsigned int iNumVertices, ASE::Mesh& mesh)
  1219. {
  1220. // allocate enough storage in the array
  1221. mesh.mPositions.resize(iNumVertices);
  1222. int iDepth = 0;
  1223. while (true)
  1224. {
  1225. if ('*' == *this->m_szFile)
  1226. {
  1227. // Vertex entry
  1228. if (0 == strncmp(this->m_szFile,"*MESH_VERTEX" ,12) &&
  1229. IsSpaceOrNewLine(*(this->m_szFile+12)))
  1230. {
  1231. this->m_szFile+=13;
  1232. aiVector3D vTemp;
  1233. unsigned int iIndex;
  1234. this->ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
  1235. if (iIndex >= iNumVertices)
  1236. {
  1237. this->LogWarning("Vertex has an invalid index. It will be ignored");
  1238. }
  1239. else mesh.mPositions[iIndex] = vTemp;
  1240. continue;
  1241. }
  1242. }
  1243. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_VERTEX_LIST");
  1244. }
  1245. return;
  1246. }
  1247. // ------------------------------------------------------------------------------------------------
  1248. void Parser::ParseLV3MeshFaceListBlock(unsigned int iNumFaces, ASE::Mesh& mesh)
  1249. {
  1250. // allocate enough storage in the face array
  1251. mesh.mFaces.resize(iNumFaces);
  1252. int iDepth = 0;
  1253. while (true)
  1254. {
  1255. if ('*' == *this->m_szFile)
  1256. {
  1257. // Face entry
  1258. if (0 == strncmp(this->m_szFile,"*MESH_FACE" ,10) &&
  1259. IsSpaceOrNewLine(*(this->m_szFile+10)))
  1260. {
  1261. this->m_szFile+=11;
  1262. ASE::Face mFace;
  1263. this->ParseLV4MeshFace(mFace);
  1264. if (mFace.iFace >= iNumFaces)
  1265. {
  1266. this->LogWarning("Face has an invalid index. It will be ignored");
  1267. }
  1268. else mesh.mFaces[mFace.iFace] = mFace;
  1269. continue;
  1270. }
  1271. }
  1272. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_FACE_LIST");
  1273. }
  1274. return;
  1275. }
  1276. // ------------------------------------------------------------------------------------------------
  1277. void Parser::ParseLV3MeshTListBlock(unsigned int iNumVertices,
  1278. ASE::Mesh& mesh, unsigned int iChannel)
  1279. {
  1280. // allocate enough storage in the array
  1281. mesh.amTexCoords[iChannel].resize(iNumVertices);
  1282. int iDepth = 0;
  1283. while (true)
  1284. {
  1285. if ('*' == *this->m_szFile)
  1286. {
  1287. // Vertex entry
  1288. if (0 == strncmp(this->m_szFile,"*MESH_TVERT" ,11) &&
  1289. IsSpaceOrNewLine(*(this->m_szFile+11)))
  1290. {
  1291. this->m_szFile+=12;
  1292. aiVector3D vTemp;
  1293. unsigned int iIndex;
  1294. this->ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
  1295. if (iIndex >= iNumVertices)
  1296. {
  1297. this->LogWarning("Tvertex has an invalid index. It will be ignored");
  1298. }
  1299. else mesh.amTexCoords[iChannel][iIndex] = vTemp;
  1300. if (0.0f != vTemp.z)
  1301. {
  1302. // we need 3 coordinate channels
  1303. mesh.mNumUVComponents[iChannel] = 3;
  1304. }
  1305. continue;
  1306. }
  1307. }
  1308. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_TVERT_LIST");
  1309. }
  1310. return;
  1311. }
  1312. // ------------------------------------------------------------------------------------------------
  1313. void Parser::ParseLV3MeshTFaceListBlock(unsigned int iNumFaces,
  1314. ASE::Mesh& mesh, unsigned int iChannel)
  1315. {
  1316. int iDepth = 0;
  1317. while (true)
  1318. {
  1319. if ('*' == *this->m_szFile)
  1320. {
  1321. // Face entry
  1322. if (0 == strncmp(this->m_szFile,"*MESH_TFACE" ,12) &&
  1323. IsSpaceOrNewLine(*(this->m_szFile+12)))
  1324. {
  1325. this->m_szFile+=13;
  1326. unsigned int aiValues[3];
  1327. unsigned int iIndex = 0;
  1328. this->ParseLV4MeshLongTriple(aiValues,iIndex);
  1329. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
  1330. {
  1331. this->LogWarning("UV-Face has an invalid index. It will be ignored");
  1332. }
  1333. else
  1334. {
  1335. // copy UV indices
  1336. mesh.mFaces[iIndex].amUVIndices[iChannel][0] = aiValues[0];
  1337. mesh.mFaces[iIndex].amUVIndices[iChannel][1] = aiValues[1];
  1338. mesh.mFaces[iIndex].amUVIndices[iChannel][2] = aiValues[2];
  1339. }
  1340. continue;
  1341. }
  1342. }
  1343. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_TFACE_LIST");
  1344. }
  1345. return;
  1346. }
  1347. // ------------------------------------------------------------------------------------------------
  1348. void Parser::ParseLV3MappingChannel(unsigned int iChannel, ASE::Mesh& mesh)
  1349. {
  1350. unsigned int iNumTVertices = 0;
  1351. unsigned int iNumTFaces = 0;
  1352. int iDepth = 0;
  1353. while (true)
  1354. {
  1355. if ('*' == *this->m_szFile)
  1356. {
  1357. // Number of texture coordinates in the mesh
  1358. if (0 == strncmp(this->m_szFile,"*MESH_NUMTVERTEX" ,16) &&
  1359. IsSpaceOrNewLine(*(this->m_szFile+16)))
  1360. {
  1361. this->m_szFile+=17;
  1362. this->ParseLV4MeshLong(iNumTVertices);continue;
  1363. }
  1364. // Number of UVWed faces in the mesh
  1365. if (0 == strncmp(this->m_szFile,"*MESH_NUMTVFACES" ,16) &&
  1366. IsSpaceOrNewLine(*(this->m_szFile+16)))
  1367. {
  1368. this->m_szFile+=17;
  1369. this->ParseLV4MeshLong(iNumTFaces);continue;
  1370. }
  1371. // mesh texture vertex list block
  1372. if (0 == strncmp(this->m_szFile,"*MESH_TVERTLIST" ,15) &&
  1373. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1374. {
  1375. this->m_szFile+=16;
  1376. this->SkipOpeningBracket();
  1377. this->ParseLV3MeshTListBlock(iNumTVertices,mesh,iChannel);
  1378. continue;
  1379. }
  1380. // mesh texture face block
  1381. if (0 == strncmp(this->m_szFile,"*MESH_TFACELIST" ,15) &&
  1382. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1383. {
  1384. this->m_szFile+=16;
  1385. this->SkipOpeningBracket();
  1386. this->ParseLV3MeshTFaceListBlock(iNumTFaces,mesh, iChannel);
  1387. continue;
  1388. }
  1389. }
  1390. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_MAPPING_CHANNEL");
  1391. }
  1392. return;
  1393. }
  1394. // ------------------------------------------------------------------------------------------------
  1395. void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh& mesh)
  1396. {
  1397. // allocate enough storage in the array
  1398. mesh.mVertexColors.resize(iNumVertices);
  1399. int iDepth = 0;
  1400. while (true)
  1401. {
  1402. if ('*' == *this->m_szFile)
  1403. {
  1404. // Vertex entry
  1405. if (0 == strncmp(this->m_szFile,"*MESH_VERTCOL" ,13) &&
  1406. IsSpaceOrNewLine(*(this->m_szFile+13)))
  1407. {
  1408. this->m_szFile+=14;
  1409. aiColor4D vTemp;
  1410. vTemp.a = 1.0f;
  1411. unsigned int iIndex;
  1412. this->ParseLV4MeshFloatTriple(&vTemp.r,iIndex);
  1413. if (iIndex >= iNumVertices)
  1414. {
  1415. this->LogWarning("Vertex color has an invalid index. It will be ignored");
  1416. }
  1417. else mesh.mVertexColors[iIndex] = vTemp;
  1418. continue;
  1419. }
  1420. }
  1421. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_CVERTEX_LIST");
  1422. }
  1423. return;
  1424. }
  1425. // ------------------------------------------------------------------------------------------------
  1426. void Parser::ParseLV3MeshCFaceListBlock(unsigned int iNumFaces, ASE::Mesh& mesh)
  1427. {
  1428. int iDepth = 0;
  1429. while (true)
  1430. {
  1431. if ('*' == *this->m_szFile)
  1432. {
  1433. // Face entry
  1434. if (0 == strncmp(this->m_szFile,"*MESH_CFACE" ,12) &&
  1435. IsSpaceOrNewLine(*(this->m_szFile+12)))
  1436. {
  1437. this->m_szFile+=13;
  1438. unsigned int aiValues[3];
  1439. unsigned int iIndex = 0;
  1440. this->ParseLV4MeshLongTriple(aiValues,iIndex);
  1441. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
  1442. {
  1443. this->LogWarning("UV-Face has an invalid index. It will be ignored");
  1444. }
  1445. else
  1446. {
  1447. // copy color indices
  1448. mesh.mFaces[iIndex].mColorIndices[0] = aiValues[0];
  1449. mesh.mFaces[iIndex].mColorIndices[1] = aiValues[1];
  1450. mesh.mFaces[iIndex].mColorIndices[2] = aiValues[2];
  1451. }
  1452. continue;
  1453. }
  1454. }
  1455. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_CFACE_LIST");
  1456. }
  1457. return;
  1458. }
  1459. // ------------------------------------------------------------------------------------------------
  1460. void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh& sMesh)
  1461. {
  1462. // allocate enough storage for the normals
  1463. sMesh.mNormals.resize(sMesh.mPositions.size(),
  1464. aiVector3D( std::numeric_limits<float>::quiet_NaN(), 0.0f, 0.0f));
  1465. int iDepth = 0;
  1466. // we need the *MESH_VERTEXNORMAL blocks, ignore the face normals
  1467. // if there are only face normals we calculate them outselfes using the SGs
  1468. while (true)
  1469. {
  1470. if ('*' == *this->m_szFile)
  1471. {
  1472. if (0 == strncmp(this->m_szFile,"*MESH_VERTEXNORMAL",18) &&
  1473. IsSpaceOrNewLine(*(this->m_szFile+18)))
  1474. {
  1475. this->m_szFile += 19;
  1476. // parse a simple float triple
  1477. aiVector3D vNormal;
  1478. unsigned int iIndex = 0;
  1479. this->ParseLV4MeshFloatTriple(&vNormal.x,iIndex);
  1480. if (iIndex >= sMesh.mNormals.size())
  1481. {
  1482. this->LogWarning("Normal index is too large");
  1483. iIndex = (unsigned int)sMesh.mNormals.size()-1;
  1484. }
  1485. // important: this->m_szFile might now point to '}' ...
  1486. sMesh.mNormals[iIndex] = vNormal;
  1487. continue;
  1488. }
  1489. }
  1490. AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_NORMALS");
  1491. }
  1492. return;
  1493. }
  1494. // ------------------------------------------------------------------------------------------------
  1495. void Parser::ParseLV4MeshFace(ASE::Face& out)
  1496. {
  1497. // skip spaces and tabs
  1498. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1499. {
  1500. this->LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]");
  1501. this->SkipToNextToken();
  1502. return;
  1503. }
  1504. // parse the face index
  1505. out.iFace = strtol10(this->m_szFile,&this->m_szFile);
  1506. // next character should be ':'
  1507. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1508. {
  1509. // FIX: there are some ASE files which haven't got : here ....
  1510. this->LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]");
  1511. this->SkipToNextToken();
  1512. return;
  1513. }
  1514. // FIX: there are some ASE files which haven't got : here ....
  1515. if(':' == *this->m_szFile)++this->m_szFile;
  1516. // parse all mesh indices
  1517. for (unsigned int i = 0; i < 3;++i)
  1518. {
  1519. unsigned int iIndex = 0;
  1520. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1521. {
  1522. // LOG
  1523. __EARTHQUAKE_XXL:
  1524. this->LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
  1525. "A,B or C expected [#3]");
  1526. this->SkipToNextToken();
  1527. return;
  1528. }
  1529. switch (*this->m_szFile)
  1530. {
  1531. case 'A':
  1532. case 'a':
  1533. break;
  1534. case 'B':
  1535. case 'b':
  1536. iIndex = 1;
  1537. break;
  1538. case 'C':
  1539. case 'c':
  1540. iIndex = 2;
  1541. break;
  1542. default: goto __EARTHQUAKE_XXL;
  1543. };
  1544. ++this->m_szFile;
  1545. // next character should be ':'
  1546. if(!SkipSpaces(this->m_szFile,&this->m_szFile) || ':' != *this->m_szFile)
  1547. {
  1548. this->LogWarning("Unable to parse *MESH_FACE Element: "
  1549. "Unexpected EOL. \':\' expected [#2]");
  1550. this->SkipToNextToken();
  1551. return;
  1552. }
  1553. ++this->m_szFile;
  1554. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1555. {
  1556. this->LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
  1557. "Vertex index ecpected [#4]");
  1558. this->SkipToNextToken();
  1559. return;
  1560. }
  1561. out.mIndices[iIndex] = strtol10(this->m_szFile,&this->m_szFile);
  1562. }
  1563. // now we need to skip the AB, BC, CA blocks.
  1564. while (true)
  1565. {
  1566. if ('*' == *this->m_szFile)break;
  1567. if (IsLineEnd(*this->m_szFile))
  1568. {
  1569. //this->iLineNumber++;
  1570. return;
  1571. }
  1572. this->m_szFile++;
  1573. }
  1574. // parse the smoothing group of the face
  1575. if (0 == strncmp(this->m_szFile,"*MESH_SMOOTHING",15) &&
  1576. IsSpaceOrNewLine(*(this->m_szFile+15)))
  1577. {
  1578. this->m_szFile+=16;
  1579. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1580. {
  1581. this->LogWarning("Unable to parse *MESH_SMOOTHING Element: "
  1582. "Unexpected EOL. Smoothing group(s) expected [#5]");
  1583. this->SkipToNextToken();
  1584. return;
  1585. }
  1586. // parse smoothing groups until we don_t anymore see commas
  1587. // FIX: There needn't always be a value, sad but true
  1588. while (true)
  1589. {
  1590. if (*this->m_szFile < '9' && *this->m_szFile >= '0')
  1591. {
  1592. out.iSmoothGroup |= (1 << strtol10(this->m_szFile,&this->m_szFile));
  1593. }
  1594. SkipSpaces(this->m_szFile,&this->m_szFile);
  1595. if (',' != *this->m_szFile)
  1596. {
  1597. break;
  1598. }
  1599. ++this->m_szFile;
  1600. SkipSpaces(this->m_szFile,&this->m_szFile);
  1601. }
  1602. }
  1603. // *MESH_MTLID is optional, too
  1604. while (true)
  1605. {
  1606. if ('*' == *this->m_szFile)break;
  1607. if (IsLineEnd(*this->m_szFile))
  1608. {
  1609. //this->iLineNumber++;
  1610. return;
  1611. }
  1612. this->m_szFile++;
  1613. }
  1614. if (0 == strncmp(this->m_szFile,"*MESH_MTLID",11) && IsSpaceOrNewLine(*(this->m_szFile+11)))
  1615. {
  1616. this->m_szFile+=12;
  1617. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1618. {
  1619. this->LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. "
  1620. "Material index expected [#6]");
  1621. this->SkipToNextToken();
  1622. return;
  1623. }
  1624. out.iMaterial = strtol10(this->m_szFile,&this->m_szFile);
  1625. }
  1626. return;
  1627. }
  1628. // ------------------------------------------------------------------------------------------------
  1629. void Parser::ParseLV4MeshLongTriple(unsigned int* apOut)
  1630. {
  1631. ai_assert(NULL != apOut);
  1632. for (unsigned int i = 0; i < 3;++i)
  1633. {
  1634. // skip spaces and tabs
  1635. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1636. {
  1637. // LOG
  1638. this->LogWarning("Unable to parse indexable long triple: unexpected EOL [#1]");
  1639. ++this->iLineNumber;
  1640. apOut[0] = apOut[1] = apOut[2] = 0;
  1641. return;
  1642. }
  1643. apOut[i] = strtol10(this->m_szFile,&this->m_szFile);
  1644. }
  1645. }
  1646. // ------------------------------------------------------------------------------------------------
  1647. void Parser::ParseLV4MeshLongTriple(unsigned int* apOut, unsigned int& rIndexOut)
  1648. {
  1649. ai_assert(NULL != apOut);
  1650. // skip spaces and tabs
  1651. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1652. {
  1653. // LOG
  1654. this->LogWarning("Unable to parse indexed long triple: unexpected EOL [#4]");
  1655. rIndexOut = 0;
  1656. apOut[0] = apOut[1] = apOut[2] = 0;
  1657. ++this->iLineNumber;
  1658. return;
  1659. }
  1660. // parse the index
  1661. rIndexOut = strtol10(this->m_szFile,&this->m_szFile);
  1662. // parse the three others
  1663. this->ParseLV4MeshLongTriple(apOut);
  1664. return;
  1665. }
  1666. // ------------------------------------------------------------------------------------------------
  1667. void Parser::ParseLV4MeshFloatTriple(float* apOut, unsigned int& rIndexOut)
  1668. {
  1669. ai_assert(NULL != apOut);
  1670. // skip spaces and tabs
  1671. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1672. {
  1673. // LOG
  1674. this->LogWarning("Unable to parse indexed float triple: unexpected EOL [#1]");
  1675. rIndexOut = 0;
  1676. apOut[0] = apOut[1] = apOut[2] = 0.0f;
  1677. ++this->iLineNumber;
  1678. return;
  1679. }
  1680. // parse the index
  1681. rIndexOut = strtol10(this->m_szFile,&this->m_szFile);
  1682. // parse the three others
  1683. this->ParseLV4MeshFloatTriple(apOut);
  1684. return;
  1685. }
  1686. // ------------------------------------------------------------------------------------------------
  1687. void Parser::ParseLV4MeshFloatTriple(float* apOut)
  1688. {
  1689. ai_assert(NULL != apOut);
  1690. for (unsigned int i = 0; i < 3;++i)
  1691. {
  1692. // skip spaces and tabs
  1693. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1694. {
  1695. // LOG
  1696. this->LogWarning("Unable to parse float triple: unexpected EOL [#5]");
  1697. apOut[0] = apOut[1] = apOut[2] = 0.0f;
  1698. ++this->iLineNumber;
  1699. return;
  1700. }
  1701. // parse the float
  1702. this->m_szFile = fast_atof_move(this->m_szFile,apOut[i]);
  1703. }
  1704. return;
  1705. }
  1706. // ------------------------------------------------------------------------------------------------
  1707. void Parser::ParseLV4MeshFloat(float& fOut)
  1708. {
  1709. // skip spaces and tabs
  1710. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1711. {
  1712. // LOG
  1713. this->LogWarning("Unable to parse float: unexpected EOL [#1]");
  1714. fOut = 0.0f;
  1715. ++this->iLineNumber;
  1716. return;
  1717. }
  1718. // parse the first float
  1719. this->m_szFile = fast_atof_move(this->m_szFile,fOut);
  1720. // go to the next valid sequence
  1721. //this->SkipToNextToken();
  1722. return;
  1723. }
  1724. // ------------------------------------------------------------------------------------------------
  1725. void Parser::ParseLV4MeshLong(unsigned int& iOut)
  1726. {
  1727. // skip spaces and tabs
  1728. if(!SkipSpaces(this->m_szFile,&this->m_szFile))
  1729. {
  1730. // LOG
  1731. this->LogWarning("Unable to parse long: unexpected EOL [#1]");
  1732. iOut = 0;
  1733. ++this->iLineNumber;
  1734. return;
  1735. }
  1736. // parse the value
  1737. iOut = strtol10(this->m_szFile,&this->m_szFile);
  1738. // go to the next valid sequence
  1739. //this->SkipToNextToken();
  1740. return;
  1741. }