21 Commits

Author SHA1 Message Date
8f6acab783 remove print
All checks were successful
Linux arm64 / Build (push) Successful in 1m3s
2024-10-02 16:58:58 +02:00
5d856dc66b CONFIG
All checks were successful
Linux arm64 / Build (push) Successful in 1m3s
2024-10-02 16:56:38 +02:00
cf85af9a77 Delete networks/legacy_roads/house.py
Some checks failed
Linux arm64 / Build (push) Failing after 1m11s
2024-10-02 14:33:57 +00:00
4710083a46 Update main.py
Some checks failed
Linux arm64 / Build (push) Failing after 1m12s
2024-10-02 14:29:31 +00:00
8c1f3c3bf5 Update main69.py
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-10-02 14:29:17 +00:00
3598ef42db Update House.py
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-10-02 14:28:54 +00:00
3f0d905503 Add main.py
All checks were successful
Linux arm64 / Build (push) Successful in 1m3s
2024-10-02 14:21:21 +00:00
c6c483b639 Update main2.py
Some checks failed
Linux arm64 / Build (push) Failing after 1m3s
2024-10-02 14:19:52 +00:00
f891d44951 Update main.py
Some checks failed
Linux arm64 / Build (push) Failing after 1m11s
2024-10-02 14:13:55 +00:00
f8e839f1d9 set host
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-10-02 14:11:38 +00:00
1b9f443d76 Update .github/workflows/gdmc.yml
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-10-02 14:09:47 +00:00
1487b76348 Update .github/workflows/gdmc.yml
Some checks failed
Linux arm64 / Build (push) Failing after 58s
2024-10-02 14:07:12 +00:00
d1c347352d Update .github/workflows/gdmc.yml
Some checks failed
Linux arm64 / Build (push) Failing after 57s
2024-10-02 14:03:55 +00:00
cb972cbd06 Update .github/workflows/gdmc.yml
Some checks failed
Linux arm64 / Build (push) Failing after 7s
2024-10-02 14:03:30 +00:00
f08e5e4eca Update .github/workflows/gdmc.yml
Some checks failed
Linux arm64 / Build (push) Failing after 3s
2024-10-02 14:02:34 +00:00
9c4688575c Update .github/workflows/gdmc.yml
Some checks failed
Linux arm64 / Build (push) Failing after 3s
2024-10-02 14:01:33 +00:00
9589d99610 Add .github/workflows/gdmc.yml
Some checks failed
Linux arm64 / Build (push) Failing after 59s
2024-10-02 13:57:29 +00:00
WhyteTiger
3a48815279 refactoring : terraforming.py 2024-09-28 11:01:20 +02:00
12cdacba4e Optimize remove_trees 2024-09-27 23:37:24 +02:00
68241ae415 Fix heightmap generation with trees 2024-09-27 23:02:24 +02:00
Melvyn
f747dd5b46 refactor : suppression d'une double boucle for dans l'algo de remove_trees 2024-09-27 19:47:01 +02:00
37 changed files with 143 additions and 2098 deletions

24
.github/workflows/gdmc.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: Linux arm64
run-name: Run genaration
on: [push]
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Pip
run: |
apt update
apt install python3-virtualenv libgl1-mesa-glx -y
virtualenv --python=python3 pythonenv
source pythonenv/bin/activate
pip install -r requirements.txt
- name: Run
run: |
source pythonenv/bin/activate
python3 main.py

View File

