diff --git a/hub/city_model_structure/building.py b/hub/city_model_structure/building.py index e4d654b2..5a6e109e 100644 --- a/hub/city_model_structure/building.py +++ b/hub/city_model_structure/building.py @@ -810,3 +810,17 @@ class Building(CityObject): orientation_losses_factor[_key]['south'])] self._onsite_electrical_production[_key] = _results return self._onsite_electrical_production + + @property + def lower_corner(self): + """ + Get building lower corner. + """ + return [self._min_x, self._min_y, self._min_z] + + @property + def upper_corner(self): + """ + Get building upper corner. + """ + return [self._max_x, self._max_y, self._max_z] diff --git a/hub/exports/formats/glb.py b/hub/exports/formats/glb.py index 67b5a960..6329788d 100644 --- a/hub/exports/formats/glb.py +++ b/hub/exports/formats/glb.py @@ -1,4 +1,3 @@ -import glob import os import shutil import subprocess @@ -33,24 +32,18 @@ class Glb: def _export(self): try: for building in self._city.buildings: - print(self._city.lower_corner, self._city.upper_corner) city = City(self._city.lower_corner, self._city.upper_corner, self._city.srs_name) - city.name = building.name city.add_city_object(building) + city.name = building.name Obj(city, self._path) glb = f'{self._path}/{building.name}.glb' subprocess.run([ self._obj2gtl, '-i', f'{self._path}/{building.name}.obj', '-b', - '-o', f'{glb}', - '--triangleWindingOrderSanitization', - '--inputUpAxis', 'Y', - '--outputUpAxis', 'Y' + '-o', f'{glb}' ]) - os.unlink(f'{self._path}/{building.name}.obj') os.unlink(f'{self._path}/{building.name}.mtl') except (subprocess.SubprocessError, subprocess.TimeoutExpired, subprocess.CalledProcessError) as err: raise GltExceptionError from err - diff --git a/hub/exports/formats/obj.py b/hub/exports/formats/obj.py index 219bb1ac..d212740c 100644 --- a/hub/exports/formats/obj.py +++ b/hub/exports/formats/obj.py @@ -4,7 +4,6 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2022 Concordia CERC group Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ -import math from pathlib import Path import numpy as np @@ -27,7 +26,7 @@ class Obj: def _to_vertex(self, coordinate): x, y, z = self._ground(coordinate) - return f'v {x} {z} {y}\n' + return f'v {x} {z} -{y}\n' # to match opengl expectations def _to_texture_vertex(self, coordinate): u, v, _ = self._ground(coordinate) @@ -55,22 +54,22 @@ class Obj: with open(mtl_file_path, 'w', encoding='utf-8') as mtl: mtl.write("newmtl cerc_base_material\n") mtl.write("Ka 1.0 1.0 1.0 # Ambient color (white)\n") - mtl.write("Kd 0.3 0.1 0.3 # Diffuse color (greenish)\n") + mtl.write("Kd 0.1 0.3 0.1 # Diffuse color (greenish)\n") mtl.write("Ks 1.0 1.0 1.0 # Specular color (white)\n") mtl.write("Ns 400.0 # Specular exponent (defines shininess)\n") vertices = {} - normals_index = {} faces = [] vertex_index = 0 normal_index = 0 with open(obj_file_path, 'w', encoding='utf-8') as obj: obj.write("# cerc-hub export\n") - obj.write(f'mtllib {mtl_name}') + obj.write(f'mtllib {mtl_name}\n') for building in self._city.buildings: obj.write(f'# building {building.name}\n') obj.write(f'g {building.name}\n') obj.write('s off\n') + for surface in building.surfaces: obj.write(f'# surface {surface.name}\n') face = [] @@ -79,7 +78,6 @@ class Obj: textures = [] for coordinate in surface.perimeter_polygon.coordinates: vertex = self._to_vertex(coordinate) - if vertex not in vertices: vertex_index += 1 vertices[vertex] = vertex_index @@ -88,8 +86,7 @@ class Obj: textures.append(self._to_texture_vertex(coordinate)) # only append if non-existing else: current = vertices[vertex] - - face.insert(0, f'{current}/{current}/{normal_index}') # insert counterclockwise + face.append(f'{current}/{current}/{normal_index}') # insert clockwise obj.writelines(normal) # add the normal obj.writelines(textures) # add the texture vertex