UNPKG

@playcanvas/splat-transform

Version:

Library and CLI tool for 3D Gaussian splat format conversion and transformation

113 lines (112 loc) 4.1 kB
import { Transform } from '../utils'; /** * Union of all typed array types supported for column data. */ type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array; /** * String identifiers for typed array element types. */ type ColumnType = 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'float32' | 'float64'; /** * A named column of typed array data within a DataTable. * * Columns store homogeneous numeric data efficiently using JavaScript typed arrays. * * @example * ```ts * const positions = new Column('x', new Float32Array([1.0, 2.0, 3.0])); * console.log(positions.name); // 'x' * console.log(positions.dataType); // 'float32' * ``` */ declare class Column { name: string; data: TypedArray; constructor(name: string, data: TypedArray); get dataType(): ColumnType | null; clone(): Column; } /** * A row object mapping column names to numeric values. * @ignore */ type Row = { [colName: string]: number; }; /** * A table of columnar data representing Gaussian splat properties. * * DataTable is the core data structure for splat data. Each column represents * a property (e.g., position, rotation, color) as a typed array, and all columns * must have the same number of rows. * * Standard columns include: * - Position: `x`, `y`, `z` * - Rotation: `rot_0`, `rot_1`, `rot_2`, `rot_3` (quaternion) * - Scale: `scale_0`, `scale_1`, `scale_2` (log scale) * - Color: `f_dc_0`, `f_dc_1`, `f_dc_2` (spherical harmonics DC) * - Opacity: `opacity` (logit) * - Spherical Harmonics: `f_rest_0` through `f_rest_44` * * @example * ```ts * const table = new DataTable([ * new Column('x', new Float32Array([0, 1, 2])), * new Column('y', new Float32Array([0, 0, 0])), * new Column('z', new Float32Array([0, 0, 0])) * ]); * console.log(table.numRows); // 3 * console.log(table.numColumns); // 3 * ``` */ declare class DataTable { columns: Column[]; transform: Transform; constructor(columns: Column[], transform?: Transform); get numRows(): number; getRow(index: number, row?: Row, columns?: Column[]): Row; setRow(index: number, row: Row, columns?: Column[]): void; get numColumns(): number; get byteLength(): number; get columnNames(): string[]; get columnData(): TypedArray[]; get columnTypes(): ColumnType[]; getColumn(index: number): Column; getColumnIndex(name: string): number; getColumnByName(name: string): Column | null; hasColumn(name: string): boolean; addColumn(column: Column): void; removeColumn(name: string): boolean; /** * Creates a copy of this DataTable, optionally selecting specific rows and/or columns. * * @param options - Optional selection criteria. * @param options.rows - Row indices to include (and their order). If omitted, all rows are copied. * @param options.columns - Column names to include. If omitted, all columns are copied. * @returns A new DataTable with copied data. * * @example * ```ts * const full = table.clone(); * const subset = table.clone({ rows: [0, 2, 4], columns: ['x', 'y', 'z'] }); * ``` */ clone(options?: { rows?: Uint32Array | number[]; columns?: string[]; }): DataTable; /** * Permutes the rows of this DataTable in-place according to the given indices. * After calling, row `i` will contain the data that was previously at row `indices[i]`. * * This is a memory-efficient alternative to `clone({ rows })` that modifies the table * in-place rather than creating a copy. It reuses ArrayBuffers between columns to * minimize memory allocations. * * @param indices - Array of indices defining the permutation. Must have the same * length as the number of rows, and must be a valid permutation * (each index 0 to n-1 appears exactly once). */ permuteRowsInPlace(indices: Uint32Array | number[]): void; } export { Column, DataTable, TypedArray, ColumnType, Row };