Open gofmans opened 2 years ago
Can you share the one specific STL mesh that you see the issue with? Otherwise, it's tough for us to reproduce this.
Handling Trimesh
in pv.wrap
has some strong assumptions:
https://github.com/pyvista/pyvista/blob/b709dcee6b7ef0c6eb1341c491b9552cdb866044/pyvista/utilities/helpers.py#L973-L980
If Trimesh
can have anything other than triangle faces (triangle strips perhaps? any cell type not exposed through its .faces
attribute) we'd be missing out on those.
Thanks for your comments, I looked into the resulting mesh and came across a solution.
It seems like wrapping the mesh by pyvista results in a set of "open edges" that have to be removed before plotting with the silhouette parameter.
This could be done by using "clean" operation followed by "triangulate":
import trimesh
import pyvista as pv
# loading mesh with trimesh and wrapping with pv
trimesh_mesh = trimesh.load(problematic_case_path)
pv_wrapped = pv.wrap(trimesh_mesh)
# loading mesh using pv
pv_mesh = pv.read(problematic_case_path)
# this code crashes
pltr = pv.Plotter()
pltr.add_mesh(pv_wrapped,silhouette=True)
pltr.show()
# this is the solution
pltr = pv.Plotter()
clean_pv_wrapped = pv_wrapped.clean()
triangulated_clean_pv_wrapped = clean_pv_wrapped.triangulate()
pltr.add_mesh(triangulated_clean_pv_wrapped,silhouette=True)
pltr.show()
This way, after wrapping the trimesh object cleaning and triangulating, the resulting number of cells matches the one from the original pv mesh:
Any thoughts on why this works?
Describe the bug, what's wrong, and what you expected.
I encountered an error while trying to plot a mesh after loading it with Trimesh package and wrapping with pyvista . Oddly, when I plot the mesh without the "silhouette=True" parameter everything works just fine.
Moreover, I noticed a mismatch between the resulting number of faces after the "wrapping" by pyvista in comparison with native loading of the mesh directly with pyvista (see Screenshots section).
I found a similar problem in this discussion but the solution did not work for me: https://github.com/pyvista/pyvista/issues/966
This problem only happens to one specific STL object that I use, and for all other objects the number of faces is similar in both ways of loading, plus, I can plot them with silhouette==True without any issues....
Any help would be greatly appreciated :) Thanks for the awsome work so far!
Steps to reproduce the bug.
System Information.
Screenshots