import { Color, Mesh, Object3D } from 'three'; import { type FuelSettings } from '../engine/fuel.ts'; import { type LightingDivisor, type BrickSize, type SmokeDivisor, type VelocityDivisor } from '../engine/types.ts'; export type DeepReadonly = { readonly [Key in keyof T]: T[Key] extends object ? DeepReadonly : T[Key]; }; export type ColorValue = Color | number | `#${string}`; export type Vec3 = [number, number, number]; export type ReconstructionFilter = 'trilinear' | 'quadratic' | 'cubic'; /** Flame lifetime response: how long flames live, what they produce and how they look. */ export interface FlameOptions { /** Seconds for a flame's normalized remaining lifetime to decay from one to zero. */ lifespan?: number; /** Peak relative heat production per second, weighted by the flame's remaining lifetime. */ heatRate?: number; /** Peak relative smoke production per second, weighted by the flame's remaining lifetime. */ smokeRate?: number; /** Gas expansion produced over the flame lifetime, in 1/s; also the expansion for each * unit of fuel burned a second. */ expansionRate?: number; /** Exponential heat decay rate in 1/s. */ cooling?: number; color?: ColorValue; brightness?: number; /** Flame absorption per meter at full glow; also scales its emission. Defaults to 0.55. */ opacity?: number; /** Maximum blackbody temperature, in kelvin, used for flame color. */ temperature?: number; /** Thermal glow from hot smoke. */ sootGlow?: number; } export interface SmokeOptions { /** Exponential smoke decay rate in 1/s. */ dissipation?: number; color?: ColorValue; /** Light extinction per unit of smoke. */ density?: number; /** Henyey–Greenstein anisotropy from -0.9 to 0.9. */ scattering?: number; /** Extinction multiplier for self-shadowing from directional light. */ shadowDensity?: number; } export interface MotionOptions { /** Upward acceleration per unit heat. */ buoyancy?: number; /** Downward acceleration per unit smoke. */ smokeWeight?: number; /** Exponential velocity decay rate in 1/s. */ damping?: number; /** Vorticity-confinement strength; adds small swirling detail. */ vorticity?: number; } /** Optional fuel. Emitters and explosions supply fuel that the flow carries; where it is * hot enough it burns as flame, its amount up to 1 the flame's lifetime, and the flame * settings give its heat, smoke and expansion. The gas also expands as the fuel burns, by * the flame's expansion rate for each unit burned a second. */ export interface FuelOptions { enabled?: boolean; /** Heat required before fuel burns. */ ignitionHeat?: number; /** First-order fuel consumption in 1/s. */ burnRate?: number; } export interface LightingOptions { /** Light nearby scene surfaces from the flames: a point light for each emitter and each * burning explosion, at the flames nearest it. With Three.js ClusteredLighting every one * is a light of its own; otherwise four lights go to those brightest at the camera. */ illuminateScene?: boolean; intensity?: number; } export interface RenderingOptions { /** Incident-light cells per fine field cell along each axis: 1, 2 or 4. Defaults to 4. */ lightingDivisor?: LightingDivisor; /** Field reconstruction; trilinear is fastest, cubic is smoothest. */ filter?: ReconstructionFilter; /** Most volume samples a ray takes. Rays take two a voxel, fewer when they are long. */ raySteps?: number; /** March every other pixel on each axis, then finish each pixel's clipped end at * full resolution. About a quarter of the cost, with slightly softer detail. */ halfResolution?: boolean; } /** Where the simulation stores and computes cells. It holds only the flame, smoke and * fuel above the cutoff, plus the sources, and grows and shrinks with them. Heat alone is * invisible and does not hold it. */ export interface GridOptions { /** Most cells the simulation may store and compute. When the content needs more, the * cells past the budget stay empty. */ maxVoxels?: number; /** Smoke and fuel density, and remaining flame lifetime from 0 to 1, below which * they no longer hold cells open. */ cutoff?: number; /** A solid ground below world y = 0. */ ground?: boolean; } /** Settings that can change at any time through `simulation.configure()`. */ export interface SimulationConfigureOptions { grid?: GridOptions; flame?: FlameOptions; smoke?: SmokeOptions; motion?: MotionOptions; fuel?: FuelOptions; lighting?: LightingOptions; rendering?: RenderingOptions; } /** * The simulation runs in world space and has no fixed extent: it holds the content * wherever it is, in cells of `voxelSize`. */ export interface SimulationOptions extends SimulationConfigureOptions { /** Edge length of one flame, heat and fuel cell, in meters. */ voxelSize?: number; /** Velocity and pressure cells are `velocityDivisor` times larger: 1, 2 or 4. */ velocityDivisor?: VelocityDivisor; /** Fine cells per brick side: 8, 16 or 32. Independent of velocity resolution. Defaults to 16. */ brickSize?: BrickSize; /** Smoke simulation/transport cells are 1, 2 or 4 times the voxel size. Defaults to 1. */ smokeDivisor?: SmokeDivisor; /** Bounded MacCormack transport for scalar fields and smoke. Defaults to true. */ scalarMacCormack?: boolean; /** Integer seed for repeatable variation. */ seed?: number; } export interface EmissionOptions { /** Normalized flame lifetime supplied by the source, from 0 to 1. */ flame?: number; heatRate?: number; smokeRate?: number; /** Fuel added per second; requires `fuel.enabled` on the simulation. */ fuelRate?: number; } export interface VelocityOptions { direction?: Vec3; speed?: number; } export type EmitterShape = { type: 'sphere'; radius?: number; } | { type: 'mesh'; object: Mesh; }; export interface EmitterOptions { shape?: EmitterShape; active?: boolean; emission?: EmissionOptions; velocity?: VelocityOptions | null; } export interface EmitterPatch extends Omit { /** Sphere emitters can change radius; the shape type is construction-only. */ shape?: { radius?: number; }; } export interface ExplosionOptions { radius?: number; charge?: { flame?: number; heat?: number; smoke?: number; fuel?: number; }; outwardSpeed?: number; /** Initial heat/lifetime variation, sampled once when the burst is injected. */ variation?: { /** Base noise spacing in meters; larger values make broader patches. */ period?: number; /** Maximum fractional reduction of heat/lifetime, from 0 (off) to 1. */ strength?: number; }; } export type ForceOptions = { type: 'wind'; direction: Vec3; /** Acceleration in m/s². */ strength: number; active?: boolean; } | { type: 'turbulence'; strength: number; /** Noise spatial frequency in 1/m. */ scale: number; active?: boolean; } | { type: 'vortex'; /** Center in world coordinates. */ center?: Vec3; axis?: Vec3; /** Tangential acceleration; negative reverses rotation. */ strength: number; radius?: number; lift?: number; inward?: number; active?: boolean; } | { type: 'radial'; center?: Vec3; /** Positive pushes outward; negative pulls inward. */ strength: number; radius?: number; active?: boolean; }; export type ForcePatch = Partial, 'type'>> | Partial, 'type'>> | Partial, 'type'>> | Partial, 'type'>>; export type ColliderShape = { type: 'sphere'; radius: number; } | { type: 'box'; size: Vec3; } | { type: 'mesh'; }; /** `object` supplies the collider's transform; mesh colliders also use its geometry. */ export type ColliderOptions = { object: Object3D; shape: Exclude; } | { object: Mesh; shape: { type: 'mesh'; }; }; /** What the renderer shows: the final image, or one field. Vorticity is computed from the * velocity; expansion is the flames' target divergence; pressure and divergence are the * solver's, copied for the view after every step. */ export declare const DEBUG_FIELDS: readonly ['beauty', 'lifetime', 'heat', 'smoke', 'velocity', 'flame', 'fuel', 'vorticity', 'expansion', 'pressure', 'divergence']; export type DebugField = (typeof DEBUG_FIELDS)[number]; /** Each debug view's heat map: it spans values from 0 to `range`, or from -range to range * when `signed`, in `unit`. Velocity and vorticity show their magnitudes. */ export declare const DEBUG_SCALES: Readonly, { range: number; signed: boolean; unit: string; }>>; export interface DebugOptions { /** Outline the bricks the solver computes. */ bricks?: boolean; field?: DebugField; } type ResolvedColor = Omit, 'color'> & { color: string; }; export interface ResolvedSimulationOptions { voxelSize: number; velocityDivisor: VelocityDivisor; brickSize: BrickSize; smokeDivisor: SmokeDivisor; scalarMacCormack: boolean; seed: number; grid: Required; flame: ResolvedColor; smoke: ResolvedColor; motion: Required; fuel: FuelSettings; lighting: Required; rendering: Required; } export interface ResolvedEmitterOptions { shape: { type: 'sphere'; radius: number; } | { type: 'mesh'; }; active: boolean; emission: Required; velocity: Required | null; } export interface ResolvedExplosionOptions { radius: number; charge: { flame: number; heat: number; smoke: number; fuel: number; }; outwardSpeed: number; variation: { period: number; strength: number; }; } export type ResolvedForceOptions = Required> | Required> | Required> | Required>; /** Invalid patches reject before any state is changed. Unknown keys are errors. */ export declare function keys(value: unknown, allowed: readonly string[], label: string): void; export declare function number(value: unknown, label: string, min?: number, max?: number): number; export declare function boolean(value: unknown, label: string): boolean; export declare function vector(value: unknown, label: string, min?: number, max?: number): Vec3; export declare function direction(value: unknown, label: string): Vec3; type ConstructionKey = 'voxelSize' | 'brickSize' | 'velocityDivisor' | 'smokeDivisor' | 'scalarMacCormack' | 'seed'; type ResolvedSettings = Omit; /** Valid [min, max] of every numeric option. Validation and editors both read it. */ export declare const LIMITS: { readonly simulation: { readonly voxelSize: readonly [0.002, 4]; }; readonly grid: { readonly maxVoxels: readonly [4096, 268435456]; readonly cutoff: readonly [0, 1]; }; readonly flame: { readonly lifespan: readonly [0.01, 5]; readonly heatRate: readonly [0, 20]; readonly smokeRate: readonly [0, 20]; readonly expansionRate: readonly [0, 20]; readonly cooling: readonly [0, 20]; readonly brightness: readonly [0, 20]; readonly opacity: readonly [0, 20]; readonly temperature: readonly [800, 10000]; readonly sootGlow: readonly [0, 5]; }; readonly smoke: { readonly dissipation: readonly [0, 20]; readonly density: readonly [0, 20]; readonly scattering: readonly [-0.9, 0.9]; readonly shadowDensity: readonly [0, 20]; }; readonly motion: { readonly buoyancy: readonly [0, 20]; readonly smokeWeight: readonly [0, 20]; readonly damping: readonly [0, 20]; readonly vorticity: readonly [0, 20]; }; readonly fuel: { readonly ignitionHeat: readonly [0, 100]; readonly burnRate: readonly [0, 100]; }; readonly lighting: { readonly intensity: readonly [0, 20]; }; readonly rendering: { readonly raySteps: readonly [8, 1024]; }; readonly emitter: { readonly radius: readonly [0.01, 16]; readonly flame: readonly [0, 1]; readonly rate: readonly [0, 100]; readonly speed: readonly [0, 50]; }; readonly explosion: { readonly radius: readonly [0.01, 16]; readonly outwardSpeed: readonly [0, 50]; readonly period: readonly [0.01, 32]; readonly strength: readonly [0, 1]; readonly flame: readonly [0, 1]; readonly amount: readonly [0, 100]; }; readonly wind: { readonly strength: readonly [0, 50]; }; readonly turbulence: { readonly strength: readonly [0, 50]; readonly scale: readonly [0.01, 32]; }; readonly vortex: { readonly strength: readonly [-50, 50]; readonly radius: readonly [0.01, 32]; readonly lift: readonly [-50, 50]; readonly inward: readonly [0, 50]; }; readonly radial: { readonly strength: readonly [-50, 50]; readonly radius: readonly [0.01, 32]; }; readonly collider: { readonly radius: readonly [0.01, 32]; readonly size: readonly [0.01, 64]; }; }; export declare const GROUPS: readonly ['grid', 'flame', 'smoke', 'motion', 'fuel', 'lighting', 'rendering']; /** Merge a configurable patch into resolved settings, validating every supplied value. */ export declare function resolveSettings(patch: SimulationConfigureOptions, previous?: ResolvedSettings): ResolvedSettings; export declare function resolveSimulation(options?: SimulationOptions): ResolvedSimulationOptions; export type EmitterKind = 'fire' | 'jet' | 'smoke' | 'emitter'; export declare function emitterDefaults(kind: EmitterKind): ResolvedEmitterOptions; export declare function resolveEmitter(patch: EmitterPatch | EmitterOptions, previous: ResolvedEmitterOptions, constructing?: boolean): ResolvedEmitterOptions; export declare function resolveExplosion(patch?: ExplosionOptions, previous?: ResolvedExplosionOptions): ResolvedExplosionOptions; export declare function resolveForce(patch: ForceOptions | ForcePatch, previous?: ResolvedForceOptions): ResolvedForceOptions; export declare function resolveCollider(options: ColliderOptions): ColliderOptions; export {};