2021-03-01 22:26:33 +01:00
|
|
|
--- Applies a layer of 2D noise over the terrain in the defined region.
|
|
|
|
-- @module worldeditadditions.noise2d
|
|
|
|
|
2021-07-03 02:44:36 +02:00
|
|
|
local wea = worldeditadditions
|
|
|
|
|
2021-03-01 22:26:33 +01: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
|
2021-07-03 23:53:16 +02:00
|
|
|
-- @param noise_params table A noise parameters table.
|
2021-12-31 03:42:32 +01:00
|
|
|
function wea.noise.run2d(pos1, pos2, noise_params)
|
2021-03-01 22:26:33 +01:00
|
|
|
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
|
|
|
-- pos2 will always have the highest co-ordinates now
|
|
|
|
|
2021-07-03 02:44:36 +02:00
|
|
|
-- Fill in the default params
|
2021-07-04 15:35:02 +02:00
|
|
|
-- print("DEBUG noise_params_custom ", wea.format.map(noise_params))
|
2021-12-31 03:42:32 +01:00
|
|
|
noise_params = wea.noise.params_apply_default(noise_params)
|
2021-07-04 15:35:02 +02:00
|
|
|
-- print("DEBUG noise_params[1] ", wea.format.map(noise_params[1]))
|
2021-07-03 02:44:36 +02:00
|
|
|
|
2021-03-01 22:26:33 +01:00
|
|
|
-- Fetch the nodes in the specified area
|
|
|
|
local manip, area = worldedit.manip_helpers.init(pos1, pos2)
|
|
|
|
local data = manip:get_data()
|
|
|
|
|
2021-12-31 03:42:32 +01:00
|
|
|
local heightmap_old, heightmap_size = wea.terrain.make_heightmap(
|
2021-03-01 22:26:33 +01:00
|
|
|
pos1, pos2,
|
|
|
|
manip, area,
|
|
|
|
data
|
|
|
|
)
|
2021-12-31 03:42:32 +01:00
|
|
|
local heightmap_new = wea.table.shallowcopy(heightmap_old)
|
2021-03-01 22:26:33 +01:00
|
|
|
|
2021-07-03 23:53:16 +02:00
|
|
|
local success, noisemap = wea.noise.make_2d(
|
|
|
|
heightmap_size,
|
|
|
|
pos1,
|
|
|
|
noise_params)
|
|
|
|
if not success then return success, noisemap end
|
2021-03-01 22:26:33 +01:00
|
|
|
|
2021-07-04 14:21:13 +02:00
|
|
|
local message
|
2021-07-03 23:53:16 +02:00
|
|
|
success, message = wea.noise.apply_2d(
|
2021-07-03 02:44:36 +02:00
|
|
|
heightmap_new,
|
|
|
|
noisemap,
|
|
|
|
heightmap_size,
|
2021-07-04 14:21:13 +02:00
|
|
|
pos1, pos2,
|
2021-07-03 23:53:16 +02:00
|
|
|
noise_params[1].apply
|
2021-07-03 02:44:36 +02:00
|
|
|
)
|
2021-07-03 23:53:16 +02:00
|
|
|
if not success then return success, message end
|
|
|
|
|
2021-07-30 20:48:10 +02:00
|
|
|
local stats
|
2021-12-31 03:42:32 +01:00
|
|
|
success, stats = wea.terrain.apply_heightmap_changes(
|
2021-07-03 02:44:36 +02:00
|
|
|
pos1, pos2,
|
|
|
|
area, data,
|
|
|
|
heightmap_old, heightmap_new,
|
|
|
|
heightmap_size
|
|
|
|
)
|
|
|
|
if not success then return success, stats end
|
2021-03-01 22:26:33 +01:00
|
|
|
|
|
|
|
-- Save the modified nodes back to disk & return
|
|
|
|
worldedit.manip_helpers.finish(manip, data)
|
|
|
|
|
|
|
|
return true, stats
|
|
|
|
end
|