PerlinNoiseMap

From Minetest Developer Wiki
Revision as of 11:56, 4 June 2014 by 85.1.67.73 (talk) (Add examples + noiseparams)
Jump to navigation Jump to search

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.