Migrate transpose_from_heitmap

This commit is contained in:
2024-06-16 17:07:38 +02:00
parent ed5d7f85a5
commit b3aba8a97c
17 changed files with 22 additions and 22 deletions

24
main.py
View File

@@ -3,7 +3,8 @@ import random
import gdpc.exceptions import gdpc.exceptions
from world_maker.world_maker import * from world_maker.world_maker import *
from world_maker.Skeleton import Skeleton, transpose_form_heightmap, simplify_coordinates from world_maker.data_analysis import transpose_form_heightmap
from world_maker.Skeleton import Skeleton, simplify_coordinates
from networks.geometry.Point3D import Point3D from networks.geometry.Point3D import Point3D
from networks.roads_2.Road import Road from networks.roads_2.Road import Road
from networks.legacy_roads import roads from networks.legacy_roads import roads
@@ -17,12 +18,13 @@ def main():
editor = Editor(buffering=True) editor = Editor(buffering=True)
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
origin = ((buildArea.begin).x, (buildArea.begin).z)
# set_roads(skeleton_mountain) set_roads(skeleton_mountain, origin)
# set_roads(skeleton_highway) set_roads(skeleton_highway, origin)
# set_roads_grids(road_grid) set_roads_grids(road_grid, origin)
roads.setRoads(skeleton_mountain) # roads.setRoads(skeleton_mountain)
roads.setRoads(skeleton_highway) # roads.setRoads(skeleton_highway)
blocks = { blocks = {
"wall": "blackstone", "wall": "blackstone",
@@ -61,28 +63,28 @@ def main():
house.build() house.build()
def set_roads_grids(road_grid: Road_grid): def set_roads_grids(road_grid: Road_grid, origin):
for i in range(len(road_grid)): for i in range(len(road_grid)):
if road_grid[i].border: if road_grid[i].border:
for j in range(len(road_grid)): for j in range(len(road_grid)):
# Same line # Same line
if (road_grid[i].position.x == road_grid[j].position.x and road_grid[i].position.y != road_grid[j].position.y) or (road_grid[i].position.x != road_grid[j].position.x and road_grid[i].position.y == road_grid[j].position.y): if (road_grid[i].position.x == road_grid[j].position.x and road_grid[i].position.y != road_grid[j].position.y) or (road_grid[i].position.x != road_grid[j].position.x and road_grid[i].position.y == road_grid[j].position.y):
point_1 = transpose_form_heightmap( point_1 = transpose_form_heightmap(
'./world_maker/data/heightmap.png', (road_grid[i].position.x, road_grid[i].position.y)) './world_maker/data/heightmap.png', (road_grid[i].position.x, road_grid[i].position.y), origin)
point_2 = transpose_form_heightmap( point_2 = transpose_form_heightmap(
'./world_maker/data/heightmap.png', (road_grid[j].position.x, road_grid[j].position.y)) './world_maker/data/heightmap.png', (road_grid[j].position.x, road_grid[j].position.y), origin)
Road( Road(
[Point3D(point_1[0], point_1[1], point_1[2]), Point3D(point_2[0], point_2[1], point_2[2])], 9) [Point3D(point_1[0], point_1[1], point_1[2]), Point3D(point_2[0], point_2[1], point_2[2])], 9)
def set_roads(skeleton: Skeleton): def set_roads(skeleton: Skeleton, origin):
# Parsing # Parsing
print("[Roads] Start parsing...") print("[Roads] Start parsing...")
for i in range(len(skeleton.lines)): for i in range(len(skeleton.lines)):
print(f"[Roads] Parsing skeleton {i+1}/{len(skeleton.lines)}.") print(f"[Roads] Parsing skeleton {i+1}/{len(skeleton.lines)}.")
for j in range(len(skeleton.lines[i])): for j in range(len(skeleton.lines[i])):
xyz = transpose_form_heightmap('./world_maker/data/heightmap.png', xyz = transpose_form_heightmap('./world_maker/data/heightmap.png',
skeleton.coordinates[skeleton.lines[i][j]]) skeleton.coordinates[skeleton.lines[i][j]], origin)
skeleton.lines[i][j] = xyz skeleton.lines[i][j] = xyz
print("[Roads] Start simplification...") print("[Roads] Start simplification...")

View File

@@ -16,17 +16,6 @@ def handle_import_image(image: Union[str, Image]) -> Image:
return image return image
def transpose_form_heightmap(heightmap: Union[str, Image], coordinates):
heightmap = handle_import_image(heightmap).convert('L')
editor = Editor()
xMin = (editor.getBuildArea().begin).x
zMin = (editor.getBuildArea().begin).z
return (coordinates[0] + xMin, heightmap.getpixel(
(coordinates[0], coordinates[-1])), coordinates[-1] + zMin)
def simplify_coordinates(coordinates, epsilon): def simplify_coordinates(coordinates, epsilon):
if len(coordinates) < 3: if len(coordinates) < 3:
return coordinates return coordinates

Binary file not shown.

Before

Width:  |  Height:  |  Size: 509 B

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 439 B

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 989 B

After

Width:  |  Height:  |  Size: 942 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 824 B

After

Width:  |  Height:  |  Size: 817 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 469 B

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@@ -299,3 +299,12 @@ def rectangle_2D_to_3D(rectangle: list[tuple[tuple[int, int], tuple[int, int]]],
new_rectangle.append( new_rectangle.append(
((start[0], avg_height, start[1]), (end[0], avg_height + randint(height_min, height_max), end[1]))) ((start[0], avg_height, start[1]), (end[0], avg_height + randint(height_min, height_max), end[1])))
return new_rectangle return new_rectangle
def transpose_form_heightmap(heightmap: Union[str, Image], coordinates, origin: tuple[int, int]) -> tuple[int, int, int]:
heightmap = handle_import_image(heightmap).convert('L')
xMin, zMin = origin
return (coordinates[0] + xMin, heightmap.getpixel(
(coordinates[0], coordinates[-1])), coordinates[-1] + zMin)

View File