Header only mesh voxelizer in c99; Karim Naaji (2016).
npm install voxelizer.csh
$ npm i voxelizer.c
`
And then include voxelizer.h as follows:
`c
// main.c
#define VOXELIZER_IMPLEMENTATION
#include
int main() { / ... / }
`
Finally, compile while adding the path node_modules/voxelizer.c to your compiler's include paths.
`bash
$ clang -I./node_modules/voxelizer.c main.c # or, use gcc
$ gcc -I./node_modules/voxelizer.c main.c
`
You may also use a simpler approach with the cpoach tool, which automatically adds the necessary include paths of all the installed dependencies for your project.
`bash
$ cpoach clang main.c # or, use gcc
$ cpoach gcc main.c
`
Usage
To generate a voxelized mesh, create an instance of vx_mesh_t and initialize its
vertices and indices like this:
`c
vx_mesh_t* mesh;
vx_mesh_t* result;
mesh = vx_mesh_alloc(nvertices, nindices);
// Add vertices and indices from the original mesh you want to voxelize
// [...]
// Precision factor to reduce "holes" artifact
float precision = 0.01;
// Run voxelization
result = vx_voxelize(mesh, 0.025, 0.025, 0.025, precision);
vx_mesh_free(result);
vx_mesh_free(mesh);
``