warp.bvh_query_sphere#
- warp.bvh_query_sphere( ) _BvhQuerySphere#
Kernel
Construct a sphere query against a BVH object.
Iterates over all items whose bounding box overlaps the sphere (exact sphere-AABB squared-distance test). Tangential contact (the nearest point on the AABB surface exactly on the sphere) is included. A negative
radiusis clamped to zero. This is a tighter broad-phase than padding a query AABB by the radius, since the sphere is inscribed in the padded box. Advance withbvh_query_next().- Parameters:
id – The BVH identifier
center – The center of the sphere in BVH space
radius – The radius of the sphere; negative values are clamped to zero
root – The node to begin the query from, or -1 (default) for the BVH’s global root
- Returns:
A
warp.BvhQuery. It is opaque; pass it tobvh_query_next().
Example
@wp.kernel def find_items_in_sphere(bvh_id: wp.uint64, center: wp.vec3, radius: float, hits: wp.array[wp.int32]): query = wp.bvh_query_sphere(bvh_id, center, radius) item = int(0) while wp.bvh_query_next(query, item): hits[item] = wp.int32(1) lowers = wp.array([[0, 0, 0], [2, 0, 0]], dtype=wp.vec3) uppers = wp.array([[1, 1, 1], [3, 1, 1]], dtype=wp.vec3) bvh = wp.Bvh(lowers=lowers, uppers=uppers) hits = wp.zeros(2, dtype=wp.int32) wp.launch(find_items_in_sphere, dim=1, inputs=[bvh.id, wp.vec3(0.5, 0.5, 0.5), 0.6, hits]) print(hits.numpy().tolist())
[1, 0]