ASEParser.cpp 69 KB

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