UAV/tools/merge_obj.py

35 lines
854 B
Python
Raw Normal View History

2024-12-29 12:03:53 +08:00
import open3d as o3d
import numpy as np
# 读取 .obj 文件
def load_obj(file_path):
mesh = o3d.io.read_triangle_mesh(file_path)
if not mesh.is_empty():
return mesh
else:
raise ValueError(f"Failed to load {file_path}")
# 合并两个网格
def merge_meshes(mesh1, mesh2):
# 直接合并网格
combined_mesh = mesh1 + mesh2
return combined_mesh
# 保存合并后的网格
def save_merged_mesh(mesh, output_path):
o3d.io.write_triangle_mesh(output_path, mesh)
print(f"Saved merged mesh to {output_path}")
# 示例用法
mesh1 = load_obj("model1.obj")
mesh2 = load_obj("model2.obj")
# 合并两个网格
merged_mesh = merge_meshes(mesh1, mesh2)
# 保存合并后的网格
save_merged_mesh(merged_mesh, "merged_model.obj")
# 可视化合并后的网格
o3d.visualization.draw_geometries([merged_mesh])