@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,840 @@
1
+ // @margo/core-built 0.1.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const e=(engine,version="0.1.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), j = k(m), M = m.length && p.length ? D(p, 138) / D(m, 500) : 0, N = e.extinction, P = m.length ? Math.max(N, 2.9 * M * (1 - O / N) - .226) : N, F = (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
+ }, I = Math.min(.174 * c ** -.19, 1), L = S ** 1.5 / (495 + .0594 * S ** 1.5), R = 133 * S ** -.7913, z = L * (T / E) ** R * Math.exp(R * (1 - T / E)), B = (e) => {
183
+ let t = h(e);
184
+ return t > 0 ? e.reduce((e, n) => e + n.area / t * n.w * .9445, 0) : 0;
185
+ }, V = z * s * I * (B(p) * F(A, N) + (m.length ? B(m) * F(j, P) : 0)), H = Math.exp((.792 + .681 * Math.sqrt(S)) * (T + .1)) / (192 + .2595 * S), U = (e, t) => t > 0 ? e.reduce((e, n) => e + n.area / t * Math.exp(-138 / n.c.sav) * (250 + 1116 * n.m), 0) : 0, W = w * (b * U(p, g) + x * U(m, _));
186
+ return {
187
+ model: e,
188
+ sigma: S,
189
+ beta: T,
190
+ betaOp: E,
191
+ ir: V,
192
+ rate0: V * H / W * 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, j = 18622e3, M = .3, N = (() => {
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
+ })(), P = 6, F = 20, I = .003, L = -1e9, R = 0;
286
+ function z(e) {
287
+ let t = e >>> 0;
288
+ return () => {
289
+ t = t + 1831565813 >>> 0;
290
+ let e = t;
291
+ return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), ((e ^ e >>> 14) >>> 0) / 4294967296;
292
+ };
293
+ }
294
+ var B = class n {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
295
+ constructor(e) {
296
+ if (this.name = "fire-front:" + R++, this.time = 0, this.embers = 0, this.spots = 0, this.disposed = !1, this.acc = 0, this.fuels = [], this.burning = [], this.pending = [], this.travel = /* @__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");
297
+ this.options = e;
298
+ let t = e.size ?? [1024, 1024], n = f(e.cell ?? 8, "cell", 1, 100);
299
+ for (let e of t) f(e, "size", n, 1e5);
300
+ 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.");
301
+ 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 = z(f(e.seed ?? 1, "seed", 0, 4294967295)), this.checkLive();
302
+ let r = this.width * this.height;
303
+ 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), e.canopy && (this.stands = new Float32Array(r * 3)), this.rows = new Float32Array(this.width * 4), this.fill();
304
+ for (let t of e.ignitions ?? []) this.queue(t);
305
+ }
306
+ static create(e = {}) {
307
+ return new n(e);
308
+ }
309
+ static attach(t, r = {}) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
310
+ let i = new n(r);
311
+ return e(t).use(i), i;
312
+ }
313
+ checkLive() {
314
+ let e = this.options;
315
+ 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");
316
+ if (Array.isArray(e.wind)) for (let t of e.wind) f(t, "wind", -200, 200);
317
+ }
318
+ register(e) {
319
+ let t = this.fuels.indexOf(e);
320
+ if (t < 0) {
321
+ if (this.fuels.length >= 250) throw RangeError("FireFront holds at most 250 different fuel models.");
322
+ this.fuels.push(e), t = this.fuels.length - 1;
323
+ }
324
+ return t + 1;
325
+ }
326
+ resolve(e) {
327
+ if (e != null) {
328
+ if (typeof e == "string") {
329
+ let t = a[e];
330
+ if (!t) throw TypeError(`Unknown fuel model ${e}; use one of ${Object.keys(a).join(", ")} or a FuelModel.`);
331
+ return t;
332
+ }
333
+ return e;
334
+ }
335
+ }
336
+ fill() {
337
+ 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);
338
+ for (let a = 0; a < n; a++) for (let n = 0; n < t; n++) {
339
+ let l = i[0] + (n + .5) * r, u = i[1] + (a + .5) * r, d = s(l, u);
340
+ if (!Number.isFinite(d)) throw RangeError("FireFront ground must return finite heights");
341
+ c[a * t + n] = d;
342
+ let p = this.resolve(typeof o == "function" ? o(l, u) : o);
343
+ if (p ? this.cellFuel[a * t + n] = this.register(p) : this.stateOf[a * t + n] = 3, this.stands) {
344
+ let r = e.canopy(l, u);
345
+ 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([
346
+ r.baseHeight,
347
+ r.bulkDensity,
348
+ r.height
349
+ ], (a * t + n) * 3));
350
+ }
351
+ }
352
+ for (let e = 0; e < n; e++) for (let i = 0; i < t; i++) {
353
+ 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);
354
+ 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);
355
+ }
356
+ let l = this.register(a.STRUCTURE), u = 0;
357
+ for (let a of e.structures ?? []) {
358
+ u++;
359
+ let e = a.radius ?? 6;
360
+ for (let o = 0; o < n; o++) for (let n = 0; n < t; n++) {
361
+ let s = i[0] + (n + .5) * r, c = i[1] + (o + .5) * r;
362
+ 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));
363
+ }
364
+ }
365
+ }
366
+ cellAt(e, t) {
367
+ let n = Math.floor((e - this.origin[0]) / this.cell), r = Math.floor((t - this.origin[1]) / this.cell);
368
+ return n < 0 || r < 0 || n >= this.width || r >= this.height ? -1 : r * this.width + n;
369
+ }
370
+ state(e, t) {
371
+ let n = this.cellAt(e, t);
372
+ return n < 0 ? -1 : this.stateOf[n];
373
+ }
374
+ arrivalTime(e, t) {
375
+ let n = this.cellAt(e, t);
376
+ return n < 0 ? -1 : this.arrival[n];
377
+ }
378
+ crownFraction(e, t) {
379
+ let n = this.cellAt(e, t);
380
+ return n < 0 ? 0 : this.crownOf[n];
381
+ }
382
+ get crowningCells() {
383
+ let e = 0;
384
+ for (let t of this.burning) this.stateOf[t] === 1 && this.crownOf[t] > 0 && e++;
385
+ return e;
386
+ }
387
+ canopyAt(e, t, n) {
388
+ if (this.options.crown === !1 || t.structure) return;
389
+ if (!this.stands) return t.canopy;
390
+ let r = e * 3;
391
+ 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;
392
+ }
393
+ get burningCells() {
394
+ let e = 0;
395
+ for (let t of this.burning) this.stateOf[t] === 1 && e++;
396
+ return e;
397
+ }
398
+ get smokeColumns() {
399
+ return this.columns;
400
+ }
401
+ get smokeEmission() {
402
+ let e = 0;
403
+ for (let t of this.segs.values()) e += t.heat / .7;
404
+ return (this.options.smokeYield ?? 15) * e / j;
405
+ }
406
+ get radiantPower() {
407
+ let e = 0;
408
+ for (let t of this.segs.values()) e += t.heat;
409
+ return M / .7 * e;
410
+ }
411
+ get active() {
412
+ return this.burning.length > 0 || this.pending.length > 0;
413
+ }
414
+ queue(e) {
415
+ if (!Array.isArray(e.at) || e.at.length !== 2) throw TypeError("FireFront ignition needs at: [x, z]");
416
+ 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));
417
+ }
418
+ ignite(e, t, n = 0, r = this.time) {
419
+ return this.queue({
420
+ at: [e, t],
421
+ radius: n,
422
+ time: r
423
+ }), this;
424
+ }
425
+ bedsFor() {
426
+ 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;
427
+ 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;
428
+ }
429
+ light(e, t) {
430
+ if (this.stateOf[e] !== 0 || !this.cellFuel[e]) return !1;
431
+ let n = this.bedsFor()[this.cellFuel[e] - 1], r = n.model;
432
+ 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, !0;
433
+ }
434
+ lightArea(e, t) {
435
+ 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);
436
+ 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++) {
437
+ let s = a[0] + (r + .5) * i - e.at[0], c = a[1] + (d + .5) * i - e.at[1];
438
+ s * s + c * c <= o * o + i * i * .5 && this.light(d * n + r, t);
439
+ }
440
+ }
441
+ windAt(e, t, n) {
442
+ let r = this.options.wind ?? [0, 0];
443
+ if (Array.isArray(r)) n[0] = r[0], n[1] = r[1];
444
+ else {
445
+ let i = r.sample(e, 0, t, this.time);
446
+ n[0] = i[0], n[1] = i[i.length - 1];
447
+ }
448
+ }
449
+ advanceTime(e) {
450
+ if (this.disposed) throw new t("disposed", "FireFront is disposed; attach a new FireFront");
451
+ for (f(e, "delta", 0, 86400), this.checkLive(), this.acc += e; this.acc >= this.step - 1e-9;) this.acc -= this.step, this.advance(this.step);
452
+ this.dirty && this.publish(), this.syncFlames();
453
+ }
454
+ resetTime() {
455
+ if (this.disposed) return;
456
+ this.time = this.acc = this.embers = this.spots = 0, this.random = z(f(this.options.seed ?? 1, "seed", 0, 4294967295));
457
+ let e = this.stateOf;
458
+ for (let t = 0; t < e.length; t++) e[t] !== 3 && (e[t] = 0);
459
+ this.arrival.fill(-1), this.burnout.fill(-1);
460
+ for (let e of [
461
+ this.intensity,
462
+ this.exposure,
463
+ this.crownOf,
464
+ this.fed
465
+ ]) e.fill(0);
466
+ this.burning = [], this.born = [], this.pending = [];
467
+ for (let e of this.options.ignitions ?? []) this.queue(e);
468
+ this.travel.clear(), this.segs.clear(), this.flameAcc.clear(), this.bedKey = "", this.beds = [], this.fm10 = void 0, this.frontKeys.fill(void 0), this.houseKeys.fill(void 0);
469
+ for (let e of [
470
+ ...this.columns,
471
+ ...this.frontFlames,
472
+ ...this.houseFlames,
473
+ ...this.emberPool
474
+ ]) e.resetTime();
475
+ this.dirty = !0, this.texture && this.publish(), this.syncFlames();
476
+ }
477
+ update(e) {
478
+ this.advanceTime(e);
479
+ }
480
+ async settle(e = 86400, t) {
481
+ f(e, "maxSeconds", 0, 1e9);
482
+ let n = this.time + e, r = 0;
483
+ for (; this.active && this.time < n;) t?.throwIfAborted(), this.advance(this.step), ++r % 4096 == 0 && await Promise.resolve();
484
+ return this.dirty && this.publish(), this.time;
485
+ }
486
+ advance(e) {
487
+ let t = this.time + e, n = this.options, { width: r, height: i, cell: a } = this, o = this.bedsFor();
488
+ for (; this.pending.length && (this.pending[0].time ?? 0) <= t;) this.lightArea(this.pending.shift(), t);
489
+ for (let e of this.born) this.burning.push(e);
490
+ this.born.length = 0;
491
+ let s = n.windReduction ?? .4, c = n.spotting ?? .02, l = [0, 0], u = this.fm10, d = n.foliarMoisture ?? 1, f = {
492
+ baseHeight: 0,
493
+ bulkDensity: 0,
494
+ height: 0
495
+ }, p = [];
496
+ this.segs.clear(), this.flameAcc.clear();
497
+ for (let g of this.burning) {
498
+ let _ = g % r, y = (g - _) / r, b = this.origin[0] + (_ + .5) * a, x = this.origin[1] + (y + .5) * a, S = o[this.cellFuel[g] - 1];
499
+ this.stateOf[g] === 1 && t >= this.burnout[g] && (this.stateOf[g] = 2, this.dirty = !0), this.windAt(b, x, l);
500
+ let w = Math.hypot(l[0], l[1]) * s, E = m(S, w), D = this.slopeX[g], O = this.slopeZ[g], k = Math.hypot(D, O), A = h(S, k), M = w > 1e-9 ? l[0] / Math.hypot(l[0], l[1]) : 0, P = w > 1e-9 ? l[1] / Math.hypot(l[0], l[1]) : 0, F = k > 1e-9 ? D / k : 0, I = k > 1e-9 ? O / k : 0, R = E * M + A * F, z = E * P + A * I, B = Math.hypot(R, z), V = v(S, E, A, B), H = B > 1e-9 ? R / B : 1, U = B > 1e-9 ? z / B : 0, W = Math.sqrt(Math.max(V.lengthToBreadth ** 2 - 1, 0)) / V.lengthToBreadth, G = this.canopyAt(g, S.model, f), K, q = H, J = U, Y = W;
501
+ if (G) {
502
+ let e = Math.hypot(l[0], l[1]), t = T(u, e), n = h(u, k), r = t * M + n * F, i = t * P + n * I, a = Math.hypot(r, i), o = C(V, G, d, 3.34 * u.rate0 * (1 + a), e, this.fed[g] === 1);
503
+ o.fraction > 0 && (K = o, a > 1e-9 && (q = r / a, J = i / a), Y = Math.sqrt(Math.max(o.lengthToBreadth ** 2 - 1, 0)) / o.lengthToBreadth);
504
+ }
505
+ let ee = this.stateOf[g] === 1, X = S.model.structure === !0, Z = K ?? V;
506
+ if (ee) {
507
+ this.intensity[g] = Z.firelineIntensity / 1e3, K && K.fraction > this.crownOf[g] && (this.crownOf[g] = K.fraction);
508
+ let r = a * a, i = X ? .7 * S.consumed * j / (n.structureBurnTime ?? 1800) * r : .7 * V.reactionIntensity * 1e3 * r * (K ? K.firelineIntensity / K.rate / (V.firelineIntensity / V.rate) : 1), o = Math.floor((x - this.origin[1]) / this.seg) * 65536 + Math.floor((b - this.origin[0]) / this.seg), s = this.segs.get(o);
509
+ s ? (s.x += b * i, s.z += x * i, s.heat += i, s.cells++) : this.segs.set(o, {
510
+ x: b * i,
511
+ z: x * i,
512
+ heat: i,
513
+ cells: 1
514
+ });
515
+ let u = X ? this.structureOf[g] ? -this.structureOf[g] : L - o : o, d = this.flameAcc.get(u);
516
+ d ? (d.x += b * i, d.z += x * i, d.heat += i, d.cells++, d.intensity += Z.firelineIntensity * i, d.crown += (K?.fraction ?? 0) * i, d.xx += b * b * i, d.zz += x * x * i, d.xz += b * x * i, d.minX = Math.min(d.minX, b - a / 2), d.maxX = Math.max(d.maxX, b + a / 2), d.minZ = Math.min(d.minZ, x - a / 2), d.maxZ = Math.max(d.maxZ, x + a / 2)) : this.flameAcc.set(u, {
517
+ x: b * i,
518
+ z: x * i,
519
+ heat: i,
520
+ cells: 1,
521
+ intensity: Z.firelineIntensity * i,
522
+ crown: (K?.fraction ?? 0) * i,
523
+ xx: b * b * i,
524
+ zz: x * x * i,
525
+ xz: b * x * i,
526
+ minX: b - a / 2,
527
+ maxX: b + a / 2,
528
+ minZ: x - a / 2,
529
+ maxZ: x + a / 2,
530
+ structure: X ? this.structureOf[g] : 0
531
+ }), Z.firelineIntensity > 1e3 && c > 0 && this.throwEmbers(g, Z, l, t, e, c), X || this.exposeStructures(g, Z.flameLength, e, t);
532
+ }
533
+ let Q = this.travel.get(g);
534
+ Q || this.travel.set(g, Q = new Float32Array(N.length));
535
+ let $ = !1;
536
+ for (let n = 0; n < N.length; n++) {
537
+ if (Q[n] >= 1) continue;
538
+ let [o, s] = N[n], c = _ + o, l = y + s, u = l * r + c;
539
+ if (c < 0 || l < 0 || c >= r || l >= i || !this.cellFuel[u] || this.fuels[this.cellFuel[u] - 1].structure || this.stateOf[u] !== 0) {
540
+ Q[n] = 2;
541
+ continue;
542
+ }
543
+ let d = K !== void 0 && this.canopyAt(u, this.fuels[this.cellFuel[u] - 1], f) !== void 0, p = d ? K.rate : V.rate, m = d ? Y : W, h = Math.hypot(o, s) * a, g = (o * (d ? q : H) + s * (d ? J : U)) / Math.hypot(o, s), v = p * (1 - m) / (1 - m * g);
544
+ v > 1e-9 ? (Q[n] = Q[n] + v * e / h, Q[n] >= 1 && this.light(u, t) && d && K.type === "active" ? this.fed[u] = 1 : $ = !0) : Q[n] = 2;
545
+ }
546
+ this.stateOf[g] === 1 || $ ? p.push(g) : this.travel.delete(g);
547
+ }
548
+ for (let e of this.born) p.push(e);
549
+ this.born.length = 0, this.burning = p, this.time = t;
550
+ }
551
+ exposeStructures(e, t, n, r) {
552
+ 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;
553
+ for (let e = -s; e <= s; e++) for (let d = -s; d <= s; d++) {
554
+ let s = c + d, f = l + e;
555
+ if (!d && !e || s < 0 || f < 0 || s >= i || f >= a) continue;
556
+ let p = f * i + s;
557
+ 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)));
558
+ }
559
+ }
560
+ throwEmbers(e, t, n, r, i, a) {
561
+ let o = a * (t.firelineIntensity - 1e3) / 1e3 * i * (this.cell * this.cell / 64), s = Math.floor(o);
562
+ if (this.random() < o - s && s++, !s) return;
563
+ 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];
564
+ for (let e = 0; e < s; e++) {
565
+ 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]);
566
+ if (this.embers++, o < 0 || this.stateOf[o] !== 0 || !this.cellFuel[o]) continue;
567
+ 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 = {
568
+ from: h,
569
+ to: a,
570
+ time: r,
571
+ ignited: f
572
+ };
573
+ f && this.light(o, r) && this.spots++, this.options.onSpot?.(p);
574
+ }
575
+ }
576
+ segments() {
577
+ let e = this.options.ground ?? (() => 0), t = [];
578
+ for (let [n, r] of this.segs) {
579
+ 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;
580
+ t.push({
581
+ x: i,
582
+ z: a,
583
+ y: e(i, a),
584
+ heat: r.heat,
585
+ cells: r.cells,
586
+ flameLength: c
587
+ });
588
+ }
589
+ return t.sort((e, t) => t.heat - e.heat);
590
+ }
591
+ flames() {
592
+ let e = this.options.ground ?? (() => 0), t = this.options.structureVent ?? .1, n = [];
593
+ for (let [r, i] of this.flameAcc) {
594
+ 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)];
595
+ n.push({
596
+ kind: s ? "structure" : "front",
597
+ x: a,
598
+ z: o,
599
+ y: e(a, o),
600
+ heat: i.heat,
601
+ cells: i.cells,
602
+ intensity: _,
603
+ flameLength: y,
604
+ footprint: g,
605
+ yaw: s ? 0 : -p,
606
+ structure: i.structure > 0 ? i.structure - 1 : -1,
607
+ crown: s ? 0 : i.crown / i.heat,
608
+ slope: x,
609
+ key: r
610
+ });
611
+ }
612
+ return n.sort((e, t) => t.heat - e.heat);
613
+ }
614
+ get flameVolumes() {
615
+ return this.frontFlames;
616
+ }
617
+ get flameEmbers() {
618
+ return this.emberPool;
619
+ }
620
+ get buildingFlameVolumes() {
621
+ return this.houseFlames;
622
+ }
623
+ publish() {
624
+ this.dirty = !1;
625
+ let e = this.engine?.gpu, t = this.texture;
626
+ if (e && t) {
627
+ let { width: n, height: r, rows: i } = this;
628
+ for (let a = 0; a < r; a++) {
629
+ for (let e = 0; e < n; e++) {
630
+ let t = a * n + e;
631
+ 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];
632
+ }
633
+ e.queue.writeTexture({
634
+ texture: t,
635
+ origin: [0, a]
636
+ }, i, { bytesPerRow: n * 16 }, [n, 1]);
637
+ }
638
+ }
639
+ let n = this.segments();
640
+ for (let e = 0; e < this.columns.length; e++) {
641
+ let t = this.columns[e], r = n[e];
642
+ if (!r) t.setHeat(0);
643
+ else {
644
+ let e = t.options.position, n = !(t.options.heat > 0);
645
+ 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();
646
+ }
647
+ }
648
+ }
649
+ read() {
650
+ let e = new Float32Array(this.width * this.height * 4);
651
+ 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];
652
+ return e;
653
+ }
654
+ setWind(e) {
655
+ return this.options.wind = e, this;
656
+ }
657
+ setup(e) {
658
+ if (this.disposed) throw new t("disposed", "FireFront is disposed; attach a new FireFront");
659
+ this.engine = e;
660
+ let n = e.gpu;
661
+ if (n) {
662
+ if (this.width > n.limits.maxTextureDimension2D || this.height > n.limits.maxTextureDimension2D) throw RangeError("FireFront grid exceeds the GPU texture limit; raise cell.");
663
+ this.texture = n.createTexture({
664
+ label: "fire-front burn",
665
+ size: [this.width, this.height],
666
+ format: "rgba32float",
667
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC
668
+ }), this.dirty = !0, this.publish();
669
+ }
670
+ this.smokeReady = Promise.all([this.makeColumns(e), this.makeFlames(e)]).then(() => void 0);
671
+ }
672
+ get ready() {
673
+ return this.smokeReady;
674
+ }
675
+ async makeColumns(e) {
676
+ let t = f(this.options.columns ?? 12, "columns", 0, 256);
677
+ if (!t) return;
678
+ let { Smoke: n } = await import("@margoengine/vfx/smoke");
679
+ if (this.disposed) return;
680
+ let r = this.options.smoke ?? {};
681
+ for (this.smokeRadius = r.radius === void 0; this.columns.length < t;) this.columns.push(n.attach(e, {
682
+ lifetime: 300,
683
+ rate: 16,
684
+ stability: 15e-5,
685
+ color: [
686
+ .24,
687
+ .22,
688
+ .2
689
+ ],
690
+ opacity: .6,
691
+ ...r,
692
+ position: [
693
+ 0,
694
+ -1e6,
695
+ 0
696
+ ],
697
+ heat: 0
698
+ }));
699
+ if (this.smokeLook) for (let e of this.columns) this.smokeLook(e);
700
+ this.dirty = !0, this.publish();
701
+ }
702
+ async makeFlames(e) {
703
+ let t = this.options, n = f(t.flames ?? 16, "flames", 0, 256), r = f(t.buildingFlames ?? 8, "buildingFlames", 0, 256);
704
+ if (!n && !r) return;
705
+ let { Flame: i } = await import("@margoengine/vfx/flame"), a = t.flame?.lights;
706
+ if (a && "maxLights" in a) {
707
+ let { LightGroups: t } = await import("@margoengine/clustered/groups");
708
+ a = this.lightGroups = t.attach(e, a);
709
+ }
710
+ if (this.disposed) return;
711
+ let o = () => i.attach(e, {
712
+ haze: I,
713
+ ...t.flame,
714
+ ...a ? { lights: a } : {},
715
+ position: [
716
+ 0,
717
+ -1e6,
718
+ 0
719
+ ],
720
+ length: 0,
721
+ footprint: [1, 1],
722
+ wind: [0, 0]
723
+ });
724
+ for (; this.frontFlames.length < n;) this.frontFlames.push(o());
725
+ for (; this.houseFlames.length < r;) this.houseFlames.push(o());
726
+ if (n && t.flameEmbers !== !1 && await this.makeEmbers(e, n), !this.disposed) {
727
+ if (this.flameLook) for (let e of [...this.frontFlames, ...this.houseFlames]) e.setFlameLook(this.flameLook);
728
+ this.syncFlames();
729
+ }
730
+ }
731
+ async makeEmbers(e, t) {
732
+ let [{ VFX: n }, { curves: r }, { shapes: i }, { stretch: a }, { schedule: o }, { overLife: s }, { scaleHearthEmbers: c }, { snowNight: l }] = await Promise.all([
733
+ import("@margoengine/vfx/base"),
734
+ import("@margoengine/vfx/curves"),
735
+ import("@margoengine/vfx/shapes"),
736
+ import("@margoengine/vfx/stretch"),
737
+ import("@margoengine/vfx/schedule"),
738
+ import("@margoengine/vfx/over-life"),
739
+ import("@margoengine/vfx/flame"),
740
+ import("@margoengine/sky/scene-kits")
741
+ ]);
742
+ if (this.disposed) return;
743
+ let u = c(l().hearth.embers, F, [F, F]);
744
+ for (; this.emberPool.length < t;) {
745
+ let t = structuredClone(u);
746
+ delete t.schedule, this.emberBase.push({
747
+ rate: u.rate,
748
+ size: u.size,
749
+ intensity: u.intensity,
750
+ velocity: [...u.velocity]
751
+ }), this.emberPool.push(n.attach(e, {
752
+ ...t,
753
+ position: [
754
+ 0,
755
+ -1e6,
756
+ 0
757
+ ],
758
+ rate: 0,
759
+ wind: [0, 0]
760
+ }, {
761
+ curves: r,
762
+ emitter: i,
763
+ stretch: a,
764
+ schedule: o,
765
+ overLife: s
766
+ }));
767
+ }
768
+ }
769
+ setFlameLook(e) {
770
+ this.flameLook = { ...e };
771
+ for (let e of [...this.frontFlames, ...this.houseFlames]) e.setFlameLook(this.flameLook);
772
+ return this.placeEmbers(), this;
773
+ }
774
+ setSmokeLook(e) {
775
+ this.smokeLook = e;
776
+ for (let t of this.columns) e(t);
777
+ return this;
778
+ }
779
+ syncFlames() {
780
+ if (!this.frontFlames.length && !this.houseFlames.length) return;
781
+ let e = this.flames();
782
+ 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"));
783
+ }
784
+ place(e, t, n) {
785
+ let r = n.slice(0, e.length);
786
+ for (let n = 0; n < e.length; n++) t[n] !== void 0 && !r.some((e) => e.key === t[n]) && (t[n] = void 0);
787
+ for (let n of r) if (!t.includes(n.key)) {
788
+ let r = -1;
789
+ for (let n = 0; n < e.length; n++) if (t[n] === void 0) {
790
+ r = n;
791
+ break;
792
+ }
793
+ t[r] = n.key;
794
+ }
795
+ let i = this.options.windReduction ?? .4;
796
+ for (let n = 0; n < e.length; n++) {
797
+ let a = e[n], o = t[n] === void 0 ? void 0 : r.find((e) => e.key === t[n]), s = a.options;
798
+ if (!o) {
799
+ s.length = 0;
800
+ continue;
801
+ }
802
+ let c = s.position, l = s.footprint, u = s.wind, d = o.kind === "structure" ? .7 : 1;
803
+ 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.slope = o.slope, 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;
804
+ }
805
+ }
806
+ placeEmbers() {
807
+ let e = this.flameLook, t = (t) => e && typeof e[t] == "number" ? e[t] : 1;
808
+ for (let e = 0; e < this.emberPool.length; e++) {
809
+ let n = this.emberPool[e], r = this.emberBase[e], i = this.frontFlames[e], a = n.options, o = i?.options.length ?? 0;
810
+ if (!i || !(o > 0)) {
811
+ a.rate = 0;
812
+ continue;
813
+ }
814
+ 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));
815
+ a.position[0] = s.position[0], a.position[1] = s.position[1] + o / 3, a.position[2] = s.position[2], a.emissionExtent = [
816
+ (l * c[0] + u * c[1]) / 2,
817
+ o / 6,
818
+ (u * c[0] + l * c[1]) / 2
819
+ ], 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];
820
+ }
821
+ }
822
+ onPreUpdate(e) {
823
+ this.advanceTime(e);
824
+ }
825
+ dispose() {
826
+ if (!this.disposed) {
827
+ this.disposed = !0, this.engine?.sceneOf(this)?.removePlugin(this.name), this.texture?.destroy(), this.texture = void 0;
828
+ for (let e of this.columns) e.dispose();
829
+ this.columns.length = 0;
830
+ for (let e of [...this.frontFlames, ...this.houseFlames]) e.dispose();
831
+ for (let e of this.emberPool) e.dispose();
832
+ this.emberPool.length = 0, this.lightGroups?.dispose(), this.lightGroups = void 0, this.frontFlames.length = 0, this.houseFlames.length = 0, this.engine = void 0;
833
+ }
834
+ }
835
+ [Symbol.dispose]() {
836
+ this.dispose();
837
+ }
838
+ };
839
+ //#endregion
840
+ export { O as BURNING, k as BURNT, a as FUEL_MODELS, B as FireFront, A as NO_FUEL, M 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 };