---
id: "three-mesh-bvh"
title: "three-mesh-bvh"
aliases: [BVH, three-mesh-bvh, three-mesh-bvh (BVH for three.js)]
domain: "geometry"
stage: "geometry"
realtime: "realtime"
platforms: [webgl2, webgpu, cpu]
year_introduced: 2019
inputs: [mesh]
outputs: [depth, normals]
style: "both"
dynamic: "both"
cost: "cheap"
authority: "gkjohnson, 2018"
url: "https://texelatlas.vercel.app/t/three-mesh-bvh/"
sources_verified_at: "2026-11-29"
---
# three-mesh-bvh (gkjohnson, 2018)

> 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.

## 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

## 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 use it

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](https://texelatlas.vercel.app/t/mesh-boolean-manifold.md) when you need to modify geometry, and a bespoke SDF [Exact Euclidean Distance Transform](https://texelatlas.vercel.app/t/exact-euclidean-distance-transform.md) grid for repeated inside/outside tests on a fixed mesh.

## Cost

cheap — Build time grows with n log n; queries are logarithmic, so a raycast on millions of triangles takes microseconds to milliseconds.

## Failure modes

- 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

## Engine support

- threejs: plugin — `npm i three-mesh-bvh` (evidence: https://github.com/gkjohnson/three-mesh-bvh, checked 2026-12-01)

## Dataflow

- Inputs: mesh
- Outputs: depth, normals
- Platforms: webgl2, webgpu, cpu

## Combines with

- [Isotropic Remeshing](https://texelatlas.vercel.app/t/isotropic-remeshing.md): Fast closest-point queries reproject remeshed vertices onto the source.
- [Exact Euclidean Distance Transform](https://texelatlas.vercel.app/t/exact-euclidean-distance-transform.md): Bake a distance volume from the mesh by querying the BVH at each grid point.

## Sources

1. [primary] gkjohnson (2018) gkjohnson/three-mesh-bvh. https://github.com/gkjohnson/three-mesh-bvh License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "three-mesh-bvh." https://texelatlas.vercel.app/t/three-mesh-bvh/ (accessed 2026-12-01).
