@@ -25,6 +25,9 @@ bool ObjLoader::loadFromFile(const std::string& file_path) {
2525 if (!reader_.Warning ().empty ()) {
2626 std::cout << " TinyObjReader: " << reader_.Warning ();
2727 }
28+ shapes_ = reader_.GetShapes ();
29+ materials_ = reader_.GetMaterials ();
30+ attribute_ = reader_.GetAttrib ();
2831 return true ;
2932}
3033
@@ -40,48 +43,46 @@ bool ObjLoader::loadFromFile(const std::string& file_path,
4043 if (!reader_.Warning ().empty ()) {
4144 std::cout << " TinyObjReader: " << reader_.Warning ();
4245 }
46+ shapes_ = reader_.GetShapes ();
47+ materials_ = reader_.GetMaterials ();
48+ attribute_ = reader_.GetAttrib ();
4349 return true ;
4450}
4551
46- int ObjLoader::numShapes () const {
47- return static_cast <int >(reader_.GetShapes ().size ());
48- }
52+ int ObjLoader::numShapes () const { return static_cast <int >(shapes_.size ()); }
4953
5054int ObjLoader::numFaces (const int shape_id) const {
51- const auto & shapes = reader_.GetShapes ();
52- return static_cast <int >(shapes[shape_id].mesh .num_face_vertices .size ());
55+ return static_cast <int >(shapes_[shape_id].mesh .num_face_vertices .size ());
5356}
5457
5558int ObjLoader::numVertices (const int shape_id, const int face_id) const {
56- const auto & shape = reader_. GetShapes () [shape_id];
59+ const auto & shape = shapes_ [shape_id];
5760 return static_cast <int >(shape.mesh .num_face_vertices [face_id]);
5861}
5962
6063glm::vec3 ObjLoader::getVertexPos (const int shape_id,
6164 const int vertex_id) const {
62- const auto & shape = reader_. GetShapes () [shape_id];
65+ const auto & shape = shapes_ [shape_id];
6366 tinyobj::index_t idx = shape.mesh .indices [vertex_id];
6467
65- const auto & attrib = reader_.GetAttrib ();
66- tinyobj::real_t vx = attrib.vertices [idx.vertex_index * 3 + 0 ];
67- tinyobj::real_t vy = attrib.vertices [idx.vertex_index * 3 + 1 ];
68- tinyobj::real_t vz = attrib.vertices [idx.vertex_index * 3 + 2 ];
68+ tinyobj::real_t vx = attribute_.vertices [idx.vertex_index * 3 + 0 ];
69+ tinyobj::real_t vy = attribute_.vertices [idx.vertex_index * 3 + 1 ];
70+ tinyobj::real_t vz = attribute_.vertices [idx.vertex_index * 3 + 2 ];
6971
7072 return glm::vec3 (vx, vy, vz);
7173}
7274
7375glm::vec3 ObjLoader::getNormalVec (const int shape_id,
7476 const int normal_id) const {
75- const auto & shape = reader_. GetShapes () [shape_id];
77+ const auto & shape = shapes_ [shape_id];
7678 tinyobj::index_t idx = shape.mesh .indices [normal_id];
7779
7880 glm::vec3 normal{0 .0f , 0 .0f , 0 .0f };
7981
8082 if (idx.normal_index > 0 ) {
81- const auto & attrib = reader_.GetAttrib ();
82- normal.x = attrib.normals [idx.vertex_index * 3 + 0 ];
83- normal.y = attrib.normals [idx.vertex_index * 3 + 1 ];
84- normal.z = attrib.normals [idx.vertex_index * 3 + 2 ];
83+ normal.x = attribute_.normals [idx.vertex_index * 3 + 0 ];
84+ normal.y = attribute_.normals [idx.vertex_index * 3 + 1 ];
85+ normal.z = attribute_.normals [idx.vertex_index * 3 + 2 ];
8586 } else {
8687 std::cout << " TinyObjReader: no normal vectors found in shape " << shape_id
8788 << " , id " << normal_id << " !\n " ;
0 commit comments