/** * A scene of several independently-posed Gaussian splat clouds that all sort * and blend as one. * * The problem it solves: two separate {@link SplatMesh} instances are two * transparent draw calls, each depth-sorted only within itself, so where the * clouds overlap one is painted wholesale in front of the other ("pasted over") * - the same artifact PlayCanvas's unified rendering and Spark's accumulator * exist to fix. `MergedSplatMesh` concatenates every cloud into **one pool** and * runs **one global depth sort**, so splats from different clouds interleave * correctly, from any angle. * * Each cloud ("source") keeps its own world transform, applied in the shader * (never baked into the pool): the sorter transforms each splat's center to * world space before measuring depth, and the material places each splat's * center and covariance by its source's matrix. So {@link setSourceTransform} * is a handful of uniform writes - a source can be dragged or animated every * frame at full rate, at any splat count, with no data re-upload. * * The placement runs **before** the modifier stack, so an application effect sees each * splat where it visually is: an SDF light shape spanning two sources paints * one continuous shape, and a reveal sweeps them together. A modifier that * wants to travel *with* a moved source reads `ctx.sourceCenter` instead of * `ctx.localCenter`. See `docs/guide/effects-and-modifiers.md`. * * On WebGPU the world-depth sort runs in a compute pass; on the WebGL2 * fallback the worker applies the same source matrices on the CPU before * sorting. Both backends therefore inter-sort sources correctly. * * Limitations, all inherited from the dynamic pool: sources may not carry * palette (SOG `shN`) view-dependent color - per-file palettes cannot be merged * - but DC color and per-splat (LCC) SH are fine; all sources share one * antialias setting (from the mesh options). * * Sources are fully decoded {@link SplatData} copied once into the pool. * {@link StreamedSplatMesh} swaps its resident LOD cut every frame, so it cannot * be a merged source. Compose streamed meshes with fully loaded meshes through * {@link UnifiedSplatMesh} instead. */ import * as THREE from 'three/webgpu'; import { SplatMesh, type SplatMeshOptions, type SplatNearestResult, type SplatHeightResult, type SplatRayResult } from './splat-mesh'; import type { SplatData } from './splat-data'; import { type SplatOrientation } from './orientation'; /** Construction options for a {@link MergedSplatMesh}. */ export interface MergedSplatMeshOptions extends SplatMeshOptions { /** Total pool size in splats - must cover the sum of every source added. */ capacity: number; /** Maximum number of sources (default {@link MAX_MERGED_SPLAT_SOURCES}). */ maxSources?: number; } /** Per-source placement options. */ export interface MergedSplatSourceOptions { /** * Y-up normalization for this source's data frame, like {@link SplatMesh}'s * `orientation`. `'y-up'` (default) applies the format's stand-up correction * before the placement matrix; `'source'` places the raw data frame. */ orientation?: SplatOrientation; } /** * One pool, one global sort, many independently-posed splat sources - see the * module overview above for the artifact this exists to remove. */ export declare class MergedSplatMesh extends SplatMesh { private readonly matrices; private readonly maxSources; /** Indexed by source id; holes are left by {@link removeSource}. */ private readonly sources; private nextId; constructor(options: MergedSplatMeshOptions); /** Number of live sources. */ get sourceCount(): number; /** * Adds a cloud at a world placement and returns its id (for * {@link setSourceTransform} / {@link removeSource}). The data is copied into * the shared pool in its own local frame; the placement is applied live in * the shader. * * @throws if the pool cannot fit the cloud, or the source limit is reached. */ addSource(data: SplatData, placement?: THREE.Matrix4, options?: MergedSplatSourceOptions): number; /** * Re-places a source. Cheap by design: only the shared matrix uniform and the * sort bound change, so it is safe to call every frame while dragging. * * Bad-id semantics across the triad: this method **throws** (a write to a * dead source is a caller bug that would otherwise vanish silently), * {@link getSourceTransform} returns `undefined` (querying is how you ask * whether a source is live), and {@link removeSource} returns `false` * (removal is idempotent). * * @throws if `id` is not a live source. */ setSourceTransform(id: number, placement: THREE.Matrix4): void; /** * The current world matrix of a source (a copy), or `undefined` if `id` is * not a live source - see {@link setSourceTransform} for the bad-id triad. */ getSourceTransform(id: number): THREE.Matrix4 | undefined; /** * Removes a source and frees its pool range. The id is not reused (later ids * keep their matrix slots), so long-lived churn should prefer reusing a scene * over unbounded add/remove. * * @returns `true` when a live source was removed, `false` when `id` was not * live (idempotent - see {@link setSourceTransform} for the bad-id triad). */ removeSource(id: number): boolean; /** Releases per-source CPU query caches alongside the base mesh resources. */ dispose(): void; /** Nearest undisplaced center, ranked after source placement and the outer world transform. */ queryNearest(worldPoint: THREE.Vector3, radius: number): SplatNearestResult | null; /** Highest placed center beneath a world point, with world-Y drop and horizontal tolerance. */ queryHeight(worldPoint: THREE.Vector3, maxDrop: number, radius?: number): SplatHeightResult | null; /** First placed center inside the world-space ray cone; retains a linear scan. */ queryRay(ray: THREE.Ray, radiusAtUnitDistance?: number, minimumRadius?: number): SplatRayResult | null; private visitQueryCenters; /** Recomputes a source's world matrix (placement ยท correction) and republishes it. */ private applyPlacement; /** Sort depth is quantized over the world span of every source, not the pool's local box. */ protected refreshSortBounds(): void; /** * Mesh-local bounds spanning every source at its **current placement** - * the pool's own box would be the union of the sources' data frames, which * is not where any of them is drawn. Each source's data-frame box is * transformed by its matrix, so a rotated source contributes the (standard, * conservative) axis-aligned box of its rotated bounds. * * Hosts use this to place effects, so it has to agree with what * `ctx.localCenter` reports; it tracks {@link setSourceTransform}. */ computeSplatBounds(): THREE.Box3; }