Try to fix skeleton parsing

This commit is contained in:
2024-06-24 04:47:29 +02:00
parent 5fdfa9e6b9
commit 107b3e08c4
23 changed files with 19 additions and 14 deletions

26
main.py
View File

@@ -26,13 +26,13 @@ def main():
abs(buildArea.begin.z - buildArea.end.z) / 2) abs(buildArea.begin.z - buildArea.end.z) / 2)
length_world = sqrt((center[0]*2) ** 2 + (center[1]*2) ** 2) length_world = sqrt((center[0]*2) ** 2 + (center[1]*2) ** 2)
remove_trees('./world_maker/data/heightmap.png', './world_maker/data/treemap.png', # remove_trees('./world_maker/data/heightmap.png', './world_maker/data/treemap.png',
'./world_maker/data/smooth_sobel_watermap.png') # './world_maker/data/smooth_sobel_watermap.png')
smooth_terrain('./world_maker/data/heightmap.png', # smooth_terrain('./world_maker/data/heightmap.png',
'./world_maker/data/heightmap_smooth.png', './world_maker/data/smooth_sobel_watermap.png') # './world_maker/data/heightmap_smooth.png', './world_maker/data/smooth_sobel_watermap.png')
set_roads(skeleton_mountain, origin) # set_roads(skeleton_highway, origin)
set_roads(skeleton_highway, origin) # set_roads(skeleton_mountain, origin)
# set_roads_grids(road_grid, origin) # set_roads_grids(road_grid, origin)
# roads.setRoads(skeleton_mountain) # roads.setRoads(skeleton_mountain)
# roads.setRoads(skeleton_highway) # roads.setRoads(skeleton_highway)
@@ -114,16 +114,22 @@ def set_roads(skeleton: Skeleton, origin):
# Simplification # Simplification
for i in range(len(skeleton.lines)): for i in range(len(skeleton.lines)):
print(f"[Roads] Simplify skelton {i + 1}/{len(skeleton.lines)}") print(f"[Roads] Simplify skelton {i + 1}/{len(skeleton.lines)}")
skeleton.lines[i] = simplify_coordinates(skeleton.lines[i], 10) print(f"[Roads] Number of points: {len(skeleton.lines[i])}")
skeleton.lines[i] = simplify_coordinates(skeleton.lines[i], 20)
j = 0
while j < len(skeleton.lines[i])-1:
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:
del skeleton.lines[i][j+1]
print("[Roads] Delete point to close")
j += 1
print(
f"[Roads] Number of points after simplification: {len(skeleton.lines[i])}")
print("[Roads] Start generation...") print("[Roads] Start generation...")
for i in range(len(skeleton.lines)): for i in range(len(skeleton.lines)):
print(f"[Roads] Generating roads {i + 1}/{len(skeleton.lines)}.") print(f"[Roads] Generating roads {i + 1}/{len(skeleton.lines)}.")
if len(skeleton.lines[i]) >= 4: if len(skeleton.lines[i]) >= 4:
Road(Point3D.from_arrays(skeleton.lines[i]), 9) Road(Point3D.from_arrays(skeleton.lines[i]), 9)
else:
print(
f"[Roads] Ignore roads {i + 1} with {len(skeleton.lines[i])} coordinates between {skeleton.lines[i][1]} and {skeleton.lines[i][-1]}.")
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -125,7 +125,8 @@ class Road:
self.polyline_total_line_output[nearest[0]].y])[0] self.polyline_total_line_output[nearest[0]].y])[0]
for j in range(len(circle_list)): for j in range(len(circle_list)):
if j != middle_lane_index: if j != middle_lane_index and len(circle_list[j]) > 0:
print(len(circle_list[j]), circle_list[j])
circle_list[j] = circle_list[j][0].optimized_path( circle_list[j] = circle_list[j][0].optimized_path(
circle_list[j]) circle_list[j])
if len(circle_list[j]) != 1: if len(circle_list[j]) != 1:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 B

After

Width:  |  Height:  |  Size: 1005 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 B

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 B

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 750 B

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 790 B

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 B

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 B

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 B

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 936 B

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 905 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -87,6 +87,7 @@ def draw_rectangles(rectangles, grid, heightmap):
image.putpixel((x, y), round(height_average)) image.putpixel((x, y), round(height_average))
return image return image
def area_of_rectangles(rectangles): def area_of_rectangles(rectangles):
area = 0 area = 0
for rectangle in rectangles: for rectangle in rectangles:
@@ -95,7 +96,6 @@ def area_of_rectangles(rectangles):
return area return area
def generate_building(image: str | Image.Image, heightmap: str | Image.Image, output: str = './world_maker/data/building.png', 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 = 3, min_width: int = 10, max_width: int = 25):
print("[Building] Start generating building position...") print("[Building] Start generating building position...")
@@ -111,5 +111,3 @@ def generate_building(image: str | Image.Image, heightmap: str | Image.Image, ou
rectangles_output = rectangles rectangles_output = rectangles
draw_rectangles(rectangles_output, grid, heightmap).save(output) draw_rectangles(rectangles_output, grid, heightmap).save(output)
return rectangles_output return rectangles_output