-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjReader.cpp
54 lines (43 loc) · 1.26 KB
/
ObjReader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "ObjReader.hpp"
#include <fstream>
#include <iostream>
#include <string>
void ObjReader::read_object_file(
const std::string& filename,
Vertex::VertMap& vmap,
VertexNormal::VertNormalMap& vnmap,
TextureCoordinate::TextCoordinateMap& tcmap,
Face::FaceMap& fmap)
{
std::ifstream file;
file.open (filename.c_str());
std::string single_line;
while (getline(file,single_line))
{
read_element_from_string(
single_line,vmap,vnmap,tcmap,fmap);
}
file.close();
// calculate normals for all faces
for (Face::FaceMapIter fiter = fmap.begin(); fiter != fmap.end();
++fiter)
{
fiter->second->calc_normals(vnmap);
}
}
void ObjReader::read_element_from_string(
const std::string& line_to_read,
Vertex::VertMap& vmap,
VertexNormal::VertNormalMap& vnmap,
TextureCoordinate::TextCoordinateMap& tcmap,
Face::FaceMap& fmap)
{
if (Vertex::construct_from_line(vmap,line_to_read))
return;
if (TextureCoordinate::construct_from_line(tcmap,line_to_read))
return;
if (VertexNormal::construct_from_line(vnmap,line_to_read))
return;
if (Face::construct_from_line(vmap,tcmap,vnmap,fmap,line_to_read))
return;
}