ObjFileParser.cpp 18 KB

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