hawk.geometry#
A bounding-volume hierarchy over triangles, and the closest hit of a ray against it.
build_bvh() builds the tree on the host (NumPy, median split on the longest
axis of the centroids) into flat tables. closest_hit() is the traversal as
a kernel helper: a stack of node indices in a vector, the box test
(hawk.math.ray_aabb()) against the nearest hit so far, and the triangle test
(hawk.math.ray_tri()) on each leaf, so it runs on the host and the device
alike and nothing in it is a library call. The value is correct, not tuned.
A kernel declares the tables as planes and gets the tree’s static facts from the host object:
bvh = build_bvh(triangles) # (n, 3, 3) vertices
@hawk.kernel
def shadow(o: Vector[3], d: Vector[3], tmax: Scalar, y: Mutable[Vector[5]],
lo: Table[Scalar], hi: Table[Scalar], left: Table[Index],
right: Table[Index], first: Table[Index], size: Table[Index],
tri: Table[Scalar]):
y = closest_hit(bvh.tables(lo, hi, left, right, first, size, tri), o, d, tmax)
bvh.planes() gives the arrays to bind, under the same names. The result is
[hit, t, u, v, leaf_position]; bvh.order[leaf_position] is the triangle’s
index in the input.
Module Attributes
The planes of a tree, in the order |
Functions
|
The tree over |
|
The nearest hit of the ray |
Classes