Rasterization
Dense rasterization
This will result in a dense occupancy grid where each voxel is classified as Inside, Outside, or Boundary.
// Flood fill classifies interior; requires a closed mesh
DenseRasterizer.RasterizeMesh(oGrid, mesh, floodFill: true);
oGridwill be mutated.floodFillis optional and defaults tofalse. It is recommended to set it totrueif the mesh is closed (watertight) to correctly identify interior voxels. This is a post-processing step that fills in the interior of the mesh after rasterization.
Sparse rasterization
This will only return a list of voxel origins that are classified as Boundary.
List<Vector3> origins = SparseRasterizer.RasterizeMesh(Mesh, size);
Polyline Rasterization
The library supports voxelizing polylines into a 3D grid. This is useful for applications like pathfinding, spatial analysis, or visualizing line-based geometries in a voxel representation.
Example: Voxelizing a Polyline
PolylineF polyline = new(new Vector3[] {
new(0, 0, 0),
new(1, 2, 1),
new(2, 0, 2),
new(3, 3, 3)
});
// sparse voxelization with a voxel size of 0.1 in all dimensions
List<Vector3> origins = SparseVoxelization.RasterizePolyline(polyline, new Vector3(0.1f, 0.1f, 0.1f));
// dense voxelization into an occupancy grid
OccupancyGrid oGrid = new(
voxelSize: new Vector3(0.1f, 0.1f, 0.1f),
bounds: polyline.GetBounds()
);
DenseVoxelization.RasterizePolyline(oGrid, polyline);