@margoengine/vfx 0.1.0 → 1.0.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 (46) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +4 -4
  3. package/README.md +2241 -1642
  4. package/dist/{base-C9upJytz.js → base-LGs65K7K.js} +174 -123
  5. package/dist/base.d.ts +104 -2
  6. package/dist/base.js +1 -1
  7. package/dist/blown-sand.js +3 -3
  8. package/dist/clouds.d.ts +12 -4
  9. package/dist/clouds.js +35 -18
  10. package/dist/compat-BFjXAQuu.js +14 -0
  11. package/dist/debris.d.ts +43 -0
  12. package/dist/debris.js +33 -1
  13. package/dist/dust-current.d.ts +66 -0
  14. package/dist/dust-current.js +92 -0
  15. package/dist/fire-front.d.ts +72 -1
  16. package/dist/fire-front.js +309 -69
  17. package/dist/fire.d.ts +24 -3
  18. package/dist/fire.js +114 -93
  19. package/dist/flame.d.ts +171 -3
  20. package/dist/flame.js +343 -131
  21. package/dist/flocking-shaders.d.ts +48 -0
  22. package/dist/flocking-sim.d.ts +623 -0
  23. package/dist/flocking.d.ts +145 -0
  24. package/dist/flocking.js +1846 -0
  25. package/dist/gunfire.d.ts +52 -6
  26. package/dist/gunfire.js +108 -98
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +5 -5
  29. package/dist/json.js +2 -0
  30. package/dist/lit-Dx2tNwP-.js +152 -0
  31. package/dist/lit.d.ts +8 -1
  32. package/dist/lit.js +1 -105
  33. package/dist/mesh.d.ts +2 -0
  34. package/dist/mesh.js +92 -69
  35. package/dist/over-life.js +16 -15
  36. package/dist/reactive-mask-B8xbyzlk.js +69 -0
  37. package/dist/ribbons.d.ts +4 -2
  38. package/dist/ribbons.js +87 -73
  39. package/dist/settings.js +1 -1
  40. package/dist/shader.d.ts +5 -0
  41. package/dist/shared/fog.d.ts +33 -33
  42. package/dist/shared/pass.d.ts +53 -53
  43. package/dist/shared/settings.d.ts +89 -89
  44. package/dist/smoke.d.ts +72 -4
  45. package/dist/smoke.js +280 -56
  46. package/package.json +200 -192
