True roads very quick

This commit is contained in:
2024-06-24 21:54:10 +02:00
parent cf889d3e10
commit 8a3909c12f
21 changed files with 146 additions and 72 deletions

60
main.py
View File

@@ -17,43 +17,45 @@ from networks.geometry.Circle import Circle
def main():
rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker()
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()
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')
smooth_terrain('./world_maker/data/heightmap.png',
'./world_maker/data/heightmap_smooth.png', './world_maker/data/smooth_sobel_watermap.png')
# remove_trees('./world_maker/data/heightmap.png', './world_maker/data/treemap.png',
# './world_maker/data/smooth_sobel_watermap.png')
# smooth_terrain('./world_maker/data/heightmap.png',
# './world_maker/data/heightmap_smooth.png', './world_maker/data/smooth_sobel_watermap.png')
set_roads(skeleton_highway, origin)
set_roads(skeleton_mountain, origin)
# set_roads(skeleton_highway, origin)
# set_roads(skeleton_mountain, origin)
# set_roads_grids(road_grid, origin)
# 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(

View File

@@ -240,7 +240,7 @@ class Segment2D:
reel_distance = self.points_thick_by_line[0][0].distance(
self.points_thick_by_line[-1][0])
delta_correction = round(reel_distance - thickness)
delta_correction = round(reel_distance - thickness)-1
if delta_correction > 0:
for i in range(delta_correction):
if (-1) ** i == 1:

View File

