From 66d4bb50e417c00f4a14329b523474020c50b790 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 20 Apr 2011 15:46:30 -0400 Subject: [PATCH] fix basePath(); load .mtl relative to .obj path --- WFObj.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/WFObj.cc b/WFObj.cc index d5fc99d..5a93164 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -71,14 +71,8 @@ static vector 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; }