MeshToSDF icon indicating copy to clipboard operation
MeshToSDF copied to clipboard

Make the SDF filled

Open danielzeller opened this issue 5 years ago • 3 comments

Hey, great example :) I'm trying to use this for realtime collision detection for a SkinneMesh. The SDF being hollow thing is making that a bit tricky. Is there any way to make the SDF filled so the distance goes from 1 to -1? Cheers Daniel

danielzeller avatar Nov 19 '20 19:11 danielzeller

Hey, I'd also love to find a way to make the SDF solid. Any pointers about how to solve the problem would be appreciated. Thanks!

highlyinteractive avatar Apr 13 '21 10:04 highlyinteractive

So currently the way the algorithm works is by writing a binary mask + coordinate into a voxel grid where each triangle intersects with our grid (aka an approximate voxel shell of the mesh), and then flood-filling this to get the distance field. To make it "solid", this could be extended in a few ways, with various tradeoffs and problems for different geometries. Also note that you'll have to ensure the geometry is manifold to get any meaningful result, otherwise it'll be like using a paintbucket tool without making sure the lines are joined...

  1. Instead of writing binary mask write a trinary one, having each triangle write inside for the grid cells on the frontface and outside for the grid cells on the backface. The floodfill will then fill the inside with the label written by the backfaces. The problems with this is that projecting the coords of the triangle "forward"/"backward" when you have non-ideal geometry could cause the inside to end up outside. You will also have to modify the mask writing to ensure that the voxel shell represented by the mask is fully closed
  2. Compute mask as normal. Write a single point that you a-priory know is on the inside (or outside). Then run one floodfill floodfilling this point into the inside (or outside). This has the problem of first getting a point you know is inside or outside (but for skinned models, this could be fine). The larger problem is ensuring you don't have paintbucket-tool-without-closed-lines effect happening due to the voxel shell having holes. Perhaps that can be fixed by a pass that dilates or erodes it

aman-tiwari avatar Apr 26 '21 01:04 aman-tiwari

This reminded me, at the very end of this blog post about JFA the author says:

"He (Demofox) also has a post on doing SDF with a bit more detail. The only thing I would add to his description is that you do not need to run the JFA twice in order to generate the signed aspect. When computing the final distance you just check the original mask again and multiply the distance by -1 when inside the mask before you bias scale into the 0 to 1 range. I never saw any problem doing that."

I've been meaning to try this with MeshToSDF but haven't gotten around to it. Does it make sense to you @aman-tiwari ? Is it worth investigating?

Thanks.

ShiftedClock avatar Apr 26 '21 07:04 ShiftedClock