Add remove tree
10
main.py
@@ -5,6 +5,7 @@ import gdpc.exceptions
|
||||
from world_maker.world_maker import *
|
||||
from world_maker.data_analysis import transpose_form_heightmap
|
||||
from world_maker.Skeleton import Skeleton, simplify_coordinates
|
||||
from world_maker.terraforming import remove_trees
|
||||
from networks.geometry.Point3D import Point3D
|
||||
from networks.roads_2.Road import Road
|
||||
from networks.legacy_roads import roads
|
||||
@@ -20,9 +21,12 @@ def main():
|
||||
buildArea = editor.getBuildArea()
|
||||
origin = ((buildArea.begin).x, (buildArea.begin).z)
|
||||
|
||||
set_roads(skeleton_mountain, origin)
|
||||
set_roads(skeleton_highway, origin)
|
||||
set_roads_grids(road_grid, origin)
|
||||
remove_trees('./world_maker/data/heightmap.png',
|
||||
'./world_maker/data/treemap.png', './world_maker/data/smooth_sobel_watermap.png')
|
||||
|
||||
# set_roads(skeleton_mountain, origin)
|
||||
# set_roads(skeleton_highway, origin)
|
||||
# set_roads_grids(road_grid, origin)
|
||||
# roads.setRoads(skeleton_mountain)
|
||||
# roads.setRoads(skeleton_highway)
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 505 B After Width: | Height: | Size: 254 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 387 B After Width: | Height: | Size: 198 B |
|
Before Width: | Height: | Size: 942 B After Width: | Height: | Size: 844 B |
BIN
world_maker/data/removed_treesmap.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 817 B After Width: | Height: | Size: 960 B |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 9.7 KiB |
|
Before Width: | Height: | Size: 359 B After Width: | Height: | Size: 268 B |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.3 KiB |
@@ -0,0 +1,54 @@
|
||||
from typing import Union
|
||||
|
||||
import numpy as np
|
||||
from gdpc import Editor, Block, geometry
|
||||
from PIL import Image
|
||||
from skimage import morphology
|
||||
|
||||
from world_maker.data_analysis import handle_import_image
|
||||
|
||||
|
||||
def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask: Union[str, Image], ):
|
||||
|
||||
editor = Editor(buffering=True)
|
||||
build_area = editor.getBuildArea()
|
||||
build_rectangle = build_area.toRect()
|
||||
|
||||
start = build_rectangle.begin
|
||||
|
||||
distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]), max(
|
||||
build_rectangle.end[1], build_rectangle.begin[1]) - min(build_rectangle.end[1], build_rectangle.begin[1]))
|
||||
|
||||
heightmap = handle_import_image(heightmap).convert('L')
|
||||
treesmap = handle_import_image(treesmap).convert('L')
|
||||
mask = handle_import_image(mask)
|
||||
|
||||
removed_treesmap = Image.new("RGB", distance, 0)
|
||||
|
||||
removed = []
|
||||
for x in range(0, distance[0]):
|
||||
for z in range(0, distance[1]):
|
||||
|
||||
if mask.getpixel((x, z)) == 255 and treesmap.getpixel((x, z)) > 0 and (x, z) not in removed:
|
||||
|
||||
treeArea = morphology.flood(treesmap, (z, x), tolerance=1)
|
||||
blend = Image.blend(Image.fromarray(treeArea).convert(
|
||||
'RGB'), removed_treesmap.convert('RGB'), 0.5)
|
||||
|
||||
array = np.array(blend.convert('L'))
|
||||
bool_array = array > 1
|
||||
removed_treesmap = Image.fromarray(bool_array)
|
||||
|
||||
removed.append((x, z))
|
||||
print(x, z)
|
||||
|
||||
removed_treesmap.save('./world_maker/data/removed_treesmap.png')
|
||||
|
||||
for x in range(0, distance[0]):
|
||||
for z in range(0, distance[1]):
|
||||
print("removing tree in ", start[0] + x, start[1] + z)
|
||||
if removed_treesmap.getpixel((x, z)) != 0:
|
||||
y = heightmap.getpixel((x, z))
|
||||
y_top = removed_treesmap.getpixel((x, z))
|
||||
geometry.placeLine(
|
||||
editor, (start[0] + x, y+1, start[1] + z), (start[0] + x, y_top, start[1] + z), Block('air'))
|
||||
|
||||