2021-07-03 00:44:36 +00:00
local wea = worldeditadditions
2021-03-16 21:39:12 +00:00
--- Makes sure that the default settings are all present in the given params table.
-- This way not all params have to be specified by the user.
-- @param params table The params table generated from the user's input.
-- @return table A NEW table with all the missing properties filled in with the default values.
function worldeditadditions . noise . params_apply_default ( params )
local params_default = {
2021-07-03 00:44:36 +00:00
-- How to apply the noise to the heightmap. Different values result in
-- different effects:
-- - The exact string "add": Noise values are added to each heightmap pixel.
-- - The exact string "multiply": Each heightmap pixel is multiplied by the corresponding noise value.
2021-07-06 00:08:36 +00:00
-- - 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.
2021-07-04 12:21:13 +00:00
apply = 5 ,
2021-07-03 00:44:36 +00:00
-- The backend noise algorithm to use
2021-03-16 21:39:12 +00:00
algorithm = " perlin " ,
-- Zooms in and out
2021-07-03 00:44:36 +00:00
scale = wea.Vector3 . new ( 1 , 1 , 1 ) ,
2021-03-16 21:39:12 +00:00
-- Offset the generated noise by this vector.
2021-07-03 00:44:36 +00:00
offset = wea.Vector3 . new ( 0 , 0 , 0 ) ,
2021-03-16 21:39:12 +00:00
-- Apply this exponent to the resulting noise value
exponent = 1 ,
-- Multiply the resulting noise value by this number. Changes the "strength" of the noise
multiply = 1 ,
-- Add this number to the resulting noise value
add = 0
-- The seed to generate the noise with. nil = randomly chosen
-- The perlin generator isn't currently seedable :-/
-- seed = nil
}
if not params [ 1 ] then params = { params } end
-- If params[1] is thing, this is a list of params
2021-07-03 21:53:16 +00:00
-- This might be a thing if we're dealing with multiple octaves
2021-03-16 21:39:12 +00:00
for i , params_el in ipairs ( params ) do
2021-07-12 01:45:32 +00:00
local default_copy = wea.table . shallowcopy ( params_default )
2021-07-03 21:53:16 +00:00
-- Keyword support
2021-07-12 01:45:32 +00:00
for i , keyword in ipairs ( wea.noise . engines.available ) do
if params_el [ keyword ] ~= nil then
params_el.algorithm = keyword
end
end
2021-07-04 12:21:13 +00:00
2021-07-03 21:53:16 +00:00
-- Apply this table to fill in the gaps
2021-07-12 01:45:32 +00:00
wea.table . apply (
2021-03-16 21:39:12 +00:00
params_el ,
default_copy
)
params [ i ] = default_copy
end
return params
end