Spatial index for fast ray, frustum, and AABB queries against a Scene.

Maintains its own per-object world-space AABBs and a hierarchical bounding-volume tree on top, so queries can skip whole branches of the scene at once. Self-contained — no dependency on other index helpers.

The index is lazy and self-maintaining: any scene mutation (object created, destroyed, or moved; model destroyed) marks the tree dirty, and the next query rebuilds. Build cost is O(N log N) and runs at most once between mutations, regardless of how many queries fire after.

Why lazy rebuild instead of incremental refit? BIM scenes are typically static once loaded — load triggers a flurry of onSceneObjectCreated events, then the tree settles. Lazy rebuild absorbs all of those in a single tree build at the next query, instead of N separate insert/refit passes. For interactive editing of small numbers of objects, query latency stays bounded because rebuild cost scales with object count, not mutation count.

Hierarchy strategy: top-down median-centroid split on the longest axis of the parent's AABB. Leaves stop subdividing at LEAF_THRESHOLD objects. This is faster to build than a full SAH BVH and queries within ~5–15% of SAH for the typical near-uniform AABB distribution of building models.

Queries:

Each query has a forEachIn… streaming variant that takes a visitor callback. Returning false from the callback halts iteration — useful for "find first hit" or "any inside?" patterns where you don't want to pay for the full result set.

Constructors

Properties

scene: Scene

The Scene this index is bound to.

Accessors

Methods

  • Returns every object whose world AABB overlaps the given query AABB.

    Uses the same inside/intersect/outside fast paths as the frustum walk: if the query AABB fully contains a node's AABB, we collect every leaf below it without further tests.

    Parameters

    Returns string[]

  • Returns every object whose world AABB intersects the given frustum.

    Skips both fully-outside branches and tests within fully-inside ones — a node entirely inside the frustum has every descendant inside too, so we collect its leaves without per-AABB testing.

    Parameters

    Returns string[]

  • Forces an immediate rebuild of the BVH. Normally callers don't need this — the next query rebuilds automatically — but it's useful in benchmarking and in the rare case where you want to amortise build cost outside the query path.

    Returns void