We recommend reading Core Concepts prior to this document to gain an understanding of the approach our geometry kernel takes to representing implicit shapes.
The Metafold geometry kernel represents shapes using signed distance fields (SDFs). Many shape editing operations (e.g. CSG, shelling, etc.) rely on the SDF giving exact distances to the surface of the shape in order to produce accurate results.
Many of our implicit shape functions produce anything but exact SDFs. Primitive shapes, surface lattices, and other shapes supported by our geometry kernel, are all conveniently represented by a variety of simple implicit functions and pseudo-SDFs. It is possible to compute an exact SDF from any of these functions by redistancing the resulting sample values. You can do this in a Metafold shape function using the Redistance operator. The result of applying the operator is a grid of exact distances to the surface of the shape!
Some shapes, like the gyroid, are especially hard to reason about without redistancing applied. Take the shapes below for example:
Modeling a gyroid with constant thickness wall (material) is notoriously difficult to do correctly. The gyroid function is what we refer to as an “indicator” function: it is negative on one side of the surface, positive on the other side, and zero at the surface. It has no other guarantees otherwise, at best it gives us an indication of where the gyroid surface is, but only the sign of the values is helpful to us.
Shelling a gyroid as-is will give us a wall of “some thickness”, but:
- the units are not real—0.15 in gyroid space ≠ 0.15 mm in terms of real world units; and
- if you were to measure the thickness along the entire shape you would find that it varies by some amount, i.e. the wall is not of constant thickness.
If we first redistance the gyroid, then shell it, all of these problems go away: we get a wall with constant thickness at exactly the thickness we asked for. Note that visualizing the cross section of some material that isn’t perpendicular to the cross section plane will give the illusion that the wall is not of constant thickness, but rest assured this is expected. If you were to measure the thickness along the entire shape you would find that it is in fact constant!
We could adjust the non-redistanced version of the shelled gyroid to visually match the redistanced version, but the same issues remain: the shell thickness is not in tangible units, and the resulting wall is varied.
Note that some filter operations may also produce pseudo-SDFs, so appending the Redistance operator to the very end of your shape function is generally recommended to ensure the final result is exact.
- While our redistancing algorithm is incredibly fast, it still incurs a small overhead per-application of the Redistance operator. The overhead is usually negligible, but it becomes noticeable when there are many Redistance operators in a single graph, or if the resolution is relatively high. Having control over where redistancing happens allows the designer of the shape function to better balance the tradeoffs between performance and accuracy. Not all operations demand exact distances, so redistancing only when required can help reduce computation time.
- Although excluding the Redistance operator may technically produce inaccurate results, there are some cases where the “look” of the shape is more important than the correctness of the operations. We would still recommend appending a Redistance to the end of the shape function as downstream consumers of the shape volume may benefit from having exact distances (e.g. rendering, meshing, etc.)