@@ -2,6 +2,7 @@ from time import sleep
from gdpc import Editor, Block, geometry from gdpc import Editor, Block, geometry
import numpy as np import numpy as np
import math import math
import config
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
@@ -1250,7 +1251,7 @@ class House:
if __name__ == "__main__": if __name__ == "__main__":
editor = Editor(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
coordinates_min = [min(buildArea.begin[i], buildArea.last[i]) coordinates_min = [min(buildArea.begin[i], buildArea.last[i])
for i in range(3)] for i in range(3)]

2
config.py Normal file
View File

@@ -0,0 +1,2 @@
def getHost():
return "http://gdmc.ale-pri.com:9000"

19
main.py
View File

@@ -15,7 +15,8 @@ from networks.geometry.Point3D import Point3D
from networks.geometry.Point2D import Point2D from networks.geometry.Point2D import Point2D
from networks.geometry.Circle import Circle from networks.geometry.Circle import Circle
from PIL import Image from PIL import Image as img
from PIL.Image import Image
from utils.JsonReader import JsonReader from utils.JsonReader import JsonReader
from utils.YamlReader import YamlReader from utils.YamlReader import YamlReader
from buildings.Building import Building from buildings.Building import Building
@@ -23,6 +24,7 @@ from buildings.Building import Building
from utils.functions import * from utils.functions import *
from utils.Enums import DIRECTION from utils.Enums import DIRECTION
import time import time
import config
def main(): def main():
@@ -31,7 +33,7 @@ def main():
rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker() rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker()
time_world_maker = time.time() - start_time time_world_maker = time.time() - start_time
print(f"[TIME] World_maker {time_world_maker}") print(f"[TIME] World_maker {time_world_maker}")
editor = Editor(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
origin = ((buildArea.begin).x, (buildArea.begin).z) origin = ((buildArea.begin).x, (buildArea.begin).z)
center = (abs(buildArea.begin.x - buildArea.end.x) / 2, center = (abs(buildArea.begin.x - buildArea.end.x) / 2,
@@ -44,6 +46,7 @@ def main():
time_remove_tree = time.time() - start_time time_remove_tree = time.time() - start_time
print(f"[TIME] Remove tree {time_remove_tree}") print(f"[TIME] Remove tree {time_remove_tree}")
"""
start_time = time.time() start_time = time.time()
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')
@@ -117,17 +120,17 @@ def main():
entranceDirection[random.randint(0, 3)], blocks) entranceDirection[random.randint(0, 3)], blocks)
house.build() house.build()
time_houses = time.time() - start_time time_houses = time.time() - start_time
print(f"[TIME] Houses {time_houses}") print(f"[TIME] Houses {time_houses}") """
print("[GDMC] Done!\n\n") print("[GDMC] Done!\n\n")
print(f"[TIME] Total {time.time() - start_time_all}") print(f"[TIME] Total {time.time() - start_time_all}")
print(f"[TIME] World_maker {time_world_maker}") print(f"[TIME] World_maker {time_world_maker}")
print(f"[TIME] Remove tree {time_remove_tree}") print(f"[TIME] Remove tree {time_remove_tree}")
print(f"[TIME] Smooth terrain {time_smooth_terrain}") #print(f"[TIME] Smooth terrain {time_smooth_terrain}")
print(f"[TIME] Roads {time_roads}") #print(f"[TIME] Roads {time_roads}")
print(f"[TIME] Buildings {time_buildings}") #print(f"[TIME] Buildings {time_buildings}")
print(f"[TIME] Houses {time_houses}") #print(f"[TIME] Houses {time_houses}")
def get_height_building_from_center(center, position, length_world): def get_height_building_from_center(center, position, length_world):
@@ -162,7 +165,7 @@ def set_roads(skeleton: Skeleton, origin):
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]], origin) skeleton.coordinates[skeleton.lines[i][j]], origin)
heightmap_smooth = Image.open( heightmap_smooth = img.open(
'./world_maker/data/road_heightmap.png') './world_maker/data/road_heightmap.png')
skeleton.lines[i][j] = [xyz[0], heightmap_smooth.getpixel( skeleton.lines[i][j] = [xyz[0], heightmap_smooth.getpixel(
(skeleton.coordinates[skeleton.lines[i][j]][0], skeleton.coordinates[skeleton.lines[i][j]][-1])), xyz[2]] (skeleton.coordinates[skeleton.lines[i][j]][0], skeleton.coordinates[skeleton.lines[i][j]][-1])), xyz[2]]

12
main69.py Normal file
View File

@@ -0,0 +1,12 @@
from gdpc import Editor, Block, geometry
editor = Editor(host="http://gdmc.ale-pri.com:9000", buffering=True)
# Get a block
block = editor.getBlock((0,48,0))
# Place a block
editor.placeBlock((0,80,0), Block("stone"))
# Build a cube
geometry.placeCuboid(editor, (0,80,2), (2,82,4), Block("oak_planks"))

