refactoring : terraforming.py
This commit is contained in:
@@ -31,13 +31,11 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask
|
|||||||
if mask.getpixel((x, z)) != 0 and treesmap.getpixel((x, z)) > 0:
|
if mask.getpixel((x, z)) != 0 and treesmap.getpixel((x, z)) > 0:
|
||||||
|
|
||||||
tree_area = morphology.flood(treesmap, (z, x), tolerance=1)
|
tree_area = morphology.flood(treesmap, (z, x), tolerance=1)
|
||||||
removed_treesmap = img.fromarray(
|
removed_treesmap = img.fromarray(np.where(tree_area, treesmap, 0).astype(np.uint8))
|
||||||
np.where(tree_area, treesmap, 0).astype(np.uint8))
|
|
||||||
|
|
||||||
y = heightmap.getpixel((x, z))
|
y = heightmap.getpixel((x, z))
|
||||||
y_top = removed_treesmap.getpixel((x, z))
|
y_top = removed_treesmap.getpixel((x, z))
|
||||||
geometry.placeLine(
|
geometry.placeLine(editor, (start[0] + x, y+1, start[1] + z), (start[0] + x, y_top, start[1] + z), Block('air'))
|
||||||
editor, (start[0] + x, y+1, start[1] + z), (start[0] + x, y_top, start[1] + z), Block('air'))
|
|
||||||
|
|
||||||
removed_treesmap.save('./world_maker/data/removed_treesmap.png')
|
removed_treesmap.save('./world_maker/data/removed_treesmap.png')
|
||||||
print("[Remove tree] Done.")
|
print("[Remove tree] Done.")
|
||||||
@@ -64,8 +62,7 @@ def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Im
|
|||||||
slice = editor.loadWorldSlice(build_rectangle)
|
slice = editor.loadWorldSlice(build_rectangle)
|
||||||
smoothable_blocks = lookup.OVERWORLD_SOILS | lookup.OVERWORLD_STONES | lookup.SNOWS
|
smoothable_blocks = lookup.OVERWORLD_SOILS | lookup.OVERWORLD_STONES | lookup.SNOWS
|
||||||
|
|
||||||
for x in range(0, distance[0]):
|
for (x, z) in [(x, z) for x in range(distance[0]) for z in range(distance[1])] :
|
||||||
for z in range(0, distance[1]):
|
|
||||||
|
|
||||||
if mask.getpixel((x, z)) == 0:
|
if mask.getpixel((x, z)) == 0:
|
||||||
continue
|
continue
|
||||||
@@ -81,14 +78,11 @@ def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Im
|
|||||||
if block.id not in smoothable_blocks:
|
if block.id not in smoothable_blocks:
|
||||||
continue
|
continue
|
||||||
if delta > 0:
|
if delta > 0:
|
||||||
geometry.placeLine(
|
geometry.placeLine(editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), Block('air'))
|
||||||
editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), Block('air'))
|
editor.placeBlock((start[0] + x, y_smooth, start[1] + z), block)
|
||||||
editor.placeBlock(
|
|
||||||
(start[0] + x, y_smooth, start[1] + z), block)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
geometry.placeLine(
|
geometry.placeLine(editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), block)
|
||||||
editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), block)
|
|
||||||
|
|
||||||
smooth_terrain_delta.save('./world_maker/data/smooth_terrain_delta.png')
|
smooth_terrain_delta.save('./world_maker/data/smooth_terrain_delta.png')
|
||||||
print("[Smooth terrain] Done.")
|
print("[Smooth terrain] Done.")
|
||||||
|
|||||||
Reference in New Issue
Block a user