@@ -1,89 +1,89 @@
1
- /** A colour value: linear RGB. */
2
- export type SettingColor = readonly [number, number, number];
3
- /** One gradient stop: a colour at a position (`elevation` unless the row's `stopKey` says otherwise). */
4
- export type SettingStop = { readonly color: SettingColor };
5
- /** One value of a setting: a number, a colour, a choice, gradient stops, or null where `nullable`. */
6
- export type SettingValue = number | SettingColor | string | readonly SettingStop[] | null;
7
- /** Values by setting name; a name left out takes its default. */
8
- export type SettingValues = Readonly<Record<string, SettingValue>>;
9
- /** One slider row, the shape every package's `/settings` entry shares. */
10
- export interface SettingRow {
11
- readonly name: string;
12
- readonly group: string;
13
- /** `number` is a slider, `color` three sliders or a picker, `choice` a list, `gradient` a stop editor. */
14
- readonly kind: 'number' | 'color' | 'choice' | 'gradient';
15
- /** The value with which the target draws exactly as it does without the option (null: follow the weather). */
16
- readonly default: SettingValue;
17
- readonly min?: number;
18
- readonly max?: number;
19
- readonly step?: number;
20
- readonly choices?: readonly string[];
21
- /** May be null: the target uses its own value, or follows the weather when `weather` is set. */
22
- readonly nullable?: boolean;
23
- /** The weather master slider that drives this row while it is null. */
24
- readonly weather?: string;
25
- /** The key a gradient stop is placed by (default `elevation`). */
26
- readonly stopKey?: string;
27
- readonly unit: string;
28
- readonly about: string;
29
- /** True: cheap to write every frame (no pipeline, buffer or texture is created), so it can be keyed over a shot. False: writing it rebuilds something. */
30
- readonly live: boolean;
31
- }
32
- export declare const numberSetting: (
33
- name: string,
34
- group: string,
35
- value: number,
36
- min: number,
37
- max: number,
38
- step: number,
39
- unit: string,
40
- about: string,
41
- live?: boolean,
42
- ) => SettingRow;
43
- export declare const colorSetting: (
44
- name: string,
45
- group: string,
46
- value: SettingColor,
47
- min: number,
48
- max: number,
49
- about: string,
50
- live?: boolean,
51
- ) => SettingRow;
52
- export declare const choiceSetting: (
53
- name: string,
54
- group: string,
55
- choices: readonly string[],
56
- about: string,
57
- live?: boolean,
58
- ) => SettingRow;
59
- /** The row with a null default that follows the weather master slider `weather` until a value is given. */
60
- export declare const followsWeather: (row: SettingRow, weather: string) => SettingRow;
61
- /** Marks `key` of `target` as set by hand (`held` true) or hands it back to the weather (false). */
62
- export declare function holdFromWeather(target: object, key: string, held?: boolean): void;
63
- /** True while `key` of `target` holds a value set by hand, which the weather drive leaves alone. */
64
- export declare const heldFromWeather: (target: object, key: string) => boolean;
65
- export declare const sameSettingValue: (a: unknown, b: unknown) => boolean;
66
- export declare function copySettingValue(v: SettingValue): SettingValue;
67
- /** A fresh object holding every row at its default (a slider panel's state). */
68
- export declare function settingDefaults(rows: readonly SettingRow[]): Record<string, SettingValue>;
69
- /** The rows that may change every frame without a rebuild. */
70
- export declare const liveSettings: (rows: readonly SettingRow[]) => SettingRow[];
71
- /** A name to row map. */
72
- export declare const settingIndex: (rows: readonly SettingRow[]) => Map<string, SettingRow>;
73
- /** @throws RangeError when `v` is not a value of `row`. */
74
- export declare function checkSettingValue(row: SettingRow, v: unknown, label: string): void;
75
- /** @throws TypeError for an unknown name; RangeError for a bad value or a null on a row that is not nullable. */
76
- export declare function checkSettings(
77
- rows: readonly SettingRow[] | ReadonlyMap<string, SettingRow>,
78
- values: SettingValues,
79
- label: string,
80
- entry?: string,
81
- ): void;
82
- /** Checks `values`, then calls `write` once per row (or per row `only` accepts) with the given value or the default. */
83
- export declare function applySettings(
84
- rows: readonly SettingRow[],
85
- values: SettingValues,
86
- label: string,
87
- write: (row: SettingRow, value: SettingValue) => void,
88
- only?: (row: SettingRow) => boolean,
89
- ): void;
1
+ /** A colour value: linear RGB. */
2
+ export type SettingColor = readonly [number, number, number];
3
+ /** One gradient stop: a colour at a position (`elevation` unless the row's `stopKey` says otherwise). */
4
+ export type SettingStop = { readonly color: SettingColor };
5
+ /** One value of a setting: a number, a colour, a choice, gradient stops, or null where `nullable`. */
6
+ export type SettingValue = number | SettingColor | string | readonly SettingStop[] | null;
7
+ /** Values by setting name; a name left out takes its default. */
8
+ export type SettingValues = Readonly<Record<string, SettingValue>>;
9
+ /** One slider row, the shape every package's `/settings` entry shares. */
10
+ export interface SettingRow {
11
+ readonly name: string;
12
+ readonly group: string;
13
+ /** `number` is a slider, `color` three sliders or a picker, `choice` a list, `gradient` a stop editor. */
14
+ readonly kind: 'number' | 'color' | 'choice' | 'gradient';
15
+ /** The value with which the target draws exactly as it does without the option (null: follow the weather). */
16
+ readonly default: SettingValue;
17
+ readonly min?: number;
18
+ readonly max?: number;
19
+ readonly step?: number;
20
+ readonly choices?: readonly string[];
21
+ /** May be null: the target uses its own value, or follows the weather when `weather` is set. */
22
+ readonly nullable?: boolean;
23
+ /** The weather master slider that drives this row while it is null. */
24
+ readonly weather?: string;
25
+ /** The key a gradient stop is placed by (default `elevation`). */
26
+ readonly stopKey?: string;
27
+ readonly unit: string;
28
+ readonly about: string;
29
+ /** True: cheap to write every frame (no pipeline, buffer or texture is created), so it can be keyed over a shot. False: writing it rebuilds something. */
30
+ readonly live: boolean;
31
+ }
32
+ export declare const numberSetting: (
33
+ name: string,
34
+ group: string,
35
+ value: number,
36
+ min: number,
37
+ max: number,
38
+ step: number,
39
+ unit: string,
40
+ about: string,
41
+ live?: boolean,
42
+ ) => SettingRow;
43
+ export declare const colorSetting: (
44
+ name: string,
45
+ group: string,
46
+ value: SettingColor,
47
+ min: number,
48
+ max: number,
49
+ about: string,
50
+ live?: boolean,
51
+ ) => SettingRow;
52
+ export declare const choiceSetting: (
53
+ name: string,
54
+ group: string,
55
+ choices: readonly string[],
56
+ about: string,
57
+ live?: boolean,
58
+ ) => SettingRow;
59
+ /** The row with a null default that follows the weather master slider `weather` until a value is given. */
60
+ export declare const followsWeather: (row: SettingRow, weather: string) => SettingRow;
61
+ /** Marks `key` of `target` as set by hand (`held` true) or hands it back to the weather (false). */
62
+ export declare function holdFromWeather(target: object, key: string, held?: boolean): void;
63
+ /** True while `key` of `target` holds a value set by hand, which the weather drive leaves alone. */
64
+ export declare const heldFromWeather: (target: object, key: string) => boolean;
65
+ export declare const sameSettingValue: (a: unknown, b: unknown) => boolean;
66
+ export declare function copySettingValue(v: SettingValue): SettingValue;
67
+ /** A fresh object holding every row at its default (a slider panel's state). */
68
+ export declare function settingDefaults(rows: readonly SettingRow[]): Record<string, SettingValue>;
69
+ /** The rows that may change every frame without a rebuild. */
70
+ export declare const liveSettings: (rows: readonly SettingRow[]) => SettingRow[];
71
+ /** A name to row map. */
72
+ export declare const settingIndex: (rows: readonly SettingRow[]) => Map<string, SettingRow>;
73
+ /** @throws RangeError when `v` is not a value of `row`. */
74
+ export declare function checkSettingValue(row: SettingRow, v: unknown, label: string): void;
75
+ /** @throws TypeError for an unknown name; RangeError for a bad value or a null on a row that is not nullable. */
76
+ export declare function checkSettings(
77
+ rows: readonly SettingRow[] | ReadonlyMap<string, SettingRow>,
78
+ values: SettingValues,
79
+ label: string,
80
+ entry?: string,
81
+ ): void;
82
+ /** Checks `values`, then calls `write` once per row (or per row `only` accepts) with the given value or the default. */
83
+ export declare function applySettings(
84
+ rows: readonly SettingRow[],
85
+ values: SettingValues,
86
+ label: string,
87
+ write: (row: SettingRow, value: SettingValue) => void,
88
+ only?: (row: SettingRow) => boolean,
89
+ ): void;
package/dist/smoke.d.ts CHANGED
@@ -61,6 +61,15 @@ export interface PlumePoint {
61
61
  * @param stability Air stability s, 1/s^2, 0 or more ({@link airStability}); 0 is neutral (no ceiling). Default 0.
62
62
  */
63
63
  export declare function plumeRise(seconds: number, flux: number, wind: number, radius: number, stability?: number, out?: PlumePoint): PlumePoint;
64
+ /**
65
+ * The speed of the jet a fire's plume turns into under a flat ceiling, m/s (Alpert 1972): 0.96 (Q / H)^(1/3) within
66
+ * r / H 0.15 of the plume's axis, 0.195 Q^(1/3) H^(1/2) / r^(5/6) beyond.
67
+ * @param heat The fire's heat release, watts, 0 or more.
68
+ * @param height The ceiling's height over the fire, metres, above 0.
69
+ * @param distance Horizontal distance from the plume's axis, metres, 0 or more. Default `height`.
70
+ * @example ceilingJetSpeed(1e6, 3); // about 1.35 m/s, 3 m out under a ceiling 3 m over a 1 MW fire
71
+ */
72
+ export declare function ceilingJetSpeed(heat: number, height: number, distance?: number): number;
64
73
  /** Where the smoke comes from: a `Fire` of `@margoengine/vfx/fire` (its flames' position and wind). */
65
74
  export interface SmokeSource {
66
75
  /** Hearth flames. */
@@ -75,9 +84,17 @@ export interface SmokeSource {
75
84
  };
76
85
  };
77
86
  }
