Skip to content

A BVH over the surfaces' boxes for raycast, locate and closest - #37

Merged
fmrico merged 1 commit into
rollingfrom
surface_bvh
Oct 17, 2026
Merged

fmrico merged 1 commit into
rollingfrom
surface_bvh

Conversation

@fmrico

@fmrico fmrico commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Raycast, locate without a hint and closest went through every surface of the map, testing its box before descending into its own BVH. Maps built from point clouds of terrain have thousands of small surfaces, and that loop dominated the cost.

  • rebuild_geometry_accels() now also builds a BVH over the surfaces' boxes.
  • Raycasts (and locate without a hint, which casts vertical rays) visit only the surfaces whose boxes the ray enters.
  • closest_navcel() visits the nearest boxes first and prunes those farther than the best so far.
  • If surfaces are added without a rebuild, the queries go through every surface, as before.

One thread, simulated excavation at 0.2 m (746 k NavCels, about 5 000 surfaces):

Before After
Locate without a hint 18.3 µs 4.3 µs
Raycast 16.9 µs 2.5 µs
Update from a 8.7 k-point scan (mark and clear) 85 ms 23 ms

On a three-floor garage (124 k NavCels, few surfaces) nothing changes beyond noise.

Five new tests check raycast, closest and locate against brute force over every NavCel on 600 overlapping surfaces, and cover surfaces added without a rebuild, empty maps and single-surface maps.

Raycast, locate without a hint and closest went through every surface,
testing its box before descending into its own BVH; maps of terrain
built from point clouds have thousands of small surfaces, and that loop
dominated the cost.

rebuild_geometry_accels() now also builds a BVH over the surfaces'
boxes: raycasts visit only the surfaces whose boxes the ray enters, and
closest_navcel() visits the nearest boxes first, pruning the farther
ones. Surfaces added without a rebuild fall back to the linear loop.

Signed-off-by: Francisco Martín Rico <fmrico@gmail.com>
@fmrico
fmrico merged commit 48c97e6 into rolling Oct 17, 2026
1 of 2 checks passed
@fmrico
fmrico deleted the surface_bvh branch October 17, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant