Browse Source

Merge branch 'master' of https://github.com/assimp/assimp

Kim Kulling 9 years ago
parent
commit
42d29b1bfe
3 changed files with 16 additions and 7 deletions
  1. 1 1
      code/ObjFileImporter.cpp
  2. 12 5
      code/ObjFileParser.cpp
  3. 3 1
      code/ObjFileParser.h

+ 1 - 1
code/ObjFileImporter.cpp

@@ -177,7 +177,7 @@ void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene,
     m_progress->UpdateFileRead(1, 3);
 
     // parse the file into a temporary representation
-    ObjFileParser parser(m_Buffer, modelName, pIOHandler, m_progress);
+    ObjFileParser parser(m_Buffer, modelName, pIOHandler, m_progress, file);
 
     // And create the proper return structures out of it
     CreateDataFromImport(parser.GetModel(), pScene);

+ 12 - 5
code/ObjFileParser.cpp

@@ -61,13 +61,14 @@ const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
 
 // -------------------------------------------------------------------
 //  Constructor with loaded data and directories.
-ObjFileParser::ObjFileParser(std::vector<char> &data,const std::string &modelName, IOSystem *io, ProgressHandler* progress ) :
+ObjFileParser::ObjFileParser(std::vector<char> &data, const std::string &modelName, IOSystem *io, ProgressHandler* progress, const std::string &originalObjFileName) :
     m_DataIt(data.begin()),
     m_DataItEnd(data.end()),
     m_pModel(NULL),
     m_uiLine(0),
     m_pIO( io ),
-    m_progress(progress)
+    m_progress(progress),
+    m_originalObjFileName(originalObjFileName)
 {
     std::fill_n(m_buffer,Buffersize,0);
 
@@ -573,9 +574,15 @@ void ObjFileParser::getMaterialLib()
     IOStream *pFile = m_pIO->Open( absName );
 
     if (!pFile ) {
-        DefaultLogger::get()->error( "OBJ: Unable to locate material file " + strMatName );
-        m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
-        return;
+        DefaultLogger::get()->error("OBJ: Unable to locate material file " + strMatName);
+        std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl";
+        DefaultLogger::get()->info("OBJ: Opening fallback material file " + strMatFallbackName);
+        pFile = m_pIO->Open(strMatFallbackName);
+        if (!pFile) {
+            DefaultLogger::get()->error("OBJ: Unable to locate fallback material file " + strMatName);
+            m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
+            return;
+        }
     }
 
     // Import material library data from file.

+ 3 - 1
code/ObjFileParser.h

@@ -72,7 +72,7 @@ public:
 
 public:
     /// \brief  Constructor with data array.
-    ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io, ProgressHandler* progress);
+    ObjFileParser(std::vector<char> &Data, const std::string &strModelName, IOSystem* io, ProgressHandler* progress, const std::string &originalObjFileName);
     /// \brief  Destructor
     ~ObjFileParser();
     /// \brief  Model getter.
@@ -143,6 +143,8 @@ private:
     //! Pointer to progress handler
     ProgressHandler* m_progress;
     /// Path to the current model
+    // name of the obj file where the buffer comes from
+    const std::string& m_originalObjFileName;
 };
 
 }   // Namespace Assimp