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