2024-05-19 11:24:40 +02:00
|
|
|
|
2024-05-19 17:22:30 +02:00
|
|
|
local function clamp(v, min, max)
|
|
|
|
if v > max then
|
|
|
|
return max
|
|
|
|
elseif v < min then
|
|
|
|
return min
|
|
|
|
else
|
|
|
|
return v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function color_adjust(c, v)
|
|
|
|
return {
|
|
|
|
a = c.a,
|
|
|
|
r = clamp(c.r + v, 0, 255),
|
|
|
|
g = clamp(c.g + v, 0, 255),
|
|
|
|
b = clamp(c.b + v, 0, 255)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-05-22 09:40:07 +02:00
|
|
|
function isogen.draw(pos1, pos2, cube_len)
|
2024-05-19 17:22:30 +02:00
|
|
|
local min, max = vector.sort(pos1, pos2)
|
2024-05-19 11:24:40 +02:00
|
|
|
cube_len = cube_len or 24
|
|
|
|
|
2024-05-19 17:22:30 +02:00
|
|
|
minetest.load_area(min, max)
|
|
|
|
|
|
|
|
local size = vector.add(vector.subtract(max, min), 1)
|
2024-05-19 11:24:40 +02:00
|
|
|
local width, height = isogen.calculate_image_size(size, cube_len)
|
2024-05-19 17:22:30 +02:00
|
|
|
local center_x, center_y = isogen.get_center_cube_offset(size, cube_len)
|
2024-05-19 11:24:40 +02:00
|
|
|
local canvas = isogen.create_canvas(width, height)
|
|
|
|
|
2024-05-19 17:22:30 +02:00
|
|
|
local ipos = vector.new(1, -1, 1)
|
|
|
|
local list = {}
|
|
|
|
|
|
|
|
-- top layer
|
|
|
|
for x=min.x, max.x do
|
|
|
|
for z=min.z, max.z do
|
2024-05-22 10:32:27 +02:00
|
|
|
isogen.probe_position(min, max, vector.new(x, max.y, z), ipos, list)
|
2024-05-19 17:22:30 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- left layer (without top stride)
|
|
|
|
for x=min.x, max.x do
|
|
|
|
for y=min.y, max.y-1 do
|
2024-05-22 10:32:27 +02:00
|
|
|
isogen.probe_position(min, max, vector.new(x, y, min.z), ipos, list)
|
2024-05-19 17:22:30 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- right layer (without top and left stride)
|
|
|
|
for z=min.z+1, max.z do
|
|
|
|
for y=min.y, max.y-1 do
|
2024-05-22 10:32:27 +02:00
|
|
|
isogen.probe_position(min, max, vector.new(min.x, y, z), ipos, list)
|
2024-05-19 17:22:30 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-19 17:31:03 +02:00
|
|
|
table.sort(list, function(a, b)
|
|
|
|
return a.order < b.order
|
|
|
|
end)
|
2024-05-19 17:22:30 +02:00
|
|
|
|
|
|
|
for _, entry in ipairs(list) do
|
|
|
|
local rel_pos = vector.subtract(entry.pos, min)
|
2024-05-22 10:32:27 +02:00
|
|
|
local color = entry.color
|
|
|
|
local x, y = isogen.get_cube_position(center_x, center_y, cube_len, 0, rel_pos)
|
|
|
|
isogen.draw_cube(canvas, cube_len, x, y, color, color_adjust(color, -10), color_adjust(color, 10))
|
2024-05-19 17:22:30 +02:00
|
|
|
end
|
|
|
|
|
2024-05-19 11:24:40 +02:00
|
|
|
return canvas:png()
|
|
|
|
end
|