I am trying to convert 3D models in STL format to point cloud using open3d. Previously, I loaded each model individually and it was generating the point could. But since I have around 200 3D models I can't do it individually so want to automate the process so that the code itself loads all the models and exports the point cloud as CSV file.
Since I couldn't find the source to automate this, I am transforming the general code used to load multiple CSV files from a folder. Below is the code I am currently using
import open3d as o3d
from glob import glob
import os
ndir=os.chdir(r"D:\3D Models\train")
file_extension = ".stl"
all_filenames = [i for i in glob(f"*{file_extension}")]
print(all_filenames)
len(all_filenames)
for i in all_filenames:
mesh = o3d.io.read_triangle_mesh("i")
pointcloud = mesh.sample_points_poisson_disk(5000)
[Open3D WARNING] Read geometry::TriangleMesh failed: unknown file extension.
I always get this error and don't know how to overcome it. Can someone please help?
You made a simple mistake during filenames creation.
Your path variable i
inside the quotes will be interpreted as single char.
for i in all_filenames:
mesh = o3d.io.read_triangle_mesh(i)
pointcloud = mesh.sample_points_poisson_disk(5000)