FIX: ObjLoader failed to locate material files if the input path contained 'wrong' path delimiters.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@471 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/1/head
parent
3435623463
commit
64168ba975
|
@ -104,11 +104,9 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||||
TextFileToBuffer(file.get(),m_Buffer);
|
TextFileToBuffer(file.get(),m_Buffer);
|
||||||
|
|
||||||
//
|
//
|
||||||
std::string strDirectory( 1, io.getOsSeparator() ), strModelName;
|
std::string strModelName;
|
||||||
std::string::size_type pos = pFile.find_last_of( io.getOsSeparator() );
|
std::string::size_type pos = pFile.find_last_of( "\\/" );
|
||||||
if ( pos != std::string::npos )
|
if ( pos != std::string::npos ) {
|
||||||
{
|
|
||||||
strDirectory = pFile.substr(0, pos);
|
|
||||||
strModelName = pFile.substr(pos+1, pFile.size() - pos - 1);
|
strModelName = pFile.substr(pos+1, pFile.size() - pos - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -117,7 +115,7 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the file into a temporary representation
|
// parse the file into a temporary representation
|
||||||
ObjFileParser parser(m_Buffer, strDirectory, strModelName, pIOHandler);
|
ObjFileParser parser(m_Buffer, strModelName, pIOHandler);
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
|
@ -57,10 +57,7 @@ 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,
|
ObjFileParser::ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* _io) :
|
||||||
const std::string &strAbsPath,
|
|
||||||
const std::string &strModelName, IOSystem* _io) :
|
|
||||||
m_strAbsPath(strAbsPath),
|
|
||||||
m_DataIt(Data.begin()),
|
m_DataIt(Data.begin()),
|
||||||
m_DataItEnd(Data.end()),
|
m_DataItEnd(Data.end()),
|
||||||
m_pModel(NULL),
|
m_pModel(NULL),
|
||||||
|
@ -440,13 +437,12 @@ void ObjFileParser::getMaterialLib()
|
||||||
m_DataIt++;
|
m_DataIt++;
|
||||||
|
|
||||||
// Check for existence
|
// Check for existence
|
||||||
std::string strMatName(pStart, &(*m_DataIt));
|
const std::string strMatName(pStart, &(*m_DataIt));
|
||||||
std::string absName = m_strAbsPath + io->getOsSeparator() + strMatName;
|
IOStream *pFile = io->Open(strMatName);
|
||||||
IOStream *pFile = io->Open(absName.c_str());
|
|
||||||
|
|
||||||
if (!pFile )
|
if (!pFile )
|
||||||
{
|
{
|
||||||
DefaultLogger::get()->error("OBJ: Unable to locate material file " + absName);
|
DefaultLogger::get()->error("OBJ: Unable to locate material file " + strMatName);
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -457,7 +453,7 @@ void ObjFileParser::getMaterialLib()
|
||||||
io->Close( pFile );
|
io->Close( pFile );
|
||||||
|
|
||||||
// Importing the material library
|
// Importing the material library
|
||||||
ObjFileMtlImporter mtlImporter( buffer, absName, m_pModel );
|
ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel );
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
|
@ -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 &strAbsPath, const std::string &strModelName, IOSystem* io);
|
ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io);
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
~ObjFileParser();
|
~ObjFileParser();
|
||||||
/// \brief Model getter.
|
/// \brief Model getter.
|
||||||
|
@ -114,8 +114,6 @@ private:
|
||||||
private:
|
private:
|
||||||
/// Default material name
|
/// Default material name
|
||||||
static const std::string DEFAULT_MATERIAL;/* = "defaultmaterial";*/
|
static const std::string DEFAULT_MATERIAL;/* = "defaultmaterial";*/
|
||||||
//! Absolute filepath to model
|
|
||||||
std::string m_strAbsPath;
|
|
||||||
//! Iterator to current position in buffer
|
//! Iterator to current position in buffer
|
||||||
DataArrayIt m_DataIt;
|
DataArrayIt m_DataIt;
|
||||||
//! Iterator to end position of buffer
|
//! Iterator to end position of buffer
|
||||||
|
|
Loading…
Reference in New Issue