When you use hou.Geometry.intersect(), the hou.Geometry will store an acceleration structure. This is reset if the geometry changes at all, however. A ray cache allows you to maintain an acceleration structure and re-use it if only the point positions change.
Return a new
GeometryRayCache. The same ray cache can be used
across multiple geometries and, where possible, it will cache the
acceleration structures for faster ray intersection.
intersect(ray_origin, ray_direction, position_out, normal_out, uvw_out, min_hit=0.01, max_hit=1E18, tolerance=0.01)
Determines the intersection point of a ray with the geometry in this object.
This method is unusual in that instead of returning multiple pieces of information about the intersection, it requires that you pass it objects which it modifies in-place with the information.
Returns the ID number of the hit primitive if the ray intersected the geometry, or
-1 if the ray did not hit.
A hou.Vector3 object representing the starting point of the ray in world space.
A hou.Vector3 object representing the direction vector of the ray.
Pass a hou.Vector3 object to this argument. The method will change the object’s values to represent the intersection position in world space.
Pass a hou.Vector3 object to this argument. The method will change the object’s values to represent the normal direction from the surface to the ray.
Pass a hou.Vector3 object to this argument. The method will change the object’s values to represent the UVW position within the intersecting primitive where the ray hit.
Ignore intersections closer than this distance.
You can use the
min_hit argument to iterate through all possible hits along the ray, by setting the
min_hit a tiny bit farther than the previous hit.
hit_positions =  prev_dist = 0.01 while geometry.intersect(origin, direction, position, normal, uvw, min_hit=prev_dist): # Make sure to store a *copy* of the position, not the object # that is being modified in each iteration of the loop hit_positions.append(hou.Vector3(position)) prev_dist = origin.distanceTo(position) + 0.01
Ignore intersections farther than this distance.
Use this parameter to adjust the accuracy of intersections. If the ray approaches the geometry within the tolerance value, an intersection hit is assumed. A 0.01 tolerance (default) gives strict intersections while larger values produces less accurate intersections.