Merge pull request #835 from robertliebo/VCS-1030/ObjMtlFilenameFallback

Vcs 1030/obj mtl filename fallback
pull/837/head
Kim Kulling 2016-03-22 20:35:41 +01:00
commit 6be4d82a6b
3 changed files with 16 additions and 7 deletions

View File

@ -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);

View File

@ -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.

View File

@ -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