fix basePath(); load .mtl relative to .obj path

This commit is contained in:
Josh Holtrop 2011-04-20 15:46:30 -04:00
parent d78d956826
commit 66d4bb50e4

View File

@ -71,14 +71,8 @@ static vector<string> splitString(const string & str, char delim)
static string basePath(const string & str) static string basePath(const string & str)
{ {
string path = str; size_t pos = str.find_last_of("/\\");
size_t pos; return pos != string::npos ? string(str, 0, pos + 1) : "./";
if ( (pos = path.find_last_of("/\\")) != string::npos )
{
path.erase(pos + 1);
return path;
}
return "";
} }
//#define DEBUG_GL_ERROR //#define DEBUG_GL_ERROR
@ -132,12 +126,12 @@ bool WFObj::load(const char *fname)
{ {
clear(); clear();
m_path = fname;
Buffer buff; Buffer buff;
if (!m_loadfile(fname, buff)) if (!m_loadfile(fname, buff))
return false; return false;
m_path = fname;
return load(buff); return load(buff);
} }
@ -332,9 +326,10 @@ WFObj::VertexRef WFObj::readVertexRef(const std::string ref)
void WFObj::loadMaterial(const std::string & name) void WFObj::loadMaterial(const std::string & name)
{ {
Buffer buff; Buffer buff;
if (!m_loadfile(name.c_str(), buff)) string path = (name[0] != '/') ? basePath(m_path) + name : name;
if (!m_loadfile(path.c_str(), buff))
{ {
cerr << "WFObj: error: couldn't open material file '" << name << "'" cerr << "WFObj: error: couldn't open material file '" << path << "'"
<< endl; << endl;
return; return;
} }