openscad.lua: make inverted simpler and more betterererererer

This commit is contained in:
Starbeamrainbowlabs 2020-04-30 11:39:56 +01:00
parent f3a1874ab0
commit 589d2451ee
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
1 changed files with 5 additions and 6 deletions

View File

@ -5,17 +5,16 @@ function M.write3d(maze, width, height, depth, filename)
local inverted = true
local out = io.open(filename, "w")
out:write("// Generated by multimaze (lua)\n")
out:write("// Hit the Render button (F6) to make the preview look better")
out:write("// Hit the Render button (F6) to make the preview look better\n")
out:write("// Uncomment to make the preview look transclucent")
out:write("// Uncomment to make the preview look transclucent\n")
out:write("// color(\"red\", 0.25)\n");
if inverted then out:write("difference() {\n\tcube(size=["..scale*width..", "..scale*height..", "..scale*depth.."])")
else out:write("union() {") end
out:write("\n")
out:write("union() {\n")
for z = 0, depth - 1, 1 do
for y = 0, height - 1, 1 do
for x = 0, width - 1, 1 do
if maze[z][y][x] == "#" then
if (maze[z][y][x] == "#" and not inverted) or
(maze[z][y][x] == " " and inverted) then
out:write("\ttranslate(["..x*scale..", "..y*scale..", "..z*scale.."]) cube(size = "..scale..");\n")
end
end