fix basePath(); load .mtl relative to .obj path
This commit is contained in:
parent
d78d956826
commit
66d4bb50e4
19
WFObj.cc
19
WFObj.cc
@ -71,14 +71,8 @@ static vector<string> splitString(const string & str, char delim)
|
||||
|
||||
static string basePath(const string & str)
|
||||
{
|
||||
string path = str;
|
||||
size_t pos;
|
||||
if ( (pos = path.find_last_of("/\\")) != string::npos )
|
||||
{
|
||||
path.erase(pos + 1);
|
||||
return path;
|
||||
}
|
||||
return "";
|
||||
size_t pos = str.find_last_of("/\\");
|
||||
return pos != string::npos ? string(str, 0, pos + 1) : "./";
|
||||
}
|
||||
|
||||
//#define DEBUG_GL_ERROR
|
||||
@ -132,12 +126,12 @@ bool WFObj::load(const char *fname)
|
||||
{
|
||||
clear();
|
||||
|
||||
m_path = fname;
|
||||
|
||||
Buffer buff;
|
||||
if (!m_loadfile(fname, buff))
|
||||
return false;
|
||||
|
||||
m_path = fname;
|
||||
|
||||
return load(buff);
|
||||
}
|
||||
|
||||
@ -332,9 +326,10 @@ WFObj::VertexRef WFObj::readVertexRef(const std::string ref)
|
||||
void WFObj::loadMaterial(const std::string & name)
|
||||
{
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user