-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobj_to_pcd.py
29 lines (22 loc) · 918 Bytes
/
obj_to_pcd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import open3d as o3d
from os import listdir
from os.path import isfile, isdir, join
import numpy as np
input_path = "./input_obj"
output_path = "./output_pcd"
files = listdir(input_path)
for f in sorted(files):
fullpath = join(input_path, f)
if isfile(fullpath) and f.endswith(".obj"):
mesh = o3d.io.read_triangle_mesh(fullpath)
mesh.remove_duplicated_vertices()
mesh.remove_duplicated_triangles()
filename = f.split(".")[0]
pcd = o3d.geometry.PointCloud()
pcd.points = mesh.vertices
pcd.colors = mesh.vertex_colors
pcd.normals = mesh.vertex_normals
# R = pcd.get_rotation_matrix_from_xyz((0, np.pi / 2, 0))
# pcd.rotate(R, center=(0, 0, 0))
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) # flip upside down along y axis
o3d.io.write_point_cloud(output_path + "/" + filename + ".pcd", pcd, write_ascii=True)