perlinnoise.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ---@meta
  2. ---PerlinNoise and PerlinNoiseMap
  3. ---------------------------------
  4. -- FIXME: No documentation provided.
  5. ---@class mt.PerlinNoiseParams
  6. -- A perlin noise generator. It can be created via `PerlinNoise()` or
  7. -- `minetest.get_perlin()`. For `minetest.get_perlin()`, the actual seed used is
  8. -- the noiseparams seed plus the world seed, to create world-specific noise.
  9. ---@class mt.PerlinNoise
  10. -- Returns 2D noise value at `pos={x=,y=}`.
  11. ---@field get_2d fun(self:self, pos:mt.Vector): mt.PerlinNoise
  12. -- Returns 3D noise value at `pos={x=,y=,z=}`.
  13. ---@field get_3d fun(self:self, pos:mt.Vector): mt.PerlinNoise
  14. ---@overload fun(seeddiff, octaves, persistence, spread):mt.PerlinNoise Deprecated.
  15. ---@param noiseparams mt.PerlinNoiseParams
  16. ---@return mt.PerlinNoise
  17. function PerlinNoise(noiseparams) end
  18. ---@overload fun(seeddiff, octaves, persistence, spread):mt.PerlinNoise Deprecated.
  19. ---@param noiseparams mt.PerlinNoiseParams
  20. ---@return mt.PerlinNoise
  21. function minetest.get_perlin(noiseparams) end
  22. -- A fast, bulk perlin noise generator.
  23. --
  24. -- It can be created via `PerlinNoiseMap(noiseparams, size)` or
  25. -- `minetest.get_perlin_map(noiseparams, size)`. For `minetest.get_perlin_map()`,
  26. -- the actual seed used is the noiseparams seed plus the world seed, to create
  27. -- world-specific noise.
  28. ---@class mt.PerlinNoiseMap
  29. local map
  30. -- Returns a `<size.x>` times `<size.y>` 2D array of 2D noise
  31. -- with values starting at `pos={x=,y=}`.
  32. ---@param pos mt.Vector
  33. ---@return mt.PerlinNoise[]
  34. function map:get_2d_map(pos) end
  35. -- Returns a `<size.x>` times `<size.y>` times `<size.z>` 3D array of 3D noise
  36. -- with values starting at `pos={x=,y=,z=}`.
  37. ---@param pos mt.Vector
  38. ---@return mt.PerlinNoise[][]
  39. function map:get_3d_map(pos) end
  40. -- Returns a flat `<size.x * size.y>` element array of 2D noise
  41. -- with values starting at `pos={x=,y=}`.
  42. ---@param pos mt.Vector
  43. -- If `buffer` is not nil, this table will be used to store the result
  44. -- instead of creating a new table.
  45. ---@param buffer mt.PerlinNoise[]|nil
  46. ---@return mt.PerlinNoise[]
  47. function map:get_2d_map_flat(pos, buffer) end
  48. -- Returns a flat `<size.x * size.y * size.z>` element array of 3D noise
  49. -- with values starting at `pos={x=,y=,z=}`.
  50. ---@param pos mt.Vector
  51. -- If `buffer` is not nil, this table will be used to store the result
  52. -- instead of creating a new table.
  53. ---@param buffer mt.PerlinNoise[]|nil
  54. ---@return mt.PerlinNoise[]
  55. function map:get_3d_map_flat(pos, buffer) end
  56. -- Calculates the 2d noise map starting at `pos`.
  57. -- The result is stored internally.
  58. ---@param pos mt.Vector
  59. function map:calc_2d_map(pos) end
  60. -- Calculates the 3d noise map starting at `pos`.
  61. -- The result is stored internally.
  62. ---@param pos mt.Vector
  63. function map:calc_3d_map(pos) end
  64. -- In the form of an array,
  65. -- returns a slice of the most recently computed noise results. The result slice
  66. -- begins at coordinates `slice_offset` and takes a chunk of `slice_size`. E.g.
  67. -- to grab a 2-slice high horizontal 2d plane of noise starting at buffer offset
  68. -- y = 20: `noisevals = noise:get_map_slice({y=20}, {y=2})` It is important to
  69. -- note that `slice_offset` offset coordinates begin at 1, and are relative to
  70. -- the starting position of the most recently calculated noise. To grab a single
  71. -- vertical column of noise starting at map coordinates x = 1023, y=1000, z =
  72. -- 1000: `noise:calc_3d_map({x=1000, y=1000, z=1000})`
  73. -- `noisevals = noise:get_map_slice({x=24, z=1}, {x=1, z=1})`
  74. ---@param slice_offset mt.Vector
  75. ---@param slice_size mt.Vector
  76. ---@param buffer mt.PerlinNoise[]|nil
  77. ---@return mt.PerlinNoise[]
  78. function map:get_map_slice(slice_offset, slice_size, buffer) end
  79. ---@param noiseparams mt.PerlinNoiseParams
  80. -- Format of `size` is `{x=dimx, y=dimy, z=dimz}`. The `z` component is omitted for
  81. -- 2D noise, and it must be must be larger than 1 for 3D noise (otherwise `nil` is
  82. -- returned).
  83. ---@param size mt.Vector
  84. -- If `buffer` is not nil, this table will be used to store the result
  85. -- instead of creating a new table.
  86. ---@param buffer mt.PerlinNoiseMap|nil
  87. ---@return mt.PerlinNoiseMap
  88. function PerlinNoiseMap(noiseparams, size, buffer) end
  89. ---@param noiseparams mt.PerlinNoiseParams
  90. -- Format of `size` is `{x=dimx, y=dimy, z=dimz}`. The `z` component is omitted for
  91. -- 2D noise, and it must be must be larger than 1 for 3D noise (otherwise `nil` is
  92. -- returned).
  93. ---@param size mt.Vector
  94. -- If `buffer` is not nil, this table will be used to store the result
  95. -- instead of creating a new table.
  96. ---@param buffer mt.PerlinNoiseMap|nil
  97. ---@return mt.PerlinNoiseMap
  98. function minetest.get_perlin_map(noiseparams, size, buffer) end