Difference between revisions of "PerlinNoiseMap"

From Minetest Developer Wiki
Jump to navigation Jump to search
(Add examples + noiseparams)
m (Slight reformatting for clarity)
Line 6: Line 6:
 
{| class="wikitable collapsible sortable"
 
{| class="wikitable collapsible sortable"
 
| <source enclose="none">get2dMap(pos)</source>
 
| <source enclose="none">get2dMap(pos)</source>
| <size.x>X<size.y> 2d array of 2d noise values starting at <source enclose="none">pos={x=,y=}</source>
+
| <source enclose="none">size.x</source> '''x''' <source enclose="none">size.y</source> 2d array of 2d noise values starting at <source enclose="none">pos={x=,y=}</source>
 
|-
 
|-
 
| <source enclose="none">get3dMap(pos)</source>
 
| <source enclose="none">get3dMap(pos)</source>
| <size.x>X<size.y>X<size.z> 3d array of 3d noise values starting at <source enclose="none">pos={x=,y=,z=}</source>
+
| <source enclose="none">size.x</source> '''x''' <source enclose="none">size.y</source> '''x''' <source enclose="none">size.z</source> 3d array of 3d noise values starting at <source enclose="none">pos={x=,y=,z=}</source>
 
|-
 
|-
 
| <source enclose="none">get2dMap_flat(pos)</source>
 
| <source enclose="none">get2dMap_flat(pos)</source>
| Flat <size.x * size.y> element array of 2d noise values starting at <source enclose="none">pos={x=,y=}</source>
+
| Flat <source enclose="none">size.x</source> * <source enclose="none">size.y</source> element array of 2d noise values starting at <source enclose="none">pos={x=,y=}</source>
 
|-
 
|-
 
| <source enclose="none">get3dMap_flat(pos)</source>
 
| <source enclose="none">get3dMap_flat(pos)</source>

Revision as of 22:00, 5 July 2014

A fast, bulk perlin noise generator Can be created via

  • PerlinNoiseMap(noiseparams, size)
  • minetest.get_perlin_map(noiseparams, size)

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 an other 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)
Mbox important.png This article is incomplete.
Please help expand this article to include more useful information.