From 7c7b7715bcaa1fe11219d2bedefb64753f058970 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Tue, 12 May 2015 19:32:11 +0200 Subject: [PATCH] Vein gen cleanup and experimental ores in veins. --- rocks/veins.lua | 101 ++++++++++++++++++++++++++------------------------------ 1 file changed, 47 insertions(+), 54 deletions(-) rewrite rocks/veins.lua (76%) diff --git a/rocks/veins.lua b/rocks/veins.lua dissimilarity index 76% index 555e0c3..a2a3a95 100644 --- a/rocks/veins.lua +++ b/rocks/veins.lua @@ -1,54 +1,47 @@ --- experimental fast vein generator - -local function draw_sphere(data,area,pos,radius,with) - local rsq=radius^2 - radius=radius+2 - for x=-radius, radius do - for y=-radius, radius do - for z=-radius, radius do - if (x^2)+(y^2)+(z^2)<=rsq then - data[area:index(x+pos.x,y+pos.y,z+pos.z)]=with - end - end end end -end - -local function line(data,area,A,B,with) - local length=vector.distance(A,B) - local step=1/length - for t=0, 1, step do - local p=vector.add(vector.multiply(A,(1-t)), vector.multiply(B,t) ) - p=vector.round(p) - data[area:index(p.x,p.y,p.z)]=with - end -end - -rocksl.genvein=function(minp,maxp,pr,vm,area) - local t1 = os.clock() - local data = vm:get_data() - - 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 c_sample=minetest.get_content_id("default:mese") - - - 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) - local pointB2=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) - local l1=vector.distance(pointA,pointB)+vector.distance(pointB,pointC) - local l2=1/(vector.distance(pointA,pointB2)+vector.distance(pointB2,pointC)) - local step=1.3/math.max(l1,l2) - for t=0, 1, step do - local p - p=vector.multiply(pointA,(1-t)^2) - p=vector.add(p, vector.multiply(pointC,t*t) ) - p=vector.add(p, vector.multiply(pointB,2*t*(1-t)) ) - local p2=vector.add(p, vector.multiply(pointB2,2*t*(1-t)) ) - line(data,area,p,p2,c_sample) - end - - vm:set_data(data) - minetest.log("action", "rocks/genvein/ "..math.ceil((os.clock() - t1) * 1000).." ms ") -end \ No newline at end of file +-- experimental fast vein generator + + +rocksl.genvein=function(minp,maxp,pr,vm,area) + local t1 = os.clock() + local data = vm:get_data() + + 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 c_sample=minetest.get_content_id("default:stone") + local c_sample_ore=minetest.get_content_id("default:mese") + + + local A=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) + local B=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) + local C=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) + local D=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) + local l1=vector.distance(A,C)+vector.distance(C,B) + local l2=vector.distance(A,D)+vector.distance(D,B) + local step=1.4/math.max(l1,l2) + print("step="..step.." l1="..l1.." l2="..l2) + local scarcity=6 + local ocn=pr:next(0,scarcity)+(scarcity/2) + for t=0, 1, step do + local P=vector.multiply(A,(1-t)^2) + P=vector.add(P, vector.multiply(B,t*t) ) + local Q=vector.add(P, vector.multiply(D,2*t*(1-t)) ) + P=vector.add(P, vector.multiply(C,2*t*(1-t)) ) + local step2=1/vector.distance(P,Q) + for u=0, 1, step2 do + local R=vector.add(vector.multiply(P,(1-u)), vector.multiply(Q,u) ) + local di=area:indexp(vector.round(R)) + if ocn<1 then + data[di]=c_sample_ore + ocn=pr:next(0,scarcity)+(scarcity/2) + else + data[di]=c_sample + ocn=ocn-1 + end + end + end + + vm:set_data(data) + minetest.log("action", "rocks/genvein/ "..math.ceil((os.clock() - t1) * 1000).." ms ") +end \ No newline at end of file -- 2.11.4.GIT