system_assignation/exports/formats/obj.py
2021-03-16 17:15:08 -04:00

29 lines
1.1 KiB
Python

from exports.formats.triangular import Triangular
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')
def to_ground_points(self):
reference_coordinates = self._city.lower_corner
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_dic = GeometryFactory('obj', file_path_in).scene
for vertex in scene_dic['vertices']:
for i in range(0, 3):
vertex[i] -= reference_coordinates[i]
aux_variable = vertex[1]
vertex[1] = vertex[2]
vertex[2] = aux_variable
scene = Trimesh(vertices=scene_dic['vertices'], faces=scene_dic['faces'])
obj_file = trimesh.exchange.obj.export_obj(scene)
with open(file_path_out, 'w') as file:
file.write(obj_file)