blob: a13af1f2b4fe9c2b8c98abc9254cc7ce719928a3 (
plain)
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
|
#include "loader.h"
#include "../core/exception.h"
#include <fstream>
#include <sstream>
namespace yage
{
void load_obj(std::string filename, std::vector<glm::vec4> &vertices,
std::vector<glm::vec3> &normals, std::vector<GLushort> &elements)
{
std::ifstream in(filename, std::ios::in);
if (!in.is_open()) {
throw FileLoadException("Could not load obj file '" + filename + "'");
}
std::string line;
while (getline(in, line)) {
if (line.substr(0, 2) == "v ") {
std::istringstream s(line.substr(2));
glm::vec4 v;
s >> v.x >> v.y >> v.z;
v.w = 1.f;
vertices.push_back(v);
} else if (line.substr(0, 2) == "f ") {
std::istringstream s(line.substr(2));
GLushort a, b, c;
s >> a >> b >> c;
a--, b--, c--;
elements.push_back(a);
elements.push_back(b);
elements.push_back(c);
} else {
// do nothing otherwise
}
}
normals.resize()
}
} // namespace yage
|