2021-03-16 20:14:40 -04:00
|
|
|
"""
|
|
|
|
export a city from trimesh into Triangular format (obj or stl)
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
|
|
"""
|
2021-03-16 12:33:22 -04:00
|
|
|
from pathlib import Path
|
|
|
|
from trimesh import Trimesh
|
|
|
|
|
2021-03-16 16:58:52 -04:00
|
|
|
|
2021-03-16 12:33:22 -04:00
|
|
|
class Triangular:
|
2021-03-25 09:11:30 -04:00
|
|
|
def __init__(self, city, path, triangular_format, write_mode='w'):
|
2021-03-16 12:33:22 -04:00
|
|
|
self._city = city
|
|
|
|
self._path = path
|
|
|
|
self._triangular_format = triangular_format
|
2021-03-25 09:11:30 -04:00
|
|
|
self._write_mode = write_mode
|
2021-03-16 20:14:40 -04:00
|
|
|
self._export()
|
2021-03-16 12:33:22 -04:00
|
|
|
|
2021-03-16 20:14:40 -04:00
|
|
|
def _export(self):
|
2021-03-16 12:33:22 -04:00
|
|
|
if self._city.name is None:
|
|
|
|
self._city.name = 'unknown_city'
|
|
|
|
file_name = self._city.name + '.' + self._triangular_format
|
|
|
|
file_path = (Path(self._path).resolve() / file_name).resolve()
|
|
|
|
trimesh = Trimesh()
|
|
|
|
for building in self._city.buildings:
|
|
|
|
trimesh = trimesh.union(building.simplified_polyhedron.trimesh)
|
2021-03-25 09:11:30 -04:00
|
|
|
|
|
|
|
with open(file_path, self._write_mode) as file:
|
2021-03-16 12:33:22 -04:00
|
|
|
file.write(trimesh.export(file_type=self._triangular_format))
|