Minetest-WorldEditAdditions/worldeditadditions/lib/erode/erode.lua
Starbeamrainbowlabs fd5804dd9c
//erode: Finish the initial round of bugfixing, but I'm on the fence about it.
Specifically, I'm unsure about whether I'm happy with the effects of the 
algorithm.
Also, we convolve with a 3x3 gaussian kernel after erosion is complete - 
and we have verified that the erosion is having an positive effect at 
"roughening up" a terrain surface.
It seems like the initial blog post was correct: the algorithm does tend 
to make steep surfaces steeper.
It also appears that it's more effective on larger areas, and 'gentler' 
curves. THis might be because the surface normals are more conducive to 
making the snowballs roll.
Finally, we need to decide whether we want to keep the precomputed 
normals as we have now, or whether we want to dynamically compute them 
at the some of request.
2020-08-21 20:59:50 +01:00

43 lines
1.5 KiB
Lua

worldeditadditions.erode = {}
dofile(worldeditadditions.modpath.."/lib/erode/snowballs.lua")
function worldeditadditions.erode.run(pos1, pos2, algorithm, params)
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local manip, area = worldedit.manip_helpers.init(pos1, pos2)
local data = manip:get_data()
local heightmap_size = {}
heightmap_size[0] = (pos2.z - pos1.z) + 1
heightmap_size[1] = (pos2.x - pos1.x) + 1
local region_height = (pos2.y - pos1.y) + 1
local heightmap = worldeditadditions.make_heightmap(pos1, pos2, manip, area, data)
local heightmap_eroded = worldeditadditions.shallowcopy(heightmap)
-- print("[erode.run] algorithm: "..algorithm..", params:");
-- print(worldeditadditions.map_stringify(params))
worldeditadditions.print_2d(heightmap, heightmap_size[1])
if algorithm == "snowballs" then
local success, msg = worldeditadditions.erode.snowballs(heightmap, heightmap_eroded, heightmap_size, region_height, params)
if not success then return success, msg end
else
return false, "Error: Unknown algorithm '"..algorithm.."'. Currently implemented algorithms: snowballs (2d; hydraulic-like). Ideas for algorithms to implement are welcome!"
end
local success, stats = worldeditadditions.apply_heightmap_changes(
pos1, pos2, area, data,
heightmap, heightmap_eroded, heightmap_size
)
if not success then return success, stats end
worldedit.manip_helpers.finish(manip, data)
print("[erode] stats")
print(worldeditadditions.map_stringify(stats))
return true, stats
end