@shapeshift-labs/frontier-lod
v0.1.2
Published
Patch-native level-of-detail and significance primitives for Frontier rendering and computation workloads.
Downloads
409
Maintainers
Readme
@shapeshift-labs/frontier-lod
Patch-native level-of-detail and significance primitives for Frontier rendering and computation workloads. The package stores LOD profiles and item state as JSON, accepts Frontier patch tuples for mutation, and keeps hot distance/significance state in typed-array caches.
API Shape
import {
createLodBandFrame,
createLodCompactFrame,
createLodEngine,
createLodMultiObserverFrame,
createLodTransitionFrame,
createLodWorkPlan,
lodItem,
lodLevel,
lodProfile,
materializeLodFrame,
scheduleLodWork,
setLodItemPositionPatch
} from '@shapeshift-labs/frontier-lod';
const profile = lodProfile('npc', [
lodLevel('full', { maxDistance: 20, renderCost: 8, computeCost: 8, updateIntervalMs: 16, lane: 'near' }),
lodLevel('sim', { maxDistance: 80, renderCost: 3, computeCost: 2, updateIntervalMs: 120, lane: 'mid' }),
lodLevel('coarse', { maxDistance: 220, renderCost: 1, computeCost: 1, updateIntervalMs: 1000, lane: 'far' }),
lodLevel('culled', { visible: false, renderCost: 0, computeCost: 0, updateIntervalMs: -1 })
]);
const lod = createLodEngine({
profiles: [profile],
items: [
lodItem('npc:1', 0, 0, { profile: 'npc', radius: 1, priority: 2 }),
lodItem('npc:2', 90, 0, { profile: 'npc', radius: 1 })
]
});
const frame = lod.evaluate({ x: 0, y: 0 }, {
includeHidden: true,
budget: { maxVisible: 2000, maxRenderCost: 8000, maxComputeCost: 5000 }
});
const materialized = materializeLodFrame(frame);
const workPlan = createLodWorkPlan(frame, { nowMs: performance.now() });
scheduleLodWork(scheduler, workPlan, (item) => updateNpc(item.id, item.levelId));
lod.commit(setLodItemPositionPatch(1, 40, 0), {
origin: { actionId: 'npc.move', causeId: 'pathfinding.tick' }
});
const compact = lod.evaluateInto(createLodCompactFrame(lod.itemCount), { x: 0, y: 0 }, { mode: 'distance' });
const bands = lod.evaluateBandsInto(createLodBandFrame(lod.itemCount), { x: 0, y: 0 });
const transitions = lod.evaluateBandTransitionsInto(createLodTransitionFrame(lod.itemCount), { x: 0, y: 0 });
const sharedWorld = lod.evaluateMultiObserverInto(createLodMultiObserverFrame(lod.itemCount), [
{ x: 0, y: 0 },
{ x: 300, y: 0, qualityBias: 0.9 }
]);Design Notes
frontier-lod deliberately does not own a renderer, virtualizer, scene graph, pathfinder, game loop, or scheduler. It produces JSON-shaped frames for inspection/persistence and typed-array frames for hot loops.
- JSON snapshots are the durable LOD state.
- Frontier patch tuples are the mutation format.
- Item scalar changes update typed caches by exact item index.
- Profiles support distance, screen-coverage, and priority/significance selection.
- LOD levels carry render cost, compute cost, lane, update interval, visibility, and metadata.
- Budgeted evaluation degrades lower-significance items when render/compute/visible budgets are exceeded.
evaluate(...)produces a serializable inspection/materialization frame.evaluateInto(...)reuses typed buffers for per-frame distance/screen/priority loops.evaluateBandsInto(...)is a distance-band-only hot path for very large homogeneous sets.evaluateBandTransitionsInto(...)is a Unity CullingGroup-style event path: it keeps internal band state current but only materializes changed indexes, previous levels, and next levels.evaluateMultiObserverInto(...)selects one shared LOD frame across several cameras, spectators, minimaps, AI-interest origins, or server-relevance observers without requiring separate full frames and a merge pass.materializeLodFrame(...)exposes visible/hidden/by-level index lists for DOM, Canvas, WebGL, WebGPU, or game hosts.createLodWorkPlan(...)converts levels and update intervals into scheduler-friendly compute tasks.- Scheduler integration is structural, so
frontier-schedulercan queue work without becoming a dependency. - Scene/virtual/pathfinding integration stays data-shaped: scene graphs can feed world positions, virtualizers can materialize visible indexes, and pathfinding/game systems can lower update cadence for far or low-priority entities.
Related Packages
The published Frontier package family is generated from one shared package catalog so READMEs stay in sync across packages:
@shapeshift-labs/frontier: Core JSON diff/apply, compact patch tuples, JSON Pointer, equality, clone, validation, Unicode helpers, and tiny dependency-free runtime budget/scheduler primitives.@shapeshift-labs/frontier-query: Shared query-key, selector path, condition, entity identity, and table-shape primitives.@shapeshift-labs/frontier-codec: Patch serialization, binary frames, canonical JSON, and patch-history codecs.@shapeshift-labs/frontier-engine: Stateful planned diff engine, adaptive profiles, schema plans, and engine-level history helpers.@shapeshift-labs/frontier-state: Patch-routed app-state subscriptions, owned commits, maintained views, and path mapping.@shapeshift-labs/frontier-state-cache: Normalized query-result cache with entity/query watchers, persistence, change logs, optimistic layers, scheduled persistence, and mutation bridge.@shapeshift-labs/frontier-state-cache-idb: IndexedDB persistence adapter for Frontier state-cache snapshots and durable change logs.@shapeshift-labs/frontier-state-cache-file: Structured file persistence adapter for Frontier state-cache snapshots and change logs.@shapeshift-labs/frontier-state-cache-sql: SQL persistence adapter for Frontier state-cache snapshots and change logs.@shapeshift-labs/frontier-schema: JSON Schema validation, Frontier profile generation, CloudEvent envelopes, and query/table schema helpers.@shapeshift-labs/frontier-event-log: Bounded event logs, replay cursors, consumer acknowledgements, keyed compaction, checkpoints, and Frontier patch event records.@shapeshift-labs/frontier-scheduler: Deterministic work scheduling, lanes, cancellation, backpressure, frame policies, replay snapshots, and work graphs.@shapeshift-labs/frontier-logging: Opt-in structured logging, browser telemetry, scheduled sinks, file sinks, exporters, benchmark traces, and Frontier patch/update summaries.@shapeshift-labs/frontier-mutation: Explicit mutation and selector plans compiled to Frontier patches or CRDT operations.@shapeshift-labs/frontier-virtual: DOM-neutral virtualization, layout providers, range materialization, grids, spatial/frustum indexes, patch invalidation, camera anchors, and serializable layout state.@shapeshift-labs/frontier-scene: Patch-native 2D/3D scene graph, transform propagation, bounds queries, virtual/culling adapters, spatial invalidation, and camera/frustum materialization.@shapeshift-labs/frontier-pathfinding: Patch-native grid pathfinding, typed-array A*/Dijkstra search, flow fields, connected components, line-of-sight smoothing, dirty-cell invalidation, and scheduler-friendly path jobs.@shapeshift-labs/frontier-dom: Patch-native DOM and host renderer bindings, manifest hydration, JSX runtime/compiler helpers, SSR, devtools, and logging bridges.@shapeshift-labs/frontier-playwright: Playwright/headless automation probes for Frontier state, DOM, devtools, marks, and timeline queries.@shapeshift-labs/frontier-crdt: Native CRDT documents, update tooling, awareness, branches, conflict introspection, version frames, and undo.@shapeshift-labs/frontier-crdt-sync: CRDT sync endpoints, repo/storage/provider contracts, scheduled sync work, document URLs, local networks, model checking, forensics, and text binding contracts.@shapeshift-labs/frontier-crdt-websocket: WebSocket client/server transports for Frontier CRDT sync providers.@shapeshift-labs/frontier-react: React external-store hooks and adapters for Frontier state, cache, and CRDT surfaces.@shapeshift-labs/frontier-richtext: Rich text Delta normalization/application, marks, embeds, ranges, and cursor/selection transforms for local editor integrations.@shapeshift-labs/frontier-realtime: Shared realtime command, tick, snapshot, prediction, reconciliation, interpolation, rollback, message, and delta primitives.@shapeshift-labs/frontier-realtime-server: Authoritative realtime room, tick, command validation, rate-limit, session, and snapshot-history runtime.@shapeshift-labs/frontier-realtime-websocket: WebSocket client, wire, and Node room-server transport for Frontier realtime.@shapeshift-labs/frontier-game: Game-facing entity, component, player, room, ownership, spatial interest, rollback, physics, and replication helpers above realtime.
Package source repositories:
siliconjungle/-shapeshift-labs-frontiersiliconjungle/-shapeshift-labs-frontier-querysiliconjungle/-shapeshift-labs-frontier-codecsiliconjungle/-shapeshift-labs-frontier-enginesiliconjungle/-shapeshift-labs-frontier-statesiliconjungle/-shapeshift-labs-frontier-state-cachesiliconjungle/-shapeshift-labs-frontier-state-cache-idbsiliconjungle/-shapeshift-labs-frontier-state-cache-filesiliconjungle/-shapeshift-labs-frontier-state-cache-sqlsiliconjungle/-shapeshift-labs-frontier-schemasiliconjungle/-shapeshift-labs-frontier-event-logsiliconjungle/-shapeshift-labs-frontier-schedulersiliconjungle/-shapeshift-labs-frontier-loggingsiliconjungle/-shapeshift-labs-frontier-mutationsiliconjungle/-shapeshift-labs-frontier-virtualsiliconjungle/-shapeshift-labs-frontier-scenesiliconjungle/-shapeshift-labs-frontier-pathfindingsiliconjungle/-shapeshift-labs-frontier-lodsiliconjungle/-shapeshift-labs-frontier-domsiliconjungle/-shapeshift-labs-frontier-playwrightsiliconjungle/-shapeshift-labs-frontier-crdtsiliconjungle/-shapeshift-labs-frontier-crdt-syncsiliconjungle/-shapeshift-labs-frontier-crdt-websocketsiliconjungle/-shapeshift-labs-frontier-reactsiliconjungle/-shapeshift-labs-frontier-richtextsiliconjungle/-shapeshift-labs-frontier-realtimesiliconjungle/-shapeshift-labs-frontier-realtime-serversiliconjungle/-shapeshift-labs-frontier-realtime-websocketsiliconjungle/-shapeshift-labs-frontier-game
Install
npm install @shapeshift-labs/frontier-lodBenchmarks
These are Frontier-only package measurements, not competitor comparisons.
Run package-local measurements:
npm run benchThe benchmark covers 100k-item distance, compact typed-array, distance-band, sparse transition, multi-observer, screen-coverage, priority budget, materialization, scheduler work-plan, and patch-routed position update fixtures.
Latest local package benchmark on Node v26.1.0, darwin arm64, 100k items and 30 rounds:
| Fixture | Median | p95 |
| --- | ---: | ---: |
| evaluate-bands-distance-100000 | 1.02 ms | 1.65 ms |
| evaluate-band-transitions-static-100000 | 822.87 us | 1.26 ms |
| evaluate-multi-observer-distance-100000 | 1.76 ms | 1.89 ms |
| evaluate-compact-distance-100000 | 1.34 ms | 2.32 ms |
| evaluate-distance-100000 | 5.10 ms | 6.08 ms |
| evaluate-screen-100000 | 17.38 ms | 31.32 ms |
| evaluate-budget-100000 | 21.76 ms | 30.00 ms |
| materialize-frame-100000 | 1.13 ms | 1.68 ms |
| work-plan-100000 | 12.61 ms | 16.18 ms |
| patch-128-positions-100000 | 99.25 us | 175.62 us |
