Query raycast intersections
Use the get_raycast_locations
node to return the locations of the first intersections of rays with a mesh. 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, rays are cast from the ball's point positions along their normals. If the rays hit the plane, the interpolated vertex colors are sampled.
To find the locations of raycast intersections and sample values from them:
Add a
get_raycast_locations
node to the graph.Connect the target object toward which you are casting rays into the
geometry
input.Connect the source positions from which the rays originate into the
positions
input.Connect the matching directions along which to cast each ray into the
directions
input.Specify the
proximity_method
:semi-line
shoots an infinite ray along the direction vector.line
shoots infinite rays along both the positive and negative direction vectors.segment
shoots a ray along the direction vector but only as far as the vector's length. This allows for different distances for each ray, unlikecutoff_distance
.
Set
use_cutoff_distance
andcutoff_distance
as desired. When used, only intersections that within the cutoff distance are returned. If you use a cutoff distance in addition to thesegment
method, the shorter distance is used for each ray individually.Set
min_distance
to a non-zero value if desired. This prevents returning locations that are too close to each position. It can be useful to avoid always returning the input position when casting rays from an object onto itself.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-ray 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