Query the closest location on a geometry
Use the get_closest_locations
node to return the closest location of each input position on a mesh or strands object. You can then use the locations with the sample_property
node to sample the values of properties such as position, color, surface normal, and so on.
In the example above, the particles' positions are used to get the closest locations on the mesh, and the locations are used to sample the interpolated values of colors that are stored on the mesh's vertices. The positions of the locations are also sampled to create strands from the particles.
To find the closest locations on a geometric object and then sample values from them:
Add a
get_closest_locations
node to the graph.Connect the object with the data values that you want into the
geometry
input.Connect the positions for which you want the closest locations into the
positions
input. For many typical effects, these are often thepoint_position
values of another geometric object.Set
use_cutoff_distance
andcutoff_distance
as desired.- When using a cutoff distance, the query searches for locations only within a sphere of radius
cutoff_distance
centered on each position. If there is no location on the geometry within that sphere, the corresponding element of thefound
array is false. In addition, the corresponding element of the outputlocations
array is an invalid location that always returns the default value for any property that is sampled from it. - It is often a good idea to use a cutoff distance, even when it is not strictly necessary for controlling your effect. It can speed up execution because it limits the space that needs to be searched.
- When using a cutoff distance, the query searches for locations only within a sphere of radius
Use the outputs of the
get_closest_locations
node to sample the values of properties on the geometry:- You can connect the
locations
output into one or moresample_property
nodes to sample properties immediately (see Sample geo properties at locations). In these cases, you typically sample on the same geometry that is connected to theget_closest_locations
node. - You can use the
found
output withif
nodes to control what happens next in the graph on a per-position basis, including whether or not to sample properties. - If the input positions correspond to the points of another geometric object, you can store the outputs as geo properties on that object to use them elsewhere (see Getting and setting properties of geometric objects). You can also cache them and use them for future frames in a simulation (see Create custom simulations).
- You can connect the