Introduction
Summary
@pmndrs/bvh builds bounding volume hierarchies (BVHs) for WebGPU. You give it triangles. It gives you trees in one
fixed GPU layout, built on the CPU (tinybvh in WebAssembly) or on the GPU (H-PLOC or LBVH), refit on the GPU when
things move, and read by a WGSL ray walk that you put in your own shaders.
A BVH is a tree of boxes over a scene's triangles. It lets a ray, or a point, skip almost every triangle on the way to the one that matters. Ray tracing, picking, shadows, collision and distance fields all start from one.
The core imports no engine. three.js support lives behind @pmndrs/bvh/three, Babylon.js support behind
@pmndrs/bvh/babylon, and worker builds behind @pmndrs/bvh/worker. The same trees serve a raw compute pass, three's
node system, a worker, or another library on the same GPUDevice.
The package is at version 0.0.0 and not on npm yet. The API can still change before 0.1.
What is in it
What it is not
- It has no WebGL2 path. The CPU queries work anywhere JavaScript runs, but no GPU work targets WebGL2.
- It is not a renderer. The package ends at the hit: the triangle, instance, barycentrics, face normal and a material number it carries but never reads. What a hit looks like (lights, sampling, textures) is yours.
- Babylon.js support is "it works", not polish:
/babylonhas picking that returnsscene.pick'sPickingInfo, a mesh conversion, and the walk in aComputeShaderon theWebGPUEngine's device, reached through the engine's internals (Babylon.js). It has no scene sync or skinning. - Points and lines are primitives on the CPU only (Points and lines): the GPU walk and
SceneTreestake triangles. - It is not a drop-in for all of three-mesh-bvh. Nearly all of its CPU API is here, and a few things are left out on purpose (Coming from three-mesh-bvh).
Where to start
- Installation: the package and a device with
subgroups. - First build: a vanilla quick start and two three.js quick starts.
- The GPU layout, if you will write your own walk or read the trees yourself.
Users of three-mesh-bvh can start at Coming from three-mesh-bvh.
How the docs are organised
The sections run from first steps to depth, top to bottom in the sidebar:
- Getting started and Concepts teach the layout and the rules every builder follows.
- Builders, Scenes, Workers and Engines cover building trees and keeping them current, then sharing a device with three or Babylon.
- Tracing is the GPU side: the walk, queries and distance fields. CPU queries is the same on the CPU.
- three.js has the engine pages, including the drop-ins for three-mesh-bvh.
- Serialization, Performance (how every number was measured), Examples and the API reference close the site.
The repository front page, the README, has the three quick starts side by side, and HISTORY.md tells how the package got here.