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-9d2fd5bffc1f
pull/1/head
aramis_acg 2009-08-24 08:46:04 +00:00
parent 3435623463
commit 64168ba975
3 changed files with 10 additions and 18 deletions

View File

@ -104,11 +104,9 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
TextFileToBuffer(file.get(),m_Buffer);
//
std::string strDirectory( 1, io.getOsSeparator() ), strModelName;
std::string::size_type pos = pFile.find_last_of( io.getOsSeparator() );
if ( pos != std::string::npos )
{
strDirectory = pFile.substr(0, pos);
std::string strModelName;
std::string::size_type pos = pFile.find_last_of( "\\/" );
if ( pos != std::string::npos ) {
strModelName = pFile.substr(pos+1, pFile.size() - pos - 1);
}
else
@ -117,7 +115,7 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
}
// 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
CreateDataFromImport(parser.GetModel(), pScene);

View File

@ -57,10 +57,7 @@ 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 &strAbsPath,
const std::string &strModelName, IOSystem* _io) :
m_strAbsPath(strAbsPath),
ObjFileParser::ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* _io) :
m_DataIt(Data.begin()),
m_DataItEnd(Data.end()),
m_pModel(NULL),
@ -440,13 +437,12 @@ void ObjFileParser::getMaterialLib()
m_DataIt++;
// Check for existence
std::string strMatName(pStart, &(*m_DataIt));
std::string absName = m_strAbsPath + io->getOsSeparator() + strMatName;
IOStream *pFile = io->Open(absName.c_str());
const std::string strMatName(pStart, &(*m_DataIt));
IOStream *pFile = io->Open(strMatName);
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 );
return;
}
@ -457,7 +453,7 @@ void ObjFileParser::getMaterialLib()
io->Close( pFile );
// Importing the material library
ObjFileMtlImporter mtlImporter( buffer, absName, m_pModel );
ObjFileMtlImporter mtlImporter( buffer, strMatName, m_pModel );
}
// -------------------------------------------------------------------

View File

@ -72,7 +72,7 @@ public:
public:
/// \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
~ObjFileParser();
/// \brief Model getter.
@ -114,8 +114,6 @@ private:
private:
/// Default material name
static const std::string DEFAULT_MATERIAL;/* = "defaultmaterial";*/
//! Absolute filepath to model
std::string m_strAbsPath;
//! Iterator to current position in buffer
DataArrayIt m_DataIt;
//! Iterator to end position of buffer