ObjFileParser.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2010, ASSIMP Development 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 Development 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. #include "AssimpPCH.h"
  35. #ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
  36. #include "ObjFileParser.h"
  37. #include "ObjFileMtlImporter.h"
  38. #include "ObjTools.h"
  39. #include "ObjFileData.h"
  40. #include "fast_atof.h"
  41. #include "../include/aiTypes.h"
  42. #include "DefaultIOSystem.h"
  43. namespace Assimp
  44. {
  45. // -------------------------------------------------------------------
  46. const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
  47. // fix: changed that to our standard default name
  48. // -------------------------------------------------------------------
  49. // Constructor with loaded data and directories.
  50. ObjFileParser::ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem *io ) :
  51. m_DataIt(Data.begin()),
  52. m_DataItEnd(Data.end()),
  53. m_pModel(NULL),
  54. m_uiLine(0),
  55. m_pIO( io )
  56. {
  57. std::fill_n(m_buffer,BUFFERSIZE,0);
  58. // Create the model instance to store all the data
  59. m_pModel = new ObjFile::Model();
  60. m_pModel->m_ModelName = strModelName;
  61. m_pModel->m_pDefaultMaterial = new ObjFile::Material();
  62. m_pModel->m_pDefaultMaterial->MaterialName.Set( DEFAULT_MATERIAL );
  63. m_pModel->m_MaterialLib.push_back( DEFAULT_MATERIAL );
  64. m_pModel->m_MaterialMap[ DEFAULT_MATERIAL ] = m_pModel->m_pDefaultMaterial;
  65. // Start parsing the file
  66. parseFile();
  67. }
  68. // -------------------------------------------------------------------
  69. // Destrcutor.
  70. ObjFileParser::~ObjFileParser()
  71. {
  72. delete m_pModel->m_pDefaultMaterial;
  73. m_pModel->m_pDefaultMaterial = NULL;
  74. delete m_pModel;
  75. m_pModel = NULL;
  76. }
  77. // -------------------------------------------------------------------
  78. // Returns a pointer to the model instance.
  79. ObjFile::Model *ObjFileParser::GetModel() const
  80. {
  81. return m_pModel;
  82. }
  83. // -------------------------------------------------------------------
  84. // File parsing method.
  85. void ObjFileParser::parseFile()
  86. {
  87. if (m_DataIt == m_DataItEnd)
  88. return;
  89. while (m_DataIt != m_DataItEnd)
  90. {
  91. switch (*m_DataIt)
  92. {
  93. case 'v': // Parse a vertex texture coordinate
  94. {
  95. ++m_DataIt;
  96. if (*m_DataIt == ' ')
  97. {
  98. // Read in vertex definition
  99. getVector3(m_pModel->m_Vertices);
  100. }
  101. else if (*m_DataIt == 't')
  102. {
  103. // Read in texture coordinate (2D)
  104. ++m_DataIt;
  105. getVector2(m_pModel->m_TextureCoord);
  106. }
  107. else if (*m_DataIt == 'n')
  108. {
  109. // Read in normal vector definition
  110. ++m_DataIt;
  111. getVector3( m_pModel->m_Normals );
  112. }
  113. }
  114. break;
  115. case 'f': // Parse a face
  116. {
  117. getFace();
  118. }
  119. break;
  120. case '#': // Parse a comment
  121. {
  122. getComment();
  123. }
  124. break;
  125. case 'u': // Parse a material desc. setter
  126. {
  127. getMaterialDesc();
  128. }
  129. break;
  130. case 'm': // Parse a material library
  131. {
  132. getMaterialLib();
  133. }
  134. break;
  135. case 'g': // Parse group name
  136. {
  137. getGroupName();
  138. }
  139. break;
  140. case 's': // Parse group number
  141. {
  142. getGroupNumber();
  143. }
  144. break;
  145. case 'o': // Parse object name
  146. {
  147. getObjectName();
  148. }
  149. break;
  150. default:
  151. {
  152. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  153. }
  154. break;
  155. }
  156. }
  157. }
  158. // -------------------------------------------------------------------
  159. // Copy the next word in a temporary buffer
  160. void ObjFileParser::copyNextWord(char *pBuffer, size_t length)
  161. {
  162. size_t index = 0;
  163. m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
  164. while ( m_DataIt != m_DataItEnd && !isSeparator(*m_DataIt) )
  165. {
  166. pBuffer[index] = *m_DataIt;
  167. index++;
  168. if (index == length-1)
  169. break;
  170. ++m_DataIt;
  171. }
  172. pBuffer[index] = '\0';
  173. }
  174. // -------------------------------------------------------------------
  175. // Copy the next line into a temporary buffer
  176. void ObjFileParser::copyNextLine(char *pBuffer, size_t length)
  177. {
  178. size_t index = 0;
  179. while (m_DataIt != m_DataItEnd)
  180. {
  181. if (*m_DataIt == '\n' || *m_DataIt == '\r' || index == length-1)
  182. break;
  183. pBuffer[ index ] = *m_DataIt;
  184. ++index;
  185. ++m_DataIt;
  186. }
  187. pBuffer[ index ] = '\0';
  188. }
  189. // -------------------------------------------------------------------
  190. // Get values for a new 3D vector instance
  191. void ObjFileParser::getVector3(std::vector<aiVector3D> &point3d_array)
  192. {
  193. float x, y, z;
  194. copyNextWord(m_buffer, BUFFERSIZE);
  195. x = (float) fast_atof(m_buffer);
  196. copyNextWord(m_buffer, BUFFERSIZE);
  197. y = (float) fast_atof(m_buffer);
  198. copyNextWord(m_buffer, BUFFERSIZE);
  199. z = (float) fast_atof(m_buffer);
  200. point3d_array.push_back( aiVector3D( x, y, z ) );
  201. //skipLine();
  202. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  203. }
  204. // -------------------------------------------------------------------
  205. // Get values for a new 2D vector instance
  206. void ObjFileParser::getVector2( std::vector<aiVector2D> &point2d_array )
  207. {
  208. float x, y;
  209. copyNextWord(m_buffer, BUFFERSIZE);
  210. x = (float) fast_atof(m_buffer);
  211. copyNextWord(m_buffer, BUFFERSIZE);
  212. y = (float) fast_atof(m_buffer);
  213. point2d_array.push_back(aiVector2D(x, y));
  214. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  215. }
  216. // -------------------------------------------------------------------
  217. // Get values for a new face instance
  218. void ObjFileParser::getFace()
  219. {
  220. copyNextLine(m_buffer, BUFFERSIZE);
  221. if (m_DataIt == m_DataItEnd)
  222. return;
  223. char *pPtr = m_buffer;
  224. char *pEnd = &pPtr[BUFFERSIZE];
  225. pPtr = getNextToken<char*>(pPtr, pEnd);
  226. if (pPtr == pEnd || *pPtr == '\0')
  227. return;
  228. std::vector<unsigned int> *pIndices = new std::vector<unsigned int>;
  229. std::vector<unsigned int> *pTexID = new std::vector<unsigned int>;
  230. std::vector<unsigned int> *pNormalID = new std::vector<unsigned int>;
  231. bool hasNormal = false;
  232. bool vt = (!m_pModel->m_TextureCoord.empty());
  233. bool vn = (!m_pModel->m_Normals.empty());
  234. int iStep = 0, iPos = 0;
  235. while (pPtr != pEnd)
  236. {
  237. iStep = 1;
  238. if (*pPtr == '\0')
  239. break;
  240. if (*pPtr=='\r' || *pPtr=='\n')
  241. break;
  242. if (*pPtr=='/' )
  243. {
  244. if (iPos == 0)
  245. {
  246. //if there are no texturecoordinates in the obj file but normals
  247. if (!vt && vn) {
  248. iPos = 1;
  249. iStep++;
  250. }
  251. }
  252. iPos++;
  253. }
  254. else if ( isSeparator(*pPtr) )
  255. {
  256. iPos = 0;
  257. }
  258. else
  259. {
  260. //OBJ USES 1 Base ARRAYS!!!!
  261. const int iVal = atoi( pPtr );
  262. int tmp = iVal;
  263. while ( ( tmp = tmp / 10 )!=0 )
  264. ++iStep;
  265. if ( iVal > 0 )
  266. {
  267. // Store parsed index
  268. if ( 0 == iPos )
  269. {
  270. pIndices->push_back( iVal-1 );
  271. }
  272. else if ( 1 == iPos )
  273. {
  274. pTexID->push_back( iVal-1 );
  275. }
  276. else if ( 2 == iPos )
  277. {
  278. pNormalID->push_back( iVal-1 );
  279. hasNormal = true;
  280. }
  281. else
  282. {
  283. reportErrorTokenInFace();
  284. }
  285. }
  286. }
  287. for ( int i=0; i<iStep; i++ )
  288. ++pPtr;
  289. }
  290. ObjFile::Face *face = new ObjFile::Face( pIndices, pNormalID, pTexID );
  291. // Set active material, if one set
  292. if (NULL != m_pModel->m_pCurrentMaterial)
  293. face->m_pMaterial = m_pModel->m_pCurrentMaterial;
  294. else
  295. face->m_pMaterial = m_pModel->m_pDefaultMaterial;
  296. // Create a default object, if nothing there
  297. if ( NULL == m_pModel->m_pCurrent )
  298. createObject( "defaultobject" );
  299. // Assign face to mesh
  300. if ( NULL == m_pModel->m_pCurrentMesh )
  301. {
  302. createMesh();
  303. }
  304. // Store the face
  305. m_pModel->m_pCurrentMesh->m_Faces.push_back( face );
  306. m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int)face->m_pVertices->size();
  307. m_pModel->m_pCurrentMesh->m_uiUVCoordinates[ 0 ] += (unsigned int)face->m_pTexturCoords[0].size();
  308. if( !m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal )
  309. {
  310. m_pModel->m_pCurrentMesh->m_hasNormals = true;
  311. }
  312. // Skip the rest of the line
  313. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  314. }
  315. // -------------------------------------------------------------------
  316. // Get values for a new material description
  317. void ObjFileParser::getMaterialDesc()
  318. {
  319. // Get next data for material data
  320. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  321. if (m_DataIt == m_DataItEnd)
  322. return;
  323. char *pStart = &(*m_DataIt);
  324. while ( m_DataIt != m_DataItEnd && !isSeparator(*m_DataIt) )
  325. ++m_DataIt;
  326. // Get name
  327. std::string strName(pStart, &(*m_DataIt));
  328. if ( strName.empty())
  329. return;
  330. // Search for material
  331. std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strName );
  332. if ( it == m_pModel->m_MaterialMap.end() )
  333. {
  334. // Not found, use default material
  335. m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
  336. DefaultLogger::get()->error("OBJ: failed to locate material " + strName + ", skipping");
  337. }
  338. else
  339. {
  340. // Found, using detected material
  341. m_pModel->m_pCurrentMaterial = (*it).second;
  342. if ( needsNewMesh( strName ))
  343. {
  344. createMesh();
  345. }
  346. m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strName );
  347. }
  348. // Skip rest of line
  349. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  350. }
  351. // -------------------------------------------------------------------
  352. // Get a comment, values will be skipped
  353. void ObjFileParser::getComment()
  354. {
  355. while (m_DataIt != m_DataItEnd)
  356. {
  357. if ( '\n' == (*m_DataIt))
  358. {
  359. ++m_DataIt;
  360. break;
  361. }
  362. else
  363. {
  364. ++m_DataIt;
  365. }
  366. }
  367. }
  368. // -------------------------------------------------------------------
  369. // Get material library from file.
  370. void ObjFileParser::getMaterialLib()
  371. {
  372. // Translate tuple
  373. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  374. if (m_DataIt == m_DataItEnd)
  375. return;
  376. char *pStart = &(*m_DataIt);
  377. while (m_DataIt != m_DataItEnd && !isNewLine(*m_DataIt))
  378. m_DataIt++;
  379. // Check for existence
  380. const std::string strMatName(pStart, &(*m_DataIt));
  381. IOStream *pFile = m_pIO->Open(strMatName);
  382. if (!pFile )
  383. {
  384. DefaultLogger::get()->error("OBJ: Unable to locate material file " + strMatName);
  385. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  386. return;
  387. }
  388. // Import material library data from file
  389. std::vector<char> buffer;
  390. BaseImporter::TextFileToBuffer(pFile,buffer);
  391. m_pIO->Close( pFile );
  392. // Importing the material library
  393. ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel );
  394. }
  395. // -------------------------------------------------------------------
  396. // Set a new material definition as the current material.
  397. void ObjFileParser::getNewMaterial()
  398. {
  399. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  400. m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
  401. if ( m_DataIt == m_DataItEnd )
  402. return;
  403. char *pStart = &(*m_DataIt);
  404. std::string strMat( pStart, *m_DataIt );
  405. while ( m_DataIt != m_DataItEnd && isSeparator( *m_DataIt ) )
  406. m_DataIt++;
  407. std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strMat );
  408. if ( it == m_pModel->m_MaterialMap.end() )
  409. {
  410. // Show a warning, if material was not found
  411. DefaultLogger::get()->warn("OBJ: Unsupported material requested: " + strMat);
  412. m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
  413. }
  414. else
  415. {
  416. // Set new material
  417. if ( needsNewMesh( strMat ) )
  418. {
  419. createMesh();
  420. }
  421. m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strMat );
  422. }
  423. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  424. }
  425. // -------------------------------------------------------------------
  426. int ObjFileParser::getMaterialIndex( const std::string &strMaterialName )
  427. {
  428. int mat_index = -1;
  429. if ( strMaterialName.empty() )
  430. return mat_index;
  431. for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index)
  432. {
  433. if ( strMaterialName == m_pModel->m_MaterialLib[ index ])
  434. {
  435. mat_index = (int)index;
  436. break;
  437. }
  438. }
  439. return mat_index;
  440. }
  441. // -------------------------------------------------------------------
  442. // Getter for a group name.
  443. void ObjFileParser::getGroupName()
  444. {
  445. // Get next word from data buffer
  446. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  447. m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
  448. if ( isEndOfBuffer( m_DataIt, m_DataItEnd ) )
  449. return;
  450. // Store groupname in group library
  451. char *pStart = &(*m_DataIt);
  452. while ( m_DataIt != m_DataItEnd && !isSeparator(*m_DataIt) )
  453. m_DataIt++;
  454. std::string strGroupName(pStart, &(*m_DataIt));
  455. // Change active group, if necessary
  456. if ( m_pModel->m_strActiveGroup != strGroupName )
  457. {
  458. // Search for already existing entry
  459. ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(strGroupName);
  460. // We are mapping groups into the object structure
  461. createObject( strGroupName );
  462. // New group name, creating a new entry
  463. if (it == m_pModel->m_Groups.end())
  464. {
  465. std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
  466. m_pModel->m_Groups[ strGroupName ] = pFaceIDArray;
  467. m_pModel->m_pGroupFaceIDs = (pFaceIDArray);
  468. }
  469. else
  470. {
  471. m_pModel->m_pGroupFaceIDs = (*it).second;
  472. }
  473. m_pModel->m_strActiveGroup = strGroupName;
  474. }
  475. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  476. }
  477. // -------------------------------------------------------------------
  478. // Not supported
  479. void ObjFileParser::getGroupNumber()
  480. {
  481. // Not used
  482. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  483. }
  484. // -------------------------------------------------------------------
  485. // Stores values for a new object instance, name will be used to
  486. // identify it.
  487. void ObjFileParser::getObjectName()
  488. {
  489. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  490. if (m_DataIt == m_DataItEnd)
  491. return;
  492. char *pStart = &(*m_DataIt);
  493. while ( m_DataIt != m_DataItEnd && !isSeparator( *m_DataIt ) )
  494. ++m_DataIt;
  495. std::string strObjectName(pStart, &(*m_DataIt));
  496. if (!strObjectName.empty())
  497. {
  498. // Reset current object
  499. m_pModel->m_pCurrent = NULL;
  500. // Search for actual object
  501. for (std::vector<ObjFile::Object*>::const_iterator it = m_pModel->m_Objects.begin();
  502. it != m_pModel->m_Objects.end();
  503. ++it)
  504. {
  505. if ((*it)->m_strObjName == strObjectName)
  506. {
  507. m_pModel->m_pCurrent = *it;
  508. break;
  509. }
  510. }
  511. // Allocate a new object, if current one was not found before
  512. if ( NULL == m_pModel->m_pCurrent )
  513. createObject(strObjectName);
  514. }
  515. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  516. }
  517. // -------------------------------------------------------------------
  518. // Creates a new object instance
  519. void ObjFileParser::createObject(const std::string &strObjectName)
  520. {
  521. ai_assert( NULL != m_pModel );
  522. //ai_assert( !strObjectName.empty() );
  523. m_pModel->m_pCurrent = new ObjFile::Object;
  524. m_pModel->m_pCurrent->m_strObjName = strObjectName;
  525. m_pModel->m_Objects.push_back( m_pModel->m_pCurrent );
  526. createMesh();
  527. if( m_pModel->m_pCurrentMaterial )
  528. {
  529. m_pModel->m_pCurrentMesh->m_uiMaterialIndex =
  530. getMaterialIndex( m_pModel->m_pCurrentMaterial->MaterialName.data );
  531. m_pModel->m_pCurrentMesh->m_pMaterial = m_pModel->m_pCurrentMaterial;
  532. }
  533. }
  534. // -------------------------------------------------------------------
  535. // Creates a new mesh
  536. void ObjFileParser::createMesh()
  537. {
  538. ai_assert( NULL != m_pModel );
  539. m_pModel->m_pCurrentMesh = new ObjFile::Mesh;
  540. m_pModel->m_Meshes.push_back( m_pModel->m_pCurrentMesh );
  541. unsigned int meshId = m_pModel->m_Meshes.size()-1;
  542. if ( NULL != m_pModel->m_pCurrent )
  543. {
  544. m_pModel->m_pCurrent->m_Meshes.push_back( meshId );
  545. }
  546. else
  547. {
  548. DefaultLogger::get()->error("OBJ: No object detected to attach a new mesh instance.");
  549. }
  550. }
  551. // -------------------------------------------------------------------
  552. // Returns true, if a new mesh must be created.
  553. bool ObjFileParser::needsNewMesh( const std::string &rMaterialName )
  554. {
  555. if(m_pModel->m_pCurrentMesh == 0)
  556. {
  557. // No mesh data yet
  558. return true;
  559. }
  560. bool newMat = false;
  561. int matIdx = getMaterialIndex( rMaterialName );
  562. int curMatIdx = m_pModel->m_pCurrentMesh->m_uiMaterialIndex;
  563. if ( curMatIdx != int(ObjFile::Mesh::NoMaterial) || curMatIdx != matIdx )
  564. {
  565. // New material -> only one material per mesh, so we need to create a new
  566. // material
  567. newMat = true;
  568. }
  569. return newMat;
  570. }
  571. // -------------------------------------------------------------------
  572. // Shows an error in parsing process.
  573. void ObjFileParser::reportErrorTokenInFace()
  574. {
  575. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  576. DefaultLogger::get()->error("OBJ: Not supported token in face description detected");
  577. }
  578. // -------------------------------------------------------------------
  579. } // Namespace Assimp
  580. #endif // !! ASSIMP_BUILD_NO_OBJ_IMPORTER