diff --git a/main.py b/main.py index ec00ed0..7f912dc 100644 --- a/main.py +++ b/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) diff --git a/world_maker/data/building.png b/world_maker/data/building.png index 500240b..4d8c79a 100644 Binary files a/world_maker/data/building.png and b/world_maker/data/building.png differ diff --git a/world_maker/data/city_map.png b/world_maker/data/city_map.png index 69a5698..ae6e3f8 100644 Binary files a/world_maker/data/city_map.png and b/world_maker/data/city_map.png differ diff --git a/world_maker/data/district.png b/world_maker/data/district.png index a8450b7..c4193b7 100644 Binary files a/world_maker/data/district.png and b/world_maker/data/district.png differ diff --git a/world_maker/data/heightmap.png b/world_maker/data/heightmap.png index 661d0e1..b379956 100644 Binary files a/world_maker/data/heightmap.png and b/world_maker/data/heightmap.png differ diff --git a/world_maker/data/highwaymap.png b/world_maker/data/highwaymap.png index 4c8bdf4..dc3fecf 100644 Binary files a/world_maker/data/highwaymap.png and b/world_maker/data/highwaymap.png differ diff --git a/world_maker/data/mountain_map.png b/world_maker/data/mountain_map.png index 3bda4d8..89ef441 100644 Binary files a/world_maker/data/mountain_map.png and b/world_maker/data/mountain_map.png differ diff --git a/world_maker/data/removed_treesmap.png b/world_maker/data/removed_treesmap.png new file mode 100644 index 0000000..f41640e Binary files /dev/null and b/world_maker/data/removed_treesmap.png differ diff --git a/world_maker/data/roadmap.png b/world_maker/data/roadmap.png index 38c872c..da2b612 100644 Binary files a/world_maker/data/roadmap.png and b/world_maker/data/roadmap.png differ diff --git a/world_maker/data/skeleton_highway.png b/world_maker/data/skeleton_highway.png index 908df2d..9ac6485 100644 Binary files a/world_maker/data/skeleton_highway.png and b/world_maker/data/skeleton_highway.png differ diff --git a/world_maker/data/skeleton_highway_area.png b/world_maker/data/skeleton_highway_area.png index 08fb7d9..6a9ecf9 100644 Binary files a/world_maker/data/skeleton_highway_area.png and b/world_maker/data/skeleton_highway_area.png differ diff --git a/world_maker/data/skeleton_mountain.png b/world_maker/data/skeleton_mountain.png index afa970a..44968bb 100644 Binary files a/world_maker/data/skeleton_mountain.png and b/world_maker/data/skeleton_mountain.png differ diff --git a/world_maker/data/smooth_sobel_watermap.png b/world_maker/data/smooth_sobel_watermap.png index 7900f1f..64c79e6 100644 Binary files a/world_maker/data/smooth_sobel_watermap.png and b/world_maker/data/smooth_sobel_watermap.png differ diff --git a/world_maker/data/sobelmap.png b/world_maker/data/sobelmap.png index c981114..4020e72 100644 Binary files a/world_maker/data/sobelmap.png and b/world_maker/data/sobelmap.png differ diff --git a/world_maker/data/treemap.png b/world_maker/data/treemap.png index 058db06..474d635 100644 Binary files a/world_maker/data/treemap.png and b/world_maker/data/treemap.png differ diff --git a/world_maker/terraforming.py b/world_maker/terraforming.py index e69de29..28455b2 100644 --- a/world_maker/terraforming.py +++ b/world_maker/terraforming.py @@ -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'))