ObjFileParser.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. {
  294. DefaultLogger::get()->error("Obj: Ignoring empty face");
  295. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  296. return;
  297. }
  298. ObjFile::Face *face = new ObjFile::Face( pIndices, pNormalID, pTexID, type );
  299. // Set active material, if one set
  300. if (NULL != m_pModel->m_pCurrentMaterial)
  301. face->m_pMaterial = m_pModel->m_pCurrentMaterial;
  302. else
  303. face->m_pMaterial = m_pModel->m_pDefaultMaterial;
  304. // Create a default object, if nothing is there
  305. if ( NULL == m_pModel->m_pCurrent )
  306. createObject( "defaultobject" );
  307. // Assign face to mesh
  308. if ( NULL == m_pModel->m_pCurrentMesh )
  309. {
  310. createMesh();
  311. }
  312. // Store the face
  313. m_pModel->m_pCurrentMesh->m_Faces.push_back( face );
  314. m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int)face->m_pVertices->size();
  315. m_pModel->m_pCurrentMesh->m_uiUVCoordinates[ 0 ] += (unsigned int)face->m_pTexturCoords[0].size();
  316. if( !m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal )
  317. {
  318. m_pModel->m_pCurrentMesh->m_hasNormals = true;
  319. }
  320. // Skip the rest of the line
  321. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  322. }
  323. // -------------------------------------------------------------------
  324. // Get values for a new material description
  325. void ObjFileParser::getMaterialDesc()
  326. {
  327. // Get next data for material data
  328. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  329. if (m_DataIt == m_DataItEnd)
  330. return;
  331. char *pStart = &(*m_DataIt);
  332. while ( m_DataIt != m_DataItEnd && !isSeparator(*m_DataIt) )
  333. ++m_DataIt;
  334. // Get name
  335. std::string strName(pStart, &(*m_DataIt));
  336. if ( strName.empty())
  337. return;
  338. // Search for material
  339. std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strName );
  340. if ( it == m_pModel->m_MaterialMap.end() )
  341. {
  342. // Not found, use default material
  343. m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
  344. DefaultLogger::get()->error("OBJ: failed to locate material " + strName + ", skipping");
  345. }
  346. else
  347. {
  348. // Found, using detected material
  349. m_pModel->m_pCurrentMaterial = (*it).second;
  350. if ( needsNewMesh( strName ))
  351. {
  352. createMesh();
  353. }
  354. m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strName );
  355. }
  356. // Skip rest of line
  357. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  358. }
  359. // -------------------------------------------------------------------
  360. // Get a comment, values will be skipped
  361. void ObjFileParser::getComment()
  362. {
  363. while (m_DataIt != m_DataItEnd)
  364. {
  365. if ( '\n' == (*m_DataIt))
  366. {
  367. ++m_DataIt;
  368. break;
  369. }
  370. else
  371. {
  372. ++m_DataIt;
  373. }
  374. }
  375. }
  376. // -------------------------------------------------------------------
  377. // Get material library from file.
  378. void ObjFileParser::getMaterialLib()
  379. {
  380. // Translate tuple
  381. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  382. if (m_DataIt == m_DataItEnd)
  383. return;
  384. char *pStart = &(*m_DataIt);
  385. while (m_DataIt != m_DataItEnd && !isNewLine(*m_DataIt))
  386. m_DataIt++;
  387. // Check for existence
  388. const std::string strMatName(pStart, &(*m_DataIt));
  389. IOStream *pFile = m_pIO->Open(strMatName);
  390. if (!pFile )
  391. {
  392. DefaultLogger::get()->error("OBJ: Unable to locate material file " + strMatName);
  393. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  394. return;
  395. }
  396. // Import material library data from file
  397. std::vector<char> buffer;
  398. BaseImporter::TextFileToBuffer(pFile,buffer);
  399. m_pIO->Close( pFile );
  400. // Importing the material library
  401. ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel );
  402. }
  403. // -------------------------------------------------------------------
  404. // Set a new material definition as the current material.
  405. void ObjFileParser::getNewMaterial()
  406. {
  407. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  408. m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
  409. if ( m_DataIt == m_DataItEnd )
  410. return;
  411. char *pStart = &(*m_DataIt);
  412. std::string strMat( pStart, *m_DataIt );
  413. while ( m_DataIt != m_DataItEnd && isSeparator( *m_DataIt ) )
  414. m_DataIt++;
  415. std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strMat );
  416. if ( it == m_pModel->m_MaterialMap.end() )
  417. {
  418. // Show a warning, if material was not found
  419. DefaultLogger::get()->warn("OBJ: Unsupported material requested: " + strMat);
  420. m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial;
  421. }
  422. else
  423. {
  424. // Set new material
  425. if ( needsNewMesh( strMat ) )
  426. {
  427. createMesh();
  428. }
  429. m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strMat );
  430. }
  431. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  432. }
  433. // -------------------------------------------------------------------
  434. int ObjFileParser::getMaterialIndex( const std::string &strMaterialName )
  435. {
  436. int mat_index = -1;
  437. if ( strMaterialName.empty() )
  438. return mat_index;
  439. for (size_t index = 0; index < m_pModel->m_MaterialLib.size(); ++index)
  440. {
  441. if ( strMaterialName == m_pModel->m_MaterialLib[ index ])
  442. {
  443. mat_index = (int)index;
  444. break;
  445. }
  446. }
  447. return mat_index;
  448. }
  449. // -------------------------------------------------------------------
  450. // Getter for a group name.
  451. void ObjFileParser::getGroupName()
  452. {
  453. // Get next word from data buffer
  454. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  455. m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
  456. if ( isEndOfBuffer( m_DataIt, m_DataItEnd ) )
  457. return;
  458. // Store the group name in the group library
  459. char *pStart = &(*m_DataIt);
  460. while ( m_DataIt != m_DataItEnd && !isSeparator(*m_DataIt) )
  461. m_DataIt++;
  462. std::string strGroupName( pStart, &(*m_DataIt) );
  463. // Change active group, if necessary
  464. if ( m_pModel->m_strActiveGroup != strGroupName )
  465. {
  466. // Search for already existing entry
  467. ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(strGroupName);
  468. // We are mapping groups into the object structure
  469. createObject( strGroupName );
  470. // New group name, creating a new entry
  471. if (it == m_pModel->m_Groups.end())
  472. {
  473. std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
  474. m_pModel->m_Groups[ strGroupName ] = pFaceIDArray;
  475. m_pModel->m_pGroupFaceIDs = (pFaceIDArray);
  476. }
  477. else
  478. {
  479. m_pModel->m_pGroupFaceIDs = (*it).second;
  480. }
  481. m_pModel->m_strActiveGroup = strGroupName;
  482. }
  483. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  484. }
  485. // -------------------------------------------------------------------
  486. // Not supported
  487. void ObjFileParser::getGroupNumber()
  488. {
  489. // Not used
  490. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  491. }
  492. // -------------------------------------------------------------------
  493. // Stores values for a new object instance, name will be used to
  494. // identify it.
  495. void ObjFileParser::getObjectName()
  496. {
  497. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  498. if (m_DataIt == m_DataItEnd)
  499. return;
  500. char *pStart = &(*m_DataIt);
  501. while ( m_DataIt != m_DataItEnd && !isSeparator( *m_DataIt ) )
  502. ++m_DataIt;
  503. std::string strObjectName(pStart, &(*m_DataIt));
  504. if (!strObjectName.empty())
  505. {
  506. // Reset current object
  507. m_pModel->m_pCurrent = NULL;
  508. // Search for actual object
  509. for (std::vector<ObjFile::Object*>::const_iterator it = m_pModel->m_Objects.begin();
  510. it != m_pModel->m_Objects.end();
  511. ++it)
  512. {
  513. if ((*it)->m_strObjName == strObjectName)
  514. {
  515. m_pModel->m_pCurrent = *it;
  516. break;
  517. }
  518. }
  519. // Allocate a new object, if current one was not found before
  520. if ( NULL == m_pModel->m_pCurrent )
  521. createObject(strObjectName);
  522. }
  523. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  524. }
  525. // -------------------------------------------------------------------
  526. // Creates a new object instance
  527. void ObjFileParser::createObject(const std::string &strObjectName)
  528. {
  529. ai_assert( NULL != m_pModel );
  530. //ai_assert( !strObjectName.empty() );
  531. m_pModel->m_pCurrent = new ObjFile::Object;
  532. m_pModel->m_pCurrent->m_strObjName = strObjectName;
  533. m_pModel->m_Objects.push_back( m_pModel->m_pCurrent );
  534. createMesh();
  535. if( m_pModel->m_pCurrentMaterial )
  536. {
  537. m_pModel->m_pCurrentMesh->m_uiMaterialIndex =
  538. getMaterialIndex( m_pModel->m_pCurrentMaterial->MaterialName.data );
  539. m_pModel->m_pCurrentMesh->m_pMaterial = m_pModel->m_pCurrentMaterial;
  540. }
  541. }
  542. // -------------------------------------------------------------------
  543. // Creates a new mesh
  544. void ObjFileParser::createMesh()
  545. {
  546. ai_assert( NULL != m_pModel );
  547. m_pModel->m_pCurrentMesh = new ObjFile::Mesh;
  548. m_pModel->m_Meshes.push_back( m_pModel->m_pCurrentMesh );
  549. unsigned int meshId = m_pModel->m_Meshes.size()-1;
  550. if ( NULL != m_pModel->m_pCurrent )
  551. {
  552. m_pModel->m_pCurrent->m_Meshes.push_back( meshId );
  553. }
  554. else
  555. {
  556. DefaultLogger::get()->error("OBJ: No object detected to attach a new mesh instance.");
  557. }
  558. }
  559. // -------------------------------------------------------------------
  560. // Returns true, if a new mesh must be created.
  561. bool ObjFileParser::needsNewMesh( const std::string &rMaterialName )
  562. {
  563. if(m_pModel->m_pCurrentMesh == 0)
  564. {
  565. // No mesh data yet
  566. return true;
  567. }
  568. bool newMat = false;
  569. int matIdx = getMaterialIndex( rMaterialName );
  570. int curMatIdx = m_pModel->m_pCurrentMesh->m_uiMaterialIndex;
  571. if ( curMatIdx != int(ObjFile::Mesh::NoMaterial) || curMatIdx != matIdx )
  572. {
  573. // New material -> only one material per mesh, so we need to create a new
  574. // material
  575. newMat = true;
  576. }
  577. return newMat;
  578. }
  579. // -------------------------------------------------------------------
  580. // Shows an error in parsing process.
  581. void ObjFileParser::reportErrorTokenInFace()
  582. {
  583. m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  584. DefaultLogger::get()->error("OBJ: Not supported token in face description detected");
  585. }
  586. // -------------------------------------------------------------------
  587. } // Namespace Assimp
  588. #endif // !! ASSIMP_BUILD_NO_OBJ_IMPORTER