city_retrofit/exports/formats/obj.py

29 lines
983 B
Python
Raw Normal View History

2021-03-16 20:14:40 -04:00
"""
export a city into Obj format
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from exports.formats.triangular import Triangular
2021-03-16 16:58:52 -04:00
from pathlib import Path
from imports.geometry_factory import GeometryFactory
import trimesh.exchange.obj
from trimesh import Trimesh
class Obj(Triangular):
def __init__(self, city, path):
super().__init__(city, path, 'obj')
2021-03-16 16:58:52 -04:00
def to_ground_points(self):
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()
scene = GeometryFactory('obj', file_path_in).scene
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)