From b303f8758a328bbe520713abc459f11a604feb6c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 21 Aug 2020 22:01:24 +0100 Subject: [PATCH] //erode snowballs: make tweaks & add new noconv param --- README.md | 3 +- worldeditadditions/lib/erode/erode.lua | 12 ++++---- worldeditadditions/lib/erode/snowballs.lua | 29 ++++++++++--------- worldeditadditions/utils/tables.lua | 3 -- .../commands/convolve.lua | 2 -- .../commands/erode.lua | 6 ++-- 6 files changed, 25 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index f21e9f3..54ab716 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,8 @@ velocity_hist_count | `float` | 3 | The number of previous history values to init_velocity | `float` | 0.25 | The maximum random initial velocity of a snowball for each component of the velocity vector. scale_iterations | `float` | 0.04 | How much to scale erosion by as time goes on. Higher values mean that any given snowball will erode more later on as more steps pass. maxdiff | `float` | 0.4 | The maximum difference in height (between 0 and 1) that is acceptable as a percentage of the defined region's height. -count | `float` | 50000 | The number of snowballs to simulate. +count | `float` | 25000 | The number of snowballs to simulate. +noconv | any | n/a | When set to any value, disables to automatic 3x3 gaussian convolution. If you find any good combinations of these parameters, please [open an issue](https://github.com/sbrl/Minetest-WorldEditAdditions/issues/new) (or a PR!) and let me know! I'll include good combinations here. diff --git a/worldeditadditions/lib/erode/erode.lua b/worldeditadditions/lib/erode/erode.lua index eb2a24c..f85e51b 100644 --- a/worldeditadditions/lib/erode/erode.lua +++ b/worldeditadditions/lib/erode/erode.lua @@ -20,23 +20,21 @@ function worldeditadditions.erode.run(pos1, pos2, algorithm, params) -- print("[erode.run] algorithm: "..algorithm..", params:"); -- print(worldeditadditions.map_stringify(params)) - worldeditadditions.print_2d(heightmap, heightmap_size[1]) - + -- worldeditadditions.print_2d(heightmap, heightmap_size[1]) + local success, msg, stats if algorithm == "snowballs" then - local success, msg = worldeditadditions.erode.snowballs(heightmap, heightmap_eroded, heightmap_size, region_height, params) + success, msg = worldeditadditions.erode.snowballs(heightmap, heightmap_eroded, heightmap_size, region_height, params) if not success then return success, msg end else return false, "Error: Unknown algorithm '"..algorithm.."'. Currently implemented algorithms: snowballs (2d; hydraulic-like). Ideas for algorithms to implement are welcome!" end - local success, stats = worldeditadditions.apply_heightmap_changes( + success, stats = worldeditadditions.apply_heightmap_changes( pos1, pos2, area, data, heightmap, heightmap_eroded, heightmap_size ) if not success then return success, stats end worldedit.manip_helpers.finish(manip, data) - print("[erode] stats") - print(worldeditadditions.map_stringify(stats)) - return true, stats + return true, msg, stats end diff --git a/worldeditadditions/lib/erode/snowballs.lua b/worldeditadditions/lib/erode/snowballs.lua index dd3e369..394d3d7 100644 --- a/worldeditadditions/lib/erode/snowballs.lua +++ b/worldeditadditions/lib/erode/snowballs.lua @@ -84,14 +84,13 @@ function worldeditadditions.erode.snowballs(heightmap_initial, heightmap, height init_velocity = 0.25, scale_iterations = 0.04, maxdiff = 0.4, - count = 50000 + count = 25000 } -- Apply the default settings worldeditadditions.table_apply(params_custom, params) - print("[erode/snowballs] params: ") - print(worldeditadditions.map_stringify(params)) - + -- print("[erode/snowballs] params: ") + -- print(worldeditadditions.map_stringify(params)) local normals = worldeditadditions.calculate_normals(heightmap, heightmap_size) @@ -111,7 +110,7 @@ function worldeditadditions.erode.snowballs(heightmap_initial, heightmap, height if not success then return false, "Error: Failed at snowball "..i..":"..steps end end - print("[snowballs] "..#stats_steps.." snowballs simulated, max "..params.max_steps.." steps, averaged ~"..worldeditadditions.average(stats_steps).."") + -- print("[snowballs] "..#stats_steps.." snowballs simulated, max "..params.max_steps.." steps, averaged ~"..worldeditadditions.average(stats_steps).."") -- Round everything to the nearest int, since you can't really have -- something like .141592671 of a node @@ -130,14 +129,16 @@ function worldeditadditions.erode.snowballs(heightmap_initial, heightmap, height end end - local success, matrix = worldeditadditions.get_conv_kernel("gaussian", 3, 3) - if not success then return success, matrix end - matrix_size = {} matrix_size[0] = 3 matrix_size[1] = 3 - worldeditadditions.conv.convolve( - heightmap, heightmap_size, - matrix, - matrix_size - ) + if not params.noconv then + local success, matrix = worldeditadditions.get_conv_kernel("gaussian", 3, 3) + if not success then return success, matrix end + matrix_size = {} matrix_size[0] = 3 matrix_size[1] = 3 + worldeditadditions.conv.convolve( + heightmap, heightmap_size, + matrix, + matrix_size + ) + end - return true, params.count.." snowballs simulated" + return true, ""..#stats_steps.." snowballs simulated, max "..params.max_steps.." steps (average ~"..worldeditadditions.average(stats_steps)..")" end diff --git a/worldeditadditions/utils/tables.lua b/worldeditadditions/utils/tables.lua index 99e41ac..2c868b3 100644 --- a/worldeditadditions/utils/tables.lua +++ b/worldeditadditions/utils/tables.lua @@ -21,10 +21,7 @@ end -- @param source table The source to take values from -- @param target table The target to write values to function worldeditadditions.table_apply(source, target) - print("[table_apply] start") for key, value in pairs(source) do - print("[table_apply] Applying", key, "=", value) target[key] = value end - print("[table_apply] end") end diff --git a/worldeditadditions_commands/commands/convolve.lua b/worldeditadditions_commands/commands/convolve.lua index a54979e..3af7002 100644 --- a/worldeditadditions_commands/commands/convolve.lua +++ b/worldeditadditions_commands/commands/convolve.lua @@ -23,7 +23,6 @@ worldedit.register_command("convolve", { end if #parts >= 2 then local parts_dimension = worldeditadditions.split(parts[2], ",%s*", false) - print("[convolve] [str]width", parts_dimension[1], "[str]height", parts_dimension[2]) width = tonumber(parts_dimension[1]) if not width then return false, "Error: Invalid width (it must be a positive odd integer)." @@ -52,7 +51,6 @@ worldedit.register_command("convolve", { func = function(name, kernel_name, kernel_width, kernel_height, sigma) local start_time = worldeditadditions.get_ms_time() - print("[exec] kernel_width", kernel_width, "kernel_height", kernel_height) local success, kernel = worldeditadditions.get_conv_kernel(kernel_name, kernel_width, kernel_height, sigma) if not success then return success, kernel end diff --git a/worldeditadditions_commands/commands/erode.lua b/worldeditadditions_commands/commands/erode.lua index e5c4ad7..4fc1c37 100644 --- a/worldeditadditions_commands/commands/erode.lua +++ b/worldeditadditions_commands/commands/erode.lua @@ -31,14 +31,14 @@ worldedit.register_command("erode", { end, func = function(name, algorithm, params) local start_time = worldeditadditions.get_ms_time() - local success, stats = worldeditadditions.erode.run( + local success, msg, stats = worldeditadditions.erode.run( worldedit.pos1[name], worldedit.pos2[name], algorithm, params ) - if not success then return success, stats end + if not success then return success, msg end local time_taken = worldeditadditions.get_ms_time() - start_time minetest.log("action", name .. " used //erode "..algorithm.." at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", adding " .. stats.added .. " nodes and removing " .. stats.removed .. " nodes in " .. time_taken .. "s") - return true, stats.added .. " nodes added and " .. stats.removed .. " nodes removed in " .. worldeditadditions.human_time(time_taken) + return true, msg.."\n"..stats.added .. " nodes added and " .. stats.removed .. " nodes removed in " .. worldeditadditions.human_time(time_taken) end })