summaryrefslogtreecommitdiff
path: root/gfx/models/obj.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-13 14:52:03 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-13 14:52:03 +0000
commitd2b167f2d1ca15e42a177b65cdf34f35592452f7 (patch)
treeacdd75da65e879412934fb024274a6849b823439 /gfx/models/obj.h
parentFlip texture images to match OpenGL expectations (diff)
downloadilt-d2b167f2d1ca15e42a177b65cdf34f35592452f7.tar.bz2
ilt-d2b167f2d1ca15e42a177b65cdf34f35592452f7.tar.xz
ilt-d2b167f2d1ca15e42a177b65cdf34f35592452f7.zip
New .obj parser, packer, mesher
Diffstat (limited to 'gfx/models/obj.h')
-rw-r--r--gfx/models/obj.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/gfx/models/obj.h b/gfx/models/obj.h
new file mode 100644
index 0000000..96c5e94
--- /dev/null
+++ b/gfx/models/obj.h
@@ -0,0 +1,36 @@
+#ifndef OBJ_H
+#define OBJ_H
+
+#ifndef yyFlexLexer
+# define yyFlexLexer objbaseFlexLexer
+# include <FlexLexer.h>
+#endif
+#include <filesystem>
+#include <fstream>
+#include <glm/glm.hpp>
+#include <memory>
+#include <vector>
+
+class ObjParser : yyFlexLexer {
+public:
+ explicit ObjParser(const std::filesystem::path & fileName) : ObjParser {std::make_unique<std::ifstream>(fileName)}
+ {
+ }
+
+ explicit ObjParser(std::unique_ptr<std::istream> in) : yyFlexLexer(in.get())
+ {
+ ObjParser::yylex();
+ }
+
+ int yylex() override;
+
+ std::vector<glm::vec4> vertices;
+ std::vector<glm::vec3> texCoords;
+ std::vector<glm::vec3> normals;
+ using FaceElement = glm::vec<3, int>;
+ using Face = std::vector<FaceElement>;
+ std::vector<Face> faces;
+ glm::length_t axis {0};
+};
+
+#endif