three-mesh-bvh
A bounding volume hierarchy for three.js geometries: fast raycasts, closest-point and shape queries and GPU-side traversal, with a web worker builder. The practical way to run geometric queries on meshes in the browser.
Also known as BVH, three-mesh-bvh, three-mesh-bvh (BVH for three.js)
In the family Geometry, meshing & signed distance fields, spatial acceleration
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Plugin | npm i three-mesh-bvh docs |
| Babylon.js 9.38.0 | Not applicable | three.js-specific library; not applicable to Babylon.js. |
| Godot 4.7 | Not applicable | three.js-specific library; not applicable to Godot. |
| Unity | Not applicable | three-mesh-bvh is a three.js library. |
| Unreal 5.7 | Not applicable | three.js-specific BVH library; not applicable to Unreal Engine. |
| Blender 5.2 | Not applicable | three.js library; not applicable to Blender. |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Triangles are recursively partitioned by a splitting strategy such as centre, average or surface-area heuristic until leaf buckets are small, storing bounds in flat typed arrays for cache-friendly traversal. Queries walk the tree and skip subtrees whose boxes miss: raycast, first-hit, closest point to a point, intersection with another geometry or shape, and bounds-tree-versus-bounds-tree tests. The library patches Mesh raycasting in three.js so existing code gets faster. It can build in a worker, serialise the tree, refit it for skinned or deformed geometry, and expose the data as textures for shaders to traverse, enabling GPU path tracing. It also supports geometry with indexed or non-indexed attributes.
When to choose it
Reach for it when
- raycasting against large meshes in three.js is slow
- picking and collisions on dense models lag
- need fast spatial queries for browser 3d
- mouse hover on high poly meshes drops the frame rate
Choose it for picking, painting, sculpt brushes, collision of characters against level geometry, signed-distance baking and path tracing in three.js. Prefer Manifold Mesh Booleans when you need to modify geometry, and a bespoke SDF Exact Euclidean Distance Transform grid for repeated inside/outside tests on a fixed mesh.
Field marks
- Build cost on very large meshes can stall the main thread without the worker path
- Deforming meshes need refit; heavy deformation degrades tree quality
- Memory overhead of tree buffers on top of geometry
- Inside/outside tests require closed meshes; open meshes give wrong parity
Crosses
- Isotropic Remeshing: Fast closest-point queries reproject remeshed vertices onto the source.
- Exact Euclidean Distance Transform: Bake a distance volume from the mesh by querying the BVH at each grid point.
Sources
- primarygkjohnson (2018). gkjohnson/three-mesh-bvh. A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.GitHub API · license MIT · 2026-11-29