From 108c280843c8a544dba0300fabadff9e81a7002e Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 1 Mar 2021 21:26:33 +0000 Subject: [PATCH] Start laying out stuff for our noise experiment, but it isn't hooked up yet and isn't finished. --- worldeditadditions/lib/noise/engines.lua | 3 ++ worldeditadditions/lib/noise/make_2d.lua | 9 ++++++ worldeditadditions/lib/noise/noise.lua | 3 ++ worldeditadditions/lib/noise/noise2d.lua | 38 ++++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 worldeditadditions/lib/noise/engines.lua create mode 100644 worldeditadditions/lib/noise/make_2d.lua create mode 100644 worldeditadditions/lib/noise/noise.lua create mode 100644 worldeditadditions/lib/noise/noise2d.lua diff --git a/worldeditadditions/lib/noise/engines.lua b/worldeditadditions/lib/noise/engines.lua new file mode 100644 index 0000000..7d172fd --- /dev/null +++ b/worldeditadditions/lib/noise/engines.lua @@ -0,0 +1,3 @@ +function worldeditadditions.noise.engine_perlin_2d(x, y) + +end diff --git a/worldeditadditions/lib/noise/make_2d.lua b/worldeditadditions/lib/noise/make_2d.lua new file mode 100644 index 0000000..9810d44 --- /dev/null +++ b/worldeditadditions/lib/noise/make_2d.lua @@ -0,0 +1,9 @@ + +-- ███ ███ █████ ██ ██ ███████ ██████ ██████ +-- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ████ ██ ███████ █████ █████ █████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██████ +function worldeditadditions.noise.make_2d(size, noise_func) + -- TODO: Follow https://www.redblobgames.com/maps/terrain-from-noise/ +end diff --git a/worldeditadditions/lib/noise/noise.lua b/worldeditadditions/lib/noise/noise.lua new file mode 100644 index 0000000..30b2549 --- /dev/null +++ b/worldeditadditions/lib/noise/noise.lua @@ -0,0 +1,3 @@ +worldeditadditions.noise = {} + +dofile(worldeditadditions.modpath.."/lib/noise/alg_perlin.lua") diff --git a/worldeditadditions/lib/noise/noise2d.lua b/worldeditadditions/lib/noise/noise2d.lua new file mode 100644 index 0000000..5661628 --- /dev/null +++ b/worldeditadditions/lib/noise/noise2d.lua @@ -0,0 +1,38 @@ +--- Applies a layer of 2D noise over the terrain in the defined region. +-- @module worldeditadditions.noise2d + +-- ███ ██ ██████ ██ ███████ ███████ ██████ ██████ +-- ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ███████ █████ █████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ████ ██████ ██ ███████ ███████ ███████ ██████ +--- 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. +function worldeditadditions.noise2d(pos1, pos2, noise_params) + 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, 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 + ) + local heightmap_new = worldeditadditions.shallowcopy(heightmap_old) + + local perlin_map = PerlinNoiseMap(noise_params, heightmap_size) + + + local stats = { added = 0, removed = 0 } + + -- Save the modified nodes back to disk & return + -- No need to save - this function doesn't actually change anything + worldedit.manip_helpers.finish(manip, data) + + return true, stats +end