From 7cb4600c154e166b65a6a625c1e3c3318ad1d9ec Mon Sep 17 00:00:00 2001 From: guille Date: Wed, 11 Oct 2023 14:32:31 +0200 Subject: [PATCH] Correct the positions for the boxes --- hub/exports/formats/cesiumjs_tileset.py | 24 ++++++++++++++++++++---- hub/exports/formats/glb.py | 7 +++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/hub/exports/formats/cesiumjs_tileset.py b/hub/exports/formats/cesiumjs_tileset.py index 6dd0ad24..99c04d3a 100644 --- a/hub/exports/formats/cesiumjs_tileset.py +++ b/hub/exports/formats/cesiumjs_tileset.py @@ -23,6 +23,14 @@ class CesiumjsTileset: except pyproj.exceptions.CRSError as err: raise pyproj.exceptions.CRSError from err self._to_gps = Transformer.from_crs(input_reference, pyproj.CRS('EPSG:4326')) + city_upper_corner = [ + self._city.upper_corner[0] - self._city.lower_corner[0], + self._city.upper_corner[1] - self._city.lower_corner[1], + self._city.upper_corner[2] - self._city.lower_corner[2] + ] + city_lower_corner = [0, 0, 0] + + print('root') self._tile_set = { 'asset': { 'version': '1.1', @@ -75,7 +83,7 @@ class CesiumjsTileset: 'geometricError': 240, 'root': { 'boundingVolume': { - 'box': CesiumjsTileset._box_values(self._city.upper_corner, self._city.lower_corner) + 'box': CesiumjsTileset._box_values(city_upper_corner, city_lower_corner) }, 'geometricError': 70, 'refine': 'ADD', @@ -87,10 +95,13 @@ class CesiumjsTileset: @staticmethod def _box_values(upper_corner, lower_corner): + x = (upper_corner[0] - lower_corner[0]) / 2 + x_center = ((upper_corner[0] - lower_corner[0]) / 2) + lower_corner[0] y = (upper_corner[1] - lower_corner[1]) / 2 + y_center = ((upper_corner[1] - lower_corner[1]) / 2) + lower_corner[1] z = (upper_corner[2] - lower_corner[2]) / 2 - return [x, y, z, x, 0, 0, 0, y, 0, 0, 0, z] + return [x_center, y_center, z, x, 0, 0, 0, y, 0, 0, 0, z] def _ground_coordinates(self, coordinates): ground_coordinates = [] @@ -104,10 +115,15 @@ class CesiumjsTileset: for building in self._city.buildings: upper_corner = [-math.inf, -math.inf, 0] lower_corner = [math.inf, math.inf, 0] - + lower_corner_coordinates = lower_corner for surface in building.grounds: # todo: maybe we should add the terrain? coordinates = self._ground_coordinates(surface.solid_polygon.coordinates) lower_corner = [min([c[0] for c in coordinates]), min([c[1] for c in coordinates]), 0] + lower_corner_coordinates = [ + min([c[0] for c in surface.solid_polygon.coordinates]), + min([c[1] for c in surface.solid_polygon.coordinates]), + 0 + ] upper_corner = [max([c[0] for c in coordinates]), max([c[1] for c in coordinates]), building.max_height] tile = { @@ -119,7 +135,7 @@ class CesiumjsTileset: 'class': 'building', 'properties': { 'name': building.name, - 'position': self._to_gps.transform(lower_corner[0], lower_corner[1]), + 'position': self._to_gps.transform(lower_corner_coordinates[0], lower_corner_coordinates[1]), 'aliases': building.aliases, 'volume': building.volume, 'floor_area': building.floor_area, diff --git a/hub/exports/formats/glb.py b/hub/exports/formats/glb.py index 558705c8..08776ccc 100644 --- a/hub/exports/formats/glb.py +++ b/hub/exports/formats/glb.py @@ -41,10 +41,13 @@ class Glb: subprocess.run([ self._obj2gtl, '-i', f'{self._path}/{building.name}.obj', - '-o', f'{glb}', '-b', - '--normalTexture', f'{self._path}/{building.name}.mtl' + '-o', f'{glb}', + '--triangleWindingOrderSanitization', + '--inputUpAxis', 'Y', + '--outputUpAxis', 'Y' ]) + 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: