HamiltonJacobi equation and surface propagation
In the previous post I mentioned level set method can be used for offset surface. In this post I will use IPython to prototype the general idea.
Overview
The main issue of current Blender Solidify modifier is self intersection. It works well for most cases, however, self intersection happens when we offset too much into the shape.
We may expect the geometry could “merge” at the self intersected places. The level set method is good at handling this kind of topology change.
The problem modeling is based on J. A. Sethian’s book^{1}. We first build a signed distance field() for the geometry. And then solve HamiltonJacobi equation to propagate the zero level of surface along the normal direction(the gradient) with a normal speed().
Since our geometry is represented in distance field implicitly, the topology change(i.e. merging or melding of surfaces) is handled for free.
Implementation
The complete source can be found here
I use numpy, matplotlib, and numba(for performance):
We first build a meshgrid to place the distance field of geometry.
Then we fill the meshgrid with distance field. In my test case I use two touching spheres. The distance field can be computed analytically for spheres. In practice we may traverse all polygons to calculate it for geometry represented in mesh.
Next we convect the distance field according to the HamiltonJacobi equation:
Note that for simplicity I use central differencing for spatial derivatives, and do not pay much attention on CFL condition. In a real world implementation some advanced scheme(e.g. upwind or other ones derived from conservation law) has to be used. And some numerical issues should be carefully handled. For now I just want to illustrate the general ideas.
We show the experiment results below. The first one contains no topology change. This happens when we do not offset the surface too much.
The next one has topology change. We can see that the offset surface breaks into two pieces.
Notes
We have to perform a meshtodistancefield operation in order to use level set method, and also a distancefieldtomesh operation (e.g. dual contouring, marching cube, etc) in order to represent the offset surface in Blender mesh data structure.
The contouring method should be handled very carefully or nonmanifold geometry would be introduced into our mesh.
References

Sethian, James Albert. Level set methods and fast marching methods: evolving interfaces in computational geometry, fluid mechanics, computer vision, and materials science. Vol. 3. Cambridge university press, 1999. ↩