warp.bvh_query_next#
- warp.bvh_query_next( ) bool#
Kernel
Advance a BVH query to the next overlapping item and report whether one was found.
Writes the index of the current item to
indexand returnsTrue; returnsFalseonce the query is exhausted (indexis then left unchanged). The reported index is the item’s index into thelowers/uppersarrays passed towarp.Bvh. Used in awhileloop together withbvh_query_aabb()orbvh_query_ray().For ray queries,
max_distbounds how far along the ray to look for intersections, measured in multiples of the ray direction’s length (so it is a distance only ifdirwas normalized). It has no effect on AABB queries.Note that increasing
max_distmay miss intersections: a subtree already rejected for being beyondmax_distis never revisited, even if a later, largermax_distwould reach it. It is therefore only safe to monotonically reducemax_distduring a query.- Parameters:
query – The query to advance, from
bvh_query_aabb()orbvh_query_ray()index – Output; receives the index of the current overlapping item
max_dist – For ray queries, the maximum distance along the ray to check for intersections (in multiples of
dir’s length). Has no effect on AABB queries.
- Returns:
Trueif another overlapping item was found (its index written toindex),Falseif the query is exhausted.
Example
@wp.kernel def query_region(bvh_id: wp.uint64, lowers: wp.array[wp.vec3], uppers: wp.array[wp.vec3], lo: wp.vec3, hi: wp.vec3, centers: wp.array[wp.vec3]): query = wp.bvh_query_aabb(bvh_id, lo, hi) item = int(0) while wp.bvh_query_next(query, item): centers[item] = 0.5 * (lowers[item] + uppers[item]) lowers = wp.array([[0, 0, 0], [2, 0, 0], [4, 0, 0]], dtype=wp.vec3) uppers = wp.array([[1, 1, 1], [3, 1, 1], [5, 1, 1]], dtype=wp.vec3) bvh = wp.Bvh(lowers=lowers, uppers=uppers) centers = wp.zeros(3, dtype=wp.vec3) # center of each object whose box overlaps the region wp.launch(query_region, dim=1, inputs=[bvh.id, lowers, uppers, wp.vec3(0.5, 0.5, 0.5), wp.vec3(2.5, 0.5, 0.5)], outputs=[centers]) print(centers.numpy().tolist())
[[0.5, 0.5, 0.5], [2.5, 0.5, 0.5], [0.0, 0.0, 0.0]]