//sculptlist: fix bugs. It works!

This commit is contained in:
Starbeamrainbowlabs 2021-12-27 19:36:57 +00:00
parent 10c9d6f886
commit d657ce1abe
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
8 changed files with 34 additions and 15 deletions

@ -57,7 +57,7 @@ dofile(wea.modpath.."/lib/spiral_circle.lua")
dofile(wea.modpath.."/lib/conv/conv.lua") dofile(wea.modpath.."/lib/conv/conv.lua")
dofile(wea.modpath.."/lib/erode/erode.lua") dofile(wea.modpath.."/lib/erode/erode.lua")
dofile(wea.modpath.."/lib/noise/init.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/copy.lua")
dofile(wea.modpath.."/lib/move.lua") dofile(wea.modpath.."/lib/move.lua")

@ -1,6 +1,7 @@
local wea = worldeditadditions
--- Returns a smooth gaussian brush. --- 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. -- @param sigma=2 number The 'smoothness' of the brush. Higher values are more smooth.
return function(size, sigma) return function(size, sigma)
local size = math.min(size.x, size.y) local size = math.min(size.x, size.y)
@ -9,5 +10,13 @@ return function(size, sigma)
return false, "Error: Invalid brush size." return false, "Error: Invalid brush size."
end end
local success, gaussian = worldeditadditions.conv.kernel_gaussian(size, sigma) 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 } return success, gaussian, { x = size, y = size }
end end

@ -3,6 +3,6 @@ local wea = worldeditadditions
local __smooth = dofile(wea.modpath.."/lib/sculpt/brushes/__smooth.lua") local __smooth = dofile(wea.modpath.."/lib/sculpt/brushes/__smooth.lua")
return function(size) 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 return success, brush, size_actual
end end

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

@ -13,6 +13,8 @@ local sculpt = {
apply = dofile(wea.modpath.."/lib/sculpt/apply.lua") apply = dofile(wea.modpath.."/lib/sculpt/apply.lua")
} }
return sculpt
-- TODO: Automatically find & register all text file based brushes in the brushes directory -- 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 -- 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

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

@ -33,7 +33,7 @@ end
function worldeditadditions.min(list) function worldeditadditions.min(list)
if #list == 0 then return nil end if #list == 0 then return nil end
local min = nil local min = nil
for i,value in ipairs(list) do for i,value in pairs(list) do
if min == nil or min > value then if min == nil or min > value then
min = value min = value
end end
@ -46,8 +46,11 @@ end
-- @returns number The maximum value in the given list. -- @returns number The maximum value in the given list.
function worldeditadditions.max(list) function worldeditadditions.max(list)
if #list == 0 then return nil end 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 local max = nil
for i,value in ipairs(list) do for i,value in pairs(list) do
if max == nil or max < value then if max == nil or max < value then
max = value max = value
end end

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