//sculpt: implement circle brush

This commit is contained in:
Starbeamrainbowlabs 2021-12-28 17:45:20 +00:00
parent 2da0f2dcc2
commit 17cc91ba1c
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
6 changed files with 62 additions and 44 deletions

View file

@ -12,6 +12,8 @@ local function apply(pos1, brush_name, height, brush_size)
local success, brush, brush_size_actual = wea.sculpt.make_brush(brush_name, brush_size) local success, brush, brush_size_actual = wea.sculpt.make_brush(brush_name, brush_size)
if not success then return success, brush end if not success then return success, brush end
print(wea.sculpt.make_preview(brush, brush_size_actual))
local brush_size_terrain = Vector3.new( local brush_size_terrain = Vector3.new(
brush_size_actual.x, brush_size_actual.x,
0, 0,

View file

@ -9,14 +9,11 @@ return function(size)
local centre = (size / 2):floor() local centre = (size / 2):floor()
local minsize = math.floor(math.min(size.x, size.y) / 2) local minsize = math.floor(math.min(size.x, size.y) / 2)
print("centre", centre, "minsize", minsize)
for y = size.y - 1, 0, -1 do for y = size.y - 1, 0, -1 do
for x = size.x - 1, 0, -1 do for x = size.x - 1, 0, -1 do
local i = y*size.x + x local i = y*size.x + x
if math.floor((centre - Vector3.new(x, y, 0)):length()) < minsize then
if math.floor((centre - Vector3.new(x, y, 0)):abs():length()) < minsize - 2 then
brush[i] = 1 brush[i] = 1
else else
brush[i] = 0 brush[i] = 0

View file

@ -9,6 +9,7 @@ local sculpt = {
circle = dofile(wea.modpath.."/lib/sculpt/brushes/circle.lua") circle = dofile(wea.modpath.."/lib/sculpt/brushes/circle.lua")
}, },
make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua"), make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua"),
make_preview = dofile(wea.modpath.."/lib/sculpt/make_preview.lua"),
preview_brush = dofile(wea.modpath.."/lib/sculpt/preview_brush.lua"), preview_brush = dofile(wea.modpath.."/lib/sculpt/preview_brush.lua"),
read_brush_static = dofile(wea.modpath.."/lib/sculpt/read_brush_static.lua"), read_brush_static = dofile(wea.modpath.."/lib/sculpt/read_brush_static.lua"),
apply_heightmap = dofile(wea.modpath.."/lib/sculpt/apply_heightmap.lua"), apply_heightmap = dofile(wea.modpath.."/lib/sculpt/apply_heightmap.lua"),

View file

@ -0,0 +1,54 @@
local wea = worldeditadditions
local Vector3 = wea.Vector3
local make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua")
--- Generates a textual preview of a given brush.
-- @param brush table The brush in question to preview.
-- @param size Vector3 The size of the brush.
-- @returns string A preview of the brush as a string.
local function make_preview(brush, size, framed)
if framed == nil then framed = true end
-- Values to map brush pixel values to.
-- Brush pixel values are first multiplied by 10 before comparing to these numbers
local values = {}
values["@"] = 9.5
values["#"] = 8
values["="] = 6
values[":"] = 5
values["-"] = 4
values["."] = 1
values[" "] = 0
local frame_vertical = "+"..string.rep("-", math.max(0, size.x)).."+"
local result = {}
if framed then table.insert(result, frame_vertical) end
for y = size.y-1, 0, -1 do
local row = {}
if framed then table.insert(row, "|") end
for x = size.x-1, 0, -1 do
local i = y*size.x + x
local pixel = " "
local threshold_cur = -1
for value,threshold in pairs(values) do
if brush[i] * 10 > threshold and threshold_cur < threshold then
pixel = value
threshold_cur = threshold
end
end
table.insert(row, pixel)
end
if framed then table.insert(row, "|") end
table.insert(result, table.concat(row))
end
if framed then table.insert(result, frame_vertical) end
return table.concat(result, "\n")
end
return make_preview

View file

@ -2,6 +2,7 @@ local wea = worldeditadditions
local Vector3 = wea.Vector3 local Vector3 = wea.Vector3
local make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua") local make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua")
local make_preview = dofile(wea.modpath.."/lib/sculpt/make_preview.lua")
--- Generates a textual preview of a given brush. --- Generates a textual preview of a given brush.
-- @param brush_name string The name of the brush to create a preview for. -- @param brush_name string The name of the brush to create a preview for.
@ -10,47 +11,11 @@ local make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua")
local function preview_brush(brush_name, target_size, framed) local function preview_brush(brush_name, target_size, framed)
if framed == nil then framed = true end if framed == nil then framed = true end
if not target_size then target_size = Vector3.new(10, 10, 0) end if not target_size then target_size = Vector3.new(10, 10, 0) end
local success, brush, brush_size = make_brush(brush_name, target_size) local success, brush, brush_size = make_brush(brush_name, target_size)
if not success then return success, brush end
-- Values to map brush pixel values to. return true, make_preview(brush, brush_size, framed)
-- Brush pixel values are first multiplied by 10 before comparing to these numbers
local values = {}
values["@"] = 9.5
values["#"] = 8
values["="] = 6
values[":"] = 5
values["-"] = 4
values["."] = 1
values[" "] = 0
local frame_vertical = "+"..string.rep("-", math.max(0, brush_size.x)).."+"
local result = {}
if framed then table.insert(result, frame_vertical) end
for y = brush_size.y-1, 0, -1 do
local row = {}
if framed then table.insert(row, "|") end
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] * 10 > threshold and threshold_cur < threshold then
pixel = value
threshold_cur = threshold
end
end
table.insert(row, pixel)
end
if framed then table.insert(row, "|") end
table.insert(result, table.concat(row))
end
if framed then table.insert(result, frame_vertical) end
return true, table.concat(result, "\n")
end end
return preview_brush return preview_brush

View file

@ -56,7 +56,6 @@ worldedit.register_command("sculpt", {
local brush_min = wea.min(brush) local brush_min = wea.min(brush)
local brush_max = wea.max(brush) local brush_max = wea.max(brush)
local range_nodes = (brush_max * height) - (brush_min * height) local range_nodes = (brush_max * height) - (brush_min * height)
print("//sculpt range_nodes", range_nodes)
return size_actual.x * size_actual.y * range_nodes return size_actual.x * size_actual.y * range_nodes
end, end,