add resolvePath() to find files rel to .obj path

This commit is contained in:
Josh Holtrop 2011-05-16 15:32:11 -04:00
parent 1918cc89bf
commit 08e558482f
2 changed files with 8 additions and 2 deletions

View File

@ -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)

View File

@ -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<Vertex> m_vertices[VERTEX_TYPES];