{
 "id": "three-mesh-bvh",
 "title": "three-mesh-bvh",
 "aliases": [
  "BVH",
  "three-mesh-bvh",
  "three-mesh-bvh (BVH for three.js)"
 ],
 "domain": "geometry",
 "subdomain": "spatial acceleration",
 "stage": "geometry",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "cpu"
 ],
 "year_introduced": 2019,
 "inputs": [
  "mesh"
 ],
 "outputs": [
  "depth",
  "normals"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "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.",
 "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": "Choose it for picking, painting, sculpt brushes, collision of characters against level geometry, signed-distance baking and path tracing in three.js. Prefer `mesh-boolean-manifold` when you need to modify geometry, and a bespoke SDF `exact-euclidean-distance-transform` grid for repeated inside/outside tests on a fixed mesh.",
 "cost": {
  "class": "cheap",
  "notes": "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "gh:gkjohnson/three-mesh-bvh",
   "type": "code",
   "title": "gkjohnson/three-mesh-bvh",
   "description": "A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.",
   "authors": [
    "gkjohnson"
   ],
   "year": 2018,
   "venue": "GitHub",
   "url": "https://github.com/gkjohnson/three-mesh-bvh",
   "ids": {
    "repo": "gkjohnson/three-mesh-bvh"
   },
   "license": "MIT",
   "extra": {
    "stars": 3601,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-28T18:11:52Z",
    "language": "JavaScript",
    "homepage": "https://gkjohnson.github.io/three-mesh-bvh/raycast.html",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gkjohnson/three-mesh-bvh",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gkjohnson/three-mesh-bvh",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gkjohnson/three-mesh-bvh",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gkjohnson/three-mesh-bvh",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gkjohnson/three-mesh-bvh",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gkjohnson/three-mesh-bvh",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "gkjohnson2018gkjohnson"
  }
 ],
 "presets": [],
 "related": [
  "mesh-boolean-manifold",
  "isotropic-remeshing",
  "coacd-convex-decomposition",
  "sah-bvh-construction"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "isotropic-remeshing",
   "why": "Fast closest-point queries reproject remeshed vertices onto the source."
  },
  {
   "id": "exact-euclidean-distance-transform",
   "why": "Bake a distance volume from the mesh by querying the BVH at each grid point."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/geometry/three-mesh-bvh.json"
 },
 "solves": [
  "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"
 ],
 "authority": "gkjohnson, 2018",
 "url": "https://texelatlas.vercel.app/t/three-mesh-bvh/",
 "execution_fidelity": "none",
 "fidelity_label": "No Live Specimen",
 "benchmark_eligible": false
}