1
0
mirror of git://repo.or.cz/rocks.git synced 2024-11-15 23:10:40 +01:00

Experimental vein generator based on sphere deformed vith 3D noise.

The nyan cat is a bonus :)
This commit is contained in:
Tomáš Brada 2015-04-03 21:32:20 +02:00
parent dbbd865125
commit 229e0e4e80
2 changed files with 51 additions and 0 deletions

18
ign.lua
View File

@ -55,8 +55,26 @@ rocks.register_igneous=reg
reg("rocks:diorite", { spread=40, height=32, treshold=0.23})
reg("rocks:gabbro", { spread=40, height=32, treshold=0.36})
-- vein stuff
local sample_vein_col={
{ primary="default:nyancat",
wherein="rocks:granite",
miny=-160, maxy=20,
radius=10,
--radius={ average=15, amplitude=6 },
density=1,
rarity=0.025, -- this^3*mapblock_volume veins per mapblock
localized={
{ primary="rocks:pegmatite_diamond", size=3, count=5,
rarity=0.3 -- (this/count) chance of spawning cluster in the vein
}
}
}
}
minetest.register_on_generated(function(minp, maxp, seed)
rocksl.layergen(ign,minp,maxp,seed)
rocksl.veingen(sample_vein_col,minp,maxp,seed)
end)
minetest.register_on_shutdown(function()

View File

@ -101,4 +101,37 @@ rocksl.layergen=function(layer, minp, maxp, seed)
end
end
rocksl.veingen=function(veins,minp,maxp,seed)
local side_length=(maxp.y-minp.y)
local random=PseudoRandom(seed-79)
local noise=minetest.get_perlin(-79,1,0.7,8)
print("begin veingen")
for _,vein in ipairs(veins) do
if (minp.y<vein.maxy) and (maxp.y>vein.maxy) then
local iterations_count= (vein.rarity*side_length)^3
iterations_count=iterations_count+random:next(-1,1)
for iteration=1, iterations_count do
local x0=minp.x+ random:next(0,side_length)
local y0=minp.y+ random:next(0,side_length)
local z0=minp.z+ random:next(0,side_length)
if true or (minetest.get_node({x0,y0,z0}).name==vein.wherein) then
print("vein "..vein.primary.." @ "..x0..","..y0..","..z0)
for x=-vein.radius, vein.radius do
for y=-vein.radius, vein.radius do
for z=-vein.radius, vein.radius do
p={x=x+x0,y=y+y0,z=z+z0}
local nv=noise:get3d(p)*5
if ((x^2)+(y^2)+(z^2))<((vein.radius+nv)^2) then
minetest.set_node(p, {name=vein.primary})
end
end end end
else
print("vein "..vein.primary.." bad environmnent")
end
end
end
end
print("end veingen")
end
-- ~ Tomas Brod