diff --git a/src/model.cpp b/src/model.cpp index 082b6fa..7b35ade 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -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 tmp_positions; std::vector 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)]; } } diff --git a/src/mtllib.cpp b/src/mtllib.cpp index 105153d..65a487f 100644 --- a/src/mtllib.cpp +++ b/src/mtllib.cpp @@ -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]; +} diff --git a/src/mtllib.hpp b/src/mtllib.hpp index a0e8291..ab92ecb 100644 --- a/src/mtllib.hpp +++ b/src/mtllib.hpp @@ -13,7 +13,10 @@ class Mtllib: RESOURCE(Mtllib) public: - std::map materials; + const Material *operator[](const std::string &name) const; + +private: + std::map _materials; }; #endif // _MTLLIB_HPP_