ObjFileParser.cpp 19 KB

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