Minetest-WorldEditAdditions/worldeditadditions/lib/sculpt/brushes/circle_soft1.lua

48 lines
1.1 KiB
Lua
Raw Normal View History

2021-12-28 18:32:40 +00:00
local wea = worldeditadditions
2022-09-19 00:16:22 +00:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
2021-12-28 18:32:40 +00:00
return function(size)
local brush = {}
local centre = (size / 2):floor()
local minsize = math.floor(math.min(size.x, size.y) / 2)
local border = 1
local kernel_size = 3
-- Make the circle
-- We don't use 0 to 1 here, because we have to blur it and the existing convolutional
-- system rounds values.
for y = size.y - 1, 0, -1 do
for x = size.x - 1, 0, -1 do
local i = y*size.x + x
if math.floor((centre - Vector3.new(x, y, 0)):length()) < minsize - border then
brush[i] = 100000
else
brush[i] = 0
end
end
end
-- Make the kernel & blur it
local success, kernel = wea.conv.kernel_gaussian(kernel_size, 2)
if not success then return success, kernel end
2022-09-19 00:16:22 +00:00
local success2, msg = wea.conv.convolve(
2021-12-28 18:32:40 +00:00
brush, Vector3.new(size.x, 0, size.y),
kernel, Vector3.new(kernel_size, 0, kernel_size)
2021-12-28 18:32:40 +00:00
)
if not success2 then return success2, msg end
-- Rescale to be between 0 and 1
2022-09-19 00:16:22 +00:00
local max_value = wea_c.max(brush)
2021-12-28 18:32:40 +00:00
for i,value in pairs(brush) do
brush[i] = brush[i] / max_value
end
return true, brush, size
end