-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobj_parse.cpp
More file actions
74 lines (66 loc) · 1.43 KB
/
obj_parse.cpp
File metadata and controls
74 lines (66 loc) · 1.43 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <fstream>
#include "obj_parse.h"
obj_model::obj_model(char *filename) {
std::ifstream inf(filename);
std::string token;
if (!inf) {
//std::cout << "Couldn't open file \"" << filename << "\""
// << std::endl;
return;
} else {
//std::cout << "Opened file \"" << filename << "\"" <<
// std::endl;
}
// TODO Boost::coroutine for parsing?
while (inf) {
inf >> token;
//std::cout << "Found a token '" << token << "'" << std::endl;
if (0 == token.compare("#")) {
std::getline(inf, token);
continue;
}
if (0 == token.compare("v")) {
std::string v2, v3;
inf >> token;
inf >> v2;
inf >> v3;
vertex v = {
std::stof(token), std::stof(v2), std::stof(v3)
};
obj_model::v.push_back(v);
}
if (0 == token.compare("vt")) {
std::string v2;
inf >> token;
inf >> v2;
uv u = {
std::stof(token), std::stof(v2)
};
obj_model::u.push_back(u);
}
if (0 == token.compare("vn")) {
std::string v2, v3;
inf >> token;
inf >> v2;
inf >> v3;
normal n = {
std::stof(token), std::stof(v2), std::stof(v3)
};
obj_model::n.push_back(n);
}
if (0 == token.compare("f")) {
// for now this just grabs the vertex number and ignores
// everything else
std::string v2, v3, v4;
inf >> token;
inf >> v2;
inf >> v3;
inf >> v4;
face f = {
std::stoi(token), std::stoi(v2), std::stoi(v3),
std::stoi(v4)
};
obj_model::f.push_back(f);
}
}
}