@@ -11,6 +11,7 @@ from utils.Enums import LINE_THICKNESS_MODE
from gdpc import Block, Editor, geometry
from scipy.ndimage import gaussian_filter1d
import numpy as np
import random
class Road:
@@ -61,36 +62,62 @@ class Road:
if len(self.polyline.segments[i].segment()) > 2:
last_valid_index = i
self.polyline.segments[i].segment_thick(
self.width, LINE_THICKNESS_MODE.MIDDLE)
self.width-1, LINE_THICKNESS_MODE.MIDDLE)
for k in range(len(self.polyline.segments[i].points_thick_by_line)):
kk = k % 7
match kk:
case 0:
blob = 'pink_concrete'
case 1:
blob = 'red_concrete'
case 2:
blob = 'orange_concrete'
case 3:
blob = 'yellow_concrete'
case 4:
blob = 'green_concrete'
case 5:
blob = 'blue_concrete'
case 6:
blob = 'purple_concrete'
for m in range(len(self.polyline.segments[i].points_thick_by_line[k])):
kk = k % self.width
if kk in [round((self.width-1)/2)]:
if m % 4 == 0:
block = random.choices(
["stone", "andesite"],
weights=[3, 1],
k=1,
)[0]
else:
block = random.choices(
["yellow_concrete", "yellow_concrete_powder"],
weights=[3, 1],
k=1,
)[0]
elif kk in [self.width-2, 0]:
block = random.choices(
["white_concrete", "white_concrete_powder"],
weights=[3, 1],
k=1,
)[0]
else:
block = random.choices(
["stone", "andesite"],
weights=[3, 1],
k=1,
)[0]
nearest = self.polyline.segments[i].points_thick_by_line[k][m].nearest(
Point3D.to_2d(self.polyline_total_line_output, removed_axis='y'), True)
self.output_block.append(
(Point3D.insert_3d([self.polyline.segments[i].points_thick_by_line[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block(blob)))
(Point3D.insert_3d([self.polyline.segments[i].points_thick_by_line[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block(block)))
self.output_block.append(
(Point3D.insert_3d([self.polyline.segments[i].points_thick_by_line[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y-1])[0].coordinates, Block(random.choices(
["stone", "andesite"],
weights=[3, 1],
k=1,
)[0])))
for m in range(len(self.polyline.segments[i].gaps[k])):
block = random.choices(
["stone", "andesite"],
weights=[3, 1],
k=1,
)[0]
nearest = self.polyline.segments[i].gaps[k][m].nearest(
Point3D.to_2d(self.polyline_total_line_output, removed_axis='y'), True)
self.output_block.append(
(Point3D.insert_3d([self.polyline.segments[i].gaps[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block("black_concrete")))
(Point3D.insert_3d([self.polyline.segments[i].gaps[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block(block)))
self.output_block.append(
(Point3D.insert_3d([self.polyline.segments[i].gaps[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y-1])[0].coordinates, Block(random.choices(
["stone", "andesite"],
weights=[3, 1],
k=1,
)[0])))
# Circle
if i != len(self.polyline.segments)-1:
@@ -147,25 +174,41 @@ class Road:
Point3D.insert_3d([gaps[j][k]], 'y', [
circle_list[j][gaps[j][k].nearest(Point3D.to_2d(circle_list[j], 'y'), True)[0]].y])[0])
kk = j % 7
match kk:
case 0:
blob = 'pink_concrete'
case 1:
blob = 'red_concrete'
case 2:
blob = 'orange_concrete'
case 3:
blob = 'yellow_concrete'
case 4:
blob = 'green_concrete'
case 5:
blob = 'blue_concrete'
case 6:
blob = 'purple_concrete'
for k in range(len(circle_list[j])):
kk = j % self.width
if kk in [round(self.width/2)]:
if k % 4 == 0:
block = random.choices(
["stone", "andesite"],
weights=[3, 1],
k=1,
)[0]
else:
block = random.choices(
["yellow_concrete", "yellow_concrete_powder"],
weights=[3, 1],
k=1,
)[0]
elif kk in [self.width-1, 0]:
block = random.choices(
["white_concrete", "white_concrete_powder"],
weights=[3, 1],
k=1,
)[0]
else:
block = random.choices(
["stone", "andesite"],
weights=[3, 1],
k=1,
)[0]
self.output_block.append(
(circle_list[j][k].coordinates, Block(blob)))
(circle_list[j][k].coordinates, Block(block)))
self.output_block.append(
((circle_list[j][k].coordinates[0], circle_list[j][k].coordinates[1]-1, circle_list[j][k].coordinates[2]), Block(random.choices(
["stone", "andesite"],
weights=[3, 1],
k=1,
)[0])))
def _projection_gaussian(self):
nearest_points_to_reference = []

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -97,7 +97,7 @@ def area_of_rectangles(rectangles):
def generate_building(image: str | Image.Image, heightmap: str | Image.Image, output: str = './world_maker/data/building.png',
number_of_try: int = 3, min_width: int = 10, max_width: int = 25):
number_of_try: int = 1, min_width: int = 10, max_width: int = 25):
print("[Building] Start generating building position...")
image = handle_import_image(image).convert('L')
rectangles_output = []

View File

@@ -7,10 +7,13 @@ from world_maker.Position import Position
from random import randint
from world_maker.pack_rectangle import generate_building
import numpy as np
def world_maker():
world = World()
heightmap, watermap, treemap = get_data(world)
# 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')
@@ -34,6 +37,7 @@ def world_maker():
road = city.draw_roads(4)
road.save('./world_maker/data/roadmap.png')
# Buildings
subtract_map(smooth_sobel_water_map, road).save(
'./world_maker/data/city_map.png')
subtract_map('./world_maker/data/city_map.png',
@@ -45,6 +49,7 @@ def world_maker():
'./world_maker/data/city_map.png', './world_maker/data/heightmap.png', output='./world_maker/data/building.png')
rectangle_building = rectangle_2D_to_3D(rectangle_building)
# Houses
skeleton_mountain = skeleton_mountain_map(image_mountain_map)
subtract_map('./world_maker/data/mountain_map.png',
'./world_maker/data/skeleton_mountain_area.png').save('./world_maker/data/mountain_map.png')
@@ -52,10 +57,24 @@ def world_maker():
'./world_maker/data/skeleton_highway_area.png').save('./world_maker/data/mountain_map.png')
subtract_map(smooth_sobel_water_map, filter_negative(
'./world_maker/data/mountain_map.png')).save('./world_maker/data/mountain_map.png')
rectangle_mountain = generate_building(
'./world_maker/data/mountain_map.png', './world_maker/data/heightmap.png', output='./world_maker/data/building_moutain.png')
rectangle_mountain = rectangle_2D_to_3D(rectangle_mountain)
# Road
heightmap_smooth_2 = filter_smooth(heightmap, 4)
heightmap_smooth_2.save('./world_maker/data/heightmap_smooth_2.png')
overide_map('./world_maker/data/skeleton_highway_area.png',
'./world_maker/data/skeleton_mountain_area.png').save('./world_maker/data/full_road.png')
overide_map('./world_maker/data/full_road.png',
'./world_maker/data/roadmap.png').save('./world_maker/data/full_road.png')
road_heightmap = subtract_map(
heightmap_smooth_2, filter_negative('./world_maker/data/full_road.png'))
road_heightmap.save('./world_maker/data/road_heightmap.png')
# Terraforming
# Smooth initialization
overide_map('./world_maker/data/heightmap.png',
@@ -63,14 +82,24 @@ def world_maker():
overide_map('./world_maker/data/heightmap_with_building.png',
'./world_maker/data/building.png').save('./world_maker/data/heightmap_with_building.png')
filter_smooth(
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_smooth.png')
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_with_building.png')
overide_map('./world_maker/data/heightmap_with_building.png',
road_heightmap).save('./world_maker/data/heightmap_with_building.png')
filter_smooth('./world_maker/data/heightmap_with_building.png',
2).save('./world_maker/data/heightmap_with_building.png')
# Smooth repetition
for i in range(10):
overide_map('./world_maker/data/heightmap_with_building.png',
'./world_maker/data/building_moutain.png').save('./world_maker/data/heightmap_with_building.png')
overide_map('./world_maker/data/heightmap_with_building.png',
'./world_maker/data/building.png').save('./world_maker/data/heightmap_with_building.png')
filter_smooth(
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_smooth.png')
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_with_building.png')
filter_smooth(
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_smooth.png')
return rectangle_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid