Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410/** Glyph mesh-layer factories; one `SimpleMeshLayer` per probe. Probes are partitioned into three buckets (leaf / non-leaf / unknown) by {@link ./deck-scatter-helpers.ts}, then each probe gets its own `SimpleMeshLayer` with a per-probe canvas texture from {@link ./deck-textures.ts} that bakes the npm name and fill colour directly onto the mesh surface. Depth testing then naturally occludes back-glyph names behind front glyphs. Spheres for leaf and unknown probes, octahedra for non-leaf. Geometries live in {@link ./deck-geometries.ts}; texture baking in {@link ./deck-textures.ts}; per-probe colour / radius / position accessors in {@link ./deck-accessors.ts}; partitioning + name-bake selection in {@link ./deck-scatter-helpers.ts}. Per-probe layers (≈ 117 total at this catalog size) trade a higher draw-call count for correct depth-of-text rendering. A texture atlas with per-instance UV transforms would consolidate this back to three draw calls but needs a custom layer extension; not worth the complexity at this scale. @example ```ts import { buildLeafScatterLayer } from './deck-scatter.ts'; const layers = buildLeafScatterLayer({ probes, state, bounds, visibleIndices }); ``` */
import type { Layer, } from '@deck.gl/core';import { SimpleMeshLayer, } from '@deck.gl/mesh-layers';import type { Geometry, } from '@luma.gl/engine';
import { POSITION_UNKNOWN, probeFillColor, probePosition, probeRadiusWorld, unknownClusterPosition,} from './deck-accessors.ts';import type { SceneBounds, } from './deck-config.ts';import { octahedronGeometry, sphereGeometry,} from './deck-geometries.ts';import { computeNameBakeSet, partitionProbes, type ScatterDatum,} from './deck-scatter-helpers.ts';import { makeProbeTexture, type MeshShape, type Rgba,} from './deck-textures.ts';import type { PackageProbe, } from './probe.ts';import type { AppState, } from './script/state.ts';
//region Constants
/** Opacity multiplier applied to probes that fail the active filter set. ≈ 5 %. */const OPACITY_FILTERED = 0.05;/** Opacity multiplier for probes that pass every filter. */const OPACITY_VISIBLE = 1;/** Opaque-alpha byte used when baking the per-probe texture (filter fade is applied via `Layer.opacity` instead). */const TEXTURE_ALPHA = 255;
//endregion Constants
//region Per-probe layer factory
/** Builds the per-probe `SimpleMeshLayer`. Per-glyph position, scale, and texture; per-layer opacity for the filtered-fade effect. Texture sampling overrides `getColor` in deck.gl's `SimpleMeshLayer`, so the colour painted into the canvas IS the surface colour; the per-layer opacity supplies the visible / filtered fade. Lighting is intentionally left on (`material` default) so the mesh keeps its 3D shading. @param datum - Probe + original index. @param state - Current state. @param bounds - Scene bounds. @param visibleIndices - Set of original indices that pass every filter. @param mesh - Geometry: sphere or octahedron. @param shape - Texture-layout selector matching `mesh`. @param idPrefix - Layer-id prefix; suffixed with `originalIndex` for uniqueness. @param bake - Whether to draw the npm name into the texture (vs colour-only). @param positionOverride - Optional explicit position; when set, takes precedence over `probePosition`. @returns SimpleMeshLayer instance. */function buildProbeLayer( { datum, state, bounds, visibleIndices, mesh, shape, idPrefix, bake, positionOverride, }: { readonly datum: ScatterDatum; readonly state: AppState; readonly bounds: SceneBounds; readonly visibleIndices: ReadonlySet<number>; readonly mesh: Geometry; readonly shape: MeshShape; readonly idPrefix: string; readonly bake: boolean; readonly positionOverride?: readonly [ number, number, number, ]; },): Layer { /** `true` when the probe passes every filter; drives the layer's `opacity`. */ const isVisible = visibleIndices.has(datum.originalIndex,); /** Probe's fill colour computed at full opacity so the baked texture stays opaque. */ const color = probeFillColor({ probe: datum.probe, state, bounds, isVisible: true, },); /** Same colour with a fixed alpha so the texture canvas paints solid pixels (layer opacity handles fading). */ const opaqueColor: Rgba = [ color[0], color[1], color[2], TEXTURE_ALPHA, ]; /** Probe-specific texture canvas (colour, optional name) reused as the mesh texture. */ const texture = makeProbeTexture({ probe: datum.probe, fillColor: opaqueColor, shape, withName: bake, },); /** Data-driven position, or {@link POSITION_UNKNOWN} when any spatial dim is unknown for this probe. */ const dataPosition = probePosition({ probe: datum.probe, state, },); /** World-space position; honours the unknown-cluster override, then the data position, then the origin fallback. */ const pos = positionOverride ?? (dataPosition === POSITION_UNKNOWN ? [ 0, 0, 0, ] : dataPosition); /** Per-probe scale factor; deck.gl's `getScale` returns the same value on every axis. */ const radius = probeRadiusWorld({ probe: datum.probe, state, bounds, },); return new SimpleMeshLayer<ScatterDatum>({ id: `${idPrefix}-${datum.originalIndex .toString()}`, data: [ datum, ], mesh, texture, opacity: isVisible ? OPACITY_VISIBLE : OPACITY_FILTERED, getPosition: function getPosition() { return pos; }, getScale: function getScale() { return [ radius, radius, radius, ] as const; }, pickable: true, },);}
//endregion Per-probe layer factory
//region Layer factories
/** Builds one `SimpleMeshLayer` per leaf probe; sphere mesh, texture baked with the probe's colour and (per the toggle) its npm name. @param probes - Full probe array. @param state - Current state. @param bounds - Scene bounds. @param visibleIndices - Set of original indices that pass every filter. @returns Array of SimpleMeshLayers, one per leaf probe. @example ```ts const layers = buildLeafScatterLayer({ probes, state, bounds, visibleIndices }); ``` */export function buildLeafScatterLayer( { probes, state, bounds, visibleIndices, }: { readonly probes: readonly PackageProbe[]; readonly state: AppState; readonly bounds: SceneBounds; readonly visibleIndices: ReadonlySet<number>; },): readonly Layer[] { /** Leaf-only partition; non-leaf and unknown probes are handled by sibling factories. */ const { leaf, } = partitionProbes({ probes, state, },); /** Set of probe indices whose npm name should be baked into the texture this frame. */ const nameSet = computeNameBakeSet({ probes, state, },); return leaf.map(function asLayer(datum,) { return buildProbeLayer({ datum, state, bounds, visibleIndices, mesh: sphereGeometry, shape: 'sphere', idPrefix: 'scatter-leaf', bake: nameSet.has(datum.originalIndex,), },); },);}
/** Builds one `SimpleMeshLayer` per non-leaf probe; octahedron mesh, texture baked with the probe's colour and (per the toggle) its npm name on every face. @param probes - Full probe array. @param state - Current state. @param bounds - Scene bounds. @param visibleIndices - Set of original indices that pass every filter. @returns Array of SimpleMeshLayers, one per non-leaf probe. @example ```ts const layers = buildNonLeafScatterLayer({ probes, state, bounds, visibleIndices }); ``` */export function buildNonLeafScatterLayer( { probes, state, bounds, visibleIndices, }: { readonly probes: readonly PackageProbe[]; readonly state: AppState; readonly bounds: SceneBounds; readonly visibleIndices: ReadonlySet<number>; },): readonly Layer[] { /** Non-leaf partition; leaves and unknown probes are handled by sibling factories. */ const { nonLeaf, } = partitionProbes({ probes, state, },); /** Set of probe indices whose npm name should be baked into the texture this frame. */ const nameSet = computeNameBakeSet({ probes, state, },); return nonLeaf.map(function asLayer(datum,) { return buildProbeLayer({ datum, state, bounds, visibleIndices, mesh: octahedronGeometry, shape: 'octahedron', idPrefix: 'scatter-nonleaf', bake: nameSet.has(datum.originalIndex,), },); },);}
/** Builds one `SimpleMeshLayer` per unknown probe; sphere mesh placed at the unknown-cluster jitter position, texture with the mid-grey unknown colour and (per the toggle) the npm name. @param probes - Full probe array. @param state - Current state. @param bounds - Scene bounds. @param visibleIndices - Set of original indices that pass every filter. @returns Array of SimpleMeshLayers, empty when the bucket has no probes. @example ```ts const layers = buildUnknownClusterLayer({ probes, state, bounds, visibleIndices }); ``` */export function buildUnknownClusterLayer( { probes, state, bounds, visibleIndices, }: { readonly probes: readonly PackageProbe[]; readonly state: AppState; readonly bounds: SceneBounds; readonly visibleIndices: ReadonlySet<number>; },): readonly Layer[] { /** Unknown-bucket partition; leaves and non-leaves are handled by sibling factories. */ const { unknown, } = partitionProbes({ probes, state, },); /** Set of probe indices whose npm name should be baked into the texture this frame. */ const nameSet = computeNameBakeSet({ probes, state, },); return unknown.map(function asLayer(datum,) { /** Jittered cluster position so unknown probes don't stack at the same point. */ const pos = unknownClusterPosition({ index: datum.originalIndex, bounds, },); return buildProbeLayer({ datum, state, bounds, visibleIndices, mesh: sphereGeometry, shape: 'sphere', idPrefix: 'scatter-unknown', bake: nameSet.has(datum.originalIndex,), positionOverride: pos, },); },);}
//endregion Layer factories