Merge pull request #835 from robertliebo/VCS-1030/ObjMtlFilenameFallback
Vcs 1030/obj mtl filename fallbackpull/837/head
commit
6be4d82a6b
|
@ -177,7 +177,7 @@ void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene,
|
||||||
m_progress->UpdateFileRead(1, 3);
|
m_progress->UpdateFileRead(1, 3);
|
||||||
|
|
||||||
// parse the file into a temporary representation
|
// 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
|
// And create the proper return structures out of it
|
||||||
CreateDataFromImport(parser.GetModel(), pScene);
|
CreateDataFromImport(parser.GetModel(), pScene);
|
||||||
|
|
|
@ -61,13 +61,14 @@ const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Constructor with loaded data and directories.
|
// 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_DataIt(data.begin()),
|
||||||
m_DataItEnd(data.end()),
|
m_DataItEnd(data.end()),
|
||||||
m_pModel(NULL),
|
m_pModel(NULL),
|
||||||
m_uiLine(0),
|
m_uiLine(0),
|
||||||
m_pIO( io ),
|
m_pIO( io ),
|
||||||
m_progress(progress)
|
m_progress(progress),
|
||||||
|
m_originalObjFileName(originalObjFileName)
|
||||||
{
|
{
|
||||||
std::fill_n(m_buffer,Buffersize,0);
|
std::fill_n(m_buffer,Buffersize,0);
|
||||||
|
|
||||||
|
@ -573,9 +574,15 @@ void ObjFileParser::getMaterialLib()
|
||||||
IOStream *pFile = m_pIO->Open( absName );
|
IOStream *pFile = m_pIO->Open( absName );
|
||||||
|
|
||||||
if (!pFile ) {
|
if (!pFile ) {
|
||||||
DefaultLogger::get()->error( "OBJ: Unable to locate material file " + strMatName );
|
DefaultLogger::get()->error("OBJ: Unable to locate material file " + strMatName);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl";
|
||||||
return;
|
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.
|
// Import material library data from file.
|
||||||
|
|
|
@ -72,7 +72,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \brief Constructor with data array.
|
/// \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
|
/// \brief Destructor
|
||||||
~ObjFileParser();
|
~ObjFileParser();
|
||||||
/// \brief Model getter.
|
/// \brief Model getter.
|
||||||
|
@ -143,6 +143,8 @@ private:
|
||||||
//! Pointer to progress handler
|
//! Pointer to progress handler
|
||||||
ProgressHandler* m_progress;
|
ProgressHandler* m_progress;
|
||||||
/// Path to the current model
|
/// Path to the current model
|
||||||
|
// name of the obj file where the buffer comes from
|
||||||
|
const std::string& m_originalObjFileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Namespace Assimp
|
} // Namespace Assimp
|
||||||
|
|
Loading…
Reference in New Issue