Search code examples
pythonvoxelpyvista

Stray Voxels after mesh Voxelization using Pyvista


I've been playing around with the Threejs BufferGeometry and Pyvista.

I was able to export it to Pyvista, the visualization of the mesh works just perfectly :

Normal Visualization

but I when I voxalize it, It gets some weird stray voxles all around the 3D Scene :

Voxelized Mesh

Did any one faced this kind of issues or knows to fix this kind of issue ?

Thank you in advance.

tried meshfix, connectivity and lowering the Pyvista Voxelization density value but It didn't change much.

EDIT :

The used code :

mesh = pv.read("test2.stl")

p.add_mesh(mesh, color="lightblue", opacity=0.5)

voxels = pv.voxelize(
    mesh.triangulate(), density=mesh.length / 300, check_surface=False
).connectivity()


p.add_mesh(voxels, color=True, show_edges=True, opacity=1)

p.enable_anti_aliasing("ssaa")
p.export_obj("voxeled.obj")
p.show()

Solution

  • These artifacts remind me of this PyVista issue. I found a workaround for (potentially some of these stray pixels) by triangulating the mesh before voxelization. We made triangulation before voxelization automatic, this was added for PyVista release 0.37.0, released November 2022.

    So if you're using a PyVista version older than 0.37.0, either manually triangulate your mesh with mesh.triangulate().voxelize(), or update your PyVista version. If you're already on a more recent version then the issue is unrelated.