mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-25 08:33:00 +00:00
//spline: plot chaikin curve
This commit is contained in:
parent
9a4b4beb76
commit
2748f4cdfa
5 changed files with 29 additions and 9 deletions
|
@ -30,6 +30,7 @@ dofile(wea.modpath.."/lib/scale.lua")
|
||||||
dofile(wea.modpath.."/lib/spiral_square.lua")
|
dofile(wea.modpath.."/lib/spiral_square.lua")
|
||||||
dofile(wea.modpath.."/lib/spiral_circle.lua")
|
dofile(wea.modpath.."/lib/spiral_circle.lua")
|
||||||
dofile(wea.modpath.."/lib/dome.lua")
|
dofile(wea.modpath.."/lib/dome.lua")
|
||||||
|
dofile(wea.modpath.."/lib/spline.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")
|
||||||
|
|
|
@ -58,15 +58,18 @@ function worldeditadditions.spline(pos_list, width_start, width_end, steps, targ
|
||||||
-- 3: Replace nodes
|
-- 3: Replace nodes
|
||||||
---
|
---
|
||||||
|
|
||||||
|
local pos_prev = pos_list_chaikin[1]:floor()
|
||||||
for i = 1, #pos_list_chaikin do
|
for i = 1, #pos_list_chaikin do
|
||||||
local pos_next = pos_list_chaikin[i]
|
local pos_next = pos_list_chaikin[i]:floor()
|
||||||
local width_next = widths_lerped[i]
|
local width_next = widths_lerped[i]
|
||||||
|
|
||||||
|
print("DEBUG:spline DRAW pos", pos_next, "width", width_next, "length", (pos_next - pos_prev):length())
|
||||||
-- For now, just plot a point at each node
|
-- For now, just plot a point at each node
|
||||||
local index_node = area:index(pos_next.x, pos_next.y, pos_next.z)
|
local index_node = area:index(pos_next.x, pos_next.y, pos_next.z)
|
||||||
data[index_node] = node_id
|
data[index_node] = node_id
|
||||||
|
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
pos_prev = pos_next:clone()
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
@ -19,7 +19,7 @@ worldeditadditions_core.register_command("spline", {
|
||||||
local replace_node
|
local replace_node
|
||||||
local width_start
|
local width_start
|
||||||
local width_end
|
local width_end
|
||||||
local steps = 6
|
local steps = 3
|
||||||
|
|
||||||
if #parts < 1 then
|
if #parts < 1 then
|
||||||
return false, "Error: The replace_node (e.g. dirt) was not specified."
|
return false, "Error: The replace_node (e.g. dirt) was not specified."
|
||||||
|
@ -79,6 +79,7 @@ worldeditadditions_core.register_command("spline", {
|
||||||
pos_list,
|
pos_list,
|
||||||
width_start,
|
width_start,
|
||||||
width_end,
|
width_end,
|
||||||
|
steps,
|
||||||
replace_node
|
replace_node
|
||||||
)
|
)
|
||||||
if not success then return success, nodes_replaced end
|
if not success then return success, nodes_replaced end
|
||||||
|
|
|
@ -245,5 +245,6 @@ anchor = wea_c.EventEmitter.new({
|
||||||
set_all = set_all,
|
set_all = set_all,
|
||||||
compat_worldedit_get = compat_worldedit_get
|
compat_worldedit_get = compat_worldedit_get
|
||||||
})
|
})
|
||||||
|
anchor.debug = true
|
||||||
|
|
||||||
return anchor
|
return anchor
|
||||||
|
|
|
@ -17,21 +17,35 @@ end
|
||||||
-- @param steps number The number of interpolatioon passes to do.
|
-- @param steps number The number of interpolatioon passes to do.
|
||||||
-- @returns Vector3[] A (longer) list of interpolated points.
|
-- @returns Vector3[] A (longer) list of interpolated points.
|
||||||
local function chaikin(arr_pos, steps)
|
local function chaikin(arr_pos, steps)
|
||||||
|
print("DEBUG:chaikin START", wea_c.inspect(arr_pos))
|
||||||
local result = wea_c.table.shallowcopy(arr_pos)
|
local result = wea_c.table.shallowcopy(arr_pos)
|
||||||
|
|
||||||
|
local pos_start = result[1]
|
||||||
|
local pos_end = result[#result]
|
||||||
|
|
||||||
for pass = 1, steps do
|
for pass = 1, steps do
|
||||||
local pos_start = result[1]
|
local result_nextpass = {}
|
||||||
local pos_end = result[#result]
|
-- local offset = 0
|
||||||
|
for i = 1,#result-1,1 do
|
||||||
for i = 1,#result-1,2 do
|
local pos_cur = result[i]
|
||||||
result[i] = linear_interpolate(result[i], result[i+1], 0.25)
|
local pos_next = result[i+1]
|
||||||
table.insert(result, i+1, linear_interpolate(result[i], result[i+2]))
|
print("DEBUG:chaikin SUBSTEP i", i, "pos_cur", pos_cur, "pos_next", pos_next)
|
||||||
|
|
||||||
|
table.insert(result_nextpass, linear_interpolate(pos_cur, pos_next, 0.25))
|
||||||
|
table.insert(result_nextpass, linear_interpolate(pos_cur, pos_next, 0.75))
|
||||||
|
-- result[i+offset] = linear_interpolate(pos_cur, pos_next, 0.25)
|
||||||
|
-- table.insert(result, i+1+offset, linear_interpolate(pos_cur, pos_next, 0.75))
|
||||||
|
-- offset = offset + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- table.remove(result, #result-1) -- In the original, but I don't know why
|
-- table.remove(result, #result-1) -- In the original, but I don't know why
|
||||||
|
|
||||||
|
result = result_nextpass
|
||||||
-- Keep the starting & ending positions the same
|
-- Keep the starting & ending positions the same
|
||||||
result[1] = pos_start
|
result[1] = pos_start
|
||||||
result[#result] = pos_end
|
result[#result] = pos_end
|
||||||
|
|
||||||
|
print("DEBUG:chakin STEP", wea_c.inspect(result))
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue