Geometry Nodes: Add a minimum distance attribute to the Attribute Proximity Node
Currently, the Attribute Proximity node finds the closest point in the target geometry. This patch adds an attribute input (or a slider) for a minimum distance, so for example instead of the closest point, the closest point that is at least 5 meters away could be found.
To do this, a member min_dist_sq has been added to the BVHTreeNearest struct. The function BLI_bvhtree_find_nearest_ex has been amended to make use of this. For simplicity, this behavior has only been added to dfs_find_nearest and not to heap_find_nearest, because the latter is only being used in certain situations by the shrinkwrap modifier. To clarify this, the flag parameter has been amended into an enum with either the option BVH_NEAREST_OPTIMAL_ORDER and the new option BVH_USE_MIN_DISTANCE.
Most of the implementation of the attribute / float input part on the Attribute Proximity node itself, including the required RNA and DNA has been adapted from the math node.
Here are some examples:
This could for example be used in mograph scenarios:
In this example, without the minimum distance, the closest attachment point each cable finds, is the attachment point from which it itself started (so the distance is 0m). With the minimum distance, we can force each cable to pick a target that is not on the same pole!
Caveats: Currently, the minimum distance works by repeatedly discarding the nearest point that the depth first search on the BVH tree found, until the point is outside (or on >=) the minimum distance. This means that the higher the minimum distance is (the closer points are being skipped), the more calculations are being made.
For a minimum distance of 0 (i.e. how it was before) or every distance that leads to no skipping of points the performance penalty by this patch should be rather small and is constant time.
In the future the search could be optimized by utilizing the BVH, but as of right now I don't understand the kDOPs not enough to pull that off.