@pmndrs/bvh
    Preparing search index...

    Interface BvhTraverseCallbacks

    The callbacks of CpuMeshBvh.traverse: three-mesh-bvh's shapecast callbacks, with its argument order. box is [minX, minY, minZ, maxX, maxY, maxZ] in a scratch array that is only valid during the call; copy it to keep it.

    nodeIndex names the box: the child slot it is in (parentNode * 2 + side, 0 for left, 1 for right), unique per box in this tree and below 2 * nodeCount. A tree whose root is one leaf reports that leaf as 0.

    Ranges are tree positions (three-mesh-bvh's indirect mode): read them with CpuMeshBvh.getTriangle or map them to the original triangle with CpuMeshBvh.resolveTriangleIndex.

    interface BvhTraverseCallbacks {
        boundsTraverseOrder?(box: Float32Array): number;
        intersectsBounds(
            box: Float32Array,
            isLeaf: boolean,
            score: number | undefined,
            depth: number,
            nodeIndex: number,
        ): unknown;
        intersectsRange(
            offset: number,
            count: number,
            contained: boolean,
            depth: number,
            nodeIndex: number,
            box: Float32Array,
        ): unknown;
    }
    Index
    • Scores a box, once per child; of two siblings the lower score is visited first (left first on a tie). Without it, left before right.

      Parameters

      • box: Float32Array

      Returns number

    • Whether the walk enters a box. A falsy answer (false, undefined, BVH_NOT_INTERSECTED) skips it; BVH_CONTAINED reports the box's whole subtree as one contained range without asking about the boxes below it; anything else truthy (BVH_INTERSECTED, true) enters it. isLeaf: the box holds a triangle range rather than two more boxes. score is boundsTraverseOrder's for this box (undefined without one). The root's box is never asked about, as in three-mesh-bvh: the first boxes asked are the root's children, at depth 1.

      Parameters

      • box: Float32Array
      • isLeaf: boolean
      • score: number | undefined
      • depth: number
      • nodeIndex: number

      Returns unknown

    • A range of tree positions, offset to offset + count - 1: an entered leaf's (contained false), or a contained box's whole subtree (one call, contained true). A truthy return stops the walk, and CpuMeshBvh.traverse returns true.

      Parameters

      • offset: number
      • count: number
      • contained: boolean
      • depth: number
      • nodeIndex: number
      • box: Float32Array

      Returns unknown