Convert ObjMesh to pymeshlab’s mesh class to apply meshlab filters.
In this notebook, we define functions to convert our ObjMesh class to and from pymeshlab.
convert_to_pymeshlab
def convert_to_pymeshlab( mesh:ObjMesh, add_texture_info:NoneType=None, # Whether to add texture info to the pymeshlab.Mesh. If None, texture is added ifavailable for at least one vertex.)->Mesh:
Convert tcmesh.ObjMesh to pymeshlab.Mesh.
See https://pymeshlab.readthedocs.io/en/latest/classes/mesh.html Note: normal information is recalculated by pymeshlab. Discards any non-triangle faces.
The texture information is saved as a vertex attribute via v_tex_coords_matrix. Note that this discards information since a vertex can have multiple texture coordinates. For this reason, we also save it as wedge_tex_coord_matrix (i.e. per triangle).
def convert_from_pymeshlab( mesh:Mesh, reconstruct_texture_from_faces:bool=True, # Whether to reconstruct texture information from per-face data (True), orper-vertex data (False) texture_vertex_decimals:int=10, # Texture vertices are rounded to texture_vertex_decimals decimals.)->ObjMesh:
Convert pymeshlab mesh to ObjMesh.
Texture vertices can be reconstructed from wedge_tex_coord_matrix (per face) or from the vertex attribute vertex_tex_coord_matrix. Reconstruction from face texture can accommodate multiple texture coordinates per vertex (e.g. for UV maps with seams).
Warning: readOBJ() ignored non-comment line 4:
o Drosophila_CAAX-mCherry_mesh_remeshed
Warning: readOBJ() ignored non-comment line 48073:
l 2534 8160
/tmp/ipykernel_1942205/15752383.py:16: RuntimeWarning: invalid value encountered in divide
normals = (normals.T / np.linalg.norm(normals, axis=-1)).T