Protected_Float32 view of the whole buffer, as long as it was when last read.
Protected_Int32 view of the whole buffer, as long as it was when last read.
ReadonlybufferThe tree's nodes: grown by its writer, the same buffer.
ReadonlyisTells a BoxTree (a reader, the BoxTree or its BoxTreeStructure) apart.
ReadonlysignalsTells the changes of the tree's buffer, once its worker made them.
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.
Float32 view of the whole buffer; made again when it grew.
Int32 view of the whole buffer; made again when it grew.
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.
The root node, or -1 when the tree is empty.
Leaves in the tree once the changes sent are applied.
Protected_Views of a fixed length on the whole buffer (see the class).
Inserts leaves at once: one subtree over their boxes. Throws, adding none, when the tree cannot hold them (canHold). The arrays are sent to the worker at the end of the task, transferred (empty after it, detached) or, when small, copied with the others of the message: not to be used again; not views on a SharedArrayBuffer.
Their ids (the parts' instance indices), not in the tree.
Their world boxes, 6 floats each (min xyz, max xyz).
Their flags (see PartFlags).
Whether count more leaves fit in the tree (a part takes 2 nodes, maxNodes at most).
Nodes traverse visits with these options.
Stops the workers: the tree stays as it is.
The leaves whose box holds the point, the nearest box centre first.
The leaves whose box the ray crosses, nearest entry first.
Grows every box by this much on each side.
Only the leaf whose box the ray enters first (default): the boxes the ray enters farther than it are not walked.
Empties the tree: the changes not sent yet are dropped.
Sets the flags of a leaf (see PartFlags): the flags set in a row (moves between them
included) merged into one command, the last of a leaf winning.
Calls callback on each node, depth first from the root.
Moves leaves to new boxes (6 floats each), their flags kept. The arrays are transferred, as add's.
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).
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 itsBoxTreeWorker: 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 moves and the flags merge past each other: a loop moving and hiding leaves one by one sends two commands. 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.