From abb3e6b8544a5a9ff1f410e0719909fd9f5a36ce Mon Sep 17 00:00:00 2001 From: Robert Liebo Date: Tue, 22 Mar 2016 18:38:28 +0100 Subject: [PATCH 1/2] [VCS-1030] fallback for non-found .mtl file: try file name of original obj with just the file extension replaced by "mtl" --- code/ObjFileImporter.cpp | 2 +- code/ObjFileParser.cpp | 16 +++++++++++----- code/ObjFileParser.h | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index f5c727ec9..9bc2fc506 100644 --- a/code/ObjFileImporter.cpp +++ b/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); diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index f23cea879..4ef544f28 100644 --- a/code/ObjFileParser.cpp +++ b/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 &data,const std::string &modelName, IOSystem *io, ProgressHandler* progress ) : +ObjFileParser::ObjFileParser(std::vector &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,14 @@ void ObjFileParser::getMaterialLib() IOStream *pFile = m_pIO->Open( absName ); if (!pFile ) { - DefaultLogger::get()->error( "OBJ: Unable to locate material file " + strMatName ); - m_DataIt = skipLine( 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"; + pFile = m_pIO->Open(strMatFallbackName); + if (!pFile) { + DefaultLogger::get()->error("OBJ: Unable to locate material fallback file " + strMatName); + m_DataIt = skipLine(m_DataIt, m_DataItEnd, m_uiLine); + return; + } } // Import material library data from file. diff --git a/code/ObjFileParser.h b/code/ObjFileParser.h index e16de49a8..7170f0d50 100644 --- a/code/ObjFileParser.h +++ b/code/ObjFileParser.h @@ -72,7 +72,7 @@ public: public: /// \brief Constructor with data array. - ObjFileParser(std::vector &Data,const std::string &strModelName, IOSystem* io, ProgressHandler* progress); + ObjFileParser(std::vector &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 From 124fc9ae27a8e2d0d60f39b005a3cce8f73fab46 Mon Sep 17 00:00:00 2001 From: Robert Liebo Date: Tue, 22 Mar 2016 18:39:52 +0100 Subject: [PATCH 2/2] [VCS-1030] add log info about .mtl fallback --- code/ObjFileParser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 4ef544f28..a6f515aba 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -576,9 +576,10 @@ void ObjFileParser::getMaterialLib() if (!pFile ) { 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 material fallback file " + strMatName); + DefaultLogger::get()->error("OBJ: Unable to locate fallback material file " + strMatName); m_DataIt = skipLine(m_DataIt, m_DataItEnd, m_uiLine); return; }