export { computeSOGChunkBounds } from './SOGChunkBounds.js'; import * as THREE from 'three/webgpu'; import type { StorageBufferNode, StorageInstancedBufferAttribute, UniformNode } from 'three/webgpu'; import type { TSLFloatNode, TSLUintNode, TSLVec3Node, TSLVec4Node } from '../types/tsl.js'; /** Storage/dequantization modes supported by Gaussian source resources. */ export type SplatSourceMode = 'expanded' | 'compact' | 'sog' | 'spacetime' | 'video'; /** Fixed-width source-space vector used by SOG metadata. */ export type SOGVector3 = readonly [number, number, number]; /** Fixed-width source-space vector with an opacity component. */ export type SOGVector4 = readonly [number, number, number, number]; /** Decoded RGBA image used by direct SOG resources. */ export interface SOGImage { data: Uint8Array | Uint8ClampedArray; width: number; height: number; } /** Required direct-SOG image planes. */ export interface SOGImages { means_l: SOGImage; means_u: SOGImage; quats: SOGImage; scales: SOGImage; sh0: SOGImage; [name: string]: SOGImage; } /** Numeric range/codebook metadata for one SOG attribute group. */ export interface SOGAttributeMetadata> { mins?: TVector | undefined; maxs?: TVector | undefined; codebook?: readonly (number | null)[] | null | undefined; [key: string]: unknown; } /** Normalized metadata surface consumed by direct SOG decoding. */ export interface SOGMetadata { means?: SOGAttributeMetadata | undefined; scales?: SOGAttributeMetadata | undefined; sh0?: SOGAttributeMetadata | undefined; mins?: SOGVector3 | undefined; maxs?: SOGVector3 | undefined; [key: string]: unknown; } /** Raw decoded SOG payload retained for direct packed rendering. */ export interface SOGSource { version: number; meta: SOGMetadata; images: SOGImages; } /** Float attributes shared by expanded and compact source resources. */ export interface SplatSourceData { positions: Float32Array | null; scales: Float32Array | null; rotations: Float32Array | null; colors: Float32Array | null; sogSource?: SOGSource | null | undefined; /** Pre-interleaved [position, scale] vec4 pairs in the expanded GPU layout (loader fused pack). */ packedPositionsScales?: Float32Array | null | undefined; /** Pre-interleaved [rotation, color] vec4 pairs in the expanded GPU layout (loader fused pack). */ packedRotationsColors?: Float32Array | null | undefined; } /** Source data carrying loader-packed expanded GPU layouts. */ export interface PackedExpandedSplatSourceData extends SplatSourceData { packedPositionsScales: Float32Array; packedRotationsColors: Float32Array; } /** Source data whose four expanded float attributes are resident on the CPU. */ export interface ExpandedSplatSourceData extends SplatSourceData { positions: Float32Array; scales: Float32Array; rotations: Float32Array; colors: Float32Array; } /** Source data carrying the direct packed SOG payload. */ export interface DirectSOGSplatSourceData extends SplatSourceData { sogSource: SOGSource; } /** TSL readers consumed by projection and animation compute graphs. */ export interface SplatSourceReadNodes { readPosition(index: TSLUintNode): TSLVec3Node; readScale(index: TSLUintNode): TSLVec3Node; readRotation(index: TSLUintNode): TSLVec4Node; readColor(index: TSLUintNode): TSLVec4Node; readAlpha(index: TSLUintNode): TSLFloatNode; } type FloatStorageNode = StorageBufferNode & { value: StorageInstancedBufferAttribute & { array: Float32Array; }; }; type UintStorageNode = StorageBufferNode<'uint'> & { value: StorageInstancedBufferAttribute & { array: Uint32Array; }; }; /** GPU allocations used by the expanded float source. */ export interface ExpandedSplatGPUResources { positionsScales: FloatStorageNode<'vec4'>; rotationsColors: FloatStorageNode<'vec4'>; } /** GPU allocations used by the compact source. */ export interface CompactSplatGPUResources { positions: FloatStorageNode<'vec3'>; packedAttributes: UintStorageNode; } /** GPU allocations used by the direct packed SOG source. */ export interface SOGSplatGPUResources { sogPacked: UintStorageNode; sogScaleCodebook: FloatStorageNode<'float'> | null; sogSH0Codebook: FloatStorageNode<'float'> | null; } /** Expanded ranged-write payload used by streaming residency. */ export interface ExpandedSplatUploadData { positions: Float32Array; scales: Float32Array; rotations: Float32Array; colors: Float32Array; } /** Source factory options. */ export interface SplatSourceResourceOptions { attributeMode?: 'expanded' | 'compact' | 'sog' | 'auto' | undefined; compactAllowColorClamping?: boolean | undefined; capacity?: number | undefined; } /** * Base adapter for Gaussian splat source attributes. * * @class SplatSourceResource * @short Internal source adapter for expanded and compact Gaussian splat GPU attributes. * @category GaussianSplatting */ export declare class SplatSourceResource { data: TData; count: number; capacity: number; mode: SplatSourceMode; cpuBytes: number; gpuBytes: number; /** CPU time spent submitting the current frame's source upload, when applicable. */ frameUploadMilliseconds: number | null; /** Compute context dispatched to resolve the current frame's source attributes. */ frameTimestampContext: unknown | null; constructor(data: TData, count: number, capacity?: number); createGPUResources(): TGPUResources; upload(buffers: TGPUResources): void; buildReadNodes(buffers: TGPUResources): SplatSourceReadNodes; /** * A flat, comparable signature of this source's shader-side dequantization configuration (value * ranges + codebooks). Two same-mode sources with equal signatures decode identically, so a * sequence can reuse resident buffers across them (only the packed data is re-uploaded) instead of * reallocating to rebuild the compute graph. Expanded floats carry no dequant config → empty. * * @returns {number[]} Comparable signature (compared element-wise). */ rangeSignature(): number[]; dispose(): void; readPositionsCPU(): Float32Array | null; readScalesCPU(): Float32Array | null; readRotationsCPU(): Float32Array | null; readColorsCPU(): Float32Array | null; } /** Expanded float validation source. */ export declare class ExpandedFloatSplatSource extends SplatSourceResource { constructor(data: ExpandedSplatSourceData, count: number, capacity?: number); createGPUResources(): ExpandedSplatGPUResources; upload(buffers: ExpandedSplatGPUResources): void; /** * Partial upload for streaming residency (GaussianSplatsStream): packs `count` splats from * plain arrays into the interleaved GPU layout starting at destination slot `dstIndex`, and * registers buffer update ranges so only the touched bytes travel to the GPU (three's WebGPU * backend honors BufferAttribute.updateRanges with partial writeBuffer calls). * * @param {Object} buffers GPU resources created by createGPUResources(). * @param {number} dstIndex First destination splat slot. * @param {{positions:Float32Array, scales:Float32Array, rotations:Float32Array, colors:Float32Array}|null} data * Source arrays indexed from `srcIndex`, or null to zero-fill (alpha 0 — projection-culled). * @param {number} srcIndex First source splat index within `data`. * @param {number} count Number of splats to write. */ uploadRange(buffers: ExpandedSplatGPUResources, dstIndex: number, data: ExpandedSplatUploadData | null, srcIndex: number, count: number): void; buildReadNodes(buffers: ExpandedSplatGPUResources): SplatSourceReadNodes; } /** * Expanded source backed by loader-packed GPU-layout arrays (fused pack path). * * When the resident capacity equals the asset count, the packed arrays are wrapped as the * storage attributes directly — zero CPU-side copying, and the loader-transferred arrays ARE * the upload staging memory. Reads, layout, and ranged writes are identical to * {@link ExpandedFloatSplatSource}. */ export declare class PackedExpandedFloatSplatSource extends SplatSourceResource { constructor(data: PackedExpandedSplatSourceData, count: number, capacity?: number); createGPUResources(): ExpandedSplatGPUResources; upload(buffers: ExpandedSplatGPUResources): void; uploadRange(buffers: ExpandedSplatGPUResources, dstIndex: number, data: ExpandedSplatUploadData | null, srcIndex: number, count: number): void; buildReadNodes(buffers: ExpandedSplatGPUResources): SplatSourceReadNodes; readPositionsCPU(): Float32Array | null; readScalesCPU(): Float32Array | null; readRotationsCPU(): Float32Array | null; readColorsCPU(): Float32Array | null; private _deinterleave; } /** Compact 24-byte source: float center plus three packed uint attributes. */ export declare class CompactSplatSource extends SplatSourceResource { scaleMin: [number, number, number]; scaleMax: [number, number, number]; clampedColors: number; scaleMinUniform: UniformNode<'vec3', THREE.Vector3>; scaleRangeUniform: UniformNode<'vec3', THREE.Vector3>; constructor(data: ExpandedSplatSourceData, count: number, capacity?: number); private _prepareRanges; rangeSignature(): number[]; createGPUResources(): CompactSplatGPUResources; upload(buffers: CompactSplatGPUResources): void; buildReadNodes(buffers: CompactSplatGPUResources): SplatSourceReadNodes; } /** Direct SOG source: packed decoded image pixels with shader-side attribute dequantization. */ export declare class SOGSplatSource extends SplatSourceResource { sog: SOGSource; version: number; meta: SOGMetadata; images: SOGImages; scaleCodebook: Float32Array | null; sh0Codebook: Float32Array | null; meansMinUniform: UniformNode<'vec3', THREE.Vector3>; meansRangeUniform: UniformNode<'vec3', THREE.Vector3>; scaleMinUniform: UniformNode<'vec3', THREE.Vector3>; scaleRangeUniform: UniformNode<'vec3', THREE.Vector3>; sh0MinUniform: UniformNode<'vec4', THREE.Vector4>; sh0RangeUniform: UniformNode<'vec4', THREE.Vector4>; constructor(data: DirectSOGSplatSourceData, count: number, capacity?: number); private _normalizeCodebook; rangeSignature(): number[]; createGPUResources(): SOGSplatGPUResources; upload(buffers: SOGSplatGPUResources): void; buildReadNodes(buffers: SOGSplatGPUResources): SplatSourceReadNodes; readPositionsCPU(): Float32Array; readScalesCPU(): Float32Array; readRotationsCPU(): Float32Array; readColorsCPU(): Float32Array; } export declare function createSplatSourceResource(data: SplatSourceData, count: number, options?: SplatSourceResourceOptions): ExpandedFloatSplatSource | PackedExpandedFloatSplatSource | CompactSplatSource | SOGSplatSource;