diff --git a/src/easymesh/easymesh-parser.y b/src/easymesh/easymesh-parser.y index 59a43013..f34ee875 100644 --- a/src/easymesh/easymesh-parser.y +++ b/src/easymesh/easymesh-parser.y @@ -49,7 +49,7 @@ %token T_TRANSLATEX T_ROTATEX T_TAPERX T_TWISTX T_SHEARX T_STRETCHX T_BENDXY T_BENDXZ T_SCALEX T_MIRRORX %token T_TRANSLATEY T_ROTATEY T_TAPERY T_TWISTY T_SHEARY T_STRETCHY T_BENDYX T_BENDYZ T_SCALEY T_MIRRORY %token T_TRANSLATEZ T_ROTATEZ T_TAPERZ T_TWISTZ T_SHEARZ T_STRETCHZ T_BENDZX T_BENDZY T_SCALEZ T_MIRRORZ -%token T_TRANSLATE T_SCALE T_TOGGLESCALEWINDING T_RADIALJITTER T_SPLITTRIANGLE T_SMOOTHMESH +%token T_TRANSLATE T_ROTATE T_SCALE T_TOGGLESCALEWINDING T_RADIALJITTER T_SPLITTRIANGLE T_SMOOTHMESH %token T_CSGUNION T_CSGSUBSTRACT T_CSGSUBSTRACTLOSS T_CSGAND T_CSGXOR %token T_CHAMFER @@ -101,14 +101,6 @@ mesh_expression: | mesh_open mesh_expression_list mesh_close ; -mesh_open: - '[' { mc.m_mesh.OpenBrace(); } - ; - -mesh_close: - ']' { mc.m_mesh.CloseBrace(); } - ; - mesh_command_list: mesh_command | mesh_command_list mesh_command @@ -118,6 +110,23 @@ mesh_command: color_command | transform_command | primitive_command + | csg_command + ; + +csg_command: + T_CSGUNION { mc.m_mesh.CsgUnion(); } + | T_CSGSUBSTRACT { mc.m_mesh.CsgSubstract(); } + | T_CSGSUBSTRACTLOSS { mc.m_mesh.CsgSubstractLoss(); } + | T_CSGAND { mc.m_mesh.CsgAnd(); } + | T_CSGXOR { mc.m_mesh.CsgXor(); } + ; + +mesh_open: + '[' { mc.m_mesh.OpenBrace(); } + ; + +mesh_close: + ']' { mc.m_mesh.CloseBrace(); } ; color_command: @@ -126,16 +135,15 @@ color_command: | T_COLOR COLOR { uint32_t x = $2; ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); mc.m_mesh.SetCurColor(vec4(v) * (1.f / 255.f)); } - | T_BGCOLOR fv fv fv fv { mc.m_mesh.SetCurColor2(vec4($2, $3, $4, $5)); } - | T_BGCOLOR v4 { mc.m_mesh.SetCurColor2(vec4($2[0], $2[1], $2[2], $2[3])); } - | T_BGCOLOR COLOR { uint32_t x = $2; + | T_BCOLOR fv fv fv fv { mc.m_mesh.SetCurColor2(vec4($2, $3, $4, $5)); } + | T_BCOLOR v4 { mc.m_mesh.SetCurColor2(vec4($2[0], $2[1], $2[2], $2[3])); } + | T_BCOLOR COLOR { uint32_t x = $2; ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); mc.m_mesh.SetCurColor2(vec4(v) * (1.f / 255.f)); } ; transform_command: - T_CHAMFER fv { mc.m_mesh.Chamfer($2); } - | T_TRANSLATEX fv { mc.m_mesh.Translate(vec3($2, 0.f, 0.f)); } + T_TRANSLATEX fv { mc.m_mesh.Translate(vec3($2, 0.f, 0.f)); } | T_TRANSLATEY fv { mc.m_mesh.Translate(vec3(0.f, $2, 0.f)); } | T_TRANSLATEZ fv { mc.m_mesh.Translate(vec3(0.f, 0.f, $2)); } | T_TRANSLATE fv fv fv { mc.m_mesh.Translate(vec3($2, $3, $4)); } @@ -143,6 +151,9 @@ transform_command: | T_ROTATEX fv { mc.m_mesh.RotateX($2); } | T_ROTATEY fv { mc.m_mesh.RotateY($2); } | T_ROTATEZ fv { mc.m_mesh.RotateZ($2); } + | T_ROTATE fv fv fv fv { mc.m_mesh.RotateZ($2, vec3($3, $4, $5)); } + | T_ROTATE fv vec3 { mc.m_mesh.RotateZ($2, vec3($3[0], $3[1], $3[2])); } + | T_RADIALJITTER fv { mc.m_mesh.RadialJitter($2); } | T_TAPERX fv fv fv bv { mc.m_mesh.TaperX($2, $3, $4, $5); } | T_TAPERX fv fv fv { mc.m_mesh.TaperX($2, $3, $4); } | T_TAPERX fv fv { mc.m_mesh.TaperX($2, $3); } @@ -194,15 +205,10 @@ transform_command: | T_MIRRORX { mc.m_mesh.MirrorX(); } | T_MIRRORY { mc.m_mesh.MirrorY(); } | T_MIRRORZ { mc.m_mesh.MirrorZ(); } - | T_RADIALJITTER fv { mc.m_mesh.RadialJitter($2); } + | T_CHAMFER fv { mc.m_mesh.Chamfer($2); } | T_SPLITTRIANGLE iv { mc.m_mesh.SplitTriangles($2); } | T_SMOOTHMESH iv iv iv { mc.m_mesh.SmoothMesh($2, $3, $4); } | T_TOGGLESCALEWINDING { mc.m_mesh.ToggleScaleWinding(); } - | T_CSGUNION { mc.m_mesh.CsgUnion(); } - | T_CSGSUBSTRACT { mc.m_mesh.CsgSubstract(); } - | T_CSGSUBSTRACTLOSS { mc.m_mesh.CsgSubstractLoss(); } - | T_CSGAND { mc.m_mesh.CsgAnd(); } - | T_CSGXOR { mc.m_mesh.CsgXor(); } ; primitive_command: @@ -210,6 +216,9 @@ primitive_command: | T_CYLINDER iv fv fv fv bv bv { mc.m_mesh.AppendCylinder($2, $3, $4, $5, $6, $7); } | T_CYLINDER iv fv fv fv bv { mc.m_mesh.AppendCylinder($2, $3, $4, $5, $6); } | T_CYLINDER iv fv fv fv { mc.m_mesh.AppendCylinder($2, $3, $4, $5); } + | T_SPHERE iv fv { mc.m_mesh.AppendSphere($2, $3); } + | T_CAPSULE iv fv fv { mc.m_mesh.AppendCapsule($2, $3, $4); } + | T_TORUS iv fv fv { mc.m_mesh.AppendTorus($2, $3, $4); } | T_BOX fv fv fv fv { mc.m_mesh.AppendBox(vec3($2, $3, $4), $5); } | T_BOX fv fv fv { mc.m_mesh.AppendBox(vec3($2, $3, $4)); } | T_BOX fv { mc.m_mesh.AppendBox(vec3($2, $2, $2)); } @@ -221,14 +230,12 @@ primitive_command: | T_FLATCHAMFBOX fv fv fv fv { mc.m_mesh.AppendFlatChamfBox(vec3($2, $3, $4), $5); } | T_FLATCHAMFBOX fv fv { mc.m_mesh.AppendFlatChamfBox(vec3($2, $2, $2), $3); } | T_FLATCHAMFBOX v3 fv { mc.m_mesh.AppendFlatChamfBox(vec3($2[0], $2[1], $2[2]), $3); } - | T_SPHERE iv fv { mc.m_mesh.AppendSphere($2, $3); } - | T_CAPSULE iv fv fv { mc.m_mesh.AppendCapsule($2, $3, $4); } - | T_TORUS iv fv fv { mc.m_mesh.AppendTorus($2, $3, $4); } | T_STAR iv fv fv bv bv { mc.m_mesh.AppendStar($2, $3, $4, $5, $6); } | T_STAR iv fv fv bv { mc.m_mesh.AppendStar($2, $3, $4, $5); } | T_STAR iv fv fv { mc.m_mesh.AppendStar($2, $3, $4); } | T_EXPANDEDSTAR iv fv fv fv { mc.m_mesh.AppendExpandedStar($2, $3, $4, $5); } | T_EXPANDEDSTAR iv fv fv { mc.m_mesh.AppendExpandedStar($2, $3, $4); } + | T_DISC iv fv bv { mc.m_mesh.AppendDisc($2, $3, $4); } | T_DISC iv fv { mc.m_mesh.AppendDisc($2, $3); } | T_TRIANGLE fv bv { mc.m_mesh.AppendSimpleTriangle($2, $3); } diff --git a/src/easymesh/easymesh-scanner.l b/src/easymesh/easymesh-scanner.l index 04f665ba..1c80d9b1 100644 --- a/src/easymesh/easymesh-scanner.l +++ b/src/easymesh/easymesh-scanner.l @@ -47,10 +47,16 @@ typedef lol::EasyMeshParser::token_type token_type; yylloc->step(); %} +(csgu|csgunion) { return token::T_CSGUNION; } +(csgs|csgsubstract) { return token::T_CSGSUBSTRACT; } +(csgsl|csgsubstractloss) { return token::T_CSGSUBSTRACTLOSS; } +(csga|csgand) { return token::T_CSGAND; } +(csgx|csgxor) { return token::T_CSGXOR; } + +(tsw|scalewinding) { return token::T_TOGGLESCALEWINDING; } (sc|setcolor) { return token::T_COLOR; } -(scb|setbgcolor) { return token::T_BGCOLOR; } +(scb|setbcolor) { return token::T_BCOLOR; } -(ch|chamfer) { return token::T_CHAMFER; } (tx|translatex) { return token::T_TRANSLATEX; } (ty|translatey) { return token::T_TRANSLATEY; } (tz|translatez) { return token::T_TRANSLATEZ; } @@ -58,6 +64,8 @@ typedef lol::EasyMeshParser::token_type token_type; (rx|rotatex) { return token::T_ROTATEX; } (ry|rotatey) { return token::T_ROTATEY; } (rz|rotatez) { return token::T_ROTATEZ; } +(r|rotate) { return token::T_ROTATE; } +(rj|radialjitter) { return token::T_RADIALJITTER; } (tax|taperx) { return token::T_TAPERX; } (tay|tapery) { return token::T_TAPERY; } (taz|taperz) { return token::T_TAPERZ; } @@ -80,33 +88,26 @@ typedef lol::EasyMeshParser::token_type token_type; (sy|scaley) { return token::T_SCALEY; } (sz|scalez) { return token::T_SCALEZ; } (s|scale) { return token::T_SCALE; } -(tsw|scalewinding) { return token::T_TOGGLESCALEWINDING; } (mx|mirrorx) { return token::T_MIRRORX; } (my|mirrory) { return token::T_MIRRORY; } (mz|mirrorz) { return token::T_MIRRORZ; } -(rj|radialjitter) { return token::T_RADIALJITTER; } +(ch|chamfer) { return token::T_CHAMFER; } (splt|splittriangle) { return token::T_SPLITTRIANGLE; } (smth|smooth) { return token::T_SMOOTHMESH; } -(csgu|csgunion) { return token::T_CSGUNION; } -(csgs|csgsubstract) { return token::T_CSGSUBSTRACT; } -(csgsl|csgsubstractloss) { return token::T_CSGSUBSTRACTLOSS; } -(csga|csgand) { return token::T_CSGAND; } -(csgx|csgxor) { return token::T_CSGXOR; } - -(ab|addbox) { return token::T_BOX; } (ac|addcylinder) { return token::T_CYLINDER; } +(asph|addsphere) { return token::T_SPHERE; } (acap|addcapsule) { return token::T_CAPSULE; } -(acg|addcog) { return token::T_COG; } -(ad|adddisc) { return token::T_DISC; } -(aes|addexpandedstar) { return token::T_EXPANDEDSTAR; } +(ato|addtorus) { return token::T_TORUS; } +(ab|addbox) { return token::T_BOX; } +(ascb|addsmoothchamfbox) { return token::T_SMOOTHCHAMFBOX; } (afcb|addflatchamfbox) { return token::T_FLATCHAMFBOX; } -(aq|addquad) { return token::T_QUAD; } (as|addstar) { return token::T_STAR; } -(ascb|addsmoothchamfbox) { return token::T_SMOOTHCHAMFBOX; } -(asph|adsphere) { return token::T_SPHERE; } +(aes|addexpandedstar) { return token::T_EXPANDEDSTAR; } +(ad|adddisc) { return token::T_DISC; } (at|addtriangle) { return token::T_TRIANGLE; } -(ato|addtorus) { return token::T_TORUS; } +(aq|addquad) { return token::T_QUAD; } +(acg|addcog) { return token::T_COG; } %{ /* ======= BASE DATA TYPES ========================================= */ %} %{ /* COLOR */ %} diff --git a/src/easymesh/easymesh.h b/src/easymesh/easymesh.h index 56ce8514..f19b6941 100644 --- a/src/easymesh/easymesh.h +++ b/src/easymesh/easymesh.h @@ -558,22 +558,25 @@ public: /* [cmd:csgx] Performs a Xor operation as (m0_Outside/m0_Inside-inverted + m1_Outside/m1_Inside-inverted) */ void CsgXor() { MeshCsg(CSGUsage::Xor); } + //------------------------------------------------------------------------- + //Mesh Base operations + //------------------------------------------------------------------------- public: /* [cmd:[] from this point onward, any operation will not be performed on previous vertices */ void OpenBrace(); /* [cmd:]] Merge current vertices with previous context */ void CloseBrace(); - /* [cmd:tsw] When activation, on negative-scaling, normal fixing will not occur */ + /* [cmd:tsw] When activated, on negative-scaling, normal-vector correction will not occur */ void ToggleScaleWinding(); - /* [cmd:sc] Set vertices color */ + /* [cmd:sc] Set base color */ void SetCurColor(vec4 const &color); - /* [cmd:scb] Set vertices color 2 */ + /* [cmd:scb] Set base color 2 */ void SetCurColor2(vec4 const &color); -private: //------------------------------------------------------------------------- //Internal : Basic triangle/vertex operations //------------------------------------------------------------------------- +private: void AddVertex(vec3 const &coord); void AddDuplicateVertex(int i); void AddLerpVertex(int i, int j, float alpha); @@ -586,8 +589,9 @@ public: //DEBUG void ComputeTexCoord(float uv_scale, int uv_offset); //------------------------------------------------------------------------- - //Vertices operations + //Internal : Vertices operations //------------------------------------------------------------------------- +private: void SetVertColor(vec4 const &color); void SetTexCoordData(vec2 const &new_offset, vec2 const &new_scale); void SetTexCoordData2(vec2 const &new_offset, vec2 const &new_scale); @@ -617,11 +621,11 @@ public: - axis : rotation axis. */ void Rotate(float angle, vec3 const &axis); - /* [cmd:rj] Randomly move vertices along Origin-to-vertex as o2v *= (1.0 + rand(r)) + /* [cmd:rj] Randomly move vertices along Origin-to-vertex as f(vtx) = vtx + o2v * (1.0 + rand(r)) - r : jitter maximum value. */ void RadialJitter(float r); - /* [cmd:tax] multiply axis y&z by x as y *= (1.0 + (ny * x + xoff)) + /* [cmd:tax] multiply axis y&z by x as f(y) = y * (1.0 + (ny * x + xoff)) - ny : value of n for y. - nz : value of n for z. - xoff : value of xoff. @@ -632,7 +636,7 @@ public: void TaperY(float nx, float nz, float yoff=0.f, bool absolute=true); /* [cmd:taz] Same as TaperX, with Z */ void TaperZ(float nx, float ny, float zoff=0.f, bool absolute=true); - /* [cmd:twx] Twist vertices around x axis with x as rotation value as p = (RotateX(x * t + toff) * p) + /* [cmd:twx] Twist vertices around x axis with x as rotation value as f(p) = (RotateX(x * t + toff) * p) - t : Angle multiplier. - toff : Applied offset. */ @@ -641,7 +645,7 @@ public: void TwistY(float t, float toff=0.f); /* [cmd:twz] Same as TwistX, with Z */ void TwistZ(float t, float toff=0.f); - /* [cmd:shx] Shear vertices using x value as shear quantity as y += (ny * x + xoff) + /* [cmd:shx] Shear vertices using x value as shear quantity as f(y) = y + (ny * x + xoff) - ny : Value of n for y. - nz : Value of n for z. - xoff : Value of xoff. @@ -652,7 +656,7 @@ public: void ShearY(float nx, float nz, float yoff=0.f, bool absolute=true); /* [cmd:shz] Same as ShearX, with Z */ void ShearZ(float nx, float ny, float zoff=0.f, bool absolute=true); - /* [cmd:stx] Stretch vertices using x value as stretch quantity as y += (pow(x, ny) + xoff) + /* [cmd:stx] Stretch vertices using x value as stretch quantity as f(y) = y + (pow(x, ny) + xoff) - ny : Value of n for y. - nz : Value of n for z. - xoff : Value of xoff. @@ -662,7 +666,7 @@ public: void StretchY(float nx, float nz, float yoff=0.f); /* [cmd:stz] Same as StretchX, with Z */ void StretchZ(float nx, float ny, float zoff=0.f); - /* [cmd:bdxy] Bend vertices using x as bend quantity along y axis using p = (RotateY(x * t + toff) * p) + /* [cmd:bdxy] Bend vertices using x as bend quantity along y axis using f(p) = (RotateY(x * t + toff) * p) - t : Angle multiplier. - xoff : Applied offset. */ @@ -716,11 +720,11 @@ public: Acts as an OpenBrace */ void DupAndScale(vec3 const &s); - /* [cmd:ch] Performs a chamfer operation //TODO : Make it work. + /* [cmd:ch] Performs a chamfer operation //TODO : Make it work - f : Chamfer quantity. */ void Chamfer(float f); - /* [cmd:splt] split triangles in 4 smaller ones. + /* [cmd:splt] split triangles in 4 smaller ones - pass : Number of pass applied. */ void SplitTriangles(int pass); @@ -728,11 +732,11 @@ private: void SplitTriangles(int pass, VertexDictionnary *vert_dict); public: /* [cmd:smth] Smooth the mesh by subdivising it. - - main_pass : a main pass is made of (n0 split then n1 smooth) repeat. - - split_per_main_pass : n0 value in above explanation. - - smooth_per_main_pass : n1 value in above explanation. + - pass : a pass is made of (n0 split then n1 smooth) repeat. + - split_per_pass : n0 value in above explanation. + - smooth_per_pass : n1 value in above explanation. */ - void SmoothMesh(int main_pass, int split_per_main_pass, int smooth_per_main_pass); + void SmoothMesh(int pass, int split_per_pass, int smooth_per_pass); //------------------------------------------------------------------------- //Mesh shape operations @@ -769,7 +773,6 @@ public: /* [cmd:ab] Box centered on (0,0,0) with BBox [-.5 * size][.5 * size] - size : size of the box. - chamf : size of the chamfer. - - smooth : if (true) will smooth normals : TOOD:TOREMOVE : smooth should be handled elsewhere */ void AppendBox(vec3 const &size, float chamf=0.f); //Same as AppendBox diff --git a/test/EasyMeshDictionnary.js b/test/EasyMeshDictionnary.js new file mode 100644 index 00000000..5f277a52 --- /dev/null +++ b/test/EasyMeshDictionnary.js @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------- +//Command vars operations +//------------------------------------------------------------------------- +CmdVar("float", ["Fraction value", "0.0"]); +CmdVar("int", ["No decimal value", "0"]); +CmdVar("bool", ["Boolean value", "true/false", "1/0"]); +CmdVar("color", ["Red/Green/Blue/{Alpha}", + "HEXA: #ABC{D}", " #AABBCC{DD}", + "FLOAT: f f f f", " (f f f f)", " (f)"]); +CmdVar("vec3", ["X/Y/Z as float", " f f f", "(f f f)", "(f)"]); + +//------------------------------------------------------------------------- +//Mesh CSG operations +//------------------------------------------------------------------------- +CmdType(["csgu", "csgunion"], "Performs a Union operation as (mesh0_Outside + mesh1_Outside)"); +CmdType(["csgs", "csgsubstract"], "Performs a Substract operation as (mesh0_Outside + mesh1_Inside-inverted)"); +CmdType(["csgsl", "csgsubstractloss"], "Performs a Substract operation without keeping the mesh1 part"); +CmdType(["csga", "csgand"], "Performs an And operation as (mesh0_Inside + mesh1_Inside)"); +CmdType(["csgx", "csgxor"], "Performs a Xor operation as (m0_Outside/m0_Inside-inverted + m1_Outside/m1_Inside-inverted)"); + +//------------------------------------------------------------------------- +//Mesh Base operations +//------------------------------------------------------------------------- +CmdType(["tsw", "scalewinding"], "When activated, on negative-scaling,\nnormal-vector correction will not occur"); +CmdType(["sc", "setcolor"], "Set A color", [CmdArg("color", "color")]); +CmdType(["scb", "setbgcolor"], "Set B color", [CmdArg("color", "color")]); + +//------------------------------------------------------------------------- +//Mesh transform operations +//------------------------------------------------------------------------- +CmdType(["tx", "translatex"], "Translate vertices along the X axis", [CmdArg("float", "n")]); +CmdType(["ty", "translatey"], "Translate vertices along the Y axis", [CmdArg("float", "n")]); +CmdType(["tz", "translatez"], "Translate vertices along the Z axis", [CmdArg("float", "n")]); +CmdType(["t", "translate"], "Translate vertices", [CmdArg("vec3", "v")]); +CmdType(["rx", "rotatex"], "Rotate vertices along the X axis", [CmdArg("float", "degree")]); +CmdType(["ry", "rotatey"], "Rotate vertices along the Y axis", [CmdArg("float", "degree")]); +CmdType(["rz", "rotatez"], "Rotate vertices along the Z axis", [CmdArg("float", "degree")]); +CmdType(["r", "rotate"], "Rotate vertices along the given axis", [CmdArg("float", "degree"), CmdArg("vec3", "axis")]); +CmdType(["rj", "radialjitter"], "Randomly move vertices along Origin-to-vertex as f(vtx) = vtx + o2v * (1.0 + rand(r))", [CmdArg("float", "r")]); +CmdType(["tax", "taperx"], "multiply axis y/z by f(x)\nf(z) = z * (1.0 + (nz * f(x) + xoff))\nf(x) = absolute ? abs_x : x", [CmdArg("float", "ny"), CmdArg("float", "nz"), CmdArg("float", "xoff", "0.0"), CmdArg("bool", "absolute", "true")]); +CmdType(["tay", "tapery"], "multiply axis x/z by f(y)\nf(x) = x * (1.0 + (nx * f(y) + yoff))\nf(y) = absolute ? abs_y : y", [CmdArg("float", "nx"), CmdArg("float", "nz"), CmdArg("float", "yoff", "0.0"), CmdArg("bool", "absolute", "true")]); +CmdType(["taz", "taperz"], "multiply axis x/y by f(z)\nf(y) = y * (1.0 + (ny * f(z) + zoff))\nf(z) = absolute ? abs_z : z", [CmdArg("float", "nx"), CmdArg("float", "ny"), CmdArg("float", "zoff", "0.0"), CmdArg("bool", "absolute", "true")]); +CmdType(["twx", "twistx"], "Twist vertices around x axis with x as rotation value\nf(p) = (RotateX(x * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["twy", "twisty"], "Twist vertices around y axis with y as rotation value\nf(p) = (RotateY(y * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["twz", "twistz"], "Twist vertices around z axis with z as rotation value\nf(p) = (RotateZ(z * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["shx", "shearx"], "Shear vertices using x value as shear quantity\nf(z) = z + (nz * f(x) + xoff)\nf(x) = absolute ? abs_x : x", [CmdArg("float", "ny"), CmdArg("float", "nz"), CmdArg("float", "xoff", "0.0"), CmdArg("bool", "absolute", "true")]); +CmdType(["shy", "sheary"], "Shear vertices using y value as shear quantity\nf(x) = x + (nx * f(y) + yoff)\nf(y) = absolute ? abs_y : y", [CmdArg("float", "nx"), CmdArg("float", "nz"), CmdArg("float", "yoff", "0.0"), CmdArg("bool", "absolute", "true")]); +CmdType(["shz", "shearz"], "Shear vertices using z value as shear quantity\nf(y) = y + (ny * f(z) + zoff)\nf(z) = absolute ? abs_z : z", [CmdArg("float", "nx"), CmdArg("float", "ny"), CmdArg("float", "zoff", "0.0"), CmdArg("bool", "absolute", "true")]); +CmdType(["stx", "stretchx"], "Stretch vertices using x value as stretch quantity\nf(z) = z + (pow(x, nz) + xoff)", [CmdArg("float", "ny"), CmdArg("float", "nz"), CmdArg("float", "xoff", "0.0")]); +CmdType(["sty", "stretchy"], "Stretch vertices using y value as stretch quantity\nf(x) = x + (pow(y, nx) + yoff)", [CmdArg("float", "nx"), CmdArg("float", "nz"), CmdArg("float", "yoff", "0.0")]); +CmdType(["stz", "stretchz"], "Stretch vertices using z value as stretch quantity\nf(y) = y + (pow(z, ny) + zoff)", [CmdArg("float", "nx"), CmdArg("float", "ny"), CmdArg("float", "zoff", "0.0")]); +CmdType(["bdxy", "bendxy"], "Bend vertices using x as bend quantity along y axis\nf(p) = (RotateY(x * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["bdxz", "bendxz"], "Bend vertices using x as bend quantity along z axis\nf(p) = (RotateZ(x * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["bdyx", "bendyx"], "Bend vertices using y as bend quantity along x axis\nf(p) = (RotateX(y * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["bdyz", "bendyz"], "Bend vertices using y as bend quantity along z axis\nf(p) = (RotateZ(y * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["bdzx", "bendzx"], "Bend vertices using z as bend quantity along x axis\nf(p) = (RotateX(z * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["bdzy", "bendzy"], "Bend vertices using z as bend quantity along y axis\nf(p) = (RotateY(z * t + toff) * p)", [CmdArg("float", "t"), CmdArg("float", "toff", "0.0")]); +CmdType(["sx", "scalex"], "Scale vertices", [CmdArg("vec3", "s")]); +CmdType(["sy", "scaley"], "Scale vertices", [CmdArg("vec3", "s")]); +CmdType(["sz", "scalez"], "Scale vertices", [CmdArg("vec3", "s")]); +CmdType(["s", "scale"], "Uniformly Scale vertices", [CmdArg("float", "s")]); +CmdType(["mx", "mirrorx"], "Mirror vertices through X-plane"); +CmdType(["my", "mirrory"], "Mirror vertices through Y-plane"); +CmdType(["mz", "mirrorz"], "Mirror vertices through Z-plane"); +CmdType(["ch", "chamfer"], "DOES NOT WORK: Performs a chamfer operation", [CmdArg("float", "f")]); +CmdType(["splt", "splittriangle"], "split triangles in 4 smaller ones", [CmdArg("int", "pass")]); +CmdType(["smth", "smooth"], "Smooth the mesh by subdivising it", [CmdArg("int", "pass"), CmdArg("int", "split_per_pass"), CmdArg("int", "smooth_per_pass")]); + +//------------------------------------------------------------------------- +//Mesh shape operations +//------------------------------------------------------------------------- +CmdType(["ac", "addcylinder"], "Cylinder centered on (0,0,0) with BBox:\nMin: [-.5 * max(d1, d2),-.5 * h,-.5 * max(d1, d2)]\nMax: [ .5 * max(d1, d2), .5 * h, .5 * max(d1, d2)]", + [CmdArg("int", "nsides"), CmdArg("float", "h"), CmdArg("float", "d1"), CmdArg("float", "d2"), + CmdArg("bool", "dualsides", "false"), CmdArg("bool", "smooth", "false"), CmdArg("bool", "close", "false")]); +CmdType(["asph", "addsphere"], "Sphere centered on (0,0,0) with BBox:\nMin: [-.5 * d]\nMax: [ .5 * d]", [CmdArg("int", "ndivisions"), CmdArg("float", "d")]); +CmdType(["acap", "addcapsule"], "Capsule centered on (0,0,0) with BBox:\nMin: [-.5 * d,-(.5 * d + h),-.5 * d]\nMax: [ .5 * d, (.5 * d + h), .5 * d]", [CmdArg("int", "ndivisions"), CmdArg("float", "h"), CmdArg("float", "d")]); +CmdType(["ato", "addtorus"], "Torus centered on (0,0,0) with BBox:\nMax: [-.5 * d2]\nMax: [ .5 * d2]", [CmdArg("int", "ndivisions"), CmdArg("float", "d1"), CmdArg("float", "d2")]); +CmdType(["ab", "addbox"], "Box centered on (0,0,0) with BBox:\nMin: [-.5 * size]\nMax: [ .5 * size]", [CmdArg("vec3", "size"), CmdArg("float", "chamf", "0.0")]); +CmdType(["ascb", "addsmoothchamfbox"], "Box centered on (0,0,0) with BBox:\nMin: [-.5 * size]\nMax: [ .5 * size]", [CmdArg("vec3", "size"), CmdArg("float", "chamf")]); +CmdType(["afcb", "addflatchamfbox"], "Box centered on (0,0,0) with BBox:\nMin: [-.5 * size]\nMax: [ .5 * size]", [CmdArg("vec3", "size"), CmdArg("float", "chamf")]); +CmdType(["as", "addstar"], "Append a Star centered on (0,0,0)\nContained in a disc of max(d1, d2) diameter.", + [CmdArg("int", "nbranches"), CmdArg("float", "d1"), CmdArg("float", "d2"), + CmdArg("bool", "fade", "false"), CmdArg("bool", "fade2", "false")]); +CmdType(["aes", "addexpandedstar"], "Star centered on (0,0,0)\nContained in a disc of max(max(d1, d2), max(d1 + extrad, d2 + extrad)) diameter.\nExpanded star branches use Color2.", + [CmdArg("int", "nbranches"), CmdArg("float", "d1"), CmdArg("float", "d2"), CmdArg("float", "extrad", "0.0")]); +CmdType(["ad", "adddisc"], "Disc centered on (0,0,0) with d diameter.", [CmdArg("int", "nsides"), CmdArg("float", "d"), CmdArg("bool", "fade", "false")]); +CmdType(["at", "addtriangle"], "Triangle centered on (0,0,0)\nContained in a disc of d diameter.", [CmdArg("float", "d"), CmdArg("bool", "fade", "false")]); +CmdType(["aq", "addquad"], "Quad centered on (0,0,0) with BBox:\nMin: [-size * .5f, 0,-size * .5f]\nMax: [ size * .5f, 0, size * .5f]", [CmdArg("float", "size"), CmdArg("bool", "fade", "false")]); +CmdType(["acg", "addcog"], "Gear centered on (0,0,0) with BBox:\nMin: [-.5 * max(d1, d2),-.5 * h,-.5 * max(d1, d2)]\nMax: [ .5 * max(d1, d2), .5 * h, .5 * max(d1, d2)]", + [CmdArg("float", "h"), CmdArg("float", "d10"), CmdArg("float", "d20"), CmdArg("float", "d1"), CmdArg("float", "d2"), CmdArg("float", "d12"), CmdArg("float", "d22"), + CmdArg("float", "sidemul", "1.0"), CmdArg("bool", "offset", "false")]); diff --git a/test/TypeDictionnary.js b/test/TypeDictionnary.js new file mode 100644 index 00000000..54177d00 --- /dev/null +++ b/test/TypeDictionnary.js @@ -0,0 +1,158 @@ +function TypeDictionnary(m_name) +{ + this.m_name = m_name; + this.m_cmds = new Array(); + this.m_vars = new Array(); +} + +//----------------------------------------------------------------------------- +//Command Var object +//----------------------------------------------------------------------------- +function CmdVarObj() { } +function CmdVar(m_type, m_syntax) +{ + var current_mesh_dict = GetCmdDictionnary(); + new_obj = new CmdVarObj(); + new_obj.m_type = m_type; + new_obj.m_syntax = m_syntax; + new_obj.ToString = function() + { + var res = m_type + ' '; + if (m_syntax != undefined) + for (var i = 0; i < m_syntax.length; i++) + res += m_syntax[i] + ' '; + } + current_mesh_dict.m_vars[current_mesh_dict.m_vars.length] = new_obj; +} + +//----------------------------------------------------------------------------- +//Command Argument object +//----------------------------------------------------------------------------- +function CmdArgObj() { } +function CmdArg(m_type, m_name, m_optional) +{ + new_obj = new CmdArgObj(); + new_obj.m_type = m_type; + new_obj.m_name = m_name; + new_obj.m_optional = m_optional; + new_obj.ToString = function() + { + if (m_optional != undefined) + return m_type + ' ' + m_name + ' = ' + m_optional; + return m_type + ' ' + m_name; + } + return new_obj; +} + +//----------------------------------------------------------------------------- +//Command Typing object +//----------------------------------------------------------------------------- +function CmdTypeObj() { } +function CmdType(m_name, m_comment, m_arg) +{ + var current_mesh_dict = GetCmdDictionnary(); + new_obj = new CmdTypeObj(); + new_obj.m_name = m_name; + new_obj.m_comment = m_comment; + new_obj.m_arg = m_arg; + new_obj.ToString = function() + { + var str = m_name.toString() + ' [' + m_comment + ']'; + if (m_arg != undefined) + { + str += '{'; + var found_optional = false; + for (var vi = 0; vi < m_arg.length; vi++) + { + if (m_arg[vi].m_optional != undefined && found_optional == false) + { + str += ' ['; + found_optional = true; + } + if (vi != 0) + str += ', '; + str += m_arg[vi].ToString(); + } + if (found_optional == true) + str += ']'; + str += '}'; + } + return str; + } + new_obj.CheckCommand = function(check_name) + { + if (m_name != undefined && check_name.length > 0) + { + for (var i = 0; i < m_name.length; i++) + { + if (m_name[i] != undefined) + { + var pattern = new RegExp("^[ ]*" + check_name + "[a-z]*"); + if (pattern.test(m_name[i])) + return true; + } + } + } + return false; + } + current_mesh_dict.m_cmds[current_mesh_dict.m_cmds.length] = new_obj; +} + +//----------------------------------------------------------------------------- +//Tries to find a matching command in the dictionnary based on the current cursor location in the given TextArea. +//----------------------------------------------------------------------------- +function FindMatchingCommand(src_text_area) +{ + if (src_text_area != undefined) + { + var current_mesh_dict = GetCmdDictionnary(); + var found_match = ""; + var check = true; + var cursor = Math.min(src_text_area.selectionStart, src_text_area.value.length - 1); + //Weird test to ensure we don't start searching on the next line or on the next word. + if (!src_text_area.value[cursor].match(/^[ \n]$/)) + cursor++; + cursor = Math.min(cursor, src_text_area.value.length - 1); + + var o = 0; + while (check && o < 10) + { + //Move backward to find the first letter on this line + for (; cursor > 0; cursor--) + if (src_text_area.value[cursor].match(/^[a-z\n]+$/)) + break; + + //Move backward to find the start of the command + for (; cursor > 0; cursor--) + if (!src_text_area.value[cursor - 1].match(/^[#0-9a-z]+$/)) + break; + + //If the cursor is on a "#" and the previous is a " ", we're on a color, repeat the operation + if (cursor > 0 && src_text_area.value[cursor - 1].match(/[ ]/) && + src_text_area.value[cursor].match(/[#]/)) + check = true; + else + check = false; + o++; + } + + //Move forward to find the end of the word + for (; cursor < src_text_area.value.length; cursor++) + { + if (src_text_area.value[cursor].match(/^[a-z]+$/)) + found_match += src_text_area.value[cursor]; + else + break; + } + + //Try to match the command with the dictionnary + var match_data = new Object(); + match_data.match = found_match; + match_data.match_list = new Array(); + for (cursor = 0; cursor < current_mesh_dict.m_cmds.length; cursor++) + if (current_mesh_dict.m_cmds[cursor].CheckCommand(found_match)) + match_data.match_list[match_data.match_list.length] = cursor; + + return match_data; + } +} diff --git a/test/data/mesh-buffer.txt b/test/data/mesh-buffer.txt index c6a8ea47..e5d2a698 100644 --- a/test/data/mesh-buffer.txt +++ b/test/data/mesh-buffer.txt @@ -1,7 +1,18 @@ -[sc#f8f ab 1 splt 4 twy 90] +sc#f8f afcb 1 1 1 0 + + + + + + + + +//test +//[sc#f8f ab 1 splt 4 twy 90] + // splt 5 twy 90 0 //[sc#f8f afcb 10 10 10 .25 tx 0 splt 4 twy 1.6 0 ] //sc#fff diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index 8dacaf75..bcd9e9e1 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -24,8 +24,10 @@ using namespace lol; static int const TEXTURE_WIDTH = 256; #define R_M 2.f -#define WIDTH (770.f * R_M) -#define HEIGHT (200.f * R_M) +#define DEFAULT_WIDTH (770.f * R_M) +#define DEFAULT_HEIGHT (200.f * R_M) +#define WIDTH ((float)Video::GetSize().x) +#define HEIGHT ((float)Video::GetSize().y) #define SCREEN_W (10.f / WIDTH) #define SCREEN_LIMIT 1.1f #define RATIO_HW (HEIGHT / WIDTH) @@ -522,7 +524,7 @@ int main(int argc, char **argv) { System::Init(argc, argv); - Application app("MeshViewer", ivec2((int)WIDTH, (int)HEIGHT), 60.0f); + Application app("MeshViewer", ivec2((int)DEFAULT_WIDTH, (int)DEFAULT_HEIGHT), 60.0f); if (argc > 1) new MeshViewer(argv[1]); else diff --git a/test/meshviewer.vcxproj b/test/meshviewer.vcxproj index e4ec6b52..8b422b03 100644 --- a/test/meshviewer.vcxproj +++ b/test/meshviewer.vcxproj @@ -60,12 +60,14 @@ true + true true + diff --git a/test/meshviewer_index.html b/test/meshviewer_index.html index 37384cbc..23a5e6ea 100644 --- a/test/meshviewer_index.html +++ b/test/meshviewer_index.html @@ -1,4 +1,4 @@ - + - Mesh Viewer NaCl - - + + + + + Mesh Viewer : Native Client version. - + - - test - + NO-STATUS - + - + + - + -Status - - - -//This is a comment -sc#f8f afcb 1 1 1 0 - - - - Update Mesh - +Send Mesh Command ! + + + + + //This is a comment +sc#f8f afcb 1 1 1 0 + + + + + Variable Types usage : + + + + + + + + + + + + + + + + + + + + +
-