Mesh Voxelization

Yesterday I stumbled upon a tweet about a header only mesh voxelizer library in C. This library creates a voxelized mesh from a triangular mesh. It’s really simple to use and I decided to add it to GeeXLab (in v0.12.0.0).

This voxelization library does not perform deep voxelization (voxels inside of the mesh), only shell voxelization. But for voxel art, shell voxelization is enough.

The voxelized mesh has lot of vertices / faces compared to the original mesh. The number of vertices / faces depend on the number of vertices / faces of the input mesh as well as the voxel size. Here are some values for an input mesh with 441 vertices and 800 faces (the torus mesh has a radius of 20 unities):
– voxel size: 0.75 unity – vertices=61312, faces=91968
– voxel size: 0.5 unity – vertices=144968, faces=217452

With the bunny mesh (2503 vertices and 4968 faces), the voxelized mesh has 53720 vertices and 80580 faces for a voxel size of 0.2.

voxel size: 0.2

voxel size: 0.1voxel size: 0.1

Because I was playing with voxelization, I took some time to code and test a very simple geometry shader-based voxelizer: each triangle is converted into a point and from this point, the geometry shader generates a cube made up of 6 faces (4 vertices per face).

That works but the previous voxelizer library gives better results.

All GeeXLab demos related to this article are available in the code sample pack in the gl-32/voxelize/ folder. GeeXLab 0.12.0+ is required.

For those interested, here is the complete GLSL code for the geometry shader based voxelizer as you can find it in GeeXLab demos (demo03.xml and demo04.xml):