corrections corners bugs, clean tree structure and start entrance

This commit is contained in:
AKreuzer
2024-06-11 03:06:06 +02:00
parent 536c71d372
commit de3950d376
21 changed files with 153 additions and 86 deletions

View File

@@ -1,30 +1,33 @@
import random as rd import random as rd
from utils.Enums import COLLUMN_STYLE
from buildings.Foundations import Foundations from buildings.Foundations import Foundations
from buildings.Facade import Facade from buildings.Facade import Facade
class Building: class Building:
def __init__(self, position : tuple[int,int], size : tuple[int, int], matrice : list[list[int]]): def __init__(self,rdata, position : tuple[int,int], size : tuple[int, int], matrice : list[list[int]], floors : int):
self.position = position self.position = position
self.length, self.width = size self.length, self.width = size
self.matrice = matrice self.matrice = matrice
self.floors = floors
# Generate every random components here # Generate every random components here
is_collumn_full_tile = bool(rd.getrandbits(1))
is_inner_or_outer = rd.choice(list(COLLUMN_STYLE))
tile_size = self.gen_tile_size() tile_size = self.gen_tile_size()
floor_height = rd.randint(4, 7)
is_inner_or_outer = COLLUMN_STYLE.BOTH self.foundations = Foundations(rdata["foundations"], size, matrice, tile_size,)
self.facade = Facade(rdata["facade"], self.foundations.vertices, self.foundations.is_inner_or_outer)
self.foundations = Foundations(size, matrice, tile_size, is_collumn_full_tile, is_inner_or_outer) def build(self, editor, materials : list[str]):
self.facade = Facade(self.foundations.vertices, floor_height, is_inner_or_outer) for y in range(self.floors):
with editor.pushTransform((self.position[0], y*(self.foundations.floor_height+1), self.position[1])):
self.foundations.build(editor, materials)
self.facade.build(editor, materials)
def gen_tile_size(self) -> int: def gen_tile_size(self) -> int:
# Tiles are constant square units different for each buildings # Tiles are constant square units different for each buildings
return self.length
smaller_side = min(self.length, self.width) smaller_side = min(self.length, self.width)
# area is too small, will work but not very well # area is too small, will work but not very well
if smaller_side <= 5 : return smaller_side
if smaller_side <= 15 : return smaller_side // 5 if smaller_side <= 15 : return smaller_side // 5
return rd.randint(3, smaller_side // len(self.matrice)) return rd.randint(3, smaller_side // len(self.matrice))

0
buildings/Entrance.py Normal file
View File

View File

@@ -1,36 +1,64 @@
import random as rd import random as rd
from utils.Enums import COLLUMN_STYLE from utils.functions import *
from utils.Enums import COLLUMN_STYLE,DIRECTION,INTER_FLOOR_BORDER
from gdpc import Editor, Block, geometry, Transform from gdpc import Editor, Block, geometry, Transform
from buildings.geometry.Vertice import Vertice from buildings.geometry.Vertice import Vertice
from buildings.geometry.Point import Point
from buildings.elements.Window import Window from buildings.elements.Window import Window
from buildings.elements.Balcony import Balcony from buildings.elements.Balcony import Balcony
class Facade: class Facade:
def __init__(self, rdata, vertices : list[Vertice], is_inner_or_outer : COLLUMN_STYLE): def __init__(self, rdata, vertices : list[Vertice], collumn_style : COLLUMN_STYLE):
self.rdata = rdata self.rdata = rdata
self.vertices = vertices self.vertices = vertices
self.is_inner_or_outer = is_inner_or_outer self.collumn_style = collumn_style
self.height, self.length = self.get_dimentions() self.height, self.length = self.get_dimentions()
self.padding = 0 self.padding = 0
self.window = self.get_window() self.window = self.get_window()
self.has_balcony = self.has_balcony() self.has_balcony = self.has_balcony()
self.balcony = self.get_balcony() self.balcony = self.get_balcony()
self.has_inter_floor = self.has_inter_floor() self.has_inter_floor, self.inter_floor_border_style = self.has_inter_floor()
self.editor, self.materials = None,None self.editor, self.materials = None,None
def build(self, editor : Editor, materials : list[str]): def build(self, editor : Editor, materials : list[str]):
self.editor = editor self.editor = editor
self.materials = materials self.materials = materials
points = sum([[vertice.point1, vertice.point2] for vertice in self.vertices], [])
for vertice in self.vertices: for vertice in self.vertices:
flip=(vertice.facing == DIRECTION.WEST or vertice.facing == DIRECTION.SOUTH, False, False)
vertice.fill(editor, materials[0], self.height, xpadding = self.padding, zpadding = self.padding) vertice.fill(editor, materials[0], self.height, xpadding = self.padding, zpadding = self.padding)
with editor.pushTransform(Transform(vertice.point1.position,rotation = vertice.facing.value)): with editor.pushTransform(Transform(vertice.point1.position,rotation = vertice.facing.value, flip = flip)):
self.window.build(editor, materials) self.window.build(editor, materials)
self.build_inter_floor() if self.has_inter_floor: self.build_inter_floor()
if self.has_balcony: self.balcony.build(editor, materials) if self.has_balcony: self.balcony.build(editor, materials)
self.correct_corners(points,vertice)
def correct_corners(self,points : list[Point], v : Vertice):
if self.padding == 0:
if self.window.border_radius != 0 and self.window.width == self.length:
if v.point1 in points:
self.editor.placeBlock((0,self.window.ypadding,0), Block(self.materials[8]))
self.editor.placeBlock((0,self.window.ypadding+self.window.height,0), Block(self.materials[8], {"type": "top"}))
if v.point2 in points:
self.editor.placeBlock((self.length-1,self.window.ypadding,0), Block(self.materials[8]))
self.editor.placeBlock((self.length-1,self.window.ypadding+self.window.height,0), Block(self.materials[8], {"type": "top"}))
if self.has_inter_floor:
material = Block("air")
if self.inter_floor_border_style == INTER_FLOOR_BORDER.SLAB:
material = Block(self.materials[8], {"type": "top"})
elif self.inter_floor_border_style == INTER_FLOOR_BORDER.STAIRS:
material = Block(self.materials[4], {"facing": "south", "half": "top"})
if v.point1 in points:
self.editor.placeBlock((-1,self.height,-1), material)
if v.point2 in points:
self.editor.placeBlock((self.length,self.height,-1), material)
def get_window(self) -> Window: def get_window(self) -> Window:
if self.is_inner_or_outer == COLLUMN_STYLE.OUTER or self.is_inner_or_outer == COLLUMN_STYLE.BOTH: if self.collumn_style.value >= 2: # collumn_style >= 2 = outer collumns
self.padding = 1 self.padding = 1
max_width = self.length-2*self.padding max_width = self.length-2*self.padding
@@ -41,19 +69,17 @@ class Facade:
def get_balcony(self) -> Balcony|None: def get_balcony(self) -> Balcony|None:
if not self.has_balcony: return None if not self.has_balcony: return None
max_width = self.length-2*self.padding max_width = self.length-2*self.padding
return Balcony(self.rdata["balcony"], max_width, self.window) return Balcony(self.rdata["balcony"], max_width, self.window, self.collumn_style)
def build_inter_floor(self): def build_inter_floor(self):
if self.has_inter_floor: geometry.placeCuboid(self.editor,(self.padding,self.height,0),(self.length-1-self.padding,self.height,0),Block(self.materials[0]))
geometry.placeCuboid(self.editor,(0,self.height,0),(self.length-1,self.height,0),Block(self.materials[0])) geometry.placeCuboid(self.editor,(self.padding,self.height,-1),(self.length-1-self.padding,self.height,-1),Block(self.materials[4], {"facing": "south", "half": "top"}))
geometry.placeCuboid(self.editor,(0,self.height,-1),(self.length-1,self.height,-1),Block(self.materials[4], {"facing": "south", "half": "top"}))
def has_balcony(self) -> bool: def has_balcony(self) -> bool:
return True
return self.rdata["balcony"]["proba"] >= rd.random() return self.rdata["balcony"]["proba"] >= rd.random()
def has_inter_floor(self) -> bool: def has_inter_floor(self) -> bool:
return self.rdata["inter_floor"] >= rd.random() return (self.rdata["inter_floor"]["proba"] >= rd.random(), select_random(self.rdata["inter_floor"]["border_style"], INTER_FLOOR_BORDER))
def get_dimentions(self) -> tuple[int]: def get_dimentions(self) -> tuple[int]:
return ( self.vertices[0].get_height(), len(self.vertices[0])) return ( self.vertices[0].get_height(), len(self.vertices[0]))

View File

@@ -1,28 +1,28 @@
import random as rd import random as rd
import numpy as np import numpy as np
import math import math
from utils.Enums import COLLUMN_STYLE from utils.Enums import COLLUMN_STYLE
from utils.functions import *
from buildings.geometry.Tile import Tile from buildings.geometry.Tile import Tile
from buildings.geometry.Polygon import Polygon from buildings.geometry.Polygon import Polygon
from buildings.geometry.Point import Point from buildings.geometry.Point import Point
from buildings.geometry.Rectangle import Rectangle
from buildings.elements.Collumn import Collumn from buildings.elements.Collumn import Collumn
class Foundations: class Foundations:
# TODO : gérer les collones sur les tiles trop petites et les colones 1tile/2 + fulltile # TODO : gérer les collones sur les tiles trop petites et les colones 1tile/2
def __init__(self, def __init__(self,
rdata,
size : tuple[int, int], size : tuple[int, int],
matrice : list[list[int]], matrice : list[list[int]],
tile_size : int, tile_size : int):
is_collumn_full_tile : bool,
is_inner_or_outer : COLLUMN_STYLE):
# Foundations are the base of the building, they are made of tiles and based on a matrice # Foundations are the base of the building, they are made of tiles and based on a matrice
# Random components # Random components
self.tile_size = tile_size self.tile_size = tile_size
self.is_collumn_full_tile = is_collumn_full_tile self.is_inner_or_outer = select_random(rdata["collumn_style"], COLLUMN_STYLE)
self.is_inner_or_outer = is_inner_or_outer self.floor_height = rd.randint(rdata["floor"]["min_height"], rdata["floor"]["max_height"])-1
self.size = size self.size = size
self.length, self.width = size self.length, self.width = size
@@ -35,6 +35,17 @@ class Foundations:
self.z_distribution = [] self.z_distribution = []
self.polygon = self.get_polygon() self.polygon = self.get_polygon()
self.collumns = self.get_columns() self.collumns = self.get_columns()
def build(self, editor, materials : list[str]):
self.polygon.fill(editor, materials[5],0)
self.polygon.fill(editor, materials[6], self.floor_height)
self.build_collumns(editor, materials)
def build_collumns(self, editor, materials : list[str]):
for collumn in self.collumns:
if collumn.is_outer and self.is_inner_or_outer == COLLUMN_STYLE.INNER: continue
if not collumn.is_outer and self.is_inner_or_outer == COLLUMN_STYLE.OUTER: continue
collumn.fill(editor, materials[7], self.floor_height)
def add_tile(self, tile : Tile): def add_tile(self, tile : Tile):
self.tiles.append(tile) self.tiles.append(tile)
@@ -42,11 +53,10 @@ class Foundations:
def get_polygon(self) -> Polygon: def get_polygon(self) -> Polygon:
## The polygon is a shape of tiles representing the foundation shape ## The polygon is a shape of tiles representing the foundation shape
polygon = Polygon(self.size) polygon = Polygon(self.size)
avaliable_space = (self.length_in_tiles, self.width_in_tiles)
# we save the distribution, usefull for the next steps # we save the distribution, usefull for the next steps
self.x_distribution = self.get_distribution(len(self.matrice), avaliable_space[0]) self.x_distribution = self.get_distribution(len(self.matrice), self.length_in_tiles)
self.z_distribution = self.get_distribution(len(self.matrice[0]), avaliable_space[1]) self.z_distribution = self.get_distribution(len(self.matrice[0]), self.width_in_tiles)
# this bullshit is to create tiles from the matrice and the distribution # this bullshit is to create tiles from the matrice and the distribution
x_padding = 0 x_padding = 0
@@ -61,7 +71,7 @@ class Foundations:
z_padding += zsize * self.tile_size z_padding += zsize * self.tile_size
x_padding += xsize * self.tile_size x_padding += xsize * self.tile_size
polygon.set_vertices_and_neighbors(self.tiles, self.vertices) polygon.set_vertices_and_neighbors(self.tiles, self.vertices, self.floor_height)
polygon.compress(self.tiles, self.vertices) polygon.compress(self.tiles, self.vertices)
return polygon return polygon
@@ -106,6 +116,7 @@ class Foundations:
return sizes return sizes
def get_columns(self) -> list[Collumn]: def get_columns(self) -> list[Collumn]:
if self.is_inner_or_outer == COLLUMN_STYLE.NONE: return []
collumns = [] collumns = []
for tile in self.tiles: for tile in self.tiles:

View File

@@ -2,10 +2,12 @@ Encadrement fenêtre
toit de balcon avec/sans pilliers toit de balcon avec/sans pilliers
border radius balcon border radius balcon
collumn style collumn style
rembard object
détails facade détails facade
rdc rdc
toit toit
tiles 3d tiles 3d
opti géométrique textures object
opti textures opti textures
opti géométrique
opti gdpc opti gdpc

View File

@@ -1,16 +1,17 @@
import random as rd import random as rd
from gdpc import Editor, Block, geometry from gdpc import Editor, Block, geometry
from utils.functions import * from utils.functions import *
from utils.Enums import BALCONY_BORDER_RADIUS from utils.Enums import BALCONY_BORDER_RADIUS,COLLUMN_STYLE
from buildings.geometry.Point import Point from buildings.geometry.Point import Point
from buildings.geometry.Vertice import Vertice from buildings.geometry.Vertice import Vertice
from buildings.elements.Window import Window from buildings.elements.Window import Window
class Balcony: class Balcony:
def __init__(self, rdata, max_width : int, windows : Window): def __init__(self, rdata, max_width : int, windows : Window, collumn_style : COLLUMN_STYLE):
self.rdata = rdata self.rdata = rdata
self.windows = windows self.windows = windows
self.max_width = max_width self.max_width = max_width
self.collumn_style = collumn_style
self.length = self.get_len() self.length = self.get_len()
self.has_multiple = self.has_multiple() self.has_multiple = self.has_multiple()
self.has_details = self.has_details() self.has_details = self.has_details()
@@ -94,7 +95,8 @@ class Balcony:
def get_attach_points(self) -> list[int]: def get_attach_points(self) -> list[int]:
# points where the structures can start/finish # points where the structures can start/finish
points = [i for i in range(self.max_width)] padding = 0 if self.collumn_style.value < 2 else 1 # collumn_style < 2 = no outer collumns
points = [i + padding for i in range(self.max_width)]
if self.follow_window: if self.follow_window:
pad = self.windows.padding pad = self.windows.padding
for w in self.windows.windows: for w in self.windows.windows:
@@ -104,7 +106,7 @@ class Balcony:
return points return points
def create_structure(self, x1 : int, x2 : int) -> Vertice: def create_structure(self, x1 : int, x2 : int) -> Vertice:
return Vertice(Point(x1,0,0), Point(x2,0,-self.length)) return Vertice(Point(x = x1), Point(x = x2,z = -self.length))
def append_structure(self, structures : list[Vertice], x1 : int, x2 : int, attach_points : list[int], len_attach_points : int, centered : bool): def append_structure(self, structures : list[Vertice], x1 : int, x2 : int, attach_points : list[int], len_attach_points : int, centered : bool):
structures.append(self.create_structure(attach_points[x1], attach_points[x2])) structures.append(self.create_structure(attach_points[x1], attach_points[x2]))

View File

@@ -8,4 +8,7 @@ class Collumn(Rectangle):
def set_is_outer(self, is_outer : bool): def set_is_outer(self, is_outer : bool):
self.is_outer = is_outer self.is_outer = is_outer
def __repr__(self):
return super().__repr__() + f"\nIs outer : {self.is_outer}\n\n"

View File

@@ -0,0 +1,3 @@
class Buttons:
def __init__(self):
pass

View File

@@ -5,7 +5,7 @@ from utils.Enums import WINDOW_BORDER_RADIUS
from utils.functions import * from utils.functions import *
from buildings.geometry.Point import Point from buildings.geometry.Point import Point
from buildings.geometry.Vertice import Vertice from buildings.geometry.Vertice import Vertice
from buildings.elements.Glass import Glass from buildings.elements.WindowElt.Glass import Glass
class Window: class Window:
def __init__(self, rdata, max_width : int, max_height : int, facade_len : int, facade_height : int): def __init__(self, rdata, max_width : int, max_height : int, facade_len : int, facade_height : int):
@@ -31,7 +31,7 @@ class Window:
if leng > 1: self.build_border_radius(g.x1, g.x2) if leng > 1: self.build_border_radius(g.x1, g.x2)
def build_crossbars(self, x1 : int, x2 : int, len : int): def build_crossbars(self, x1 : int, x2 : int, len : int):
if self.has_vertical_crossbar and self.height >= self.rdata["crossbars"]["min_height_for_vertical_crossbar"]: if self.has_vertical_crossbar and self.height+1 >= self.rdata["crossbars"]["min_height_for_vertical_crossbar"]:
y = self.height//2 y = self.height//2
geometry.placeCuboid(self.editor,(x1,y,0),(x2,y,0),Block(self.materials[3])) geometry.placeCuboid(self.editor,(x1,y,0),(x2,y,0),Block(self.materials[3]))
if self.has_horizontal_crossbar and len >= self.rdata["crossbars"]["min_width_for_horizontal_crossbar"]: if self.has_horizontal_crossbar and len >= self.rdata["crossbars"]["min_width_for_horizontal_crossbar"]:
@@ -46,7 +46,6 @@ class Window:
self.editor.placeBlock((x1,0,0),Block(self.materials[4], {"facing": "west"})) self.editor.placeBlock((x1,0,0),Block(self.materials[4], {"facing": "west"}))
self.editor.placeBlock((x2,0,0),Block(self.materials[4], {"facing": "east"})) self.editor.placeBlock((x2,0,0),Block(self.materials[4], {"facing": "east"}))
def get_windows(self) -> list[Glass]: def get_windows(self) -> list[Glass]:
windows = [] windows = []
if not self.has_multiple: windows = [Glass(0,self.width-1,[self.create_window(0, self.width)])] if not self.has_multiple: windows = [Glass(0,self.width-1,[self.create_window(0, self.width)])]
@@ -103,7 +102,7 @@ class Window:
def create_window(self, x1 : int, length : int = None) -> Vertice: def create_window(self, x1 : int, length : int = None) -> Vertice:
x2 = x1 if length is None else x1 + length -1 x2 = x1 if length is None else x1 + length -1
return Vertice(Point(x1,0,0), Point(x2,self.height,0)) return Vertice(Point(x = x1), Point(x2,self.height))
def has_multiple_windows(self): def has_multiple_windows(self):
if self.width > self.rdata["size"]["max_width"]: return True if self.width > self.rdata["size"]["max_width"]: return True

View File

@@ -1,14 +1,17 @@
class Point: class Point:
def __init__(self, x : int = None, y : int = None, z : int = None, p : tuple[int] = None): def __init__(self, x : int = 0, y : int = 0, z : int = 0, p : tuple[int] = None):
if p != None: x,y,z = p if p != None: x,y,z = p
self.x = x self.x = x
self.y = y self.y = y
self.z = z self.z = z
self.position = (x,y,z) self.position = (x,y,z)
def set_position(self, x : int = None, y : int = None, z : int = None, p : tuple[int] = None): def set_position(self, x : int = 0, y : int = 0, z : int = 0, p : tuple[int] = None):
if p != None: x,y,z = p if p != None: x,y,z = p
self.x = x if x != None else self.x self.x = x if x != None else self.x
self.y = y if y != None else self.y self.y = y if y != None else self.y
self.z = z if z != None else self.z self.z = z if z != None else self.z
self.position = (self.x,self.y,self.z) self.position = (self.x,self.y,self.z)
def __repr__(self):
return f"Point({self.position})"

View File

@@ -1,5 +1,5 @@
from utils.Enums import DIRECTION from utils.Enums import DIRECTION
from gdpc import Editor, Block, geometry from gdpc import Editor, Block, geometry, Transform
from buildings.geometry.Tile import Tile from buildings.geometry.Tile import Tile
from buildings.geometry.Point import Point from buildings.geometry.Point import Point
from buildings.geometry.Rectangle import Rectangle from buildings.geometry.Rectangle import Rectangle
@@ -11,10 +11,11 @@ class Polygon:
self.shape = [] self.shape = []
self.vertices = [] self.vertices = []
def fill_polygon(self, editor : Editor, material : str, y : int, y2 : int = None): def fill(self, editor : Editor, material : str, y : int = 0, y2 : int = None):
if y2 == None: y2 = y if y2 == None: y2 = 0
for rect in self.shape: for rect in self.shape:
rect.fill(editor, material, y, y2) with editor.pushTransform(Transform((0,y,0))):
rect.fill(editor, material, y2)
def fill_vertice(self, editor : Editor, material : str, y : int, y2 : int = None): def fill_vertice(self, editor : Editor, material : str, y : int, y2 : int = None):
if y2 == None: y2 = y if y2 == None: y2 = y
@@ -66,7 +67,7 @@ class Polygon:
if len(remaining_vertices) == 0: self.vertices.append(current) if len(remaining_vertices) == 0: self.vertices.append(current)
def set_vertices_and_neighbors(self, tiles : list[Tile], vertices : list[Vertice]): def set_vertices_and_neighbors(self, tiles : list[Tile], vertices : list[Vertice], height : int):
for tile in tiles: for tile in tiles:
targets = tile.get_neighbors_coords() targets = tile.get_neighbors_coords()
for vertice_num,target in enumerate(targets): for vertice_num,target in enumerate(targets):
@@ -74,7 +75,7 @@ class Polygon:
if not has_neighbor: if not has_neighbor:
vertice = tile.get_vertice(vertice_num) vertice = tile.get_vertice(vertice_num)
vertices.append(vertice) vertices.append(vertice)
tile.set_vertice(DIRECTION(vertice_num), vertice) tile.set_vertice(DIRECTION(vertice_num), vertice, height)
else : else :
tile.set_neighbor(vertice_num, has_neighbor) tile.set_neighbor(vertice_num, has_neighbor)

View File

@@ -10,7 +10,7 @@ class Rectangle:
return (self.point1.position, self.point2.position) return (self.point1.position, self.point2.position)
def get_height(self): def get_height(self):
return self.point2.y - self.point1.y + 1 return self.point2.y - self.point1.y
def fill(self,editor : Editor, material : str, y : int = None, xpadding : int = 0, zpadding : int = 0): def fill(self,editor : Editor, material : str, y : int = None, xpadding : int = 0, zpadding : int = 0):
if self.point2.x - self.point1.x < 2*xpadding: xpadding = 0 if self.point2.x - self.point1.x < 2*xpadding: xpadding = 0
@@ -18,3 +18,6 @@ class Rectangle:
if y is None: y = self.point2.y if y is None: y = self.point2.y
geometry.placeCuboid(editor, (self.point1.x+xpadding, 0, self.point1.z+zpadding), (self.point2.x-xpadding, y, self.point2.z-zpadding), Block(material)) geometry.placeCuboid(editor, (self.point1.x+xpadding, 0, self.point1.z+zpadding), (self.point2.x-xpadding, y, self.point2.z-zpadding), Block(material))
def __repr__(self):
return f"{type(self).__name__}\n1 : {str(self.point1)},\n2 : {str(self.point2)}"

View File

@@ -32,9 +32,9 @@ class Tile:
def get_neighbors_coords(self): def get_neighbors_coords(self):
return [Point(x = self.pos.x, z = self.pos.z - self.size), # north return [Point(x = self.pos.x, z = self.pos.z - self.size), # north
Point(x = self.pos.x - self.size, z = self.pos.z), # west Point(x = self.pos.x + self.size, z = self.pos.z), # east
Point(x = self.pos.x, z = self.pos.z + self.size), # south Point(x = self.pos.x, z = self.pos.z + self.size), # south
Point(x = self.pos.x + self.size, z = self.pos.z)] # east Point(x = self.pos.x - self.size, z = self.pos.z)] # west
def get_neighbor(self, direction) -> Point: def get_neighbor(self, direction) -> Point:
@@ -80,8 +80,9 @@ class Tile:
case DIRECTION.SOUTH : case DIRECTION.SOUTH :
return self.south_vertice return self.south_vertice
def set_vertice(self, direction : DIRECTION, vertice : Vertice): def set_vertice(self, direction : DIRECTION, vertice : Vertice, height : int):
self.has_vertice = True self.has_vertice = True
vertice.point2.y = height
match(direction): match(direction):
case DIRECTION.WEST : case DIRECTION.WEST :
self.west_vertice = vertice self.west_vertice = vertice

View File

@@ -18,4 +18,7 @@ class Vertice(Rectangle):
def __len__(self): def __len__(self):
return self.point2.x - self.point1.x + self.point2.z - self.point1.z + 1 return self.point2.x - self.point1.x + self.point2.z - self.point1.z + 1
def __repr__(self):
return super().__repr__() + f"\nFacing : {self.facing} \n\n"

38
main.py
View File

@@ -5,11 +5,6 @@ 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
from buildings.geometry.Vertice import Vertice
from buildings.geometry.Point import Point
from utils.Enums import DIRECTION,COLLUMN_STYLE,WINDOW_BORDER_RADIUS
from buildings.Facade import Facade
from utils.functions import * from utils.functions import *
editor = Editor(buffering=True) editor = Editor(buffering=True)
@@ -20,32 +15,23 @@ shapes = f.data
y = YamlReader('params.yml') y = YamlReader('params.yml')
random_data = y.data random_data = y.data
# transform = Transform((0,-60,-20),rotation = 0)
# editor.transform.push(transform)
# for i in range(4):
# with editor.pushTransform(Transform(rotation = i)):
# geometry.placeCuboid(editor, (0,0,0), (0,3,5), Block("stone"))
transform = Transform((0,-60,-5),rotation = 0) transform = Transform((0,-60,80),rotation = 0)
editor.transform.push(transform) editor.transform.push(transform)
geometry.placeCuboid(editor, (0,0,-3), (100,15,1), Block("air")) geometry.placeCuboid(editor, (-5,0,-8), (170,25,25), Block("air"))
x = 0 padd = 0
facade = [] for i in range(4,13):
for i in range(3,13): building = Building(random_data["buildings"], (padd, 0), (i,i), shapes[0]['matrice'], 3)
facade.append(Facade(random_data["buildings"]["facade"],[Vertice(Point(x,0,0), Point(x+i,i,0), DIRECTION.NORTH)],COLLUMN_STYLE.NONE)) building.build(editor, ["stone_bricks","glass_pane","glass","cobblestone_wall","stone_brick_stairs","oak_planks","white_concrete","cobblestone","stone_brick_slab"])
x += i+2 padd += i + 10
for f in facade:
f.build(editor, ["stone_bricks","glass_pane","glass","cobblestone_wall","stone_brick_stairs"])
# F = Foundations((0,0), (20,20), shapes[0]['matrice'])
# F.polygon.fill_polygon(editor, "stone", -60)
# geometry.placeCuboid(editor, (-10,-60,-10), (85,-55,85), Block("air"))
# B = Building((0,0), (75,75), shapes[7]['matrice'])
# B.foundations.polygon.fill_vertice(editor, "pink_wool", -60)
# for collumn in B.foundations.collumns:
# collumn.fill(editor, "white_concrete", -60, -55)
# B.foundations.polygon.fill_polygon(editor, "white_concrete", -60)

View File

@@ -4,7 +4,7 @@ buildings:
min_tile_size: 3 min_tile_size: 3
max_tile_size: 12 max_tile_size: 12
foudations: foundations:
collumn_style : collumn_style :
# proportion of each style # proportion of each style
none: 1 none: 1
@@ -16,6 +16,7 @@ buildings:
max_height: 7 max_height: 7
facade: facade:
windows: windows:
size: size:
min_height: 2 min_height: 2
@@ -39,7 +40,7 @@ buildings:
none: 2 none: 2
top: 1 top: 1
top_and_bottom: 1 top_and_bottom: 1
inter_floor: 0.5
balcony: balcony:
proba : 0.25 proba : 0.25
growth: 0.5 # [growth]% chance to have min_width + 1 balcony length, [growth**2]% chance to have min_width + 2 balcony length, etc growth: 0.5 # [growth]% chance to have min_width + 1 balcony length, [growth**2]% chance to have min_width + 2 balcony length, etc
@@ -59,4 +60,19 @@ buildings:
none: 6 none: 6
# no difference if there is no details # no difference if there is no details
medium: 1 medium: 1
full: 1 full: 1
Entrance:
centered: 0.8
different_facade: 0.75
size:
min_height: 5
max_height: 9
inter_floor:
proba: 0.5
border_style:
# bloc used to fill the corner of the interfloor
none: 1
slab: 2
stairs: 2

View File

@@ -2,9 +2,9 @@ from enum import Enum
class DIRECTION(Enum): class DIRECTION(Enum):
NORTH = 0 NORTH = 0
WEST = 1 EAST = 1
SOUTH = 2 SOUTH = 2
EAST = 3 WEST = 3
class COLLUMN_STYLE(Enum): class COLLUMN_STYLE(Enum):
NONE = 0 NONE = 0
@@ -20,4 +20,9 @@ class WINDOW_BORDER_RADIUS(Enum):
class BALCONY_BORDER_RADIUS(Enum): class BALCONY_BORDER_RADIUS(Enum):
NONE = 0 NONE = 0
MEDIUM = 1 MEDIUM = 1
FULL = 2 FULL = 2
class INTER_FLOOR_BORDER(Enum):
NONE = 0
SLAB = 1
STAIRS = 2