@playcanvas/splat-transform
Version:
Library and CLI tool for 3D Gaussian splat format conversion and transformation
52 lines (51 loc) • 1.89 kB
TypeScript
import { DataTable } from '../data-table';
interface KdTreeNode {
index: number;
count: number;
left?: KdTreeNode;
right?: KdTreeNode;
}
declare class KdTree {
centroids: DataTable;
root: KdTreeNode;
private colData;
constructor(centroids: DataTable);
findNearest(point: Float32Array, filterFunc?: (index: number) => boolean): {
index: number;
distanceSqr: number;
cnt: number;
};
findKNearest(point: Float32Array, k: number, filterFunc?: (index: number) => boolean): {
indices: Int32Array<ArrayBuffer>;
distances: Float32Array<ArrayBuffer>;
};
/**
* Flatten the tree into GPU-friendly typed arrays. Each tree node is
* assigned a tree-index in pre-order DFS. The arrays are parallel:
* for tree-index `t`, the node holds splat `nodeSplatIdx[t]` whose
* position is `(nodeX[t], nodeY[t], nodeZ[t])`. Children live at
* `nodeLeft[t]` and `nodeRight[t]` (tree indices), with the sentinel
* `0xFFFFFFFF` for missing children.
*
* Positions are denormalised at each tree node (rather than indirected
* through `nodeSplatIdx` + the source position arrays) so a tree-walk
* does one read per visit instead of two. Costs 12 bytes/node extra.
*
* Layout assumes the underlying `centroids` DataTable has columns
* `x`, `y`, `z` (the first three columns). The constructor accepts
* any column set, so callers must ensure these are present and first.
*
* @returns Parallel arrays of length N where N = number of points.
* The root is at index 0.
*/
flattenForGpu(): {
nodeSplatIdx: Uint32Array;
nodeX: Float32Array;
nodeY: Float32Array;
nodeZ: Float32Array;
nodeLeft: Uint32Array;
nodeRight: Uint32Array;
rootIdx: number;
};
}
export { KdTreeNode, KdTree };