//sculptlist: fix bugs. It works!

This commit is contained in:
Starbeamrainbowlabs 2021-12-27 19:36:57 +00:00
parent 10c9d6f886
commit d657ce1abe
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
8 changed files with 34 additions and 15 deletions

View File

@ -57,7 +57,7 @@ dofile(wea.modpath.."/lib/spiral_circle.lua")
dofile(wea.modpath.."/lib/conv/conv.lua")
dofile(wea.modpath.."/lib/erode/erode.lua")
dofile(wea.modpath.."/lib/noise/init.lua")
dofile(wea.modpath.."/lib/sculpt/init.lua")
wea.sculpt = dofile(wea.modpath.."/lib/sculpt/init.lua")
dofile(wea.modpath.."/lib/copy.lua")
dofile(wea.modpath.."/lib/move.lua")

View File

@ -1,6 +1,7 @@
local wea = worldeditadditions
--- Returns a smooth gaussian brush.
-- @param size Vector3 The target size of the brush. Note that the actual size fo the brush will be different, as the gaussian function has some limitations.
-- @param size Vector3 The target size of the brush. Note that the actual size of the brush will be different, as the gaussian function has some limitations.
-- @param sigma=2 number The 'smoothness' of the brush. Higher values are more smooth.
return function(size, sigma)
local size = math.min(size.x, size.y)
@ -9,5 +10,13 @@ return function(size, sigma)
return false, "Error: Invalid brush size."
end
local success, gaussian = worldeditadditions.conv.kernel_gaussian(size, sigma)
-- Normalise values to fill the range 0 - 1
-- By default, wea.conv.kernel_gaussian values add up to 1 in total
local max = wea.max(gaussian)
for i=0,size*size-1 do
gaussian[i] = gaussian[i] / max
end
return success, gaussian, { x = size, y = size }
end

View File

@ -3,6 +3,6 @@ local wea = worldeditadditions
local __smooth = dofile(wea.modpath.."/lib/sculpt/brushes/__smooth.lua")
return function(size)
local success, brush, size_actual = __smooth(size, 1)
local success, brush, size_actual = __smooth(size, 1.25)
return success, brush, size_actual
end

View File

@ -3,6 +3,6 @@ local wea = worldeditadditions
local __smooth = dofile(wea.modpath.."/lib/sculpt/brushes/__smooth.lua")
return function(size)
local success, brush, size_actual = __smooth(size, 5)
local success, brush, size_actual = __smooth(size, 3)
return success, brush, size_actual
end

View File

@ -13,6 +13,8 @@ local sculpt = {
apply = dofile(wea.modpath.."/lib/sculpt/apply.lua")
}
return sculpt
-- TODO: Automatically find & register all text file based brushes in the brushes directory
-- TODO: Implement automatic scaling of static brushes to the correct size. We have ..scale already, but we probably need to implement a proper 2d canvas scaling algorithm. Some options to consider: linear < [bi]cubic < nohalo/lohalo

View File

@ -22,15 +22,17 @@ local function preview_brush(brush_name, target_size)
values["."] = 1
values[" "] = 0
print(wea.inspect(brush))
local result = {}
for z = target_size.z, 0, -1 do
for y = brush_size.y-1, 0, -1 do
local row = {}
for x = target_size.x, 0, -1 do
local i = z*brush_size.x + x
for x = brush_size.x-1, 0, -1 do
local i = y*brush_size.x + x
local pixel = " "
local threshold_cur = -1
for value,threshold in pairs(values) do
if brush[i] > threshold and threshold_cur < threshold then
if brush[i] * 10 > threshold and threshold_cur < threshold then
pixel = value
threshold_cur = threshold
end
@ -39,8 +41,8 @@ local function preview_brush(brush_name, target_size)
end
table.insert(result, table.concat(row))
end
return true, table.concat(result)
print("RESULT", wea.inspect(result))
return true, table.concat(result, "\n")
end
return preview_brush

View File

@ -33,7 +33,7 @@ end
function worldeditadditions.min(list)
if #list == 0 then return nil end
local min = nil
for i,value in ipairs(list) do
for i,value in pairs(list) do
if min == nil or min > value then
min = value
end
@ -46,8 +46,11 @@ end
-- @returns number The maximum value in the given list.
function worldeditadditions.max(list)
if #list == 0 then return nil end
-- We use pairs() instead of ipairs() here, because then we can support
-- zero-indexed 1D heightmaps too - and we don't care that the order is
-- undefined with pairs().
local max = nil
for i,value in ipairs(list) do
for i,value in pairs(list) do
if max == nil or max < value then
max = value
end

View File

@ -20,13 +20,16 @@ minetest.register_chatcommand("/sculptlist", {
if params_text == "preview" then
for brush_name, brush_def in pairs(wea.sculpt.brushes) do
local preview = wea.sculpt.preview_brush(brush_name)
local success, preview = wea.sculpt.preview_brush(brush_name)
local brush_size = "dynamic"
if type(brush_size) ~= "function" then
if type(brush_def) ~= "function" then
brush_size = brush_def.size
end
print("//sculptlist: preview for "..brush_name..":")
print(preview)
table.insert(msg, brush_name.." ["..brush_size.."]:\n")
table.insert(msg, preview.."\n\n")
end
@ -34,7 +37,7 @@ minetest.register_chatcommand("/sculptlist", {
local display = { { "Name", "Native Size" } }
for brush_name, brush_def in pairs(wea.sculpt.brushes) do
local brush_size = "dynamic"
if type(brush_size) ~= "function" then
if type(brush_def) ~= "function" then
brush_size = brush_def.size
end