0

I wrote a little script, that has the task of loading a mesh (ply), then to apply some filters and finally export the whole thing back as a ply.

So far so good. But the resulting ply-file comes out unreadable. If I try to open it in MeshLab, it says: "Face with more than 3 vertices"

here is the code part that concerns pymeshlab (cleaned):

import pymeshlab as ml
ms = ml.MeshSet()
ms.load_new_mesh(path + mesh_name)
ms.apply_filter('convert_pervertex_uv_into_perwedge_uv')
ms.apply_filter('transfer_color_texture_to_vertex')
ms.save_current_mesh(path + 'AutomatedGeneration3.ply')

Did I miss something? There is actually no error message in executing this script. I also tried to use some parameters for the saving filter but it hadn't changed anything.

How do I get it right?

Rockcat
  • 3,002
  • 2
  • 14
  • 28
Coder1234
  • 65
  • 1
  • 4
  • Can you add the line "ms.set_versbosity(True)" to the beginning of the script to see if meshlab write some error? – Rockcat Jan 22 '21 at 19:05
  • He says he is missing the texture of the ply-file. The texture exists in the same directory as the ply and my script copies it into the meshlab directory as well (that's where ML searches it when I do it by hand) – Coder1234 Jan 25 '21 at 07:33
  • 1
    okay, I changed the the parameters of save_current_mesh() from 'binary=True' to 'binary=False' and now it produces the correct mesh. – Coder1234 Jan 25 '21 at 08:08

1 Answers1

0

This seems to be a bug in the .ply exporter used internally in the method ms.save_current_mesh().

The method is trying to save all the information stored in the mesh, which at this point is texture_per_vertex, texture_per_wedge and color_per_vertex, and something is going wrong there.

I have managed a workaround by disabling save the texture_per_wedge (which is necessary just for transfer_color_texture_to_vertex filter.

import pymeshlab as ml
ms = ml.MeshSet()
#Load a mesh with texture per wedge
ms.load_new_mesh('input_pervertex_uv.ply')
m = ms.current_mesh()

print("Input mesh has", m.vertex_number(), 'vertex and', m.face_number(), 'faces' )

ms.apply_filter('convert_pervertex_uv_into_perwedge_uv')
ms.apply_filter('transfer_color_texture_to_vertex')

#Export mesh with color_per_vertex but without texture
ms.save_current_mesh('output.ply',save_wedge_texcoord=False,save_vertex_coord=False )

The list of valid arguments for save_current_mesh can be read here https://pymeshlab.readthedocs.io/en/latest/filter_list.html#save-parameters

Please note that save_vertex_coord refers to Texture coordinates per vertex!!!

Rockcat
  • 3,002
  • 2
  • 14
  • 28