Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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