mirror of
git://repo.or.cz/rocks.git
synced 2025-01-04 07:10:28 +01:00
Vein generator working with 1 3d perlin per vein and 1 prng per ore.
This commit is contained in:
parent
0d5facc4c5
commit
80d7db8d44
20
init.lua
20
init.lua
@ -8,7 +8,7 @@ if (minetest.get_modpath("intllib")) then
|
|||||||
S = function ( s ) return s end
|
S = function ( s ) return s end
|
||||||
end
|
end
|
||||||
|
|
||||||
local modpath=minetest.get_modpath(minetest.get_current_modname()))
|
local modpath=minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
|
||||||
dofile(modpath.."/register.lua")
|
dofile(modpath.."/register.lua")
|
||||||
|
|
||||||
@ -25,36 +25,36 @@ rocks.noiseparams_layers = {
|
|||||||
-- test layer
|
-- test layer
|
||||||
--
|
--
|
||||||
|
|
||||||
rocks.register_layer("test1",{ gain=40, height=70, limit=2, seed=1 },"rocks:black_granite")
|
rocks.register_layer("test1",{ gain=40, height=70, limit=2, seed=1 }, "air") --"rocks:black_granite")
|
||||||
|
|
||||||
-- uhlie ako vrstva je kokotina.
|
-- uhlie ako vrstva je kokotina.
|
||||||
|
|
||||||
rocks.register_layer("test3",{ gain=40, height=65, limit=2, seed=3 },"rocks:pink_granite")
|
rocks.register_layer("test3",{ gain=40, height=65, limit=2, seed=3 },"air") --"rocks:pink_granite")
|
||||||
|
|
||||||
rocks.register_layer("test4",{ gain=40, height=90, limit=2, seed=4 },"rocks:white_granite")
|
rocks.register_layer("test4",{ gain=40, height=90, limit=2, seed=4 },"air") --"rocks:white_granite")
|
||||||
|
|
||||||
--
|
--
|
||||||
-- test vein
|
-- test vein
|
||||||
--
|
--
|
||||||
|
|
||||||
rocks.register_vein("testvein1",{
|
rocks.register_vein("testvein1",{
|
||||||
spread = {x=5, y=90, z=5}, -- tall, narrow
|
spread = {x=15, y=15, z=15}, -- tall, narrow
|
||||||
-- larger values -> larger and less frequent vein
|
-- larger values -> larger and less frequent vein
|
||||||
treshold=0.5, -- betveen -2 and +2, mapgen will use this or per-ore treshold if it is larger
|
treshold=0.8, -- betveen -2 and +2, mapgen will use this or per-ore treshold if it is larger
|
||||||
-- 2 never generate
|
-- 2 never generate
|
||||||
-- 1 extremly rare
|
-- 1 extremly rare
|
||||||
-- 0 50% chance
|
-- 0 50% chance
|
||||||
-- less than 0 = SPAM
|
-- less than 0 = SPAM
|
||||||
seed = 9, -- random seed
|
seed = 9, -- random seed
|
||||||
hmin=65, -- set to nil to generate everywhere
|
hmin=5, -- set to nil to generate everywhere
|
||||||
hmax=90,
|
hmax=100,
|
||||||
layers={ "test3" }, -- only occur in layers
|
layers={ "test3" }, -- only occur in layers
|
||||||
})
|
})
|
||||||
rocks.register_ore( "testvein1", "default:dirt" , {treshold=0, chance=1 } )
|
rocks.register_ore( "testvein1", "default:glass" , {treshold=0, chance=1 } )
|
||||||
-- treshold=0 chance=1 ... generate everywhere
|
-- treshold=0 chance=1 ... generate everywhere
|
||||||
rocks.register_ore( "testvein1", "default:wood" , {treshold=0, chance=0.2} )
|
rocks.register_ore( "testvein1", "default:wood" , {treshold=0, chance=0.2} )
|
||||||
-- chance<1 ... vein contains chance*100% of the material, evenly randomly distributed
|
-- chance<1 ... vein contains chance*100% of the material, evenly randomly distributed
|
||||||
rocks.register_ore( "testvein1", "default:lava_source", {treshold=0.8, chance=1 } )
|
rocks.register_ore( "testvein1", "default:tree", {treshold=0.87, chance=1 } )
|
||||||
-- treshold>0 ... generate in the center, larger value -> narrower
|
-- treshold>0 ... generate in the center, larger value -> narrower
|
||||||
-- 20% wood, lava in center, dirt the rest
|
-- 20% wood, lava in center, dirt the rest
|
||||||
-- ore with smallest chance and highest treshold is selected
|
-- ore with smallest chance and highest treshold is selected
|
||||||
|
58
mapgen.lua
58
mapgen.lua
@ -2,14 +2,21 @@
|
|||||||
-- layer generator
|
-- layer generator
|
||||||
--
|
--
|
||||||
|
|
||||||
local function mknoises(layers,minp,maxp)
|
local function mknoises(layers,minp,maxp,seed)
|
||||||
local nm={}
|
local nm={}
|
||||||
for ln,ld in pairs(rocks.layers) do
|
for ln,ld in pairs(rocks.layers) do
|
||||||
if (ld.height-ld.gain<maxp.y)and((not ld.maxheight)or(ld.maxheight+ld.gain>minp.y)) then
|
if (ld.height-ld.gain<maxp.y)and((not ld.maxheight)or(ld.maxheight+ld.gain>minp.y)) then
|
||||||
local np=rocks.noiseparams_layers
|
local np=rocks.noiseparams_layers
|
||||||
np.seed=ld.seed
|
np.seed=ld.seed
|
||||||
local side_length = maxp.x - minp.x + 1
|
local side_length = (maxp.x - minp.x) + 1
|
||||||
ld.nmap=minetest.get_perlin_map(np,{x=side_length, y=side_length, z=side_length}):get2dMap({x=minp.x, y=minp.z})
|
local map_lengths_xyz = {x=side_length, y=side_length, z=side_length}
|
||||||
|
ld.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get2dMap({x=minp.x, y=minp.z})
|
||||||
|
local vidx=1
|
||||||
|
for vn,vd in pairs(ld.veins) do
|
||||||
|
-- todo check if hmax,hmin is in current block
|
||||||
|
vd.onmap=minetest.get_perlin_map(vd.np,map_lengths_xyz):get3dMap_flat(minp)
|
||||||
|
vidx=vidx+1
|
||||||
|
end
|
||||||
table.insert(nm,ld)
|
table.insert(nm,ld)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -32,17 +39,17 @@ end
|
|||||||
local stonectx=nil
|
local stonectx=nil
|
||||||
|
|
||||||
minetest.register_on_generated(function(minp, maxp, seed)
|
minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
if not stonectx then stonectx= minetest.get_content_id("default:stone") end
|
if not stone_ctx then stone_ctx= minetest.get_content_id("air") end
|
||||||
-- noise values range (-1;+1) (1 octave)
|
-- noise values range (-1;+1) (1 octave)
|
||||||
-- 3 octaves it is like 1.7 max
|
-- 3 octaves it is like 1.7 max
|
||||||
-- 4 octaves with 0.8 presist = 2.125 max !!
|
-- 4 octaves with 0.8 presist = 2.125 max !!
|
||||||
-- if ...
|
|
||||||
local timebefore=os.clock();
|
local timebefore=os.clock();
|
||||||
local manipulator, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local manipulator, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||||
local nodes = manipulator:get_data()
|
local nodes = manipulator:get_data()
|
||||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||||
-- initialize noises and sort out unused layers
|
-- initialize noises and sort out unused layers
|
||||||
local availlayers=mknoises(rocks.layers,minp,maxp)
|
local availlayers=mknoises(rocks.layers,minp,maxp,seed)
|
||||||
|
local perlin_index = 1
|
||||||
--
|
--
|
||||||
for x=minp.x,maxp.x,1 do
|
for x=minp.x,maxp.x,1 do
|
||||||
for z=minp.z,maxp.z,1 do
|
for z=minp.z,maxp.z,1 do
|
||||||
@ -51,6 +58,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
if (minp.x>0)and(minp.x<200) then layers=nil end --< debug
|
if (minp.x>0)and(minp.x<200) then layers=nil end --< debug
|
||||||
if layers then for y=minp.y,maxp.y,1 do
|
if layers then for y=minp.y,maxp.y,1 do
|
||||||
|
|
||||||
|
local p_pos = area:index(x, y, z)
|
||||||
|
|
||||||
--* select layer
|
--* select layer
|
||||||
local layer
|
local layer
|
||||||
for ln,ld in pairs(layers) do
|
for ln,ld in pairs(layers) do
|
||||||
@ -65,26 +74,47 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
--* select vein
|
--* select vein
|
||||||
local vein=nil
|
local vein=nil
|
||||||
if layer then
|
if layer then
|
||||||
-- vein=todo... iterate vein's noises and select one above it's treshold
|
for vn,vd in pairs(layer.veins) do
|
||||||
|
if ((not vd.hmin) or y>vd.hmin)
|
||||||
|
and((not vd.hmax) or y<vd.hmax)
|
||||||
|
and(vd.onmap[perlin_index]>vd.treshold)
|
||||||
|
then
|
||||||
|
vein=vd
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--if vein then print("[rocks] generate vein") end
|
||||||
end
|
end
|
||||||
|
|
||||||
--* select rock
|
--* select rock
|
||||||
local rock=nil
|
local rock=nil
|
||||||
if vein then
|
if vein then
|
||||||
rock=nil -- todo... --> based on pseudorandom, no pattern, just random
|
for von,vod in pairs(vein.ores) do
|
||||||
elseif layer then
|
if not vod.pr then vod.pr=PseudoRandom(seed+von) end
|
||||||
rock=layer.rock -- not in vein > select base rock
|
if (vein.onmap[perlin_index]>vod.treshold)
|
||||||
|
and(vod.pr:next(0,1)<=vod.chance) --< todo add pseudorandom chance
|
||||||
|
and( (not rock) or
|
||||||
|
(vod.treshold>=rock.treshold
|
||||||
|
-- or vod.chance<=rock.chance works better with this disabled
|
||||||
|
)
|
||||||
|
)
|
||||||
|
then
|
||||||
|
rock=vod
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (not rock) and layer then
|
||||||
|
rock=layer.rock -- not in vein? > select base rock
|
||||||
end
|
end
|
||||||
|
|
||||||
--* place rocks
|
--* place rocks
|
||||||
if rock then
|
if (rock) and(nodes[p_pos]==stone_ctx) then
|
||||||
if not rock.ctx then
|
if not rock.ctx then
|
||||||
rock.ctx=minetest.get_content_id(rock.block)
|
rock.ctx=minetest.get_content_id(rock.node)
|
||||||
end
|
end
|
||||||
local p_pos = area:index(x, y, z)
|
|
||||||
nodes[p_pos] = rock.ctx
|
nodes[p_pos] = rock.ctx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
perlin_index =perlin_index+1
|
||||||
end end
|
end end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
16
register.lua
16
register.lua
@ -22,7 +22,7 @@ rocks.register_layer=function(name,params,rock)
|
|||||||
maxheight=maxheight,
|
maxheight=maxheight,
|
||||||
limit=params.limit,
|
limit=params.limit,
|
||||||
seed=params.seed,
|
seed=params.seed,
|
||||||
rock={ block=rock },
|
rock={ node=rock },
|
||||||
veins={}
|
veins={}
|
||||||
}
|
}
|
||||||
print("[rocks] layer "..name)
|
print("[rocks] layer "..name)
|
||||||
@ -35,7 +35,9 @@ rocks.register_vein=function(name,params)
|
|||||||
rocks.veins[name]={
|
rocks.veins[name]={
|
||||||
np={
|
np={
|
||||||
offset=0, scale=1, octaves=1, presist=0.8,
|
offset=0, scale=1, octaves=1, presist=0.8,
|
||||||
spread=params.spread, seed=params.seed
|
spread={x=params.spread.y, y=params.spread.z, z=params.spread.x},
|
||||||
|
-- swapped, becouse we generate by horizontal layers
|
||||||
|
seed=params.seed
|
||||||
},
|
},
|
||||||
treshold=params.treshold,
|
treshold=params.treshold,
|
||||||
hmin=params.hmin, hmax=params.hmax,
|
hmin=params.hmin, hmax=params.hmax,
|
||||||
@ -51,12 +53,8 @@ end
|
|||||||
rocks.register_ore=function( vein, node, params )
|
rocks.register_ore=function( vein, node, params )
|
||||||
-- params= {treshold=0, chance=1 }
|
-- params= {treshold=0, chance=1 }
|
||||||
ore={ node=node }
|
ore={ node=node }
|
||||||
if params.treshold and (params.treshold>rocks.veins[vein].treshold) then
|
ore.treshold=(params.treshold or rocks.veins[vein].treshold)
|
||||||
ore.treshold=params.treshold
|
ore.chance= (params.chance or 1)
|
||||||
end
|
|
||||||
if params.chance and (params.chance<1) then
|
|
||||||
ore.chance=params.chance
|
|
||||||
end
|
|
||||||
table.insert(rocks.veins[vein].ores, ore)
|
table.insert(rocks.veins[vein].ores, ore)
|
||||||
print("[rocks] ore "..node.." in "..vein.." chance="..(ore.chance or "1").." treshold="..(ore.treshold or rocks.veins[vein].treshold))
|
print("[rocks] ore "..node.." in "..vein.." chance="..ore.chance.." treshold="..ore.treshold)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user