ASEParser.cpp 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2020, 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. }
  425. // get a reference to the material
  426. Material &sMat = m_vMaterials[iIndex + iOldMaterialCount];
  427. // parse the material block
  428. ParseLV2MaterialBlock(sMat);
  429. continue;
  430. }
  431. }
  432. AI_ASE_HANDLE_TOP_LEVEL_SECTION();
  433. }
  434. }
  435. // ------------------------------------------------------------------------------------------------
  436. void Parser::ParseLV2MaterialBlock(ASE::Material &mat) {
  437. AI_ASE_PARSER_INIT();
  438. unsigned int iNumSubMaterials = 0;
  439. while (true) {
  440. if ('*' == *filePtr) {
  441. ++filePtr;
  442. if (TokenMatch(filePtr, "MATERIAL_NAME", 13)) {
  443. if (!ParseString(mat.mName, "*MATERIAL_NAME"))
  444. SkipToNextToken();
  445. continue;
  446. }
  447. // ambient material color
  448. if (TokenMatch(filePtr, "MATERIAL_AMBIENT", 16)) {
  449. ParseLV4MeshFloatTriple(&mat.mAmbient.r);
  450. continue;
  451. }
  452. // diffuse material color
  453. if (TokenMatch(filePtr, "MATERIAL_DIFFUSE", 16)) {
  454. ParseLV4MeshFloatTriple(&mat.mDiffuse.r);
  455. continue;
  456. }
  457. // specular material color
  458. if (TokenMatch(filePtr, "MATERIAL_SPECULAR", 17)) {
  459. ParseLV4MeshFloatTriple(&mat.mSpecular.r);
  460. continue;
  461. }
  462. // material shading type
  463. if (TokenMatch(filePtr, "MATERIAL_SHADING", 16)) {
  464. if (TokenMatch(filePtr, "Blinn", 5)) {
  465. mat.mShading = Discreet3DS::Blinn;
  466. } else if (TokenMatch(filePtr, "Phong", 5)) {
  467. mat.mShading = Discreet3DS::Phong;
  468. } else if (TokenMatch(filePtr, "Flat", 4)) {
  469. mat.mShading = Discreet3DS::Flat;
  470. } else if (TokenMatch(filePtr, "Wire", 4)) {
  471. mat.mShading = Discreet3DS::Wire;
  472. } else {
  473. // assume gouraud shading
  474. mat.mShading = Discreet3DS::Gouraud;
  475. SkipToNextToken();
  476. }
  477. continue;
  478. }
  479. // material transparency
  480. if (TokenMatch(filePtr, "MATERIAL_TRANSPARENCY", 21)) {
  481. ParseLV4MeshFloat(mat.mTransparency);
  482. mat.mTransparency = ai_real(1.0) - mat.mTransparency;
  483. continue;
  484. }
  485. // material self illumination
  486. if (TokenMatch(filePtr, "MATERIAL_SELFILLUM", 18)) {
  487. ai_real f = 0.0;
  488. ParseLV4MeshFloat(f);
  489. mat.mEmissive.r = f;
  490. mat.mEmissive.g = f;
  491. mat.mEmissive.b = f;
  492. continue;
  493. }
  494. // material shininess
  495. if (TokenMatch(filePtr, "MATERIAL_SHINE", 14)) {
  496. ParseLV4MeshFloat(mat.mSpecularExponent);
  497. mat.mSpecularExponent *= 15;
  498. continue;
  499. }
  500. // two-sided material
  501. if (TokenMatch(filePtr, "MATERIAL_TWOSIDED", 17)) {
  502. mat.mTwoSided = true;
  503. continue;
  504. }
  505. // material shininess strength
  506. if (TokenMatch(filePtr, "MATERIAL_SHINESTRENGTH", 22)) {
  507. ParseLV4MeshFloat(mat.mShininessStrength);
  508. continue;
  509. }
  510. // diffuse color map
  511. if (TokenMatch(filePtr, "MAP_DIFFUSE", 11)) {
  512. // parse the texture block
  513. ParseLV3MapBlock(mat.sTexDiffuse);
  514. continue;
  515. }
  516. // ambient color map
  517. if (TokenMatch(filePtr, "MAP_AMBIENT", 11)) {
  518. // parse the texture block
  519. ParseLV3MapBlock(mat.sTexAmbient);
  520. continue;
  521. }
  522. // specular color map
  523. if (TokenMatch(filePtr, "MAP_SPECULAR", 12)) {
  524. // parse the texture block
  525. ParseLV3MapBlock(mat.sTexSpecular);
  526. continue;
  527. }
  528. // opacity map
  529. if (TokenMatch(filePtr, "MAP_OPACITY", 11)) {
  530. // parse the texture block
  531. ParseLV3MapBlock(mat.sTexOpacity);
  532. continue;
  533. }
  534. // emissive map
  535. if (TokenMatch(filePtr, "MAP_SELFILLUM", 13)) {
  536. // parse the texture block
  537. ParseLV3MapBlock(mat.sTexEmissive);
  538. continue;
  539. }
  540. // bump map
  541. if (TokenMatch(filePtr, "MAP_BUMP", 8)) {
  542. // parse the texture block
  543. ParseLV3MapBlock(mat.sTexBump);
  544. }
  545. // specular/shininess map
  546. if (TokenMatch(filePtr, "MAP_SHINESTRENGTH", 17)) {
  547. // parse the texture block
  548. ParseLV3MapBlock(mat.sTexShininess);
  549. continue;
  550. }
  551. // number of submaterials
  552. if (TokenMatch(filePtr, "NUMSUBMTLS", 10)) {
  553. ParseLV4MeshLong(iNumSubMaterials);
  554. // allocate enough storage
  555. mat.avSubMaterials.resize(iNumSubMaterials, Material("INVALID SUBMATERIAL"));
  556. }
  557. // submaterial chunks
  558. if (TokenMatch(filePtr, "SUBMATERIAL", 11)) {
  559. unsigned int iIndex = 0;
  560. ParseLV4MeshLong(iIndex);
  561. if (iIndex >= iNumSubMaterials) {
  562. LogWarning("Out of range: submaterial index is too large");
  563. iIndex = iNumSubMaterials - 1;
  564. }
  565. // get a reference to the material
  566. Material &sMat = mat.avSubMaterials[iIndex];
  567. // parse the material block
  568. ParseLV2MaterialBlock(sMat);
  569. continue;
  570. }
  571. }
  572. AI_ASE_HANDLE_SECTION("2", "*MATERIAL");
  573. }
  574. }
  575. // ------------------------------------------------------------------------------------------------
  576. void Parser::ParseLV3MapBlock(Texture &map) {
  577. AI_ASE_PARSER_INIT();
  578. // ***********************************************************
  579. // *BITMAP should not be there if *MAP_CLASS is not BITMAP,
  580. // but we need to expect that case ... if the path is
  581. // empty the texture won't be used later.
  582. // ***********************************************************
  583. bool parsePath = true;
  584. std::string temp;
  585. while (true) {
  586. if ('*' == *filePtr) {
  587. ++filePtr;
  588. // type of map
  589. if (TokenMatch(filePtr, "MAP_CLASS", 9)) {
  590. temp.clear();
  591. if (!ParseString(temp, "*MAP_CLASS"))
  592. SkipToNextToken();
  593. if (temp != "Bitmap" && temp != "Normal Bump") {
  594. ASSIMP_LOG_WARN_F("ASE: Skipping unknown map type: ", temp);
  595. parsePath = false;
  596. }
  597. continue;
  598. }
  599. // path to the texture
  600. if (parsePath && TokenMatch(filePtr, "BITMAP", 6)) {
  601. if (!ParseString(map.mMapName, "*BITMAP"))
  602. SkipToNextToken();
  603. if (map.mMapName == "None") {
  604. // Files with 'None' as map name are produced by
  605. // an Maja to ASE exporter which name I forgot ..
  606. ASSIMP_LOG_WARN("ASE: Skipping invalid map entry");
  607. map.mMapName = "";
  608. }
  609. continue;
  610. }
  611. // offset on the u axis
  612. if (TokenMatch(filePtr, "UVW_U_OFFSET", 12)) {
  613. ParseLV4MeshFloat(map.mOffsetU);
  614. continue;
  615. }
  616. // offset on the v axis
  617. if (TokenMatch(filePtr, "UVW_V_OFFSET", 12)) {
  618. ParseLV4MeshFloat(map.mOffsetV);
  619. continue;
  620. }
  621. // tiling on the u axis
  622. if (TokenMatch(filePtr, "UVW_U_TILING", 12)) {
  623. ParseLV4MeshFloat(map.mScaleU);
  624. continue;
  625. }
  626. // tiling on the v axis
  627. if (TokenMatch(filePtr, "UVW_V_TILING", 12)) {
  628. ParseLV4MeshFloat(map.mScaleV);
  629. continue;
  630. }
  631. // rotation around the z-axis
  632. if (TokenMatch(filePtr, "UVW_ANGLE", 9)) {
  633. ParseLV4MeshFloat(map.mRotation);
  634. continue;
  635. }
  636. // map blending factor
  637. if (TokenMatch(filePtr, "MAP_AMOUNT", 10)) {
  638. ParseLV4MeshFloat(map.mTextureBlend);
  639. continue;
  640. }
  641. }
  642. AI_ASE_HANDLE_SECTION("3", "*MAP_XXXXXX");
  643. }
  644. return;
  645. }
  646. // ------------------------------------------------------------------------------------------------
  647. bool Parser::ParseString(std::string &out, const char *szName) {
  648. char szBuffer[1024];
  649. if (!SkipSpaces(&filePtr)) {
  650. ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Unexpected EOL", szName);
  651. LogWarning(szBuffer);
  652. return false;
  653. }
  654. // there must be '"'
  655. if ('\"' != *filePtr) {
  656. ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Strings are expected "
  657. "to be enclosed in double quotation marks",
  658. szName);
  659. LogWarning(szBuffer);
  660. return false;
  661. }
  662. ++filePtr;
  663. const char *sz = filePtr;
  664. while (true) {
  665. if ('\"' == *sz)
  666. break;
  667. else if ('\0' == *sz) {
  668. ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Strings are expected to "
  669. "be enclosed in double quotation marks but EOF was reached before "
  670. "a closing quotation mark was encountered",
  671. szName);
  672. LogWarning(szBuffer);
  673. return false;
  674. }
  675. sz++;
  676. }
  677. out = std::string(filePtr, (uintptr_t)sz - (uintptr_t)filePtr);
  678. filePtr = sz + 1;
  679. return true;
  680. }
  681. // ------------------------------------------------------------------------------------------------
  682. void Parser::ParseLV1ObjectBlock(ASE::BaseNode &node) {
  683. AI_ASE_PARSER_INIT();
  684. while (true) {
  685. if ('*' == *filePtr) {
  686. ++filePtr;
  687. // first process common tokens such as node name and transform
  688. // name of the mesh/node
  689. if (TokenMatch(filePtr, "NODE_NAME", 9)) {
  690. if (!ParseString(node.mName, "*NODE_NAME"))
  691. SkipToNextToken();
  692. continue;
  693. }
  694. // name of the parent of the node
  695. if (TokenMatch(filePtr, "NODE_PARENT", 11)) {
  696. if (!ParseString(node.mParent, "*NODE_PARENT"))
  697. SkipToNextToken();
  698. continue;
  699. }
  700. // transformation matrix of the node
  701. if (TokenMatch(filePtr, "NODE_TM", 7)) {
  702. ParseLV2NodeTransformBlock(node);
  703. continue;
  704. }
  705. // animation data of the node
  706. if (TokenMatch(filePtr, "TM_ANIMATION", 12)) {
  707. ParseLV2AnimationBlock(node);
  708. continue;
  709. }
  710. if (node.mType == BaseNode::Light) {
  711. // light settings
  712. if (TokenMatch(filePtr, "LIGHT_SETTINGS", 14)) {
  713. ParseLV2LightSettingsBlock((ASE::Light &)node);
  714. continue;
  715. }
  716. // type of the light source
  717. if (TokenMatch(filePtr, "LIGHT_TYPE", 10)) {
  718. if (!ASSIMP_strincmp("omni", filePtr, 4)) {
  719. ((ASE::Light &)node).mLightType = ASE::Light::OMNI;
  720. } else if (!ASSIMP_strincmp("target", filePtr, 6)) {
  721. ((ASE::Light &)node).mLightType = ASE::Light::TARGET;
  722. } else if (!ASSIMP_strincmp("free", filePtr, 4)) {
  723. ((ASE::Light &)node).mLightType = ASE::Light::FREE;
  724. } else if (!ASSIMP_strincmp("directional", filePtr, 11)) {
  725. ((ASE::Light &)node).mLightType = ASE::Light::DIRECTIONAL;
  726. } else {
  727. LogWarning("Unknown kind of light source");
  728. }
  729. continue;
  730. }
  731. } else if (node.mType == BaseNode::Camera) {
  732. // Camera settings
  733. if (TokenMatch(filePtr, "CAMERA_SETTINGS", 15)) {
  734. ParseLV2CameraSettingsBlock((ASE::Camera &)node);
  735. continue;
  736. } else if (TokenMatch(filePtr, "CAMERA_TYPE", 11)) {
  737. if (!ASSIMP_strincmp("target", filePtr, 6)) {
  738. ((ASE::Camera &)node).mCameraType = ASE::Camera::TARGET;
  739. } else if (!ASSIMP_strincmp("free", filePtr, 4)) {
  740. ((ASE::Camera &)node).mCameraType = ASE::Camera::FREE;
  741. } else {
  742. LogWarning("Unknown kind of camera");
  743. }
  744. continue;
  745. }
  746. } else if (node.mType == BaseNode::Mesh) {
  747. // mesh data
  748. // FIX: Older files use MESH_SOFTSKIN
  749. if (TokenMatch(filePtr, "MESH", 4) ||
  750. TokenMatch(filePtr, "MESH_SOFTSKIN", 13)) {
  751. ParseLV2MeshBlock((ASE::Mesh &)node);
  752. continue;
  753. }
  754. // mesh material index
  755. if (TokenMatch(filePtr, "MATERIAL_REF", 12)) {
  756. ParseLV4MeshLong(((ASE::Mesh &)node).iMaterialIndex);
  757. continue;
  758. }
  759. }
  760. }
  761. AI_ASE_HANDLE_TOP_LEVEL_SECTION();
  762. }
  763. return;
  764. }
  765. // ------------------------------------------------------------------------------------------------
  766. void Parser::ParseLV2CameraSettingsBlock(ASE::Camera &camera) {
  767. AI_ASE_PARSER_INIT();
  768. while (true) {
  769. if ('*' == *filePtr) {
  770. ++filePtr;
  771. if (TokenMatch(filePtr, "CAMERA_NEAR", 11)) {
  772. ParseLV4MeshFloat(camera.mNear);
  773. continue;
  774. }
  775. if (TokenMatch(filePtr, "CAMERA_FAR", 10)) {
  776. ParseLV4MeshFloat(camera.mFar);
  777. continue;
  778. }
  779. if (TokenMatch(filePtr, "CAMERA_FOV", 10)) {
  780. ParseLV4MeshFloat(camera.mFOV);
  781. continue;
  782. }
  783. }
  784. AI_ASE_HANDLE_SECTION("2", "CAMERA_SETTINGS");
  785. }
  786. return;
  787. }
  788. // ------------------------------------------------------------------------------------------------
  789. void Parser::ParseLV2LightSettingsBlock(ASE::Light &light) {
  790. AI_ASE_PARSER_INIT();
  791. while (true) {
  792. if ('*' == *filePtr) {
  793. ++filePtr;
  794. if (TokenMatch(filePtr, "LIGHT_COLOR", 11)) {
  795. ParseLV4MeshFloatTriple(&light.mColor.r);
  796. continue;
  797. }
  798. if (TokenMatch(filePtr, "LIGHT_INTENS", 12)) {
  799. ParseLV4MeshFloat(light.mIntensity);
  800. continue;
  801. }
  802. if (TokenMatch(filePtr, "LIGHT_HOTSPOT", 13)) {
  803. ParseLV4MeshFloat(light.mAngle);
  804. continue;
  805. }
  806. if (TokenMatch(filePtr, "LIGHT_FALLOFF", 13)) {
  807. ParseLV4MeshFloat(light.mFalloff);
  808. continue;
  809. }
  810. }
  811. AI_ASE_HANDLE_SECTION("2", "LIGHT_SETTINGS");
  812. }
  813. return;
  814. }
  815. // ------------------------------------------------------------------------------------------------
  816. void Parser::ParseLV2AnimationBlock(ASE::BaseNode &mesh) {
  817. AI_ASE_PARSER_INIT();
  818. ASE::Animation *anim = &mesh.mAnim;
  819. while (true) {
  820. if ('*' == *filePtr) {
  821. ++filePtr;
  822. if (TokenMatch(filePtr, "NODE_NAME", 9)) {
  823. std::string temp;
  824. if (!ParseString(temp, "*NODE_NAME"))
  825. SkipToNextToken();
  826. // If the name of the node contains .target it
  827. // represents an animated camera or spot light
  828. // target.
  829. if (std::string::npos != temp.find(".Target")) {
  830. if ((mesh.mType != BaseNode::Camera || ((ASE::Camera &)mesh).mCameraType != ASE::Camera::TARGET) &&
  831. (mesh.mType != BaseNode::Light || ((ASE::Light &)mesh).mLightType != ASE::Light::TARGET)) {
  832. ASSIMP_LOG_ERROR("ASE: Found target animation channel "
  833. "but the node is neither a camera nor a spot light");
  834. anim = nullptr;
  835. } else
  836. anim = &mesh.mTargetAnim;
  837. }
  838. continue;
  839. }
  840. // position keyframes
  841. if (TokenMatch(filePtr, "CONTROL_POS_TRACK", 17) ||
  842. TokenMatch(filePtr, "CONTROL_POS_BEZIER", 18) ||
  843. TokenMatch(filePtr, "CONTROL_POS_TCB", 15)) {
  844. if (!anim)
  845. SkipSection();
  846. else
  847. ParseLV3PosAnimationBlock(*anim);
  848. continue;
  849. }
  850. // scaling keyframes
  851. if (TokenMatch(filePtr, "CONTROL_SCALE_TRACK", 19) ||
  852. TokenMatch(filePtr, "CONTROL_SCALE_BEZIER", 20) ||
  853. TokenMatch(filePtr, "CONTROL_SCALE_TCB", 17)) {
  854. if (!anim || anim == &mesh.mTargetAnim) {
  855. // Target animation channels may have no rotation channels
  856. ASSIMP_LOG_ERROR("ASE: Ignoring scaling channel in target animation");
  857. SkipSection();
  858. } else
  859. ParseLV3ScaleAnimationBlock(*anim);
  860. continue;
  861. }
  862. // rotation keyframes
  863. if (TokenMatch(filePtr, "CONTROL_ROT_TRACK", 17) ||
  864. TokenMatch(filePtr, "CONTROL_ROT_BEZIER", 18) ||
  865. TokenMatch(filePtr, "CONTROL_ROT_TCB", 15)) {
  866. if (!anim || anim == &mesh.mTargetAnim) {
  867. // Target animation channels may have no rotation channels
  868. ASSIMP_LOG_ERROR("ASE: Ignoring rotation channel in target animation");
  869. SkipSection();
  870. } else
  871. ParseLV3RotAnimationBlock(*anim);
  872. continue;
  873. }
  874. }
  875. AI_ASE_HANDLE_SECTION("2", "TM_ANIMATION");
  876. }
  877. }
  878. // ------------------------------------------------------------------------------------------------
  879. void Parser::ParseLV3ScaleAnimationBlock(ASE::Animation &anim) {
  880. AI_ASE_PARSER_INIT();
  881. unsigned int iIndex;
  882. while (true) {
  883. if ('*' == *filePtr) {
  884. ++filePtr;
  885. bool b = false;
  886. // For the moment we're just reading the three floats -
  887. // we ignore the additional information for bezier's and TCBs
  888. // simple scaling keyframe
  889. if (TokenMatch(filePtr, "CONTROL_SCALE_SAMPLE", 20)) {
  890. b = true;
  891. anim.mScalingType = ASE::Animation::TRACK;
  892. }
  893. // Bezier scaling keyframe
  894. if (TokenMatch(filePtr, "CONTROL_BEZIER_SCALE_KEY", 24)) {
  895. b = true;
  896. anim.mScalingType = ASE::Animation::BEZIER;
  897. }
  898. // TCB scaling keyframe
  899. if (TokenMatch(filePtr, "CONTROL_TCB_SCALE_KEY", 21)) {
  900. b = true;
  901. anim.mScalingType = ASE::Animation::TCB;
  902. }
  903. if (b) {
  904. anim.akeyScaling.push_back(aiVectorKey());
  905. aiVectorKey &key = anim.akeyScaling.back();
  906. ParseLV4MeshFloatTriple(&key.mValue.x, iIndex);
  907. key.mTime = (double)iIndex;
  908. }
  909. }
  910. AI_ASE_HANDLE_SECTION("3", "*CONTROL_POS_TRACK");
  911. }
  912. }
  913. // ------------------------------------------------------------------------------------------------
  914. void Parser::ParseLV3PosAnimationBlock(ASE::Animation &anim) {
  915. AI_ASE_PARSER_INIT();
  916. unsigned int iIndex;
  917. while (true) {
  918. if ('*' == *filePtr) {
  919. ++filePtr;
  920. bool b = false;
  921. // For the moment we're just reading the three floats -
  922. // we ignore the additional information for bezier's and TCBs
  923. // simple scaling keyframe
  924. if (TokenMatch(filePtr, "CONTROL_POS_SAMPLE", 18)) {
  925. b = true;
  926. anim.mPositionType = ASE::Animation::TRACK;
  927. }
  928. // Bezier scaling keyframe
  929. if (TokenMatch(filePtr, "CONTROL_BEZIER_POS_KEY", 22)) {
  930. b = true;
  931. anim.mPositionType = ASE::Animation::BEZIER;
  932. }
  933. // TCB scaling keyframe
  934. if (TokenMatch(filePtr, "CONTROL_TCB_POS_KEY", 19)) {
  935. b = true;
  936. anim.mPositionType = ASE::Animation::TCB;
  937. }
  938. if (b) {
  939. anim.akeyPositions.push_back(aiVectorKey());
  940. aiVectorKey &key = anim.akeyPositions.back();
  941. ParseLV4MeshFloatTriple(&key.mValue.x, iIndex);
  942. key.mTime = (double)iIndex;
  943. }
  944. }
  945. AI_ASE_HANDLE_SECTION("3", "*CONTROL_POS_TRACK");
  946. }
  947. }
  948. // ------------------------------------------------------------------------------------------------
  949. void Parser::ParseLV3RotAnimationBlock(ASE::Animation &anim) {
  950. AI_ASE_PARSER_INIT();
  951. unsigned int iIndex;
  952. while (true) {
  953. if ('*' == *filePtr) {
  954. ++filePtr;
  955. bool b = false;
  956. // For the moment we're just reading the floats -
  957. // we ignore the additional information for bezier's and TCBs
  958. // simple scaling keyframe
  959. if (TokenMatch(filePtr, "CONTROL_ROT_SAMPLE", 18)) {
  960. b = true;
  961. anim.mRotationType = ASE::Animation::TRACK;
  962. }
  963. // Bezier scaling keyframe
  964. if (TokenMatch(filePtr, "CONTROL_BEZIER_ROT_KEY", 22)) {
  965. b = true;
  966. anim.mRotationType = ASE::Animation::BEZIER;
  967. }
  968. // TCB scaling keyframe
  969. if (TokenMatch(filePtr, "CONTROL_TCB_ROT_KEY", 19)) {
  970. b = true;
  971. anim.mRotationType = ASE::Animation::TCB;
  972. }
  973. if (b) {
  974. anim.akeyRotations.push_back(aiQuatKey());
  975. aiQuatKey &key = anim.akeyRotations.back();
  976. aiVector3D v;
  977. ai_real f;
  978. ParseLV4MeshFloatTriple(&v.x, iIndex);
  979. ParseLV4MeshFloat(f);
  980. key.mTime = (double)iIndex;
  981. key.mValue = aiQuaternion(v, f);
  982. }
  983. }
  984. AI_ASE_HANDLE_SECTION("3", "*CONTROL_ROT_TRACK");
  985. }
  986. }
  987. // ------------------------------------------------------------------------------------------------
  988. void Parser::ParseLV2NodeTransformBlock(ASE::BaseNode &mesh) {
  989. AI_ASE_PARSER_INIT();
  990. int mode = 0;
  991. while (true) {
  992. if ('*' == *filePtr) {
  993. ++filePtr;
  994. // name of the node
  995. if (TokenMatch(filePtr, "NODE_NAME", 9)) {
  996. std::string temp;
  997. if (!ParseString(temp, "*NODE_NAME"))
  998. SkipToNextToken();
  999. std::string::size_type s;
  1000. if (temp == mesh.mName) {
  1001. mode = 1;
  1002. } else if (std::string::npos != (s = temp.find(".Target")) &&
  1003. mesh.mName == temp.substr(0, s)) {
  1004. // This should be either a target light or a target camera
  1005. if ((mesh.mType == BaseNode::Light && ((ASE::Light &)mesh).mLightType == ASE::Light::TARGET) ||
  1006. (mesh.mType == BaseNode::Camera && ((ASE::Camera &)mesh).mCameraType == ASE::Camera::TARGET)) {
  1007. mode = 2;
  1008. } else {
  1009. ASSIMP_LOG_ERROR("ASE: Ignoring target transform, "
  1010. "this is no spot light or target camera");
  1011. }
  1012. } else {
  1013. ASSIMP_LOG_ERROR("ASE: Unknown node transformation: " + temp);
  1014. // mode = 0
  1015. }
  1016. continue;
  1017. }
  1018. if (mode) {
  1019. // fourth row of the transformation matrix - and also the
  1020. // only information here that is interesting for targets
  1021. if (TokenMatch(filePtr, "TM_ROW3", 7)) {
  1022. ParseLV4MeshFloatTriple((mode == 1 ? mesh.mTransform[3] : &mesh.mTargetPosition.x));
  1023. continue;
  1024. }
  1025. if (mode == 1) {
  1026. // first row of the transformation matrix
  1027. if (TokenMatch(filePtr, "TM_ROW0", 7)) {
  1028. ParseLV4MeshFloatTriple(mesh.mTransform[0]);
  1029. continue;
  1030. }
  1031. // second row of the transformation matrix
  1032. if (TokenMatch(filePtr, "TM_ROW1", 7)) {
  1033. ParseLV4MeshFloatTriple(mesh.mTransform[1]);
  1034. continue;
  1035. }
  1036. // third row of the transformation matrix
  1037. if (TokenMatch(filePtr, "TM_ROW2", 7)) {
  1038. ParseLV4MeshFloatTriple(mesh.mTransform[2]);
  1039. continue;
  1040. }
  1041. // inherited position axes
  1042. if (TokenMatch(filePtr, "INHERIT_POS", 11)) {
  1043. unsigned int aiVal[3];
  1044. ParseLV4MeshLongTriple(aiVal);
  1045. for (unsigned int i = 0; i < 3; ++i)
  1046. mesh.inherit.abInheritPosition[i] = aiVal[i] != 0;
  1047. continue;
  1048. }
  1049. // inherited rotation axes
  1050. if (TokenMatch(filePtr, "INHERIT_ROT", 11)) {
  1051. unsigned int aiVal[3];
  1052. ParseLV4MeshLongTriple(aiVal);
  1053. for (unsigned int i = 0; i < 3; ++i)
  1054. mesh.inherit.abInheritRotation[i] = aiVal[i] != 0;
  1055. continue;
  1056. }
  1057. // inherited scaling axes
  1058. if (TokenMatch(filePtr, "INHERIT_SCL", 11)) {
  1059. unsigned int aiVal[3];
  1060. ParseLV4MeshLongTriple(aiVal);
  1061. for (unsigned int i = 0; i < 3; ++i)
  1062. mesh.inherit.abInheritScaling[i] = aiVal[i] != 0;
  1063. continue;
  1064. }
  1065. }
  1066. }
  1067. }
  1068. AI_ASE_HANDLE_SECTION("2", "*NODE_TM");
  1069. }
  1070. return;
  1071. }
  1072. // ------------------------------------------------------------------------------------------------
  1073. void Parser::ParseLV2MeshBlock(ASE::Mesh &mesh) {
  1074. AI_ASE_PARSER_INIT();
  1075. unsigned int iNumVertices = 0;
  1076. unsigned int iNumFaces = 0;
  1077. unsigned int iNumTVertices = 0;
  1078. unsigned int iNumTFaces = 0;
  1079. unsigned int iNumCVertices = 0;
  1080. unsigned int iNumCFaces = 0;
  1081. while (true) {
  1082. if ('*' == *filePtr) {
  1083. ++filePtr;
  1084. // Number of vertices in the mesh
  1085. if (TokenMatch(filePtr, "MESH_NUMVERTEX", 14)) {
  1086. ParseLV4MeshLong(iNumVertices);
  1087. continue;
  1088. }
  1089. // Number of texture coordinates in the mesh
  1090. if (TokenMatch(filePtr, "MESH_NUMTVERTEX", 15)) {
  1091. ParseLV4MeshLong(iNumTVertices);
  1092. continue;
  1093. }
  1094. // Number of vertex colors in the mesh
  1095. if (TokenMatch(filePtr, "MESH_NUMCVERTEX", 15)) {
  1096. ParseLV4MeshLong(iNumCVertices);
  1097. continue;
  1098. }
  1099. // Number of regular faces in the mesh
  1100. if (TokenMatch(filePtr, "MESH_NUMFACES", 13)) {
  1101. ParseLV4MeshLong(iNumFaces);
  1102. continue;
  1103. }
  1104. // Number of UVWed faces in the mesh
  1105. if (TokenMatch(filePtr, "MESH_NUMTVFACES", 15)) {
  1106. ParseLV4MeshLong(iNumTFaces);
  1107. continue;
  1108. }
  1109. // Number of colored faces in the mesh
  1110. if (TokenMatch(filePtr, "MESH_NUMCVFACES", 15)) {
  1111. ParseLV4MeshLong(iNumCFaces);
  1112. continue;
  1113. }
  1114. // mesh vertex list block
  1115. if (TokenMatch(filePtr, "MESH_VERTEX_LIST", 16)) {
  1116. ParseLV3MeshVertexListBlock(iNumVertices, mesh);
  1117. continue;
  1118. }
  1119. // mesh face list block
  1120. if (TokenMatch(filePtr, "MESH_FACE_LIST", 14)) {
  1121. ParseLV3MeshFaceListBlock(iNumFaces, mesh);
  1122. continue;
  1123. }
  1124. // mesh texture vertex list block
  1125. if (TokenMatch(filePtr, "MESH_TVERTLIST", 14)) {
  1126. ParseLV3MeshTListBlock(iNumTVertices, mesh);
  1127. continue;
  1128. }
  1129. // mesh texture face block
  1130. if (TokenMatch(filePtr, "MESH_TFACELIST", 14)) {
  1131. ParseLV3MeshTFaceListBlock(iNumTFaces, mesh);
  1132. continue;
  1133. }
  1134. // mesh color vertex list block
  1135. if (TokenMatch(filePtr, "MESH_CVERTLIST", 14)) {
  1136. ParseLV3MeshCListBlock(iNumCVertices, mesh);
  1137. continue;
  1138. }
  1139. // mesh color face block
  1140. if (TokenMatch(filePtr, "MESH_CFACELIST", 14)) {
  1141. ParseLV3MeshCFaceListBlock(iNumCFaces, mesh);
  1142. continue;
  1143. }
  1144. // mesh normals
  1145. if (TokenMatch(filePtr, "MESH_NORMALS", 12)) {
  1146. ParseLV3MeshNormalListBlock(mesh);
  1147. continue;
  1148. }
  1149. // another mesh UV channel ...
  1150. if (TokenMatch(filePtr, "MESH_MAPPINGCHANNEL", 19)) {
  1151. unsigned int iIndex(0);
  1152. ParseLV4MeshLong(iIndex);
  1153. if (0 == iIndex) {
  1154. LogWarning("Mapping channel has an invalid index. Skipping UV channel");
  1155. // skip it ...
  1156. SkipSection();
  1157. } else {
  1158. if (iIndex < 2) {
  1159. LogWarning("Mapping channel has an invalid index. Skipping UV channel");
  1160. // skip it ...
  1161. SkipSection();
  1162. }
  1163. if (iIndex > AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  1164. LogWarning("Too many UV channels specified. Skipping channel ..");
  1165. // skip it ...
  1166. SkipSection();
  1167. } else {
  1168. // parse the mapping channel
  1169. ParseLV3MappingChannel(iIndex - 1, mesh);
  1170. }
  1171. continue;
  1172. }
  1173. }
  1174. // mesh animation keyframe. Not supported
  1175. if (TokenMatch(filePtr, "MESH_ANIMATION", 14)) {
  1176. LogWarning("Found *MESH_ANIMATION element in ASE/ASK file. "
  1177. "Keyframe animation is not supported by Assimp, this element "
  1178. "will be ignored");
  1179. //SkipSection();
  1180. continue;
  1181. }
  1182. if (TokenMatch(filePtr, "MESH_WEIGHTS", 12)) {
  1183. ParseLV3MeshWeightsBlock(mesh);
  1184. continue;
  1185. }
  1186. }
  1187. AI_ASE_HANDLE_SECTION("2", "*MESH");
  1188. }
  1189. return;
  1190. }
  1191. // ------------------------------------------------------------------------------------------------
  1192. void Parser::ParseLV3MeshWeightsBlock(ASE::Mesh &mesh) {
  1193. AI_ASE_PARSER_INIT();
  1194. unsigned int iNumVertices = 0, iNumBones = 0;
  1195. while (true) {
  1196. if ('*' == *filePtr) {
  1197. ++filePtr;
  1198. // Number of bone vertices ...
  1199. if (TokenMatch(filePtr, "MESH_NUMVERTEX", 14)) {
  1200. ParseLV4MeshLong(iNumVertices);
  1201. continue;
  1202. }
  1203. // Number of bones
  1204. if (TokenMatch(filePtr, "MESH_NUMBONE", 12)) {
  1205. ParseLV4MeshLong(iNumBones);
  1206. continue;
  1207. }
  1208. // parse the list of bones
  1209. if (TokenMatch(filePtr, "MESH_BONE_LIST", 14)) {
  1210. ParseLV4MeshBones(iNumBones, mesh);
  1211. continue;
  1212. }
  1213. // parse the list of bones vertices
  1214. if (TokenMatch(filePtr, "MESH_BONE_VERTEX_LIST", 21)) {
  1215. ParseLV4MeshBonesVertices(iNumVertices, mesh);
  1216. continue;
  1217. }
  1218. }
  1219. AI_ASE_HANDLE_SECTION("3", "*MESH_WEIGHTS");
  1220. }
  1221. return;
  1222. }
  1223. // ------------------------------------------------------------------------------------------------
  1224. void Parser::ParseLV4MeshBones(unsigned int iNumBones, ASE::Mesh &mesh) {
  1225. AI_ASE_PARSER_INIT();
  1226. mesh.mBones.resize(iNumBones, Bone("UNNAMED"));
  1227. while (true) {
  1228. if ('*' == *filePtr) {
  1229. ++filePtr;
  1230. // Mesh bone with name ...
  1231. if (TokenMatch(filePtr, "MESH_BONE_NAME", 14)) {
  1232. // parse an index ...
  1233. if (SkipSpaces(&filePtr)) {
  1234. unsigned int iIndex = strtoul10(filePtr, &filePtr);
  1235. if (iIndex >= iNumBones) {
  1236. LogWarning("Bone index is out of bounds");
  1237. continue;
  1238. }
  1239. if (!ParseString(mesh.mBones[iIndex].mName, "*MESH_BONE_NAME"))
  1240. SkipToNextToken();
  1241. continue;
  1242. }
  1243. }
  1244. }
  1245. AI_ASE_HANDLE_SECTION("3", "*MESH_BONE_LIST");
  1246. }
  1247. }
  1248. // ------------------------------------------------------------------------------------------------
  1249. void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mesh) {
  1250. AI_ASE_PARSER_INIT();
  1251. mesh.mBoneVertices.resize(iNumVertices);
  1252. while (true) {
  1253. if ('*' == *filePtr) {
  1254. ++filePtr;
  1255. // Mesh bone vertex
  1256. if (TokenMatch(filePtr, "MESH_BONE_VERTEX", 16)) {
  1257. // read the vertex index
  1258. unsigned int iIndex = strtoul10(filePtr, &filePtr);
  1259. if (iIndex >= mesh.mPositions.size()) {
  1260. iIndex = (unsigned int)mesh.mPositions.size() - 1;
  1261. LogWarning("Bone vertex index is out of bounds. Using the largest valid "
  1262. "bone vertex index instead");
  1263. }
  1264. // --- ignored
  1265. ai_real afVert[3];
  1266. ParseLV4MeshFloatTriple(afVert);
  1267. std::pair<int, float> pairOut;
  1268. while (true) {
  1269. // first parse the bone index ...
  1270. if (!SkipSpaces(&filePtr)) break;
  1271. pairOut.first = strtoul10(filePtr, &filePtr);
  1272. // then parse the vertex weight
  1273. if (!SkipSpaces(&filePtr)) break;
  1274. filePtr = fast_atoreal_move<float>(filePtr, pairOut.second);
  1275. // -1 marks unused entries
  1276. if (-1 != pairOut.first) {
  1277. mesh.mBoneVertices[iIndex].mBoneWeights.push_back(pairOut);
  1278. }
  1279. }
  1280. continue;
  1281. }
  1282. }
  1283. AI_ASE_HANDLE_SECTION("4", "*MESH_BONE_VERTEX");
  1284. }
  1285. return;
  1286. }
  1287. // ------------------------------------------------------------------------------------------------
  1288. void Parser::ParseLV3MeshVertexListBlock(
  1289. unsigned int iNumVertices, ASE::Mesh &mesh) {
  1290. AI_ASE_PARSER_INIT();
  1291. // allocate enough storage in the array
  1292. mesh.mPositions.resize(iNumVertices);
  1293. while (true) {
  1294. if ('*' == *filePtr) {
  1295. ++filePtr;
  1296. // Vertex entry
  1297. if (TokenMatch(filePtr, "MESH_VERTEX", 11)) {
  1298. aiVector3D vTemp;
  1299. unsigned int iIndex;
  1300. ParseLV4MeshFloatTriple(&vTemp.x, iIndex);
  1301. if (iIndex >= iNumVertices) {
  1302. LogWarning("Invalid vertex index. It will be ignored");
  1303. } else
  1304. mesh.mPositions[iIndex] = vTemp;
  1305. continue;
  1306. }
  1307. }
  1308. AI_ASE_HANDLE_SECTION("3", "*MESH_VERTEX_LIST");
  1309. }
  1310. return;
  1311. }
  1312. // ------------------------------------------------------------------------------------------------
  1313. void Parser::ParseLV3MeshFaceListBlock(unsigned int iNumFaces, ASE::Mesh &mesh) {
  1314. AI_ASE_PARSER_INIT();
  1315. // allocate enough storage in the face array
  1316. mesh.mFaces.resize(iNumFaces);
  1317. while (true) {
  1318. if ('*' == *filePtr) {
  1319. ++filePtr;
  1320. // Face entry
  1321. if (TokenMatch(filePtr, "MESH_FACE", 9)) {
  1322. ASE::Face mFace;
  1323. ParseLV4MeshFace(mFace);
  1324. if (mFace.iFace >= iNumFaces) {
  1325. LogWarning("Face has an invalid index. It will be ignored");
  1326. } else
  1327. mesh.mFaces[mFace.iFace] = mFace;
  1328. continue;
  1329. }
  1330. }
  1331. AI_ASE_HANDLE_SECTION("3", "*MESH_FACE_LIST");
  1332. }
  1333. return;
  1334. }
  1335. // ------------------------------------------------------------------------------------------------
  1336. void Parser::ParseLV3MeshTListBlock(unsigned int iNumVertices,
  1337. ASE::Mesh &mesh, unsigned int iChannel) {
  1338. AI_ASE_PARSER_INIT();
  1339. // allocate enough storage in the array
  1340. mesh.amTexCoords[iChannel].resize(iNumVertices);
  1341. while (true) {
  1342. if ('*' == *filePtr) {
  1343. ++filePtr;
  1344. // Vertex entry
  1345. if (TokenMatch(filePtr, "MESH_TVERT", 10)) {
  1346. aiVector3D vTemp;
  1347. unsigned int iIndex;
  1348. ParseLV4MeshFloatTriple(&vTemp.x, iIndex);
  1349. if (iIndex >= iNumVertices) {
  1350. LogWarning("Tvertex has an invalid index. It will be ignored");
  1351. } else
  1352. mesh.amTexCoords[iChannel][iIndex] = vTemp;
  1353. if (0.0f != vTemp.z) {
  1354. // we need 3 coordinate channels
  1355. mesh.mNumUVComponents[iChannel] = 3;
  1356. }
  1357. continue;
  1358. }
  1359. }
  1360. AI_ASE_HANDLE_SECTION("3", "*MESH_TVERT_LIST");
  1361. }
  1362. return;
  1363. }
  1364. // ------------------------------------------------------------------------------------------------
  1365. void Parser::ParseLV3MeshTFaceListBlock(unsigned int iNumFaces,
  1366. ASE::Mesh &mesh, unsigned int iChannel) {
  1367. AI_ASE_PARSER_INIT();
  1368. while (true) {
  1369. if ('*' == *filePtr) {
  1370. ++filePtr;
  1371. // Face entry
  1372. if (TokenMatch(filePtr, "MESH_TFACE", 10)) {
  1373. unsigned int aiValues[3];
  1374. unsigned int iIndex = 0;
  1375. ParseLV4MeshLongTriple(aiValues, iIndex);
  1376. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size()) {
  1377. LogWarning("UV-Face has an invalid index. It will be ignored");
  1378. } else {
  1379. // copy UV indices
  1380. mesh.mFaces[iIndex].amUVIndices[iChannel][0] = aiValues[0];
  1381. mesh.mFaces[iIndex].amUVIndices[iChannel][1] = aiValues[1];
  1382. mesh.mFaces[iIndex].amUVIndices[iChannel][2] = aiValues[2];
  1383. }
  1384. continue;
  1385. }
  1386. }
  1387. AI_ASE_HANDLE_SECTION("3", "*MESH_TFACE_LIST");
  1388. }
  1389. return;
  1390. }
  1391. // ------------------------------------------------------------------------------------------------
  1392. void Parser::ParseLV3MappingChannel(unsigned int iChannel, ASE::Mesh &mesh) {
  1393. AI_ASE_PARSER_INIT();
  1394. unsigned int iNumTVertices = 0;
  1395. unsigned int iNumTFaces = 0;
  1396. while (true) {
  1397. if ('*' == *filePtr) {
  1398. ++filePtr;
  1399. // Number of texture coordinates in the mesh
  1400. if (TokenMatch(filePtr, "MESH_NUMTVERTEX", 15)) {
  1401. ParseLV4MeshLong(iNumTVertices);
  1402. continue;
  1403. }
  1404. // Number of UVWed faces in the mesh
  1405. if (TokenMatch(filePtr, "MESH_NUMTVFACES", 15)) {
  1406. ParseLV4MeshLong(iNumTFaces);
  1407. continue;
  1408. }
  1409. // mesh texture vertex list block
  1410. if (TokenMatch(filePtr, "MESH_TVERTLIST", 14)) {
  1411. ParseLV3MeshTListBlock(iNumTVertices, mesh, iChannel);
  1412. continue;
  1413. }
  1414. // mesh texture face block
  1415. if (TokenMatch(filePtr, "MESH_TFACELIST", 14)) {
  1416. ParseLV3MeshTFaceListBlock(iNumTFaces, mesh, iChannel);
  1417. continue;
  1418. }
  1419. }
  1420. AI_ASE_HANDLE_SECTION("3", "*MESH_MAPPING_CHANNEL");
  1421. }
  1422. return;
  1423. }
  1424. // ------------------------------------------------------------------------------------------------
  1425. void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh &mesh) {
  1426. AI_ASE_PARSER_INIT();
  1427. // allocate enough storage in the array
  1428. mesh.mVertexColors.resize(iNumVertices);
  1429. while (true) {
  1430. if ('*' == *filePtr) {
  1431. ++filePtr;
  1432. // Vertex entry
  1433. if (TokenMatch(filePtr, "MESH_VERTCOL", 12)) {
  1434. aiColor4D vTemp;
  1435. vTemp.a = 1.0f;
  1436. unsigned int iIndex;
  1437. ParseLV4MeshFloatTriple(&vTemp.r, iIndex);
  1438. if (iIndex >= iNumVertices) {
  1439. LogWarning("Vertex color has an invalid index. It will be ignored");
  1440. } else
  1441. mesh.mVertexColors[iIndex] = vTemp;
  1442. continue;
  1443. }
  1444. }
  1445. AI_ASE_HANDLE_SECTION("3", "*MESH_CVERTEX_LIST");
  1446. }
  1447. return;
  1448. }
  1449. // ------------------------------------------------------------------------------------------------
  1450. void Parser::ParseLV3MeshCFaceListBlock(unsigned int iNumFaces, ASE::Mesh &mesh) {
  1451. AI_ASE_PARSER_INIT();
  1452. while (true) {
  1453. if ('*' == *filePtr) {
  1454. ++filePtr;
  1455. // Face entry
  1456. if (TokenMatch(filePtr, "MESH_CFACE", 10)) {
  1457. unsigned int aiValues[3];
  1458. unsigned int iIndex = 0;
  1459. ParseLV4MeshLongTriple(aiValues, iIndex);
  1460. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size()) {
  1461. LogWarning("UV-Face has an invalid index. It will be ignored");
  1462. } else {
  1463. // copy color indices
  1464. mesh.mFaces[iIndex].mColorIndices[0] = aiValues[0];
  1465. mesh.mFaces[iIndex].mColorIndices[1] = aiValues[1];
  1466. mesh.mFaces[iIndex].mColorIndices[2] = aiValues[2];
  1467. }
  1468. continue;
  1469. }
  1470. }
  1471. AI_ASE_HANDLE_SECTION("3", "*MESH_CFACE_LIST");
  1472. }
  1473. return;
  1474. }
  1475. // ------------------------------------------------------------------------------------------------
  1476. void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) {
  1477. AI_ASE_PARSER_INIT();
  1478. // Allocate enough storage for the normals
  1479. sMesh.mNormals.resize(sMesh.mFaces.size() * 3, aiVector3D(0.f, 0.f, 0.f));
  1480. unsigned int index, faceIdx = UINT_MAX;
  1481. // FIXME: rewrite this and find out how to interpret the normals
  1482. // correctly. This is crap.
  1483. // Smooth the vertex and face normals together. The result
  1484. // will be edgy then, but otherwise everything would be soft ...
  1485. while (true) {
  1486. if ('*' == *filePtr) {
  1487. ++filePtr;
  1488. if (faceIdx != UINT_MAX && TokenMatch(filePtr, "MESH_VERTEXNORMAL", 17)) {
  1489. aiVector3D vNormal;
  1490. ParseLV4MeshFloatTriple(&vNormal.x, index);
  1491. if (faceIdx >= sMesh.mFaces.size())
  1492. continue;
  1493. // Make sure we assign it to the correct face
  1494. const ASE::Face &face = sMesh.mFaces[faceIdx];
  1495. if (index == face.mIndices[0])
  1496. index = 0;
  1497. else if (index == face.mIndices[1])
  1498. index = 1;
  1499. else if (index == face.mIndices[2])
  1500. index = 2;
  1501. else {
  1502. ASSIMP_LOG_ERROR("ASE: Invalid vertex index in MESH_VERTEXNORMAL section");
  1503. continue;
  1504. }
  1505. // We'll renormalize later
  1506. sMesh.mNormals[faceIdx * 3 + index] += vNormal;
  1507. continue;
  1508. }
  1509. if (TokenMatch(filePtr, "MESH_FACENORMAL", 15)) {
  1510. aiVector3D vNormal;
  1511. ParseLV4MeshFloatTriple(&vNormal.x, faceIdx);
  1512. if (faceIdx >= sMesh.mFaces.size()) {
  1513. ASSIMP_LOG_ERROR("ASE: Invalid vertex index in MESH_FACENORMAL section");
  1514. continue;
  1515. }
  1516. // We'll renormalize later
  1517. sMesh.mNormals[faceIdx * 3] += vNormal;
  1518. sMesh.mNormals[faceIdx * 3 + 1] += vNormal;
  1519. sMesh.mNormals[faceIdx * 3 + 2] += vNormal;
  1520. continue;
  1521. }
  1522. }
  1523. AI_ASE_HANDLE_SECTION("3", "*MESH_NORMALS");
  1524. }
  1525. return;
  1526. }
  1527. // ------------------------------------------------------------------------------------------------
  1528. void Parser::ParseLV4MeshFace(ASE::Face &out) {
  1529. // skip spaces and tabs
  1530. if (!SkipSpaces(&filePtr)) {
  1531. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]");
  1532. SkipToNextToken();
  1533. return;
  1534. }
  1535. // parse the face index
  1536. out.iFace = strtoul10(filePtr, &filePtr);
  1537. // next character should be ':'
  1538. if (!SkipSpaces(&filePtr)) {
  1539. // FIX: there are some ASE files which haven't got : here ....
  1540. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]");
  1541. SkipToNextToken();
  1542. return;
  1543. }
  1544. // FIX: There are some ASE files which haven't got ':' here
  1545. if (':' == *filePtr) ++filePtr;
  1546. // Parse all mesh indices
  1547. for (unsigned int i = 0; i < 3; ++i) {
  1548. unsigned int iIndex = 0;
  1549. if (!SkipSpaces(&filePtr)) {
  1550. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL");
  1551. SkipToNextToken();
  1552. return;
  1553. }
  1554. switch (*filePtr) {
  1555. case 'A':
  1556. case 'a':
  1557. break;
  1558. case 'B':
  1559. case 'b':
  1560. iIndex = 1;
  1561. break;
  1562. case 'C':
  1563. case 'c':
  1564. iIndex = 2;
  1565. break;
  1566. default:
  1567. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
  1568. "A,B or C expected [#3]");
  1569. SkipToNextToken();
  1570. return;
  1571. };
  1572. ++filePtr;
  1573. // next character should be ':'
  1574. if (!SkipSpaces(&filePtr) || ':' != *filePtr) {
  1575. LogWarning("Unable to parse *MESH_FACE Element: "
  1576. "Unexpected EOL. \':\' expected [#2]");
  1577. SkipToNextToken();
  1578. return;
  1579. }
  1580. ++filePtr;
  1581. if (!SkipSpaces(&filePtr)) {
  1582. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
  1583. "Vertex index ecpected [#4]");
  1584. SkipToNextToken();
  1585. return;
  1586. }
  1587. out.mIndices[iIndex] = strtoul10(filePtr, &filePtr);
  1588. }
  1589. // now we need to skip the AB, BC, CA blocks.
  1590. while (true) {
  1591. if ('*' == *filePtr) break;
  1592. if (IsLineEnd(*filePtr)) {
  1593. //iLineNumber++;
  1594. return;
  1595. }
  1596. filePtr++;
  1597. }
  1598. // parse the smoothing group of the face
  1599. if (TokenMatch(filePtr, "*MESH_SMOOTHING", 15)) {
  1600. if (!SkipSpaces(&filePtr)) {
  1601. LogWarning("Unable to parse *MESH_SMOOTHING Element: "
  1602. "Unexpected EOL. Smoothing group(s) expected [#5]");
  1603. SkipToNextToken();
  1604. return;
  1605. }
  1606. // Parse smoothing groups until we don't anymore see commas
  1607. // FIX: There needn't always be a value, sad but true
  1608. while (true) {
  1609. if (*filePtr < '9' && *filePtr >= '0') {
  1610. out.iSmoothGroup |= (1 << strtoul10(filePtr, &filePtr));
  1611. }
  1612. SkipSpaces(&filePtr);
  1613. if (',' != *filePtr) {
  1614. break;
  1615. }
  1616. ++filePtr;
  1617. SkipSpaces(&filePtr);
  1618. }
  1619. }
  1620. // *MESH_MTLID is optional, too
  1621. while (true) {
  1622. if ('*' == *filePtr) break;
  1623. if (IsLineEnd(*filePtr)) {
  1624. return;
  1625. }
  1626. filePtr++;
  1627. }
  1628. if (TokenMatch(filePtr, "*MESH_MTLID", 11)) {
  1629. if (!SkipSpaces(&filePtr)) {
  1630. LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. "
  1631. "Material index expected [#6]");
  1632. SkipToNextToken();
  1633. return;
  1634. }
  1635. out.iMaterial = strtoul10(filePtr, &filePtr);
  1636. }
  1637. return;
  1638. }
  1639. // ------------------------------------------------------------------------------------------------
  1640. void Parser::ParseLV4MeshLongTriple(unsigned int *apOut) {
  1641. ai_assert(nullptr != apOut);
  1642. for (unsigned int i = 0; i < 3; ++i)
  1643. ParseLV4MeshLong(apOut[i]);
  1644. }
  1645. // ------------------------------------------------------------------------------------------------
  1646. void Parser::ParseLV4MeshLongTriple(unsigned int *apOut, unsigned int &rIndexOut) {
  1647. ai_assert(nullptr != apOut);
  1648. // parse the index
  1649. ParseLV4MeshLong(rIndexOut);
  1650. // parse the three others
  1651. ParseLV4MeshLongTriple(apOut);
  1652. }
  1653. // ------------------------------------------------------------------------------------------------
  1654. void Parser::ParseLV4MeshFloatTriple(ai_real *apOut, unsigned int &rIndexOut) {
  1655. ai_assert(nullptr != apOut);
  1656. // parse the index
  1657. ParseLV4MeshLong(rIndexOut);
  1658. // parse the three others
  1659. ParseLV4MeshFloatTriple(apOut);
  1660. }
  1661. // ------------------------------------------------------------------------------------------------
  1662. void Parser::ParseLV4MeshFloatTriple(ai_real *apOut) {
  1663. ai_assert(nullptr != apOut);
  1664. for (unsigned int i = 0; i < 3; ++i)
  1665. ParseLV4MeshFloat(apOut[i]);
  1666. }
  1667. // ------------------------------------------------------------------------------------------------
  1668. void Parser::ParseLV4MeshFloat(ai_real &fOut) {
  1669. // skip spaces and tabs
  1670. if (!SkipSpaces(&filePtr)) {
  1671. // LOG
  1672. LogWarning("Unable to parse float: unexpected EOL [#1]");
  1673. fOut = 0.0;
  1674. ++iLineNumber;
  1675. return;
  1676. }
  1677. // parse the first float
  1678. filePtr = fast_atoreal_move<ai_real>(filePtr, fOut);
  1679. }
  1680. // ------------------------------------------------------------------------------------------------
  1681. void Parser::ParseLV4MeshLong(unsigned int &iOut) {
  1682. // Skip spaces and tabs
  1683. if (!SkipSpaces(&filePtr)) {
  1684. // LOG
  1685. LogWarning("Unable to parse long: unexpected EOL [#1]");
  1686. iOut = 0;
  1687. ++iLineNumber;
  1688. return;
  1689. }
  1690. // parse the value
  1691. iOut = strtoul10(filePtr, &filePtr);
  1692. }
  1693. #endif // ASSIMP_BUILD_NO_3DS_IMPORTER
  1694. #endif // !! ASSIMP_BUILD_NO_BASE_IMPORTER