mirror of
https://github.com/Mjokfox/WorldEdit_terraform.git
synced 2024-12-04 15:14:01 -05:00
Compare commits
3 commits
b546bbf085
...
dbb8b7d2c4
Author | SHA1 | Date | |
---|---|---|---|
|
dbb8b7d2c4 | ||
|
53a3937e45 | ||
|
27319454b0 |
4 changed files with 35 additions and 39 deletions
53
init.lua
53
init.lua
|
@ -1,26 +1,17 @@
|
|||
local S = minetest.get_translator("worldedit_commands")
|
||||
|
||||
local terraform = {}
|
||||
local worldedit_terraform = {}
|
||||
|
||||
mh = worldedit.manip_helpers
|
||||
|
||||
local radius_limit = minetest.settings:get("radius_limit")
|
||||
local radius_limit = tonumber(minetest.settings:get("worldedit_terraform_radius_limit")) or 10
|
||||
local threshold_multiplier = tonumber(minetest.settings:get("worldedit_terraform_threshold_multiplier")) or 20
|
||||
local gauss_sigma = tonumber(minetest.settings:get("worldedit_terraform_gauss_sigma")) or 4
|
||||
local guass_radius = tonumber(minetest.settings:get("worldedit_terraform_guass_radius")) or 2
|
||||
|
||||
if (radius_limit == nil) then
|
||||
radius_limit = 10
|
||||
minetest.settings:set("radius_limit",10)
|
||||
else
|
||||
radius_limit = tonumber(radius_limit)
|
||||
end
|
||||
|
||||
|
||||
local threshold_multiplier = minetest.settings:get("threshold_multiplier")
|
||||
|
||||
if (threshold_multiplier == nil) then
|
||||
threshold_multiplier = 1
|
||||
minetest.settings:set("threshold_multiplier",1)
|
||||
else
|
||||
threshold_multiplier = tonumber(threshold_multiplier)
|
||||
if (threshold_multiplier > 100) then
|
||||
threshold_multiplier = 100
|
||||
minetest.settings:set("worldedit_terraform_threshold_multiplier",100)
|
||||
end
|
||||
|
||||
local function createGaussianKernel(radius, sigma)
|
||||
|
@ -53,12 +44,11 @@ local function createGaussianKernel(radius, sigma)
|
|||
return kernel
|
||||
end
|
||||
|
||||
local kernelradius = 4
|
||||
local kernel = createGaussianKernel(kernelradius, 2)
|
||||
local kernel = createGaussianKernel(guass_radius, gauss_sigma)
|
||||
|
||||
terraform.terraform = function(pos,radius,threshold,shape)
|
||||
worldedit_terraform.terraform = function(pos,radius,threshold,shape)
|
||||
|
||||
local manip, area = mh.init_radius(pos, radius+kernelradius)
|
||||
local manip, area = mh.init_radius(pos, radius+guass_radius)
|
||||
|
||||
local data = mh.get_empty_data(area)
|
||||
|
||||
|
@ -68,14 +58,14 @@ terraform.terraform = function(pos,radius,threshold,shape)
|
|||
|
||||
local function convolute(conpos)
|
||||
local sum = 0
|
||||
for kx = -kernelradius, kernelradius do
|
||||
for ky = -kernelradius, kernelradius do
|
||||
for kz = -kernelradius, kernelradius do
|
||||
for kx = -guass_radius, guass_radius do
|
||||
for ky = -guass_radius, guass_radius do
|
||||
for kz = -guass_radius, guass_radius do
|
||||
local temppos = vector.new(conpos.x + kx, conpos.y + ky, conpos.z + kz)
|
||||
local node = manip:get_node_at(temppos)
|
||||
if node.name ~= "ignore" then
|
||||
if node.name ~= "air" then
|
||||
sum = sum + kernel[kx + kernelradius + 1][ky + kernelradius + 1][kz + kernelradius + 1]
|
||||
sum = sum + kernel[kx + guass_radius + 1][ky + guass_radius + 1][kz + guass_radius + 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -107,7 +97,7 @@ terraform.terraform = function(pos,radius,threshold,shape)
|
|||
mh.finish(manip, data)
|
||||
end
|
||||
|
||||
terraform.check_terraform = function(param)
|
||||
worldedit_terraform.check_terraform = function(param)
|
||||
local found, _, radius, threshold, shape = param:find("^(%d+)%s+(%d+)%s+(%a+)$")
|
||||
if found == nil then
|
||||
return false
|
||||
|
@ -117,16 +107,17 @@ terraform.check_terraform = function(param)
|
|||
if(radius > radius_limit) then radius = radius_limit end
|
||||
if(threshold > 100) then threshold = 100 end
|
||||
if(shape == "cube") then shape = true else shape = false end
|
||||
return true, radius, ((threshold/500)*threshold_multiplier)+0.4, shape
|
||||
threshold = 0.5-(threshold_multiplier/200)+((threshold_multiplier*threshold)/10000)
|
||||
return true, radius, threshold, shape
|
||||
end
|
||||
|
||||
worldedit.register_command("terraform", {
|
||||
params = "<radius> <shape> <threshold offset>",
|
||||
description = S("Terraform the blocks in <shape>(true = cube, false = sphere) at WorldEdit position 1 with radius <radius> and <threshold> [0,100], <radius> is limited to conf max radius."),
|
||||
params = "<radius> <threshold offset> <shape>",
|
||||
description = S("Terraform the blocks in <shape>(\"cube\" or \"sphere\") at WorldEdit position 1 with radius <radius> and <threshold> [0,100], <radius> is limited to configured max radius."),
|
||||
privs = {worldedit=true},
|
||||
require_pos = 1,
|
||||
parse = terraform.check_terraform,
|
||||
parse = worldedit_terraform.check_terraform,
|
||||
func = function(name, radius, threshold,shape)
|
||||
terraform.terraform(worldedit.pos1[name], radius, threshold, shape)
|
||||
worldedit_terraform.terraform(worldedit.pos1[name], radius, threshold, shape)
|
||||
end,
|
||||
})
|
4
mod.conf
4
mod.conf
|
@ -1,5 +1,5 @@
|
|||
name = terraform
|
||||
title = terraform
|
||||
name = worldedit_terraform
|
||||
title = worldedit_terraform
|
||||
depends = worldedit
|
||||
optional_depends = default
|
||||
description = a terraform command for worldedit
|
||||
|
|
|
@ -12,8 +12,10 @@ shape: Shape of the terraform area, either "sphere" or "cube".
|
|||
|
||||
## Settings
|
||||
|
||||
radius_limit (int): Maximum allowable radius for the terraform operation.\
|
||||
threshold_multiplier (int): Multiplier applied to the threshold value.
|
||||
radius_limit: Maximum allowable radius for the terraform operation.\
|
||||
threshold_multiplier: Multiplier applied to the threshold value.\
|
||||
gauss_sigma: The sigma value used in the generation of the guassian kernel.\
|
||||
guass_radius: The radius of the kernel.
|
||||
|
||||
## Examples
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# I recommend not going much higher than 10 as it gets really slow
|
||||
radius_limit (the maximum radius the terraform command can have) int 10
|
||||
# A multiplier for the threshold value for the convolution algorithm
|
||||
threshold_multiplier (the internal multiplier for the block placement threshold) int 1
|
||||
worldedit_terraform_radius_limit (The maximum radius of the terraform command) int 10
|
||||
# 20 is default, which ranges the threshold between 0.4 and 0.6 for 0-100 in the command. 0 disables it, 100 ranges it between 0 and 1
|
||||
worldedit_terraform_threshold_multiplier (Multiplier for the threshold) int 20
|
||||
# lower makes it more center targeted, high makes it more equally distributed
|
||||
worldedit_terraform_gauss_sigma (The sigma value for the gaussian kernel) int 4
|
||||
# Higher values make it more accurate, but the computation time increase cubic along with the terraform radius
|
||||
worldedit_terraform_guass_radius (The radius for the gaussian kernel) int 2
|
Loading…
Reference in a new issue