2021-03-01 21:26:33 +00:00
|
|
|
--- Applies a layer of 2D noise over the terrain in the defined region.
|
|
|
|
-- @module worldeditadditions.noise2d
|
|
|
|
|
2021-07-03 00:44:36 +00:00
|
|
|
local wea = worldeditadditions
|
|
|
|
|
2021-03-01 21:26:33 +00:00
|
|
|
-- ███ ██ ██████ ██ ███████ ███████ ██████ ██████
|
|
|
|
-- ████ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
|
|
-- ██ ██ ██ ██ ██ ██ ███████ █████ █████ ██ ██
|
|
|
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
|
|
-- ██ ████ ██████ ██ ███████ ███████ ███████ ██████
|
|
|
|
--- Applies a layer of 2d noise over the terrain in the defined region.
|
|
|
|
-- @param pos1 Vector pos1 of the defined region
|
|
|
|
-- @param pos2 Vector pos2 of the defined region
|
|
|
|
-- @param noise_params table A noise parameters table. Will be passed unmodified to PerlinNoise() from the Minetest API.
|
2021-07-03 00:44:36 +00:00
|
|
|
function worldeditadditions.noise.noise2d(pos1, pos2, noise_params)
|
2021-03-01 21:26:33 +00:00
|
|
|
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
2021-07-03 00:44:36 +00:00
|
|
|
local region_height = pos1.y - pos2.y
|
2021-03-01 21:26:33 +00:00
|
|
|
-- pos2 will always have the highest co-ordinates now
|
|
|
|
|
2021-07-03 00:44:36 +00:00
|
|
|
-- Fill in the default params
|
|
|
|
noise_params = worldeditadditions.noise.params_apply_default(noise_params)
|
|
|
|
|
2021-03-01 21:26:33 +00:00
|
|
|
-- Fetch the nodes in the specified area
|
|
|
|
local manip, area = worldedit.manip_helpers.init(pos1, pos2)
|
|
|
|
local data = manip:get_data()
|
|
|
|
|
|
|
|
local heightmap_old, heightmap_size = worldeditadditions.make_heightmap(
|
|
|
|
pos1, pos2,
|
|
|
|
manip, area,
|
|
|
|
data
|
|
|
|
)
|
2021-06-27 23:56:29 +00:00
|
|
|
local heightmap_new = worldeditadditions.table.shallowcopy(heightmap_old)
|
2021-03-01 21:26:33 +00:00
|
|
|
|
2021-07-03 00:44:36 +00:00
|
|
|
local noisemap = wea.noise.make_2d(noise_params, heightmap_size)
|
2021-03-01 21:26:33 +00:00
|
|
|
|
2021-07-03 00:44:36 +00:00
|
|
|
wea.noise.apply_2d(
|
|
|
|
heightmap_new,
|
|
|
|
noisemap,
|
|
|
|
heightmap_size,
|
|
|
|
region_height,
|
|
|
|
noise_params.apply
|
|
|
|
)
|
2021-03-01 21:26:33 +00:00
|
|
|
|
2021-07-03 00:44:36 +00:00
|
|
|
local success, stats = wea.apply_heightmap_changes(
|
|
|
|
pos1, pos2,
|
|
|
|
area, data,
|
|
|
|
heightmap_old, heightmap_new,
|
|
|
|
heightmap_size
|
|
|
|
)
|
|
|
|
if not success then return success, stats end
|
2021-03-01 21:26:33 +00:00
|
|
|
|
|
|
|
-- Save the modified nodes back to disk & return
|
|
|
|
worldedit.manip_helpers.finish(manip, data)
|
|
|
|
|
|
|
|
return true, stats
|
|
|
|
end
|