View File

@@ -5,6 +5,7 @@ from skan.csr import skeleton_to_csgraph
from collections import Counter from collections import Counter
from PIL import Image from PIL import Image
import random import random
import config
from gdpc import Editor from gdpc import Editor
@@ -141,7 +142,7 @@ class Skeleton:
Returns: Returns:
image: 2D path of the skeleton on top of the heightmap. image: 2D path of the skeleton on top of the heightmap.
""" """
editor = Editor() editor = Editor(host=config.getHost())
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
buildRect = buildArea.toRect() buildRect = buildArea.toRect()

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,7 @@ from gdpc import Block as place
import numpy as np import numpy as np
import networks.legacy_roads.maths as maths import networks.legacy_roads.maths as maths
import math import math
import config
import networks.legacy_roads.tools as tools import networks.legacy_roads.tools as tools
@@ -506,7 +507,7 @@ def irlToMc(coordinates):
heightmap = Image.open('./world_maker/data/heightmap.png') heightmap = Image.open('./world_maker/data/heightmap.png')
editor = Editor() editor = Editor(host=config.getHost())
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
xMin = (editor.getBuildArea().begin).x xMin = (editor.getBuildArea().begin).x
yMin = (editor.getBuildArea().begin).y yMin = (editor.getBuildArea().begin).y
@@ -549,7 +550,7 @@ def setRoads(skeleton):
for i in range(len(housesCoordinates)): for i in range(len(housesCoordinates)):
pos = housesCoordinates[i] pos = housesCoordinates[i]
# print(pos, "pos0") # print(pos, "pos0")
editor = Editor() editor = Editor(host=config.getHost())
xMin = (editor.getBuildArea().begin).x xMin = (editor.getBuildArea().begin).x
yMin = (editor.getBuildArea().begin).y yMin = (editor.getBuildArea().begin).y
zMin = (editor.getBuildArea().begin).z zMin = (editor.getBuildArea().begin).z

View File

@@ -1,10 +1,11 @@
from gdpc import Block as place from gdpc import Block as place
from gdpc import Editor from gdpc import Editor
import config
import networks.legacy_roads.maths as maths import networks.legacy_roads.maths as maths
USE_BATCHING = True USE_BATCHING = True
editor = Editor(buffering=True, caching=True, multithreading=True) editor = Editor(host= config.getHost(), buffering=True, caching=True, multithreading=True)
def setBlock(block, xyz): def setBlock(block, xyz):

View File

