@pmndrs/bvh
    Preparing search index...

    Class SkinnedMeshBVH

    three-mesh-bvh's SkinnedMeshBVH(mesh, options): a BvhBoundsTree over the posed triangles of mesh (see the file comment). The options are computeBoundsTree's.

    Hierarchy (View Summary)

    Index
    geometry: BufferGeometry
    index: BufferAttribute<BufferAttributeEventMap> | null
    indexVersion: number

    The tree in the GPU layout. Its buffers are this object's own storage: refit writes them in place.

    mesh: Mesh

    The mesh whose pose the tree follows.

    posedPositions: Float32Array

    The posed positions (x, y, z per vertex), rewritten by refit.

    position: BufferAttribute<BufferAttributeEventMap> | InterleavedBufferAttribute

    The position attribute and index the tree was built from (or last refitted to), and their versions then.

    positionVersion: number
    staleWarned: boolean = false

    Warned once that the geometry changed since the build.

    • get depth(): number

      The deepest box's depth, as traverse reports it (three-mesh-bvh's depth: the root's children are at 1).

      Returns number

    • get followsPose(): boolean

      Whether the tree holds a posed mesh's triangles (SkinnedMeshBVH): then acceleratedRaycast walks it for a SkinnedMesh or a morphed mesh instead of falling back to three's raycast.

      Returns boolean

    • get hitGeometry(): BufferGeometry

      The geometry a hit's fields are read from (face corners and normal, uv, normal): the tree's own, or a posed view of it.

      Returns BufferGeometry

    • True when the geometry's positions and index are the ones the tree was built from (or refitted to).

      Returns boolean

    • three-mesh-bvh's MeshBVH.deserialize(data, geometry, { setIndex }): a tree for geometry from three-mesh-bvh's serialized format (its MeshBVH.serialize, or BvhBoundsTree.serialize), or from our bytes (bvh.serialize()). For three-mesh-bvh's format, setIndex (default true) sets the geometry's index from data.index as three-mesh-bvh does (makes one when the geometry has none, else copies into it); the tree's shape is kept and its boxes made exact (meshBvhFromThreeMeshBvh). The other options are computeBoundsTree's. Doesn't set geometry.boundsTree; setBoundsTree does.

      Parameters

      Returns BvhBoundsTree

    • The core's form (CpuMeshBvh.deserialize(bytes, options)), for subclasses whose constructor takes a layout.

      Type Parameters

      • T

      Parameters

      Returns T

    • Bytes this object holds: the layout (nodes; triangles, 48-byte records or with corners: 'positions' 16 bytes; parents), the one-instance top level and lookups made so far. Not the source geometry.

      Returns number

    • Box around every triangle, current after refit: into target as [minX, minY, minZ, maxX, maxY, maxZ], or into its min and max (a three Box3). Default a new Float32Array(6).

      Type Parameters

      Parameters

      • Optionaltarget: T

      Returns T

    • The corners of the triangle at a tree position, as the tree stores them: 9 numbers into target.

      Parameters

      • treePosition: number
      • target: Float32Array<ArrayBufferLike> | number[] = ...

      Returns Float32Array<ArrayBufferLike> | number[]

    • The walk under raycast: every hit (or the closest only) with t in [tMin, tMax], in units of direction as given. side culls natively in the walk (BVH_FRONT_SIDE front faces only, BVH_BACK_SIDE back faces only; default BVH_DOUBLE_SIDE, the WGSL walk's behaviour; CPU only). accept decides which of the rest count (by original triangle and side), the others are passed through. All hits come in walk order, not sorted. A closest-hit query without accept runs the walk with no triangle filter at all.

      Parameters

      • origin: readonly [number, number, number]
      • direction: readonly [number, number, number]
      • tMin: number
      • tMax: number
      • firstHitOnly: boolean
      • accept: BvhTriangleAccept | null = null
      • side: number = BVH_DOUBLE_SIDE

      Returns BvhRayIntersection[]

    • three-mesh-bvh's intersectsGeometry(geometry, geometryToBvh): against the geometry's own tree when it has one of ours (geometry.boundsTree), else against its triangles. A tree or { positions, indices } pass too.

      Parameters

      • other:
            | MeshInput
            | CpuMeshBvh<unknown>
            | BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>
      • OptionalgeometryToBvh: BvhMatrix4Like | Matrix4 | null

      Returns boolean

    • Whether point is inside the mesh: at least two of three rays vote it inside (insideVotes). rule is 'parity' (the default; odd crossings, any winding) or 'winding' (non-zero signed crossings; overlapping closed parts stay inside, triangles must be wound consistently). Exact for a closed mesh away from its surface; on an open mesh, rays through a hole disagree and the vote decides (docs/tracing/sdf.mdx). The CPU twin of the GPU's bvhIsInside.

      Parameters

      Returns boolean

    • Every hit on the faces side selects, sorted by distance. The second argument is the side (three's FrontSide/BackSide/DoubleSide values), a BvhRaycastOptions, or anything with side (a three material); near and far may follow, as in three-mesh-bvh.

      Parameters

      • ray: BvhRayLike
      • OptionalmaterialOrSide:
            | number
            | BvhRaycastOptions
            | Material<MaterialEventMap>
            | Material<MaterialEventMap>[]
      • Optionalnear: number
      • Optionalfar: number

      Returns BvhBoundsTreeHit[]

    • Intersects a local-space ray (origin, direction: three's ray through the inverse of the world matrix, not renormalized, so t is the world distance) with the triangles three would test for material. firstHitOnly: the closest only. Returns local hits, or null when a range off a multiple of 3 needs a shifted tree and tinybvh isn't loaded.

      Parameters

      • origin: readonly [number, number, number]
      • direction: readonly [number, number, number]
      • near: number
      • far: number
      • material: Material<MaterialEventMap> | Material<MaterialEventMap>[]
      • drawRange: { count: number; start: number }
      • firstHitOnly: boolean

      Returns BvhLocalHit[] | null

    • Poses every vertex again (mesh.getVertexPosition) and refits the tree to it, keeping its shape: three-mesh-bvh's refit() after the skeleton or the morph influences moved. With input, refits to those arrays instead (as the core does).

      Parameters

      Returns void

    • three-mesh-bvh's MeshBVH.serialize(bvh, { cloneBuffers }): the tree in three-mesh-bvh's serialized format (indirect mode, index a copy of the geometry's), which its MeshBVH.deserialize reads (serializeThreeMeshBvh). bvh.serialize() gives our own format.

      Parameters

      • bvh: CpuMeshBvh<unknown> & {
            geometry?: BufferGeometry<
                NormalBufferAttributes,
                BufferGeometryEventMap,
            >;
        }
      • options: { cloneBuffers?: boolean } = {}

      Returns ThreeMeshBvhSerialized

    • Walks the tree, asking callbacks which boxes to enter and handing over triangle ranges, with three-mesh-bvh's shapecast contract (BvhTraverseCallbacks): depth first, the root's box never asked about, each child scored once by boundsTraverseOrder and the lower score visited first, a falsy intersectsBounds skipping the box, a contained box reported as one range, and a truthy intersectsRange stopping the walk. Returns true when it was stopped.

      Parameters

      Returns boolean

    • three-mesh-bvh's node walk (BVH.traverse(callback), 0.9.18), for the debug utilities and the helper: every node in depth-first order, left before right, starting with the root at depth 0 (its box the tree's bounds; a one-leaf tree's root is that leaf). box is a new Float32Array(6), [minX, minY, minZ, maxX, maxY, maxZ], per node. A leaf gets its first tree position and triangle count; an inner node gets its split axis (0, 1, 2), which our layout doesn't store: it is taken as the axis along which the children's centres lie furthest apart. A truthy return skips the node's children.

      Parameters

      • callback: (
            depth: number,
            isLeaf: boolean,
            box: Float32Array,
            offsetOrSplit: number,
            count: number,
        ) => unknown

      Returns void

    • three-mesh-bvh's writePrimitiveRangeBounds: the box around the triangles at tree positions offset to offset + count - 1, into target at targetOffset as [minX, minY, minZ, maxX, maxY, maxZ]. Read from the source geometry when the tree has one (so edits made since the build or the last refit show, as three-mesh-bvh reads the geometry), else from the corners the tree stores.

      Parameters

      • offset: number
      • count: number
      • target: Float32Array<ArrayBufferLike> | number[] | Float64Array<ArrayBufferLike>
      • targetOffset: number = 0

      Returns void