cnr-isti-vclab / PyMeshLab

The open source mesh processing python library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

suggestion: change error to a warning in boolean operations

XuliaDS opened this issue · comments

Hi:
Every time two meshes have empty intersection or one mesh is inside the other, pymeshlab raises an exception: "vertex matrix is empty", killing the program.
In my opinion, the error is too harsh... It should raise a warning saying "empty intersection", etc. and create an empty mesh. For some usage, one may want to compare two meshes to see their relative position, etc. rather than actually using the resulting boolean mesh.
I did a dirty wrap around my boolean call:

try:
    ms.generate_boolean_difference(first_mesh=obj1, second_mesh=obj2, transfer_face_quality=transfer)
except:
    msg=f" Object {obj1} is completely inside of object {obj2}. Boolean difference is empty "
    logging.warning(msg)
    return -1

and similarly for the intersection

try:
    ms.generate_boolean_intersection(first_mesh=obj1, second_mesh=obj2, transfer_face_quality=transfer)
except:
    msg = f" Object {obj1} does not intersect with object {obj2}. Boolean intersection is empty "
    logging.warning(msg)
    return -1

In my case, I have a dictionary with names associated with meshes ID: eg. obj["cube"] = 1. so then know that when I get obj["m1_vs_m2"] = my_boolean(obj[m1], obj[m2], "DIFFERENCE")
obj["m1_vs_m2"] == -1,
it was an empty operation but the algotirhm doesn't end there.

Probably there are better fixes... Or maybe nobody finds this useful...

Cheers,