warp.bvh_query_aabb#
- warp.bvh_query_aabb( ) BvhQuery#
Kernel
Construct an axis-aligned bounding box (AABB) query against a BVH.
Returns a query that iterates over every item in the BVH whose stored bounding box overlaps the query box
[low, high]. Advance the query and read each result withbvh_query_next().lowandhighare given in BVH space, i.e. the same coordinate space as thelowers/uppersarrays passed towarp.Bvh.To restrict traversal to a subtree, set
rootto that node’s index (for a grouped BVH the group root is obtained frombvh_get_group_root()). Ifrootis -1 (default), traversal starts at the BVH’s global root.- Parameters:
id – The BVH identifier
low – The lower bound of the query box, in BVH space
high – The upper bound of the query box, in BVH space
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(), which writes the index of each overlapping item (an index into the arrays passed towarp.Bvh) to itsindexargument.
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]]