2018-06-09 12:05:09 +00:00
--- Overlap command. Places a specified node on top of
-- @module worldeditadditions.overlay
function worldedit . ellipsoid ( position , radius , target_node )
-- position = { x, y, z }
-- Fetch the nodes in the specified area
-- OPTIMIZE: We should be able to calculate a more efficient box-area here
2018-06-09 12:10:42 +00:00
local manip , area = worldedit.manip_helpers . init_radius ( position , math.max ( radius.x , radius.y , radius.z ) )
2018-06-09 12:05:09 +00:00
local data = manip : get_data ( )
local node_id = minetest.get_content_id ( target_node )
local node_id_air = minetest.get_content_id ( " air " )
local stride_z , stride_y = area.zstride , area.ystride
2018-06-09 12:36:25 +00:00
-- TODO: This won't work, because we need to vary the calculation we use this in based on what part of the ellipsoid we're working on / in, not compare to a static value
local radius_distance_sq = worldeditadditions.vector . lengthsquared ( radius )
2018-06-09 12:05:09 +00:00
2018-06-09 12:10:42 +00:00
local count = 0 -- The number of nodes replaced
2018-06-09 12:36:25 +00:00
local idx_z_base = area : index ( position.x , position.y , position.z ) -- initial z offset
2018-06-09 12:05:09 +00:00
for z = - radius.z , radius.z do
local idx_y_base = idx_z_base
2018-06-09 12:36:25 +00:00
for y = - radius.y , radius.y do
2018-06-09 12:05:09 +00:00
local i = idx_y_base
2018-06-09 12:36:25 +00:00
for x = - radius.x , radius.x do
2018-06-09 12:05:09 +00:00
-- If we're inside the ellipse, then fill it in
2018-06-09 18:35:32 +00:00
local x_comp , y_comp , z_comp = x / radius.x , y / radius.y , z / radius.z
if x_comp * x_comp + y_comp * y_comp + z_comp * z_comp <= 1 then
2018-06-09 12:05:09 +00:00
data [ i ] = node_id
2018-06-09 12:10:42 +00:00
count = count + 1
2018-06-09 18:35:32 +00:00
2018-06-09 12:05:09 +00:00
end
i = i + 1
end
2018-06-09 12:36:25 +00:00
idx_y_base = idx_y_base + stride_y
2018-06-09 12:05:09 +00:00
end
2018-06-09 12:36:25 +00:00
idx_z_base = idx_z_base + stride_z
2018-06-09 12:05:09 +00:00
end
-- Save the modified nodes back to disk & return
worldedit.manip_helpers . finish ( manip , data )
2018-06-09 12:10:42 +00:00
return count
2018-06-09 12:05:09 +00:00
end