mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-08-20 05:24:20 +02:00
//sculpt: implement circle brush
This commit is contained in:
parent
2da0f2dcc2
commit
17cc91ba1c
@ -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)
|
||||
if not success then return success, brush end
|
||||
|
||||
print(wea.sculpt.make_preview(brush, brush_size_actual))
|
||||
|
||||
local brush_size_terrain = Vector3.new(
|
||||
brush_size_actual.x,
|
||||
0,
|
||||
|
@ -9,14 +9,11 @@ return function(size)
|
||||
local centre = (size / 2):floor()
|
||||
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 x = size.x - 1, 0, -1 do
|
||||
local i = y*size.x + x
|
||||
|
||||
|
||||
if math.floor((centre - Vector3.new(x, y, 0)):abs():length()) < minsize - 2 then
|
||||
if math.floor((centre - Vector3.new(x, y, 0)):length()) < minsize then
|
||||
brush[i] = 1
|
||||
else
|
||||
brush[i] = 0
|
||||
|
@ -9,6 +9,7 @@ local sculpt = {
|
||||
circle = dofile(wea.modpath.."/lib/sculpt/brushes/circle.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"),
|
||||
read_brush_static = dofile(wea.modpath.."/lib/sculpt/read_brush_static.lua"),
|
||||
apply_heightmap = dofile(wea.modpath.."/lib/sculpt/apply_heightmap.lua"),
|
||||
|
54
worldeditadditions/lib/sculpt/make_preview.lua
Normal file
54
worldeditadditions/lib/sculpt/make_preview.lua
Normal 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
|
@ -2,6 +2,7 @@ local wea = worldeditadditions
|
||||
local Vector3 = wea.Vector3
|
||||
|
||||
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.
|
||||
-- @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)
|
||||
if framed == nil then framed = true 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)
|
||||
if not success then return success, brush 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, 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")
|
||||
return true, make_preview(brush, brush_size, framed)
|
||||
end
|
||||
|
||||
return preview_brush
|
||||
|
@ -56,7 +56,6 @@ worldedit.register_command("sculpt", {
|
||||
local brush_min = wea.min(brush)
|
||||
local brush_max = wea.max(brush)
|
||||
local range_nodes = (brush_max * height) - (brush_min * height)
|
||||
print("//sculpt range_nodes", range_nodes)
|
||||
|
||||
return size_actual.x * size_actual.y * range_nodes
|
||||
end,
|
||||
|
Loading…
Reference in New Issue
Block a user