ASEParser.cpp 69 KB

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