diff --git a/buildings/Building.py b/buildings/Building.py index 2b6729b..ac91246 100644 --- a/buildings/Building.py +++ b/buildings/Building.py @@ -1,6 +1,9 @@ import random as rd +from utils.Enums import DIRECTION +from gdpc import Editor, Block, geometry from buildings.Foundations import Foundations from buildings.Facade import Facade +from buildings.Entrance import Entrance class Building: def __init__(self,rdata, position : tuple[int,int], size : tuple[int, int], matrice : list[list[int]], floors : int): @@ -14,16 +17,17 @@ class Building: self.foundations = Foundations(rdata["foundations"], size, matrice, tile_size,) self.facade = Facade(rdata["facade"], self.foundations.vertices, self.foundations.is_inner_or_outer) + self.entrance = Entrance(rdata, self.foundations.vertices, DIRECTION.EAST, self.foundations.is_inner_or_outer) - def build(self, editor, materials : list[str]): + def build(self, editor : Editor, materials : list[str]): 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) + if y == 0: self.entrance.build(editor, materials) + else : self.facade.build(editor, materials) def gen_tile_size(self) -> int: # Tiles are constant square units different for each buildings - return self.length smaller_side = min(self.length, self.width) # area is too small, will work but not very well diff --git a/buildings/Entrance.py b/buildings/Entrance.py index 37a98c8..2ee7ee4 100644 --- a/buildings/Entrance.py +++ b/buildings/Entrance.py @@ -1,28 +1,55 @@ import random as rd -from utils.Enums import DIRECTION +from gdpc import Editor, Block, geometry +from utils.Enums import DIRECTION,COLLUMN_STYLE from buildings.geometry.Vertice import Vertice +from buildings.Facade import Facade class Entrance: - def __init__(self, rdata, vertices : list[Vertice], direction : DIRECTION): + def __init__(self, rdata, vertices : list[Vertice], direction : DIRECTION, collumn_style : COLLUMN_STYLE): self.vertices = vertices self.direction = direction self.rdata = rdata + self.collumn_style = collumn_style self.is_centered = self.is_centered() - self.door_vertices = self.get_door_vertices() + self.door_vertice, self.facade = self.get_door_and_facade() + + def build(self, editor : Editor, materials : list[str]): + self.facade.build(editor, materials) + self.door_vertice.fill(editor, materials[0]) def is_centered(self) -> bool: - return rd.random() <= self.rdata["centered"] + return rd.random() <= self.rdata["entrance"]["centered"] - def get_door_vertices(self) -> Vertice: + def get_door_and_facade(self) -> tuple[Vertice, Facade]: oriented_vertices = self.get_oriented_vertices() + facade_vertices = self.vertices.copy() + door_vertice = None + + if self.is_centered: + oriented_vertices.sort(key = lambda v: v.point1.x if self.direction.value % 2 == 0 else v.point1.z) # if direction is north or south, sort by x, else sort by z + mid = len(oriented_vertices) // 2 + ver1, ver2 = oriented_vertices[mid], oriented_vertices[-mid-1] + if ver1.point1.position == ver2.point1.position: + door_vertice = ver1 + else : + door_vertice = Vertice(ver2.point1, ver1.point2) + facade_vertices.remove(ver2) + facade_vertices.remove(ver1) + + else: + door_vertice = rd.choice(oriented_vertices) + facade_vertices.remove(door_vertice) + + facade = Facade(self.rdata["facade"], facade_vertices, self.collumn_style) + return(door_vertice, facade) def get_oriented_vertices(self) -> list[Vertice]: # get the most off-centered vertices that are in the same direction as self.direction - same_direction_vertices = sorted([v for v in self.vertices if v.direction == self.direction], - lambda v: v.point1.z if self.direction.value % 2 == 0 else v.point1.x, # if direction is north or south, sort by x, else sort by z + same_direction_vertices = sorted([v for v in self.vertices if v.facing == self.direction], + key = lambda v: v.point1.z if self.direction.value % 2 == 0 else v.point1.x, # if direction is north or south, sort by x, else sort by z reverse = self.direction == DIRECTION.NORTH or self.direction == DIRECTION.WEST) # if direction is north or west, sort in reverse extremum = same_direction_vertices[0] return [v for v in same_direction_vertices if - (v.poin1.x == extremum.point1.x and self.direction.value % 2 == 0) or + (v.point1.x == extremum.point1.x and self.direction.value % 2 == 0) or (v.point1.z == extremum.point1.z and self.direction.value % 2 == 1)] \ No newline at end of file diff --git a/buildings/Facade.py b/buildings/Facade.py index eab9e98..27d195e 100644 --- a/buildings/Facade.py +++ b/buildings/Facade.py @@ -37,10 +37,10 @@ class Facade: 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: + if points.count(v.point1) >= 2: 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: + if points.count(v.point2) >= 2: 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"})) @@ -51,9 +51,9 @@ class Facade: elif self.inter_floor_border_style == INTER_FLOOR_BORDER.STAIRS: material = Block(self.materials[4], {"facing": "south", "half": "top"}) - if v.point1 in points: + if points.count(v.point1) >= 2: self.editor.placeBlock((-1,self.height,-1), material) - if v.point2 in points: + if points.count(v.point2) >= 2: self.editor.placeBlock((self.length,self.height,-1), material) diff --git a/buildings/TODO b/buildings/TODO index 2b34928..59fac34 100644 --- a/buildings/TODO +++ b/buildings/TODO @@ -1,13 +1,16 @@ Encadrement fenêtre toit de balcon avec/sans pilliers -border radius balcon collumn style rembard object détails facade rdc -toit +toit (clim, chateau deau, pubs) tiles 3d textures object opti textures opti géométrique -opti gdpc \ No newline at end of file +opti gdpc +pilliers quand trop de fenêtres + pas de pilliers si tile trop petite +limitateur taille +facade lisses/ immeubles collés +matrices pré-distribués \ No newline at end of file diff --git a/buildings/geometry/Tile.py b/buildings/geometry/Tile.py index 37c5059..24d5f64 100644 --- a/buildings/geometry/Tile.py +++ b/buildings/geometry/Tile.py @@ -61,16 +61,16 @@ class Tile: def get_vertice(self,vertice : int|DIRECTION) -> Vertice: # gives the corresponding vertice : - # 0 = north, 1 = west, 2 = south, 3 = east + # 0 = north, 1 = east, 2 = south, 3 = west match(vertice): case 0 : return Vertice(self.north_west, self.north_east, DIRECTION.NORTH) case 1 : - return Vertice(self.north_west, self.south_west, DIRECTION.WEST) + return Vertice(self.north_east, self.south_east, DIRECTION.EAST) case 2 : return Vertice(self.south_west, self.south_east, DIRECTION.SOUTH) case 3 : - return Vertice(self.north_east, self.south_east, DIRECTION.EAST) + return Vertice(self.north_west, self.south_west, DIRECTION.WEST) case DIRECTION.WEST : return self.west_vertice case DIRECTION.EAST : diff --git a/main.py b/main.py index 45a620d..666b717 100644 --- a/main.py +++ b/main.py @@ -21,25 +21,26 @@ random_data = y.data # with editor.pushTransform(Transform(rotation = i)): # geometry.placeCuboid(editor, (0,0,0), (0,3,5), Block("stone")) -transform = Transform((0,-60,80),rotation = 0) +transform = Transform((0,-60,110),rotation = 0) editor.transform.push(transform) -geometry.placeCuboid(editor, (-5,0,-8), (170,25,25), Block("air")) +geometry.placeCuboid(editor, (-5,0,-8), (60,10,70), Block("air")) +buildings = [] +buildings.append(Building(random_data["buildings"], (0, 0), (20,20), shapes[0]['matrice'], 1)) +buildings.append(Building(random_data["buildings"], (25, 0), (30,30), shapes[5]['matrice'], 1)) +buildings.append(Building(random_data["buildings"], (0, 35), (30,30), shapes[6]['matrice'], 1)) +buildings.append(Building(random_data["buildings"], (35, 35), (20,20), shapes[7]['matrice'], 1)) -padd = 0 -for i in range(4,13): - building = Building(random_data["buildings"], (padd, 0), (i,i), shapes[0]['matrice'], 3) +for building in buildings : building.build(editor, ["stone_bricks","glass_pane","glass","cobblestone_wall","stone_brick_stairs","oak_planks","white_concrete","cobblestone","stone_brick_slab"]) - padd += i + 10 - # # Get a block # block = editor.getBlock((0,48,0)) # # Place a block -#editor.placeBlock((0 , 5, 0), Block("stone")) +# editor.placeBlock((0 , 5, 0), Block("stone")) # # Build a cube # geometry.placeCuboid(editor, (458, 92, 488), (468, 99, 471), Block("oak_planks")) diff --git a/params.yml b/params.yml index 6ed391a..35ac334 100644 --- a/params.yml +++ b/params.yml @@ -8,7 +8,7 @@ buildings: collumn_style : # proportion of each style none: 1 - inner: 1 + inner: 5 outer: 1 both: 1 floor: @@ -62,17 +62,17 @@ buildings: medium: 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 \ No newline at end of file + stairs: 2 + + entrance: + centered: 0.8 + different_facade: 0.75 + size: + min_height: 5 + max_height: 9 \ No newline at end of file