0

I'm trying to process a batch of STL files through pymeshlab. I'm using two filters, i.e., "remeshing_isotropic_explicit_remeshing" and "mls_projection_apss". The problem arise with filter "mls_projection_apss" which by default uses mesh id = 0 for both control and proxy mesh, resulting in algorithm always using the mesh with id 0 for all future iterations.

Please help me with how to define that ID of current mesh in the meshset is used as control and proxy mesh instead of default "0".

Current code:

for filename in os.listdir(inputdir):
    if filename.endswith(".stl"):
        ms.load_new_mesh (os.path.join(inputdir, filename))
        print(os.path.join(filename))
        ms.current_mesh_id()
        print(ms.current_mesh_id())
        ms.remeshing_isotropic_explicit_remeshing(targetlen=0.1, checksurfdist=True, maxsurfdist=0.1)
        ms.mls_projection_apss(controlmesh=, proxymesh=, filterscale=2)
        ms.save_current_mesh(os.path.join(outputdir_2, filename))
  • Maybe some more clarification... The filter works fine with default setting, i.e. "ms.mls_projection_apss" without any parameters. However, when I enter "filterscale" parameter the algorithm saves only the first mesh in batch with correct filename. Filter scale is an important parameter in my case. – justone Oct 08 '21 at 11:36

1 Answers1

0

This is working for me, but I'm not sure if it is what you want. One problem that I have detected is that ms.mls_projection_apss() seems to change current_mesh to 0, so ms.save_current_mesh() is saving the original mesh and not the result of the MLS filter.

import pymeshlab as ml
ms = ml.MeshSet()

for filename in os.listdir(inputdir):
    if filename.endswith(".stl"):
        ms.load_new_mesh (os.path.join(inputdir, filename))
        m = ms.current_mesh()
        print(os.path.join(filename), ms.current_mesh_id(), m.vertex_number(), 'vertex', m.face_number(), 'faces' )

        ms.remeshing_isotropic_explicit_remeshing(targetlen=0.1, checksurfdist=True, maxsurfdist=0.1)

        #Get the id of the last mesh in the set
        last_id = ms.number_meshes()-1
        ms.mls_projection_apss(controlmesh=last_id, proxymesh=last_id, filterscale=2)

        #Ensure we select last mesh before saving result
        ms.set_current_mesh(ms.number_meshes()-1)
        m = ms.current_mesh()
        print("Saving", os.path.join(outputdir_2, filename), m.vertex_number(), 'vertex', m.face_number(), 'faces' )
        ms.save_current_mesh(os.path.join(outputdir_2, filename))
Rockcat
  • 3,002
  • 2
  • 14
  • 28