Python implementation of BVH with surface area hierarchy (SAH).
- numpy
- libigl (optional, only used in
performance.py
to load mesh) - matplotlib (optional, only used in
performance.py
to plot curves)
Find the following snippet to build a BVH and accelerate ray-casting:
from BVH import Ray, buildBVH
## initialize ray
ray = Ray(origin, direction)
## initialize BVH with vertices and faces
bvh = buildBVH(V, F)
## find intersection
hit, t, idx = bvh.intersect(ray)
## find the face index if ray hits the mesh
if hit:
faceIdx = bvh.triangles[idx].faceIdx
To compare the performance between BVH and brute-force loop, simply run the performance.py
:
python performance.py