diff --git a/context/cube.lua b/context/cube.lua index f026976..c894edc 100644 --- a/context/cube.lua +++ b/context/cube.lua @@ -1,8 +1,7 @@ function mtscad.Context:cube(x, y, z) - -- TODO: deal with negative sizes - local pos2 = vector.add(self.pos, {x=x-1, y=y-1, z=z-1}) + -- TODO: prevent negative sizes local pos1 = vector.copy(self.pos) - pos1, pos2 = mtscad.sort_pos(pos1, pos2) + local pos2 = vector.add(self.pos, {x=x-1, y=y-1, z=z-1}) for xi=pos1.x,pos2.x do for yi=pos1.y,pos2.y do diff --git a/context/grid.lua b/context/grid.lua new file mode 100644 index 0000000..f6ff076 --- /dev/null +++ b/context/grid.lua @@ -0,0 +1,20 @@ + +function mtscad.Context:grid(x, y, z) + -- TODO: prevent negative sizes + local pos1 = vector.copy(self.pos) + local pos2 = vector.add(self.pos, {x=x-1, y=y-1, z=z-1}) + + -- TODO: lines between outer positions + for xi=pos1.x,pos2.x,x-1 do + for yi=pos1.y,pos2.y,y-1 do + for zi=pos1.z,pos2.z,z-1 do + local ipos = { x=xi, y=yi, z=zi } + local tpos = mtscad.transform_pos(pos1, ipos, self.rotation) + local tnode = mtscad.transform_node(self.node, self.rotation) + minetest.set_node(tpos, tnode) + end + end + end + return self +end + diff --git a/init.lua b/init.lua index 469c5b6..81b2fa7 100644 --- a/init.lua +++ b/init.lua @@ -8,6 +8,7 @@ dofile(MP .. "/context/execute.lua") dofile(MP .. "/context/translate.lua") dofile(MP .. "/context/rotate.lua") dofile(MP .. "/context/cube.lua") +dofile(MP .. "/context/grid.lua") dofile(MP .. "/context/slope.lua") dofile(MP .. "/util.lua") dofile(MP .. "/test.lua") \ No newline at end of file diff --git a/test.lua b/test.lua index bdba6de..228b01f 100644 --- a/test.lua +++ b/test.lua @@ -1,15 +1,4 @@ -local function cube_outliers(ctx, size) - ctx - :cube(size, 1, 1) - :cube(1, size, 1) - :cube(1, 1, size) - :translate(size-1, 0, size-1) - :cube(-size, 1, 1) - :cube(1, size, 1) - :cube(1, 1, -size) -end - local function rot_test(ctx) ctx :with({ name="wool:red" }) @@ -43,7 +32,7 @@ local function test_code(ctx) ctx :with({ name="default:copperblock" }) :translate(2,2,2) - :execute(cube_outliers, 5) + :grid(5, 5, 5) end minetest.register_chatcommand("test", {