From da1c56cc2369e81cf20d4565b3ff9a6f796167c3 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 10 Jun 2020 01:38:09 +0100 Subject: [PATCH] Add //convolve documentation to README & aliases --- README.md | 28 +++++++++++++++++++ .../commands/convolve.lua | 5 +++- worldeditadditions_commands/multi.lua | 8 +++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d205d1d..7c8549e 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,34 @@ Here are all the above examples together: //replacemix dirt 3 sandstone 10 dry_dirt cobble 2 ``` +### `//convolve [[,]] []` +Advanced version of `//smooth` from we_env, and so far the _only_ WorldEditAdditions command to have any aliases (`//smoothadv` and `//conv`). + +Extracts a heightmap from the defined region and then proceeds to [convolve](https://en.wikipedia.org/wiki/Kernel_(image_processing)) over it with the specified kernel. The kernel can be thought of as the filter that will be applied to the heightmap. Once done, the newly convolved heightmap is applied to the terrain. + +Possible kernels: + +Kernel | Description +----------------|------------------------------ +[`box`](https://en.wikipedia.org/wiki/Box_blur) | A simple uniform box blur. +`pascal` | A kernel derived from the odd layers of [Pascal's Triangle](https://en.wikipedia.org/wiki/Pascal%27s_triangle). Slightly less smooth than a Gaussian blur. +[`gaussian`](https://en.wikipedia.org/wiki/Gaussian_blur) | The default. A Gaussian blur - should give the smoothest result, and also the most customisable - see below. + +If you can think of any other convolutional filters that would be useful, please [open an issue](https://github.com/sbrl/Minetest-WorldEditAdditions/issues/new). The code backing this command is very powerful and flexible, so adding additional convolutional filters should be pretty trivial. + +The width and height (if specified) refer to the dimensions of the kernel and must be odd integers and are separated by a single comma (and _no_ space). If the height is not specified, it defaults to the width. If using the `gaussian` kernel, the width and height must be identical. Larger kernels are slower, but produce a more smoothed effect and take more nearby nodes into account for every column. Defaults to a 5x5 kernel. + +The sigma value is only applicable to the `gaussian` kernel, and can be thought of as the 'smoothness' to apply. Greater values result in more smoothing. Default: 2 + +``` +//convolve +//convolve box 7 +//convolve pascal 11,3 +//convolve gaussian 7 +//convolve gaussian 9 10 +//convolve gaussian 5 0.2 +``` + ### `//count` Counts all the nodes in the defined region and returns the result along with calculated percentages (note that if the chat window used a monospace font, the returned result would be a perfect table. If someone has a ~~hack~~ solution to make the columns line up neatly, please [open an issue](https://github.com/sbrl/Minetest-WorldEditAdditions/issues/new) :D) diff --git a/worldeditadditions_commands/commands/convolve.lua b/worldeditadditions_commands/commands/convolve.lua index 0992aa9..9f50076 100644 --- a/worldeditadditions_commands/commands/convolve.lua +++ b/worldeditadditions_commands/commands/convolve.lua @@ -5,7 +5,7 @@ -- ██████ ██████ ██ ████ ████ ██████ ███████ ████ ███████ worldedit.register_command("convolve", { params = " [[,]] []", - description = "Advanced version of //smooth from we_env. Convolves over the defined region with the given kernel. Possible kernels: box, pascal, gaussian. The width & height (if specified) must be odd integers. If the height is not specified, it defaults to the width. gaussian should give the smoothest result, but the width & height must be identical. The sigma value is only applicable to gaussian kernels.", + description = "Advanced version of //smooth from we_env. Convolves over the defined region with the given kernel. Possible kernels: box, pascal, gaussian. The width & height (if specified) must be odd integers. If the height is not specified, it defaults to the width. gaussian should give the smoothest result, but the width & height must be identical. The sigma value is only applicable to gaussian kernels, and can be thought of as the 'smoothness' to apply.", privs = { worldedit = true }, require_pos = 2, parse = function(params_text) @@ -72,3 +72,6 @@ worldedit.register_command("convolve", { return true, "Added "..stats.added.." and removed "..stats.removed.." nodes" end }) + +worldedit.alias_command("smoothadv", "convolve") +worldedit.alias_command("conv", "convolve") diff --git a/worldeditadditions_commands/multi.lua b/worldeditadditions_commands/multi.lua index b5e703f..474afec 100644 --- a/worldeditadditions_commands/multi.lua +++ b/worldeditadditions_commands/multi.lua @@ -3,7 +3,7 @@ -- explode(seperator, string) -- From http://lua-users.org/wiki/SplitJoin -function explode(delim, str) +local function explode(delim, str) local ll, is_done local delim_length = string.len(delim) ll = 0 @@ -27,13 +27,13 @@ function explode(delim, str) end -- From http://lua-users.org/wiki/StringTrim -function trim(s) +local function trim(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end minetest.register_chatcommand("/multi", { - params = "// // .....", - description = "Executes multiple chat commands in sequence.", + params = "/ // / .....", + description = "Executes multiple chat commands in sequence. Just prepend a list of space-separated chat commands with //multi, and you're good to go! The forward slashes at the beginning of each chat command must be the same as if you were executing it normally.", privs = { worldedit = true }, func = function(name, params_text)