# SkinnedMeshBVH

class in `three-mesh-bvh`, extends `GeometryBVH`

```js
import { SkinnedMeshBVH } from 'three-mesh-bvh';
```

BVH for `SkinnedMesh` objects. Computes primitive bounds using
`SkinnedMesh.getVertexPosition` so the tree reflects the current posed state
of the mesh. Call `refit()` after updating the skeleton to keep bounds accurate.

Example: Refitting a BVH to an animated skinned mesh every frame

```js
import { AnimationMixer, Clock, HemisphereLight } from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { SkinnedMeshBVH, BVHHelper } from 'three-mesh-bvh';

// scene, camera and renderer are initialized here

const URL = 'https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/trex/scene.gltf';

scene.add( new HemisphereLight( 0xffffff, 0x444444, 3 ) );

const { scene: model, animations } = await new GLTFLoader().loadAsync( URL );
model.scale.setScalar( 0.3 );
model.position.set( 0, - 0.7, 0.4 );
scene.add( model );

const helpers = [];
model.traverse( object => {

	if ( object.isSkinnedMesh ) {

		object.frustumCulled = false;
		const helper = new BVHHelper( object, new SkinnedMeshBVH( object ), 10 );
		helper.traverse( child => child.frustumCulled = false );
		helpers.push( helper );
		scene.add( helper );

	}

} );

const mixer = new AnimationMixer( model );
mixer.clipAction( animations[ 0 ] ).play();

const clock = new Clock();
renderer.setAnimationLoop( () => {

	mixer.update( clock.getDelta() );
	scene.updateMatrixWorld( true );
	for ( const helper of helpers ) {

		helper.bvh.refit();
		helper.update();

	}

	renderer.render( scene, camera );

} );
```

## Constructor

```js
new SkinnedMeshBVH( mesh: SkinnedMesh, options?: Object )
```

- `mesh`, `SkinnedMesh`
- `options`, `Object`, optional: Same options as `GeometryBVH`.

## Methods

### .shapecast

```js
.shapecast( callbacks: Object ): boolean
```

Performs a spatial query against the BVH. Extends the base `shapecast` with an
`intersectsTriangle` callback that is called once per triangle primitive in leaf nodes.

- `callbacks`, `Object`
  - `intersectsBounds`, `IntersectsBoundsCallback`
  - `intersectsTriangle`, `IntersectsTriangleCallback`, optional
  - `intersectsRange`, `IntersectsRangeCallback`, optional
  - `boundsTraverseOrder`, `BoundsTraverseOrderCallback`, optional