87
+ /** The walls of a gallery under a roof ({@link SmokeOptions.gallery}). */
88
+ export interface SmokeGallery {
89
+ /** The world axis the gallery runs along. */
90
+ axis: 'x' | 'z';
91
+ /** The world coordinates of its two walls on the other horizontal axis (z for `axis: 'x'`), the lower first. */
92
+ walls: readonly [number, number];
93
+ }
78
94
  /**
79
95
  * `Smoke.attach` settings. `position` or `fire` is required. Read every frame (change a field and the next frame shows
80
- * it) except `lifetime`, `prewarm`, `texture`, `lights`, `shadows` and `depth`, which are read at attach.
96
+ * it) except `lifetime`, `prewarm`, `texture`, `lights`, `shadows` and `depth`, which are read at attach, as is
97
+ * whether there is a `ceiling` (its height is read every frame).
81
98
  */
82
99
  export interface SmokeOptions {
83
100
  /** The source, world units (the top of the fire). Default: the fire's flames' position. */
@@ -98,6 +115,20 @@ export interface SmokeOptions {
98
115
  * Briggs' final rise and spreads there. Default 0 (neutral air, no ceiling).
99
116
  */
100
117
  stability?: number;
118
+ /**
119
+ * The world height of a flat roof over the source, metres: a room, a tunnel, a deck. The column stops where its top
120
+ * meets the roof, widens no further, and runs out under it in every direction at Alpert's ceiling jet speed
121
+ * ({@link ceilingJetSpeed} of the whole heat release, `heat` over 0.7), staying under the roof. A source at or over
122
+ * the roof spreads under it at once. Default none: open sky (without it a column indoors climbs through the roof,
123
+ * and its old puffs, metres wide, hide what is under it).
124
+ */
125
+ ceiling?: number;
126
+ /**
127
+ * Two walls under the `ceiling`: a tunnel, a corridor, a mine drift. The layer turns along the gallery in both
128
+ * directions instead of running out as a disc, so it stays dense far from the fire; no puff passes a wall or grows
129
+ * wider than the gallery. Chosen at attach with a `ceiling`; its fields are read every frame. Default none.
130
+ */
131
+ gallery?: SmokeGallery;
101
132
  /**
102
133
  * The wind, `[x, z]` m/s or `{sample(x, y, z, t)}` (a `WindField` fits): the column bends over by Briggs' law and
103
134
  * leans atan(U / w). Default none, and then a `WeatherDrive` in the scene writes the weather's wind; a wind given
@@ -114,8 +145,12 @@ export interface SmokeOptions {
114
145
  opacity?: number;
115
146
  /** Curl-noise churn, m/s^2, 0 or more. Default 0.4 (0 for a smooth column). */
116
147
  turbulence?: number;
117
- /** Fill the column before the first frame (simulated in steps of 0.1 s, or a 600th of a long life). Read at attach. Default true. */
118
- prewarm?: boolean;
148
+ /**
149
+ * Fill the column before the first frame: true to its full height (simulated in steps of 0.1 s, or a 600th of a long
150
+ * life), or a number of seconds the source has been burning, 0 to `lifetime`, for a column that has only grown that far
151
+ * (a still or a seek partway up its rise). Read at attach. Default true.
152
+ */
153
+ prewarm?: boolean | number;
119
154
  /**
120
155
  * The fire's glow on the column from below: the puffs are lit by a point source at the source position radiating
121
156
  * {@link RADIANT_FRACTION} of the fire's release (0.3 / 0.7 of `heat`), over the source radius (`VFXLit.glow`), so
@@ -123,6 +158,28 @@ export interface SmokeOptions {
123
158
  * to 10. Read every frame. Default 1.
124
159
  */
125
160
  glow?: number;
161
+ /**
162
+ * The engine sun intensity of the scene's noon sun, which the glow is referred to (`VFXLit.noon`): the sky's
163
+ * `lighting.intensity`. Read every frame. Default pi.
164
+ */
165
+ noon?: number;
166
+ /**
167
+ * Light of the air round the column, red, green and blue shares of the noon sun's light (`VFXLit.air`): a firelit
168
+ * pall lights the puffs inside it, so a column over a burning front is not lit by its base alone
169
+ * (KB-VFX-COLUMNAMBIENT1). Read every frame; `FireFront.air` writes it. Default none.
170
+ */
171
+ air?: readonly [number, number, number];
172
+ /**
173
+ * The reflectance of the pall over the column, red, green and blue, each 0 to 1 (`VFXLit.airReflectance`): the
174
+ * `air`'s light comes up from the fire and the pall sends back this share of it, so the puffs glow underneath
175
+ * (KB-VFX-SMOKEFLAT1). Read every frame; `FireFront.airReflectance` writes it. Default `PALL_REFLECTANCE`.
176
+ */
177
+ airReflectance?: readonly [number, number, number];
178
+ /**
179
+ * The ground's albedo under the column, 0 to 1 (`VFXLit.ground`): the sky's ambient lights the puffs' tops and this
180
+ * share of it their undersides (KB-VFX-SMOKEFLAT1). Read every frame. Default 0.2.
181
+ */
182
+ ground?: number;
126
183
  /** A puff sprite (RGBA8 sRGB, alpha the coverage), multiplied by the colour. Read at attach. Default: a soft disc. */
127
184
  texture?: VFXTexture;
128
185
  /** Point and spot lights on the puffs (`Clustered` of `@margoengine/clustered`). Read at attach. Default: the sun and ambient only. */
@@ -165,6 +222,8 @@ export declare class Smoke implements EnginePlugin {
165
222
  /** The still-air drag on the puffs' horizontal velocity, per second, as a node constant: 0 while a wind applies. */
166
223
  private readonly still;
167
224
  private readonly lit;
225
+ /** Undefined under open sky. */
226
+ private readonly roof;
168
227
  private readonly glowAt;
169
228
  private constructor();
170
229
  /** Turns the still-air drag on when no wind moves the puffs (none, [0, 0], or a field that is calm here now). */
@@ -173,11 +232,20 @@ export declare class Smoke implements EnginePlugin {
173
232
  private radius;
174
233
  /** Checks every frame-read option and copies the source, colour and extent into place (no allocation). */
175
234
  private check;
235
+ /** Puts the roof's box and the jet under it where this frame's source, radius, heat and ceiling put them. */
236
+ private placeRoof;
237
+ /** Puts the gallery's walls where this frame's options put them; its half width, or Infinity without one. */
238
+ private placeWalls;
239
+ /** Half the gallery's width, metres; Infinity without one. */
240
+ private halfWidth;
176
241
  /** The wind the column follows this frame: its own, else what the fire or the weather wrote on the puffs. */
177
242
  private wind;
178
243
  /** Rewrites the speed and size curves in place for this flux, wind and air (no allocation). */
179
244
  private write;
180
- /** The column now: rise, speed and radius at a puff age of `seconds` for the wind it follows this frame. */
245
+ /**
246
+ * The column now: rise, speed and radius at a puff age of `seconds` for the wind it follows this frame. Under a
247
+ * `ceiling` the rise and radius stop at the roof (`level`, with no rise speed).
248
+ */
181
249
  column(seconds: number): PlumePoint;
182
250
  setup(engine: Engine): void;
183
251
  /** Seconds on the column's clock: the sum of its frame deltas. */