@playcanvas/splat-transform
Version:
Library and CLI tool for 3D Gaussian splat format conversion and transformation
56 lines (55 loc) • 2.31 kB
TypeScript
import type { Bounds } from '../data-table';
import { SparseVoxelGrid } from '../voxel/sparse-voxel-grid';
/**
* Solid leaf node marker: childMask = 0xFF, baseOffset = 0.
* This is unambiguous because BFS layout guarantees children always come after
* their parent, so baseOffset = 0 is never valid for an interior node.
*/
declare const SOLID_LEAF_MARKER: number;
/**
* Sparse voxel octree using Laine-Karras node format.
*/
interface SparseOctree {
/** Grid bounds aligned to 4x4x4 block boundaries */
gridBounds: Bounds;
/** Original Gaussian scene bounds */
sceneBounds: Bounds;
/** Size of each voxel in world units */
voxelResolution: number;
/** Voxels per leaf dimension (always 4) */
leafSize: number;
/** Maximum tree depth */
treeDepth: number;
/** Number of interior nodes */
numInteriorNodes: number;
/** Number of mixed leaf nodes */
numMixedLeaves: number;
/** All nodes in Laine-Karras format (interior + leaves) */
nodes: Uint32Array;
/** Voxel masks for mixed leaves: pairs of u32 (lo, hi) */
leafData: Uint32Array;
}
interface BuildSparseOctreeOptions {
/** Release the input grid's backing storage after the octree has copied the data it needs. */
consumeGrid?: boolean;
/** Force dense-mip construction; intended for tests and benchmarks. */
dense?: boolean;
}
/**
* Build a sparse octree from a SparseVoxelGrid.
*
* Walks the grid's `types` array word-by-word (skipping empty words), counts
* solid + mixed blocks, then emits Morton-keyed (solidStream, mixedStream,
* mixedMasks) typed arrays sized exactly. The streams are then sorted; this
* is the only place Morton encoding is paid in the post-voxelization pipeline.
*
* @param grid - SparseVoxelGrid containing voxelized blocks.
* @param gridBounds - Grid bounds aligned to block boundaries
* @param sceneBounds - Original scene bounds
* @param voxelResolution - Size of each voxel in world units
* @param options - Build options.
* @returns Sparse octree structure
*/
declare function buildSparseOctree(grid: SparseVoxelGrid, gridBounds: Bounds, sceneBounds: Bounds, voxelResolution: number, options?: BuildSparseOctreeOptions): SparseOctree;
export { buildSparseOctree, SOLID_LEAF_MARKER };
export type { SparseOctree };