Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b382f8650 | ||
|
|
e9449901a7 | ||
|
|
86166905c8 | ||
|
|
22c2c1bae9 |
123
House.py
123
House.py
@@ -4,6 +4,8 @@ import numpy as np
|
||||
import math
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from pyxtension.streams import stream
|
||||
|
||||
|
||||
class House:
|
||||
def __init__(self, editor, coordinates_min, coordinates_max, direction, list_block):
|
||||
@@ -26,18 +28,18 @@ class House:
|
||||
|
||||
self.entranceCo = None
|
||||
|
||||
self.wall = Block(list_block["wall"])
|
||||
self.roof = Block(list_block["roof"])
|
||||
self.roof_slab = Block(list_block["roof_slab"])
|
||||
self.door = Block(list_block["door"])
|
||||
self.window = Block(list_block["window"])
|
||||
self.entrance = Block(list_block["entrance"])
|
||||
self.stairs = Block(list_block["stairs"])
|
||||
self.celling = Block(list_block["celling"])
|
||||
self.floor = Block(list_block["floor"])
|
||||
self.celling_slab = Block(list_block["celling_slab"])
|
||||
self.wall = Block(list_block["wall"])
|
||||
self.roof = Block(list_block["roof"])
|
||||
self.roof_slab = Block(list_block["roof_slab"])
|
||||
self.door = Block(list_block["door"])
|
||||
self.window = Block(list_block["window"])
|
||||
self.entrance = Block(list_block["entrance"])
|
||||
self.stairs = Block(list_block["stairs"])
|
||||
self.celling = Block(list_block["celling"])
|
||||
self.floor = Block(list_block["floor"])
|
||||
self.celling_slab = Block(list_block["celling_slab"])
|
||||
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):
|
||||
self.delete()
|
||||
@@ -49,37 +51,38 @@ class House:
|
||||
|
||||
x_min += 1
|
||||
z_min += 1
|
||||
x_max -= 1
|
||||
z_max -= 1
|
||||
if x_min + 1 > x_max - 1:
|
||||
x = np.random.randint(x_max - 1, x_min + 1)
|
||||
x_max -= 2
|
||||
z_max -= 2
|
||||
if x_min + 1 > x_max :
|
||||
x = np.random.randint(x_max, x_min + 1)
|
||||
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:
|
||||
z = np.random.randint(z_max - 1, z_min + 1)
|
||||
if z_min + 1 > z_max:
|
||||
z = np.random.randint(z_max, z_min + 1)
|
||||
else:
|
||||
z = np.random.randint(z_min + 1, z_max - 1)
|
||||
z = np.random.randint(z_min + 1, z_max)
|
||||
|
||||
width = perimeter_width // 2
|
||||
depth = perimeter_depth // 2
|
||||
height = y_max - y_min
|
||||
|
||||
if x + width - 1 > x_max - 1:
|
||||
x = x_max - width - 1
|
||||
if z + depth - 1 > z_max - 1:
|
||||
z = z_max - depth - 1
|
||||
if x + width - 1 > x_max:
|
||||
x = x_max - width
|
||||
if z + depth - 1 > z_max:
|
||||
z = z_max - depth
|
||||
|
||||
x_plan3d = x - x_min
|
||||
z_plan3d = z - z_min
|
||||
|
||||
for i in range(0, width - 1):
|
||||
for j in range(0, depth - 1):
|
||||
self.editor.placeBlock((x + i, y_min, z + j), self.floor)
|
||||
self.grid3d[x_plan3d + i, 0, z_plan3d + j] = True, 1
|
||||
geometry.placeCuboid(self.editor, (x, y_min, z), (x + width - 1, y_min, z + depth - 1), self.floor)
|
||||
x_range = slice(x_plan3d, x_plan3d + width - 1)
|
||||
z_range = slice(z_plan3d, z_plan3d + depth - 1)
|
||||
self.grid3d[x_range, 0, z_range] = True, 1
|
||||
|
||||
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),
|
||||
(x + width - 1, z + depth - 1))
|
||||
print("Coordinates of the corners: ", (x, z), (x, z + depth - 1),
|
||||
(x + width - 1, z), (x + width - 1, z + depth - 1))
|
||||
|
||||
x_min -= 1
|
||||
x_max -= 1
|
||||
@@ -104,54 +107,47 @@ class House:
|
||||
else:
|
||||
new_width = np.random.randint(width - 2, 5)
|
||||
|
||||
if max(x_min+1, x-new_width) > min(x_max-new_width-1, x+width):
|
||||
new_x = np.random.randint(
|
||||
min(x_max - new_width - 1, x + width), max(x_min + 1, x - new_width))
|
||||
if max(x_min+1, x-new_width) > min(x_max-new_width, x+width):
|
||||
new_x = np.random.randint(min(x_max - new_width, x + width),
|
||||
max(x_min + 1, x - new_width))
|
||||
else:
|
||||
new_x = np.random.randint(
|
||||
max(x_min + 1, x - new_width), min(x_max - new_width - 1, x + width))
|
||||
new_x = np.random.randint(max(x_min + 1, x - new_width),
|
||||
min(x_max - new_width, x + width))
|
||||
|
||||
if max(z_min+1, z-new_depth) > min(z_max-new_depth-1, z+depth):
|
||||
new_z = np.random.randint(
|
||||
min(z_max - new_depth - 1, z + depth), max(z_min + 1, z - new_depth))
|
||||
if max(z_min+1, z-new_depth) > min(z_max-new_depth, z+depth):
|
||||
new_z = np.random.randint(min(z_max - new_depth, z + depth),
|
||||
max(z_min + 1, z - new_depth))
|
||||
else:
|
||||
new_z = np.random.randint(
|
||||
max(z_min + 1, z - new_depth), min(z_max - new_depth - 1, z + depth))
|
||||
new_z = np.random.randint(max(z_min + 1, z - new_depth),
|
||||
min(z_max - new_depth, z + depth))
|
||||
|
||||
new_x_plan3d = new_x - x_min - 1
|
||||
new_z_plan3d = new_z - z_min + 1
|
||||
|
||||
adjacent_blocks = 0
|
||||
for i in range(new_x_plan3d, new_x_plan3d + new_width):
|
||||
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 \
|
||||
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:
|
||||
for i in range(new_x_plan3d, new_x_plan3d + new_width) :
|
||||
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 \
|
||||
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:
|
||||
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
|
||||
|
||||
if not np.any(
|
||||
self.grid3d[new_x_plan3d:new_x_plan3d + new_width, 0, new_z_plan3d:new_z_plan3d + new_depth][
|
||||
'bool']):
|
||||
new_x_plan3d = new_x - x_min
|
||||
new_z_plan3d = new_z - z_min
|
||||
for i in range(0, new_width):
|
||||
for j in range(0, new_depth):
|
||||
self.grid3d[new_x_plan3d + i, 0,
|
||||
new_z_plan3d + j] = True, 2
|
||||
geometry.placeCuboid(self.editor, (new_x, y_min, new_z), (new_x+new_width-1, y_min, new_z+new_depth-1), self.floor)
|
||||
new_x_plan3d += 1
|
||||
new_z_plan3d -= 1
|
||||
new_x_range = slice(new_x_plan3d, new_x_plan3d + new_width)
|
||||
new_z_range = slice(new_z_plan3d, new_z_plan3d + new_depth)
|
||||
self.grid3d[new_x_range, 0, new_z_range] = True, 2
|
||||
|
||||
if i == 0 or i == new_width - 1 or j == 0 or j == new_depth - 1:
|
||||
continue
|
||||
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
|
||||
|
||||
self.skeleton.append(
|
||||
(new_x, new_z, new_width, new_depth, height))
|
||||
break
|
||||
else:
|
||||
print("Failed to place rectangle after 100000 attempts.")
|
||||
|
||||
@@ -1249,6 +1245,7 @@ class House:
|
||||
self.placeStairs()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
editor = Editor(buffering=True)
|
||||
buildArea = editor.getBuildArea()
|
||||
|
||||
Reference in New Issue
Block a user