1
0
Fork 0

Add operator[] to class Mtllib

This commit is contained in:
Meoweg 2015-11-11 20:56:04 +00:00
parent ea811ab340
commit 62b5418410
3 changed files with 12 additions and 4 deletions

View file

@ -14,7 +14,7 @@ Model::Model(Store &store, const std::string &name)
{
std::ifstream file(filename(name), std::ios::in);
Mtllib *mtllib = nullptr;
const Mtllib *mtllib = nullptr;
std::vector<glm::vec3> tmp_positions;
std::vector<glm::vec2> tmp_tex_coords;
@ -86,7 +86,7 @@ Model::Model(Store &store, const std::string &name)
else
if (line.substr(0, 7) == "usemtl ")
{
_material = mtllib->materials[line.substr(7)];
_material = (*mtllib)[line.substr(7)];
}
}

View file

@ -23,7 +23,7 @@ Mtllib::Mtllib(Store &store, const std::string &name)
if (line.substr(0, 7) == "newmtl ")
{
material = new Material();
materials[line.substr(7)] = material;
_materials[line.substr(7)] = material;
}
else
if (line.substr(0, 7) == "map_Kd ")
@ -32,3 +32,8 @@ Mtllib::Mtllib(Store &store, const std::string &name)
}
}
}
const Material *Mtllib::operator[](const std::string &name) const
{
return ((Mtllib*)this)->_materials[name];
}

View file

@ -13,7 +13,10 @@ class Mtllib:
RESOURCE(Mtllib)
public:
std::map<std::string, const Material*> materials;
const Material *operator[](const std::string &name) const;
private:
std::map<std::string, const Material*> _materials;
};
#endif // _MTLLIB_HPP_