mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-22 19:45:02 +00:00
Noise: add perlinmt algorithm & set as default
This commit is contained in:
parent
7de09e92b3
commit
6f00394d3d
5 changed files with 41 additions and 3 deletions
|
@ -31,6 +31,7 @@ read_globals = {
|
|||
"it",
|
||||
"describe",
|
||||
"bonemeal",
|
||||
"dofile"
|
||||
"dofile",
|
||||
"PerlinNoise"
|
||||
}
|
||||
std = "max"
|
||||
|
|
|
@ -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"),
|
||||
|
|
32
worldeditadditions/lib/noise/engines/perlinmt.lua
Normal file
32
worldeditadditions/lib/noise/engines/perlinmt.lua
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue