diff --git a/main.py b/main.py index f856f0e..ff1ece2 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ import random from math import exp, sqrt -from gdpc import Editor, Block +from gdpc import Editor, Block, geometry, Transform from House import * from networks.geometry.Point3D import Point3D @@ -15,18 +15,24 @@ from networks.geometry.Point3D import Point3D from networks.geometry.Point2D import Point2D from networks.geometry.Circle import Circle +from PIL import Image +from utils.JsonReader import JsonReader +from utils.YamlReader import YamlReader +from buildings.Building import Building + +from utils.functions import * +from utils.Enums import DIRECTION + def main(): - Road([Point3D(4089, 138, 21), Point3D(4122, 128, 46), - Point3D(4120, 128, 75), Point3D(4154, 128, 90), Point3D(4182, 122, 53)], 9) - # rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker() + rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker() - # editor = Editor(buffering=True) - # buildArea = editor.getBuildArea() - # origin = ((buildArea.begin).x, (buildArea.begin).z) - # center = (abs(buildArea.begin.x - buildArea.end.x) / 2, - # abs(buildArea.begin.z - buildArea.end.z) / 2) - # length_world = sqrt((center[0]*2) ** 2 + (center[1]*2) ** 2) + editor = Editor(buffering=True) + buildArea = editor.getBuildArea() + origin = ((buildArea.begin).x, (buildArea.begin).z) + center = (abs(buildArea.begin.x - buildArea.end.x) / 2, + abs(buildArea.begin.z - buildArea.end.z) / 2) + length_world = sqrt((center[0]*2) ** 2 + (center[1]*2) ** 2) # remove_trees('./world_maker/data/heightmap.png', './world_maker/data/treemap.png', # './world_maker/data/smooth_sobel_watermap.png') @@ -39,43 +45,68 @@ def main(): # roads.setRoads(skeleton_mountain) # roads.setRoads(skeleton_highway) - # blocks = { - # "wall": "blackstone", - # "roof": "blackstone", - # "roof_slab": "blackstone_slab", - # "door": "oak_door", - # "window": "glass_pane", - # "entrance": "oak_door", - # "stairs": "quartz_stairs", - # "stairs_slab": "quartz_slab", - # "celling": "quartz_block", - # "floor": "quartz_block", - # "celling_slab": "quartz_slab", - # "garden_outline": "oak_leaves", - # "garden_floor": "grass_block" - # } + blocks = { + "wall": "blackstone", + "roof": "blackstone", + "roof_slab": "blackstone_slab", + "door": "oak_door", + "window": "glass_pane", + "entrance": "oak_door", + "stairs": "quartz_stairs", + "stairs_slab": "quartz_slab", + "celling": "quartz_block", + "floor": "quartz_block", + "celling_slab": "quartz_slab", + "garden_outline": "oak_leaves", + "garden_floor": "grass_block" + } - # entranceDirection = ["N", "S", "E", "W"] + entranceDirection = ["N", "S", "E", "W"] - # for houses in rectangle_building: - # height = get_height_building_from_center( - # center, (houses[0][0], houses[0][2]), length_world) - # start = (houses[0][0] + origin[0], houses[0] - # [1], houses[0][2] + origin[1]) - # end = (houses[1][0] + origin[0], houses[1] - # [1] + height, houses[1][2] + origin[1]) - # house = House(editor, start, end, - # entranceDirection[random.randint(0, 3)], blocks) - # house.build() + # get every differents buildings shapes + f = JsonReader('./buildings/shapes.json') + shapes = f.data + baseShape = shapes[0]['matrice'] - # for houses in rectangle_house_mountain: - # start = (houses[0][0] + origin[0], houses[0] - # [1], houses[0][2] + origin[1]) - # end = (houses[1][0] + origin[0], houses[1] - # [1], houses[1][2] + origin[1]) - # house = House(editor, start, end, - # entranceDirection[random.randint(0, 3)], blocks) - # house.build() + # get the random data for the buildings + y = YamlReader('params.yml') + random_data = y.data + + # move your editor wto the position you wanna build on + transform = Transform((75, -60, 110), rotation=0) + editor.transform.push(transform) + + # clear the area you build on + geometry.placeCuboid(editor, (-5, 0, -8), (25, 100, 25), Block("air")) + + # create a building at the relative position 0,0 with 20 blocks length and 20 blocks width, with a normal shape and 10 floors + + # build it with your custom materials + + for buildings in rectangle_building: + height = get_height_building_from_center( + center, (buildings[0][0], buildings[0][2]), length_world) + start = (min(buildings[0][0], buildings[1][0]) + origin[0], buildings[0] + [1], min(buildings[0][2], buildings[1][2]) + origin[1]) + end = (max(buildings[0][0], buildings[1][0]) + origin[0], buildings[1] + [1], max(buildings[0][2], buildings[1][2]) + origin[1]) + + transform = Transform(start, rotation=0) + editor.transform.push(transform) + + building = Building(random_data["buildings"], [ + (0, 0, 0), (end[0] - start[0], height, end[2] - start[2])], baseShape, DIRECTION.EAST) + building.build(editor, ["stone_bricks", "glass_pane", "glass", "cobblestone_wall", "stone_brick_stairs", + "oak_planks", "white_concrete", "cobblestone", "stone_brick_slab", "iron_bars"]) + + for buildings in rectangle_house_mountain: + start = (buildings[0][0] + origin[0], buildings[0] + [1], buildings[0][2] + origin[1]) + end = (buildings[1][0] + origin[0], buildings[1] + [1], buildings[1][2] + origin[1]) + house = House(editor, start, end, + entranceDirection[random.randint(0, 3)], blocks) + house.build() def get_height_building_from_center(center, position, length_world): @@ -110,7 +141,10 @@ def set_roads(skeleton: Skeleton, origin): for j in range(len(skeleton.lines[i])): xyz = transpose_form_heightmap('./world_maker/data/heightmap.png', skeleton.coordinates[skeleton.lines[i][j]], origin) - skeleton.lines[i][j] = xyz + heightmap_smooth = Image.open( + './world_maker/data/full_road_heightmap_smooth.png') + skeleton.lines[i][j] = [xyz[0], heightmap_smooth.getpixel( + (skeleton.coordinates[skeleton.lines[i][j]][0], skeleton.coordinates[skeleton.lines[i][j]][-1])), xyz[2]] print("[Roads] Start simplification...") # Simplification @@ -120,7 +154,25 @@ def set_roads(skeleton: Skeleton, origin): skeleton.lines[i] = simplify_coordinates(skeleton.lines[i], 20) j = 0 while j < len(skeleton.lines[i])-1: + print(f"[Distance] {Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2]))}") + if Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2])) <= 20: + print(skeleton.lines[i][j+1], skeleton.lines[i][j]) + del skeleton.lines[i][j+1] + print("[Roads] Delete point to close") + j += 1 + j = 0 + while j < len(skeleton.lines[i])-1: + print(f"[Distance] {Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2]))}") if Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2])) <= 10: + print(skeleton.lines[i][j+1], skeleton.lines[i][j]) + del skeleton.lines[i][j+1] + print("[Roads] Delete point to close") + j += 1 + j = 0 + while j < len(skeleton.lines[i])-1: + print(f"[Distance] {Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2]))}") + if Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2])) <= 10: + print(skeleton.lines[i][j+1], skeleton.lines[i][j]) del skeleton.lines[i][j+1] print("[Roads] Delete point to close") j += 1 @@ -132,6 +184,7 @@ def set_roads(skeleton: Skeleton, origin): print(f"[Roads] Generating roads {i + 1}/{len(skeleton.lines)}.") if len(skeleton.lines[i]) >= 4: Road(Point3D.from_arrays(skeleton.lines[i]), 9) + print(f"[ROAD] Points: {skeleton.lines[i]}") if __name__ == '__main__': diff --git a/networks/roads_2/Road.py b/networks/roads_2/Road.py index 2c3620a..57fbff1 100644 --- a/networks/roads_2/Road.py +++ b/networks/roads_2/Road.py @@ -13,6 +13,8 @@ from scipy.ndimage import gaussian_filter1d import numpy as np import random +from PIL import Image + class Road: def __init__(self, coordinates: List[Point3D], width: int): diff --git a/world_maker/data/building.png b/world_maker/data/building.png index 89a6f19..50e84fd 100644 Binary files a/world_maker/data/building.png and b/world_maker/data/building.png differ diff --git a/world_maker/data/building_moutain.png b/world_maker/data/building_moutain.png index d18f986..98933ce 100644 Binary files a/world_maker/data/building_moutain.png and b/world_maker/data/building_moutain.png differ diff --git a/world_maker/data/city_map.png b/world_maker/data/city_map.png index 1a990ec..90cf32f 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 c3ed8f0..0046569 100644 Binary files a/world_maker/data/district.png and b/world_maker/data/district.png differ diff --git a/world_maker/data/full_road.png b/world_maker/data/full_road.png index 7f0d73b..e1012ce 100644 Binary files a/world_maker/data/full_road.png and b/world_maker/data/full_road.png differ diff --git a/world_maker/data/heightmap.png b/world_maker/data/heightmap.png index 21d1690..f7fd33d 100644 Binary files a/world_maker/data/heightmap.png and b/world_maker/data/heightmap.png differ diff --git a/world_maker/data/heightmap_smooth.png b/world_maker/data/heightmap_smooth.png index 5e40027..063e77e 100644 Binary files a/world_maker/data/heightmap_smooth.png and b/world_maker/data/heightmap_smooth.png differ diff --git a/world_maker/data/heightmap_smooth_2.png b/world_maker/data/heightmap_smooth_2.png index 5e40027..e71b890 100644 Binary files a/world_maker/data/heightmap_smooth_2.png and b/world_maker/data/heightmap_smooth_2.png differ diff --git a/world_maker/data/heightmap_with_building.png b/world_maker/data/heightmap_with_building.png index 9b20ee8..f2118a4 100644 Binary files a/world_maker/data/heightmap_with_building.png and b/world_maker/data/heightmap_with_building.png differ diff --git a/world_maker/data/mountain_map.png b/world_maker/data/mountain_map.png index e0e3f4d..db0394f 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 index 7544604..1d91fc2 100644 Binary files a/world_maker/data/removed_treesmap.png and b/world_maker/data/removed_treesmap.png differ diff --git a/world_maker/data/road_heightmap.png b/world_maker/data/road_heightmap.png index 166aac1..70387cd 100644 Binary files a/world_maker/data/road_heightmap.png and b/world_maker/data/road_heightmap.png differ diff --git a/world_maker/data/roadmap.png b/world_maker/data/roadmap.png index cbe8a38..5519918 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 11fe7c2..1bf7b48 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 9c5a8d3..dae9ab0 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 b1b891a..f75a376 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/skeleton_mountain_area.png b/world_maker/data/skeleton_mountain_area.png index 474cd66..4ee1114 100644 Binary files a/world_maker/data/skeleton_mountain_area.png and b/world_maker/data/skeleton_mountain_area.png differ diff --git a/world_maker/data/smooth_for_highway.png b/world_maker/data/smooth_for_highway.png index 10b6e58..ed6d8b7 100644 Binary files a/world_maker/data/smooth_for_highway.png and b/world_maker/data/smooth_for_highway.png differ diff --git a/world_maker/data/smooth_sobel_watermap.png b/world_maker/data/smooth_sobel_watermap.png index 29ca682..f0dc10e 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/smooth_terrain_delta.png b/world_maker/data/smooth_terrain_delta.png index 3187913..b5eed7b 100644 Binary files a/world_maker/data/smooth_terrain_delta.png and b/world_maker/data/smooth_terrain_delta.png differ diff --git a/world_maker/data/sobelmap.png b/world_maker/data/sobelmap.png index 8ae2aba..d7485e2 100644 Binary files a/world_maker/data/sobelmap.png and b/world_maker/data/sobelmap.png differ diff --git a/world_maker/data/sobelmap_from_smooth.png b/world_maker/data/sobelmap_from_smooth.png index 5f09843..4afcc94 100644 Binary files a/world_maker/data/sobelmap_from_smooth.png and b/world_maker/data/sobelmap_from_smooth.png differ diff --git a/world_maker/data/treemap.png b/world_maker/data/treemap.png index e92da0d..d06ca6a 100644 Binary files a/world_maker/data/treemap.png and b/world_maker/data/treemap.png differ diff --git a/world_maker/data/watermap.png b/world_maker/data/watermap.png index 2141fe0..3d72196 100644 Binary files a/world_maker/data/watermap.png and b/world_maker/data/watermap.png differ diff --git a/world_maker/terraforming.py b/world_maker/terraforming.py index deece8d..e7eb67d 100644 --- a/world_maker/terraforming.py +++ b/world_maker/terraforming.py @@ -56,7 +56,7 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Image], mask: Union[str, Image]): print("[Smooth terrain] Starting...") - editor = Editor() + editor = Editor(buffering=True) build_area = editor.getBuildArea() build_rectangle = build_area.toRect() diff --git a/world_maker/world_maker.py b/world_maker/world_maker.py index c6db398..230f1dc 100644 --- a/world_maker/world_maker.py +++ b/world_maker/world_maker.py @@ -11,9 +11,9 @@ import numpy as np def world_maker(): - # world = World() - # heightmap, watermap, treemap = get_data(world) - heightmap, watermap, treemap = get_data_no_update() + world = World() + heightmap, watermap, treemap = get_data(world) + # heightmap, watermap, treemap = get_data_no_update() heightmap_smooth = filter_smooth(heightmap, 4) heightmap_smooth.save('./world_maker/data/heightmap_smooth.png')