39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
import trimesh
|
|
import pymeshlab
|
|
|
|
def convert_amf_to_ply(input_file, intermediate_file):
|
|
# Carrega o arquivo AMF usando trimesh
|
|
mesh = trimesh.load(input_file, file_type='amf')
|
|
|
|
# Salva a malha como arquivo PLY
|
|
mesh.export(intermediate_file, file_type='ply')
|
|
|
|
def simplify_ply_to_obj(intermediate_file, output_file, target_faces):
|
|
# Carrega o arquivo PLY usando pymeshlab
|
|
ms = pymeshlab.MeshSet()
|
|
ms.load_new_mesh(intermediate_file)
|
|
|
|
# Simplificação de malha com um número alvo de faces
|
|
ms.meshing_decimation_quadric_edge_collapse(targetfacenum=target_faces)
|
|
|
|
# Salva como arquivo OBJ, que suporta cores
|
|
ms.save_current_mesh(output_file, save_textures=True)
|
|
|
|
print(f"Simplificação concluída. Arquivo OBJ salvo em: {output_file}")
|
|
|
|
def main(input_file, output_file, target_faces):
|
|
intermediate_file = 'intermediate.ply'
|
|
|
|
# Converte AMF para PLY
|
|
convert_amf_to_ply(input_file, intermediate_file)
|
|
|
|
# Simplifica a malha PLY e converte para OBJ
|
|
simplify_ply_to_obj(intermediate_file, output_file, target_faces)
|
|
|
|
if __name__ == "__main__":
|
|
input_file = 'Montagem_Completa.AMF' # Substitua pelo caminho do seu arquivo AMF de entrada
|
|
output_file = 'montagem.obj' # Substitua pelo caminho do seu arquivo OBJ de saída
|
|
target_faces = 50000 # Número desejado de faces após a simplificação
|
|
|
|
main(input_file, output_file, target_faces)
|