Skip to content

NgtsBVH

Credits: Bvh from Drei

NgtsBVH applies Bounding Volume Hierarchy (BVH) acceleration to child meshes for significantly faster raycasting performance. It uses three-mesh-bvh under the hood.

BVH is essential for complex geometries where standard raycasting would be too slow.

Dependencies

Terminal window
npm install three-mesh-bvh

Usage

import { NgtsBVH } from 'angular-three-soba/performances';
<ngts-bvh [options]="{ firstHitOnly: true }">
<ngt-mesh>
<ngt-buffer-geometry />
<ngt-mesh-standard-material />
</ngt-mesh>
</ngts-bvh>

When to Use

  • Complex meshes with thousands of triangles
  • Scenes with many interactive objects
  • When raycasting performance is a bottleneck

Split Strategies

  • SAH (default): Surface Area Heuristic, best for most cases
  • CENTER: Split at center of bounding box
  • AVERAGE: Split at average of triangle centroids
<ngts-bvh [options]="{ strategy: CENTER, maxDepth: 30 }">
<!-- meshes -->
</ngts-bvh>

Options

Properties

name type description
enabled boolean Whether BVH acceleration is enabled, default to true
firstHitOnly boolean Use raycastFirst for faster single-hit detection, default to false
strategy SplitStrategy Split strategy for BVH construction (SAH recommended), default to SAH
verbose boolean Print warnings during tree construction, default to false
setBoundingBox boolean Set geometry bounding box after BVH construction, default to true
maxDepth number Maximum tree depth, default to 40
maxLeafTris number Target number of triangles per leaf node, default to 10
indirect boolean Use separate buffer for BVH structure (experimental), default to false