Test to add building
143
main.py
@@ -1,7 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
from math import exp, sqrt
|
from math import exp, sqrt
|
||||||
|
|
||||||
from gdpc import Editor, Block
|
from gdpc import Editor, Block, geometry, Transform
|
||||||
|
|
||||||
from House import *
|
from House import *
|
||||||
from networks.geometry.Point3D import Point3D
|
from networks.geometry.Point3D import Point3D
|
||||||
@@ -15,18 +15,24 @@ from networks.geometry.Point3D import Point3D
|
|||||||
from networks.geometry.Point2D import Point2D
|
from networks.geometry.Point2D import Point2D
|
||||||
from networks.geometry.Circle import Circle
|
from networks.geometry.Circle import Circle
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
from utils.JsonReader import JsonReader
|
||||||
|
from utils.YamlReader import YamlReader
|
||||||
|
from buildings.Building import Building
|
||||||
|
|
||||||
|
from utils.functions import *
|
||||||
|
from utils.Enums import DIRECTION
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
Road([Point3D(4089, 138, 21), Point3D(4122, 128, 46),
|
rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker()
|
||||||
Point3D(4120, 128, 75), Point3D(4154, 128, 90), Point3D(4182, 122, 53)], 9)
|
|
||||||
# rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker()
|
|
||||||
|
|
||||||
# editor = Editor(buffering=True)
|
editor = Editor(buffering=True)
|
||||||
# buildArea = editor.getBuildArea()
|
buildArea = editor.getBuildArea()
|
||||||
# origin = ((buildArea.begin).x, (buildArea.begin).z)
|
origin = ((buildArea.begin).x, (buildArea.begin).z)
|
||||||
# center = (abs(buildArea.begin.x - buildArea.end.x) / 2,
|
center = (abs(buildArea.begin.x - buildArea.end.x) / 2,
|
||||||
# abs(buildArea.begin.z - buildArea.end.z) / 2)
|
abs(buildArea.begin.z - buildArea.end.z) / 2)
|
||||||
# length_world = sqrt((center[0]*2) ** 2 + (center[1]*2) ** 2)
|
length_world = sqrt((center[0]*2) ** 2 + (center[1]*2) ** 2)
|
||||||
|
|
||||||
# remove_trees('./world_maker/data/heightmap.png', './world_maker/data/treemap.png',
|
# remove_trees('./world_maker/data/heightmap.png', './world_maker/data/treemap.png',
|
||||||
# './world_maker/data/smooth_sobel_watermap.png')
|
# './world_maker/data/smooth_sobel_watermap.png')
|
||||||
@@ -39,43 +45,68 @@ def main():
|
|||||||
# roads.setRoads(skeleton_mountain)
|
# roads.setRoads(skeleton_mountain)
|
||||||
# roads.setRoads(skeleton_highway)
|
# roads.setRoads(skeleton_highway)
|
||||||
|
|
||||||
# blocks = {
|
blocks = {
|
||||||
# "wall": "blackstone",
|
"wall": "blackstone",
|
||||||
# "roof": "blackstone",
|
"roof": "blackstone",
|
||||||
# "roof_slab": "blackstone_slab",
|
"roof_slab": "blackstone_slab",
|
||||||
# "door": "oak_door",
|
"door": "oak_door",
|
||||||
# "window": "glass_pane",
|
"window": "glass_pane",
|
||||||
# "entrance": "oak_door",
|
"entrance": "oak_door",
|
||||||
# "stairs": "quartz_stairs",
|
"stairs": "quartz_stairs",
|
||||||
# "stairs_slab": "quartz_slab",
|
"stairs_slab": "quartz_slab",
|
||||||
# "celling": "quartz_block",
|
"celling": "quartz_block",
|
||||||
# "floor": "quartz_block",
|
"floor": "quartz_block",
|
||||||
# "celling_slab": "quartz_slab",
|
"celling_slab": "quartz_slab",
|
||||||
# "garden_outline": "oak_leaves",
|
"garden_outline": "oak_leaves",
|
||||||
# "garden_floor": "grass_block"
|
"garden_floor": "grass_block"
|
||||||
# }
|
}
|
||||||
|
|
||||||
# entranceDirection = ["N", "S", "E", "W"]
|
entranceDirection = ["N", "S", "E", "W"]
|
||||||
|
|
||||||
# for houses in rectangle_building:
|
# get every differents buildings shapes
|
||||||
# height = get_height_building_from_center(
|
f = JsonReader('./buildings/shapes.json')
|
||||||
# center, (houses[0][0], houses[0][2]), length_world)
|
shapes = f.data
|
||||||
# start = (houses[0][0] + origin[0], houses[0]
|
baseShape = shapes[0]['matrice']
|
||||||
# [1], houses[0][2] + origin[1])
|
|
||||||
# end = (houses[1][0] + origin[0], houses[1]
|
|
||||||
# [1] + height, houses[1][2] + origin[1])
|
|
||||||
# house = House(editor, start, end,
|
|
||||||
# entranceDirection[random.randint(0, 3)], blocks)
|
|
||||||
# house.build()
|
|
||||||
|
|
||||||
# for houses in rectangle_house_mountain:
|
# get the random data for the buildings
|
||||||
# start = (houses[0][0] + origin[0], houses[0]
|
y = YamlReader('params.yml')
|
||||||
# [1], houses[0][2] + origin[1])
|
random_data = y.data
|
||||||
# end = (houses[1][0] + origin[0], houses[1]
|
|
||||||
# [1], houses[1][2] + origin[1])
|
# move your editor wto the position you wanna build on
|
||||||
# house = House(editor, start, end,
|
transform = Transform((75, -60, 110), rotation=0)
|
||||||
# entranceDirection[random.randint(0, 3)], blocks)
|
editor.transform.push(transform)
|
||||||
# house.build()
|
|
||||||
|
# clear the area you build on
|
||||||
|
geometry.placeCuboid(editor, (-5, 0, -8), (25, 100, 25), Block("air"))
|
||||||
|
|
||||||
|
# create a building at the relative position 0,0 with 20 blocks length and 20 blocks width, with a normal shape and 10 floors
|
||||||
|
|
||||||
|
# build it with your custom materials
|
||||||
|
|
||||||
|
for buildings in rectangle_building:
|
||||||
|
height = get_height_building_from_center(
|
||||||
|
center, (buildings[0][0], buildings[0][2]), length_world)
|
||||||
|
start = (min(buildings[0][0], buildings[1][0]) + origin[0], buildings[0]
|
||||||
|
[1], min(buildings[0][2], buildings[1][2]) + origin[1])
|
||||||
|
end = (max(buildings[0][0], buildings[1][0]) + origin[0], buildings[1]
|
||||||
|
[1], max(buildings[0][2], buildings[1][2]) + origin[1])
|
||||||
|
|
||||||
|
transform = Transform(start, rotation=0)
|
||||||
|
editor.transform.push(transform)
|
||||||
|
|
||||||
|
building = Building(random_data["buildings"], [
|
||||||
|
(0, 0, 0), (end[0] - start[0], height, end[2] - start[2])], baseShape, DIRECTION.EAST)
|
||||||
|
building.build(editor, ["stone_bricks", "glass_pane", "glass", "cobblestone_wall", "stone_brick_stairs",
|
||||||
|
"oak_planks", "white_concrete", "cobblestone", "stone_brick_slab", "iron_bars"])
|
||||||
|
|
||||||
|
for buildings in rectangle_house_mountain:
|
||||||
|
start = (buildings[0][0] + origin[0], buildings[0]
|
||||||
|
[1], buildings[0][2] + origin[1])
|
||||||
|
end = (buildings[1][0] + origin[0], buildings[1]
|
||||||
|
[1], buildings[1][2] + origin[1])
|
||||||
|
house = House(editor, start, end,
|
||||||
|
entranceDirection[random.randint(0, 3)], blocks)
|
||||||
|
house.build()
|
||||||
|
|
||||||
|
|
||||||
def get_height_building_from_center(center, position, length_world):
|
def get_height_building_from_center(center, position, length_world):
|
||||||
@@ -110,7 +141,10 @@ def set_roads(skeleton: Skeleton, origin):
|
|||||||
for j in range(len(skeleton.lines[i])):
|
for j in range(len(skeleton.lines[i])):
|
||||||
xyz = transpose_form_heightmap('./world_maker/data/heightmap.png',
|
xyz = transpose_form_heightmap('./world_maker/data/heightmap.png',
|
||||||
skeleton.coordinates[skeleton.lines[i][j]], origin)
|
skeleton.coordinates[skeleton.lines[i][j]], origin)
|
||||||
skeleton.lines[i][j] = xyz
|
heightmap_smooth = Image.open(
|
||||||
|
'./world_maker/data/full_road_heightmap_smooth.png')
|
||||||
|
skeleton.lines[i][j] = [xyz[0], heightmap_smooth.getpixel(
|
||||||
|
(skeleton.coordinates[skeleton.lines[i][j]][0], skeleton.coordinates[skeleton.lines[i][j]][-1])), xyz[2]]
|
||||||
|
|
||||||
print("[Roads] Start simplification...")
|
print("[Roads] Start simplification...")
|
||||||
# Simplification
|
# Simplification
|
||||||
@@ -120,7 +154,25 @@ def set_roads(skeleton: Skeleton, origin):
|
|||||||
skeleton.lines[i] = simplify_coordinates(skeleton.lines[i], 20)
|
skeleton.lines[i] = simplify_coordinates(skeleton.lines[i], 20)
|
||||||
j = 0
|
j = 0
|
||||||
while j < len(skeleton.lines[i])-1:
|
while j < len(skeleton.lines[i])-1:
|
||||||
|
print(f"[Distance] {Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2]))}")
|
||||||
|
if Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2])) <= 20:
|
||||||
|
print(skeleton.lines[i][j+1], skeleton.lines[i][j])
|
||||||
|
del skeleton.lines[i][j+1]
|
||||||
|
print("[Roads] Delete point to close")
|
||||||
|
j += 1
|
||||||
|
j = 0
|
||||||
|
while j < len(skeleton.lines[i])-1:
|
||||||
|
print(f"[Distance] {Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2]))}")
|
||||||
if Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2])) <= 10:
|
if Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2])) <= 10:
|
||||||
|
print(skeleton.lines[i][j+1], skeleton.lines[i][j])
|
||||||
|
del skeleton.lines[i][j+1]
|
||||||
|
print("[Roads] Delete point to close")
|
||||||
|
j += 1
|
||||||
|
j = 0
|
||||||
|
while j < len(skeleton.lines[i])-1:
|
||||||
|
print(f"[Distance] {Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2]))}")
|
||||||
|
if Point3D(skeleton.lines[i][j][0], skeleton.lines[i][j][1], skeleton.lines[i][j][2]).distance(Point3D(skeleton.lines[i][j+1][0], skeleton.lines[i][j+1][1], skeleton.lines[i][j+1][2])) <= 10:
|
||||||
|
print(skeleton.lines[i][j+1], skeleton.lines[i][j])
|
||||||
del skeleton.lines[i][j+1]
|
del skeleton.lines[i][j+1]
|
||||||
print("[Roads] Delete point to close")
|
print("[Roads] Delete point to close")
|
||||||
j += 1
|
j += 1
|
||||||
@@ -132,6 +184,7 @@ def set_roads(skeleton: Skeleton, origin):
|
|||||||
print(f"[Roads] Generating roads {i + 1}/{len(skeleton.lines)}.")
|
print(f"[Roads] Generating roads {i + 1}/{len(skeleton.lines)}.")
|
||||||
if len(skeleton.lines[i]) >= 4:
|
if len(skeleton.lines[i]) >= 4:
|
||||||
Road(Point3D.from_arrays(skeleton.lines[i]), 9)
|
Road(Point3D.from_arrays(skeleton.lines[i]), 9)
|
||||||
|
print(f"[ROAD] Points: {skeleton.lines[i]}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ from scipy.ndimage import gaussian_filter1d
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
class Road:
|
class Road:
|
||||||
def __init__(self, coordinates: List[Point3D], width: int):
|
def __init__(self, coordinates: List[Point3D], width: int):
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 407 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 145 B |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 889 B |
|
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 927 B |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 811 B |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 599 B |
|
Before Width: | Height: | Size: 251 B After Width: | Height: | Size: 101 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 522 B |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 563 B |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 491 B |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 387 B |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 891 B |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 348 B |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 657 B |
@@ -56,7 +56,7 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask
|
|||||||
def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Image], mask: Union[str, Image]):
|
def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Image], mask: Union[str, Image]):
|
||||||
|
|
||||||
print("[Smooth terrain] Starting...")
|
print("[Smooth terrain] Starting...")
|
||||||
editor = Editor()
|
editor = Editor(buffering=True)
|
||||||
build_area = editor.getBuildArea()
|
build_area = editor.getBuildArea()
|
||||||
build_rectangle = build_area.toRect()
|
build_rectangle = build_area.toRect()
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import numpy as np
|
|||||||
|
|
||||||
|
|
||||||
def world_maker():
|
def world_maker():
|
||||||
# world = World()
|
world = World()
|
||||||
# heightmap, watermap, treemap = get_data(world)
|
heightmap, watermap, treemap = get_data(world)
|
||||||
heightmap, watermap, treemap = get_data_no_update()
|
# heightmap, watermap, treemap = get_data_no_update()
|
||||||
|
|
||||||
heightmap_smooth = filter_smooth(heightmap, 4)
|
heightmap_smooth = filter_smooth(heightmap, 4)
|
||||||
heightmap_smooth.save('./world_maker/data/heightmap_smooth.png')
|
heightmap_smooth.save('./world_maker/data/heightmap_smooth.png')
|
||||||
|
|||||||