@@ -4,6 +4,7 @@ import networks.roads.lanes.Lane as Lane
import networks.roads.lines.Line as Line import networks.roads.lines.Line as Line
import json import json
import random import random
import config
from gdpc import Editor, Block, geometry from gdpc import Editor, Block, geometry
@@ -15,7 +16,7 @@ class Road:
self.width = 10 # TODO self.width = 10 # TODO
def place_roads(self): def place_roads(self):
editor = Editor(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
self.resolution, self.distance = curve_tools.resolution_distance( self.resolution, self.distance = curve_tools.resolution_distance(
self.coordinates, 12) self.coordinates, 12)

View File

@@ -12,6 +12,7 @@ from gdpc import Block, Editor, geometry
from scipy.ndimage import gaussian_filter1d from scipy.ndimage import gaussian_filter1d
import numpy as np import numpy as np
import random import random
import config
from PIL import Image from PIL import Image
@@ -279,7 +280,7 @@ class Road:
self.segment_total_line_output[i].x, reference[self.segment_total_line_output[i].nearest(Point3D.to_2d(reference, 'y'), True)[0]].y, self.segment_total_line_output[i].y), Block("black_concrete"))) self.segment_total_line_output[i].x, reference[self.segment_total_line_output[i].nearest(Point3D.to_2d(reference, 'y'), True)[0]].y, self.segment_total_line_output[i].y), Block("black_concrete")))
def place(self): def place(self):
editor = Editor(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
for i in range(len(self.output_block)): for i in range(len(self.output_block)):
editor.placeBlock(self.output_block[i][0], editor.placeBlock(self.output_block[i][0],
self.output_block[i][1]) self.output_block[i][1])

View File

@@ -4,7 +4,8 @@ from typing import List, Union
import numpy as np import numpy as np
from gdpc import Editor from gdpc import Editor
from PIL import Image, ImageDraw from PIL.Image import Image
from PIL import Image as img, ImageDraw
from skan.csr import skeleton_to_csgraph from skan.csr import skeleton_to_csgraph
from skimage.morphology import skeletonize from skimage.morphology import skeletonize
from networks.geometry.Point3D import Point3D from networks.geometry.Point3D import Point3D
@@ -12,7 +13,7 @@ from networks.geometry.Point3D import Point3D
def handle_import_image(image: Union[str, Image]) -> Image: def handle_import_image(image: Union[str, Image]) -> Image:
if isinstance(image, str): if isinstance(image, str):
return Image.open(image) return img.open(image)
return image return image
@@ -195,7 +196,7 @@ class Skeleton:
image: 2D path of the skeleton on top of the heightmap. image: 2D path of the skeleton on top of the heightmap.
""" """
print("[Skeleton] Start mapping the skeleton...") print("[Skeleton] Start mapping the skeleton...")
# editor = Editor() # editor = Editor(config)
# buildArea = editor.getBuildArea() # buildArea = editor.getBuildArea()
# buildRect = buildArea.toRect() # buildRect = buildArea.toRect()
@@ -203,7 +204,7 @@ class Skeleton:
# xzDistance = (max(buildRect.end[0], buildRect.begin[0]) - min(buildRect.end[0], buildRect.begin[0]), # xzDistance = (max(buildRect.end[0], buildRect.begin[0]) - min(buildRect.end[0], buildRect.begin[0]),
# max(buildRect.end[1], buildRect.begin[1]) - min(buildRect.end[1], buildRect.begin[1])) # max(buildRect.end[1], buildRect.begin[1]) - min(buildRect.end[1], buildRect.begin[1]))
heightmap = Image.open( heightmap = img.open(
"./world_maker/data/heightmap.png").convert('RGB') "./world_maker/data/heightmap.png").convert('RGB')
# roadsArea = Image.new("L", xzDistance, 0) # roadsArea = Image.new("L", xzDistance, 0)
# width, height = heightmap.size # width, height = heightmap.size
@@ -264,9 +265,9 @@ class Skeleton:
def road_area(self, name: str, radius: int = 10) -> Image: def road_area(self, name: str, radius: int = 10) -> Image:
print("[Skeleton] Start mapping the road area...") print("[Skeleton] Start mapping the road area...")
heightmap = Image.open("./world_maker/data/heightmap.png") heightmap = img.open("./world_maker/data/heightmap.png")
width, height = heightmap.size width, height = heightmap.size
road_area_map = Image.new("L", (width, height), 0) road_area_map = img.new("L", (width, height), 0)
road_area_map_draw = ImageDraw.Draw(road_area_map) road_area_map_draw = ImageDraw.Draw(road_area_map)
# Lines # Lines

View File

@@ -2,6 +2,7 @@ from gdpc import Editor, geometry, lookup
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from world_maker.Block import Block from world_maker.Block import Block
import config
waterBiomes = [ waterBiomes = [
"minecraft:ocean", "minecraft:ocean",
@@ -26,11 +27,13 @@ waterBlocks = [
class World: class World:
def __init__(self): def __init__(self):
editor = Editor(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
self.coordinates_min = [min(buildArea.begin[i], buildArea.last[i]) for i in range(3)] self.coordinates_min = [
self.coordinates_max = [max(buildArea.begin[i], buildArea.last[i]) for i in range(3)] 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_x = self.coordinates_max[0] - self.coordinates_min[0] + 1
self.length_y = self.coordinates_max[1] - self.coordinates_min[1] + 1 self.length_y = self.coordinates_max[1] - self.coordinates_min[1] + 1
@@ -62,14 +65,15 @@ class World:
Add block or list of block to the volume. 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): def getBlockFromCoordinates(self, coordinates):
""" """
Use already created volume to get block data. Use already created volume to get block data.
""" """
editor = Editor(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
if self.volume[coordinates[0] - self.coordinates_min[0]][coordinates[1] - self.coordinates_min[1]][ 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]][ self.volume[coordinates[0] - self.coordinates_min[0]][coordinates[1] - self.coordinates_min[1]][
@@ -85,28 +89,31 @@ class World:
for j in range(-1, 2): for j in range(-1, 2):
for k in range(-1, 2): for k in range(-1, 2):
if not (i == 0 and j == 0 and k == 0): 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): if self.isInVolume(coordinates):
Block.addNeighbors([self.getBlockFromCoordinates(coordinates)]) Block.addNeighbors(
[self.getBlockFromCoordinates(coordinates)])
def setVolume(self): def setVolume(self):
""" """
Scan the world with no optimization. Not tested on large areas. Scan the world with no optimization. Not tested on large areas.
""" """
editor = Editor(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
for x in range(self.coordinates_min[0], self.coordinates_max[0] + 1): 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 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): 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): def getData(self):
""" """
Generate all needed datas for the generator : heightmap, watermap, and preset the volume with data from the heightmap. Generate all needed datas for the generator : heightmap, watermap, and preset the volume with data from the heightmap.
""" """
editor = Editor() editor = Editor(host=config.getHost())
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
buildRect = buildArea.toRect() buildRect = buildArea.toRect()
@@ -120,8 +127,10 @@ class World:
slice = editor.loadWorldSlice(buildRect) slice = editor.loadWorldSlice(buildRect)
heightmapData = list(np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype=np.uint8)) heightmapData = list(
treesmapData = list(np.array(slice.heightmaps["MOTION_BLOCKING"], dtype=np.uint8)) 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 x in range(0, xzDistance[0]):
for z in range(0, xzDistance[1]): for z in range(0, xzDistance[1]):
@@ -148,7 +157,8 @@ class World:
# print('getData for tree', xzStart[0] + x + i, k, xzStart[1] + z + j) # 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: if blockNeighbor.id not in lookup.TREES:
height += k height += k
number += 1 number += 1
@@ -162,13 +172,15 @@ class World:
else: else:
watermap.putpixel((x, z), 0) 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 return heightmap, watermap, treesmap
def propagate(self, coordinates, scanned=[]): def propagate(self, coordinates, scanned=[]):
i = 0 i = 0
editor = Editor(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
if self.isInVolume(coordinates): if self.isInVolume(coordinates):
Block = self.getBlockFromCoordinates(coordinates) Block = self.getBlockFromCoordinates(coordinates)
self.getNeighbors(Block) self.getNeighbors(Block)
@@ -201,7 +213,7 @@ class World:
Args: Args:
mask (image): white or black image : combined watermap smoothed and sobel smoothed. mask (image): white or black image : combined watermap smoothed and sobel smoothed.
""" """
editor = Editor() editor = Editor(host=config.getHost())
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
buildRect = buildArea.toRect() buildRect = buildArea.toRect()
@@ -213,7 +225,8 @@ class World:
slice = editor.loadWorldSlice(buildRect) 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 x in range(0, xzDistance[0]):
for z in range(0, xzDistance[1]): for z in range(0, xzDistance[1]):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 421 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 910 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 912 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 308 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 89 B

View File

@@ -2,52 +2,41 @@ from typing import Union
import numpy as np import numpy as np
from gdpc import Editor, Block, geometry, lookup from gdpc import Editor, Block, geometry, lookup
from PIL import Image from PIL import Image as img
from PIL.Image import Image
from skimage import morphology from skimage import morphology
import config
from world_maker.data_analysis import handle_import_image from world_maker.data_analysis import handle_import_image
def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask: Union[str, 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) editor = Editor(host=config.getHost(), buffering=True)
build_area = editor.getBuildArea() build_area = editor.getBuildArea()
build_rectangle = build_area.toRect() build_rectangle = build_area.toRect()
start = build_rectangle.begin start = build_rectangle.begin
distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]), max( distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]),
build_rectangle.end[1], build_rectangle.begin[1]) - min(build_rectangle.end[1], build_rectangle.begin[1])) 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')
treesmap = handle_import_image(treesmap).convert('L') treesmap = handle_import_image(treesmap).convert('L')
mask = handle_import_image(mask) mask = handle_import_image(mask)
removed_treesmap = Image.new("L", distance, 0) removed_treesmap = img.new("L", distance, 0)
removed = [] for (x, z) in [(x, z) for x in range(distance[0]) for z in range(distance[1])] :
for x in range(0, distance[0]):
for z in range(0, distance[1]):
if mask.getpixel((x, z)) != 0 and treesmap.getpixel((x, z)) > 0 and (x, z) not in removed: if mask.getpixel((x, z)) != 0 and treesmap.getpixel((x, z)) > 0:
tree_area = morphology.flood(treesmap, (z, x), tolerance=1) tree_area = morphology.flood(treesmap, (z, x), tolerance=1)
blend = Image.blend(Image.fromarray(tree_area).convert( removed_treesmap = img.fromarray(np.where(tree_area, treesmap, 0).astype(np.uint8))
'L'), removed_treesmap.convert('L'), 0.5)
array = np.array(blend.convert('L'))
bool_array = array > 1
removed_treesmap = Image.fromarray(bool_array)
removed.append((x, z))
for x in range(0, distance[0]):
for z in range(0, distance[1]):
if removed_treesmap.getpixel((x, z)) != 0:
y = heightmap.getpixel((x, z)) y = heightmap.getpixel((x, z))
y_top = removed_treesmap.getpixel((x, z)) y_top = removed_treesmap.getpixel((x, z))
geometry.placeLine( geometry.placeLine(editor, (start[0] + x, y+1, start[1] + z), (start[0] + x, y_top, start[1] + z), Block('air'))
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') removed_treesmap.save('./world_maker/data/removed_treesmap.png')
print("[Remove tree] Done.") print("[Remove tree] Done.")
@@ -56,45 +45,45 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask
def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Image], mask: Union[str, Image]): 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(buffering=True) editor = Editor(host=config.getHost(), buffering=True)
build_area = editor.getBuildArea() build_area = editor.getBuildArea()
build_rectangle = build_area.toRect() build_rectangle = build_area.toRect()
start = build_rectangle.begin start = build_rectangle.begin
distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]), max( distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]),
build_rectangle.end[1], build_rectangle.begin[1]) - min(build_rectangle.end[1], build_rectangle.begin[1])) 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') 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 = Image.new("RGB", distance, 0) smooth_terrain_delta = img.new("RGB", distance, 0)
slice = editor.loadWorldSlice(build_rectangle) slice = editor.loadWorldSlice(build_rectangle)
smoothable_blocks = lookup.OVERWORLD_SOILS | lookup.OVERWORLD_STONES | lookup.SNOWS smoothable_blocks = lookup.OVERWORLD_SOILS | lookup.OVERWORLD_STONES | lookup.SNOWS
for x in range(0, distance[0]): for (x, z) in [(x, z) for x in range(distance[0]) for z in range(distance[1])] :
for z in range(0, distance[1]):
if mask.getpixel((x, z)) != 0: if mask.getpixel((x, z)) == 0:
continue
y = heightmap.getpixel((x, z)) y = heightmap.getpixel((x, z))
y_smooth = heightmap_smooth.getpixel((x, z)) y_smooth = heightmap_smooth.getpixel((x, z))
delta = y - y_smooth delta = y - y_smooth
smooth_terrain_delta.putpixel((x, z), delta) smooth_terrain_delta.putpixel((x, z), delta)
if delta != 0: if delta == 0:
continue
block = slice.getBlock((x, y, z)) block = slice.getBlock((x, y, z))
if block.id in smoothable_blocks:
if block.id not in smoothable_blocks:
continue
if delta > 0: if delta > 0:
geometry.placeLine( geometry.placeLine(editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), Block('air'))
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)
editor.placeBlock(
(start[0] + x, y_smooth, start[1] + z), block)
else: else:
geometry.placeLine( geometry.placeLine(editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), block)
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') smooth_terrain_delta.save('./world_maker/data/smooth_terrain_delta.png')
print("[Smooth terrain] Done.") print("[Smooth terrain] Done.")