Compare commits
4 Commits
remove_tre
...
House_py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b382f8650 | ||
|
|
e9449901a7 | ||
|
|
86166905c8 | ||
|
|
22c2c1bae9 |
123
House.py
123
House.py
@@ -4,6 +4,8 @@ import numpy as np
|
|||||||
import math
|
import math
|
||||||
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):
|
||||||
@@ -26,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()
|
||||||
@@ -49,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
|
||||||
@@ -104,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.")
|
||||||
|
|
||||||
@@ -1249,6 +1245,7 @@ class House:
|
|||||||
self.placeStairs()
|
self.placeStairs()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
editor = Editor(buffering=True)
|
editor = Editor(buffering=True)
|
||||||
buildArea = editor.getBuildArea()
|
buildArea = editor.getBuildArea()
|
||||||
|
|||||||
Reference in New Issue
Block a user