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.
Methods ¶
__init__()
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)
→ int
Determines the intersection point of a ray with the geometry in this object.
Note
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.
ray_origin
A hou.Vector3 object representing the starting point of the ray in world space.
ray_direction
A hou.Vector3 object representing the direction vector of the ray.
position_out
Pass a hou.Vector3 object to this argument. The method will change the object’s values to represent the intersection position in world space.
normal_out
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.
uvw_out
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.
min_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
max_hit
Ignore intersections farther than this distance.
tolerance
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.
findAllInTube(line_origin, line_direction, radius, min_hit=0, max_hit=1E18, tolerance=5E-3)
→ tuple
of hou.Point
Return a tuple of all the points in the geometry inside the tube given by the line and radius.
ray_origin
A hou.Vector3 object representing the starting point of the line in world space.
ray_direction
A hou.Vector3 object representing the direction vector of the line.
radius
Find points within this distance of the line.
min_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.
max_hit
Ignore intersections farther than this distance.
tolerance
Use this parameter to adjust the accuracy of intersections. A 5E-3 tolerance (default) gives strict intersections while larger values produces less accurate intersections.