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.
39 lines (38 loc) • 2.25 kB
TypeScript
/**
* `buildVirtualMeshCached`: `buildVirtualMesh` behind a persistent IndexedDB cache, keyed by a SHA-256 of the
* source arrays and build options. The first load builds and stores the encoded result; later loads decode
* it. Any cache problem (no IndexedDB, private mode, quota, corrupt entry) falls back to building.
*/
import { type VirtualMeshBuildOptions, type VirtualMeshData, type VirtualMeshSource } from '../preprocess/buildVirtualMesh.js';
/**
* Part of every cache key. Bump it whenever `buildVirtualMesh` produces different output for the same input
* (algorithm or default changes), so stale cached builds are never returned.
*/
export declare const VG_BUILD_VERSION = 8;
export interface VirtualGeometryCacheOptions {
/**
* Fixed cache key instead of a content hash (skips hashing the source). You must change it whenever the
* source mesh or build options change.
*/
key?: string;
/** 'indexeddb' (default) or false to always build. */
store?: 'indexeddb' | false;
/**
* Least recently used entries are evicted when the cache grows above this many bytes. Default 512 MB. Raise it for
* scenes with many multi-million-triangle meshes, so every build stays cached; the browser's own storage quota
* still applies (a write that exceeds it is skipped, never an error).
*/
maxBytes?: number;
}
export interface VirtualGeometryCachedBuildOptions extends VirtualMeshBuildOptions {
cache?: VirtualGeometryCacheOptions;
}
/**
* Same as `buildVirtualMesh`, plus a persistent cache. On a hit the build is skipped, `onProgress(1)` is still
* called, and `stats.buildMs` reports the time this call took (hashing, lookup and decoding).
*/
export declare function buildVirtualMeshCached(source: VirtualMeshSource, options?: VirtualGeometryCachedBuildOptions): Promise<VirtualMeshData>;
/** Deletes every cached build. Resolves even if IndexedDB is unavailable. */
export declare function clearVirtualMeshCache(): Promise<void>;
/** SHA-256 over every source field (typed arrays by content), the build options and the format versions. */
export declare function virtualMeshCacheKey(source: VirtualMeshSource, options?: VirtualMeshBuildOptions, customKey?: string): Promise<string>;