2021-03-16 20:14:40 -04:00
|
|
|
"""
|
|
|
|
export a city into Obj format
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2022-04-08 09:35:33 -04:00
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
2021-03-16 20:14:40 -04:00
|
|
|
"""
|
|
|
|
|
2021-03-16 16:58:52 -04:00
|
|
|
from pathlib import Path
|
|
|
|
import trimesh.exchange.obj
|
2021-08-26 13:27:43 -04:00
|
|
|
from exports.formats.triangular import Triangular
|
|
|
|
from imports.geometry_factory import GeometryFactory
|
2021-03-16 16:58:52 -04:00
|
|
|
|
2021-03-16 12:33:22 -04:00
|
|
|
|
|
|
|
class Obj(Triangular):
|
2021-08-26 13:27:43 -04:00
|
|
|
"""
|
|
|
|
Export to obj format
|
|
|
|
"""
|
2021-03-16 12:33:22 -04:00
|
|
|
def __init__(self, city, path):
|
|
|
|
super().__init__(city, path, 'obj')
|
2021-03-16 16:58:52 -04:00
|
|
|
|
|
|
|
def to_ground_points(self):
|
2021-08-26 13:27:43 -04:00
|
|
|
"""
|
|
|
|
Move closer to the origin
|
|
|
|
"""
|
2021-03-16 16:58:52 -04:00
|
|
|
file_name_in = self._city.name + '.' + self._triangular_format
|
|
|
|
file_name_out = self._city.name + '_ground.' + self._triangular_format
|
|
|
|
file_path_in = (Path(self._path).resolve() / file_name_in).resolve()
|
|
|
|
file_path_out = (Path(self._path).resolve() / file_name_out).resolve()
|
2022-11-21 13:53:58 -05:00
|
|
|
scene = GeometryFactory('obj', path=file_path_in).scene
|
2021-04-08 11:47:58 -04:00
|
|
|
scene.rezero()
|
2021-03-16 16:58:52 -04:00
|
|
|
obj_file = trimesh.exchange.obj.export_obj(scene)
|
|
|
|
with open(file_path_out, 'w') as file:
|
|
|
|
file.write(obj_file)
|