start windows

This commit is contained in:
KAymeric
2024-05-15 23:17:55 +02:00
parent 235d9be35d
commit e6d66cc18e
14 changed files with 195 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
import random as rd
from Enums import COLLUMN_STYLE
from utils.Enums import COLLUMN_STYLE
from buildings.Foundations import Foundations
from buildings.Facade import Facade

View File

@@ -1,23 +1,46 @@
from Enums import COLLUMN_STYLE
import random as rd
from utils.Enums import COLLUMN_STYLE, DIRECTION
from gdpc import Editor
from buildings.geometry.Vertice import Vertice
from buildings.geometry.Rectangle import Rectangle
from buildings.elements.Window import Window
class Facade:
def __init__(self, vertices : list[Vertice], height : int, is_inner_or_outer : COLLUMN_STYLE):
def __init__(self, rdata, vertices : list[Vertice], height : int, lenght : int, is_inner_or_outer : COLLUMN_STYLE):
self.rdata = rdata
self.vertices = vertices
self.is_inner_or_outer = is_inner_or_outer
self.height = height
self.lenght = lenght
self.window_size = self.get_window_size()
self.window = self.get_window()
self.has_balcony = self.has_balcony()
self.has_inter_floor = self.has_inter_floor()
def build_facade(self):
pass
def build(self, editor : Editor, materials : list[str], y : int):
padding = 0
if self.is_inner_or_outer == COLLUMN_STYLE.OUTER or self.is_inner_or_outer == COLLUMN_STYLE.BOTH:
padding = 1
for vertice in self.vertices:
xpadding, zpadding = 0, 0
if vertice.facing == DIRECTION.NORTH or vertice.facing == DIRECTION.SOUTH:
xpadding = padding
else: zpadding = padding
vertice.fill(editor, materials[0], y, y + self.height, xpadding = xpadding, zpadding = zpadding)
self.window.build(editor, vertice, self.height, y, materials)
def get_window_size(self) -> tuple[int,int]:
pass
max_width = self.lenght
max_height = min(self.height, self.rdata["windows"]["size"]["max_height"])
if self.is_inner_or_outer == COLLUMN_STYLE.OUTER or self.is_inner_or_outer == COLLUMN_STYLE.BOTH:
max_width -= 2
return (
rd.randint(self.rdata["windows"]["size"]["min_width"],max_width),
rd.randint(self.rdata["windows"]["size"]["min_height"],max_height)
)
def has_balcony(self) -> bool:
pass
@@ -26,4 +49,4 @@ class Facade:
pass
def get_window(self) -> Window:
pass
return Window(self.rdata["windows"] ,self.window_size)

View File

@@ -1,7 +1,7 @@
import random as rd
import numpy as np
import math
from Enums import COLLUMN_STYLE
from utils.Enums import COLLUMN_STYLE
from buildings.geometry.Tile import Tile
from buildings.geometry.Polygon import Polygon
from buildings.geometry.Point import Point
@@ -54,9 +54,9 @@ class Foundations:
# this bullshit is to create tiles from the matrice and the distribution
x_padding = self.position.x
for x,xsize in enumerate(self.x_distribution):
for x,xsize in utils.Enumerate(self.x_distribution):
z_padding = self.position.z
for z,zsize in enumerate(self.z_distribution):
for z,zsize in utils.Enumerate(self.z_distribution):
if self.matrice[x][z] == 1:
for xi in range(xsize):
for zi in range(zsize):
@@ -131,14 +131,13 @@ class Foundations:
return self._suppr_doubblons_collumns(collumns)
def _suppr_doubblons_collumns(self, collumns : list[Collumn]):
for index,collumn in enumerate(collumns):
for index,collumn in utils.Enumerate(collumns):
if index == len(collumns)-1: break
for compare in collumns[index+1:]:
if collumn.point1.position == compare.point1.position :
if compare.is_outer : collumn.set_is_outer(True)
collumns.remove(compare)
print(len(collumns))
return collumns

View File

