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(),bvh_query_ray(),bvh_query_capsule(), orbvh_query_sphere().For plain ray queries (
bvh_query_ray()),max_distbounds how far along the ray to look for intersections, measured in multiples ofdir’s length (so it is a distance only ifdirwas normalized). For capsule queries (bvh_query_capsule()), passdir = p1 - p0(unnormalized) together withmax_dist = 1.0to sweep fromp0top1.max_disthas no effect on AABB or sphere 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(),bvh_query_ray(),bvh_query_capsule(), orbvh_query_sphere()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 or sphere 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]]
- warp.bvh_query_next( ) bool
Kernel
Advance a
bvh_query_ray()query to the next intersected item.
- warp.bvh_query_next( ) bool
Kernel
Advance a
bvh_query_capsule()query to the next intersected item.
- warp.bvh_query_next( ) bool
Kernel
Advance a
bvh_query_sphere()query to the next intersected item.