Noise: add perlinmt algorithm & set as default

This commit is contained in:
Starbeamrainbowlabs 2021-08-07 22:30:10 +01:00
parent 7de09e92b3
commit 6f00394d3d
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
5 changed files with 41 additions and 3 deletions

View File

@ -31,6 +31,7 @@ read_globals = {
"it",
"describe",
"bonemeal",
"dofile"
"dofile",
"PerlinNoise"
}
std = "max"

View File

@ -2,8 +2,9 @@ local wea = worldeditadditions
return {
available = { "perlin", "sin", "white", "red", "infrared" },
available = { "perlin", "perlinmt", "sin", "white", "red", "infrared" },
Perlin = dofile(wea.modpath.."/lib/noise/engines/perlin.lua"),
PerlinMT = dofile(wea.modpath.."/lib/noise/engines/perlinmt.lua"),
Sin = dofile(wea.modpath.."/lib/noise/engines/sin.lua"),
White = dofile(wea.modpath.."/lib/noise/engines/white.lua"),
Red = dofile(wea.modpath.."/lib/noise/engines/red.lua"),

View File

@ -0,0 +1,32 @@
local wea = worldeditadditions
local PerlinMT = {}
PerlinMT.__index = PerlinMT
function PerlinMT.new(seed, params)
if not seed then seed = 0 end
local result = {
-- Provided by Minetest
engine = PerlinNoise({
offset = 0,
scale = 1,
spread = {x = 10, y = 10, z = 10},
seed = seed,
octaves = 1,
persistence = 0.63,
lacunarity = 2.0,
flags = "defaults,absvalue",
})
}
setmetatable(result, PerlinMT)
return result
end
function PerlinMT:noise( x, y, z )
local value = self.engine:get_3d(wea.Vector3.new(x, y, z))
return value
end
return PerlinMT

View File

@ -11,12 +11,16 @@ local wea = worldeditadditions
-- @param size Vector An x/y vector representing the size of the noise area to generate.
-- @param params table|table<table> A table of noise params to use to generate the noise. Values that aren't specified are filled in automatically. If a table of tables is specified, it is interpreted as multiple octaves of noise to apply in sequence.
function worldeditadditions.noise.make_2d(size, start_pos, params)
params = worldeditadditions.noise.params_apply_default(params)
local result = {}
for layer_i, layer in ipairs(params) do
local generator
if layer.algorithm == "perlin" then
generator = wea.noise.engines.Perlin.new()
elseif layer.algorithm == "perlinmt" then
generator = wea.noise.engines.PerlinMT.new()
elseif layer.algorithm == "sin" then
generator = wea.noise.engines.Sin.new()
elseif layer.algorithm == "white" then

View File

@ -13,7 +13,7 @@ function worldeditadditions.noise.params_apply_default(params)
-- - A string in the form of digits followed, then the noise will is remapped from the range 0 - 1 to the range -1 - +1 and multiplied by this number / 2, and then for each pixel in the heightmap the corresponding noise value will be added to it.
apply = 5,
-- The backend noise algorithm to use
algorithm = "perlin",
algorithm = "perlinmt",
-- Zooms in and out
scale = wea.Vector3.new(1, 1, 1),
-- Offset the generated noise by this vector.