Search code examples
computational-geometry

Voxelize a Polygon Mesh


I've implemented Marching Cube and Marching Tetrahedron algorithms to convert a voxel grid into a polygon mesh. Now I'm interested in doing the opposite, taking a polygon mesh and approximating it in a voxel grid.

I'm currently just working out my approach and curious if anyone has any guidelines. I can find the list of triangles that intersect any voxel cube fairly easily, but how do you convert the triangles into values held by the voxel vertices?

Steps

  1. Determine which cubes are inside, outside, and on the border. Border is easy to determine, since if the a cube contains any triangles it is on the border.

  2. From there I imagine I need to follow the triangle normals and project along the voxel grid to determine inside/outside. Mark all vertices that are completely surrounded by inside as 1 and all surrounded by outside as -1.

  3. ?? This is the part i'm confused about. I need to take the triangles and somehow interpolate their values into vertex values. My guess is I need to find all points of the triangle that collide with the AABB of the voxel subunit or inside it and project it onto all subunit axes. From there I need to take those accumulated positions and figure out what the values should be based by setting the values between [-1,1] such that interpolation would most closely approximate the hull within the boundary unit. <--- this part is what i don't 100% understand.


Solution

  • If I understand correctly, the values you should associate to the voxel corners are signed distances to the surface (positive outside, negative inside), so that the surface itself is at level zero.

    If a voxel is cut by a single triangle, you can just assign the distance to the plane of the triangle. If there are several triangles that cross, the situation is more complex. You might consider the orthogonal projections of the corners onto the triangles and see to which triangle they belong.