Share

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.

Getting the colors at the closest locations of a mesh

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:

  1. Add a get_closest_locations node to the graph.

  2. Connect the object with the data values that you want into the geometry input.

  3. Connect the positions for which you want the closest locations into the positions input. For many typical effects, these are often the point_position values of another geometric object.

  4. Set use_cutoff_distance and cutoff_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 the found array is false. In addition, the corresponding element of the output locations 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.
  5. 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 more sample_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 the get_closest_locations node.
    • You can use the found output with if 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).

Sampling colors and positions at closest locations in the graph

Was this information helpful?