ASEParser.cpp 50 KB

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