Add support for NoiseParams in minetest.get_perlin() and add docs on NoiseParams to lua_api.txt
parent
c151099b79
commit
2b8180a417
|
@ -482,23 +482,65 @@ A box of a regular node would look like:
|
||||||
|
|
||||||
type = "leveled" is same as "fixed", but y2 will be automatically set to level from param2
|
type = "leveled" is same as "fixed", but y2 will be automatically set to level from param2
|
||||||
|
|
||||||
|
|
||||||
Meshes
|
Meshes
|
||||||
-----------
|
-----------
|
||||||
If drawtype "mesh" is used tiles should hold model materials textures.
|
If drawtype "mesh" is used tiles should hold model materials textures.
|
||||||
Only static meshes are implemented.
|
Only static meshes are implemented.
|
||||||
For supported model formats see Irrlicht engine documentation.
|
For supported model formats see Irrlicht engine documentation.
|
||||||
|
|
||||||
|
|
||||||
|
Noise Parameters
|
||||||
|
--------------------
|
||||||
|
Noise Parameters, or commonly called NoiseParams, define the properties of perlin noise.
|
||||||
|
- offset
|
||||||
|
Offset that the noise is translated by (i.e. added) after calculation.
|
||||||
|
- scale
|
||||||
|
Factor that the noise is scaled by (i.e. multiplied) after calculation.
|
||||||
|
- spread
|
||||||
|
Vector containing values by which each coordinate is divided by before calculation.
|
||||||
|
Higher spread values result in larger noise features.
|
||||||
|
A value of {x=250, y=250, z=250} is common.
|
||||||
|
- seed
|
||||||
|
Random seed for the noise. Add the world seed to a seed offset for world-unique noise.
|
||||||
|
In the case of minetest.get_perlin(), this value has the world seed automatically added.
|
||||||
|
- octaves
|
||||||
|
Number of times the noise gradient is accumulated into the noise.
|
||||||
|
Increase this number to increase the amount of detail in the resulting noise.
|
||||||
|
A value of 6 is common.
|
||||||
|
- persistence
|
||||||
|
Factor by which the effect of the noise gradient function changes with each successive octave.
|
||||||
|
Values less than 1 make the details of successive octaves' noise diminish, while values
|
||||||
|
greater than 1 make successive octaves stronger.
|
||||||
|
A value of 0.6 is common.
|
||||||
|
- lacunarity
|
||||||
|
Factor by which the noise feature sizes change with each successive octave.
|
||||||
|
A value of 2.0 is common.
|
||||||
|
- flags
|
||||||
|
Leave this field unset for no special handling.
|
||||||
|
Currently supported are:
|
||||||
|
- defaults
|
||||||
|
Specify this if you would like to keep auto-selection of eased/not-eased while specifying
|
||||||
|
some other flags.
|
||||||
|
- eased
|
||||||
|
Maps noise gradient values onto a quintic S-curve before performing interpolation.
|
||||||
|
This results in smooth, rolling noise. Disable this for sharp-looking noise.
|
||||||
|
If no flags are specified (or defaults is), 2D noise is eased and 3D noise is not eased.
|
||||||
|
- absvalue
|
||||||
|
Accumulates the absolute value of each noise gradient result.
|
||||||
|
|
||||||
|
|
||||||
Ore types
|
Ore types
|
||||||
---------------
|
---------------
|
||||||
These tell in what manner the ore is generated.
|
These tell in what manner the ore is generated.
|
||||||
All default ores are of the uniformly-distributed scatter type.
|
All default ores are of the uniformly-distributed scatter type.
|
||||||
|
|
||||||
- scatter
|
- scatter
|
||||||
Randomly chooses a location and generates a cluster of ore.
|
Randomly chooses a location and generates a cluster of ore.
|
||||||
If noise_params is specified, the ore will be placed if the 3d perlin noise at
|
If noise_params is specified, the ore will be placed if the 3d perlin noise at
|
||||||
that point is greater than the noise_threshold, giving the ability to create a non-equal
|
that point is greater than the noise_threshold, giving the ability to create a non-equal
|
||||||
distribution of ore.
|
distribution of ore.
|
||||||
- sheet
|
- sheet
|
||||||
Creates a sheet of ore in a blob shape according to the 2d perlin noise described by noise_params.
|
Creates a sheet of ore in a blob shape according to the 2d perlin noise described by noise_params.
|
||||||
The relative height of the sheet can be controlled by the same perlin noise as well, by specifying
|
The relative height of the sheet can be controlled by the same perlin noise as well, by specifying
|
||||||
a non-zero 'scale' parameter in noise_params. IMPORTANT: The noise is not transformed by offset or
|
a non-zero 'scale' parameter in noise_params. IMPORTANT: The noise is not transformed by offset or
|
||||||
|
@ -506,10 +548,11 @@ All default ores are of the uniformly-distributed scatter type.
|
||||||
The height of the blob is randomly scattered, with a maximum height of clust_size.
|
The height of the blob is randomly scattered, with a maximum height of clust_size.
|
||||||
clust_scarcity and clust_num_ores are ignored.
|
clust_scarcity and clust_num_ores are ignored.
|
||||||
This is essentially an improved version of the so-called "stratus" ore seen in some unofficial mods.
|
This is essentially an improved version of the so-called "stratus" ore seen in some unofficial mods.
|
||||||
- claylike - NOT YET IMPLEMENTED
|
- claylike - NOT YET IMPLEMENTED
|
||||||
Places ore if there are no more than clust_scarcity number of specified nodes within a Von Neumann
|
Places ore if there are no more than clust_scarcity number of specified nodes within a Von Neumann
|
||||||
neighborhood of clust_size radius.
|
neighborhood of clust_size radius.
|
||||||
|
|
||||||
|
|
||||||
Ore attributes
|
Ore attributes
|
||||||
-------------------
|
-------------------
|
||||||
See section Flag Specifier Format.
|
See section Flag Specifier Format.
|
||||||
|
@ -534,6 +577,7 @@ The default value is simple, and is currently the only type supported.
|
||||||
probability of a node randomly appearing when placed. This decoration type is intended to be used
|
probability of a node randomly appearing when placed. This decoration type is intended to be used
|
||||||
for multi-node sized discrete structures, such as trees, cave spikes, rocks, and so on.
|
for multi-node sized discrete structures, such as trees, cave spikes, rocks, and so on.
|
||||||
|
|
||||||
|
|
||||||
Schematic specifier
|
Schematic specifier
|
||||||
--------------------
|
--------------------
|
||||||
A schematic specifier identifies a schematic by either a filename to a Minetest Schematic file (.mts)
|
A schematic specifier identifies a schematic by either a filename to a Minetest Schematic file (.mts)
|
||||||
|
@ -552,6 +596,7 @@ When passed to minetest.create_schematic, probability is an integer value rangin
|
||||||
|
|
||||||
Important note: Node aliases cannot be used for a raw schematic provided when registering as a decoration.
|
Important note: Node aliases cannot be used for a raw schematic provided when registering as a decoration.
|
||||||
|
|
||||||
|
|
||||||
Schematic attributes
|
Schematic attributes
|
||||||
---------------------
|
---------------------
|
||||||
See section Flag Specifier Format.
|
See section Flag Specifier Format.
|
||||||
|
@ -563,6 +608,7 @@ Currently supported flags: place_center_x, place_center_y, place_center_z
|
||||||
- place_center_z
|
- place_center_z
|
||||||
Placement of this decoration is centered along the Z axis.
|
Placement of this decoration is centered along the Z axis.
|
||||||
|
|
||||||
|
|
||||||
HUD element types
|
HUD element types
|
||||||
-------------------
|
-------------------
|
||||||
The position field is used for all element types.
|
The position field is used for all element types.
|
||||||
|
@ -1529,6 +1575,7 @@ minetest.find_node_near(pos, radius, nodenames) -> pos or nil
|
||||||
^ nodenames: e.g. {"ignore", "group:tree"} or "default:dirt"
|
^ nodenames: e.g. {"ignore", "group:tree"} or "default:dirt"
|
||||||
minetest.find_nodes_in_area(minp, maxp, nodenames) -> list of positions
|
minetest.find_nodes_in_area(minp, maxp, nodenames) -> list of positions
|
||||||
^ nodenames: e.g. {"ignore", "group:tree"} or "default:dirt"
|
^ nodenames: e.g. {"ignore", "group:tree"} or "default:dirt"
|
||||||
|
minetest.get_perlin(noiseparams)
|
||||||
minetest.get_perlin(seeddiff, octaves, persistence, scale)
|
minetest.get_perlin(seeddiff, octaves, persistence, scale)
|
||||||
^ Return world-specific perlin noise (int(worldseed)+seeddiff)
|
^ Return world-specific perlin noise (int(worldseed)+seeddiff)
|
||||||
minetest.get_voxel_manip()
|
minetest.get_voxel_manip()
|
||||||
|
@ -2109,8 +2156,8 @@ methods:
|
||||||
implementation making bad distribution otherwise.
|
implementation making bad distribution otherwise.
|
||||||
|
|
||||||
PerlinNoise: A perlin noise generator
|
PerlinNoise: A perlin noise generator
|
||||||
- Can be created via PerlinNoise(seed, octaves, persistence, scale)
|
- Can be created via PerlinNoise(seed, octaves, persistence, scale) or PerlinNoise(noiseparams)
|
||||||
- Also minetest.get_perlin(seeddiff, octaves, persistence, scale)
|
- Also minetest.get_perlin(seeddiff, octaves, persistence, scale) or minetest.get_perlin(noiseparams)
|
||||||
methods:
|
methods:
|
||||||
- get2d(pos) -> 2d noise value at pos={x=,y=}
|
- get2d(pos) -> 2d noise value at pos={x=,y=}
|
||||||
- get3d(pos) -> 3d noise value at pos={x=,y=,z=}
|
- get3d(pos) -> 3d noise value at pos={x=,y=,z=}
|
||||||
|
|
|
@ -590,12 +590,20 @@ int ModApiEnvMod::l_get_perlin(lua_State *L)
|
||||||
{
|
{
|
||||||
GET_ENV_PTR;
|
GET_ENV_PTR;
|
||||||
|
|
||||||
int seeddiff = luaL_checkint(L, 1);
|
NoiseParams params;
|
||||||
int octaves = luaL_checkint(L, 2);
|
|
||||||
float persistence = luaL_checknumber(L, 3);
|
|
||||||
float scale = luaL_checknumber(L, 4);
|
|
||||||
|
|
||||||
LuaPerlinNoise *n = new LuaPerlinNoise(seeddiff + int(env->getServerMap().getSeed()), octaves, persistence, scale);
|
if (lua_istable(L, 1)) {
|
||||||
|
read_noiseparams(L, 1, ¶ms);
|
||||||
|
} else {
|
||||||
|
params.seed = luaL_checkint(L, 1);
|
||||||
|
params.octaves = luaL_checkint(L, 2);
|
||||||
|
params.persist = luaL_checknumber(L, 3);
|
||||||
|
params.spread = v3f(1, 1, 1) * luaL_checknumber(L, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
params.seed += (int)env->getServerMap().getSeed();
|
||||||
|
|
||||||
|
LuaPerlinNoise *n = new LuaPerlinNoise(¶ms);
|
||||||
*(void **)(lua_newuserdata(L, sizeof(void *))) = n;
|
*(void **)(lua_newuserdata(L, sizeof(void *))) = n;
|
||||||
luaL_getmetatable(L, "PerlinNoise");
|
luaL_getmetatable(L, "PerlinNoise");
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
|
|
@ -36,8 +36,8 @@ int LuaPerlinNoise::l_get2d(lua_State *L)
|
||||||
{
|
{
|
||||||
NO_MAP_LOCK_REQUIRED;
|
NO_MAP_LOCK_REQUIRED;
|
||||||
LuaPerlinNoise *o = checkobject(L, 1);
|
LuaPerlinNoise *o = checkobject(L, 1);
|
||||||
v2f pos2d = read_v2f(L,2);
|
v2f p = read_v2f(L, 2);
|
||||||
lua_Number val = noise2d_perlin(pos2d.X/o->scale, pos2d.Y/o->scale, o->seed, o->octaves, o->persistence);
|
lua_Number val = NoisePerlin2D(&o->np, p.X, p.Y, 0);
|
||||||
lua_pushnumber(L, val);
|
lua_pushnumber(L, val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -47,23 +47,30 @@ int LuaPerlinNoise::l_get3d(lua_State *L)
|
||||||
{
|
{
|
||||||
NO_MAP_LOCK_REQUIRED;
|
NO_MAP_LOCK_REQUIRED;
|
||||||
LuaPerlinNoise *o = checkobject(L, 1);
|
LuaPerlinNoise *o = checkobject(L, 1);
|
||||||
v3f pos3d = read_v3f(L,2);
|
v3f p = read_v3f(L, 2);
|
||||||
lua_Number val = noise3d_perlin(pos3d.X/o->scale, pos3d.Y/o->scale, pos3d.Z/o->scale, o->seed, o->octaves, o->persistence);
|
lua_Number val = NoisePerlin3D(&o->np, p.X, p.Y, p.Z, 0);
|
||||||
lua_pushnumber(L, val);
|
lua_pushnumber(L, val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LuaPerlinNoise::LuaPerlinNoise(int a_seed, int a_octaves, float a_persistence,
|
LuaPerlinNoise::LuaPerlinNoise(NoiseParams *params) :
|
||||||
float a_scale):
|
np(*params)
|
||||||
seed(a_seed),
|
|
||||||
octaves(a_octaves),
|
|
||||||
persistence(a_persistence),
|
|
||||||
scale(a_scale)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
LuaPerlinNoise::LuaPerlinNoise(int a_seed, int a_octaves,
|
||||||
|
float a_persistence, float a_scale)
|
||||||
|
{
|
||||||
|
np.seed = a_seed;
|
||||||
|
np.octaves = a_octaves;
|
||||||
|
np.persist = a_persistence;
|
||||||
|
np.spread = v3f(a_scale, a_scale, a_scale);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
LuaPerlinNoise::~LuaPerlinNoise()
|
LuaPerlinNoise::~LuaPerlinNoise()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -74,11 +81,20 @@ LuaPerlinNoise::~LuaPerlinNoise()
|
||||||
int LuaPerlinNoise::create_object(lua_State *L)
|
int LuaPerlinNoise::create_object(lua_State *L)
|
||||||
{
|
{
|
||||||
NO_MAP_LOCK_REQUIRED;
|
NO_MAP_LOCK_REQUIRED;
|
||||||
int seed = luaL_checkint(L, 1);
|
|
||||||
int octaves = luaL_checkint(L, 2);
|
NoiseParams params;
|
||||||
float persistence = luaL_checknumber(L, 3);
|
|
||||||
float scale = luaL_checknumber(L, 4);
|
if (lua_istable(L, 1)) {
|
||||||
LuaPerlinNoise *o = new LuaPerlinNoise(seed, octaves, persistence, scale);
|
read_noiseparams(L, 1, ¶ms);
|
||||||
|
} else {
|
||||||
|
params.seed = luaL_checkint(L, 1);
|
||||||
|
params.octaves = luaL_checkint(L, 2);
|
||||||
|
params.persist = luaL_checknumber(L, 3);
|
||||||
|
params.spread = v3f(1, 1, 1) * luaL_checknumber(L, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaPerlinNoise *o = new LuaPerlinNoise(¶ms);
|
||||||
|
|
||||||
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
|
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
|
||||||
luaL_getmetatable(L, className);
|
luaL_getmetatable(L, className);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
|
|
@ -29,10 +29,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
*/
|
*/
|
||||||
class LuaPerlinNoise : public ModApiBase {
|
class LuaPerlinNoise : public ModApiBase {
|
||||||
private:
|
private:
|
||||||
int seed;
|
NoiseParams np;
|
||||||
int octaves;
|
|
||||||
float persistence;
|
|
||||||
float scale;
|
|
||||||
static const char className[];
|
static const char className[];
|
||||||
static const luaL_reg methods[];
|
static const luaL_reg methods[];
|
||||||
|
|
||||||
|
@ -45,9 +43,7 @@ private:
|
||||||
static int l_get3d(lua_State *L);
|
static int l_get3d(lua_State *L);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LuaPerlinNoise(int a_seed, int a_octaves, float a_persistence,
|
LuaPerlinNoise(NoiseParams *params);
|
||||||
float a_scale);
|
|
||||||
|
|
||||||
~LuaPerlinNoise();
|
~LuaPerlinNoise();
|
||||||
|
|
||||||
// LuaPerlinNoise(seed, octaves, persistence, scale)
|
// LuaPerlinNoise(seed, octaves, persistence, scale)
|
||||||
|
|
Loading…
Reference in New Issue