@@ -1,7 +1,63 @@
import random as rd
import math
from gdpc import Editor, Block, geometry
from utils.Enums import DIRECTION
from buildings.geometry.Vertice import Vertice
class Window:
def __init__(self, size : tuple[int,int]):
self.size = size
def __init__(self, rdata, size : tuple[int,int]):
self.rdata = rdata
self.width, self.height = size
self.is_grounded = self.is_grounded()
self.has_multiple_windows = self.has_multiple_windows()
self.padding = 0
def build(self, editor : Editor, vertice : Vertice, height : int, y : int, materials : list[str]):
self.padding = (vertice.get_size() - self.width)//2
if not self.is_grounded: y += (height - self.height)//2
if self.has_multiple_windows: self.build_multiple_windows(editor, vertice, self.padding, self.height, y, materials)
else : vertice.fill(editor, materials[1], y, y + self.height, xpadding = self.padding, zpadding = self.padding)
def build_multiple_windows(self, editor : Editor, vertice : Vertice, padding : int, height : int, y : int, materials : list[str]):
slices = rd.randint(2, self.width//self.rdata["size"]["min_width"])
windows_count = math.ceil(slices/2)
inter_count = slices - windows_count
window_size = rd.randint(self.rdata["size"]["min_width"], self.width-inter_count // windows_count)
inter_size = (self.width - window_size*windows_count) // inter_count
revert, switching = slices % 2 == 0, math.ceil(slices/2)
is_revert, gap = False, 0
for i in range(1,slices+1):
modulo = i % 2
if revert and i == switching: is_revert = True
# kepp a spacing between windows, "is revert" is used to keep symetry
if modulo == 0 or (modulo == 1 and is_revert):
#set the values to orient windows in x or z axis
xpadding,xlen,zpadding,zlen = 0,0,0,0
if vertice.facing == DIRECTION.NORTH or vertice.facing == DIRECTION.SOUTH:
xpadding,xlen = self.padding + gap, window_size
else: zpadding,zlen = self.padding + gap, window_size
geometry.placeCuboid(editor,
(vertice.point1.x+xpadding, y, vertice.point1.z+zpadding),
(vertice.point1.x+xpadding+xlen, y+self.height, vertice.point1.z+zpadding+zlen),
Block(materials[1]))
gap += window_size
else :
gap += inter_size
def is_grounded(self):
# if the window is grounded or if there is a padding between the window and the ground
if self.rdata["grounded"] >= rd.random(): return True
return False
def has_multiple_windows(self):
if self.width > self.rdata["size"]["max_width"]: return True
if self.width >= self.rdata["multiple"]["min_width"]:
if self.rdata["multiple"]["proba"] >= rd.random(): return True
return False
def open(self):
pass

View File

@@ -1,4 +1,4 @@
from Enums import DIRECTION
from utils.Enums import DIRECTION
from gdpc import Editor, Block, geometry
from buildings.geometry.Tile import Tile
from buildings.geometry.Point import Point
@@ -70,7 +70,7 @@ class Polygon:
def set_vertices_and_neighbors(self, tiles : list[Tile], vertices : list[Vertice]):
for tile in tiles:
targets = tile.get_neighbors_coords()
for vertice_num,target in enumerate(targets):
for vertice_num,target in utils.Enumerate(targets):
has_neighbor = self._has_neighbor(target, tiles)
if not has_neighbor:
vertice = tile.get_vertice(vertice_num)

View File

@@ -9,6 +9,9 @@ class Rectangle:
def get_position(self):
return (self.point1.position, self.point2.position)
def fill(self,editor : Editor, material : str, y : int, y2 : int = None):
def fill(self,editor : Editor, material : str, y : int, y2 : int = None, xpadding : int = 0, zpadding : int = 0):
if self.point2.x - self.point1.x < 2*xpadding: xpadding = 0
if self.point2.z - self.point1.z < 2*zpadding: zpadding = 0
if y2 == None: y2 = y
geometry.placeCuboid(editor, (self.point1.x, y, self.point1.z), (self.point2.x, y2, self.point2.z), Block(material))
geometry.placeCuboid(editor, (self.point1.x+xpadding, y, self.point1.z+zpadding), (self.point2.x-xpadding, y2, self.point2.z-zpadding), Block(material))

View File

@@ -1,5 +1,5 @@
from gdpc import Editor, Block, geometry
from Enums import DIRECTION
from utils.Enums import DIRECTION
from buildings.geometry.Point import Point
from buildings.geometry.Vertice import Vertice

View File

@@ -1,9 +1,9 @@
from Enums import DIRECTION
from utils.Enums import DIRECTION
from buildings.geometry.Point import Point
from buildings.geometry.Rectangle import Rectangle
class Vertice(Rectangle):
def __init__(self, point1 : Point, point2 : Point, facing : str):
def __init__(self, point1 : Point, point2 : Point, facing : DIRECTION):
Rectangle.__init__(self, point1, point2)
self.facing = facing