import * as THREE from 'three/webgpu'; import type { Vector3 } from 'three/webgpu'; import type { TSLFloatNode, TSLStorageNode, TSLUniformNode } from '../../types/tsl.js'; /** Pixel dimensions and grid layout of a generated Boids debug atlas. */ export interface NumberTextureAtlasDimensions { width: number; height: number; cellWidth: number; cellHeight: number; numbersPerRow: number; totalRows: number; } /** Texture and layout metadata for the Boids debug atlas. */ export interface NumberTextureAtlasResult { map: THREE.CanvasTexture; dimensions: NumberTextureAtlasDimensions; } export interface SpatialGridHelperSimulationBuffers { positions: TSLStorageNode<'vec3'>; debug?: { cellId: TSLStorageNode<'uint'>; } | undefined; } export interface SpatialGridHelperSimulationUniforms { domainDimensions: TSLUniformNode<'vec3', Vector3>; zoneRadius?: TSLFloatNode | undefined; } export interface SpatialGridHelperSimulation { is3D: boolean; debug: boolean; particleCount: number; gridCellSize: Vector3; ubos: SpatialGridHelperSimulationUniforms; buffers: SpatialGridHelperSimulationBuffers; helper?: SpatialGridHelper | null | undefined; } interface DisposableGridLines extends THREE.LineSegments { dispose(): void; } /** * Helper for visualizing the spatial grid used by particle simulations. * * @class SpatialGridHelper * @short Helper that visualizes particle spatial grid cells and optionally labels cell IDs. * @category Simulation * @tags WebGPU * * @param {Object} simulation - The simulation object (SPH, Boids) to which the helper is attached. * @param {boolean} [showTexts=true] - Whether to show cell IDs as text. * * @example * ```js * import { SPH } from 'three-blocks'; * import { SpatialGridHelper } from 'three-blocks/boids'; * import * as THREE from 'three/webgpu'; * * // Create SPH simulation with spatial grid enabled * const sph = new SPH({ * count: 4096, * is3D: true, * domainDimensions: new THREE.Vector3(20, 20, 20), * h: 1.0, * useSpatialGrid: true, * debug: true * }); * * // Create and attach grid helper for visualization * const gridHelper = new SpatialGridHelper(sph, true); * scene.add(gridHelper); * * // Optional: Update helper when domain changes * sph.setDomainFromObject(mesh); * gridHelper.init(); // Rebuild grid visualization * * // Clean up * gridHelper.dispose(); * sph.dispose(); * ``` */ declare class SpatialGridHelper extends THREE.Object3D { /** Borrowed simulation whose grid is visualized. */ simulation: SpatialGridHelperSimulation; _showTexts: boolean; _helper: DisposableGridLines | null; _helperText: THREE.Mesh | undefined; /** Number-label texture atlas owned by the helper, or `null` before initialization. */ atlasNumber: NumberTextureAtlasResult | null; /** Create and initialize a grid visualization for a simulation. */ constructor(simulation: SpatialGridHelperSimulation, showTexts?: boolean); /** Rebuild the grid-line visualization from the simulation's current domain. */ init(): void; /** Add instanced numeric cell labels using the helper's texture atlas. */ showTexts(): void; /** Remove the helper geometry and labels from their scene and release their resources. */ dispose(): void; } export { SpatialGridHelper };