ASEParser.cpp 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  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. 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.emplace_back("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.emplace_back();
  235. ParseLV1ObjectBlock(m_vDummies.back());
  236. continue;
  237. }
  238. // light object
  239. if (TokenMatch(filePtr, "LIGHTOBJECT", 11))
  240. {
  241. m_vLights.emplace_back("UNNAMED");
  242. ParseLV1ObjectBlock(m_vLights.back());
  243. continue;
  244. }
  245. // camera object
  246. if (TokenMatch(filePtr, "CAMERAOBJECT", 12)) {
  247. m_vCameras.emplace_back("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. }
  266. // ------------------------------------------------------------------------------------------------
  267. void Parser::ParseLV1SoftSkinBlock() {
  268. // TODO: fix line counting here
  269. // **************************************************************
  270. // The soft skin block is formatted differently. There are no
  271. // nested sections supported and the single elements aren't
  272. // marked by keywords starting with an asterisk.
  273. /**
  274. FORMAT BEGIN
  275. *MESH_SOFTSKINVERTS {
  276. <nodename>
  277. <number of vertices>
  278. [for <number of vertices> times:]
  279. <number of weights> [for <number of weights> times:] <bone name> <weight>
  280. }
  281. FORMAT END
  282. */
  283. // **************************************************************
  284. while (true) {
  285. if (*filePtr == '}') {
  286. ++filePtr;
  287. return;
  288. } else if (*filePtr == '\0')
  289. return;
  290. else if (*filePtr == '{')
  291. ++filePtr;
  292. else // if (!IsSpace(*filePtr) && !IsLineEnd(*filePtr))
  293. {
  294. ASE::Mesh *curMesh = nullptr;
  295. unsigned int numVerts = 0;
  296. const char *sz = filePtr;
  297. while (!IsSpaceOrNewLine(*filePtr))
  298. ++filePtr;
  299. const unsigned int diff = (unsigned int)(filePtr - sz);
  300. if (diff) {
  301. std::string name = std::string(sz, diff);
  302. for (std::vector<ASE::Mesh>::iterator it = m_vMeshes.begin();
  303. it != m_vMeshes.end(); ++it) {
  304. if ((*it).mName == name) {
  305. curMesh = &(*it);
  306. break;
  307. }
  308. }
  309. if (!curMesh) {
  310. LogWarning("Encountered unknown mesh in *MESH_SOFTSKINVERTS section");
  311. // Skip the mesh data - until we find a new mesh
  312. // or the end of the *MESH_SOFTSKINVERTS section
  313. while (true) {
  314. SkipSpacesAndLineEnd(&filePtr);
  315. if (*filePtr == '}') {
  316. ++filePtr;
  317. return;
  318. } else if (!IsNumeric(*filePtr))
  319. break;
  320. SkipLine(&filePtr);
  321. }
  322. } else {
  323. SkipSpacesAndLineEnd(&filePtr);
  324. ParseLV4MeshLong(numVerts);
  325. // Reserve enough storage
  326. curMesh->mBoneVertices.reserve(numVerts);
  327. for (unsigned int i = 0; i < numVerts; ++i) {
  328. SkipSpacesAndLineEnd(&filePtr);
  329. unsigned int numWeights;
  330. ParseLV4MeshLong(numWeights);
  331. curMesh->mBoneVertices.emplace_back();
  332. ASE::BoneVertex &vert = curMesh->mBoneVertices.back();
  333. // Reserve enough storage
  334. vert.mBoneWeights.reserve(numWeights);
  335. std::string bone;
  336. for (unsigned int w = 0; w < numWeights; ++w) {
  337. bone.clear();
  338. ParseString(bone, "*MESH_SOFTSKINVERTS.Bone");
  339. // Find the bone in the mesh's list
  340. std::pair<int, ai_real> me;
  341. me.first = -1;
  342. for (unsigned int n = 0; n < curMesh->mBones.size(); ++n) {
  343. if (curMesh->mBones[n].mName == bone) {
  344. me.first = n;
  345. break;
  346. }
  347. }
  348. if (-1 == me.first) {
  349. // We don't have this bone yet, so add it to the list
  350. me.first = static_cast<int>(curMesh->mBones.size());
  351. curMesh->mBones.emplace_back(bone);
  352. }
  353. ParseLV4MeshFloat(me.second);
  354. // Add the new bone weight to list
  355. vert.mBoneWeights.push_back(me);
  356. }
  357. }
  358. }
  359. }
  360. }
  361. if (*filePtr == '\0')
  362. return;
  363. ++filePtr;
  364. SkipSpacesAndLineEnd(&filePtr);
  365. }
  366. }
  367. // ------------------------------------------------------------------------------------------------
  368. void Parser::ParseLV1SceneBlock() {
  369. AI_ASE_PARSER_INIT();
  370. while (true) {
  371. if ('*' == *filePtr) {
  372. ++filePtr;
  373. if (TokenMatch(filePtr, "SCENE_BACKGROUND_STATIC", 23))
  374. {
  375. // parse a color triple and assume it is really the bg color
  376. ParseLV4MeshFloatTriple(&m_clrBackground.r);
  377. continue;
  378. }
  379. if (TokenMatch(filePtr, "SCENE_AMBIENT_STATIC", 20))
  380. {
  381. // parse a color triple and assume it is really the bg color
  382. ParseLV4MeshFloatTriple(&m_clrAmbient.r);
  383. continue;
  384. }
  385. if (TokenMatch(filePtr, "SCENE_FIRSTFRAME", 16)) {
  386. ParseLV4MeshLong(iFirstFrame);
  387. continue;
  388. }
  389. if (TokenMatch(filePtr, "SCENE_LASTFRAME", 15)) {
  390. ParseLV4MeshLong(iLastFrame);
  391. continue;
  392. }
  393. if (TokenMatch(filePtr, "SCENE_FRAMESPEED", 16)) {
  394. ParseLV4MeshLong(iFrameSpeed);
  395. continue;
  396. }
  397. if (TokenMatch(filePtr, "SCENE_TICKSPERFRAME", 19)) {
  398. ParseLV4MeshLong(iTicksPerFrame);
  399. continue;
  400. }
  401. }
  402. AI_ASE_HANDLE_TOP_LEVEL_SECTION();
  403. }
  404. }
  405. // ------------------------------------------------------------------------------------------------
  406. void Parser::ParseLV1MaterialListBlock() {
  407. AI_ASE_PARSER_INIT();
  408. unsigned int iMaterialCount = 0;
  409. unsigned int iOldMaterialCount = (unsigned int)m_vMaterials.size();
  410. while (true) {
  411. if ('*' == *filePtr) {
  412. ++filePtr;
  413. if (TokenMatch(filePtr, "MATERIAL_COUNT", 14)) {
  414. ParseLV4MeshLong(iMaterialCount);
  415. // now allocate enough storage to hold all materials
  416. m_vMaterials.resize(iOldMaterialCount + iMaterialCount, Material("INVALID"));
  417. continue;
  418. }
  419. if (TokenMatch(filePtr, "MATERIAL", 8)) {
  420. unsigned int iIndex = 0;
  421. ParseLV4MeshLong(iIndex);
  422. if (iIndex >= iMaterialCount) {
  423. LogWarning("Out of range: material index is too large");
  424. iIndex = iMaterialCount - 1;
  425. return;
  426. }
  427. // get a reference to the material
  428. Material &sMat = m_vMaterials[iIndex + iOldMaterialCount];
  429. // parse the material block
  430. ParseLV2MaterialBlock(sMat);
  431. continue;
  432. }
  433. if( iDepth == 1 ){
  434. // CRUDE HACK: support missing brace after "Ascii Scene Exporter v2.51"
  435. LogWarning("Missing closing brace in material list");
  436. --filePtr;
  437. return;
  438. }
  439. }
  440. AI_ASE_HANDLE_TOP_LEVEL_SECTION();
  441. }
  442. }
  443. // ------------------------------------------------------------------------------------------------
  444. void Parser::ParseLV2MaterialBlock(ASE::Material &mat) {
  445. AI_ASE_PARSER_INIT();
  446. unsigned int iNumSubMaterials = 0;
  447. while (true) {
  448. if ('*' == *filePtr) {
  449. ++filePtr;
  450. if (TokenMatch(filePtr, "MATERIAL_NAME", 13)) {
  451. if (!ParseString(mat.mName, "*MATERIAL_NAME"))
  452. SkipToNextToken();
  453. continue;
  454. }
  455. // ambient material color
  456. if (TokenMatch(filePtr, "MATERIAL_AMBIENT", 16)) {
  457. ParseLV4MeshFloatTriple(&mat.mAmbient.r);
  458. continue;
  459. }
  460. // diffuse material color
  461. if (TokenMatch(filePtr, "MATERIAL_DIFFUSE", 16)) {
  462. ParseLV4MeshFloatTriple(&mat.mDiffuse.r);
  463. continue;
  464. }
  465. // specular material color
  466. if (TokenMatch(filePtr, "MATERIAL_SPECULAR", 17)) {
  467. ParseLV4MeshFloatTriple(&mat.mSpecular.r);
  468. continue;
  469. }
  470. // material shading type
  471. if (TokenMatch(filePtr, "MATERIAL_SHADING", 16)) {
  472. if (TokenMatch(filePtr, "Blinn", 5)) {
  473. mat.mShading = Discreet3DS::Blinn;
  474. } else if (TokenMatch(filePtr, "Phong", 5)) {
  475. mat.mShading = Discreet3DS::Phong;
  476. } else if (TokenMatch(filePtr, "Flat", 4)) {
  477. mat.mShading = Discreet3DS::Flat;
  478. } else if (TokenMatch(filePtr, "Wire", 4)) {
  479. mat.mShading = Discreet3DS::Wire;
  480. } else {
  481. // assume gouraud shading
  482. mat.mShading = Discreet3DS::Gouraud;
  483. SkipToNextToken();
  484. }
  485. continue;
  486. }
  487. // material transparency
  488. if (TokenMatch(filePtr, "MATERIAL_TRANSPARENCY", 21)) {
  489. ParseLV4MeshFloat(mat.mTransparency);
  490. mat.mTransparency = ai_real(1.0) - mat.mTransparency;
  491. continue;
  492. }
  493. // material self illumination
  494. if (TokenMatch(filePtr, "MATERIAL_SELFILLUM", 18)) {
  495. ai_real f = 0.0;
  496. ParseLV4MeshFloat(f);
  497. mat.mEmissive.r = f;
  498. mat.mEmissive.g = f;
  499. mat.mEmissive.b = f;
  500. continue;
  501. }
  502. // material shininess
  503. if (TokenMatch(filePtr, "MATERIAL_SHINE", 14)) {
  504. ParseLV4MeshFloat(mat.mSpecularExponent);
  505. mat.mSpecularExponent *= 15;
  506. continue;
  507. }
  508. // two-sided material
  509. if (TokenMatch(filePtr, "MATERIAL_TWOSIDED", 17)) {
  510. mat.mTwoSided = true;
  511. continue;
  512. }
  513. // material shininess strength
  514. if (TokenMatch(filePtr, "MATERIAL_SHINESTRENGTH", 22)) {
  515. ParseLV4MeshFloat(mat.mShininessStrength);
  516. continue;
  517. }
  518. // diffuse color map
  519. if (TokenMatch(filePtr, "MAP_DIFFUSE", 11)) {
  520. // parse the texture block
  521. ParseLV3MapBlock(mat.sTexDiffuse);
  522. continue;
  523. }
  524. // ambient color map
  525. if (TokenMatch(filePtr, "MAP_AMBIENT", 11)) {
  526. // parse the texture block
  527. ParseLV3MapBlock(mat.sTexAmbient);
  528. continue;
  529. }
  530. // specular color map
  531. if (TokenMatch(filePtr, "MAP_SPECULAR", 12)) {
  532. // parse the texture block
  533. ParseLV3MapBlock(mat.sTexSpecular);
  534. continue;
  535. }
  536. // opacity map
  537. if (TokenMatch(filePtr, "MAP_OPACITY", 11)) {
  538. // parse the texture block
  539. ParseLV3MapBlock(mat.sTexOpacity);
  540. continue;
  541. }
  542. // emissive map
  543. if (TokenMatch(filePtr, "MAP_SELFILLUM", 13)) {
  544. // parse the texture block
  545. ParseLV3MapBlock(mat.sTexEmissive);
  546. continue;
  547. }
  548. // bump map
  549. if (TokenMatch(filePtr, "MAP_BUMP", 8)) {
  550. // parse the texture block
  551. ParseLV3MapBlock(mat.sTexBump);
  552. }
  553. // specular/shininess map
  554. if (TokenMatch(filePtr, "MAP_SHINESTRENGTH", 17)) {
  555. // parse the texture block
  556. ParseLV3MapBlock(mat.sTexShininess);
  557. continue;
  558. }
  559. // number of submaterials
  560. if (TokenMatch(filePtr, "NUMSUBMTLS", 10)) {
  561. ParseLV4MeshLong(iNumSubMaterials);
  562. // allocate enough storage
  563. mat.avSubMaterials.resize(iNumSubMaterials, Material("INVALID SUBMATERIAL"));
  564. }
  565. // submaterial chunks
  566. if (TokenMatch(filePtr, "SUBMATERIAL", 11)) {
  567. unsigned int iIndex = 0;
  568. ParseLV4MeshLong(iIndex);
  569. if (iIndex >= iNumSubMaterials) {
  570. LogWarning("Out of range: submaterial index is too large");
  571. iIndex = iNumSubMaterials - 1;
  572. }
  573. // get a reference to the material
  574. if (iIndex < mat.avSubMaterials.size()) {
  575. Material &sMat = mat.avSubMaterials[iIndex];
  576. // parse the material block
  577. ParseLV2MaterialBlock(sMat);
  578. }
  579. continue;
  580. }
  581. }
  582. AI_ASE_HANDLE_SECTION("2", "*MATERIAL");
  583. }
  584. }
  585. // ------------------------------------------------------------------------------------------------
  586. void Parser::ParseLV3MapBlock(Texture &map) {
  587. AI_ASE_PARSER_INIT();
  588. // ***********************************************************
  589. // *BITMAP should not be there if *MAP_CLASS is not BITMAP,
  590. // but we need to expect that case ... if the path is
  591. // empty the texture won't be used later.
  592. // ***********************************************************
  593. bool parsePath = true;
  594. std::string temp;
  595. while (true) {
  596. if ('*' == *filePtr) {
  597. ++filePtr;
  598. // type of map
  599. if (TokenMatch(filePtr, "MAP_CLASS", 9)) {
  600. temp.clear();
  601. if (!ParseString(temp, "*MAP_CLASS"))
  602. SkipToNextToken();
  603. if (temp != "Bitmap" && temp != "Normal Bump") {
  604. ASSIMP_LOG_WARN("ASE: Skipping unknown map type: ", temp);
  605. parsePath = false;
  606. }
  607. continue;
  608. }
  609. // path to the texture
  610. if (parsePath && TokenMatch(filePtr, "BITMAP", 6)) {
  611. if (!ParseString(map.mMapName, "*BITMAP"))
  612. SkipToNextToken();
  613. if (map.mMapName == "None") {
  614. // Files with 'None' as map name are produced by
  615. // an Maja to ASE exporter which name I forgot ..
  616. ASSIMP_LOG_WARN("ASE: Skipping invalid map entry");
  617. map.mMapName = std::string();
  618. }
  619. continue;
  620. }
  621. // offset on the u axis
  622. if (TokenMatch(filePtr, "UVW_U_OFFSET", 12)) {
  623. ParseLV4MeshFloat(map.mOffsetU);
  624. continue;
  625. }
  626. // offset on the v axis
  627. if (TokenMatch(filePtr, "UVW_V_OFFSET", 12)) {
  628. ParseLV4MeshFloat(map.mOffsetV);
  629. continue;
  630. }
  631. // tiling on the u axis
  632. if (TokenMatch(filePtr, "UVW_U_TILING", 12)) {
  633. ParseLV4MeshFloat(map.mScaleU);
  634. continue;
  635. }
  636. // tiling on the v axis
  637. if (TokenMatch(filePtr, "UVW_V_TILING", 12)) {
  638. ParseLV4MeshFloat(map.mScaleV);
  639. continue;
  640. }
  641. // rotation around the z-axis
  642. if (TokenMatch(filePtr, "UVW_ANGLE", 9)) {
  643. ParseLV4MeshFloat(map.mRotation);
  644. continue;
  645. }
  646. // map blending factor
  647. if (TokenMatch(filePtr, "MAP_AMOUNT", 10)) {
  648. ParseLV4MeshFloat(map.mTextureBlend);
  649. continue;
  650. }
  651. }
  652. AI_ASE_HANDLE_SECTION("3", "*MAP_XXXXXX");
  653. }
  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. }
  773. // ------------------------------------------------------------------------------------------------
  774. void Parser::ParseLV2CameraSettingsBlock(ASE::Camera &camera) {
  775. AI_ASE_PARSER_INIT();
  776. while (true) {
  777. if ('*' == *filePtr) {
  778. ++filePtr;
  779. if (TokenMatch(filePtr, "CAMERA_NEAR", 11)) {
  780. ParseLV4MeshFloat(camera.mNear);
  781. continue;
  782. }
  783. if (TokenMatch(filePtr, "CAMERA_FAR", 10)) {
  784. ParseLV4MeshFloat(camera.mFar);
  785. continue;
  786. }
  787. if (TokenMatch(filePtr, "CAMERA_FOV", 10)) {
  788. ParseLV4MeshFloat(camera.mFOV);
  789. continue;
  790. }
  791. }
  792. AI_ASE_HANDLE_SECTION("2", "CAMERA_SETTINGS");
  793. }
  794. }
  795. // ------------------------------------------------------------------------------------------------
  796. void Parser::ParseLV2LightSettingsBlock(ASE::Light &light) {
  797. AI_ASE_PARSER_INIT();
  798. while (true) {
  799. if ('*' == *filePtr) {
  800. ++filePtr;
  801. if (TokenMatch(filePtr, "LIGHT_COLOR", 11)) {
  802. ParseLV4MeshFloatTriple(&light.mColor.r);
  803. continue;
  804. }
  805. if (TokenMatch(filePtr, "LIGHT_INTENS", 12)) {
  806. ParseLV4MeshFloat(light.mIntensity);
  807. continue;
  808. }
  809. if (TokenMatch(filePtr, "LIGHT_HOTSPOT", 13)) {
  810. ParseLV4MeshFloat(light.mAngle);
  811. continue;
  812. }
  813. if (TokenMatch(filePtr, "LIGHT_FALLOFF", 13)) {
  814. ParseLV4MeshFloat(light.mFalloff);
  815. continue;
  816. }
  817. }
  818. AI_ASE_HANDLE_SECTION("2", "LIGHT_SETTINGS");
  819. }
  820. }
  821. // ------------------------------------------------------------------------------------------------
  822. void Parser::ParseLV2AnimationBlock(ASE::BaseNode &mesh) {
  823. AI_ASE_PARSER_INIT();
  824. ASE::Animation *anim = &mesh.mAnim;
  825. while (true) {
  826. if ('*' == *filePtr) {
  827. ++filePtr;
  828. if (TokenMatch(filePtr, "NODE_NAME", 9)) {
  829. std::string temp;
  830. if (!ParseString(temp, "*NODE_NAME"))
  831. SkipToNextToken();
  832. // If the name of the node contains .target it
  833. // represents an animated camera or spot light
  834. // target.
  835. if (std::string::npos != temp.find(".Target")) {
  836. if ((mesh.mType != BaseNode::Camera || ((ASE::Camera &)mesh).mCameraType != ASE::Camera::TARGET) &&
  837. (mesh.mType != BaseNode::Light || ((ASE::Light &)mesh).mLightType != ASE::Light::TARGET)) {
  838. ASSIMP_LOG_ERROR("ASE: Found target animation channel "
  839. "but the node is neither a camera nor a spot light");
  840. anim = nullptr;
  841. } else
  842. anim = &mesh.mTargetAnim;
  843. }
  844. continue;
  845. }
  846. // position keyframes
  847. if (TokenMatch(filePtr, "CONTROL_POS_TRACK", 17) ||
  848. TokenMatch(filePtr, "CONTROL_POS_BEZIER", 18) ||
  849. TokenMatch(filePtr, "CONTROL_POS_TCB", 15)) {
  850. if (!anim)
  851. SkipSection();
  852. else
  853. ParseLV3PosAnimationBlock(*anim);
  854. continue;
  855. }
  856. // scaling keyframes
  857. if (TokenMatch(filePtr, "CONTROL_SCALE_TRACK", 19) ||
  858. TokenMatch(filePtr, "CONTROL_SCALE_BEZIER", 20) ||
  859. TokenMatch(filePtr, "CONTROL_SCALE_TCB", 17)) {
  860. if (!anim || anim == &mesh.mTargetAnim) {
  861. // Target animation channels may have no rotation channels
  862. ASSIMP_LOG_ERROR("ASE: Ignoring scaling channel in target animation");
  863. SkipSection();
  864. } else
  865. ParseLV3ScaleAnimationBlock(*anim);
  866. continue;
  867. }
  868. // rotation keyframes
  869. if (TokenMatch(filePtr, "CONTROL_ROT_TRACK", 17) ||
  870. TokenMatch(filePtr, "CONTROL_ROT_BEZIER", 18) ||
  871. TokenMatch(filePtr, "CONTROL_ROT_TCB", 15)) {
  872. if (!anim || anim == &mesh.mTargetAnim) {
  873. // Target animation channels may have no rotation channels
  874. ASSIMP_LOG_ERROR("ASE: Ignoring rotation channel in target animation");
  875. SkipSection();
  876. } else
  877. ParseLV3RotAnimationBlock(*anim);
  878. continue;
  879. }
  880. }
  881. AI_ASE_HANDLE_SECTION("2", "TM_ANIMATION");
  882. }
  883. }
  884. // ------------------------------------------------------------------------------------------------
  885. void Parser::ParseLV3ScaleAnimationBlock(ASE::Animation &anim) {
  886. AI_ASE_PARSER_INIT();
  887. unsigned int iIndex;
  888. while (true) {
  889. if ('*' == *filePtr) {
  890. ++filePtr;
  891. bool b = false;
  892. // For the moment we're just reading the three floats -
  893. // we ignore the additional information for bezier's and TCBs
  894. // simple scaling keyframe
  895. if (TokenMatch(filePtr, "CONTROL_SCALE_SAMPLE", 20)) {
  896. b = true;
  897. anim.mScalingType = ASE::Animation::TRACK;
  898. }
  899. // Bezier scaling keyframe
  900. if (TokenMatch(filePtr, "CONTROL_BEZIER_SCALE_KEY", 24)) {
  901. b = true;
  902. anim.mScalingType = ASE::Animation::BEZIER;
  903. }
  904. // TCB scaling keyframe
  905. if (TokenMatch(filePtr, "CONTROL_TCB_SCALE_KEY", 21)) {
  906. b = true;
  907. anim.mScalingType = ASE::Animation::TCB;
  908. }
  909. if (b) {
  910. anim.akeyScaling.emplace_back();
  911. aiVectorKey &key = anim.akeyScaling.back();
  912. ParseLV4MeshFloatTriple(&key.mValue.x, iIndex);
  913. key.mTime = (double)iIndex;
  914. }
  915. }
  916. AI_ASE_HANDLE_SECTION("3", "*CONTROL_POS_TRACK");
  917. }
  918. }
  919. // ------------------------------------------------------------------------------------------------
  920. void Parser::ParseLV3PosAnimationBlock(ASE::Animation &anim) {
  921. AI_ASE_PARSER_INIT();
  922. unsigned int iIndex;
  923. while (true) {
  924. if ('*' == *filePtr) {
  925. ++filePtr;
  926. bool b = false;
  927. // For the moment we're just reading the three floats -
  928. // we ignore the additional information for bezier's and TCBs
  929. // simple scaling keyframe
  930. if (TokenMatch(filePtr, "CONTROL_POS_SAMPLE", 18)) {
  931. b = true;
  932. anim.mPositionType = ASE::Animation::TRACK;
  933. }
  934. // Bezier scaling keyframe
  935. if (TokenMatch(filePtr, "CONTROL_BEZIER_POS_KEY", 22)) {
  936. b = true;
  937. anim.mPositionType = ASE::Animation::BEZIER;
  938. }
  939. // TCB scaling keyframe
  940. if (TokenMatch(filePtr, "CONTROL_TCB_POS_KEY", 19)) {
  941. b = true;
  942. anim.mPositionType = ASE::Animation::TCB;
  943. }
  944. if (b) {
  945. anim.akeyPositions.emplace_back();
  946. aiVectorKey &key = anim.akeyPositions.back();
  947. ParseLV4MeshFloatTriple(&key.mValue.x, iIndex);
  948. key.mTime = (double)iIndex;
  949. }
  950. }
  951. AI_ASE_HANDLE_SECTION("3", "*CONTROL_POS_TRACK");
  952. }
  953. }
  954. // ------------------------------------------------------------------------------------------------
  955. void Parser::ParseLV3RotAnimationBlock(ASE::Animation &anim) {
  956. AI_ASE_PARSER_INIT();
  957. unsigned int iIndex;
  958. while (true) {
  959. if ('*' == *filePtr) {
  960. ++filePtr;
  961. bool b = false;
  962. // For the moment we're just reading the floats -
  963. // we ignore the additional information for bezier's and TCBs
  964. // simple scaling keyframe
  965. if (TokenMatch(filePtr, "CONTROL_ROT_SAMPLE", 18)) {
  966. b = true;
  967. anim.mRotationType = ASE::Animation::TRACK;
  968. }
  969. // Bezier scaling keyframe
  970. if (TokenMatch(filePtr, "CONTROL_BEZIER_ROT_KEY", 22)) {
  971. b = true;
  972. anim.mRotationType = ASE::Animation::BEZIER;
  973. }
  974. // TCB scaling keyframe
  975. if (TokenMatch(filePtr, "CONTROL_TCB_ROT_KEY", 19)) {
  976. b = true;
  977. anim.mRotationType = ASE::Animation::TCB;
  978. }
  979. if (b) {
  980. anim.akeyRotations.emplace_back();
  981. aiQuatKey &key = anim.akeyRotations.back();
  982. aiVector3D v;
  983. ai_real f;
  984. ParseLV4MeshFloatTriple(&v.x, iIndex);
  985. ParseLV4MeshFloat(f);
  986. key.mTime = (double)iIndex;
  987. key.mValue = aiQuaternion(v, f);
  988. }
  989. }
  990. AI_ASE_HANDLE_SECTION("3", "*CONTROL_ROT_TRACK");
  991. }
  992. }
  993. // ------------------------------------------------------------------------------------------------
  994. void Parser::ParseLV2NodeTransformBlock(ASE::BaseNode &mesh) {
  995. AI_ASE_PARSER_INIT();
  996. int mode = 0;
  997. while (true) {
  998. if ('*' == *filePtr) {
  999. ++filePtr;
  1000. // name of the node
  1001. if (TokenMatch(filePtr, "NODE_NAME", 9)) {
  1002. std::string temp;
  1003. if (!ParseString(temp, "*NODE_NAME"))
  1004. SkipToNextToken();
  1005. std::string::size_type s;
  1006. if (temp == mesh.mName) {
  1007. mode = 1;
  1008. } else if (std::string::npos != (s = temp.find(".Target")) &&
  1009. mesh.mName == temp.substr(0, s)) {
  1010. // This should be either a target light or a target camera
  1011. if ((mesh.mType == BaseNode::Light && ((ASE::Light &)mesh).mLightType == ASE::Light::TARGET) ||
  1012. (mesh.mType == BaseNode::Camera && ((ASE::Camera &)mesh).mCameraType == ASE::Camera::TARGET)) {
  1013. mode = 2;
  1014. } else {
  1015. ASSIMP_LOG_ERROR("ASE: Ignoring target transform, "
  1016. "this is no spot light or target camera");
  1017. }
  1018. } else {
  1019. ASSIMP_LOG_ERROR("ASE: Unknown node transformation: ", temp);
  1020. // mode = 0
  1021. }
  1022. continue;
  1023. }
  1024. if (mode) {
  1025. // fourth row of the transformation matrix - and also the
  1026. // only information here that is interesting for targets
  1027. if (TokenMatch(filePtr, "TM_ROW3", 7)) {
  1028. ParseLV4MeshFloatTriple((mode == 1 ? mesh.mTransform[3] : &mesh.mTargetPosition.x));
  1029. continue;
  1030. }
  1031. if (mode == 1) {
  1032. // first row of the transformation matrix
  1033. if (TokenMatch(filePtr, "TM_ROW0", 7)) {
  1034. ParseLV4MeshFloatTriple(mesh.mTransform[0]);
  1035. continue;
  1036. }
  1037. // second row of the transformation matrix
  1038. if (TokenMatch(filePtr, "TM_ROW1", 7)) {
  1039. ParseLV4MeshFloatTriple(mesh.mTransform[1]);
  1040. continue;
  1041. }
  1042. // third row of the transformation matrix
  1043. if (TokenMatch(filePtr, "TM_ROW2", 7)) {
  1044. ParseLV4MeshFloatTriple(mesh.mTransform[2]);
  1045. continue;
  1046. }
  1047. // inherited position axes
  1048. if (TokenMatch(filePtr, "INHERIT_POS", 11)) {
  1049. unsigned int aiVal[3];
  1050. ParseLV4MeshLongTriple(aiVal);
  1051. for (unsigned int i = 0; i < 3; ++i)
  1052. mesh.inherit.abInheritPosition[i] = aiVal[i] != 0;
  1053. continue;
  1054. }
  1055. // inherited rotation axes
  1056. if (TokenMatch(filePtr, "INHERIT_ROT", 11)) {
  1057. unsigned int aiVal[3];
  1058. ParseLV4MeshLongTriple(aiVal);
  1059. for (unsigned int i = 0; i < 3; ++i)
  1060. mesh.inherit.abInheritRotation[i] = aiVal[i] != 0;
  1061. continue;
  1062. }
  1063. // inherited scaling axes
  1064. if (TokenMatch(filePtr, "INHERIT_SCL", 11)) {
  1065. unsigned int aiVal[3];
  1066. ParseLV4MeshLongTriple(aiVal);
  1067. for (unsigned int i = 0; i < 3; ++i)
  1068. mesh.inherit.abInheritScaling[i] = aiVal[i] != 0;
  1069. continue;
  1070. }
  1071. }
  1072. }
  1073. }
  1074. AI_ASE_HANDLE_SECTION("2", "*NODE_TM");
  1075. }
  1076. }
  1077. // ------------------------------------------------------------------------------------------------
  1078. void Parser::ParseLV2MeshBlock(ASE::Mesh &mesh) {
  1079. AI_ASE_PARSER_INIT();
  1080. unsigned int iNumVertices = 0;
  1081. unsigned int iNumFaces = 0;
  1082. unsigned int iNumTVertices = 0;
  1083. unsigned int iNumTFaces = 0;
  1084. unsigned int iNumCVertices = 0;
  1085. unsigned int iNumCFaces = 0;
  1086. while (true) {
  1087. if ('*' == *filePtr) {
  1088. ++filePtr;
  1089. // Number of vertices in the mesh
  1090. if (TokenMatch(filePtr, "MESH_NUMVERTEX", 14)) {
  1091. ParseLV4MeshLong(iNumVertices);
  1092. continue;
  1093. }
  1094. // Number of texture coordinates in the mesh
  1095. if (TokenMatch(filePtr, "MESH_NUMTVERTEX", 15)) {
  1096. ParseLV4MeshLong(iNumTVertices);
  1097. continue;
  1098. }
  1099. // Number of vertex colors in the mesh
  1100. if (TokenMatch(filePtr, "MESH_NUMCVERTEX", 15)) {
  1101. ParseLV4MeshLong(iNumCVertices);
  1102. continue;
  1103. }
  1104. // Number of regular faces in the mesh
  1105. if (TokenMatch(filePtr, "MESH_NUMFACES", 13)) {
  1106. ParseLV4MeshLong(iNumFaces);
  1107. continue;
  1108. }
  1109. // Number of UVWed faces in the mesh
  1110. if (TokenMatch(filePtr, "MESH_NUMTVFACES", 15)) {
  1111. ParseLV4MeshLong(iNumTFaces);
  1112. continue;
  1113. }
  1114. // Number of colored faces in the mesh
  1115. if (TokenMatch(filePtr, "MESH_NUMCVFACES", 15)) {
  1116. ParseLV4MeshLong(iNumCFaces);
  1117. continue;
  1118. }
  1119. // mesh vertex list block
  1120. if (TokenMatch(filePtr, "MESH_VERTEX_LIST", 16)) {
  1121. ParseLV3MeshVertexListBlock(iNumVertices, mesh);
  1122. continue;
  1123. }
  1124. // mesh face list block
  1125. if (TokenMatch(filePtr, "MESH_FACE_LIST", 14)) {
  1126. ParseLV3MeshFaceListBlock(iNumFaces, mesh);
  1127. continue;
  1128. }
  1129. // mesh texture vertex list block
  1130. if (TokenMatch(filePtr, "MESH_TVERTLIST", 14)) {
  1131. ParseLV3MeshTListBlock(iNumTVertices, mesh);
  1132. continue;
  1133. }
  1134. // mesh texture face block
  1135. if (TokenMatch(filePtr, "MESH_TFACELIST", 14)) {
  1136. ParseLV3MeshTFaceListBlock(iNumTFaces, mesh);
  1137. continue;
  1138. }
  1139. // mesh color vertex list block
  1140. if (TokenMatch(filePtr, "MESH_CVERTLIST", 14)) {
  1141. ParseLV3MeshCListBlock(iNumCVertices, mesh);
  1142. continue;
  1143. }
  1144. // mesh color face block
  1145. if (TokenMatch(filePtr, "MESH_CFACELIST", 14)) {
  1146. ParseLV3MeshCFaceListBlock(iNumCFaces, mesh);
  1147. continue;
  1148. }
  1149. // mesh normals
  1150. if (TokenMatch(filePtr, "MESH_NORMALS", 12)) {
  1151. ParseLV3MeshNormalListBlock(mesh);
  1152. continue;
  1153. }
  1154. // another mesh UV channel ...
  1155. if (TokenMatch(filePtr, "MESH_MAPPINGCHANNEL", 19)) {
  1156. unsigned int iIndex(0);
  1157. ParseLV4MeshLong(iIndex);
  1158. if (0 == iIndex) {
  1159. LogWarning("Mapping channel has an invalid index. Skipping UV channel");
  1160. // skip it ...
  1161. SkipSection();
  1162. } else {
  1163. if (iIndex < 2) {
  1164. LogWarning("Mapping channel has an invalid index. Skipping UV channel");
  1165. // skip it ...
  1166. SkipSection();
  1167. }
  1168. if (iIndex > AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  1169. LogWarning("Too many UV channels specified. Skipping channel ..");
  1170. // skip it ...
  1171. SkipSection();
  1172. } else {
  1173. // parse the mapping channel
  1174. ParseLV3MappingChannel(iIndex - 1, mesh);
  1175. }
  1176. continue;
  1177. }
  1178. }
  1179. // mesh animation keyframe. Not supported
  1180. if (TokenMatch(filePtr, "MESH_ANIMATION", 14)) {
  1181. LogWarning("Found *MESH_ANIMATION element in ASE/ASK file. "
  1182. "Keyframe animation is not supported by Assimp, this element "
  1183. "will be ignored");
  1184. //SkipSection();
  1185. continue;
  1186. }
  1187. if (TokenMatch(filePtr, "MESH_WEIGHTS", 12)) {
  1188. ParseLV3MeshWeightsBlock(mesh);
  1189. continue;
  1190. }
  1191. }
  1192. AI_ASE_HANDLE_SECTION("2", "*MESH");
  1193. }
  1194. }
  1195. // ------------------------------------------------------------------------------------------------
  1196. void Parser::ParseLV3MeshWeightsBlock(ASE::Mesh &mesh) {
  1197. AI_ASE_PARSER_INIT();
  1198. unsigned int iNumVertices = 0, iNumBones = 0;
  1199. while (true) {
  1200. if ('*' == *filePtr) {
  1201. ++filePtr;
  1202. // Number of bone vertices ...
  1203. if (TokenMatch(filePtr, "MESH_NUMVERTEX", 14)) {
  1204. ParseLV4MeshLong(iNumVertices);
  1205. continue;
  1206. }
  1207. // Number of bones
  1208. if (TokenMatch(filePtr, "MESH_NUMBONE", 12)) {
  1209. ParseLV4MeshLong(iNumBones);
  1210. continue;
  1211. }
  1212. // parse the list of bones
  1213. if (TokenMatch(filePtr, "MESH_BONE_LIST", 14)) {
  1214. ParseLV4MeshBones(iNumBones, mesh);
  1215. continue;
  1216. }
  1217. // parse the list of bones vertices
  1218. if (TokenMatch(filePtr, "MESH_BONE_VERTEX_LIST", 21)) {
  1219. ParseLV4MeshBonesVertices(iNumVertices, mesh);
  1220. continue;
  1221. }
  1222. }
  1223. AI_ASE_HANDLE_SECTION("3", "*MESH_WEIGHTS");
  1224. }
  1225. }
  1226. // ------------------------------------------------------------------------------------------------
  1227. void Parser::ParseLV4MeshBones(unsigned int iNumBones, ASE::Mesh &mesh) {
  1228. AI_ASE_PARSER_INIT();
  1229. mesh.mBones.resize(iNumBones, Bone("UNNAMED"));
  1230. while (true) {
  1231. if ('*' == *filePtr) {
  1232. ++filePtr;
  1233. // Mesh bone with name ...
  1234. if (TokenMatch(filePtr, "MESH_BONE_NAME", 14)) {
  1235. // parse an index ...
  1236. if (SkipSpaces(&filePtr)) {
  1237. unsigned int iIndex = strtoul10(filePtr, &filePtr);
  1238. if (iIndex >= iNumBones) {
  1239. LogWarning("Bone index is out of bounds");
  1240. continue;
  1241. }
  1242. if (!ParseString(mesh.mBones[iIndex].mName, "*MESH_BONE_NAME"))
  1243. SkipToNextToken();
  1244. continue;
  1245. }
  1246. }
  1247. }
  1248. AI_ASE_HANDLE_SECTION("3", "*MESH_BONE_LIST");
  1249. }
  1250. }
  1251. // ------------------------------------------------------------------------------------------------
  1252. void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mesh) {
  1253. AI_ASE_PARSER_INIT();
  1254. mesh.mBoneVertices.resize(iNumVertices);
  1255. while (true) {
  1256. if ('*' == *filePtr) {
  1257. ++filePtr;
  1258. // Mesh bone vertex
  1259. if (TokenMatch(filePtr, "MESH_BONE_VERTEX", 16)) {
  1260. // read the vertex index
  1261. unsigned int iIndex = strtoul10(filePtr, &filePtr);
  1262. if (iIndex >= mesh.mPositions.size()) {
  1263. iIndex = (unsigned int)mesh.mPositions.size() - 1;
  1264. LogWarning("Bone vertex index is out of bounds. Using the largest valid "
  1265. "bone vertex index instead");
  1266. }
  1267. // --- ignored
  1268. ai_real afVert[3];
  1269. ParseLV4MeshFloatTriple(afVert);
  1270. std::pair<int, float> pairOut;
  1271. while (true) {
  1272. // first parse the bone index ...
  1273. if (!SkipSpaces(&filePtr)) break;
  1274. pairOut.first = strtoul10(filePtr, &filePtr);
  1275. // then parse the vertex weight
  1276. if (!SkipSpaces(&filePtr)) break;
  1277. filePtr = fast_atoreal_move<float>(filePtr, pairOut.second);
  1278. // -1 marks unused entries
  1279. if (-1 != pairOut.first) {
  1280. mesh.mBoneVertices[iIndex].mBoneWeights.push_back(pairOut);
  1281. }
  1282. }
  1283. continue;
  1284. }
  1285. }
  1286. AI_ASE_HANDLE_SECTION("4", "*MESH_BONE_VERTEX");
  1287. }
  1288. }
  1289. // ------------------------------------------------------------------------------------------------
  1290. void Parser::ParseLV3MeshVertexListBlock(
  1291. unsigned int iNumVertices, ASE::Mesh &mesh) {
  1292. AI_ASE_PARSER_INIT();
  1293. // allocate enough storage in the array
  1294. mesh.mPositions.resize(iNumVertices);
  1295. while (true) {
  1296. if ('*' == *filePtr) {
  1297. ++filePtr;
  1298. // Vertex entry
  1299. if (TokenMatch(filePtr, "MESH_VERTEX", 11)) {
  1300. aiVector3D vTemp;
  1301. unsigned int iIndex;
  1302. ParseLV4MeshFloatTriple(&vTemp.x, iIndex);
  1303. if (iIndex >= iNumVertices) {
  1304. LogWarning("Invalid vertex index. It will be ignored");
  1305. } else
  1306. mesh.mPositions[iIndex] = vTemp;
  1307. continue;
  1308. }
  1309. }
  1310. AI_ASE_HANDLE_SECTION("3", "*MESH_VERTEX_LIST");
  1311. }
  1312. }
  1313. // ------------------------------------------------------------------------------------------------
  1314. void Parser::ParseLV3MeshFaceListBlock(unsigned int iNumFaces, ASE::Mesh &mesh) {
  1315. AI_ASE_PARSER_INIT();
  1316. // allocate enough storage in the face array
  1317. mesh.mFaces.resize(iNumFaces);
  1318. while (true) {
  1319. if ('*' == *filePtr) {
  1320. ++filePtr;
  1321. // Face entry
  1322. if (TokenMatch(filePtr, "MESH_FACE", 9)) {
  1323. ASE::Face mFace;
  1324. ParseLV4MeshFace(mFace);
  1325. if (mFace.iFace >= iNumFaces) {
  1326. LogWarning("Face has an invalid index. It will be ignored");
  1327. } else
  1328. mesh.mFaces[mFace.iFace] = mFace;
  1329. continue;
  1330. }
  1331. }
  1332. AI_ASE_HANDLE_SECTION("3", "*MESH_FACE_LIST");
  1333. }
  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. }
  1363. // ------------------------------------------------------------------------------------------------
  1364. void Parser::ParseLV3MeshTFaceListBlock(unsigned int iNumFaces,
  1365. ASE::Mesh &mesh, unsigned int iChannel) {
  1366. AI_ASE_PARSER_INIT();
  1367. while (true) {
  1368. if ('*' == *filePtr) {
  1369. ++filePtr;
  1370. // Face entry
  1371. if (TokenMatch(filePtr, "MESH_TFACE", 10)) {
  1372. unsigned int aiValues[3];
  1373. unsigned int iIndex = 0;
  1374. ParseLV4MeshLongTriple(aiValues, iIndex);
  1375. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size()) {
  1376. LogWarning("UV-Face has an invalid index. It will be ignored");
  1377. } else {
  1378. // copy UV indices
  1379. mesh.mFaces[iIndex].amUVIndices[iChannel][0] = aiValues[0];
  1380. mesh.mFaces[iIndex].amUVIndices[iChannel][1] = aiValues[1];
  1381. mesh.mFaces[iIndex].amUVIndices[iChannel][2] = aiValues[2];
  1382. }
  1383. continue;
  1384. }
  1385. }
  1386. AI_ASE_HANDLE_SECTION("3", "*MESH_TFACE_LIST");
  1387. }
  1388. }
  1389. // ------------------------------------------------------------------------------------------------
  1390. void Parser::ParseLV3MappingChannel(unsigned int iChannel, ASE::Mesh &mesh) {
  1391. AI_ASE_PARSER_INIT();
  1392. unsigned int iNumTVertices = 0;
  1393. unsigned int iNumTFaces = 0;
  1394. while (true) {
  1395. if ('*' == *filePtr) {
  1396. ++filePtr;
  1397. // Number of texture coordinates in the mesh
  1398. if (TokenMatch(filePtr, "MESH_NUMTVERTEX", 15)) {
  1399. ParseLV4MeshLong(iNumTVertices);
  1400. continue;
  1401. }
  1402. // Number of UVWed faces in the mesh
  1403. if (TokenMatch(filePtr, "MESH_NUMTVFACES", 15)) {
  1404. ParseLV4MeshLong(iNumTFaces);
  1405. continue;
  1406. }
  1407. // mesh texture vertex list block
  1408. if (TokenMatch(filePtr, "MESH_TVERTLIST", 14)) {
  1409. ParseLV3MeshTListBlock(iNumTVertices, mesh, iChannel);
  1410. continue;
  1411. }
  1412. // mesh texture face block
  1413. if (TokenMatch(filePtr, "MESH_TFACELIST", 14)) {
  1414. ParseLV3MeshTFaceListBlock(iNumTFaces, mesh, iChannel);
  1415. continue;
  1416. }
  1417. }
  1418. AI_ASE_HANDLE_SECTION("3", "*MESH_MAPPING_CHANNEL");
  1419. }
  1420. }
  1421. // ------------------------------------------------------------------------------------------------
  1422. void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh &mesh) {
  1423. AI_ASE_PARSER_INIT();
  1424. // allocate enough storage in the array
  1425. mesh.mVertexColors.resize(iNumVertices);
  1426. while (true) {
  1427. if ('*' == *filePtr) {
  1428. ++filePtr;
  1429. // Vertex entry
  1430. if (TokenMatch(filePtr, "MESH_VERTCOL", 12)) {
  1431. aiColor4D vTemp;
  1432. vTemp.a = 1.0f;
  1433. unsigned int iIndex;
  1434. ParseLV4MeshFloatTriple(&vTemp.r, iIndex);
  1435. if (iIndex >= iNumVertices) {
  1436. LogWarning("Vertex color has an invalid index. It will be ignored");
  1437. } else
  1438. mesh.mVertexColors[iIndex] = vTemp;
  1439. continue;
  1440. }
  1441. }
  1442. AI_ASE_HANDLE_SECTION("3", "*MESH_CVERTEX_LIST");
  1443. }
  1444. }
  1445. // ------------------------------------------------------------------------------------------------
  1446. void Parser::ParseLV3MeshCFaceListBlock(unsigned int iNumFaces, ASE::Mesh &mesh) {
  1447. AI_ASE_PARSER_INIT();
  1448. while (true) {
  1449. if ('*' == *filePtr) {
  1450. ++filePtr;
  1451. // Face entry
  1452. if (TokenMatch(filePtr, "MESH_CFACE", 10)) {
  1453. unsigned int aiValues[3];
  1454. unsigned int iIndex = 0;
  1455. ParseLV4MeshLongTriple(aiValues, iIndex);
  1456. if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size()) {
  1457. LogWarning("UV-Face has an invalid index. It will be ignored");
  1458. } else {
  1459. // copy color indices
  1460. mesh.mFaces[iIndex].mColorIndices[0] = aiValues[0];
  1461. mesh.mFaces[iIndex].mColorIndices[1] = aiValues[1];
  1462. mesh.mFaces[iIndex].mColorIndices[2] = aiValues[2];
  1463. }
  1464. continue;
  1465. }
  1466. }
  1467. AI_ASE_HANDLE_SECTION("3", "*MESH_CFACE_LIST");
  1468. }
  1469. }
  1470. // ------------------------------------------------------------------------------------------------
  1471. void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) {
  1472. AI_ASE_PARSER_INIT();
  1473. // Allocate enough storage for the normals
  1474. sMesh.mNormals.resize(sMesh.mFaces.size() * 3, aiVector3D(0.f, 0.f, 0.f));
  1475. unsigned int index, faceIdx = UINT_MAX;
  1476. // FIXME: rewrite this and find out how to interpret the normals
  1477. // correctly. This is crap.
  1478. // Smooth the vertex and face normals together. The result
  1479. // will be edgy then, but otherwise everything would be soft ...
  1480. while (true) {
  1481. if ('*' == *filePtr) {
  1482. ++filePtr;
  1483. if (faceIdx != UINT_MAX && TokenMatch(filePtr, "MESH_VERTEXNORMAL", 17)) {
  1484. aiVector3D vNormal;
  1485. ParseLV4MeshFloatTriple(&vNormal.x, index);
  1486. if (faceIdx >= sMesh.mFaces.size())
  1487. continue;
  1488. // Make sure we assign it to the correct face
  1489. const ASE::Face &face = sMesh.mFaces[faceIdx];
  1490. if (index == face.mIndices[0])
  1491. index = 0;
  1492. else if (index == face.mIndices[1])
  1493. index = 1;
  1494. else if (index == face.mIndices[2])
  1495. index = 2;
  1496. else {
  1497. ASSIMP_LOG_ERROR("ASE: Invalid vertex index in MESH_VERTEXNORMAL section");
  1498. continue;
  1499. }
  1500. // We'll renormalize later
  1501. sMesh.mNormals[faceIdx * 3 + index] += vNormal;
  1502. continue;
  1503. }
  1504. if (TokenMatch(filePtr, "MESH_FACENORMAL", 15)) {
  1505. aiVector3D vNormal;
  1506. ParseLV4MeshFloatTriple(&vNormal.x, faceIdx);
  1507. if (faceIdx >= sMesh.mFaces.size()) {
  1508. ASSIMP_LOG_ERROR("ASE: Invalid vertex index in MESH_FACENORMAL section");
  1509. continue;
  1510. }
  1511. // We'll renormalize later
  1512. sMesh.mNormals[faceIdx * 3] += vNormal;
  1513. sMesh.mNormals[faceIdx * 3 + 1] += vNormal;
  1514. sMesh.mNormals[faceIdx * 3 + 2] += vNormal;
  1515. continue;
  1516. }
  1517. }
  1518. AI_ASE_HANDLE_SECTION("3", "*MESH_NORMALS");
  1519. }
  1520. }
  1521. // ------------------------------------------------------------------------------------------------
  1522. void Parser::ParseLV4MeshFace(ASE::Face &out) {
  1523. // skip spaces and tabs
  1524. if (!SkipSpaces(&filePtr)) {
  1525. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]");
  1526. SkipToNextToken();
  1527. return;
  1528. }
  1529. // parse the face index
  1530. out.iFace = strtoul10(filePtr, &filePtr);
  1531. // next character should be ':'
  1532. if (!SkipSpaces(&filePtr)) {
  1533. // FIX: there are some ASE files which haven't got : here ....
  1534. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]");
  1535. SkipToNextToken();
  1536. return;
  1537. }
  1538. // FIX: There are some ASE files which haven't got ':' here
  1539. if (':' == *filePtr) ++filePtr;
  1540. // Parse all mesh indices
  1541. for (unsigned int i = 0; i < 3; ++i) {
  1542. unsigned int iIndex = 0;
  1543. if (!SkipSpaces(&filePtr)) {
  1544. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL");
  1545. SkipToNextToken();
  1546. return;
  1547. }
  1548. switch (*filePtr) {
  1549. case 'A':
  1550. case 'a':
  1551. break;
  1552. case 'B':
  1553. case 'b':
  1554. iIndex = 1;
  1555. break;
  1556. case 'C':
  1557. case 'c':
  1558. iIndex = 2;
  1559. break;
  1560. default:
  1561. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
  1562. "A,B or C expected [#3]");
  1563. SkipToNextToken();
  1564. return;
  1565. };
  1566. ++filePtr;
  1567. // next character should be ':'
  1568. if (!SkipSpaces(&filePtr) || ':' != *filePtr) {
  1569. LogWarning("Unable to parse *MESH_FACE Element: "
  1570. "Unexpected EOL. \':\' expected [#2]");
  1571. SkipToNextToken();
  1572. return;
  1573. }
  1574. ++filePtr;
  1575. if (!SkipSpaces(&filePtr)) {
  1576. LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
  1577. "Vertex index ecpected [#4]");
  1578. SkipToNextToken();
  1579. return;
  1580. }
  1581. out.mIndices[iIndex] = strtoul10(filePtr, &filePtr);
  1582. }
  1583. // now we need to skip the AB, BC, CA blocks.
  1584. while (true) {
  1585. if ('*' == *filePtr) break;
  1586. if (IsLineEnd(*filePtr)) {
  1587. //iLineNumber++;
  1588. return;
  1589. }
  1590. filePtr++;
  1591. }
  1592. // parse the smoothing group of the face
  1593. if (TokenMatch(filePtr, "*MESH_SMOOTHING", 15)) {
  1594. if (!SkipSpaces(&filePtr)) {
  1595. LogWarning("Unable to parse *MESH_SMOOTHING Element: "
  1596. "Unexpected EOL. Smoothing group(s) expected [#5]");
  1597. SkipToNextToken();
  1598. return;
  1599. }
  1600. // Parse smoothing groups until we don't anymore see commas
  1601. // FIX: There needn't always be a value, sad but true
  1602. while (true) {
  1603. if (*filePtr < '9' && *filePtr >= '0') {
  1604. uint32_t value = strtoul10(filePtr, &filePtr);
  1605. if (value < 32) {
  1606. out.iSmoothGroup |= (1 << strtoul10(filePtr, &filePtr));
  1607. } else {
  1608. const std::string message = std::string("Unable to set smooth group, value with ") + ai_to_string(value) + std::string(" out of range");
  1609. LogWarning(message.c_str());
  1610. }
  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) {
  1623. break;
  1624. }
  1625. if (IsLineEnd(*filePtr)) {
  1626. return;
  1627. }
  1628. filePtr++;
  1629. }
  1630. if (TokenMatch(filePtr, "*MESH_MTLID", 11)) {
  1631. if (!SkipSpaces(&filePtr)) {
  1632. LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. "
  1633. "Material index expected [#6]");
  1634. SkipToNextToken();
  1635. return;
  1636. }
  1637. out.iMaterial = strtoul10(filePtr, &filePtr);
  1638. }
  1639. return;
  1640. }
  1641. // ------------------------------------------------------------------------------------------------
  1642. void Parser::ParseLV4MeshLongTriple(unsigned int *apOut) {
  1643. ai_assert(nullptr != apOut);
  1644. for (unsigned int i = 0; i < 3; ++i)
  1645. ParseLV4MeshLong(apOut[i]);
  1646. }
  1647. // ------------------------------------------------------------------------------------------------
  1648. void Parser::ParseLV4MeshLongTriple(unsigned int *apOut, unsigned int &rIndexOut) {
  1649. ai_assert(nullptr != apOut);
  1650. // parse the index
  1651. ParseLV4MeshLong(rIndexOut);
  1652. // parse the three others
  1653. ParseLV4MeshLongTriple(apOut);
  1654. }
  1655. // ------------------------------------------------------------------------------------------------
  1656. void Parser::ParseLV4MeshFloatTriple(ai_real *apOut, unsigned int &rIndexOut) {
  1657. ai_assert(nullptr != apOut);
  1658. // parse the index
  1659. ParseLV4MeshLong(rIndexOut);
  1660. // parse the three others
  1661. ParseLV4MeshFloatTriple(apOut);
  1662. }
  1663. // ------------------------------------------------------------------------------------------------
  1664. void Parser::ParseLV4MeshFloatTriple(ai_real *apOut) {
  1665. ai_assert(nullptr != apOut);
  1666. for (unsigned int i = 0; i < 3; ++i) {
  1667. ParseLV4MeshFloat(apOut[i]);
  1668. }
  1669. }
  1670. // ------------------------------------------------------------------------------------------------
  1671. void Parser::ParseLV4MeshFloat(ai_real &fOut) {
  1672. // skip spaces and tabs
  1673. if (!SkipSpaces(&filePtr)) {
  1674. // LOG
  1675. LogWarning("Unable to parse float: unexpected EOL [#1]");
  1676. fOut = 0.0;
  1677. ++iLineNumber;
  1678. return;
  1679. }
  1680. // parse the first float
  1681. filePtr = fast_atoreal_move<ai_real>(filePtr, fOut);
  1682. }
  1683. // ------------------------------------------------------------------------------------------------
  1684. void Parser::ParseLV4MeshLong(unsigned int &iOut) {
  1685. // Skip spaces and tabs
  1686. if (!SkipSpaces(&filePtr)) {
  1687. // LOG
  1688. LogWarning("Unable to parse long: unexpected EOL [#1]");
  1689. iOut = 0;
  1690. ++iLineNumber;
  1691. return;
  1692. }
  1693. // parse the value
  1694. iOut = strtoul10(filePtr, &filePtr);
  1695. }
  1696. #endif // ASSIMP_BUILD_NO_3DS_IMPORTER
  1697. #endif // !! ASSIMP_BUILD_NO_BASE_IMPORTER