place entrance (not fied)
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import random as rd
|
import random as rd
|
||||||
|
from utils.Enums import DIRECTION
|
||||||
|
from gdpc import Editor, Block, geometry
|
||||||
from buildings.Foundations import Foundations
|
from buildings.Foundations import Foundations
|
||||||
from buildings.Facade import Facade
|
from buildings.Facade import Facade
|
||||||
|
from buildings.Entrance import Entrance
|
||||||
|
|
||||||
class Building:
|
class Building:
|
||||||
def __init__(self,rdata, position : tuple[int,int], size : tuple[int, int], matrice : list[list[int]], floors : int):
|
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.foundations = Foundations(rdata["foundations"], size, matrice, tile_size,)
|
||||||
self.facade = Facade(rdata["facade"], self.foundations.vertices, self.foundations.is_inner_or_outer)
|
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):
|
for y in range(self.floors):
|
||||||
with editor.pushTransform((self.position[0], y*(self.foundations.floor_height+1), self.position[1])):
|
with editor.pushTransform((self.position[0], y*(self.foundations.floor_height+1), self.position[1])):
|
||||||
self.foundations.build(editor, materials)
|
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:
|
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
|
||||||
|
|||||||
@@ -1,28 +1,55 @@
|
|||||||
import random as rd
|
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.geometry.Vertice import Vertice
|
||||||
|
from buildings.Facade import Facade
|
||||||
|
|
||||||
class Entrance:
|
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.vertices = vertices
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
self.rdata = rdata
|
self.rdata = rdata
|
||||||
|
self.collumn_style = collumn_style
|
||||||
self.is_centered = self.is_centered()
|
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:
|
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()
|
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]:
|
def get_oriented_vertices(self) -> list[Vertice]:
|
||||||
# get the most off-centered vertices that are in the same direction as self.direction
|
# 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],
|
same_direction_vertices = sorted([v for v in self.vertices if v.facing == 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
|
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
|
reverse = self.direction == DIRECTION.NORTH or self.direction == DIRECTION.WEST) # if direction is north or west, sort in reverse
|
||||||
extremum = same_direction_vertices[0]
|
extremum = same_direction_vertices[0]
|
||||||
return [v for v in same_direction_vertices if
|
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)]
|
(v.point1.z == extremum.point1.z and self.direction.value % 2 == 1)]
|
||||||
|
|
||||||
@@ -37,10 +37,10 @@ class Facade:
|
|||||||
def correct_corners(self,points : list[Point], v : Vertice):
|
def correct_corners(self,points : list[Point], v : Vertice):
|
||||||
if self.padding == 0:
|
if self.padding == 0:
|
||||||
if self.window.border_radius != 0 and self.window.width == self.length:
|
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,0), Block(self.materials[8]))
|
||||||
self.editor.placeBlock((0,self.window.ypadding+self.window.height,0), Block(self.materials[8], {"type": "top"}))
|
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,0), Block(self.materials[8]))
|
||||||
self.editor.placeBlock((self.length-1,self.window.ypadding+self.window.height,0), Block(self.materials[8], {"type": "top"}))
|
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:
|
elif self.inter_floor_border_style == INTER_FLOOR_BORDER.STAIRS:
|
||||||
material = Block(self.materials[4], {"facing": "south", "half": "top"})
|
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)
|
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)
|
self.editor.placeBlock((self.length,self.height,-1), material)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
Encadrement fenêtre
|
Encadrement fenêtre
|
||||||
toit de balcon avec/sans pilliers
|
toit de balcon avec/sans pilliers
|
||||||
border radius balcon
|
|
||||||
collumn style
|
collumn style
|
||||||
rembard object
|
rembard object
|
||||||
détails facade
|
détails facade
|
||||||
rdc
|
rdc
|
||||||
toit
|
toit (clim, chateau deau, pubs)
|
||||||
tiles 3d
|
tiles 3d
|
||||||
textures object
|
textures object
|
||||||
opti textures
|
opti textures
|
||||||
opti géométrique
|
opti géométrique
|
||||||
opti gdpc
|
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
|
||||||
@@ -61,16 +61,16 @@ class Tile:
|
|||||||
|
|
||||||
def get_vertice(self,vertice : int|DIRECTION) -> Vertice:
|
def get_vertice(self,vertice : int|DIRECTION) -> Vertice:
|
||||||
# gives the corresponding vertice :
|
# gives the corresponding vertice :
|
||||||
# 0 = north, 1 = west, 2 = south, 3 = east
|
# 0 = north, 1 = east, 2 = south, 3 = west
|
||||||
match(vertice):
|
match(vertice):
|
||||||
case 0 :
|
case 0 :
|
||||||
return Vertice(self.north_west, self.north_east, DIRECTION.NORTH)
|
return Vertice(self.north_west, self.north_east, DIRECTION.NORTH)
|
||||||
case 1 :
|
case 1 :
|
||||||
return Vertice(self.north_west, self.south_west, DIRECTION.WEST)
|
return Vertice(self.north_east, self.south_east, DIRECTION.EAST)
|
||||||
case 2 :
|
case 2 :
|
||||||
return Vertice(self.south_west, self.south_east, DIRECTION.SOUTH)
|
return Vertice(self.south_west, self.south_east, DIRECTION.SOUTH)
|
||||||
case 3 :
|
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 :
|
case DIRECTION.WEST :
|
||||||
return self.west_vertice
|
return self.west_vertice
|
||||||
case DIRECTION.EAST :
|
case DIRECTION.EAST :
|
||||||
|
|||||||
17
main.py
17
main.py
@@ -21,25 +21,26 @@ random_data = y.data
|
|||||||
# with editor.pushTransform(Transform(rotation = i)):
|
# with editor.pushTransform(Transform(rotation = i)):
|
||||||
# geometry.placeCuboid(editor, (0,0,0), (0,3,5), Block("stone"))
|
# 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)
|
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 building in buildings :
|
||||||
for i in range(4,13):
|
|
||||||
building = Building(random_data["buildings"], (padd, 0), (i,i), shapes[0]['matrice'], 3)
|
|
||||||
building.build(editor, ["stone_bricks","glass_pane","glass","cobblestone_wall","stone_brick_stairs","oak_planks","white_concrete","cobblestone","stone_brick_slab"])
|
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
|
# # Get a block
|
||||||
# block = editor.getBlock((0,48,0))
|
# block = editor.getBlock((0,48,0))
|
||||||
|
|
||||||
# # Place a block
|
# # Place a block
|
||||||
#editor.placeBlock((0 , 5, 0), Block("stone"))
|
# editor.placeBlock((0 , 5, 0), Block("stone"))
|
||||||
|
|
||||||
# # Build a cube
|
# # Build a cube
|
||||||
# geometry.placeCuboid(editor, (458, 92, 488), (468, 99, 471), Block("oak_planks"))
|
# geometry.placeCuboid(editor, (458, 92, 488), (468, 99, 471), Block("oak_planks"))
|
||||||
|
|||||||
16
params.yml
16
params.yml
@@ -8,7 +8,7 @@ buildings:
|
|||||||
collumn_style :
|
collumn_style :
|
||||||
# proportion of each style
|
# proportion of each style
|
||||||
none: 1
|
none: 1
|
||||||
inner: 1
|
inner: 5
|
||||||
outer: 1
|
outer: 1
|
||||||
both: 1
|
both: 1
|
||||||
floor:
|
floor:
|
||||||
@@ -62,13 +62,6 @@ buildings:
|
|||||||
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:
|
inter_floor:
|
||||||
proba: 0.5
|
proba: 0.5
|
||||||
border_style:
|
border_style:
|
||||||
@@ -76,3 +69,10 @@ buildings:
|
|||||||
none: 1
|
none: 1
|
||||||
slab: 2
|
slab: 2
|
||||||
stairs: 2
|
stairs: 2
|
||||||
|
|
||||||
|
entrance:
|
||||||
|
centered: 0.8
|
||||||
|
different_facade: 0.75
|
||||||
|
size:
|
||||||
|
min_height: 5
|
||||||
|
max_height: 9
|
||||||
Reference in New Issue
Block a user