diff --git a/world_maker/World.py b/world_maker/World.py index 3fc41c0..3615bea 100644 --- a/world_maker/World.py +++ b/world_maker/World.py @@ -29,8 +29,10 @@ class World: editor = Editor(buffering=True) buildArea = editor.getBuildArea() - self.coordinates_min = [min(buildArea.begin[i], buildArea.last[i]) for i in range(3)] - self.coordinates_max = [max(buildArea.begin[i], buildArea.last[i]) for i in range(3)] + self.coordinates_min = [ + min(buildArea.begin[i], buildArea.last[i]) for i in range(3)] + self.coordinates_max = [ + max(buildArea.begin[i], buildArea.last[i]) for i in range(3)] self.length_x = self.coordinates_max[0] - self.coordinates_min[0] + 1 self.length_y = self.coordinates_max[1] - self.coordinates_min[1] + 1 @@ -62,7 +64,8 @@ class World: Add block or list of block to the volume. """ - self.volume[volumeCoordinates[0]][volumeCoordinates[1]][volumeCoordinates[2]] = None + self.volume[volumeCoordinates[0]][volumeCoordinates[1] + ][volumeCoordinates[2]] = None def getBlockFromCoordinates(self, coordinates): """ @@ -71,7 +74,7 @@ class World: editor = Editor(buffering=True) if self.volume[coordinates[0] - self.coordinates_min[0]][coordinates[1] - self.coordinates_min[1]][ - coordinates[2] - self.coordinates_min[2]] == None: + coordinates[2] - self.coordinates_min[2]] == None: self.volume[coordinates[0] - self.coordinates_min[0]][coordinates[1] - self.coordinates_min[1]][ coordinates[2] - self.coordinates_min[2]] = Block((coordinates[0], coordinates[1], coordinates[2]), editor.getBlock((coordinates[0], coordinates[1], @@ -85,9 +88,11 @@ class World: for j in range(-1, 2): for k in range(-1, 2): if not (i == 0 and j == 0 and k == 0): - coordinates = (Block.coordinates[0] + i, Block.coordinates[1] + j, Block.coordinates[2] + k) + coordinates = ( + Block.coordinates[0] + i, Block.coordinates[1] + j, Block.coordinates[2] + k) if self.isInVolume(coordinates): - Block.addNeighbors([self.getBlockFromCoordinates(coordinates)]) + Block.addNeighbors( + [self.getBlockFromCoordinates(coordinates)]) def setVolume(self): """ @@ -99,7 +104,8 @@ class World: for x in range(self.coordinates_min[0], self.coordinates_max[0] + 1): for y in range(self.coordinates_min[1], self.coordinates_max[1] + 1): for z in range(self.coordinates_min[2], self.coordinates_max[2] + 1): - self.addBlocks([Block((x, y, z), editor.getBlock((x, y, z)).id)]) + self.addBlocks( + [Block((x, y, z), editor.getBlock((x, y, z)).id)]) def getData(self): """ @@ -120,8 +126,10 @@ class World: slice = editor.loadWorldSlice(buildRect) - heightmapData = list(np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype=np.uint8)) - treesmapData = list(np.array(slice.heightmaps["MOTION_BLOCKING"], dtype=np.uint8)) + heightmapData = list( + np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype=np.uint16)) + treesmapData = list( + np.array(slice.heightmaps["MOTION_BLOCKING"], dtype=np.uint16)) for x in range(0, xzDistance[0]): for z in range(0, xzDistance[1]): @@ -148,7 +156,8 @@ class World: # print('getData for tree', xzStart[0] + x + i, k, xzStart[1] + z + j) - blockNeighbor = slice.getBlock((x + i, k, z + j)) + blockNeighbor = slice.getBlock( + (x + i, k, z + j)) if blockNeighbor.id not in lookup.TREES: height += k number += 1 @@ -162,7 +171,9 @@ class World: else: watermap.putpixel((x, z), 0) - self.addBlocks([Block((xzStart[0] + x, 100, xzStart[1] + z), block)]) # y set to 100 for 2D + # y set to 100 for 2D + self.addBlocks( + [Block((xzStart[0] + x, 100, xzStart[1] + z), block)]) return heightmap, watermap, treesmap @@ -213,7 +224,8 @@ class World: slice = editor.loadWorldSlice(buildRect) - heightmapData = list(np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype=np.uint8)) + heightmapData = list( + np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype=np.uint8)) for x in range(0, xzDistance[0]): for z in range(0, xzDistance[1]): @@ -230,4 +242,4 @@ class World: if __name__ == "__main__": w = World() - w.getData() \ No newline at end of file + w.getData() diff --git a/world_maker/data/building.png b/world_maker/data/building.png index 70ffa21..fd47f44 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 0e8436d..abf5458 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 3d9ce62..fd47f44 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 1a884af..36b25df 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 de2b06e..fd47f44 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 121f3f8..98eca9a 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 1f11dcd..780df58 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 47fe2db..8b081d2 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 05d9285..780df58 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 e10a62d..f249124 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 005e6e1..434627a 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 0eeaa04..fd47f44 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 3aed2f0..3c287cc 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 25126f6..042b575 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 d0ffaac..fd47f44 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 46b3242..042b575 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 3ed3c89..fd47f44 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 70accd2..9345f27 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 ee7dc27..f249124 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/sobelmap.png b/world_maker/data/sobelmap.png index c94b85a..bb24c47 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 5d165a6..f683144 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 aec9ce3..07aaab3 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 6ca934d..fd47f44 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 e23c79e..2ded98d 100644 --- a/world_maker/terraforming.py +++ b/world_maker/terraforming.py @@ -17,28 +17,30 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask start = build_rectangle.begin - distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]), + distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]), max(build_rectangle.end[1], build_rectangle.begin[1]) - min(build_rectangle.end[1], build_rectangle.begin[1])) heightmap = handle_import_image(heightmap).convert('L') - treesmap = handle_import_image(treesmap ).convert('L') - mask = handle_import_image(mask) + treesmap = handle_import_image(treesmap).convert('L') + mask = handle_import_image(mask) removed_treesmap = img.new("L", distance, 0) - for (x,z) in [(x,z) for x in range(distance[0]) for z in range(distance[1])] : + for (x, z) in [(x, z) for x in range(distance[0]) for z in range(distance[1])]: - if mask.getpixel((x, z)) != 0 and treesmap.getpixel((x, z)) > 0 : + if mask.getpixel((x, z)) != 0 and treesmap.getpixel((x, z)) > 0: tree_area = morphology.flood(treesmap, (z, x), tolerance=1) - blend = img.blend(img.fromarray(tree_area).convert('L'), removed_treesmap.convert('L'), 0.5) + blend = img.blend(img.fromarray(tree_area).convert( + 'L'), removed_treesmap.convert('L'), 0.5) array = np.array(blend.convert('L')) bool_array = array > 1 removed_treesmap = img.fromarray(bool_array) y = heightmap.getpixel((x, z)) y_top = removed_treesmap.getpixel((x, z)) - geometry.placeLine(editor, (start[0] + x, y+1, start[1] + z), (start[0] + x, y_top, start[1] + z), Block('air')) + geometry.placeLine( + 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.") @@ -53,12 +55,12 @@ def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Im start = build_rectangle.begin - distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]), + distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]), max(build_rectangle.end[1], build_rectangle.begin[1]) - min(build_rectangle.end[1], build_rectangle.begin[1])) - heightmap = handle_import_image(heightmap).convert('L') + heightmap = handle_import_image(heightmap).convert('L') heightmap_smooth = handle_import_image(heightmap_smooth).convert('L') - mask = handle_import_image(mask).convert('L') + mask = handle_import_image(mask).convert('L') smooth_terrain_delta = img.new("RGB", distance, 0) @@ -82,11 +84,14 @@ def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Im if block.id not in smoothable_blocks: continue if delta > 0: - geometry.placeLine(editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), Block('air')) - editor.placeBlock((start[0] + x, y_smooth, start[1] + z), block) + geometry.placeLine( + editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), Block('air')) + editor.placeBlock( + (start[0] + x, y_smooth, start[1] + z), block) else: - geometry.placeLine(editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), block) + geometry.placeLine( + 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("[Smooth terrain] Done.")