Reputation: 3267
I made a Python script to create a .ply file using the image and the cloud of points of a scan 3D, stored as a NumPy array.
I can open the resulting file.ply in MeshLab. It works well.
But when I import it in Blender, there is no point. The resulting object is empty.
Do you have an idea on how to solve that?
Thanks
def row_col_xyz_to_ply(self, xyz, rgb, name="output"):
"""Convers a numpy (row, col, xyz) cloud of points to ply format
Parameters:
xyz (NDArray): 3D points for each image pixel (row, col, (x,y,z))
rbg (NDArray): RGBA values for each image pixel (row, col, (r,g,b,a))
Returns:
None: save the .ply file on the disk instead
"""
# reshape
# Extract the coordinates of the points where there is actual values (not NaN) in the xyz cloud of points
points_rows, points_cols = np.where(~np.isnan(xyz[:,:,0]))
# Grab the corresponding points in the xyz cloud of points in an array
points_xyz = xyz[points_rows,points_cols,:] # n*3 array of 3D points (after nan filtering)
# Grab the corresponding points in the image in an array
points_image = rgb[points_rows,points_cols,0:3] # n*3 array of RGB points (after nan filtering)
# Create a dict of data
data = {
'x': points_xyz[:,0],
'y': points_xyz[:,1],
'z': points_xyz[:,2],
'red': points_image[:,0],
'green': points_image[:,1],
'blue': points_image[:,2]
}
# Convert it to a cloud of points
cloud = PyntCloud(pd.DataFrame(data=data))
# Path where to save it
filename = f"{name}.ply"
path = os.path.join(self.path_exports,filename)
# Save it
cloud.to_file(path)
# Debug
print("row_col_xyz_to_ply > saved: ",filename)
Upvotes: 2
Views: 1425
Reputation: 11
I ran into the same problem that Rockcat pointed out. I'm not sure if you're still looking for an answer but I found that this custom importer is a bit of a workaround. It imports every point as a vertex but doesn't need them to be connected
Upvotes: 1
Reputation: 3250
The problem is in the blender .ply importer. It doesn't support points that are not used by any triangle.
Upvotes: 1