Documentation - v19.16.0-dev
    Preparing search index...

    The scene's BoxTree on the main thread: the BVH of the parts' and the sprites' world boxes, a leaf per part or sprite (its id: see LeafIds), in a SharedArrayBuffer read in place by the culling workers and by its queries (BoxTreeReader), which give the leaves' ids. Its only writer is its BoxTreeWorker: the changes (add, update, remove, setFlags, reset) are gathered and sent to it at once at the end of the task (a microtask), and applied there in order; the tree follows them a message later (whenApplied). The moves, removals and flags made in a row are merged into one command (BoxTreeCommandQueue): a loop moving leaves one by one is refitted once. The worker also rebuilds the tree by itself, by the surface area heuristic in a builder worker, once it degraded (see BoxTreeOptions.rebuildCostRatio). signals tell each change of the buffer.

    The main thread does no work on the tree but read it.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _f32: Float32Array

    Float32 view of the whole buffer, as long as it was when last read.

    _i32: Int32Array

    Int32 view of the whole buffer, as long as it was when last read.

    buffer: SharedArrayBuffer

    The tree's nodes: grown by its writer, the same buffer.

    isBoxTree: true

    Tells a BoxTree (a reader, the BoxTree or its BoxTreeStructure) apart.

    signals: {
        changed: Signal<() => void>;
        rebuilt: Signal<(stats: BoxTreeRebuildStats) => void>;
    } = ...

    Tells the changes of the tree's buffer, once its worker made them.

    Type Declaration

    • Readonlychanged: Signal<() => void>

      The buffer changed: commands applied, or the tree rebuilt (e.g. to cull again).

    • Readonlyrebuilt: Signal<(stats: BoxTreeRebuildStats) => void>

      The worker rebuilt the tree.

    Accessors

    • get f32(): Float32Array

      Float32 view of the whole buffer; made again when it grew.

      Returns Float32Array

    • get i32(): Int32Array

      Int32 view of the whole buffer; made again when it grew.

      Returns Int32Array

    • get isApplied(): boolean

      Whether the changes made so far are in the buffer: none waits to be sent or applied, and the worker runs. The leaves' flags then follow the objects' state exactly.

      Returns boolean

    • get root(): number

      The root node, or -1 when the tree is empty.

      Returns number

    • get size(): number

      Leaves in the tree once the changes sent are applied.

      Returns number

    Methods

    • Views of a fixed length on the whole buffer (see the class).

      Returns void

    • Inserts leaves at once: one subtree over their boxes. Throws, adding none, when the tree cannot hold them (canHold). The arrays are transferred to the worker at the end of the task: empty after it (detached), not to be used again; not views on a SharedArrayBuffer.

      Parameters

      • ids: Int32Array

        Their ids (the parts' instance indices), not in the tree.

      • boxes: Float32Array

        Their world boxes, 6 floats each (min xyz, max xyz).

      • flags: Int32Array

        Their flags (see PartFlags).

      Returns void

    • Whether count more leaves fit in the tree (a part takes 2 nodes, maxNodes at most).

      Parameters

      • count: number

      Returns boolean

    • Nodes traverse visits with these options.

      Parameters

      • options: { leavesOnly?: boolean; maxDepth?: number } = {}

      Returns number

    • Stops the workers: the tree stays as it is.

      Returns void

    • The root's box; empty without leaves.

      Parameters

      • target: Box3

      Returns Box3

    • The leaves whose box the ray crosses, nearest entry first.

      Parameters

      • ray: Ray
      • boxExpansion: number = 0

        Grows every box by this much on each side.

      • onlyFirst: boolean = true

        Only the leaf whose box the ray enters first (default): the boxes the ray enters farther than it are not walked.

      Returns BoxTreeIntersection[]

    • Removes leaves. The array is transferred, as add's.

      Parameters

      • ids: Int32Array

      Returns void

    • Empties the tree: the changes not sent yet are dropped.

      Returns void

    • Sets the flags of a leaf (see PartFlags): the flags set in a row merged into one command, the last of a leaf winning.

      Parameters

      • id: number
      • flags: number

      Returns void

    • Calls callback on each node, depth first from the root.

      Parameters

      • callback: (node: BoxTreeNode, index: number, depth: number) => void
      • options: { leavesOnly?: boolean; maxDepth?: number } = {}

      Returns void

    • Moves leaves to new boxes (6 floats each), their flags kept. The arrays are transferred, as add's.

      Parameters

      • ids: Int32Array
      • boxes: Float32Array

      Returns void

    • Resolves once the changes made so far are in the buffer; rejects if one of them failed in the worker (the others are applied), or if the worker fails or was stopped (dispose).

      Returns Promise<void>