diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-13 14:52:03 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-13 14:52:03 +0000 |
commit | d2b167f2d1ca15e42a177b65cdf34f35592452f7 (patch) | |
tree | acdd75da65e879412934fb024274a6849b823439 /gfx/models/obj.ll | |
parent | Flip texture images to match OpenGL expectations (diff) | |
download | ilt-d2b167f2d1ca15e42a177b65cdf34f35592452f7.tar.bz2 ilt-d2b167f2d1ca15e42a177b65cdf34f35592452f7.tar.xz ilt-d2b167f2d1ca15e42a177b65cdf34f35592452f7.zip |
New .obj parser, packer, mesher
Diffstat (limited to 'gfx/models/obj.ll')
-rw-r--r-- | gfx/models/obj.ll | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/gfx/models/obj.ll b/gfx/models/obj.ll new file mode 100644 index 0000000..9329a5a --- /dev/null +++ b/gfx/models/obj.ll @@ -0,0 +1,121 @@ +%option batch +%option c++ +%option noyywrap +%option 8bit +%option stack +%option yyclass="ObjParser" +%option prefix="objbase" + +%{ +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#if __clang__ +#pragma GCC diagnostic ignored "-Wnull-conversion" +#endif +#include <gfx/models/obj.h> +#include <glm/glm.hpp> +#include <memory> +#include <string> +#include <vector> +class objbaseFlexLexer; +%} + +comment #.* +float -?[0-9.]+ +index -?[0-9]+ +linestring [^\r\n]* +truthy (1|on) +falsey (0|off) + +%x FACE +%x MTLLIB +%x OBJECT +%x SMOOTH +%x USEMTL +%x VERTEX +%x NORMAL +%x TEXCOORD + +%% + +<INITIAL>{comment} { + // fprintf(stderr, "COMMENT %s\n", YYText()); +} +<INITIAL>"f " { + BEGIN(FACE); + faces.emplace_back(); + faces.back().emplace_back(); + axis = 0; +} +<INITIAL>"mtllib " { + BEGIN(MTLLIB); +} +<INITIAL>"o " { + BEGIN(OBJECT); +} +<INITIAL>"s " { + BEGIN(SMOOTH); +} +<INITIAL>"usemtl " { + BEGIN(USEMTL); +} +<INITIAL>"v " { + BEGIN(VERTEX); + vertices.emplace_back(0, 0, 0, 1); + axis = 0; +} +<INITIAL>"vn " { + BEGIN(NORMAL); + normals.emplace_back(0, 0, 0); + axis = 0; +} +<INITIAL>"vt " { + BEGIN(TEXCOORD); + texCoords.emplace_back(0, 1, 1); + axis = 0; +} +<USEMTL>{linestring} { + // fprintf(stderr, "USEMTL <%s>\n", YYText()); +} +<MTLLIB>{linestring} { + // fprintf(stderr, "MTLLIB <%s>\n", YYText()); +} +<OBJECT>{linestring} { + // fprintf(stderr, "OBJECT <%s>\n", YYText()); +} +<SMOOTH>{truthy} { + // fprintf(stderr, "Set smooth\n"); +} +<SMOOTH>{falsey} { + // fprintf(stderr, "Set flat\n"); +} +<VERTEX>{float} { + vertices.back()[axis++] = std::stof(YYText()); +} +<NORMAL>{float} { + normals.back()[axis++] = std::stof(YYText()); +} +<TEXCOORD>{float} { + texCoords.back()[axis++] = std::stof(YYText()); +} +<FACE>{index} { + faces.back().back()[axis] = std::stoi(YYText()); +} +<FACE>\/ { + axis++; +} +<FACE>[ \t] { + faces.back().emplace_back(); + axis = 0; +} + +<*>[ \t] { +} +<*>[\r\n\f] { + BEGIN(INITIAL); +} + +%% + +// Make iwyu think unistd.h is required +[[maybe_unused]]static auto x=getpid; |