ASEParser.cpp 68 KB

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