@margoengine/vfx 0.0.0-stage → 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 (104) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +2240 -2
  4. package/dist/base-LGs65K7K.js +709 -0
  5. package/dist/base.d.ts +869 -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 +237 -0
  10. package/dist/clouds.js +583 -0
  11. package/dist/compat-BFjXAQuu.js +14 -0
  12. package/dist/compat-CVSEj1Bp.js +217 -0
  13. package/dist/compat.d.ts +59 -0
  14. package/dist/curves.d.ts +11 -0
  15. package/dist/curves.js +59 -0
  16. package/dist/debris.d.ts +154 -0
  17. package/dist/debris.js +290 -0
  18. package/dist/depth-collide.d.ts +7 -0
  19. package/dist/depth-collide.js +96 -0
  20. package/dist/dust-current.d.ts +66 -0
  21. package/dist/dust-current.js +92 -0
  22. package/dist/emitter.d.ts +10 -0
  23. package/dist/emitter.js +125 -0
  24. package/dist/events.d.ts +9 -0
  25. package/dist/events.js +131 -0
  26. package/dist/extra-CgGjbojB.js +4 -0
  27. package/dist/extra.d.ts +2 -0
  28. package/dist/fields.d.ts +11 -0
  29. package/dist/fields.js +95 -0
  30. package/dist/fire-front.d.ts +610 -0
  31. package/dist/fire-front.js +1080 -0
  32. package/dist/fire.d.ts +140 -0
  33. package/dist/fire.js +194 -0
  34. package/dist/flame-ramp-VoBKpYnM.js +75 -0
  35. package/dist/flame-ramp.d.ts +61 -0
  36. package/dist/flame.d.ts +428 -0
  37. package/dist/flame.js +817 -0
  38. package/dist/flipbook.d.ts +7 -0
  39. package/dist/flipbook.js +23 -0
  40. package/dist/flocking-shaders.d.ts +48 -0
  41. package/dist/flocking-sim.d.ts +623 -0
  42. package/dist/flocking.d.ts +145 -0
  43. package/dist/flocking.js +1846 -0
  44. package/dist/fog-B-kBv7g0.js +32 -0
  45. package/dist/frame-BuvMFBPp.js +4 -0
  46. package/dist/frame.d.ts +7 -0
  47. package/dist/gunfire.d.ts +742 -0
  48. package/dist/gunfire.js +1214 -0
  49. package/dist/hash-Btsp6fGK.js +7 -0
  50. package/dist/hash.d.ts +2 -0
  51. package/dist/index.d.ts +17 -0
  52. package/dist/index.js +60 -0
  53. package/dist/json.d.ts +53 -0
  54. package/dist/json.js +239 -0
  55. package/dist/lit-Dx2tNwP-.js +152 -0
  56. package/dist/lit.d.ts +18 -0
  57. package/dist/lit.js +1 -0
  58. package/dist/mesh.d.ts +16 -0
  59. package/dist/mesh.js +248 -0
  60. package/dist/node-system.d.ts +315 -0
  61. package/dist/node-system.js +384 -0
  62. package/dist/nodes.d.ts +14 -0
  63. package/dist/nodes.js +293 -0
  64. package/dist/obstacles.d.ts +3 -0
  65. package/dist/obstacles.js +25 -0
  66. package/dist/over-life.d.ts +14 -0
  67. package/dist/over-life.js +94 -0
  68. package/dist/reactive-mask-B8xbyzlk.js +69 -0
  69. package/dist/require-webgpu--tUXPsmA.js +7 -0
  70. package/dist/ribbons.d.ts +22 -0
  71. package/dist/ribbons.js +165 -0
  72. package/dist/schedule.d.ts +29 -0
  73. package/dist/schedule.js +47 -0
  74. package/dist/settings.d.ts +362 -0
  75. package/dist/settings.js +707 -0
  76. package/dist/shader.d.ts +49 -0
  77. package/dist/shadows.d.ts +26 -0
  78. package/dist/shadows.js +182 -0
  79. package/dist/shapes.d.ts +34 -0
  80. package/dist/shapes.js +81 -0
  81. package/dist/shared/fog.d.ts +33 -0
  82. package/dist/shared/pass.d.ts +53 -0
  83. package/dist/shared/settings.d.ts +89 -0
  84. package/dist/skinned.d.ts +11 -0
  85. package/dist/skinned.js +104 -0
  86. package/dist/smoke.d.ts +283 -0
  87. package/dist/smoke.js +504 -0
  88. package/dist/soft.d.ts +17 -0
  89. package/dist/soft.js +55 -0
  90. package/dist/solid.d.ts +168 -0
  91. package/dist/solid.js +403 -0
  92. package/dist/sort.d.ts +3 -0
  93. package/dist/sort.js +58 -0
  94. package/dist/space.d.ts +14 -0
  95. package/dist/space.js +88 -0
  96. package/dist/stretch.d.ts +7 -0
  97. package/dist/stretch.js +40 -0
  98. package/dist/texture.d.ts +8 -0
  99. package/dist/texture.js +45 -0
  100. package/dist/view-RKprOPAy.js +30 -0
  101. package/dist/view-rect-DkeiiUtw.js +13 -0
  102. package/dist/wrap.d.ts +3 -0
  103. package/dist/wrap.js +5 -0
  104. package/package.json +198 -4
@@ -0,0 +1,1080 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const e=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
5
+ import { MargoError as t } from "@margoengine/math/errors";
6
+ //#region src/fire-front.ts
7
+ var n = (e, t, n = 1) => ({
8
+ load: e,
9
+ sav: t,
10
+ hours: n
11
+ }), r = (e, t = 1500) => ({
12
+ load: e,
13
+ sav: t,
14
+ live: !0
15
+ }), i = (e, t, n) => ({
16
+ baseHeight: e,
17
+ bulkDensity: t,
18
+ height: n
19
+ }), a = Object.freeze({
20
+ FM1: {
21
+ name: "FM1",
22
+ classes: [n(.74, 3500)],
23
+ depth: 1,
24
+ extinction: .12
25
+ },
26
+ FM2: {
27
+ name: "FM2",
28
+ classes: [
29
+ n(2, 3e3),
30
+ n(1, 109, 10),
31
+ n(.5, 30, 100),
32
+ r(.5)
33
+ ],
34
+ depth: 1,
35
+ extinction: .15
36
+ },
37
+ FM3: {
38
+ name: "FM3",
39
+ classes: [n(3.01, 1500)],
40
+ depth: 2.5,
41
+ extinction: .25
42
+ },
43
+ FM4: {
44
+ name: "FM4",
45
+ classes: [
46
+ n(5.01, 2e3),
47
+ n(4.01, 109, 10),
48
+ n(2, 30, 100),
49
+ r(5.01)
50
+ ],
51
+ depth: 6,
52
+ extinction: .2
53
+ },
54
+ FM5: {
55
+ name: "FM5",
56
+ classes: [
57
+ n(1, 2e3),
58
+ n(.5, 109, 10),
59
+ r(2)
60
+ ],
61
+ depth: 2,
62
+ extinction: .2
63
+ },
64
+ FM6: {
65
+ name: "FM6",
66
+ classes: [
67
+ n(1.5, 1750),
68
+ n(2.5, 109, 10),
69
+ n(2, 30, 100)
70
+ ],
71
+ depth: 2.5,
72
+ extinction: .25
73
+ },
74
+ FM7: {
75
+ name: "FM7",
76
+ classes: [
77
+ n(1.13, 1750),
78
+ n(1.87, 109, 10),
79
+ n(1.5, 30, 100),
80
+ r(.37)
81
+ ],
82
+ depth: 2.5,
83
+ extinction: .4
84
+ },
85
+ FM8: {
86
+ name: "FM8",
87
+ classes: [
88
+ n(1.5, 2e3),
89
+ n(1, 109, 10),
90
+ n(2.5, 30, 100)
91
+ ],
92
+ depth: .2,
93
+ extinction: .3,
94
+ canopy: i(4, .12, 20)
95
+ },
96
+ FM9: {
97
+ name: "FM9",
98
+ classes: [
99
+ n(2.92, 2500),
100
+ n(.41, 109, 10),
101
+ n(.15, 30, 100)
102
+ ],
103
+ depth: .2,
104
+ extinction: .25,
105
+ canopy: i(6, .08, 22)
106
+ },
107
+ FM10: {
108
+ name: "FM10",
109
+ classes: [
110
+ n(3.01, 2e3),
111
+ n(2, 109, 10),
112
+ n(5.01, 30, 100),
113
+ r(2)
114
+ ],
115
+ depth: 1,
116
+ extinction: .25,
117
+ canopy: i(2, .15, 20)
118
+ },
119
+ FM11: {
120
+ name: "FM11",
121
+ classes: [
122
+ n(1.5, 1500),
123
+ n(4.51, 109, 10),
124
+ n(5.51, 30, 100)
125
+ ],
126
+ depth: 1,
127
+ extinction: .15
128
+ },
129
+ FM12: {
130
+ name: "FM12",
131
+ classes: [
132
+ n(4.01, 1500),
133
+ n(14.03, 109, 10),
134
+ n(16.53, 30, 100)
135
+ ],
136
+ depth: 2.3,
137
+ extinction: .2
138
+ },
139
+ FM13: {
140
+ name: "FM13",
141
+ classes: [
142
+ n(7.01, 1500),
143
+ n(23.04, 109, 10),
144
+ n(28.05, 30, 100)
145
+ ],
146
+ depth: 3,
147
+ extinction: .25
148
+ },
149
+ STRUCTURE: {
150
+ name: "STRUCTURE",
151
+ classes: [n(90, 60)],
152
+ depth: 10,
153
+ extinction: .3,
154
+ structure: !0
155
+ }
156
+ }), o = 32, s = 8e3, c = .01, l = 2e3 / 43560, u = .3048 / 60, d = .18935, f = (e, t, n, r) => {
157
+ if (typeof e != "number" || !Number.isFinite(e) || e < n || e > r) throw RangeError(`Invalid fire ${t}; pass a finite number from ${n} to ${r}.`);
158
+ return e;
159
+ };
160
+ function p(e, t, n = 1, r = t + .01, i = t + .02) {
161
+ if (!e.classes.length || !(e.depth > 0) || !(e.extinction > 0)) throw RangeError("Invalid fuel model; give at least one class, a depth above 0 and a moisture of extinction above 0.");
162
+ f(t, "moisture", 0, 4), f(n, "liveMoisture", 0, 4), f(r, "moisture10", 0, 4), f(i, "moisture100", 0, 4);
163
+ let a = e.classes.map((e) => {
164
+ if (!(e.load > 0) || !(e.sav > 0)) throw RangeError("Invalid fuel class; load and sav must be above 0.");
165
+ let a = e.load * l;
166
+ return {
167
+ c: e,
168
+ w: a,
169
+ m: e.live ? n : e.hours === 10 ? r : e.hours === 100 ? i : t,
170
+ area: e.sav * a / o,
171
+ live: !!e.live
172
+ };
173
+ }), d = (e) => a.filter((t) => t.live === e), p = d(!1), m = d(!0), h = (e) => e.reduce((e, t) => e + t.area, 0), g = h(p), _ = h(m), v = g + _, y = (e) => {
174
+ let t = h(e);
175
+ return t > 0 ? e.reduce((e, n) => e + n.area / t * n.c.sav, 0) : 0;
176
+ }, b = g / v, x = _ / v, S = b * y(p) + x * y(m), C = a.reduce((e, t) => e + t.w, 0), w = C / e.depth, T = w / o, E = 3.348 * S ** -.8189, D = (e, t) => e.reduce((e, n) => e + n.w * Math.exp(-t / n.c.sav), 0), O = p.length ? ((e, t) => e.reduce((e, n) => e + n.w * n.m * Math.exp(-t / n.c.sav), 0))(p, 138) / D(p, 138) : 0, k = (e) => {
177
+ let t = h(e);
178
+ return t > 0 ? e.reduce((e, n) => e + n.area / t * n.m, 0) : 0;
179
+ }, A = k(p), ee = k(m), j = m.length && p.length ? D(p, 138) / D(m, 500) : 0, M = e.extinction, N = m.length ? Math.max(M, 2.9 * j * (1 - O / M) - .226) : M, P = (e, t) => {
180
+ let n = Math.min(e / t, 1);
181
+ return 1 - 2.59 * n + 5.11 * n * n - 3.52 * n * n * n;
182
+ }, F = Math.min(.174 * c ** -.19, 1), I = S ** 1.5 / (495 + .0594 * S ** 1.5), L = 133 * S ** -.7913, R = I * (T / E) ** L * Math.exp(L * (1 - T / E)), z = (e) => {
183
+ let t = h(e);
184
+ return t > 0 ? e.reduce((e, n) => e + n.area / t * n.w * .9445, 0) : 0;
185
+ }, B = R * s * F * (z(p) * P(A, M) + (m.length ? z(m) * P(ee, N) : 0)), V = Math.exp((.792 + .681 * Math.sqrt(S)) * (T + .1)) / (192 + .2595 * S), H = (e, t) => t > 0 ? e.reduce((e, n) => e + n.area / t * Math.exp(-138 / n.c.sav) * (250 + 1116 * n.m), 0) : 0, U = w * (b * H(p, g) + x * H(m, _));
186
+ return {
187
+ model: e,
188
+ sigma: S,
189
+ beta: T,
190
+ betaOp: E,
191
+ ir: B,
192
+ rate0: B * V / U * u,
193
+ windC: 7.47 * Math.exp(-.133 * S ** .55),
194
+ windB: .02526 * S ** .54,
195
+ windE: .715 * Math.exp(-359e-6 * S),
196
+ ratio: T / E,
197
+ residence: 384 / S * 60,
198
+ consumed: C * 4.8824
199
+ };
200
+ }
201
+ function m(e, t) {
202
+ let n = Math.min(Math.max(t, 0) / u, .9 * e.ir);
203
+ return e.windC * n ** e.windB * e.ratio ** -e.windE;
204
+ }
205
+ var h = (e, t) => 5.275 * e.beta ** -.3 * t * t;
206
+ function g(e, t) {
207
+ let n = p(e, t.moisture, t.liveMoisture ?? 1, t.moisture10, t.moisture100), r = m(n, f(t.wind ?? 0, "wind", 0, 200)), i = h(n, f(t.slope ?? 0, "slope", 0, 10));
208
+ return v(n, r, i, r + i);
209
+ }
210
+ var _ = 5280;
211
+ function v(e, t, n, r) {
212
+ let i = e.rate0 * (1 + r), a = e.ir * d * i * e.residence, o = (r > 0 ? (r * e.ratio ** e.windE / e.windC) ** (1 / e.windB) : 0) * 60 / _;
213
+ return {
214
+ rate: i,
215
+ rate0: e.rate0,
216
+ windFactor: t,
217
+ slopeFactor: n,
218
+ reactionIntensity: e.ir * d,
219
+ residence: e.residence,
220
+ firelineIntensity: a,
221
+ flameLength: .0775 * a ** .46,
222
+ lengthToBreadth: Math.min(8, .936 * Math.exp(.1147 * o) + .461 * Math.exp(-.0692 * o) - .397)
223
+ };
224
+ }
225
+ function y(e, t, n) {
226
+ let r = Math.sqrt(Math.max(t * t - 1, 0)) / t;
227
+ return e * (1 - r) / (1 - r * Math.cos(n));
228
+ }
229
+ var b = 18e3, x = 1 / 1.15, S = 3600 / 1609.344;
230
+ function C(e, t, n, r, i, a = !1) {
231
+ let o = t.baseHeight, s = (.01 * Math.max(o, 0) * (460 + 2590 * n)) ** 1.5, c = .05 / t.bulkDensity, l = e.rate, u = e.firelineIntensity, d = Math.min(8, 1 + .125 * i * x * S);
232
+ if (a && r >= c && l > 0) {
233
+ let n = (u / l + b * t.bulkDensity * Math.max(t.height - o, 0)) * r;
234
+ return {
235
+ type: "active",
236
+ initiation: s,
237
+ activeRate: c,
238
+ crownRate: r,
239
+ fraction: 1,
240
+ rate: r,
241
+ firelineIntensity: n,
242
+ flameLength: Math.max(e.flameLength, .0266 * n ** (2 / 3)),
243
+ lengthToBreadth: Math.max(d, e.lengthToBreadth)
244
+ };
245
+ }
246
+ if (!(u >= s) || !(l > 0)) return {
247
+ type: "surface",
248
+ initiation: s,
249
+ activeRate: c,
250
+ crownRate: r,
251
+ fraction: 0,
252
+ rate: l,
253
+ firelineIntensity: u,
254
+ flameLength: e.flameLength,
255
+ lengthToBreadth: e.lengthToBreadth
256
+ };
257
+ let f = u / l, p = s / f, m = r >= c, h = m ? 1 : 1 - Math.exp(-13.8 * (l - p)), g = m ? r : l + h * Math.max(r - l, 0), _ = t.bulkDensity * Math.max(t.height - o, 0), v = (f + h * b * _) * g;
258
+ return {
259
+ type: m ? "active" : "passive",
260
+ initiation: s,
261
+ activeRate: c,
262
+ crownRate: r,
263
+ fraction: h,
264
+ rate: g,
265
+ firelineIntensity: v,
266
+ flameLength: Math.max(e.flameLength, .0266 * v ** (2 / 3)),
267
+ lengthToBreadth: e.lengthToBreadth + h * Math.max(d - e.lengthToBreadth, 0)
268
+ };
269
+ }
270
+ function w(e) {
271
+ let t = p(a.FM10, e.moisture, e.liveMoisture ?? 1, e.moisture10, e.moisture100);
272
+ return E(t, f(e.wind ?? 0, "wind", 0, 200), h(t, f(e.slope ?? 0, "slope", 0, 10)));
273
+ }
274
+ var T = (e, t) => m(e, .4 * t * x);
275
+ function E(e, t, n) {
276
+ return 3.34 * e.rate0 * (1 + T(e, t) + n);
277
+ }
278
+ var D = 0, O = 1, k = 2, A = 3, ee = 18622e3, j = .3, M = (() => {
279
+ let e = [];
280
+ for (let t = -2; t <= 2; t++) for (let n = -2; n <= 2; n++) {
281
+ let r = Math.abs(n), i = Math.abs(t);
282
+ (r || i) && (Math.max(r, i) === 1 || r + i === 3 && r && i) && e.push([n, t]);
283
+ }
284
+ return e;
285
+ })(), N = -1, P = 6, F = 20, I = .003, L = -1e9, R = 8, z = 0;
286
+ function B(e, t, n) {
287
+ let r = 0;
288
+ for (; r < n && e < 1;) {
289
+ if (e >= 11754943508222875e-54) {
290
+ let i = 2 ** Math.floor(Math.log2(e));
291
+ i > e ? i /= 2 : i * 2 <= e && (i *= 2);
292
+ let a = i * 2, o = i / 8388608, s = Math.fround(e + t) - e;
293
+ if (s === 0) return z = e, n;
294
+ let c = e + o;
295
+ if (c + t < a && Math.fround(c + t) - c === s) {
296
+ let i = Math.max(0, Math.floor((a - t - e) / s) + 1);
297
+ for (; i > 0 && !(e + (i - 1) * s + t < a);) i--;
298
+ for (; e + i * s + t < a;) i++;
299
+ if (i = Math.min(i, n - r), i >= 1) {
300
+ e += i * s, r += i;
301
+ continue;
302
+ }
303
+ }
304
+ }
305
+ let i = Math.fround(e + t);
306
+ if (i === e) return z = e, n;
307
+ e = i, r++;
308
+ }
309
+ return z = e, r;
310
+ }
311
+ var V = B;
312
+ function H(e, t, n) {
313
+ return B(e, t, n), z;
314
+ }
315
+ function U(e, t) {
316
+ let n = e.length;
317
+ for (e.push(t); n > 0;) {
318
+ let r = n - 1 >> 1;
319
+ if (e[r] <= t) break;
320
+ e[n] = e[r], n = r;
321
+ }
322
+ e[n] = t;
323
+ }
324
+ function W(e) {
325
+ let t = e.pop();
326
+ if (!e.length) return;
327
+ let n = 0;
328
+ for (;;) {
329
+ let r = 2 * n + 1;
330
+ if (r >= e.length || (r + 1 < e.length && e[r + 1] < e[r] && r++, e[r] >= t)) break;
331
+ e[n] = e[r], n = r;
332
+ }
333
+ e[n] = t;
334
+ }
335
+ var G = 0;
336
+ function K(e) {
337
+ let t = e >>> 0;
338
+ return () => {
339
+ t = t + 1831565813 >>> 0;
340
+ let e = t;
341
+ return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), ((e ^ e >>> 14) >>> 0) / 4294967296;
342
+ };
343
+ }
344
+ var te = class n {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
345
+ constructor(e) {
346
+ if (this.name = "fire-front:" + G++, this.time = 0, this.embers = 0, this.spots = 0, this.stepped = !1, this.doubled = 0, this.fromEngine = !1, this.disposed = !1, this.acc = 0, this.fuels = [], this.burning = [], this.pending = [], this.travel = /* @__PURE__ */ new Map(), this.carry = /* @__PURE__ */ new Map(), this.carryKey = "", this.seqN = 0, this.stepN = 0, this.visitSeq = -1, this.lazyOn = !1, this.lazy = /* @__PURE__ */ new Map(), this.due = /* @__PURE__ */ new Map(), this.dueSteps = [], this.dying = /* @__PURE__ */ new Map(), this.beds = [], this.bedKey = "", this.dirty = !0, this.columns = [], this.segs = /* @__PURE__ */ new Map(), this.flameAcc = /* @__PURE__ */ new Map(), this.frontFlames = [], this.houseFlames = [], this.emberPool = [], this.emberBase = [], this.frontKeys = [], this.houseKeys = [], this.midflame = [0, 0], this.born = [], this.smokeReady = Promise.resolve(), this.smokeRadius = !1, typeof e != "object" || !e) throw TypeError("FireFront options must be an object");
347
+ this.options = e;
348
+ let t = e.size ?? [1024, 1024], n = f(e.cell ?? 8, "cell", 1, 100);
349
+ for (let e of t) f(e, "size", n, 1e5);
350
+ if (this.width = Math.max(1, Math.ceil(t[0] / n)), this.height = Math.max(1, Math.ceil(t[1] / n)), this.width * this.height > 4194304) throw RangeError("FireFront grid is over 4,194,304 cells; raise cell or lower size.");
351
+ this.cell = n, this.origin = e.origin ?? [-t[0] / 2, -t[1] / 2], this.step = f(e.step ?? .5, "step", .05, 5), this.seg = Math.max(n, f(e.segment ?? 120, "segment", 1, 1e5)), this.random = K(f(e.seed ?? 1, "seed", 0, 4294967295)), this.checkLive();
352
+ let r = this.width * this.height;
353
+ this.cellFuel = new Uint8Array(r), this.structureOf = new Uint16Array(r), this.stateOf = new Uint8Array(r), this.arrival = new Float32Array(r).fill(-1), this.burnout = new Float32Array(r).fill(-1), this.intensity = new Float32Array(r), this.exposure = new Float32Array(r), this.slopeX = new Float32Array(r), this.slopeZ = new Float32Array(r), this.crownOf = new Float32Array(r), this.fed = new Uint8Array(r), this.seqOf = new Float64Array(r), this.cellOfSeq = new Int32Array(r + 1), e.canopy && (this.stands = new Float32Array(r * 3)), this.rows = new Float32Array(this.width * 4), this.fill();
354
+ for (let t of e.ignitions ?? []) this.queue(t);
355
+ }
356
+ static create(e = {}) {
357
+ return new n(e);
358
+ }
359
+ static attach(t, r = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
360
+ let i = new n(r);
361
+ return e(t).use(i), i;
362
+ }
363
+ checkLive() {
364
+ let e = this.options;
365
+ if (f(e.moisture ?? .06, "moisture", 0, 1), e.moisture10 !== void 0 && f(e.moisture10, "moisture10", 0, 4), e.moisture100 !== void 0 && f(e.moisture100, "moisture100", 0, 4), f(e.liveMoisture ?? .9, "liveMoisture", 0, 4), f(e.smokeYield ?? 15, "smokeYield", 0, 1e3), f(e.structureVent ?? .1, "structureVent", .01, 1), f(e.flames ?? 16, "flames", 0, 256), f(e.buildingFlames ?? 8, "buildingFlames", 0, 256), f(e.windReduction ?? .4, "windReduction", 0, 1), f(e.spotting ?? .02, "spotting", 0, 100), f(e.spotSpread ?? .7, "spotSpread", 0, 3), f(e.emberIgnition ?? .3, "emberIgnition", 0, 1), f(e.structureExposure ?? 90, "structureExposure", 1, 86400), f(e.structureBurnTime ?? 1800, "structureBurnTime", 1, 86400), f(e.foliarMoisture ?? 1, "foliarMoisture", .3, 4), e.crown !== void 0 && typeof e.crown != "boolean") throw TypeError("FireFront crown must be a boolean");
366
+ if (Array.isArray(e.wind)) for (let t of e.wind) f(t, "wind", -200, 200);
367
+ }
368
+ register(e) {
369
+ let t = this.fuels.indexOf(e);
370
+ if (t < 0) {
371
+ if (this.fuels.length >= 250) throw RangeError("FireFront holds at most 250 different fuel models.");
372
+ this.fuels.push(e), t = this.fuels.length - 1;
373
+ }
374
+ return t + 1;
375
+ }
376
+ resolve(e) {
377
+ if (e != null) {
378
+ if (typeof e == "string") {
379
+ let t = a[e];
380
+ if (!t) throw TypeError(`Unknown fuel model ${e}; use one of ${Object.keys(a).join(", ")} or a FuelModel.`);
381
+ return t;
382
+ }
383
+ return e;
384
+ }
385
+ }
386
+ fill() {
387
+ let e = this.options, { width: t, height: n, cell: r, origin: i } = this, o = e.fuel ?? "FM1", s = e.ground ?? (() => 0), c = new Float32Array(t * n);
388
+ for (let a = 0; a < n; a++) for (let n = 0; n < t; n++) {
389
+ let l = i[0] + (n + .5) * r, u = i[1] + (a + .5) * r, d = s(l, u);
390
+ if (!Number.isFinite(d)) throw RangeError("FireFront ground must return finite heights");
391
+ c[a * t + n] = d;
392
+ let p = this.resolve(typeof o == "function" ? o(l, u) : o);
393
+ if (p ? this.cellFuel[a * t + n] = this.register(p) : this.stateOf[a * t + n] = 3, this.stands) {
394
+ let r = e.canopy(l, u);
395
+ r && (f(r.baseHeight, "canopy baseHeight", 0, 100), f(r.bulkDensity, "canopy bulkDensity", .001, 2), f(r.height, "canopy height", 0, 150), this.stands.set([
396
+ r.baseHeight,
397
+ r.bulkDensity,
398
+ r.height
399
+ ], (a * t + n) * 3));
400
+ }
401
+ }
402
+ for (let e = 0; e < n; e++) for (let i = 0; i < t; i++) {
403
+ let a = e * t + i, o = Math.max(i - 1, 0), s = Math.min(i + 1, t - 1), l = Math.max(e - 1, 0), u = Math.min(e + 1, n - 1);
404
+ this.slopeX[a] = (c[e * t + s] - c[e * t + o]) / ((s - o || 1) * r), this.slopeZ[a] = (c[u * t + i] - c[l * t + i]) / ((u - l || 1) * r);
405
+ }
406
+ let l = this.register(a.STRUCTURE), u = 0;
407
+ for (let a of e.structures ?? []) {
408
+ u++;
409
+ let e = a.radius ?? 6;
410
+ for (let o = 0; o < n; o++) for (let n = 0; n < t; n++) {
411
+ let s = i[0] + (n + .5) * r, c = i[1] + (o + .5) * r;
412
+ Math.abs(s - a.at[0]) <= e && Math.abs(c - a.at[1]) <= e && (this.cellFuel[o * t + n] = l, this.structureOf[o * t + n] = u, this.stateOf[o * t + n] === 3 && (this.stateOf[o * t + n] = 0));
413
+ }
414
+ }
415
+ }
416
+ cellAt(e, t) {
417
+ let n = Math.floor((e - this.origin[0]) / this.cell), r = Math.floor((t - this.origin[1]) / this.cell);
418
+ return n < 0 || r < 0 || n >= this.width || r >= this.height ? -1 : r * this.width + n;
419
+ }
420
+ state(e, t) {
421
+ let n = this.cellAt(e, t);
422
+ return n < 0 ? -1 : this.stateOf[n];
423
+ }
424
+ arrivalTime(e, t) {
425
+ let n = this.cellAt(e, t);
426
+ return n < 0 ? -1 : this.arrival[n];
427
+ }
428
+ crownFraction(e, t) {
429
+ let n = this.cellAt(e, t);
430
+ return n < 0 ? 0 : this.crownOf[n];
431
+ }
432
+ get crowningCells() {
433
+ let e = 0;
434
+ for (let t of this.burning) this.stateOf[t] === 1 && this.crownOf[t] > 0 && e++;
435
+ return e;
436
+ }
437
+ canopyAt(e, t, n) {
438
+ if (this.options.crown === !1 || t.structure) return;
439
+ if (!this.stands) return t.canopy;
440
+ let r = e * 3;
441
+ if (this.stands[r + 1] > 0) return n.baseHeight = this.stands[r], n.bulkDensity = this.stands[r + 1], n.height = this.stands[r + 2], n;
442
+ }
443
+ get burningCells() {
444
+ let e = 0;
445
+ for (let t of this.burning) this.stateOf[t] === 1 && e++;
446
+ return e;
447
+ }
448
+ get smokeColumns() {
449
+ return this.columns;
450
+ }
451
+ get smokeEmission() {
452
+ let e = 0;
453
+ for (let t of this.segs.values()) e += t.heat / .7;
454
+ return (this.options.smokeYield ?? 15) * e / ee;
455
+ }
456
+ get radiantPower() {
457
+ let e = 0;
458
+ for (let t of this.segs.values()) e += t.heat;
459
+ return j / .7 * e;
460
+ }
461
+ get noon() {
462
+ return this.noonValue;
463
+ }
464
+ set noon(e) {
465
+ e !== void 0 && f(e, "noon", 1e-9, 1e7), this.noonValue = e;
466
+ for (let e of this.columns) this.noonOn(e);
467
+ }
468
+ noonOn(e) {
469
+ let t = e.options;
470
+ this.noonValue === void 0 ? this.options.smoke?.noon === void 0 ? delete t.noon : t.noon = this.options.smoke.noon : t.noon = this.noonValue, this.airValue ? t.air = this.airValue : this.options.smoke?.air === void 0 ? delete t.air : t.air = this.options.smoke.air, this.airBackValue ? t.airReflectance = this.airBackValue : this.options.smoke?.airReflectance === void 0 ? delete t.airReflectance : t.airReflectance = this.options.smoke.airReflectance;
471
+ }
472
+ get air() {
473
+ return this.airValue;
474
+ }
475
+ set air(e) {
476
+ if (e !== void 0) {
477
+ if (!Array.isArray(e) || e.length !== 3) throw TypeError("FireFront air must be [r, g, b] or undefined");
478
+ for (let t of e) f(t, "air", 0, 1e3);
479
+ }
480
+ this.airValue = e && [
481
+ e[0],
482
+ e[1],
483
+ e[2]
484
+ ];
485
+ for (let e of this.columns) this.noonOn(e);
486
+ }
487
+ get airReflectance() {
488
+ return this.airBackValue;
489
+ }
490
+ set airReflectance(e) {
491
+ if (e !== void 0) {
492
+ if (!Array.isArray(e) || e.length !== 3) throw TypeError("FireFront airReflectance must be [r, g, b] or undefined");
493
+ for (let t of e) f(t, "airReflectance", 0, 1);
494
+ }
495
+ this.airBackValue = e && [
496
+ e[0],
497
+ e[1],
498
+ e[2]
499
+ ];
500
+ for (let e of this.columns) this.noonOn(e);
501
+ }
502
+ get active() {
503
+ return this.burning.length > 0 || this.pending.length > 0 || this.lazy.size > 0;
504
+ }
505
+ queue(e) {
506
+ if (!Array.isArray(e.at) || e.at.length !== 2) throw TypeError("FireFront ignition needs at: [x, z]");
507
+ f(e.at[0], "ignition x", -1e7, 1e7), f(e.at[1], "ignition z", -1e7, 1e7), f(e.time ?? 0, "ignition time", 0, 1e9), f(e.radius ?? 0, "ignition radius", 0, 1e4), this.pending.push(e), this.pending.sort((e, t) => (e.time ?? 0) - (t.time ?? 0));
508
+ }
509
+ ignite(e, t, n = 0, r = this.time) {
510
+ return this.queue({
511
+ at: [e, t],
512
+ radius: n,
513
+ time: r
514
+ }), this;
515
+ }
516
+ bedsFor() {
517
+ let e = this.options, t = e.moisture ?? .06, n = e.liveMoisture ?? .9, r = e.moisture10 ?? t + .01, i = e.moisture100 ?? t + .02, o = t + "," + n + "," + r + "," + i + "," + this.fuels.length;
518
+ return o !== this.bedKey && (this.bedKey = o, this.beds = this.fuels.map((e) => p(e, t, n, r, i)), this.fm10 = p(a.FM10, t, n, r, i)), this.beds;
519
+ }
520
+ light(e, t) {
521
+ if (this.stateOf[e] !== 0 || !this.cellFuel[e]) return !1;
522
+ let n = this.bedsFor()[this.cellFuel[e] - 1], r = n.model;
523
+ return this.stateOf[e] = 1, this.arrival[e] = t, this.burnout[e] = t + (r.structure ? this.options.structureBurnTime ?? 1800 : n.residence), this.born.push(e), this.dirty = !0, this.seqOf[e] = ++this.seqN, this.cellOfSeq[this.seqN] = e, this.lazy.size && this.closeToward(e), !0;
524
+ }
525
+ closeToward(e) {
526
+ let { width: t, height: n } = this, r = e % t, i = (e - r) / t, a = this.stepN;
527
+ for (let e = 0; e < M.length; e++) {
528
+ let [o, s] = M[e], c = r - o, l = i - s;
529
+ if (c < 0 || l < 0 || c >= t || l >= n) continue;
530
+ let u = l * t + c, d = this.lazy.get(u);
531
+ d && d.open & 1 << e && (d.open &= ~(1 << e), this.closed(u, d, this.seqOf[u] > this.visitSeq ? a : a + 1));
532
+ }
533
+ }
534
+ closed(e, t, n) {
535
+ if (n > t.death && (t.death = n), t.open === 0) {
536
+ let n = this.dying.get(t.death);
537
+ n ? n.push(e) : this.dying.set(t.death, [e]);
538
+ }
539
+ }
540
+ lazify(e, t, n) {
541
+ let r = this.travel.get(e), { width: i } = this, a = e % i, o = (e - a) / i, s = this.seqOf[e], c = 0, l = [];
542
+ for (let e = 0; e < M.length; e++) {
543
+ let t = n[e];
544
+ if (r[e] >= 1 || t === N) continue;
545
+ let s = (o + M[e][1]) * i + a + M[e][0];
546
+ if (this.stateOf[s] === 0) {
547
+ if (!(t > 0)) return !1;
548
+ c |= 1 << e, l.push(e, V(r[e], t, Infinity));
549
+ }
550
+ }
551
+ let u = {
552
+ entry: t,
553
+ open: c,
554
+ death: t + 1
555
+ };
556
+ this.lazy.set(e, u);
557
+ for (let e = 0; e < l.length; e += 2) {
558
+ let n = l[e + 1];
559
+ if (n === Infinity) continue;
560
+ let r = t + n, i = this.due.get(r), a = s * 16 + l[e];
561
+ i ? i.push(a) : (this.due.set(r, [a]), U(this.dueSteps, r));
562
+ }
563
+ return c === 0 && this.closed(e, u, t + 1), !0;
564
+ }
565
+ reach(e, t, n) {
566
+ let r = Math.floor(e / 16), i = e - r * 16, a = this.cellOfSeq[r], o = this.lazy.get(a);
567
+ if (!o || !(o.open & 1 << i)) return;
568
+ o.open &= ~(1 << i), this.visitSeq = r;
569
+ let s = a + M[i][1] * this.width + M[i][0];
570
+ this.light(s, t) && this.carry.get(a)[M.length + i] === 1 ? (this.fed[s] = 1, this.closed(a, o, n)) : this.closed(a, o, n + 1);
571
+ }
572
+ flush() {
573
+ if (!this.lazy.size) return;
574
+ let e = this.stepN, t = [];
575
+ for (let [n, r] of this.lazy) {
576
+ let i = this.travel.get(n), a = this.carry.get(n);
577
+ for (let t = 0; t < M.length; t++) r.open & 1 << t ? i[t] = H(i[t], a[t], e - r.entry) : i[t] < 1 && a[t] !== N && (i[t] = 2);
578
+ t.push(n);
579
+ }
580
+ t.sort((e, t) => this.seqOf[e] - this.seqOf[t]);
581
+ let n = this.burning, r = [], i = 0, a = 0;
582
+ for (; i < n.length || a < t.length;) a >= t.length || i < n.length && this.seqOf[n[i]] < this.seqOf[t[a]] ? r.push(n[i++]) : r.push(t[a++]);
583
+ this.burning = r, this.lazy.clear(), this.due.clear(), this.dueSteps.length = 0, this.dying.clear();
584
+ }
585
+ nextLazyStep() {
586
+ let e = this.dueSteps.length ? this.dueSteps[0] : Infinity;
587
+ for (let t of this.dying.keys()) t < e && (e = t);
588
+ return e;
589
+ }
590
+ lightArea(e, t) {
591
+ let { width: n, height: r, cell: i, origin: a } = this, o = e.radius ?? 0, s = Math.floor((e.at[0] - o - a[0]) / i), c = Math.floor((e.at[0] + o - a[0]) / i), l = Math.floor((e.at[1] - o - a[1]) / i), u = Math.floor((e.at[1] + o - a[1]) / i);
592
+ for (let d = Math.max(l, 0); d <= Math.min(u, r - 1); d++) for (let r = Math.max(s, 0); r <= Math.min(c, n - 1); r++) {
593
+ let s = a[0] + (r + .5) * i - e.at[0], c = a[1] + (d + .5) * i - e.at[1];
594
+ s * s + c * c <= o * o + i * i * .5 && this.light(d * n + r, t);
595
+ }
596
+ }
597
+ windAt(e, t, n) {
598
+ let r = this.options.wind ?? [0, 0];
599
+ if (Array.isArray(r)) n[0] = r[0], n[1] = r[1];
600
+ else {
601
+ let i = r.sample(e, 0, t, this.time);
602
+ n[0] = i[0], n[1] = i[i.length - 1];
603
+ }
604
+ }
605
+ advanceTime(e) {
606
+ if (this.disposed) throw new t("disposed", "FireFront is disposed; attach a new FireFront");
607
+ for (f(e, "delta", 0, 86400), e > 0 && this.engine && !this.fromEngine && (this.stepped = !0), this.checkLive(), this.acc += e; this.acc >= this.step - 1e-9;) this.acc -= this.step, this.advance(this.step);
608
+ this.dirty && this.publish(), this.syncFlames();
609
+ }
610
+ resetTime() {
611
+ if (this.disposed) return;
612
+ this.time = this.acc = this.embers = this.spots = 0, this.stepped = !1, this.doubled = 0, this.random = K(f(this.options.seed ?? 1, "seed", 0, 4294967295));
613
+ let e = this.stateOf;
614
+ for (let t = 0; t < e.length; t++) e[t] !== 3 && (e[t] = 0);
615
+ this.arrival.fill(-1), this.burnout.fill(-1);
616
+ for (let e of [
617
+ this.intensity,
618
+ this.exposure,
619
+ this.crownOf,
620
+ this.fed
621
+ ]) e.fill(0);
622
+ this.burning = [], this.born = [], this.pending = [];
623
+ for (let e of this.options.ignitions ?? []) this.queue(e);
624
+ this.travel.clear(), this.carry.clear(), this.carryKey = "", this.lazy.clear(), this.due.clear(), this.dueSteps.length = 0, this.dying.clear(), this.seqN = this.stepN = 0, this.visitSeq = -1, this.seqOf.fill(0), this.cellOfSeq.fill(0), this.segs.clear(), this.flameAcc.clear(), this.bedKey = "", this.beds = [], this.fm10 = void 0, this.frontKeys.fill(void 0), this.houseKeys.fill(void 0);
625
+ for (let e of [
626
+ ...this.columns,
627
+ ...this.frontFlames,
628
+ ...this.houseFlames,
629
+ ...this.emberPool
630
+ ]) e.resetTime();
631
+ this.dirty = !0, this.texture && this.publish(), this.syncFlames();
632
+ }
633
+ update(e) {
634
+ this.advanceTime(e);
635
+ }
636
+ async settle(e = 86400, t) {
637
+ f(e, "maxSeconds", 0, 1e9);
638
+ let n = this.time + e, r = 0;
639
+ this.lazyOn = !0;
640
+ try {
641
+ for (; this.active && this.time < n;) {
642
+ if (t?.throwIfAborted(), this.burning.length === 0 && this.pending.length === 0) {
643
+ let e = this.nextLazyStep(), t = !1;
644
+ for (; this.stepN + 1 < e && this.time < n;) this.time += this.step, this.stepN++, t = !0;
645
+ if (t && (this.segs.clear(), this.flameAcc.clear()), this.time >= n) break;
646
+ }
647
+ this.advance(this.step), ++r % 4096 == 0 && (this.flush(), await Promise.resolve());
648
+ }
649
+ } finally {
650
+ this.flush(), this.lazyOn = !1;
651
+ }
652
+ return this.dirty && this.publish(), this.time;
653
+ }
654
+ advance(e) {
655
+ let t = this.time + e, n = this.options, { width: r, height: i, cell: a } = this, o = this.bedsFor(), s = n.wind ?? [0, 0], c = Array.isArray(s) ? [
656
+ s[0],
657
+ s[1],
658
+ n.windReduction ?? .4,
659
+ n.foliarMoisture ?? 1,
660
+ n.crown,
661
+ this.bedKey,
662
+ e
663
+ ].join() : "";
664
+ this.lazy.size && (c === "" || c !== this.carryKey) && this.flush();
665
+ let l = ++this.stepN;
666
+ for (this.visitSeq = -1; this.pending.length && (this.pending[0].time ?? 0) <= t;) this.lightArea(this.pending.shift(), t);
667
+ for (let e of this.born) this.burning.push(e);
668
+ this.born.length = 0;
669
+ let u = n.windReduction ?? .4, d = n.spotting ?? .02, f = [0, 0], p = this.fm10, g = n.foliarMoisture ?? 1, _ = {
670
+ baseHeight: 0,
671
+ bulkDensity: 0,
672
+ height: 0
673
+ }, y = c;
674
+ (y === "" || y !== this.carryKey) && (this.carry.clear(), this.carryKey = y);
675
+ let b = [];
676
+ this.segs.clear(), this.flameAcc.clear();
677
+ let x;
678
+ this.dueSteps.length && this.dueSteps[0] === l && (W(this.dueSteps), x = this.due.get(l).sort((e, t) => e - t), this.due.delete(l));
679
+ let S = 0, w = this.burning;
680
+ for (let s = 0; s < w.length; s++) {
681
+ let c = w[s], E = this.seqOf[c];
682
+ if (x) for (; S < x.length && x[S] < E * 16;) this.reach(x[S++], t, l);
683
+ this.visitSeq = E;
684
+ let D = c % r, O = (c - D) / r, k = this.origin[0] + (D + .5) * a, A = this.origin[1] + (O + .5) * a, j = o[this.cellFuel[c] - 1];
685
+ this.stateOf[c] === 1 && t >= this.burnout[c] && (this.stateOf[c] = 2, this.dirty = !0);
686
+ let P = this.stateOf[c] === 1 ? void 0 : this.carry.get(c);
687
+ if (P) {
688
+ this.carryOn(c, D, O, t, P) ? (!this.lazyOn || !this.lazify(c, l, P)) && b.push(c) : (this.travel.delete(c), this.carry.delete(c));
689
+ continue;
690
+ }
691
+ this.windAt(k, A, f);
692
+ let F = Math.hypot(f[0], f[1]) * u, I = m(j, F), R = this.slopeX[c], z = this.slopeZ[c], B = Math.hypot(R, z), V = h(j, B), H = F > 1e-9 ? f[0] / Math.hypot(f[0], f[1]) : 0, U = F > 1e-9 ? f[1] / Math.hypot(f[0], f[1]) : 0, W = B > 1e-9 ? R / B : 0, G = B > 1e-9 ? z / B : 0, K = I * H + V * W, te = I * U + V * G, q = Math.hypot(K, te), J = v(j, I, V, q), ne = q > 1e-9 ? K / q : 1, re = q > 1e-9 ? te / q : 0, ie = Math.sqrt(Math.max(J.lengthToBreadth ** 2 - 1, 0)) / J.lengthToBreadth, ae = this.canopyAt(c, j.model, _), Y, oe = ne, se = re, ce = ie;
693
+ if (ae) {
694
+ let e = Math.hypot(f[0], f[1]), t = T(p, e), n = h(p, B), r = t * H + n * W, i = t * U + n * G, a = Math.hypot(r, i), o = C(J, ae, g, 3.34 * p.rate0 * (1 + a), e, this.fed[c] === 1);
695
+ o.fraction > 0 && (Y = o, a > 1e-9 && (oe = r / a, se = i / a), ce = Math.sqrt(Math.max(o.lengthToBreadth ** 2 - 1, 0)) / o.lengthToBreadth);
696
+ }
697
+ let le = this.stateOf[c] === 1, X = j.model.structure === !0, Z = Y ?? J;
698
+ if (le) {
699
+ this.intensity[c] = Z.firelineIntensity / 1e3, Y && Y.fraction > this.crownOf[c] && (this.crownOf[c] = Y.fraction);
700
+ let r = a * a, i = X ? .7 * j.consumed * ee / (n.structureBurnTime ?? 1800) * r : .7 * J.reactionIntensity * 1e3 * r * (Y ? Y.firelineIntensity / Y.rate / (J.firelineIntensity / J.rate) : 1), o = Math.floor((A - this.origin[1]) / this.seg) * 65536 + Math.floor((k - this.origin[0]) / this.seg), s = this.segs.get(o);
701
+ s ? (s.x += k * i, s.z += A * i, s.heat += i, s.cells++) : this.segs.set(o, {
702
+ x: k * i,
703
+ z: A * i,
704
+ heat: i,
705
+ cells: 1
706
+ });
707
+ let l = X ? this.structureOf[c] ? -this.structureOf[c] : L - o : o, u = this.flameAcc.get(l);
708
+ u ? (u.x += k * i, u.z += A * i, u.heat += i, u.cells++, u.intensity += Z.firelineIntensity * i, u.crown += (Y?.fraction ?? 0) * i, u.xx += k * k * i, u.zz += A * A * i, u.xz += k * A * i, u.minX = Math.min(u.minX, k - a / 2), u.maxX = Math.max(u.maxX, k + a / 2), u.minZ = Math.min(u.minZ, A - a / 2), u.maxZ = Math.max(u.maxZ, A + a / 2)) : this.flameAcc.set(l, {
709
+ x: k * i,
710
+ z: A * i,
711
+ heat: i,
712
+ cells: 1,
713
+ intensity: Z.firelineIntensity * i,
714
+ crown: (Y?.fraction ?? 0) * i,
715
+ xx: k * k * i,
716
+ zz: A * A * i,
717
+ xz: k * A * i,
718
+ minX: k - a / 2,
719
+ maxX: k + a / 2,
720
+ minZ: A - a / 2,
721
+ maxZ: A + a / 2,
722
+ structure: X ? this.structureOf[c] : 0
723
+ }), Z.firelineIntensity > 1e3 && d > 0 && this.throwEmbers(c, Z, f, t, e, d), X || this.exposeStructures(c, Z.flameLength, e, t);
724
+ }
725
+ let Q = this.travel.get(c);
726
+ Q || this.travel.set(c, Q = new Float32Array(M.length));
727
+ let $ = y ? this.carry.get(c) : void 0;
728
+ y && !$ && this.carry.set(c, $ = new Float64Array(2 * M.length).fill(NaN));
729
+ let ue = !1;
730
+ for (let n = 0; n < M.length; n++) {
731
+ if (Q[n] >= 1) continue;
732
+ let [o, s] = M[n], c = D + o, l = O + s, u = l * r + c;
733
+ if (c < 0 || l < 0 || c >= r || l >= i || !this.cellFuel[u] || this.fuels[this.cellFuel[u] - 1].structure) {
734
+ Q[n] = 2, $ && ($[n] = N);
735
+ continue;
736
+ }
737
+ if (this.stateOf[u] !== 0) {
738
+ Q[n] = 2;
739
+ continue;
740
+ }
741
+ let d = Y !== void 0 && this.canopyAt(u, this.fuels[this.cellFuel[u] - 1], _) !== void 0, f = d ? Y.rate : J.rate, p = d ? ce : ie, m = Math.hypot(o, s) * a, h = (o * (d ? oe : ne) + s * (d ? se : re)) / Math.hypot(o, s), g = f * (1 - p) / (1 - p * h);
742
+ if (!(g > 1e-9)) {
743
+ Q[n] = 2, $ && ($[n] = N);
744
+ continue;
745
+ }
746
+ let v = g * e / m, y = d && Y.type === "active";
747
+ $ && ($[n] = v, $[M.length + n] = +!!y), Q[n] = Q[n] + v, Q[n] >= 1 && this.light(u, t) && y ? this.fed[u] = 1 : ue = !0;
748
+ }
749
+ this.stateOf[c] === 1 || ue ? b.push(c) : (this.travel.delete(c), this.carry.delete(c));
750
+ }
751
+ if (x) for (; S < x.length;) this.reach(x[S++], t, l);
752
+ let E = this.dying.get(l);
753
+ if (E) {
754
+ for (let e of E) this.lazy.delete(e), this.travel.delete(e), this.carry.delete(e);
755
+ this.dying.delete(l);
756
+ }
757
+ for (let e of this.born) b.push(e);
758
+ this.born.length = 0, this.burning = b, this.time = t;
759
+ }
760
+ carryOn(e, t, n, r, i) {
761
+ let a = this.travel.get(e), o = M.length, s = !1;
762
+ for (let e = 0; e < o; e++) {
763
+ if (a[e] >= 1) continue;
764
+ let c = i[e];
765
+ if (c === N) {
766
+ a[e] = 2;
767
+ continue;
768
+ }
769
+ let [l, u] = M[e], d = (n + u) * this.width + t + l;
770
+ this.stateOf[d] === 0 ? (a[e] = a[e] + c, a[e] >= 1 && this.light(d, r) && i[o + e] === 1 ? this.fed[d] = 1 : s = !0) : a[e] = 2;
771
+ }
772
+ return s;
773
+ }
774
+ exposeStructures(e, t, n, r) {
775
+ let { width: i, height: a, cell: o } = this, s = Math.min(8, Math.ceil(1.5 * t / o) + 1), c = e % i, l = (e - c) / i, u = this.options.structureExposure ?? 90;
776
+ for (let e = -s; e <= s; e++) for (let d = -s; d <= s; d++) {
777
+ let s = c + d, f = l + e;
778
+ if (!d && !e || s < 0 || f < 0 || s >= i || f >= a) continue;
779
+ let p = f * i + s;
780
+ this.stateOf[p] === 0 && this.cellFuel[p] && this.fuels[this.cellFuel[p] - 1].structure && (Math.max(0, Math.hypot(d, e) - 1) * o > 1.5 * t || (this.exposure[p] = this.exposure[p] + n, this.exposure[p] >= u && this.light(p, r)));
781
+ }
782
+ }
783
+ throwEmbers(e, t, n, r, i, a) {
784
+ let o = a * (t.firelineIntensity - 1e3) / 1e3 * i * (this.cell * this.cell / 64), s = Math.floor(o);
785
+ if (this.random() < o - s && s++, !s) return;
786
+ let c = Math.hypot(n[0], n[1]) * (3 * t.flameLength / 4), l = this.options.spotSpread ?? .7, { width: u, cell: d, origin: f } = this, p = e % u, m = (e - p) / u, h = [f[0] + (p + .5) * d, f[1] + (m + .5) * d];
787
+ for (let e = 0; e < s; e++) {
788
+ let e = Math.sqrt(-2 * Math.log(1 - this.random())) * Math.cos(2 * Math.PI * this.random()), t = c * Math.exp(l * e - .5 * l * l), i = Math.atan2(n[0], n[1]) + .12 * (this.random() - .5) * 2, a = [h[0] + Math.sin(i) * t, h[1] + Math.cos(i) * t], o = this.cellAt(a[0], a[1]);
789
+ if (this.embers++, o < 0 || this.stateOf[o] !== 0 || !this.cellFuel[o]) continue;
790
+ let s = this.bedsFor()[this.cellFuel[o] - 1], u = Math.min(1, (this.options.moisture ?? .06) / s.model.extinction), d = (this.options.emberIgnition ?? .3) * (1 - u) * (s.model.structure ? 1.5 : 1), f = this.random() < d, p = {
791
+ from: h,
792
+ to: a,
793
+ time: r,
794
+ ignited: f
795
+ };
796
+ f && this.light(o, r) && this.spots++, this.options.onSpot?.(p);
797
+ }
798
+ }
799
+ segments() {
800
+ let e = this.options.ground ?? (() => 0), t = [];
801
+ for (let [n, r] of this.segs) {
802
+ let i = r.x / r.heat, a = r.z / r.heat, o = this.flameAcc.get(n), s = o && o.heat > 0 ? o.intensity / o.heat : 0, c = o && o.crown > 0 ? Math.max(.0775 * s ** .46, .0266 * s ** (2 / 3)) : .0775 * s ** .46;
803
+ t.push({
804
+ x: i,
805
+ z: a,
806
+ y: e(i, a),
807
+ heat: r.heat,
808
+ cells: r.cells,
809
+ flameLength: c
810
+ });
811
+ }
812
+ return t.sort((e, t) => t.heat - e.heat);
813
+ }
814
+ flames() {
815
+ let e = this.options.ground ?? (() => 0), t = this.options.structureVent ?? .1, n = [];
816
+ for (let [r, i] of this.flameAcc) {
817
+ let a = i.x / i.heat, o = i.z / i.heat, s = r < 0, c = i.xx / i.heat - a * a, l = i.zz / i.heat - o * o, u = i.xz / i.heat - a * o, d = .5 * (c + l), f = Math.sqrt(Math.max(.25 * (c - l) ** 2 + u * u, 0)), p = Math.atan2(2 * u, c - l) / 2, m = i.maxX - i.minX, h = i.maxZ - i.minZ, g = s ? [Math.max(this.cell, i.maxX - i.minX), Math.max(this.cell, i.maxZ - i.minZ)] : [Math.max(this.cell, Math.min(Math.sqrt(12 * Math.max(d + f, 0)) + this.cell, Math.abs(Math.cos(p)) * m + Math.abs(Math.sin(p)) * h)), Math.max(this.cell, Math.min(Math.sqrt(12 * Math.max(d - f, 0)) + this.cell, Math.abs(Math.sin(p)) * m + Math.abs(Math.cos(p)) * h))], _ = s ? 0 : i.intensity / i.heat, v = Math.sqrt(4 * t * i.cells * this.cell * this.cell / Math.PI), y = s ? Math.max(.235 * (i.heat / .7 / 1e3) ** .4 - 1.02 * v, 0) : i.crown > 0 ? Math.max(.0775 * _ ** .46, .0266 * _ ** (2 / 3)) : .0775 * _ ** .46, b = Math.max(this.cell, .25 * Math.max(g[0], g[1])), x = s ? [0, 0] : [(e(a + b, o) - e(a - b, o)) / (2 * b), (e(a, o + b) - e(a, o - b)) / (2 * b)];
818
+ n.push({
819
+ kind: s ? "structure" : "front",
820
+ x: a,
821
+ z: o,
822
+ y: e(a, o),
823
+ heat: i.heat,
824
+ cells: i.cells,
825
+ intensity: _,
826
+ flameLength: y,
827
+ footprint: g,
828
+ yaw: s ? 0 : -p,
829
+ structure: i.structure > 0 ? i.structure - 1 : -1,
830
+ crown: s ? 0 : i.crown / i.heat,
831
+ slope: x,
832
+ key: r
833
+ });
834
+ }
835
+ return n.sort((e, t) => t.heat - e.heat);
836
+ }
837
+ get flameVolumes() {
838
+ return this.frontFlames;
839
+ }
840
+ get flameEmbers() {
841
+ return this.emberPool;
842
+ }
843
+ get buildingFlameVolumes() {
844
+ return this.houseFlames;
845
+ }
846
+ publish() {
847
+ this.dirty = !1;
848
+ let e = this.engine?.gpu, t = this.texture;
849
+ if (e && t) {
850
+ let { width: n, height: r, rows: i } = this;
851
+ for (let a = 0; a < r; a++) {
852
+ for (let e = 0; e < n; e++) {
853
+ let t = a * n + e;
854
+ i[e * 4] = this.arrival[t], i[e * 4 + 1] = this.burnout[t], i[e * 4 + 2] = this.intensity[t], i[e * 4 + 3] = this.stateOf[t];
855
+ }
856
+ e.queue.writeTexture({
857
+ texture: t,
858
+ origin: [0, a]
859
+ }, i, { bytesPerRow: n * 16 }, [n, 1]);
860
+ }
861
+ }
862
+ let n = this.segments();
863
+ for (let e = 0; e < this.columns.length; e++) {
864
+ let t = this.columns[e], r = n[e];
865
+ if (!r) t.setHeat(0);
866
+ else {
867
+ let e = t.options.position, n = !(t.options.heat > 0);
868
+ e[0] = r.x, e[1] = r.y + Math.max(2, r.flameLength), e[2] = r.z, this.smokeRadius && (t.options.radius = Math.min(60, Math.max(2, Math.sqrt(r.cells * this.cell * this.cell / Math.PI)))), t.setHeat(r.heat), n && t.refill();
869
+ }
870
+ }
871
+ }
872
+ read() {
873
+ let e = new Float32Array(this.width * this.height * 4);
874
+ for (let t = 0, n = this.width * this.height; t < n; t++) e[t * 4] = this.arrival[t], e[t * 4 + 1] = this.burnout[t], e[t * 4 + 2] = this.intensity[t], e[t * 4 + 3] = this.stateOf[t];
875
+ return e;
876
+ }
877
+ setWind(e) {
878
+ return this.options.wind = e, this;
879
+ }
880
+ setup(e) {
881
+ if (this.disposed) throw new t("disposed", "FireFront is disposed; attach a new FireFront");
882
+ this.engine = e;
883
+ let n = e.gpu;
884
+ if (n) {
885
+ if (this.width > n.limits.maxTextureDimension2D || this.height > n.limits.maxTextureDimension2D) throw RangeError("FireFront grid exceeds the GPU texture limit; raise cell.");
886
+ this.texture = n.createTexture({
887
+ label: "fire-front burn",
888
+ size: [this.width, this.height],
889
+ format: "rgba32float",
890
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC
891
+ }), this.dirty = !0, this.publish();
892
+ }
893
+ this.smokeReady = Promise.all([this.makeColumns(e), this.makeFlames(e)]).then(() => void 0);
894
+ }
895
+ get ready() {
896
+ return this.smokeReady;
897
+ }
898
+ async makeColumns(e) {
899
+ let t = f(this.options.columns ?? 12, "columns", 0, 256);
900
+ if (!t) return;
901
+ let { Smoke: n } = await import("@margoengine/vfx/smoke");
902
+ if (this.disposed) return;
903
+ let r = this.options.smoke ?? {};
904
+ for (this.smokeRadius = r.radius === void 0; this.columns.length < t;) this.columns.push(n.attach(e, {
905
+ lifetime: 300,
906
+ rate: 16,
907
+ stability: 15e-5,
908
+ color: [
909
+ .24,
910
+ .22,
911
+ .2
912
+ ],
913
+ opacity: .6,
914
+ ...r,
915
+ position: [
916
+ 0,
917
+ -1e6,
918
+ 0
919
+ ],
920
+ heat: 0
921
+ }));
922
+ for (let e of this.columns) this.noonOn(e);
923
+ if (this.smokeLook) for (let e of this.columns) this.smokeLook(e);
924
+ this.dirty = !0, this.publish();
925
+ }
926
+ async makeFlames(e) {
927
+ let t = this.options, n = f(t.flames ?? 16, "flames", 0, 256), r = f(t.buildingFlames ?? 8, "buildingFlames", 0, 256);
928
+ if (!n && !r) return;
929
+ let { Flame: i } = await import("@margoengine/vfx/flame"), a = t.flame?.lights;
930
+ if (a && "maxLights" in a) {
931
+ let { LightGroups: t } = await import("@margoengine/clustered/groups");
932
+ a = this.lightGroups = t.attach(e, a);
933
+ }
934
+ if (this.disposed) return;
935
+ let o = () => i.attach(e, {
936
+ haze: I,
937
+ ...t.flame,
938
+ ...a ? { lights: a } : {},
939
+ position: [
940
+ 0,
941
+ -1e6,
942
+ 0
943
+ ],
944
+ length: 0,
945
+ footprint: [1, 1],
946
+ wind: [0, 0]
947
+ });
948
+ for (; this.frontFlames.length < n;) this.frontFlames.push(o());
949
+ for (; this.houseFlames.length < r;) this.houseFlames.push(o());
950
+ if (n && t.flameEmbers !== !1 && await this.makeEmbers(e, n), !this.disposed) {
951
+ if (this.flameLook) for (let e of [...this.frontFlames, ...this.houseFlames]) e.setFlameLook(this.flameLook);
952
+ this.syncFlames();
953
+ }
954
+ }
955
+ async makeEmbers(e, t) {
956
+ let [{ VFX: n }, { curves: r }, { shapes: i }, { stretch: a }, { schedule: o }, { overLife: s }, { scaleHearthEmbers: c }, { snowNight: l }] = await Promise.all([
957
+ import("@margoengine/vfx/base"),
958
+ import("@margoengine/vfx/curves"),
959
+ import("@margoengine/vfx/shapes"),
960
+ import("@margoengine/vfx/stretch"),
961
+ import("@margoengine/vfx/schedule"),
962
+ import("@margoengine/vfx/over-life"),
963
+ import("@margoengine/vfx/flame"),
964
+ import("@margoengine/sky/scene-kits")
965
+ ]);
966
+ if (this.disposed) return;
967
+ let u = c(l().hearth.embers, F, [F, F]);
968
+ for (; this.emberPool.length < t;) {
969
+ let t = structuredClone(u);
970
+ delete t.schedule, this.emberBase.push({
971
+ rate: u.rate,
972
+ size: u.size,
973
+ intensity: u.intensity,
974
+ velocity: [...u.velocity]
975
+ }), this.emberPool.push(n.attach(e, {
976
+ ...t,
977
+ position: [
978
+ 0,
979
+ -1e6,
980
+ 0
981
+ ],
982
+ rate: 0,
983
+ wind: [0, 0]
984
+ }, {
985
+ curves: r,
986
+ emitter: i,
987
+ stretch: a,
988
+ schedule: o,
989
+ overLife: s
990
+ }));
991
+ }
992
+ }
993
+ setFlameLook(e) {
994
+ this.flameLook = { ...e };
995
+ for (let e of [...this.frontFlames, ...this.houseFlames]) e.setFlameLook(this.flameLook);
996
+ return this.placeEmbers(), this;
997
+ }
998
+ setSmokeLook(e) {
999
+ this.smokeLook = e;
1000
+ for (let t of this.columns) e(t);
1001
+ return this;
1002
+ }
1003
+ syncFlames() {
1004
+ if (!this.frontFlames.length && !this.houseFlames.length) return;
1005
+ let e = this.flames();
1006
+ this.place(this.frontFlames, this.frontKeys, e.filter((e) => e.kind === "front")), this.placeEmbers(), this.place(this.houseFlames, this.houseKeys, e.filter((e) => e.kind === "structure"));
1007
+ }
1008
+ place(e, t, n) {
1009
+ let r = n.slice(0, e.length);
1010
+ for (let n = 0; n < e.length; n++) t[n] !== void 0 && !r.some((e) => e.key === t[n]) && (t[n] = void 0);
1011
+ for (let n of r) if (!t.includes(n.key)) {
1012
+ let r = -1;
1013
+ for (let n = 0; n < e.length; n++) if (t[n] === void 0) {
1014
+ r = n;
1015
+ break;
1016
+ }
1017
+ t[r] = n.key;
1018
+ }
1019
+ let i = this.options.windReduction ?? .4;
1020
+ for (let n = 0; n < e.length; n++) {
1021
+ let a = e[n], o = t[n] === void 0 ? void 0 : r.find((e) => e.key === t[n]), s = a.options;
1022
+ if (!o) {
1023
+ s.length = 0;
1024
+ continue;
1025
+ }
1026
+ let c = s.position, l = s.footprint, u = s.wind, d = o.kind === "structure" ? .7 : 1;
1027
+ c[0] = o.x, c[1] = o.y, c[2] = o.z, l[0] = o.footprint[0] * d, l[1] = o.footprint[1] * d, s.yaw = o.yaw, s.length = o.flameLength, s.heat = o.heat / .7;
1028
+ let f = this.noonValue ?? this.options.smoke?.noon;
1029
+ f === void 0 ? delete s.noon : s.noon = f, s.slope = o.slope, s.relief = o.kind === "front" ? this.reliefOf(o, s.relief ?? new Float32Array(R ** 2)) : void 0, o.kind === "front" && (s.crowns = this.options.flame?.crowns ?? (o.crown >= .25 ? P : 0)), this.windAt(o.x, o.z, this.midflame), u[0] = this.midflame[0] * i, u[1] = this.midflame[1] * i;
1030
+ }
1031
+ }
1032
+ reliefOf(e, t) {
1033
+ let n = this.options.ground ?? (() => 0), r = Math.cos(e.yaw), i = Math.sin(e.yaw), a = e.footprint[0] / 2, o = e.footprint[1] / 2;
1034
+ for (let s = 0; s < R; s++) for (let c = 0; c < R; c++) {
1035
+ let l = (2 * c / 7 - 1) * a, u = (2 * s / 7 - 1) * o, d = r * l + i * u, f = -i * l + r * u;
1036
+ t[s * R + c] = n(e.x + d, e.z + f) - (e.y + e.slope[0] * d + e.slope[1] * f);
1037
+ }
1038
+ return t;
1039
+ }
1040
+ placeEmbers() {
1041
+ let e = this.flameLook, t = (t) => e && typeof e[t] == "number" ? e[t] : 1;
1042
+ for (let e = 0; e < this.emberPool.length; e++) {
1043
+ let n = this.emberPool[e], r = this.emberBase[e], i = this.frontFlames[e], a = n.options, o = i?.options.length ?? 0;
1044
+ if (!i || !(o > 0)) {
1045
+ a.rate = 0;
1046
+ continue;
1047
+ }
1048
+ let s = i.options, c = s.footprint, l = Math.abs(Math.cos(s.yaw ?? 0)), u = Math.abs(Math.sin(s.yaw ?? 0)), d = Math.sqrt(o / F), f = Math.min(4, Math.max(1, Math.max(c[0], c[1]) / o));
1049
+ a.position[0] = s.position[0], a.position[1] = s.position[1] + o / 3, a.position[2] = s.position[2], a.emissionExtent = [
1050
+ (l * c[0] + u * c[1]) / 2,
1051
+ o / 6,
1052
+ (u * c[0] + l * c[1]) / 2
1053
+ ], a.rate = r.rate * d * f * t("embers.count"), a.size = r.size * t("embers.size"), a.intensity = r.intensity * t("embers.radiance"), a.velocity = r.velocity.map((e) => e * d), this.windAt(s.position[0], s.position[2], this.midflame), a.wind[0] = this.midflame[0], a.wind[1] = this.midflame[1];
1054
+ }
1055
+ }
1056
+ onPreUpdate(e) {
1057
+ if (e > 0 && (this.doubled = this.stepped ? this.doubled + 1 : 0, this.stepped = !1, this.doubled >= 2)) throw new t("state", "FireFront was stepped with advanceTime between engine frames that also step it, so it burns faster than the engine clock; step it one way: leave it to the engine, or step a fire made without an engine yourself");
1058
+ this.fromEngine = !0;
1059
+ try {
1060
+ this.advanceTime(e);
1061
+ } finally {
1062
+ this.fromEngine = !1;
1063
+ }
1064
+ }
1065
+ dispose() {
1066
+ if (!this.disposed) {
1067
+ this.disposed = !0, this.engine?.sceneOf(this)?.removePlugin(this.name), this.texture?.destroy(), this.texture = void 0;
1068
+ for (let e of this.columns) e.dispose();
1069
+ this.columns.length = 0;
1070
+ for (let e of [...this.frontFlames, ...this.houseFlames]) e.dispose();
1071
+ for (let e of this.emberPool) e.dispose();
1072
+ this.emberPool.length = 0, this.lightGroups?.dispose(), this.lightGroups = void 0, this.frontFlames.length = 0, this.houseFlames.length = 0, this.engine = void 0;
1073
+ }
1074
+ }
1075
+ [Symbol.dispose]() {
1076
+ this.dispose();
1077
+ }
1078
+ };
1079
+ //#endregion
1080
+ export { O as BURNING, k as BURNT, a as FUEL_MODELS, te as FireFront, A as NO_FUEL, j as RADIANT_SHARE, D as UNBURNT, C as crownBehaviour, w as crownRate10, y as ellipseRate, g as fireBehaviour, p as fuelBed, h as slopeFactor, m as windFactor };