warp.bvh\_query\_next ===================== .. function:: warp._src.lang.bvh_query_next(query: BvhQuery, index: int32, max_dist: float32) -> bool .. hlist:: :columns: 8 * Kernel Advance a BVH query to the next overlapping item and report whether one was found. Writes the index of the current item to ``index`` and returns ``True``; returns ``False`` once the query is exhausted (``index`` is then left unchanged). The reported index is the item's index into the ``lowers``/``uppers`` arrays passed to :class:`warp.Bvh`. Used in a ``while`` loop together with :func:`bvh_query_aabb` or :func:`bvh_query_ray`. For ray queries, ``max_dist`` bounds how far along the ray to look for intersections, measured in multiples of the ray direction's length (so it is a distance only if ``dir`` was normalized). It has no effect on AABB queries. Note that increasing ``max_dist`` may miss intersections: a subtree already rejected for being beyond ``max_dist`` is never revisited, even if a later, larger ``max_dist`` would reach it. It is therefore only safe to monotonically *reduce* ``max_dist`` during a query. :param query: The query to advance, from :func:`bvh_query_aabb` or :func:`bvh_query_ray` :param index: Output; receives the index of the current overlapping item :param 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: ``True`` if another overlapping item was found (its index written to ``index``), ``False`` if the query is exhausted. .. rubric:: Example .. testcode:: @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()) .. testoutput:: [[0.5, 0.5, 0.5], [2.5, 0.5, 0.5], [0.0, 0.0, 0.0]]