ThreePipe
    Preparing search index...

    Class BVHPlugin

    BVH Plugin

    Builds a bounding volume hierarchy (three-mesh-bvh) for mesh geometries, so a raycast tests a few boxes and triangles instead of every triangle: picking, hover, snapping and placing things on surfaces stay fast on big models. Other plugins can use the same trees with getBVH.

    • Meshes in auto mode get a BVH from autoMinTriangles triangles. object.userData.bvh sets on or off per object (the object's UI has a BVH section).
    • Trees are built after the frame, within buildBudget ms per frame, and kept in geometry.boundsTree. The geometry is not changed (indirect trees: the index keeps its order).
    • A mesh with a tree raycasts with acceleratedRaycast. The Raycaster API does not change.
    • A geometry update refits the tree when it would have the same triangles (the same index or position count, draw range and groups), else builds it again.
    • A mesh that gets a geometry with a tree raycasts with that tree, when the tree has the triangles that the mesh draws (a tree made with the range option of three-mesh-bvh, or before a draw range change, can have fewer or others).
    • Not for skinned or morphed meshes, instanced or batched meshes, or meshes with their own raycast (fat lines).

    threepipe does not depend on three-mesh-bvh: install it (npm i three-mesh-bvh, 0.9.5 or newer) and give it to the plugin. With a bundler, pass a loader: new BVHPlugin(true, {load: () => import('three-mesh-bvh')}) (a separate chunk, loaded when the plugin is added), or the module: {lib: bvh}. Without options, the plugin loads three-mesh-bvh with a native dynamic import that bundlers do not process: map three-mesh-bvh in an import map (CDN builds).

    Hierarchy (View Summary)

    Index
    _dirty: boolean = false
    _viewer?: ThreeViewer
    _viewerListeners: PartialRecord<IViewerEventTypes, (e: IViewerEvent) => void> = {}
    autoMinTriangles: number = 1000

    Meshes in auto mode with at least this many triangles get a BVH

    buildBudget: number = 6

    Time for building trees after each frame, in ms. A geometry that takes longer is still built whole.

    constructor: typeof AViewerPluginSync & typeof AViewerPlugin
    enabled: boolean = true
    isViewerPluginSync: true = ...

    three-mesh-bvh, once loaded. Trees are built after it is.

    uiConfig?: UiObjectConfig<any, string, any> = undefined
    LIBRARY_MODULE: string = 'three-mesh-bvh'

    The module specifier of the default loader's native import(), resolved by the browser (an import map entry, or a full URL here). A property, so the build cannot fold it into a literal import('three-mesh-bvh'), which bundlers of apps that use threepipe would then try to resolve (and fail without three-mesh-bvh installed).

    OldPluginType?: string
    PluginType: "BVHPlugin" = 'BVHPlugin'
    • Show the boxes of an object's tree (a BVHHelper in the scene, not saved). The helper belongs to the mesh: it goes when the mesh leaves the scene, gets another geometry, is off or not supported, when the tree is dropped, and when the plugin is disabled or removed.

      Parameters

      Returns void