aboutsummaryrefslogtreecommitdiffstats
path: root/yage/experimental/loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'yage/experimental/loader.cpp')
-rw-r--r--yage/experimental/loader.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/yage/experimental/loader.cpp b/yage/experimental/loader.cpp
new file mode 100644
index 00000000..a13af1f2
--- /dev/null
+++ b/yage/experimental/loader.cpp
@@ -0,0 +1,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