# @pmndrs/bvh ## Documentation - [Introduction](/getting-started/introduction): BVH builders, refits and a ray walk for WebGPU, with no engine inside. - [Installation](/getting-started/installation): The package, its subpaths, and a WebGPU device with subgroups. - [First build](/getting-started/first-build): A vanilla WebGPU quick start, a three.js GPU quick start and a three.js CPU raycast. - [The GPU layout](/concepts/gpu-layout): Nodes, triangles, parents, instances and the top level, as every builder writes them and every walk reads them. - [The builder contract](/concepts/builder-contract): What every builder takes and gives back, so one can replace another without touching the code that traces. - [The oracle rule](/concepts/oracle): Every builder and walk must give the same answers as a tree-less reference on fixed hard cases, on every GPU tested. - [Masks, the triangle filter and materials](/concepts/masks-filter-materials): Hide instances from some rays, let some rays through some triangles, and get a material index back with each hit. - [Choosing a builder](/builders/choosing-a-builder): tinybvh on the CPU, H-PLOC and LBVH on the GPU, and the chooser that picks for you. - [Fallbacks and limits](/builders/fallbacks-and-limits): The one fallback chain, the device limits it covers, and the cap on a GPU build's peak memory. - [Adding a builder from a paper](/builders/adding-a-builder): How a new BVH build method becomes one more builder here, with the same contract, the same oracle, the same bench rows and a licence rule. - [SceneTrees](/scenes/scene-trees): A scene's trees on one device, with GPU trees first and tinybvh's swapped in mesh by mesh. - [Runtime changes](/scenes/runtime-changes): Adding, moving, hiding and removing meshes and instances while the scene runs. - [Merged static instances](/scenes/merged-static): One world-space tree over the instances that never move, for faster rays from surfaces. On by default for instances marked static. - [Refits](/scenes/refits): GpuBvhRefit for a top level over moving instances, GpuMeshRefit for one deforming mesh, and when to rebuild. - [Deforming meshes](/scenes/deforming-meshes): Skinned and morphed meshes whose vertices move on the GPU, refit every frame and rebuilt when the tree drifts. - [Clustered top level](/scenes/clustered-top-level): Cut big meshes into clusters, each its own top-level leaf, so the top level can separate meshes whose boxes overlap. three-mesh-bvh's ClusteredBVH. - [Workers](/workers/workers): tinybvh builds off the main thread with @pmndrs/bvh/worker, GPU builds and workers, and what to transfer. - [Sharing a device with an engine](/engines/sharing-a-device): Building and tracing on the device your renderer already uses, in three.js, Babylon.js and plain WebGPU. - [Babylon.js](/engines/babylon): What @pmndrs/bvh/babylon gives a Babylon.js app: picking with scene.pick's result on any engine, and the WGSL walk in a ComputeShader on the WebGPUEngine's own device, which reaches into engine internals. - [Tracing in WGSL](/tracing/wgsl-walk): Binding the walk in your own kernel, the closest and any entry points, masks, the triangle filter, the stack and the watertight test. - [Ray batches and the CPU walk](/tracing/batches-and-the-cpu-walk): GpuRays for picking and batches, TraceBatchKernel for many rays in one dispatch, its hit records, and the same walk in TypeScript. - [Spatial queries on the GPU](/tracing/gpu-queries): Closest point, sphere and box tests, and your own shapecast over the scene in WGSL, plus the triangle helpers. - [Signed distance fields](/tracing/sdf): Fill a 3D texture or a buffer with the signed distance to a scene's triangles on the GPU, with an inside test you can call in your own WGSL. - [Raycast](/cpu-queries/raycast): CpuMeshBvh, the CPU tree of one mesh, and its raycasts with sides, near and far. - [Shapecast and bvhcast](/cpu-queries/shapecast): Box, sphere and custom shapes against a tree, and one tree against another, with three-mesh-bvh's contract. - [Closest point](/cpu-queries/closest-point): The nearest point on a mesh to a point, or to another mesh, and what lies at a hit. - [Refit, scenes and helpers](/cpu-queries/helpers): CPU refits, a whole scene on the CPU, frustum culling, and three-mesh-bvh's debug functions. - [Points and lines](/cpu-queries/points-and-lines): Trees over points and line segments, with three's raycast thresholds, shapecasts and closest point, engine-free. - [Serialization and baking](/serialization/serialization-and-baking): Build trees or whole scenes once (in Node, at build time), save the bytes, check them, and load them later with no build at all. - [three.js](/three/overview): What @pmndrs/bvh/three gives a three.js app, on the GPU and on the CPU. - [Scenes and the sync](/three/scenes-and-sync): A three scene graph as SceneTrees meshes and instances, kept in step by SceneTreesObject3DSync. - [BvhTraceNodes](/three/trace-nodes): The WGSL walk in three's node system, for TSL compute and materials and for wgslFn. - [Skinned and morphed meshes](/three/skinned-and-morphed): three's skinning and morph math in a TSL compute pass, feeding the GPU refit, with nothing read back. - [CPU raycast in three](/three/cpu-raycast): computeBoundsTree and acceleratedRaycast as drop-ins, a ray against the whole scene, and builds in a worker. - [The tree object](/three/bounds-tree): geometry.boundsTree as a BvhBoundsTree, three-mesh-bvh's MeshBVH API with three's types, its build options and the helper. - [Points and lines in three](/three/points-and-lines): PointsBVH, LineSegmentsBVH, LineLoopBVH and LineBVH as drop-ins, with acceleratedRaycast on Points and line objects. - [Coming from three-mesh-bvh](/three/coming-from-three-mesh-bvh): The API mapping from three-mesh-bvh 0.9, what is missing here, what won't be, and when to stay with three-mesh-bvh. - [Builds and tracing](/performance/builds-and-tracing): Measured build times, tree quality and ray rates, with how each number was taken. - [Memory](/performance/memory): Where the bytes go, against three-mesh-bvh with fair accounting, and the levers that cut them. - [Comparison with other libraries](/performance/comparison): The same geometry and the same seeded queries through @pmndrs/bvh, three-mesh-bvh, three, bvh-tree, Babylon.js, bvh.js and Rapier. - [Examples](/examples/examples): The examples site, one line each, and how to run it. - [API reference](/api/reference): Every export of @pmndrs/bvh and its three, babylon and worker entry points, generated by TypeDoc from the source. ## MCP Server This documentation is available via Model Context Protocol (MCP) server at https://docs.pmnd.rs/api/mcp Configure in your MCP client: ```json { "mcpServers": { "pmndrs": { "type": "http", "url": "https://docs.pmnd.rs/api/mcp" } } } ``` --- For full documentation content, see llms-full.txt