From b183c489ee90f61f9aa0b5e65ab95b07a5fae17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Sun, 10 May 2015 16:05:48 +0200 Subject: [PATCH] Sample cubic bezier vein generator. --- rocks/veins.lua | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/rocks/veins.lua b/rocks/veins.lua index fd2ab79..1679d82 100644 --- a/rocks/veins.lua +++ b/rocks/veins.lua @@ -1,28 +1,42 @@ -- experimental fast vein generator +local pr + rocksl.genvein=function(minp,maxp,seed,vm,area) local t1 = os.clock() local data = vm:get_data() - local chunksize = maxp.x - minp.x + 1 + local chunksizer = maxp.x - minp.x + 1 + local chunksize = chunksizer + 1 local pmapsize = {x = chunksize, y = chunksize, z = chunksize} local minpxz = {x = minp.x, y = minp.z} - local pr=PseudoRandom(seed) + pr=pr or PseudoRandom(seed) local c_sample=minetest.get_content_id("default:mese") + local sample_scarcity=8 - local numveins_raw=(chunksize/8) - local numveins = numveins_raw + (pr:next(-100,100)/100) - local numveins = 1 - print("numveins="..numveins) + local numveins_raw=(chunksize/sample_scarcity) + local numveins = math.floor(numveins_raw + (pr:next(0,99)/100)) + print("numveins="..numveins.." raw="..numveins_raw) + print("pr="..pr:next().." seed="..seed) + print("minp="..minp.x..","..minp.y..","..minp.z) + print("maxp="..maxp.x..","..maxp.y..","..maxp.z) + --local pointA=vector.add(minp,chunksize/2) + local pointA=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) for vc=1, numveins do - local pointA=vector.new(pr:next(minp.x,maxp.x),pr:next(minp.x,maxp.x),pr:next(minp.x,maxp.x)) - local pointB=vector.new(pr:next(minp.x,maxp.x),pr:next(minp.x,maxp.x),pr:next(minp.x,maxp.x)) - local dir=vector.subtract(pointB,pointA) - local step=(1/vector.length(dir)) - --vectorA=vector.add(pointA,minp) + --local pointA=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) + local pointB=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) + local pointC=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) + print("pointA="..pointA.x..","..pointA.y..","..pointA.z) + print("pointB="..pointB.x..","..pointB.y..","..pointB.z) + print("pointC="..pointC.x..","..pointC.y..","..pointC.z) + local step=1.41/(vector.distance(pointA,pointB)+vector.distance(pointB,pointC)) + print("step="..step) for t=0, 1, step do - local p=vector.add(pointA, vector.multiply(dir,t) ) + local p=vector.multiply(pointA,(1-t)^2) + p=vector.add(p, vector.multiply(pointB,2*t*(1-t)) ) + p=vector.add(p, vector.multiply(pointC,t*t) ) + --local p=vector.add(vector.multiply(pointA,(1-t)), vector.multiply(pointB,t) ) p=vector.round(p) local di=area:index(p.x,p.y,p.z) data[di]=c_sample