Add depth to building map
|
Before Width: | Height: | Size: 387 B After Width: | Height: | Size: 89 B |
BIN
world_maker/data/building_moutain.png
Normal file
|
After Width: | Height: | Size: 128 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 217 B |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 432 B |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
world_maker/data/heightmap_with_building.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 645 B After Width: | Height: | Size: 77 B |
|
Before Width: | Height: | Size: 809 B After Width: | Height: | Size: 602 B |
|
Before Width: | Height: | Size: 454 B After Width: | Height: | Size: 133 B |
|
Before Width: | Height: | Size: 888 B After Width: | Height: | Size: 107 B |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 748 B After Width: | Height: | Size: 89 B |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 462 B |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 648 B |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 348 B |
|
Before Width: | Height: | Size: 658 B After Width: | Height: | Size: 249 B |
@@ -156,6 +156,30 @@ def subtract_map(image: Union[str, Image], substractImage: Union[str, Image]) ->
|
||||
return Image.fromarray(array_heightmap)
|
||||
|
||||
|
||||
def overide_map(base: Image, top: Image) -> Image:
|
||||
base = handle_import_image(base).convert('L')
|
||||
top = handle_import_image(top).convert('L')
|
||||
|
||||
width, height = base.size
|
||||
|
||||
if top.size != (width, height):
|
||||
raise ValueError("Mismatching images sizes")
|
||||
|
||||
result_image = Image.new('L', (width, height))
|
||||
|
||||
for x in range(width):
|
||||
for y in range(height):
|
||||
pixel1 = base.getpixel((x, y))
|
||||
pixel2 = top.getpixel((x, y))
|
||||
|
||||
if pixel1 != 0:
|
||||
result_image.putpixel((x, y), pixel1)
|
||||
else:
|
||||
result_image.putpixel((x, y), pixel2)
|
||||
|
||||
return result_image
|
||||
|
||||
|
||||
def group_map(image1: Union[str, Image], image2: Union[str, Image]) -> Image:
|
||||
image1 = handle_import_image(image1).convert('L')
|
||||
image2 = handle_import_image(image2).convert('L')
|
||||
|
||||
@@ -29,7 +29,8 @@ class Bin:
|
||||
best_spot_empty_area = empty_area
|
||||
|
||||
if best_spot is not None:
|
||||
self.rectangles.append((best_spot, (best_spot[0] + rectangle.width, best_spot[1] + rectangle.height)))
|
||||
self.rectangles.append(
|
||||
(best_spot, (best_spot[0] + rectangle.width, best_spot[1] + rectangle.height)))
|
||||
self.update_grid(rectangle, *best_spot)
|
||||
return True
|
||||
|
||||
@@ -57,7 +58,8 @@ class Bin:
|
||||
|
||||
|
||||
def pack_rectangles(rectangles, grid):
|
||||
rectangles = sorted(rectangles, key=lambda r: r.width * r.height, reverse=True)
|
||||
rectangles = sorted(
|
||||
rectangles, key=lambda r: r.width * r.height, reverse=True)
|
||||
bins = [Bin(grid)]
|
||||
|
||||
for rectangle in rectangles:
|
||||
@@ -90,21 +92,23 @@ def pack_rectangles(grid, min_width: int = 10, max_width: int = 25):
|
||||
return bin.rectangles
|
||||
|
||||
|
||||
def draw_rectangles(rectangles, grid):
|
||||
image = Image.new('RGB', (len(grid[0]), len(grid)), (0, 0, 0))
|
||||
def draw_rectangles(rectangles, grid, heightmap):
|
||||
heightmap = handle_import_image(heightmap).convert('L')
|
||||
image = Image.new('L', (len(grid[0]), len(grid)), (0))
|
||||
for rectangle in rectangles:
|
||||
start, end = rectangle
|
||||
for x in range(start[0], end[0]):
|
||||
for y in range(start[1], end[1]):
|
||||
image.putpixel((x, y), (144, 255, 144))
|
||||
image.putpixel((x, y), heightmap.getpixel((x, y)))
|
||||
return image
|
||||
|
||||
|
||||
def generate_building(image: Union[str, Image], min_width: int = 10, max_width: int = 25):
|
||||
def generate_building(image: Union[str, Image], heightmap: Union[str, Image], output: str = './world_maker/data/building.png', min_width: int = 10, max_width: int = 25):
|
||||
image = handle_import_image(image).convert('L')
|
||||
grid = np.array(image)
|
||||
rectangles = pack_rectangles(grid, min_width, max_width)
|
||||
draw_rectangles(rectangles, grid).save('./world_maker/data/building.png')
|
||||
draw_rectangles(rectangles, grid, heightmap).save(
|
||||
output)
|
||||
return rectangles
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from world_maker.data_analysis import handle_import_image
|
||||
|
||||
|
||||
def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask: Union[str, Image]):
|
||||
print(["Remove tree"] Starting...)
|
||||
print("[Remove tree] Starting...")
|
||||
editor = Editor(buffering=True)
|
||||
build_area = editor.getBuildArea()
|
||||
build_rectangle = build_area.toRect()
|
||||
@@ -44,7 +44,6 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask
|
||||
|
||||
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))
|
||||
@@ -52,12 +51,12 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask
|
||||
editor, (start[0] + x, y+1, start[1] + z), (start[0] + x, y_top, start[1] + z), Block('air'))
|
||||
|
||||
removed_treesmap.save('./world_maker/data/removed_treesmap.png')
|
||||
print(["Remove tree"] Done.)
|
||||
print("[Remove tree] Done.")
|
||||
|
||||
|
||||
def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Image], mask: Union[str, Image]):
|
||||
|
||||
print(["Smooth terrain"] Starting...)
|
||||
print("[Smooth terrain] Starting...")
|
||||
editor = Editor()
|
||||
build_area = editor.getBuildArea()
|
||||
build_rectangle = build_area.toRect()
|
||||
@@ -99,4 +98,4 @@ def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Im
|
||||
editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), block)
|
||||
|
||||
smooth_terrain_delta.save('./world_maker/data/smooth_terrain_delta.png')
|
||||
print(["Smoothing terrain"] Done.)
|
||||
print("[Smooth terrain] Done.")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from world_maker.World import World
|
||||
from PIL import Image
|
||||
from world_maker.data_analysis import (get_data, filter_negative, rectangle_2D_to_3D, skeleton_mountain_map, highway_map, filter_sobel, skeleton_highway_map,
|
||||
smooth_sobel_water, subtract_map, detect_mountain, filter_smooth)
|
||||
smooth_sobel_water, subtract_map, detect_mountain, filter_smooth, overide_map)
|
||||
from world_maker.City import City
|
||||
from world_maker.Position import Position
|
||||
from random import randint
|
||||
@@ -34,7 +34,9 @@ def world_maker():
|
||||
'./world_maker/data/skeleton_highway_area.png').save('./world_maker/data/city_map.png')
|
||||
subtract_map('./world_maker/data/city_map.png',
|
||||
'./world_maker/data/mountain_map.png').save('./world_maker/data/city_map.png')
|
||||
rectangle_building = generate_building('./world_maker/data/city_map.png')
|
||||
|
||||
rectangle_building = generate_building(
|
||||
'./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)
|
||||
|
||||
skeleton_mountain = skeleton_mountain_map(image_mountain_map)
|
||||
@@ -43,6 +45,12 @@ def world_maker():
|
||||
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/mountain_map.png', './world_maker/data/heightmap.png', output='./world_maker/data/building_moutain.png')
|
||||
rectangle_mountain = rectangle_2D_to_3D(rectangle_mountain)
|
||||
|
||||
# Terraforming
|
||||
overide_map('./world_maker/data/heightmap.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')
|
||||
return rectangle_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid
|
||||
|
||||