[1419] | 1 | %{ |
---|
| 2 | // |
---|
[1510] | 3 | // Lol Engine |
---|
[1419] | 4 | // |
---|
[2226] | 5 | // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> |
---|
| 6 | // (c) 2009-2013 Cédric Lecacheur <jordx@free.fr> |
---|
| 7 | // (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> |
---|
[1510] | 8 | // This program is free software; you can redistribute it and/or |
---|
| 9 | // modify it under the terms of the Do What The Fuck You Want To |
---|
| 10 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
[2183] | 11 | // http://www.wtfpl.net/ for more details. |
---|
[1419] | 12 | // |
---|
[1415] | 13 | |
---|
[1418] | 14 | #if defined HAVE_CONFIG_H |
---|
| 15 | # include "config.h" |
---|
| 16 | #endif |
---|
| 17 | |
---|
| 18 | #include "core.h" |
---|
[1510] | 19 | #include "easymesh/easymesh.h" |
---|
[1418] | 20 | |
---|
[1510] | 21 | #include <string> |
---|
[1418] | 22 | |
---|
| 23 | %} |
---|
| 24 | |
---|
| 25 | %require "2.3" |
---|
| 26 | %debug |
---|
| 27 | %defines |
---|
[1415] | 28 | %skeleton "lalr1.cc" |
---|
[1510] | 29 | %name-prefix="lol" |
---|
| 30 | %define parser_class_name "EasyMeshParser" |
---|
[1415] | 31 | %locations |
---|
[1510] | 32 | %parse-param { class EasyMeshCompiler& mc } |
---|
[1418] | 33 | %error-verbose |
---|
| 34 | |
---|
[1415] | 35 | %union |
---|
| 36 | { |
---|
| 37 | float fval; |
---|
[1432] | 38 | /* Can't use uin32_t here for some reason */ |
---|
| 39 | unsigned u32val; |
---|
[2152] | 40 | struct { float f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; } args; |
---|
[1415] | 41 | } |
---|
| 42 | |
---|
[1419] | 43 | %start mesh_description |
---|
| 44 | |
---|
[1418] | 45 | %token T_COLOR T_BGCOLOR |
---|
[1415] | 46 | |
---|
| 47 | %token T_TRANSLATEX T_ROTATEX T_TAPERX T_SCALEX T_MIRRORX |
---|
| 48 | %token T_TRANSLATEY T_ROTATEY T_TAPERY T_SCALEY T_MIRRORY |
---|
| 49 | %token T_TRANSLATEZ T_ROTATEZ T_TAPERZ T_SCALEZ T_MIRRORZ |
---|
[2294] | 50 | %token T_TRANSLATE T_SCALE T_TOGGLESCALEWINDING T_RADIALJITTER |
---|
[2350] | 51 | %token T_CSGUNION T_CSGSUBSTRACT T_CSGSUBSTRACTLOSS T_CSGAND T_CSGXOR |
---|
[1506] | 52 | %token T_CHAMFER |
---|
[1415] | 53 | |
---|
[1619] | 54 | %token T_CYLINDER T_BOX T_SMOOTHCHAMFBOX T_FLATCHAMFBOX T_SPHERE T_CAPSULE |
---|
[1875] | 55 | %token T_STAR T_EXPANDEDSTAR T_DISC T_TRIANGLE T_QUAD T_COG T_TORUS |
---|
[1415] | 56 | |
---|
| 57 | %token T_END 0 |
---|
[1442] | 58 | %token T_ERROR |
---|
[1415] | 59 | |
---|
| 60 | %token <fval> NUMBER |
---|
[1430] | 61 | %token <u32val> COLOR |
---|
[1415] | 62 | |
---|
| 63 | %type <fval> number |
---|
[2152] | 64 | %type <args> args1 args2 args3 args4 args5 args6 args7 args8 args9 args10 |
---|
[1415] | 65 | |
---|
[1418] | 66 | %{ |
---|
[1510] | 67 | #include "easymesh/easymesh-compiler.h" |
---|
[1415] | 68 | |
---|
[1418] | 69 | #undef yylex |
---|
[1422] | 70 | #define yylex mc.m_lexer->lex |
---|
[1418] | 71 | %} |
---|
| 72 | |
---|
[1419] | 73 | %% |
---|
[1418] | 74 | |
---|
[1415] | 75 | mesh_description: |
---|
[1434] | 76 | mesh_expression_list T_END |
---|
[1415] | 77 | ; |
---|
| 78 | |
---|
[1434] | 79 | mesh_expression_list: |
---|
| 80 | mesh_expression |
---|
| 81 | | mesh_expression mesh_expression_list |
---|
| 82 | ; |
---|
| 83 | |
---|
| 84 | mesh_expression: |
---|
| 85 | mesh_command_list |
---|
| 86 | | mesh_open mesh_expression_list mesh_close |
---|
| 87 | ; |
---|
| 88 | |
---|
| 89 | mesh_open: |
---|
| 90 | '[' { mc.m_mesh.OpenBrace(); } |
---|
| 91 | ; |
---|
| 92 | |
---|
| 93 | mesh_close: |
---|
| 94 | ']' { mc.m_mesh.CloseBrace(); } |
---|
| 95 | ; |
---|
| 96 | |
---|
[1415] | 97 | mesh_command_list: |
---|
| 98 | mesh_command |
---|
[1434] | 99 | | mesh_command_list mesh_command |
---|
[1415] | 100 | ; |
---|
| 101 | |
---|
| 102 | mesh_command: |
---|
[1442] | 103 | color_command |
---|
[1415] | 104 | | transform_command |
---|
| 105 | | primitive_command |
---|
| 106 | ; |
---|
| 107 | |
---|
| 108 | color_command: |
---|
[1422] | 109 | T_COLOR args4 { mc.m_mesh.SetCurColor(vec4($2.f0, $2.f1, $2.f2, $2.f3)); } |
---|
[1495] | 110 | | T_COLOR COLOR { uint32_t x = $2; |
---|
| 111 | vec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); |
---|
[2318] | 112 | mc.m_mesh.SetCurColor(vec4(v) * (1.f / 255)); } |
---|
[1422] | 113 | | T_BGCOLOR args4 { mc.m_mesh.SetCurColor2(vec4($2.f0, $2.f1, $2.f2, $2.f3)); } |
---|
[1495] | 114 | | T_BGCOLOR COLOR { uint32_t x = $2; |
---|
| 115 | vec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); |
---|
[2318] | 116 | mc.m_mesh.SetCurColor2(vec4(v) * (1.f / 255)); } |
---|
[1415] | 117 | ; |
---|
| 118 | |
---|
| 119 | transform_command: |
---|
[2226] | 120 | T_CHAMFER args1 { mc.m_mesh.Chamfer($2.f0); } |
---|
| 121 | | T_TRANSLATEX args1 { mc.m_mesh.Translate(vec3($2.f0, 0, 0)); } |
---|
| 122 | | T_TRANSLATEY args1 { mc.m_mesh.Translate(vec3(0, $2.f0, 0)); } |
---|
| 123 | | T_TRANSLATEZ args1 { mc.m_mesh.Translate(vec3(0, 0, $2.f0)); } |
---|
| 124 | | T_TRANSLATE args3 { mc.m_mesh.Translate(vec3($2.f0, $2.f1, $2.f2)); } |
---|
| 125 | | T_ROTATEX args1 { mc.m_mesh.RotateX($2.f0); } |
---|
| 126 | | T_ROTATEY args1 { mc.m_mesh.RotateY($2.f0); } |
---|
| 127 | | T_ROTATEZ args1 { mc.m_mesh.RotateZ($2.f0); } |
---|
| 128 | | T_TAPERX args3 { mc.m_mesh.TaperX($2.f0, $2.f1, $2.f2); } |
---|
| 129 | | T_TAPERY args3 { mc.m_mesh.TaperY($2.f0, $2.f1, $2.f2); } |
---|
| 130 | | T_TAPERZ args3 { mc.m_mesh.TaperZ($2.f0, $2.f1, $2.f2); } |
---|
| 131 | | T_SCALEX args1 { mc.m_mesh.Scale(vec3($2.f0, 1.0, 1.0)); } |
---|
| 132 | | T_SCALEY args1 { mc.m_mesh.Scale(vec3(1.0, $2.f0, 1.0)); } |
---|
| 133 | | T_SCALEZ args1 { mc.m_mesh.Scale(vec3(1.0, 1.0, $2.f0)); } |
---|
| 134 | | T_SCALE args3 { mc.m_mesh.Scale(vec3($2.f0, $2.f1, $2.f2)); } |
---|
| 135 | | T_MIRRORX { mc.m_mesh.MirrorX(); } |
---|
| 136 | | T_MIRRORY { mc.m_mesh.MirrorY(); } |
---|
| 137 | | T_MIRRORZ { mc.m_mesh.MirrorZ(); } |
---|
[2294] | 138 | | T_RADIALJITTER args1 { mc.m_mesh.RadialJitter($2.f0); } |
---|
[2226] | 139 | | T_TOGGLESCALEWINDING { mc.m_mesh.ToggleScaleWinding(); } |
---|
| 140 | | T_CSGUNION { mc.m_mesh.CsgUnion(); } |
---|
| 141 | | T_CSGSUBSTRACT { mc.m_mesh.CsgSubstract(); } |
---|
[2350] | 142 | | T_CSGSUBSTRACTLOSS { mc.m_mesh.CsgSubstractLoss(); } |
---|
[2226] | 143 | | T_CSGAND { mc.m_mesh.CsgAnd(); } |
---|
| 144 | | T_CSGXOR { mc.m_mesh.CsgXor(); } |
---|
[1415] | 145 | ; |
---|
| 146 | |
---|
| 147 | primitive_command: |
---|
[1422] | 148 | T_CYLINDER args6 { mc.m_mesh.AppendCylinder((int)$2.f0, $2.f1, |
---|
[1415] | 149 | $2.f2, $2.f3, |
---|
| 150 | (int)$2.f4, (int)$2.f5); } |
---|
[1422] | 151 | | T_BOX args3 { mc.m_mesh.AppendBox(vec3($2.f0, $2.f1, $2.f2)); } |
---|
| 152 | | T_SMOOTHCHAMFBOX args4 { mc.m_mesh.AppendSmoothChamfBox(vec3($2.f0, $2.f1, |
---|
[1415] | 153 | $2.f2), $2.f3); } |
---|
[1422] | 154 | | T_FLATCHAMFBOX args4 { mc.m_mesh.AppendFlatChamfBox(vec3($2.f0, $2.f1, |
---|
[1415] | 155 | $2.f2), $2.f3); } |
---|
[1422] | 156 | | T_SPHERE args4 { mc.m_mesh.AppendSphere($2.f0, |
---|
[1415] | 157 | vec3($2.f1, $2.f2, $2.f3)); } |
---|
[1619] | 158 | | T_CAPSULE args3 { mc.m_mesh.AppendCapsule($2.f0, $2.f1, $2.f2); } |
---|
[1875] | 159 | | T_TORUS args3 { mc.m_mesh.AppendTorus((int)$2.f0, $2.f1, $2.f2); } |
---|
[1422] | 160 | | T_STAR args5 { mc.m_mesh.AppendStar((int)$2.f0, $2.f1, $2.f2, |
---|
[1415] | 161 | (int)$2.f3, (int)$2.f4); } |
---|
[1422] | 162 | | T_EXPANDEDSTAR args4 { mc.m_mesh.AppendExpandedStar((int)$2.f0, $2.f1, |
---|
[1415] | 163 | $2.f2, $2.f3); } |
---|
[1422] | 164 | | T_DISC args3 { mc.m_mesh.AppendDisc((int)$2.f0, $2.f1, (int)$2.f2); } |
---|
| 165 | | T_TRIANGLE args2 { mc.m_mesh.AppendSimpleTriangle($2.f0, (int)$2.f1); } |
---|
| 166 | | T_QUAD args2 { mc.m_mesh.AppendSimpleQuad($2.f0, (int)$2.f1); } |
---|
[2152] | 167 | | T_COG args10 { mc.m_mesh.AppendCog((int)$2.f0, $2.f1, |
---|
| 168 | $2.f2, $2.f3, $2.f4, $2.f5, $2.f6, |
---|
| 169 | $2.f7, $2.f8, (int)$2.f9); } |
---|
[1415] | 170 | ; |
---|
| 171 | |
---|
| 172 | args1: number { $$.f0 = $1; } ; |
---|
[1434] | 173 | args2: args1 number { $$ = $1; $$.f1 = $2; } ; |
---|
| 174 | args3: args2 number { $$ = $1; $$.f2 = $2; } ; |
---|
| 175 | args4: args3 number { $$ = $1; $$.f3 = $2; } ; |
---|
| 176 | args5: args4 number { $$ = $1; $$.f4 = $2; } ; |
---|
| 177 | args6: args5 number { $$ = $1; $$.f5 = $2; } ; |
---|
| 178 | args7: args6 number { $$ = $1; $$.f6 = $2; } ; |
---|
| 179 | args8: args7 number { $$ = $1; $$.f7 = $2; } ; |
---|
[2152] | 180 | args9: args8 number { $$ = $1; $$.f8 = $2; } ; |
---|
| 181 | args10: args9 number { $$ = $1; $$.f9 = $2; } ; |
---|
[1415] | 182 | |
---|
| 183 | number: |
---|
| 184 | NUMBER { $$ = $1; } |
---|
| 185 | | '-' number { $$ = -$2; } |
---|
| 186 | ; |
---|
| 187 | |
---|
[1419] | 188 | %% |
---|
[1415] | 189 | |
---|
[1510] | 190 | void lol::EasyMeshParser::error(const EasyMeshParser::location_type& l, |
---|
[1418] | 191 | const std::string& m) |
---|
[1415] | 192 | { |
---|
[1422] | 193 | mc.Error(l, m); |
---|
[1415] | 194 | } |
---|
[1419] | 195 | |
---|