3DLIRIOUS / MeshLabXML

Create and run MeshLab XML scripts with Python
GNU Lesser General Public License v2.1
202 stars 43 forks source link

delete faces by color #15

Closed danivelikova closed 5 years ago

danivelikova commented 5 years ago

Hi, I want to delete Faces by color, which works in Meshlab GUI. I select: Filters->Selection->Select Faces by Color with the following paramenters: image

Now I want to do that by using MeshLabXML. I've tried the following but it doesn't seem to work: mlx.select.face_function(mesh, function='(r0 == 40 and g0 == 144 and b0 == 215 and a0 == 255)') mlx.delete.selected(mesh) mesh.run_script()

How can I also set the variations from red, green, blue as seen in the image? I'll appreciate your help.

3DLIRIOUS commented 5 years ago

Please note that the functions use muparser syntax, not Python. See https://beltoforion.de/article.php?a=muparser&p=features&s=idDef1#idDef1 for a list of muparser operators and functions. For example, you need to use '&&' instead of 'and'. You can select a range of colors by judicious use of the '?:' if then else operator. Play with the function in the GUI until you figure it out, then put it in the script.

danivelikova commented 5 years ago

thank you so much! It worked out. That's the code I've used in case someone else faces the same problem:

mesh=mlx.FilterScript(file_in=file_in, file_out=file_out) mlx.remesh.surface_poisson_screened(mesh) mlx.layers.join(mesh)

mlx.select.face_function(mesh, function='(b0 >= 50 && g0 >= 10 && r0 <= 70)') mlx.delete.selected(mesh) mlx.delete.small_parts(mesh, ratio=0.2) mesh.run_script()

3DLIRIOUS commented 5 years ago

Excellent, so happy you got it to work!