8

I have some vertices whose coordinates were stored as NumPy array.

xyz_np:

array([[  7,  53,  31],
       [ 61, 130, 116],
       [ 89,  65, 120],
       ...,
       [ 28,  72,  88],
       [ 77,  65,  82],
       [117,  90,  72]], dtype=int32)

I want to save these vertices as a point cloud file(such as .ply) and visualize it in Blender.

I don't have face information.

Ausrada404
  • 499
  • 1
  • 7
  • 17

1 Answers1

15

You can use Open3D to do this.

# Pass numpy array to Open3D.o3d.geometry.PointCloud and visualize
xyz = np.random.rand(100, 3)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz)
o3d.io.write_point_cloud("./data.ply", pcd)

You can also visualize the point cloud using Open3D.

o3d.visualization.draw_geometries([pcd])
Jing Zhao
  • 2,420
  • 18
  • 21
  • 1
    thanks this works for me. However, I would like to pass to o3d a vector that is not N,3 but N,4 since my pointcloud is a LiDAR-based pointcloud and it contains intensity. Do you know how can I do that? (I read this issue here but still did not get how to do it: https://github.com/isl-org/Open3D/issues/438) – desmond13 Feb 24 '22 at 08:26
  • You can use *numpy slicing*. If your numpy array `xyz` has more than three columns and you want to pass the first three columns only, just change the 4th line of the answer to `pcd.points = o3d.utility.Vector3dVector(xyz[:, :3])`. – J.P.S. Jul 10 '23 at 13:42