voxelkloudBack to the project

DOCS / PACKAGE GUIDE

@voxelkloud/view/lod
LOD selection and culling helpers

This subpath stays dependency-free so it can run in workers, SSR, tests, or any place that only needs the selector.

import from @voxelkloud/view/lodpublic

Selection loop

Resolve the knobs once per frame, reuse scratch buffers, and let the selector tell you what limited the frame.

import {
  createLodScratch,
  createLodSelection,
  resolveLodOptions,
  selectVisible,
} from '@voxelkloud/view/lod'

const opts = resolveLodOptions({ targetScreenError: 1.35, pointBudget: 3_000_000 })
const scratch = createLodScratch(tree.nodeCount)
const selection = createLodSelection(opts.maxNodes)

selectVisible(tree, cameraState, opts, scratch, selection)

How culling works

A node outside the frustum means every descendant is outside too, so the branch can be dropped immediately. Intersecting nodes keep descending, and inside nodes stop paying the six-plane test for their children.

import {
  Containment,
  classifyAabb,
  extractFrustumPlanes,
} from '@voxelkloud/view/lod'

const planes = new Float64Array(24)
extractFrustumPlanes(clipFromWorld, planes, depthRange, false)

const state = classifyAabb(planes, minX, minY, minZ, maxX, maxY, maxZ)
if (state === Containment.Outside) return

What the result tells you

selection.limitedBy says whether budget, headroom, node count, or the error floor won the frame. selection.achievedScreenError tells you what the viewer actually left on screen.

  • Use targetScreenError to say how much error is acceptable in screen pixels.
  • Use pointBudget to cap the number of selected points.
  • Use the result object to explain why a frame stopped refining.