From 08e558482f1b79ff8119c426de2ff6156fd470dc Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 16 May 2011 15:32:11 -0400 Subject: [PATCH] add resolvePath() to find files rel to .obj path --- WFObj.cc | 9 +++++++-- WFObj.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/WFObj.cc b/WFObj.cc index 5c308c7..a84bbb8 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -341,7 +341,7 @@ WFObj::VertexRef WFObj::readVertexRef(const std::string ref) void WFObj::loadMaterial(const std::string & name) { Buffer buff; - string path = (name[0] != '/') ? basePath(m_path) + name : name; + string path = resolvePath(name); if (!m_loadfile(path.c_str(), buff)) { cerr << "WFObj: error: couldn't open material file '" << path << "'" @@ -422,7 +422,7 @@ void WFObj::loadMaterial(const std::string & name) } else if (tokens[0] == "map_Kd") { - m_materials[mat_name].texture = loadTexture(tokens[1]); + m_materials[mat_name].texture = loadTexture(resolvePath(tokens[1])); if (m_materials[mat_name].texture != 0) m_materials[mat_name].flags |= Material::TEXTURE_BIT; } @@ -571,6 +571,11 @@ GLuint WFObj::loadTexture(const std::string & path) return id; } +string WFObj::resolvePath(const string & name) +{ + return (name[0] != '/') ? basePath(m_path) + name : name; +} + bool WFObj::VertexRef::operator<(const VertexRef & other) const { if (vertex != other.vertex) diff --git a/WFObj.h b/WFObj.h index dac8fea..bbd71b9 100644 --- a/WFObj.h +++ b/WFObj.h @@ -116,6 +116,7 @@ protected: void loadMaterial(const std::string & name); bool buildVBO(); GLuint loadTexture(const std::string & path); + std::string resolvePath(const std::string & name); /* variables */ std::vector m_vertices[VERTEX_TYPES];