浏览代码

Merge pull request #672 from Ang3lus/Fix-mtl-realtive-path

Properly build path to the mtl file when loading obj
Alexander Gessler 10 年之前
父节点
当前提交
1b3381d03d
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 1 1
      code/ObjFileImporter.cpp
  2. 5 2
      code/ObjFileParser.cpp

+ 1 - 1
code/ObjFileImporter.cpp

@@ -138,7 +138,7 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
     if ( pos != std::string::npos ) {
         modelName = pFile.substr(pos+1, pFile.size() - pos - 1);
         folderName = pFile.substr( 0, pos );
-        if ( folderName.empty() ) {
+        if ( !folderName.empty() ) {
             pIOHandler->PushDirectory( folderName );
         }
     } else {

+ 5 - 2
code/ObjFileParser.cpp

@@ -414,7 +414,7 @@ void ObjFileParser::getFace(aiPrimitiveType type)
 
     if ( pIndices->empty() ) {
         DefaultLogger::get()->error("Obj: Ignoring empty face");
-        // skip line and clean up 
+        // skip line and clean up
         m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
         delete pNormalID;
         delete pTexID;
@@ -539,7 +539,10 @@ void ObjFileParser::getMaterialLib()
     const std::string strMatName(pStart, &(*m_DataIt));
     std::string absName;
     if ( m_pIO->StackSize() > 0 ) {
-        const std::string &path = m_pIO->CurrentDirectory();
+        std::string path = m_pIO->CurrentDirectory();
+        if ( '/' != *path.rbegin() ) {
+          path += '/';
+        }
         absName = path + strMatName;
     } else {
         absName = strMatName;