4 Commits

Author SHA1 Message Date
WhyteTiger
3b382f8650 refactoring : createHouseSkeleton, remove another double for loop 2024-09-28 13:24:58 +02:00
WhyteTiger
e9449901a7 refactor : createHouseSkeleton 2024-09-28 13:07:24 +02:00
WhyteTiger
86166905c8 refactoring : createHouseSkeleton, remove double for loop for floor 2024-09-28 12:08:40 +02:00
WhyteTiger
22c2c1bae9 refactoring : createHouseSkeleton, x_max z_max 2024-09-28 11:16:50 +02:00
14 changed files with 2084 additions and 129 deletions

View File

@@ -1,24 +0,0 @@
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

126
House.py
View File

@@ -2,9 +2,10 @@ 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
from pyxtension.streams import stream
class House: class House:
def __init__(self, editor, coordinates_min, coordinates_max, direction, list_block): def __init__(self, editor, coordinates_min, coordinates_max, direction, list_block):
@@ -27,18 +28,18 @@ class House:
self.entranceCo = None self.entranceCo = None
self.wall = Block(list_block["wall"]) self.wall = Block(list_block["wall"])
self.roof = Block(list_block["roof"]) self.roof = Block(list_block["roof"])
self.roof_slab = Block(list_block["roof_slab"]) self.roof_slab = Block(list_block["roof_slab"])
self.door = Block(list_block["door"]) self.door = Block(list_block["door"])
self.window = Block(list_block["window"]) self.window = Block(list_block["window"])
self.entrance = Block(list_block["entrance"]) self.entrance = Block(list_block["entrance"])
self.stairs = Block(list_block["stairs"]) self.stairs = Block(list_block["stairs"])
self.celling = Block(list_block["celling"]) self.celling = Block(list_block["celling"])
self.floor = Block(list_block["floor"]) self.floor = Block(list_block["floor"])
self.celling_slab = Block(list_block["celling_slab"]) self.celling_slab = Block(list_block["celling_slab"])
self.gardenOutline = Block(list_block["garden_outline"]) self.gardenOutline = Block(list_block["garden_outline"])
self.garden_floor = Block(list_block["garden_floor"]) self.garden_floor = Block(list_block["garden_floor"])
def createHouseSkeleton(self): def createHouseSkeleton(self):
self.delete() self.delete()
@@ -50,37 +51,38 @@ class House:
x_min += 1 x_min += 1
z_min += 1 z_min += 1
x_max -= 1 x_max -= 2
z_max -= 1 z_max -= 2
if x_min + 1 > x_max - 1: if x_min + 1 > x_max :
x = np.random.randint(x_max - 1, x_min + 1) x = np.random.randint(x_max, x_min + 1)
else: else:
x = np.random.randint(x_min + 1, x_max - 1) x = np.random.randint(x_min + 1, x_max)
if z_min + 1 > z_max - 1: if z_min + 1 > z_max:
z = np.random.randint(z_max - 1, z_min + 1) z = np.random.randint(z_max, z_min + 1)
else: else:
z = np.random.randint(z_min + 1, z_max - 1) z = np.random.randint(z_min + 1, z_max)
width = perimeter_width // 2 width = perimeter_width // 2
depth = perimeter_depth // 2 depth = perimeter_depth // 2
height = y_max - y_min height = y_max - y_min
if x + width - 1 > x_max - 1: if x + width - 1 > x_max:
x = x_max - width - 1 x = x_max - width
if z + depth - 1 > z_max - 1: if z + depth - 1 > z_max:
z = z_max - depth - 1 z = z_max - depth
x_plan3d = x - x_min x_plan3d = x - x_min
z_plan3d = z - z_min z_plan3d = z - z_min
for i in range(0, width - 1): geometry.placeCuboid(self.editor, (x, y_min, z), (x + width - 1, y_min, z + depth - 1), self.floor)
for j in range(0, depth - 1): x_range = slice(x_plan3d, x_plan3d + width - 1)
self.editor.placeBlock((x + i, y_min, z + j), self.floor) z_range = slice(z_plan3d, z_plan3d + depth - 1)
self.grid3d[x_plan3d + i, 0, z_plan3d + j] = True, 1 self.grid3d[x_range, 0, z_range] = True, 1
self.skeleton.append((x, z, width - 1, depth - 1, height)) self.skeleton.append((x, z, width - 1, depth - 1, height))
print("Coordinates of the corners: ", (x, z), (x, z + depth - 1), (x + width - 1, z), print("Coordinates of the corners: ", (x, z), (x, z + depth - 1),
(x + width - 1, z + depth - 1)) (x + width - 1, z), (x + width - 1, z + depth - 1))
x_min -= 1 x_min -= 1
x_max -= 1 x_max -= 1
@@ -105,54 +107,47 @@ class House:
else: else:
new_width = np.random.randint(width - 2, 5) new_width = np.random.randint(width - 2, 5)
if max(x_min+1, x-new_width) > min(x_max-new_width-1, x+width): if max(x_min+1, x-new_width) > min(x_max-new_width, x+width):
new_x = np.random.randint( new_x = np.random.randint(min(x_max - new_width, x + width),
min(x_max - new_width - 1, x + width), max(x_min + 1, x - new_width)) max(x_min + 1, x - new_width))
else: else:
new_x = np.random.randint( new_x = np.random.randint(max(x_min + 1, x - new_width),
max(x_min + 1, x - new_width), min(x_max - new_width - 1, x + width)) min(x_max - new_width, x + width))
if max(z_min+1, z-new_depth) > min(z_max-new_depth-1, z+depth): if max(z_min+1, z-new_depth) > min(z_max-new_depth, z+depth):
new_z = np.random.randint( new_z = np.random.randint(min(z_max - new_depth, z + depth),
min(z_max - new_depth - 1, z + depth), max(z_min + 1, z - new_depth)) max(z_min + 1, z - new_depth))
else: else:
new_z = np.random.randint( new_z = np.random.randint(max(z_min + 1, z - new_depth),
max(z_min + 1, z - new_depth), min(z_max - new_depth - 1, z + depth)) min(z_max - new_depth, z + depth))
new_x_plan3d = new_x - x_min - 1 new_x_plan3d = new_x - x_min - 1
new_z_plan3d = new_z - z_min + 1 new_z_plan3d = new_z - z_min + 1
adjacent_blocks = 0 adjacent_blocks = 0
for i in range(new_x_plan3d, new_x_plan3d + new_width): for i in range(new_x_plan3d, new_x_plan3d + new_width) :
for j in range(new_z_plan3d, new_z_plan3d + new_depth): for j in range(new_z_plan3d, new_z_plan3d + new_depth) :
if self.grid3d[i - 1, 0, j]['bool'] and self.grid3d[i - 1, 0, j]['int'] == 1 or \ if self.grid3d[ i - 1, 0, j ]['bool'] and self.grid3d[i - 1, 0, j ]['int'] == 1 or \
self.grid3d[i + 1, 0, j]['bool'] and self.grid3d[i + 1, 0, j]['int'] == 1 or \ self.grid3d[i + 1, 0, j ]['bool'] and self.grid3d[i + 1, 0, j ]['int'] == 1 or \
self.grid3d[i, 0, j - 1]['bool'] and self.grid3d[i, 0, j - 1]['int'] == 1 or \ self.grid3d[i, 0, j - 1]['bool'] and self.grid3d[i, 0, j - 1]['int'] == 1 or \
self.grid3d[i, 0, j + 1]['bool'] and self.grid3d[i, 0, j + 1]['int'] == 1: self.grid3d[i, 0, j + 1]['bool'] and self.grid3d[i, 0, j + 1]['int'] == 1:
adjacent_blocks += 1 adjacent_blocks += 1
if adjacent_blocks < 3: new_x_range = slice(new_x_plan3d, new_x_plan3d + new_width)
new_z_range = slice(new_z_plan3d, new_z_plan3d + new_depth)
if adjacent_blocks < 3 or np.any(self.grid3d[new_x_range, 0, new_z_range]['bool']) :
continue continue
if not np.any( geometry.placeCuboid(self.editor, (new_x, y_min, new_z), (new_x+new_width-1, y_min, new_z+new_depth-1), self.floor)
self.grid3d[new_x_plan3d:new_x_plan3d + new_width, 0, new_z_plan3d:new_z_plan3d + new_depth][ new_x_plan3d += 1
'bool']): new_z_plan3d -= 1
new_x_plan3d = new_x - x_min new_x_range = slice(new_x_plan3d, new_x_plan3d + new_width)
new_z_plan3d = new_z - z_min new_z_range = slice(new_z_plan3d, new_z_plan3d + new_depth)
for i in range(0, new_width): self.grid3d[new_x_range, 0, new_z_range] = True, 2
for j in range(0, new_depth):
self.grid3d[new_x_plan3d + i, 0,
new_z_plan3d + j] = True, 2
if i == 0 or i == new_width - 1 or j == 0 or j == new_depth - 1: self.skeleton.append((new_x, new_z, new_width, new_depth, height))
continue break
else:
self.editor.placeBlock(
(new_x + i, y_min, new_z + j), self.floor)
self.skeleton.append(
(new_x, new_z, new_width, new_depth, height))
break
else: else:
print("Failed to place rectangle after 100000 attempts.") print("Failed to place rectangle after 100000 attempts.")
@@ -1250,8 +1245,9 @@ class House:
self.placeStairs() self.placeStairs()
if __name__ == "__main__": if __name__ == "__main__":
editor = Editor(host=config.getHost(), buffering=True) editor = Editor(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)]

