Add number of iterations, proper array indexing
parent
b250c01351
commit
be87054c49
|
@ -1,6 +1,7 @@
|
||||||
-- peoplecantblur - Generate flat areas
|
-- peoplecantblur - Generate flat areas
|
||||||
|
|
||||||
local HEIGHT_CHECK = 30
|
local HEIGHT_CHECK = 30
|
||||||
|
local BLUR_ITERATIONS = 8
|
||||||
local c_air = minetest.get_content_id("air")
|
local c_air = minetest.get_content_id("air")
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,6 +128,7 @@ local function flatten(ppos, radius)
|
||||||
local emin, emax = vm:read_from_map(minp, maxp)
|
local emin, emax = vm:read_from_map(minp, maxp)
|
||||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
|
local sidelen = maxp.x - minp.x + 1
|
||||||
|
|
||||||
-- Lookup table for content ID groups
|
-- Lookup table for content ID groups
|
||||||
local cache_c = {}
|
local cache_c = {}
|
||||||
|
@ -134,20 +136,20 @@ local function flatten(ppos, radius)
|
||||||
for z = minp.z, maxp.z do
|
for z = minp.z, maxp.z do
|
||||||
for x = minp.x, maxp.x do
|
for x = minp.x, maxp.x do
|
||||||
local ground = get_ground(
|
local ground = get_ground(
|
||||||
data,
|
data,
|
||||||
area,
|
area,
|
||||||
vector.new(x, ppos.y, z),
|
vector.new(x, ppos.y, z),
|
||||||
max_height,
|
max_height,
|
||||||
cache_c,
|
cache_c,
|
||||||
math.abs(x - ppos.x) <= radius and math.abs(z - ppos.z) <= radius
|
math.abs(x - ppos.x) <= radius and math.abs(z - ppos.z) <= radius
|
||||||
)
|
)
|
||||||
heightmap[z * 0x10000 + x] = ground
|
heightmap[(z - minp.z) * sidelen + (x - minp.x)] = ground
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the relative height from the heightmap with relative coordinates
|
-- Get the relative height from the heightmap with relative coordinates
|
||||||
local get_height = function(map, x, z, fallback)
|
local get_height = function(map, x, z, fallback)
|
||||||
local info = map[z * 0x10000 + x]
|
local info = map[(z - minp.z) * sidelen + (x - minp.x)]
|
||||||
if info and info.rel_surface then
|
if info and info.rel_surface then
|
||||||
return info.rel_surface
|
return info.rel_surface
|
||||||
end
|
end
|
||||||
|
@ -155,12 +157,12 @@ local function flatten(ppos, radius)
|
||||||
end
|
end
|
||||||
|
|
||||||
local _dirty_ = false
|
local _dirty_ = false
|
||||||
local E = 1 -- effect width
|
|
||||||
|
|
||||||
-- Apply blur filter on each position and update the nodes
|
-- Apply blur filter on each position and update the nodes
|
||||||
for z = minp.z + E, maxp.z - E do
|
for n = 0, BLUR_ITERATIONS do
|
||||||
for x = minp.x + E, maxp.x - E do
|
for z = minp.z + 1, maxp.z - 1 do
|
||||||
local p_info = heightmap[z * 0x10000 + x]
|
for x = minp.x + 1, maxp.x - 1 do
|
||||||
|
local p_info = heightmap[(z - minp.z) * sidelen + (x - minp.x)]
|
||||||
local nodes = p_info.c_contents
|
local nodes = p_info.c_contents
|
||||||
local old_h = p_info.rel_surface
|
local old_h = p_info.rel_surface
|
||||||
local above = p_info.c_above
|
local above = p_info.c_above
|
||||||
|
@ -174,15 +176,15 @@ local function flatten(ppos, radius)
|
||||||
+----+----+----+ -> 13
|
+----+----+----+ -> 13
|
||||||
]]
|
]]
|
||||||
local h = old_h + (
|
local h = old_h + (
|
||||||
get_height(heightmap, x , z - E, old_h)
|
get_height(heightmap, x , z - 1, old_h)
|
||||||
+ get_height(heightmap, x - E, z , old_h)
|
+ get_height(heightmap, x - 1, z , old_h)
|
||||||
+ get_height(heightmap, x + E, z , old_h)
|
+ get_height(heightmap, x + 1, z , old_h)
|
||||||
+ get_height(heightmap, x , z + E, old_h)
|
+ get_height(heightmap, x , z + 1, old_h)
|
||||||
) * 2 + (
|
) * 2 + (
|
||||||
get_height(heightmap, x - E, z - E, old_h)
|
get_height(heightmap, x - 1, z - 1, old_h)
|
||||||
+ get_height(heightmap, x + E, z - E, old_h)
|
+ get_height(heightmap, x + 1, z - 1, old_h)
|
||||||
+ get_height(heightmap, x - E, z + E, old_h)
|
+ get_height(heightmap, x - 1, z + 1, old_h)
|
||||||
+ get_height(heightmap, x + E, z + E, old_h)
|
+ get_height(heightmap, x + 1, z + 1, old_h)
|
||||||
)
|
)
|
||||||
|
|
||||||
h = math.floor(h / 13 + 0.5)
|
h = math.floor(h / 13 + 0.5)
|
||||||
|
@ -209,6 +211,7 @@ local function flatten(ppos, radius)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not _dirty_ then
|
if not _dirty_ then
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue