Difference between revisions of "PerlinNoiseMap"
Jump to navigation
Jump to search
m (Slight reformatting for clarity) |
(rename Minetest forum to Luanti Forums) |
||
(11 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{UnofficialLua}} | ||
+ | {{DISPLAYTITLE:PerlinNoiseMap minetest.get_perlin_map}} | ||
A fast, bulk perlin noise generator | A fast, bulk perlin noise generator | ||
Can be created via | Can be created via | ||
* <source enclose="none">PerlinNoiseMap(noiseparams, size)</source> | * <source enclose="none">PerlinNoiseMap(noiseparams, size)</source> | ||
* <source enclose="none">minetest.get_perlin_map(noiseparams, size)</source> | * <source enclose="none">minetest.get_perlin_map(noiseparams, size)</source> | ||
+ | The latter function must not be called until after the world is finished initializing, so it must be called during some kind of callback rather than at the top level mod initialization code. The first constructor, on the other hand, may be called at any time since it does not depend on the world's seed. | ||
== Methods == | == Methods == | ||
{| class="wikitable collapsible sortable" | {| class="wikitable collapsible sortable" | ||
Line 28: | Line 31: | ||
}</source> | }</source> | ||
* spread: defines how fast the (ex.) terrain high changes (frequency) | * spread: defines how fast the (ex.) terrain high changes (frequency) | ||
− | * seed: every seed generates | + | * seed: every seed generates a different perlin map |
* octaves: higher value, higher details | * octaves: higher value, higher details | ||
Line 61: | Line 64: | ||
end)</source> | end)</source> | ||
− | + | == See also == | |
+ | * [[PerlinNoise]] | ||
+ | |||
+ | == External Links == | ||
+ | [https://forum.minetest.net/viewtopic.php?f=6&t=8157 Luanti Forums thread: "minetest.get_perlin() and minetest.get_perlin_map() Return nil"] | ||
+ | |||
[[Category:Objects]] | [[Category:Objects]] | ||
+ | [[Category:Mapgen]] |
Latest revision as of 10:20, 25 October 2024
This page contains unofficial, low-quality Lua API documentation and is likely to be outdated or wrong. Do not rely on it! For the official and up-to-date documentation, see Lua API Documentation. |
This page has been proposed for deletion for the following reason: "Contains unofficial and potentially outdated, redundant and inconsistent Lua API information" If you don't think that this page should be deleted, please explain why on the talk page. |
A fast, bulk perlin noise generator Can be created via
PerlinNoiseMap(noiseparams, size)
minetest.get_perlin_map(noiseparams, size)
The latter function must not be called until after the world is finished initializing, so it must be called during some kind of callback rather than at the top level mod initialization code. The first constructor, on the other hand, may be called at any time since it does not depend on the world's seed.
Methods
get2dMap(pos)
|
size.x x size.y 2d array of 2d noise values starting at pos={x=,y=}
|
get3dMap(pos)
|
size.x x size.y x size.z 3d array of 3d noise values starting at pos={x=,y=,z=}
|
get2dMap_flat(pos)
|
Flat size.x * size.y element array of 2d noise values starting at pos={x=,y=}
|
get3dMap_flat(pos)
|
Same as get2dMap_flat, but 3d noise |
Noise Params
Here's an example of the noiseparams:
local testparam = {
offset = 0,
scale = 1,
spread = {x=2048, y=2048, z=2048},
seed = 1337,
octaves = 6,
persist = 0.6
}
- spread: defines how fast the (ex.) terrain high changes (frequency)
- seed: every seed generates a different perlin map
- octaves: higher value, higher details
Examples
minetest.register_on_generated(function(minp, maxp, seed)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local data = vm:get_data()
--get side length of the current mapgen block
local side_length = maxp.x - minp.x + 1
local map_lengths_xyz = {x=side_length, y=side_length, z=side_length}
local perlin_map = minetest.get_perlin_map(testparam, map_lengths_xyz):get2dMap_flat(minp)
--loop
local perlin_index = 1
for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
local vi = area:index(minp.x, y, z)
for x = minp.x, maxp.x do
print("Some spam value: "..tostring(perlin_map[vi])
--more efficient coding - x++
perlin_index = perlin_index + 1
vi = vi + 1
end
--go back, one side_length
perlin_index = perlin_index - side_length
end
--go forward, one side_length
perlin_index = perlin_index + side_length
end
end)
See also
External Links
Luanti Forums thread: "minetest.get_perlin() and minetest.get_perlin_map() Return nil"