View File

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

View File

@@ -24,7 +24,6 @@ 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():
@@ -33,7 +32,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(host=config.getHost(), buffering=True) editor = Editor(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,

View File

@@ -1,12 +0,0 @@
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,7 +5,6 @@ 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
@@ -142,7 +141,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(host=config.getHost()) editor = Editor()
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,7 +7,6 @@ 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
@@ -507,7 +506,7 @@ def irlToMc(coordinates):
heightmap = Image.open('./world_maker/data/heightmap.png') heightmap = Image.open('./world_maker/data/heightmap.png')
editor = Editor(host=config.getHost()) editor = Editor()
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
@@ -550,7 +549,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(host=config.getHost()) editor = Editor()
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,11 +1,10 @@
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(host= config.getHost(), buffering=True, caching=True, multithreading=True) editor = Editor(buffering=True, caching=True, multithreading=True)
def setBlock(block, xyz): def setBlock(block, xyz):

View File

@@ -4,7 +4,6 @@ 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
@@ -16,7 +15,7 @@ class Road:
self.width = 10 # TODO self.width = 10 # TODO
def place_roads(self): def place_roads(self):
editor = Editor(host=config.getHost(), buffering=True) editor = Editor(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,7 +12,6 @@ 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
@@ -280,7 +279,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(host=config.getHost(), buffering=True) editor = Editor(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

@@ -196,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(config) # editor = Editor()
# buildArea = editor.getBuildArea() # buildArea = editor.getBuildArea()
# buildRect = buildArea.toRect() # buildRect = buildArea.toRect()

View File

@@ -2,7 +2,6 @@ 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",
@@ -27,7 +26,7 @@ waterBlocks = [
class World: class World:
def __init__(self): def __init__(self):
editor = Editor(host=config.getHost(), buffering=True) editor = Editor(buffering=True)
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
self.coordinates_min = [ self.coordinates_min = [
@@ -73,7 +72,7 @@ class World:
Use already created volume to get block data. Use already created volume to get block data.
""" """
editor = Editor(host=config.getHost(), buffering=True) editor = Editor(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]][
@@ -100,7 +99,7 @@ class World:
Scan the world with no optimization. Not tested on large areas. Scan the world with no optimization. Not tested on large areas.
""" """
editor = Editor(host=config.getHost(), buffering=True) editor = Editor(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):
@@ -113,7 +112,7 @@ class World:
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(host=config.getHost()) editor = Editor()
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
buildRect = buildArea.toRect() buildRect = buildArea.toRect()
@@ -180,7 +179,7 @@ class World:
def propagate(self, coordinates, scanned=[]): def propagate(self, coordinates, scanned=[]):
i = 0 i = 0
editor = Editor(host=config.getHost(), buffering=True) editor = Editor(buffering=True)
if self.isInVolume(coordinates): if self.isInVolume(coordinates):
Block = self.getBlockFromCoordinates(coordinates) Block = self.getBlockFromCoordinates(coordinates)
self.getNeighbors(Block) self.getNeighbors(Block)
@@ -213,7 +212,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(host=config.getHost()) editor = Editor()
buildArea = editor.getBuildArea() buildArea = editor.getBuildArea()
buildRect = buildArea.toRect() buildRect = buildArea.toRect()

View File

@@ -5,14 +5,13 @@ from gdpc import Editor, Block, geometry, lookup
from PIL import Image as img from PIL import Image as img
from PIL.Image import Image 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(host=config.getHost(), buffering=True) editor = Editor(buffering=True)
build_area = editor.getBuildArea() build_area = editor.getBuildArea()
build_rectangle = build_area.toRect() build_rectangle = build_area.toRect()
@@ -45,7 +44,7 @@ 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(host=config.getHost(), buffering=True) editor = Editor(buffering=True)
build_area = editor.getBuildArea() build_area = editor.getBuildArea()
build_rectangle = build_area.toRect() build_rectangle = build_area.toRect()