three-virtual-geometry
Version:
Virtual geometry for three.js WebGPU: automatic cluster LOD and GPU-driven culling for billions of triangles. Independent implementation, not affiliated with Epic Games.
31 lines (30 loc) • 1.83 kB
TypeScript
/**
* Voxel proxies for coarse LODs, for foliage and other aggregate geometry.
*
* Triangle simplification breaks down on aggregate geometry such as a tree crown made of hundreds of
* separate leaf clumps: below a few hundred triangles it can only delete or collapse whole clumps, so
* the silhouette shrinks and the LOD error jumps. A voxel proxy keeps the volume instead: the mesh is
* voxelized, gaps between clumps are closed, and a smooth closed surface is extracted (surface nets).
* That surface is one connected shape, which simplifies gracefully to a handful of triangles.
*
* Every proxy vertex lies within about one cell of the original surface, and closing fills gaps of at most
* two cells, so `VOXEL_ERROR_CELLS * cellSize` bounds how far the proxy deviates from the original.
*/
/** Deviation of a proxy from the source mesh, in cells (surface offset plus closed gaps). */
export declare const VOXEL_ERROR_CELLS = 2;
export interface VoxelProxy {
positions: Float32Array;
normals: Float32Array;
colors: Float32Array | null;
/** UV of a representative source sample near each vertex (null when the source has no UVs). */
uvs: Float32Array | null;
indices: Uint32Array;
cellSize: number;
}
/**
* Voxelizes the triangles `indices` of a mesh with `resolution` cells along its longest side and returns
* a closed, smooth surface around the occupied volume (null if the mesh is empty).
* With `uvs`, each proxy vertex takes the UV of the first source sample in its cell's voxels, so textured
* geometry keeps plausible colors at a distance (UVs cannot be averaged across islands).
*/
export declare function buildVoxelProxy(positions: Float32Array, colors: Float32Array | null | undefined, indices: Uint32Array, resolution: number, uvs?: Float32Array | null): VoxelProxy | null;