storey division working, code needs to be cleaned

This commit is contained in:
Pilar 2021-03-30 17:57:38 -04:00
parent e5e6b19ed9
commit 809dc1b3b6

View File

@ -18,7 +18,10 @@ from helpers.geometry_helper import GeometryHelper as gh
from helpers.configuration_helper import ConfigurationHelper
import math
from pathlib import Path
from trimesh import intersections
from trimesh import Trimesh
from city_model_structure.attributes.polygon import Polygon
from city_model_structure.attributes.polyhedron import Polyhedron
class Building(CityObject):
"""
@ -376,11 +379,10 @@ class Building(CityObject):
print('number_of_storeys', number_of_storeys)
last_storey_height = float(self.max_height) - height*(number_of_storeys-1)
print('last_storey_height', last_storey_height)
if last_storey_height < height/2:
if last_storey_height < 0.9*height:
number_of_storeys -= 1
print('number storeys', number_of_storeys)
trimesh = self.simplified_polyhedron.trimesh
normal_plane = [0, 0, -1]
rest_trimesh = trimesh
for n in range(0, number_of_storeys - 1):
print(n)
@ -388,14 +390,38 @@ class Building(CityObject):
self.building_lower_corner[2] + height*(n+1)]
print('point plane', point_plane)
print('rest trimesh', rest_trimesh.volume)
trimeshes = gh.divide_mesh_by_plane(rest_trimesh, normal_plane, point_plane)
print('number meshes', len(trimeshes))
storey = trimeshes[0]
vertices, faces = intersections.slice_faces_plane(rest_trimesh.vertices, rest_trimesh.faces, [0, 0, -1],
point_plane)
lines = list(intersections.mesh_plane(rest_trimesh, [0, 0, -1], point_plane))
line_points = gh.segment_list_to_point_cloud(lines)
polyhedron = Polyhedron(Polygon(line_points).triangulate())
tri = Trimesh(polyhedron.vertices, polyhedron.faces)
new_faces = []
for face in tri.faces:
new_face = []
for point in face:
point += len(vertices)
new_face.append(point)
new_faces.append(new_face)
vertices = np.append(vertices, tri.vertices, axis=0)
faces = np.append(faces, new_faces, axis=0)
storey = Trimesh(vertices, faces)
file_name = 'storey_' + str(n) + '.obj'
path_name = (Path(__file__).parent.parent / 'tests' / 'tests_outputs' / file_name).resolve()
with open(path_name, 'w') as file:
file.write(storey.export(file_type='obj'))
rest_trimesh = trimeshes[1]
vertices, faces = intersections.slice_faces_plane(rest_trimesh.vertices, rest_trimesh.faces, [0, 0, 1],
point_plane)
new_faces = []
for face in tri.faces:
new_face = []
for point in face:
point += len(vertices)
new_face.append(point)
new_faces.append(new_face)
vertices = np.append(vertices, tri.vertices, axis=0)
faces = np.append(faces, new_faces, axis=0)
rest_trimesh = Trimesh(vertices, faces)
file_name = 'rest_trimesh_' + str(n) + '.obj'
path_name = (Path(__file__).parent.parent / 'tests' / 'tests_outputs' / file_name).resolve()
with open(path_name, 'w') as file: