@margoengine/vfx 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +1642 -3
  4. package/dist/base-C9upJytz.js +658 -0
  5. package/dist/base.d.ts +767 -0
  6. package/dist/base.js +1 -0
  7. package/dist/blown-sand.d.ts +218 -0
  8. package/dist/blown-sand.js +700 -0
  9. package/dist/clouds.d.ts +229 -0
  10. package/dist/clouds.js +566 -0
  11. package/dist/compat-CVSEj1Bp.js +217 -0
  12. package/dist/compat.d.ts +59 -0
  13. package/dist/curves.d.ts +11 -0
  14. package/dist/curves.js +59 -0
  15. package/dist/debris.d.ts +111 -0
  16. package/dist/debris.js +258 -0
  17. package/dist/depth-collide.d.ts +7 -0
  18. package/dist/depth-collide.js +96 -0
  19. package/dist/emitter.d.ts +10 -0
  20. package/dist/emitter.js +125 -0
  21. package/dist/events.d.ts +9 -0
  22. package/dist/events.js +131 -0
  23. package/dist/extra-CgGjbojB.js +4 -0
  24. package/dist/extra.d.ts +2 -0
  25. package/dist/fields.d.ts +11 -0
  26. package/dist/fields.js +95 -0
  27. package/dist/fire-front.d.ts +539 -0
  28. package/dist/fire-front.js +840 -0
  29. package/dist/fire.d.ts +119 -0
  30. package/dist/fire.js +173 -0
  31. package/dist/flame-ramp-VoBKpYnM.js +75 -0
  32. package/dist/flame-ramp.d.ts +61 -0
  33. package/dist/flame.d.ts +260 -0
  34. package/dist/flame.js +605 -0
  35. package/dist/flipbook.d.ts +7 -0
  36. package/dist/flipbook.js +23 -0
  37. package/dist/fog-B-kBv7g0.js +32 -0
  38. package/dist/frame-BuvMFBPp.js +4 -0
  39. package/dist/frame.d.ts +7 -0
  40. package/dist/gunfire.d.ts +696 -0
  41. package/dist/gunfire.js +1204 -0
  42. package/dist/hash-Btsp6fGK.js +7 -0
  43. package/dist/hash.d.ts +2 -0
  44. package/dist/index.d.ts +17 -0
  45. package/dist/index.js +60 -0
  46. package/dist/json.d.ts +53 -0
  47. package/dist/json.js +237 -0
  48. package/dist/lit.d.ts +11 -0
  49. package/dist/lit.js +105 -0
  50. package/dist/mesh.d.ts +14 -0
  51. package/dist/mesh.js +225 -0
  52. package/dist/node-system.d.ts +315 -0
  53. package/dist/node-system.js +384 -0
  54. package/dist/nodes.d.ts +14 -0
  55. package/dist/nodes.js +293 -0
  56. package/dist/obstacles.d.ts +3 -0
  57. package/dist/obstacles.js +25 -0
  58. package/dist/over-life.d.ts +14 -0
  59. package/dist/over-life.js +93 -0
  60. package/dist/require-webgpu--tUXPsmA.js +7 -0
  61. package/dist/ribbons.d.ts +20 -0
  62. package/dist/ribbons.js +151 -0
  63. package/dist/schedule.d.ts +29 -0
  64. package/dist/schedule.js +47 -0
  65. package/dist/settings.d.ts +362 -0
  66. package/dist/settings.js +707 -0
  67. package/dist/shader.d.ts +44 -0
  68. package/dist/shadows.d.ts +26 -0
  69. package/dist/shadows.js +182 -0
  70. package/dist/shapes.d.ts +34 -0
  71. package/dist/shapes.js +81 -0
  72. package/dist/shared/fog.d.ts +33 -0
  73. package/dist/shared/pass.d.ts +53 -0
  74. package/dist/shared/settings.d.ts +89 -0
  75. package/dist/skinned.d.ts +11 -0
  76. package/dist/skinned.js +104 -0
  77. package/dist/smoke.d.ts +215 -0
  78. package/dist/smoke.js +280 -0
  79. package/dist/soft.d.ts +17 -0
  80. package/dist/soft.js +55 -0
  81. package/dist/solid.d.ts +168 -0
  82. package/dist/solid.js +403 -0
  83. package/dist/sort.d.ts +3 -0
  84. package/dist/sort.js +58 -0
  85. package/dist/space.d.ts +14 -0
  86. package/dist/space.js +88 -0
  87. package/dist/stretch.d.ts +7 -0
  88. package/dist/stretch.js +40 -0
  89. package/dist/texture.d.ts +8 -0
  90. package/dist/texture.js +45 -0
  91. package/dist/view-RKprOPAy.js +30 -0
  92. package/dist/view-rect-DkeiiUtw.js +13 -0
  93. package/dist/wrap.d.ts +3 -0
  94. package/dist/wrap.js +5 -0
  95. package/package.json +192 -6
@@ -0,0 +1,260 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ import type { Engine, EnginePlugin, FrameGraph } from '@margoengine/core/extension';
4
+ import type { Clustered, PointLight } from '@margoengine/clustered';
5
+ import type { LightGroups } from '@margoengine/clustered/groups';
6
+ import { type FogLike } from './shared/fog.js';
7
+ import type { VFXWind } from '@margoengine/vfx/base';
8
+ import { type FlameRampOptions } from './flame-ramp.js';
9
+ export { blackbodyChromaticity, blackbodyColor, blackbodyLuminanceRatio, blackbodyLuminousEfficacy, flameRamp, FLAME_PEAK, type FlameRampOptions, type FlameStop, } from './flame-ramp.js';
10
+ type Vec3 = readonly [number, number, number];
11
+ /** The rise speed of a flame over sqrt(g L) (Quintiere 1989's scaling, with the constant of a flame's mean rise). */
12
+ export declare const FLAME_FROUDE = 0.5;
13
+ /** The flame length of the Cabin Hearth's fire, metres: the length the hearth kit's flames rise to. */
14
+ export declare const HEARTH_FLAME_LENGTH = 0.25;
15
+ /**
16
+ * Byram's flame length of a fireline, metres: 0.0775 I^0.46 for a fireline intensity I in kW/m (Byram 1959).
17
+ * @throws RangeError for an intensity that is not a finite number of 0 or more.
18
+ * @example byramFlameLength(10000); // 5.4 m
19
+ */
20
+ export declare function byramFlameLength(intensity: number): number;
21
+ /** The fireline intensity, kW/m, whose Byram flame length is `length` metres (the inverse of {@link byramFlameLength}). */
22
+ export declare function byramIntensity(length: number): number;
23
+ /**
24
+ * Heskestad's mean flame height, metres, of a fire releasing `heat` watts over a source `diameter` metres across:
25
+ * 0.235 Q^(2/5) - 1.02 D with Q in kW, never below 0 (Heskestad 1983).
26
+ * @throws RangeError for a heat or diameter that is not a finite number of 0 or more.
27
+ * @example heskestadFlameLength(20e6, 4); // 8.3 m: a house fire through a roof breach 4 m across
28
+ */
29
+ export declare function heskestadFlameLength(heat: number, diameter: number): number;
30
+ /** Cetegen and Ahmed 1993's puffing constant: a pool fire D metres across puffs at 1.5 D^(-1/2) Hz. */
31
+ export declare const PUFFING_CONSTANT = 1.5;
32
+ /**
33
+ * The puffing frequency, Hz, of a fire `diameter` metres across: 1.5 D^(-1/2) (Cetegen and Ahmed 1993).
34
+ * @throws RangeError for a diameter that is not a finite number above 0.
35
+ * @example puffingFrequency(4); // 0.75 Hz
36
+ */
37
+ export declare function puffingFrequency(diameter: number): number;
38
+ /**
39
+ * The source diameter, metres, that sets the puffing of a footprint `[x, z]` metres: the diameter of a circle of the same
40
+ * area for a compact fire, never more than twice its narrower side, so a long line of fire puffs as its depth does.
41
+ */
42
+ export declare function puffingDiameter(footprint: readonly [number, number]): number;
43
+ /**
44
+ * The flame's light over its peak radiance times its silhouette (flame length by width): a source of radiance Lr and
45
+ * area A has intensity Lr A, so a wall it lights is never brighter than the flame (the flame fills about half of that
46
+ * rectangle, at about its peak radiance).
47
+ */
48
+ export declare const FLAME_LIGHT_FILL = 0.5;
49
+ /**
50
+ * The share of a fire's heat release that leaves as radiation (the radiative fraction chi_r): about 0.3 for wood,
51
+ * cellulosic packing and most sooty fuels in free burn (Tewarson, "Generation of Heat and Gaseous, Liquid, and Solid
52
+ * Products in Fires", SFPE Handbook of Fire Protection Engineering, 5th ed., 2016; Koseki, "Combustion properties of
53
+ * large liquid pool fires", Fire Technology 25(3), 241-255, 1989; McCaffrey, "Purely Buoyant Diffusion Flames: Some
54
+ * Experimental Results", NBSIR 79-1910, 1979).
55
+ */
56
+ export declare const FLAME_RADIANT_FRACTION = 0.3;
57
+ /**
58
+ * The luminous flux of a fire, lumens: the radiated share of its heat release (`radiantFraction` of `heat` watts) times
59
+ * the luminous efficacy of blackbody radiation at the temperature it radiates at (`kelvin`, Planck's law through the
60
+ * photopic curve). A candle (about 80 W, chi_r about 0.2, 1,850 K soot) gives about 12 lm, the one candela it was
61
+ * named for; a 1 MW wood fire at 1,760 K about 150,000 lm.
62
+ * @throws RangeError for a heat or fraction out of range, or a temperature outside 500 to 40,000 K.
63
+ * @example flameLuminousFlux(1e6, 1760); // about 150,000 lm
64
+ */
65
+ export declare function flameLuminousFlux(heat: number, kelvin: number, radiantFraction?: number): number;
66
+ /** The heat release, watts, of a flame `length` metres tall over a source `diameter` across (Heskestad 1983 turned round). */
67
+ export declare function heskestadHeat(length: number, diameter: number): number;
68
+ /** A flame's hot plume ({@link Flame.plume}): the shape `HeatHaze` of `@margoengine/post/heat-haze` reads. */
69
+ export interface FlamePlume {
70
+ /** Centre of the footprint on the fuel, world units. */
71
+ readonly position: readonly [number, number, number];
72
+ /** Flame length now, metres (0 when out). */
73
+ readonly length: number;
74
+ /** Footprint `[x, z]` before `yaw`, metres, as drawn. */
75
+ readonly footprint: readonly [number, number];
76
+ /** Turn of the footprint about +y, radians. */
77
+ readonly yaw: number;
78
+ /** Lean in the wind, `[x, z]` world metres across per metre up. */
79
+ readonly lean: readonly [number, number];
80
+ /** The flame's clock, seconds. */
81
+ readonly time: number;
82
+ }
83
+ /** `Flame.attach` settings. `position` is required, and one of `length`, `intensity` or `heat`. */
84
+ export interface FlameOptions extends FlameRampOptions {
85
+ /** Centre of the footprint on the fuel, world units. */
86
+ position: Vec3;
87
+ /** The flame length, metres, 0 to 1,000 (0 puts the flames out). Wins over `intensity` and `heat`. */
88
+ length?: number;
89
+ /** A fireline's intensity, kW/m: the length is Byram's (Byram 1959). */
90
+ intensity?: number;
91
+ /** A fire's heat release, watts: the length is Heskestad's over the footprint's diameter (Heskestad 1983). */
92
+ heat?: number;
93
+ /** Footprint `[x, z]` before `yaw`, metres, 0 or more. Default `[0.5 length, 0.5 length]`. */
94
+ footprint?: readonly [number, number];
95
+ /** Turn of the footprint about +y, radians (its x side runs along `[cos yaw, 0, -sin yaw]`). Default 0. */
96
+ yaw?: number;
97
+ /** The wind at the flames, `[x, z]` m/s or `{sample(x, y, z, t)}`: the flames lean atan(U / w) at their rise speed w. Default none. */
98
+ wind?: VFXWind;
99
+ /**
100
+ * The slope of the ground under the flame, `[dy/dx, dy/dz]` in world axes, each -10 to 10: the flame stands on that
101
+ * plane through `position` (its base follows the ground across a long footprint instead of being cut by the slope),
102
+ * and the glow lights it. Default [0, 0] (level ground).
103
+ */
104
+ slope?: readonly [number, number];
105
+ /**
106
+ * The light the flame throws into the air and onto the ground around it, as a multiple of the physical, 0 to 8: the
107
+ * smoky air within `glowRadius` flame lengths glows with the light it scatters (Sun et al. 2005), and the ground plane
108
+ * (`slope`) is lit by it. Without `depth`, surfaces standing in that light (trees) take the light of the ground
109
+ * behind them. 0 turns it off. Default 1.
110
+ */
111
+ glow?: number;
112
+ /** Scattering coefficient of the air around the flames, per metre, 0 to 1 (a light haze 0.0005, smoke-filled air at a wildfire about 0.003 to 0.01, a clear night 0.0001). Default 0.0005. */
113
+ haze?: number;
114
+ /** Reflectance of the ground the glow lights, 0 to 1 (forest litter about 0.15). Default 0.15; 0 when `lights` is given (the point lights light the scene). */
115
+ groundAlbedo?: number;
116
+ /** How far the glow reaches, flame lengths, 0.5 to 10. Default 3. */
117
+ glowRadius?: number;
118
+ /** Opacity of the flame zone, 0 to 1. Default 1. */
119
+ opacity?: number;
120
+ /** Puffing and light flicker as a multiple of the physical (Cetegen and Ahmed 1993), 0 to 3; 0 holds the flames steady. Default 1. */
121
+ flicker?: number;
122
+ /** Size of the flame tongues as a multiple of the default (0.22 of the flame length across), 0.25 to 4. Default 1. */
123
+ tongues?: number;
124
+ /**
125
+ * A crown fire: the spacing of the burning trees, metres, 0 to 1,000. Each tree torches as its own tapering column
126
+ * (Van Wagner 1977; Alexander and Cruz 2011 put crown flames at one to two and a half times the stand height): its
127
+ * base reaches down into its crown by up to 0.3 flame lengths, its top runs from 0.6 to 1.4 flame lengths, so the
128
+ * fire's foot and crest are ragged as in a torching stand. 0 is a surface fire (one zone over the footprint). Default 0.
129
+ */
130
+ crowns?: number;
131
+ /**
132
+ * Where the flame's light goes: a `LightGroups` (the flame takes a group of its own, `flame`, `flame 2`, ...) or a
133
+ * `Clustered` (the flame then owns its whole list), attached to the same scene; it lights the meshes added to that
134
+ * `Clustered` (`clustered.add(mesh)`) and smoke whose `lit.lights` is it. Point lights over the footprint at a
135
+ * third of the flame's height, as bright as its silhouette at its peak radiance ({@link FLAME_LIGHT_FILL}), flickering with the puffing
136
+ * of the tongues above each. Read at attach. Default: no light.
137
+ */
138
+ lights?: Clustered | LightGroups;
139
+ /** Scales the light, 0 or more. Default 1. */
140
+ lightPower?: number;
141
+ /** Fog over the flames (`Fog` of `@margoengine/environment` or any `FogLike`). Default none. */
142
+ fog?: FogLike | null;
143
+ /**
144
+ * The scene depth (`DepthTexture` of `@margoengine/post/depth`): the march stops at surfaces inside the volume (a house
145
+ * in its own flames, logs, the ground), and the camera may stand inside the flames. Read at attach. Default: the box is
146
+ * depth-tested against the scene, which draws nothing from inside it.
147
+ */
148
+ depth?: () => GPUTexture | undefined;
149
+ }
150
+ /**
151
+ * A flame of any size, from a campfire to a house fire or a burning forest crown: one ray-marched volume over its
152
+ * footprint, sized by a flame length, an intensity (Byram 1959) or a heat release (Heskestad 1983). Tall tapering
153
+ * tongues rise at the buoyant speed and break up at the tip half the time at the flame length (Zukoski et al. 1985); the
154
+ * zone puffs at 1.5 D^(-1/2) Hz (Cetegen and Ahmed 1993); the colour runs from the core's temperature to the edge's
155
+ * through a camera's shoulder, so the core reads yellow-white and no pixel passes `peak` or turns white. With `lights`
156
+ * the flame lights the ground, smoke and anything near with point lights that flicker with its puffing. Every option
157
+ * is read each frame and written into one uniform, so a fire that grows, moves, leans or changes its look makes no GPU
158
+ * object after its first frame; a length of 0 puts the flames out. `applyFlameSettings` takes it as a target (the flame
159
+ * rows). WebGPU and the WebGL2 compatibility layer.
160
+ * @throws TypeError for a missing position or size; RangeError for an option out of range.
161
+ * A plugin of the scene it is attached to: disposing that scene disposes the flame.
162
+ */
163
+ export declare class Flame implements EnginePlugin {
164
+ readonly name: string;
165
+ private readonly seed;
166
+ /** Read every frame; see {@link FlameOptions}. */
167
+ readonly options: FlameOptions;
168
+ /** The light's points (empty without `lights`), their intensities as of the last frame. */
169
+ readonly lights: readonly PointLight[];
170
+ private engine?;
171
+ private disposed;
172
+ private clock;
173
+ private current;
174
+ private look;
175
+ private readonly key;
176
+ private readonly values;
177
+ private readonly view;
178
+ private readonly heat;
179
+ private readonly fogData;
180
+ private readonly target?;
181
+ private readonly group?;
182
+ private readonly steady;
183
+ private coreFloor;
184
+ /** The scene depth's samples as of this view's colour pass. */
185
+ private samples;
186
+ private uniform?;
187
+ private fogBuffer?;
188
+ private owned;
189
+ private softRuntime?;
190
+ private readonly groups;
191
+ private readonly attachment;
192
+ private readonly depthAttachment;
193
+ private constructor();
194
+ /** The flame length now, metres: `length`, else Byram's of `intensity`, else Heskestad's of `heat`. */
195
+ private length;
196
+ private check;
197
+ /** The look values now: the flame rows where `setFlameLook` set them, else the options. */
198
+ private lookOf;
199
+ /** Rewrites the temperature table when a number it depends on changed (no allocation otherwise). */
200
+ private write;
201
+ /**
202
+ * Writes the flame rows that `applyFlameSettings` resolved (`flames.core`, `edge`, `peak`, `flicker`, `tongues`,
203
+ * `size`, `radiance`, `opacity`, `ramp`, `edgeColor`); the flame keeps them while its length, footprint or wind change.
204
+ * The ember rows do nothing here (a `Flame` has no embers).
205
+ */
206
+ setFlameLook(values: Readonly<Record<string, unknown>>): this;
207
+ /**
208
+ * The hot plume over the flame as of its last frame, for `HeatHaze` of `@margoengine/post/heat-haze` (the shimmer of
209
+ * the scene behind the fire): the base, the length now, the footprint as drawn (`flames.size` included), the yaw, the
210
+ * lean in the wind (world metres across per metre up) and the flame's clock, so a seeked flame shimmers as a played
211
+ * one. One object, rewritten on each read.
212
+ */
213
+ get plume(): FlamePlume;
214
+ /** The length now, metres (0 when out). */
215
+ get flameLength(): number;
216
+ /** Seconds on the flame's clock: the sum of its frame deltas. */
217
+ get time(): number;
218
+ /** The puffing frequency now, Hz: {@link puffingFrequency} of the footprint's {@link puffingDiameter}. */
219
+ get puffing(): number;
220
+ setup(engine: Engine): void;
221
+ registerPasses(graph: FrameGraph): void;
222
+ /** The wind's lean of the flames, `[dx, dz]` per metre of height, at their rise speed `rise`. */
223
+ private lean;
224
+ /**
225
+ * Moves the flame's clock by `delta` seconds (0 or less moves nothing): the CPU part of its frame update, which a
226
+ * seek from `@margoengine/cutscene/seek` replays. Everything a frame then draws (the puffing, the flicker of the light,
227
+ * the dither shift, the wind it samples) is worked from this clock, so a flame seeked to T draws what a continuous run
228
+ * draws at T (GAP-FILM-TIME).
229
+ */
230
+ advanceTime(delta: number): void;
231
+ /**
232
+ * Back to time 0, as a fresh flame with the same options (GAP-FILM-RESET): the puffing, the light's flicker and the
233
+ * dither start again, so the same frames after it draw what a fresh flame draws.
234
+ */
235
+ resetTime(): void;
236
+ onPreUpdate(delta: number): void;
237
+ /**
238
+ * The ground plane and the glow: the slope in the footprint's axes, the glow sources' intensity (the light's total, as
239
+ * {@link FLAME_LIGHT_FILL}, over as many sources as its points), the haze and the glow box around the flame box.
240
+ */
241
+ private glow;
242
+ /** Places the light's points over the footprint and sets each one's flicker from the puffing of the tongues above it. */
243
+ private light;
244
+ private draw;
245
+ /** Sets the flame length, metres (see {@link FlameOptions.length}); the volume answers from the next frame. */
246
+ setLength(length: number): this;
247
+ /** Sets the wind at the flames (see {@link FlameOptions.wind}); undefined removes it. */
248
+ setWind(wind: VFXWind | undefined): this;
249
+ /** The light's points at their steady intensities (the mean the flicker swings about), as of the last frame. */
250
+ get steadyIntensities(): readonly number[];
251
+ /** Flames at `options.position`; see {@link FlameOptions}. */
252
+ static attach(engine: EngineKernel, options: FlameOptions): Flame;
253
+ private release;
254
+ onDeviceRestored(engine: Engine): void;
255
+ /** Removes the flames and their light (a group the flame made goes with it). */
256
+ dispose(): void;
257
+ [Symbol.dispose](): void;
258
+ }
259
+ /** The embers of a hearth kit scaled to a fire of flame length `length` over `footprint` (for `Fire.attach({flameLength})`). */
260
+ export declare function scaleHearthEmbers<T extends Record<string, unknown>>(embers: T, length: number, footprint: readonly [number, number]): T;