From e0e64dc6b96561d41cb48c740c8d47156ab7897d Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 20 Sep 2020 18:03:29 +0100 Subject: [PATCH] Start ellipseapply, but it isn't finished --- worldeditadditions/lib/ellipseapply.lua | 53 +++++++++++++++++++++++++ worldeditadditions/lib/ellipsoid.lua | 7 +++- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 worldeditadditions/lib/ellipseapply.lua diff --git a/worldeditadditions/lib/ellipseapply.lua b/worldeditadditions/lib/ellipseapply.lua new file mode 100644 index 0000000..5aeadf3 --- /dev/null +++ b/worldeditadditions/lib/ellipseapply.lua @@ -0,0 +1,53 @@ +-- ███████ ██ ██ ██ ██████ ███████ ███████ █████ ██████ ██████ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- █████ ██ ██ ██ ██████ ███████ █████ ███████ ██████ ██████ ██ ████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ███████ ███████ ██ ██ ███████ ███████ ██ ██ ██ ██ ███████ ██ + +--- Similar to cubeapply, except that it takes 2 positions and only keeps an ellipsoid-shaped area defined by the boundaries of the defined region. +-- Takes a backup copy of the defined region, runs the given function, and then +-- restores the bits around the edge that aren't inside the largest ellipsoid that will fit inside the defined region. +-- @param {Position} pos1 The 1st position defining the region boundary +-- @param {Position} pos2 The 2nd positioon defining the region boundary +-- @param {Function} func The function to call that performs the action in question. It is expected that the given function will accept no arguments. +function worldeditadditions.ellipseapply(pos1, pos2, func) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) + -- pos2 will always have the highest co-ordinates now + + -- Fetch the nodes in the specified area + local manip_before, area_before = worldedit.manip_helpers.init(pos1, pos2) + local data_before = manip:get_data() + + func() + + local manip_after, area_after = worldedit.manip_helpers.init(pos1, pos2) + local data_after = manip:get_data() + + local radius = { + x = (pos2.x - pos1.x) / 2, + y = (pos2.y - pos1.y) / 2, + z = (pos2.z - pos1.z) / 2 + } + local e_centre = { + x = pos2.x - radius.x, + y = pos2.y - radius.y, + z = pos2.z - radius.z + } + + for z = pos2.z, pos1.z, -1 do + for y = pos2.y, pos1.y, -1 do + for x = pos2.x, pos1.x, -1 do + local comp_x = (x - e_centre.x) / radius.x + local comp_y = (y - e_centre.y) / radius.y + local comp_z = (z - e_centre.z) / radius.z + + -- TODO finish this + end + end + end + + -- Save the modified nodes back to disk & return + -- No need to save - this function doesn't actually change anything + worldedit.manip_helpers.finish(manip_after, data_after) + +end diff --git a/worldeditadditions/lib/ellipsoid.lua b/worldeditadditions/lib/ellipsoid.lua index 3577cfc..d63fdb8 100644 --- a/worldeditadditions/lib/ellipsoid.lua +++ b/worldeditadditions/lib/ellipsoid.lua @@ -1,5 +1,8 @@ ---- Overlap command. Places a specified node on top of --- @module worldeditadditions.overlay +-- ███████ ██ ██ ██ ██████ ███████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- █████ ██ ██ ██ ██████ ███████ █████ +-- ██ ██ ██ ██ ██ ██ ██ +-- ███████ ███████ ███████ ██ ██ ███████ ███████ function worldeditadditions.ellipsoid(position, radius, target_node, hollow) -- position = { x, y, z }