From 3e2687f82d3e42a01629f8939caf3bc5cb369797 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 28 Dec 2021 18:32:40 +0000 Subject: [PATCH] Add soft circle brush --- .../lib/sculpt/brushes/circle_soft1.lua | 56 +++++++++++++++++++ worldeditadditions/lib/sculpt/init.lua | 3 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 worldeditadditions/lib/sculpt/brushes/circle_soft1.lua diff --git a/worldeditadditions/lib/sculpt/brushes/circle_soft1.lua b/worldeditadditions/lib/sculpt/brushes/circle_soft1.lua new file mode 100644 index 0000000..dac76b0 --- /dev/null +++ b/worldeditadditions/lib/sculpt/brushes/circle_soft1.lua @@ -0,0 +1,56 @@ +local wea = worldeditadditions +local Vector3 = wea.Vector3 + + +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 + local kernel_size_vec = {} + kernel_size_vec[0] = kernel_size + kernel_size_vec[1] = kernel_size + + -- 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 + + print("BEFORE_BLUR") + print(wea.sculpt.make_preview(brush, size)) + + -- Make the kernel & blur it + local success, kernel = wea.conv.kernel_gaussian(kernel_size, 2) + if not success then return success, kernel end + + local success2, msg = worldeditadditions.conv.convolve( + brush, Vector3.new(size.x, 0, size.y), + kernel, kernel_size_vec + ) + if not success2 then return success2, msg end + + -- Rescale to be between 0 and 1 + local max_value = wea.max(brush) + for i,value in pairs(brush) do + brush[i] = brush[i] / max_value + end + + print("AFTER_BLUR") + print(wea.sculpt.make_preview(brush, size)) + + + return true, brush, size +end diff --git a/worldeditadditions/lib/sculpt/init.lua b/worldeditadditions/lib/sculpt/init.lua index b1ae6d4..1791d35 100644 --- a/worldeditadditions/lib/sculpt/init.lua +++ b/worldeditadditions/lib/sculpt/init.lua @@ -6,7 +6,8 @@ local sculpt = { default = dofile(wea.modpath.."/lib/sculpt/brushes/default.lua"), default_soft = dofile(wea.modpath.."/lib/sculpt/brushes/default_soft.lua"), square = dofile(wea.modpath.."/lib/sculpt/brushes/square.lua"), - circle = dofile(wea.modpath.."/lib/sculpt/brushes/circle.lua") + circle = dofile(wea.modpath.."/lib/sculpt/brushes/circle.lua"), + circle_soft1 = dofile(wea.modpath.."/lib/sculpt/brushes/circle_soft1.lua") }, make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua"), make_preview = dofile(wea.modpath.."/lib/sculpt/make_preview.lua"),