@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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1642 -3
- package/dist/base-C9upJytz.js +658 -0
- package/dist/base.d.ts +767 -0
- package/dist/base.js +1 -0
- package/dist/blown-sand.d.ts +218 -0
- package/dist/blown-sand.js +700 -0
- package/dist/clouds.d.ts +229 -0
- package/dist/clouds.js +566 -0
- package/dist/compat-CVSEj1Bp.js +217 -0
- package/dist/compat.d.ts +59 -0
- package/dist/curves.d.ts +11 -0
- package/dist/curves.js +59 -0
- package/dist/debris.d.ts +111 -0
- package/dist/debris.js +258 -0
- package/dist/depth-collide.d.ts +7 -0
- package/dist/depth-collide.js +96 -0
- package/dist/emitter.d.ts +10 -0
- package/dist/emitter.js +125 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +131 -0
- package/dist/extra-CgGjbojB.js +4 -0
- package/dist/extra.d.ts +2 -0
- package/dist/fields.d.ts +11 -0
- package/dist/fields.js +95 -0
- package/dist/fire-front.d.ts +539 -0
- package/dist/fire-front.js +840 -0
- package/dist/fire.d.ts +119 -0
- package/dist/fire.js +173 -0
- package/dist/flame-ramp-VoBKpYnM.js +75 -0
- package/dist/flame-ramp.d.ts +61 -0
- package/dist/flame.d.ts +260 -0
- package/dist/flame.js +605 -0
- package/dist/flipbook.d.ts +7 -0
- package/dist/flipbook.js +23 -0
- package/dist/fog-B-kBv7g0.js +32 -0
- package/dist/frame-BuvMFBPp.js +4 -0
- package/dist/frame.d.ts +7 -0
- package/dist/gunfire.d.ts +696 -0
- package/dist/gunfire.js +1204 -0
- package/dist/hash-Btsp6fGK.js +7 -0
- package/dist/hash.d.ts +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +60 -0
- package/dist/json.d.ts +53 -0
- package/dist/json.js +237 -0
- package/dist/lit.d.ts +11 -0
- package/dist/lit.js +105 -0
- package/dist/mesh.d.ts +14 -0
- package/dist/mesh.js +225 -0
- package/dist/node-system.d.ts +315 -0
- package/dist/node-system.js +384 -0
- package/dist/nodes.d.ts +14 -0
- package/dist/nodes.js +293 -0
- package/dist/obstacles.d.ts +3 -0
- package/dist/obstacles.js +25 -0
- package/dist/over-life.d.ts +14 -0
- package/dist/over-life.js +93 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/ribbons.d.ts +20 -0
- package/dist/ribbons.js +151 -0
- package/dist/schedule.d.ts +29 -0
- package/dist/schedule.js +47 -0
- package/dist/settings.d.ts +362 -0
- package/dist/settings.js +707 -0
- package/dist/shader.d.ts +44 -0
- package/dist/shadows.d.ts +26 -0
- package/dist/shadows.js +182 -0
- package/dist/shapes.d.ts +34 -0
- package/dist/shapes.js +81 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/pass.d.ts +53 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/skinned.d.ts +11 -0
- package/dist/skinned.js +104 -0
- package/dist/smoke.d.ts +215 -0
- package/dist/smoke.js +280 -0
- package/dist/soft.d.ts +17 -0
- package/dist/soft.js +55 -0
- package/dist/solid.d.ts +168 -0
- package/dist/solid.js +403 -0
- package/dist/sort.d.ts +3 -0
- package/dist/sort.js +58 -0
- package/dist/space.d.ts +14 -0
- package/dist/space.js +88 -0
- package/dist/stretch.d.ts +7 -0
- package/dist/stretch.js +40 -0
- package/dist/texture.d.ts +8 -0
- package/dist/texture.js +45 -0
- package/dist/view-RKprOPAy.js +30 -0
- package/dist/view-rect-DkeiiUtw.js +13 -0
- package/dist/wrap.d.ts +3 -0
- package/dist/wrap.js +5 -0
- package/package.json +192 -6
package/dist/gunfire.js
ADDED
|
@@ -0,0 +1,1204 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const t=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { r as e } from "./flame-ramp-VoBKpYnM.js";
|
|
5
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
6
|
+
import { finiteVector as n } from "@margoengine/math/validate";
|
|
7
|
+
import { VFX as r } from "@margoengine/vfx/base";
|
|
8
|
+
import { curves as i } from "@margoengine/vfx/curves";
|
|
9
|
+
import { stretch as a } from "@margoengine/vfx/stretch";
|
|
10
|
+
import { overLife as o } from "@margoengine/vfx/over-life";
|
|
11
|
+
import { Flame as s } from "@margoengine/vfx/flame";
|
|
12
|
+
import { Smoke as c } from "@margoengine/vfx/smoke";
|
|
13
|
+
import { Clouds as l } from "@margoengine/vfx/clouds";
|
|
14
|
+
//#region src/gunfire.ts
|
|
15
|
+
var u = 9.81, d = 1.225, f = 1005, p = 288.15, m = 340.3, h = Object.freeze({
|
|
16
|
+
saltpetre: .75,
|
|
17
|
+
charcoal: .15,
|
|
18
|
+
sulphur: .1,
|
|
19
|
+
gasFraction: .4298,
|
|
20
|
+
solidFraction: .5591,
|
|
21
|
+
waterFraction: .0111,
|
|
22
|
+
gasVolume: .2713,
|
|
23
|
+
heat: 3004530.4,
|
|
24
|
+
flameTemperature: 2473
|
|
25
|
+
}), g = (e, t, n, r, i = !1) => {
|
|
26
|
+
if (!(typeof e == "number" && Number.isFinite(e) && (i ? e > n : e >= n) && e <= r)) throw RangeError(`Gunfire ${t} is ${e}; pass a finite number ${i ? "above" : "from"} ${n} ${i ? "and at most" : "to"} ${r}`);
|
|
27
|
+
return e;
|
|
28
|
+
};
|
|
29
|
+
function _(e) {
|
|
30
|
+
g(e, "charge", 0, 1e4);
|
|
31
|
+
let t = h;
|
|
32
|
+
return {
|
|
33
|
+
gas: e * t.gasFraction,
|
|
34
|
+
smoke: e * t.solidFraction,
|
|
35
|
+
water: e * t.waterFraction,
|
|
36
|
+
gasVolume: e * t.gasVolume,
|
|
37
|
+
heat: e * t.heat
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
var v = .04, y = .05;
|
|
41
|
+
function b(t, n = v) {
|
|
42
|
+
let r = _(t), i = (r.gasVolume + r.water * 22.414 / 18.015) * h.flameTemperature / 273.15;
|
|
43
|
+
return g(n, "flash duration", 0, 10, !0), {
|
|
44
|
+
radius: Math.cbrt(3 * i / (4 * Math.PI)),
|
|
45
|
+
duration: n,
|
|
46
|
+
color: e(h.flameTemperature)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function x(e, t, n = v) {
|
|
50
|
+
if (!(Number.isFinite(e) && Number.isFinite(t) && t >= 0 && n > 0)) throw RangeError("Gunfire flashExposure needs finite numbers, shutter 0 or more, duration above 0");
|
|
51
|
+
if (e < 0) return 0;
|
|
52
|
+
if (t < 1e-9) return Math.exp(-e / n);
|
|
53
|
+
let r = Math.max(0, e - t);
|
|
54
|
+
return n / t * (Math.exp(-r / n) - Math.exp(-e / n));
|
|
55
|
+
}
|
|
56
|
+
var S = 160, C = class {
|
|
57
|
+
constructor(e) {
|
|
58
|
+
if (this.times = new Float64Array(S), this.table = /* @__PURE__ */ new Float64Array(640), !e || typeof e != "object") throw TypeError("PowderPuff needs {charge, muzzleVelocity}");
|
|
59
|
+
let t = g(e.charge, "charge", 0, 1e4, !0), n = g(e.muzzleVelocity, "muzzleVelocity", 0, 3e3, !0), r = g(e.elevation ?? 0, "elevation", -Math.PI / 2, Math.PI / 2), i = g(e.momentum ?? 1.5, "momentum", 0, 10), a = g(e.heatFraction ?? .4, "heatFraction", 0, 1), o = g(e.entrainment ?? .25, "entrainment", .05, 1), s = g(e.stability ?? 0, "stability", 0, 1), c = g(e.airTemperature ?? p, "airTemperature", 150, 350), l = g(e.duration ?? 600, "duration", 1, 7200);
|
|
60
|
+
this.duration = l;
|
|
61
|
+
let m = b(t).radius, h = _(t);
|
|
62
|
+
this.startRadius = m, this.momentum = i * t * n / d, this.buoyancy = u * a * h.heat / (f * d * c);
|
|
63
|
+
let v = 4 / 3 * Math.PI * o ** 3, y = (e, t) => {
|
|
64
|
+
let n = v * e[0] ** 3, r = e[1] / n, i = e[2] / n;
|
|
65
|
+
t[0] = Math.hypot(r, i), t[1] = 0, t[2] = e[3], t[3] = -s * n * i, t[4] = r, t[5] = i;
|
|
66
|
+
}, x = new Float64Array([
|
|
67
|
+
m / o,
|
|
68
|
+
this.momentum * Math.cos(r),
|
|
69
|
+
this.momentum * Math.sin(r),
|
|
70
|
+
this.buoyancy,
|
|
71
|
+
0,
|
|
72
|
+
0
|
|
73
|
+
]), C = /* @__PURE__ */ new Float64Array(6), w = /* @__PURE__ */ new Float64Array(6), T = /* @__PURE__ */ new Float64Array(6), E = /* @__PURE__ */ new Float64Array(6), D = /* @__PURE__ */ new Float64Array(6), O = (e) => {
|
|
74
|
+
y(x, C);
|
|
75
|
+
for (let t = 0; t < 6; t++) D[t] = x[t] + .5 * e * C[t];
|
|
76
|
+
y(D, w);
|
|
77
|
+
for (let t = 0; t < 6; t++) D[t] = x[t] + .5 * e * w[t];
|
|
78
|
+
y(D, T);
|
|
79
|
+
for (let t = 0; t < 6; t++) D[t] = x[t] + e * T[t];
|
|
80
|
+
y(D, E);
|
|
81
|
+
for (let t = 0; t < 6; t++) x[t] = x[t] + e / 6 * (C[t] + 2 * w[t] + 2 * T[t] + E[t]);
|
|
82
|
+
}, k = .001, A = (l / k) ** (1 / 158), j = 0, M = (e) => {
|
|
83
|
+
let t = v * x[0] ** 3;
|
|
84
|
+
this.times[e] = j, this.table[e * 4] = x[4], this.table[e * 4 + 1] = x[5], this.table[e * 4 + 2] = o * x[0], this.table[e * 4 + 3] = Math.hypot(x[1], x[2]) / t;
|
|
85
|
+
};
|
|
86
|
+
M(0);
|
|
87
|
+
for (let e = 1; e < S; e++) {
|
|
88
|
+
let t = k * A ** (e - 1), n = Math.max(1, Math.ceil(50 * Math.min(1, (t - j) / Math.max(t, 1e-9)) * 4)), r = (t - j) / n;
|
|
89
|
+
for (let e = 0; e < n; e++) O(r);
|
|
90
|
+
j = t, M(e);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
at(e, t) {
|
|
94
|
+
let n = t ?? {
|
|
95
|
+
along: 0,
|
|
96
|
+
rise: 0,
|
|
97
|
+
radius: 0,
|
|
98
|
+
speed: 0
|
|
99
|
+
}, r = this.times, i = Math.max(0, Math.min(this.duration, e)), a = 0, o = 159;
|
|
100
|
+
for (; o - a > 1;) {
|
|
101
|
+
let e = a + o >> 1;
|
|
102
|
+
r[e] <= i ? a = e : o = e;
|
|
103
|
+
}
|
|
104
|
+
let s = r[o] > r[a] ? (i - r[a]) / (r[o] - r[a]) : 0, c = a * 4, l = o * 4, u = this.table;
|
|
105
|
+
return n.along = u[c] + (u[l] - u[c]) * s, n.rise = u[c + 1] + (u[l + 1] - u[c + 1]) * s, n.radius = u[c + 2] + (u[l + 2] - u[c + 2]) * s, n.speed = u[c + 3] + (u[l + 3] - u[c + 3]) * s, n;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function w(e, t, n = 10, r = .5) {
|
|
109
|
+
if (!(e >= 0 && t >= 0 && n > 0 && r >= 0)) throw RangeError("Gunfire smokeDispersion needs seconds, wind and constant 0 or more and a height above 0");
|
|
110
|
+
let i = (Math.sqrt(.0012) * t) ** 3 / (.4 * n);
|
|
111
|
+
return Math.sqrt(r * i * e ** 3);
|
|
112
|
+
}
|
|
113
|
+
function T(e) {
|
|
114
|
+
let t = Math.max(0, e), n = [
|
|
115
|
+
[0, .47],
|
|
116
|
+
[.6, .5],
|
|
117
|
+
[.8, .6],
|
|
118
|
+
[1, .82],
|
|
119
|
+
[1.2, .95],
|
|
120
|
+
[2, .92],
|
|
121
|
+
[5, .92]
|
|
122
|
+
];
|
|
123
|
+
for (let e = 1; e < n.length; e++) {
|
|
124
|
+
let [r, i] = n[e];
|
|
125
|
+
if (t <= r) {
|
|
126
|
+
let [a, o] = n[e - 1];
|
|
127
|
+
return o + (i - o) * (t - a) / (r - a);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return .92;
|
|
131
|
+
}
|
|
132
|
+
var E = (e, t) => Math.cbrt(3 * e / (4 * Math.PI * t)), D = Object.freeze({
|
|
133
|
+
density: 680,
|
|
134
|
+
strength: 74e5
|
|
135
|
+
}), O = (e = {}) => ({
|
|
136
|
+
density: g(e.density ?? D.density, "wood density", 100, 2e3),
|
|
137
|
+
strength: g(e.strength ?? D.strength, "wood strength", 1e5, 1e9)
|
|
138
|
+
});
|
|
139
|
+
function k(e, t, n, r) {
|
|
140
|
+
let i = O(r), a = g(e, "strike speed", 0, 3e3), o = Math.PI * g(t, "shot radius", 1e-4, 10) ** 2, s = g(n, "shot mass", 0, 2e3, !0), c = .5 * i.density;
|
|
141
|
+
return s / (2 * c * o) * Math.log(1 + c * a * a / i.strength);
|
|
142
|
+
}
|
|
143
|
+
function A(e, t, n, r, i) {
|
|
144
|
+
let a = O(i), o = g(e, "strike speed", 0, 3e3), s = Math.PI * g(t, "shot radius", 1e-4, 10) ** 2, c = g(n, "shot mass", 0, 2e3, !0), l = g(r, "thickness", 0, 100), u = a.strength / (.5 * a.density), d = (u + o * o) * Math.exp(-1 * a.density * s * l / c) - u;
|
|
145
|
+
return d > 0 ? Math.sqrt(d) : 0;
|
|
146
|
+
}
|
|
147
|
+
var j = .8, M = .3, N = 6e-5, P = (e) => typeof e.matrix == "function" ? e.matrix() : e, F = (e, t) => {
|
|
148
|
+
let n = [
|
|
149
|
+
t[0] - e[12],
|
|
150
|
+
t[1] - e[13],
|
|
151
|
+
t[2] - e[14]
|
|
152
|
+
], r = [
|
|
153
|
+
0,
|
|
154
|
+
0,
|
|
155
|
+
0
|
|
156
|
+
];
|
|
157
|
+
for (let t = 0; t < 3; t++) {
|
|
158
|
+
let i = e[t * 4], a = e[t * 4 + 1], o = e[t * 4 + 2];
|
|
159
|
+
r[t] = (n[0] * i + n[1] * a + n[2] * o) / (i * i + a * a + o * o || 1);
|
|
160
|
+
}
|
|
161
|
+
return r;
|
|
162
|
+
}, I = (e) => {
|
|
163
|
+
if (!e || typeof e != "object" || !e.ship) throw TypeError("Gunfire target needs {ship}: a Floater or a world matrix");
|
|
164
|
+
let t = P(e.ship);
|
|
165
|
+
if (!t || t.length < 16) throw TypeError("Gunfire target ship must have matrix() or be 16 numbers");
|
|
166
|
+
return {
|
|
167
|
+
m: t,
|
|
168
|
+
a: g(e.beam ?? 13, "target beam", .5, 100) / 2,
|
|
169
|
+
b: g(e.length ?? 50, "target length", 1, 500) / 2,
|
|
170
|
+
top: g(e.height ?? 6, "target height", 0, 50),
|
|
171
|
+
keel: -g(e.draft ?? 5, "target draft", 0, 50),
|
|
172
|
+
thickness: g(e.thickness ?? .5, "target thickness", .01, 10),
|
|
173
|
+
wood: O(e.wood)
|
|
174
|
+
};
|
|
175
|
+
}, L = (e, t) => t[1] >= e.keel && t[1] <= e.top && (t[0] / e.a) ** 2 + (t[2] / e.b) ** 2 <= 1, ee = (e, t) => {
|
|
176
|
+
let n = (t[0] / e.a) ** 2 + (t[2] / e.b) ** 2 < .98 && t[1] > e.top - .05 ? [
|
|
177
|
+
0,
|
|
178
|
+
1,
|
|
179
|
+
0
|
|
180
|
+
] : [
|
|
181
|
+
t[0] / (e.a * e.a),
|
|
182
|
+
0,
|
|
183
|
+
t[2] / (e.b * e.b)
|
|
184
|
+
], r = K(e.m, n), i = Math.hypot(r[0], r[1], r[2]) || 1;
|
|
185
|
+
return [
|
|
186
|
+
r[0] / i,
|
|
187
|
+
r[1] / i,
|
|
188
|
+
r[2] / i
|
|
189
|
+
];
|
|
190
|
+
};
|
|
191
|
+
function R(e, t, r, i = {}, a = {}) {
|
|
192
|
+
n(e, 3, "Gunfire shot position"), n(t, 3, "Gunfire shot direction"), g(r, "shot speed", 0, 3e3);
|
|
193
|
+
let o = g(i.mass ?? 14.5, "shot mass", 0, 2e3, !0), s = g(i.density ?? 7200, "shot density", 500, 25e3), c = E(o, s), l = Math.PI * c * c, u = Math.hypot(t[0], t[1], t[2]);
|
|
194
|
+
if (!(u > 0)) throw RangeError("Gunfire shot direction must not be zero");
|
|
195
|
+
let f = a.seaLevel ?? 0, p = g(a.maxTime ?? 30, "maxTime", 0, 600), h = a.drag ?? !0, _ = a.fireTime ?? 0, v = a.wind, y = (a.targets ?? []).map(I), b = y.map((t) => L(t, F(t.m, e))), x = [], S = (e, t) => a.water?.sample(e, t)?.height ?? f, C = [
|
|
196
|
+
e[0],
|
|
197
|
+
e[1],
|
|
198
|
+
e[2],
|
|
199
|
+
t[0] / u * r,
|
|
200
|
+
t[1] / u * r,
|
|
201
|
+
t[2] / u * r
|
|
202
|
+
], w = (e, t) => {
|
|
203
|
+
let [n, r] = q(v, [
|
|
204
|
+
e[0],
|
|
205
|
+
e[1],
|
|
206
|
+
e[2]
|
|
207
|
+
], _ + t), i = e[3] - n, a = e[4], s = e[5] - r, c = Math.hypot(i, a, s), u = h && c > 0 ? .5 * d * T(c / m) * l * c / o : 0;
|
|
208
|
+
return [
|
|
209
|
+
e[3],
|
|
210
|
+
e[4],
|
|
211
|
+
e[5],
|
|
212
|
+
-u * i,
|
|
213
|
+
-9.81 - u * a,
|
|
214
|
+
-u * s
|
|
215
|
+
];
|
|
216
|
+
}, D = .002, O = 0, P = (e, t, n, r) => {
|
|
217
|
+
let i = y[e], a = 0, s = 1;
|
|
218
|
+
for (let e = 0; e < 30; e++) {
|
|
219
|
+
let e = (a + s) / 2, o = [
|
|
220
|
+
t[0] + (n[0] - t[0]) * e,
|
|
221
|
+
t[1] + (n[1] - t[1]) * e,
|
|
222
|
+
t[2] + (n[2] - t[2]) * e
|
|
223
|
+
];
|
|
224
|
+
L(i, F(i.m, o)) === r ? a = e : s = e;
|
|
225
|
+
}
|
|
226
|
+
let u = t.map((e, t) => e + (n[t] - e) * s), d = [
|
|
227
|
+
u[0],
|
|
228
|
+
u[1],
|
|
229
|
+
u[2]
|
|
230
|
+
], f = [
|
|
231
|
+
u[3],
|
|
232
|
+
u[4],
|
|
233
|
+
u[5]
|
|
234
|
+
], p = F(i.m, d), m = ee(i, p), h = Math.abs(f[0] * m[0] + f[1] * m[1] + f[2] * m[2]), g = k(Math.min(3e3, h), c, o, i.wood), v = {
|
|
235
|
+
target: e,
|
|
236
|
+
kind: "lodged",
|
|
237
|
+
time: _ + O + s * D,
|
|
238
|
+
position: d,
|
|
239
|
+
local: p,
|
|
240
|
+
normal: m,
|
|
241
|
+
velocity: f,
|
|
242
|
+
after: [
|
|
243
|
+
0,
|
|
244
|
+
0,
|
|
245
|
+
0
|
|
246
|
+
],
|
|
247
|
+
depth: g,
|
|
248
|
+
hole: c * 1.1,
|
|
249
|
+
splinters: 0
|
|
250
|
+
};
|
|
251
|
+
if (x.push(v), !r && g < c) {
|
|
252
|
+
let e = [
|
|
253
|
+
f[0] + h * m[0],
|
|
254
|
+
f[1] + h * m[1],
|
|
255
|
+
f[2] + h * m[2]
|
|
256
|
+
];
|
|
257
|
+
v.kind = "ricochet", v.hole = 0, v.after = [
|
|
258
|
+
j * e[0] + M * h * m[0],
|
|
259
|
+
j * e[1] + M * h * m[1],
|
|
260
|
+
j * e[2] + M * h * m[2]
|
|
261
|
+
], v.splinters = Math.round(l * g / N);
|
|
262
|
+
for (let e = 0; e < 3; e++) C[e] = d[e] + m[e] * c * .01, C[e + 3] = v.after[e];
|
|
263
|
+
return "on";
|
|
264
|
+
}
|
|
265
|
+
let S = A(Math.min(3e3, h), c, o, i.thickness, i.wood);
|
|
266
|
+
if (v.splinters = Math.round(l * Math.min(g, i.thickness) / N), S <= 0) return "lodged";
|
|
267
|
+
v.kind = r ? "exit" : "through";
|
|
268
|
+
let w = S / h;
|
|
269
|
+
v.after = [
|
|
270
|
+
f[0] * w,
|
|
271
|
+
f[1] * w,
|
|
272
|
+
f[2] * w
|
|
273
|
+
];
|
|
274
|
+
let T = Math.hypot(f[0], f[1], f[2]) || 1;
|
|
275
|
+
for (let e = 0; e < 3; e++) C[e] = d[e] + f[e] / T * (r ? c * .01 : i.thickness + c * .01), C[e + 3] = v.after[e];
|
|
276
|
+
return b[e] = !r, "on";
|
|
277
|
+
};
|
|
278
|
+
for (; O < p;) {
|
|
279
|
+
let e = w(C, O), t = w(C.map((t, n) => t + .5 * D * e[n]), O + D / 2), n = w(C.map((e, n) => e + .5 * D * t[n]), O + D / 2), r = w(C.map((e, t) => e + D * n[t]), O + D), i = C.map((i, a) => i + D / 6 * (e[a] + 2 * t[a] + 2 * n[a] + r[a])), a = !1;
|
|
280
|
+
for (let e = 0; e < y.length && !a; e++) if (L(y[e], F(y[e].m, [
|
|
281
|
+
i[0],
|
|
282
|
+
i[1],
|
|
283
|
+
i[2]
|
|
284
|
+
])) !== b[e]) {
|
|
285
|
+
if (P(e, C, i, b[e]) === "lodged") return { hits: x };
|
|
286
|
+
a = !0;
|
|
287
|
+
}
|
|
288
|
+
if (a) {
|
|
289
|
+
O += D;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
let o = b.some(Boolean), l = C[1] - S(C[0], C[2]), u = i[1] - S(i[0], i[2]);
|
|
293
|
+
if (!o && u <= 0 && l > 0) {
|
|
294
|
+
let e = l / (l - u), t = C.map((t, n) => t + (i[n] - t) * e);
|
|
295
|
+
return {
|
|
296
|
+
hits: x,
|
|
297
|
+
impact: {
|
|
298
|
+
time: _ + O + e * D,
|
|
299
|
+
position: [
|
|
300
|
+
t[0],
|
|
301
|
+
S(t[0], t[2]),
|
|
302
|
+
t[2]
|
|
303
|
+
],
|
|
304
|
+
velocity: [
|
|
305
|
+
t[3],
|
|
306
|
+
t[4],
|
|
307
|
+
t[5]
|
|
308
|
+
],
|
|
309
|
+
radius: c,
|
|
310
|
+
density: s
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
for (let e = 0; e < 6; e++) C[e] = i[e];
|
|
315
|
+
O += D;
|
|
316
|
+
}
|
|
317
|
+
return { hits: x };
|
|
318
|
+
}
|
|
319
|
+
function te(e, t, n, r = {}, i = {}) {
|
|
320
|
+
return R(e, t, n, r, i).impact;
|
|
321
|
+
}
|
|
322
|
+
var z = .01, B = 1750, V = .02;
|
|
323
|
+
function H(e, t = .003, n = 490) {
|
|
324
|
+
g(e, "charge", 0, 1e4);
|
|
325
|
+
let r = g(t, "grain", 5e-4, .02), i = g(n, "grain speed", 0, 3e3), a = Math.PI / 6 * r ** 3 * B, o = r / (2 * z), s = .5 * d * Math.PI * (r / 2) ** 2 / a, c = [1], l = i, u = 0, f = 0, p = (e) => -s * T(e / m) * e * e;
|
|
326
|
+
for (let e = 1; e < 32; e++) {
|
|
327
|
+
let t = o * e / 31;
|
|
328
|
+
for (; f < t - 1e-12;) {
|
|
329
|
+
let e = Math.min(.001, t - f), n = p(l), r = p(l + .5 * e * n), i = p(l + .5 * e * r), a = p(l + e * i);
|
|
330
|
+
u += e / 6 * (l + 2 * (l + .5 * e * n) + 2 * (l + .5 * e * r) + (l + e * i)), l += e / 6 * (n + 2 * r + 2 * i + a), f += e;
|
|
331
|
+
}
|
|
332
|
+
c.push(i > 0 ? Math.max(0, l / i) : 0);
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
count: e * V / a,
|
|
336
|
+
burnTime: o,
|
|
337
|
+
stopping: 4 / 3 * r * B / (d * .47),
|
|
338
|
+
reach: u,
|
|
339
|
+
speeds: c
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function U(e) {
|
|
343
|
+
g(e, "soot", 0, 1);
|
|
344
|
+
let t = 8.7 * e, n = 3 * (1 - e), r = (.25 * t + .97 * n) / Math.max(1e-9, t + n);
|
|
345
|
+
return [
|
|
346
|
+
r,
|
|
347
|
+
r * .985,
|
|
348
|
+
r * .96
|
|
349
|
+
];
|
|
350
|
+
}
|
|
351
|
+
var W = 0, G = (e, t) => [
|
|
352
|
+
e[0] * t[0] + e[4] * t[1] + e[8] * t[2] + e[12],
|
|
353
|
+
e[1] * t[0] + e[5] * t[1] + e[9] * t[2] + e[13],
|
|
354
|
+
e[2] * t[0] + e[6] * t[1] + e[10] * t[2] + e[14]
|
|
355
|
+
], K = (e, t) => [
|
|
356
|
+
e[0] * t[0] + e[4] * t[1] + e[8] * t[2],
|
|
357
|
+
e[1] * t[0] + e[5] * t[1] + e[9] * t[2],
|
|
358
|
+
e[2] * t[0] + e[6] * t[1] + e[10] * t[2]
|
|
359
|
+
], q = (e, t, n) => {
|
|
360
|
+
if (!e) return [0, 0];
|
|
361
|
+
if ("sample" in e) {
|
|
362
|
+
let r = e.sample(t[0], t[1], t[2], n);
|
|
363
|
+
return [r[0], r[2]];
|
|
364
|
+
}
|
|
365
|
+
return [e[0], e[1]];
|
|
366
|
+
}, ne = [
|
|
367
|
+
1,
|
|
368
|
+
0,
|
|
369
|
+
0,
|
|
370
|
+
0,
|
|
371
|
+
0,
|
|
372
|
+
1,
|
|
373
|
+
0,
|
|
374
|
+
0,
|
|
375
|
+
0,
|
|
376
|
+
0,
|
|
377
|
+
1,
|
|
378
|
+
0,
|
|
379
|
+
0,
|
|
380
|
+
0,
|
|
381
|
+
0,
|
|
382
|
+
1
|
|
383
|
+
], re = class e {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
|
|
384
|
+
constructor(e, n) {
|
|
385
|
+
if (this.name = "vfx-gunfire:" + W++, this.flashes = [], this.lights = [], this.fired = [], this.sparks = [], this.pendingHits = [], this.hitCursor = 0, this.disposed = !1, this.clock = 0, this.cursor = 0, this.banks = [], this.drift = [0, 0], this.puffs = /* @__PURE__ */ new Map(), this.point = {
|
|
386
|
+
along: 0,
|
|
387
|
+
rise: 0,
|
|
388
|
+
radius: 0,
|
|
389
|
+
speed: 0
|
|
390
|
+
}, this.lastDelta = 1 / 30, this.options = n, !Array.isArray(n.guns) || n.guns.length < 1 || n.guns.length > 128) throw TypeError("Battery needs 1 to 128 guns; pass {guns: [{position, direction}]}");
|
|
391
|
+
for (let e of n.guns) this.checkGun(e);
|
|
392
|
+
this.queue = [...n.shots ?? []];
|
|
393
|
+
for (let e of this.queue) this.checkShot(e);
|
|
394
|
+
if (this.queue.sort((e, t) => e.time - t.time || e.gun - t.gun), n.ship && typeof n.ship.matrix != "function") throw TypeError("Battery ship needs matrix(), such as a Floater");
|
|
395
|
+
this.checkLive();
|
|
396
|
+
let s = g(n.banks ?? 48, "banks", 1, 512), c = g(n.puffs ?? 24, "puffs", 4, 128);
|
|
397
|
+
if (!Number.isInteger(s) || !Number.isInteger(c)) throw RangeError("Battery banks and puffs must be whole numbers");
|
|
398
|
+
let u = n.lights, d = u && "names" in u && "clustered" in u ? u : void 0, f = d ? d.clustered : u && "maxLights" in u ? u : void 0;
|
|
399
|
+
if (u && !f) throw TypeError("Invalid Battery lights; pass a Clustered from @margoengine/clustered or its LightGroups");
|
|
400
|
+
if (d) {
|
|
401
|
+
let e = "gunfire";
|
|
402
|
+
for (let t = 2; d.names.includes(e); t++) e = `gunfire ${t}`;
|
|
403
|
+
this.target = this.group = d.group(e);
|
|
404
|
+
} else f && (this.target = f);
|
|
405
|
+
t(e).use(this), this.clouds = l.attach(e, {
|
|
406
|
+
...n.clouds ?? {},
|
|
407
|
+
limit: s * c
|
|
408
|
+
});
|
|
409
|
+
let p = (e, t) => {
|
|
410
|
+
let n = t(), r = t(), i = Math.cbrt(t()), a = 2 * Math.PI * n, o = Math.acos(2 * r - 1);
|
|
411
|
+
return {
|
|
412
|
+
point: [
|
|
413
|
+
i * Math.sin(o) * Math.cos(a),
|
|
414
|
+
i * Math.sin(o) * Math.sin(a) * .8,
|
|
415
|
+
i * Math.cos(o)
|
|
416
|
+
],
|
|
417
|
+
volume: .75 + .25 * (1 - i) + 0 * e
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
for (let e = 0; e < s; e++) this.banks.push({
|
|
421
|
+
cloud: this.clouds.add({
|
|
422
|
+
seed: 1 + e * 7,
|
|
423
|
+
segments: c,
|
|
424
|
+
bounds: [
|
|
425
|
+
1.6,
|
|
426
|
+
1.6,
|
|
427
|
+
1.6
|
|
428
|
+
],
|
|
429
|
+
volume: 1.2,
|
|
430
|
+
distribute: p,
|
|
431
|
+
opacity: 0,
|
|
432
|
+
speed: .15
|
|
433
|
+
}),
|
|
434
|
+
shot: null,
|
|
435
|
+
puff: null
|
|
436
|
+
});
|
|
437
|
+
for (let [t, s] of n.guns.entries()) {
|
|
438
|
+
let t = b(s.charge ?? 4.5), c = n.flashDuration ?? .04, l = {
|
|
439
|
+
capacity: 64,
|
|
440
|
+
rate: 0,
|
|
441
|
+
position: [
|
|
442
|
+
0,
|
|
443
|
+
-1e6,
|
|
444
|
+
0
|
|
445
|
+
],
|
|
446
|
+
velocity: [
|
|
447
|
+
0,
|
|
448
|
+
0,
|
|
449
|
+
0
|
|
450
|
+
],
|
|
451
|
+
spread: 0,
|
|
452
|
+
gravity: [
|
|
453
|
+
0,
|
|
454
|
+
0,
|
|
455
|
+
0
|
|
456
|
+
],
|
|
457
|
+
size: t.radius,
|
|
458
|
+
lifetime: [Math.max(.05, 3 * c), Math.max(.08, 4 * c)],
|
|
459
|
+
ground: -1e9,
|
|
460
|
+
turbulence: 0,
|
|
461
|
+
intensity: 0,
|
|
462
|
+
color: [
|
|
463
|
+
t.color[0],
|
|
464
|
+
t.color[1],
|
|
465
|
+
t.color[2],
|
|
466
|
+
y
|
|
467
|
+
],
|
|
468
|
+
curves: {
|
|
469
|
+
size: [
|
|
470
|
+
.5,
|
|
471
|
+
1,
|
|
472
|
+
1,
|
|
473
|
+
.8
|
|
474
|
+
],
|
|
475
|
+
alpha: [
|
|
476
|
+
1,
|
|
477
|
+
1,
|
|
478
|
+
.6,
|
|
479
|
+
0
|
|
480
|
+
]
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
this.flashes.push(r.attach(e, l, { curves: i })), this.sparks.push(r.attach(e, {
|
|
484
|
+
capacity: 2048,
|
|
485
|
+
rate: 0,
|
|
486
|
+
position: [
|
|
487
|
+
0,
|
|
488
|
+
-1e6,
|
|
489
|
+
0
|
|
490
|
+
],
|
|
491
|
+
velocity: [
|
|
492
|
+
0,
|
|
493
|
+
0,
|
|
494
|
+
0
|
|
495
|
+
],
|
|
496
|
+
spread: 0,
|
|
497
|
+
gravity: [
|
|
498
|
+
0,
|
|
499
|
+
-9.81,
|
|
500
|
+
0
|
|
501
|
+
],
|
|
502
|
+
size: n.sparkSize ?? .3,
|
|
503
|
+
lifetime: [.1, .2],
|
|
504
|
+
ground: -1e9,
|
|
505
|
+
turbulence: 0,
|
|
506
|
+
intensity: 0,
|
|
507
|
+
color: [
|
|
508
|
+
t.color[0],
|
|
509
|
+
t.color[1],
|
|
510
|
+
t.color[2],
|
|
511
|
+
1
|
|
512
|
+
],
|
|
513
|
+
curves: { alpha: [
|
|
514
|
+
1,
|
|
515
|
+
1,
|
|
516
|
+
.8,
|
|
517
|
+
0
|
|
518
|
+
] },
|
|
519
|
+
overLife: { speed: [1, 1] },
|
|
520
|
+
stretch: { factor: 1 / 60 }
|
|
521
|
+
}, {
|
|
522
|
+
curves: i,
|
|
523
|
+
overLife: o,
|
|
524
|
+
stretch: a
|
|
525
|
+
})), this.target && this.lights.push({
|
|
526
|
+
position: [
|
|
527
|
+
0,
|
|
528
|
+
-1e6,
|
|
529
|
+
0
|
|
530
|
+
],
|
|
531
|
+
range: 1,
|
|
532
|
+
intensity: 0,
|
|
533
|
+
color: t.color,
|
|
534
|
+
radius: t.radius
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
this.splinters = r.attach(e, {
|
|
538
|
+
capacity: 2048,
|
|
539
|
+
rate: 0,
|
|
540
|
+
position: [
|
|
541
|
+
0,
|
|
542
|
+
-1e6,
|
|
543
|
+
0
|
|
544
|
+
],
|
|
545
|
+
velocity: [
|
|
546
|
+
0,
|
|
547
|
+
0,
|
|
548
|
+
0
|
|
549
|
+
],
|
|
550
|
+
spread: 0,
|
|
551
|
+
gravity: [
|
|
552
|
+
0,
|
|
553
|
+
-9.81,
|
|
554
|
+
0
|
|
555
|
+
],
|
|
556
|
+
size: .12,
|
|
557
|
+
lifetime: [1.5, 3],
|
|
558
|
+
ground: n.seaLevel ?? 0,
|
|
559
|
+
turbulence: .2,
|
|
560
|
+
angularVelocity: 8,
|
|
561
|
+
intensity: 1,
|
|
562
|
+
color: [
|
|
563
|
+
.42,
|
|
564
|
+
.3,
|
|
565
|
+
.18,
|
|
566
|
+
1
|
|
567
|
+
]
|
|
568
|
+
}), this.target?.setLights(this.lights);
|
|
569
|
+
}
|
|
570
|
+
checkGun(e) {
|
|
571
|
+
if (!e || typeof e != "object") throw TypeError("Battery gun needs {position, direction}");
|
|
572
|
+
if (n(e.position, 3, "Battery gun position"), n(e.direction, 3, "Battery gun direction"), !(Math.hypot(e.direction[0], e.direction[1], e.direction[2]) > 0)) throw RangeError("Battery gun direction must not be zero");
|
|
573
|
+
g(e.charge ?? 4.5, "charge", 0, 1e4, !0), g(e.muzzleVelocity ?? 490, "muzzleVelocity", 0, 3e3, !0);
|
|
574
|
+
}
|
|
575
|
+
checkShot(e) {
|
|
576
|
+
if (!e || !Number.isInteger(e.gun) || e.gun < 0 || e.gun >= this.options.guns.length) throw RangeError("Battery shot gun must be a gun index");
|
|
577
|
+
g(e.time, "shot time", 0, 1e7);
|
|
578
|
+
}
|
|
579
|
+
checkLive() {
|
|
580
|
+
let e = this.options;
|
|
581
|
+
if (g(e.flashDuration ?? .04, "flashDuration", .001, 1), g(e.flashSize ?? 1, "flashSize", 0, 10), g(e.flashRadiance ?? 40, "flashRadiance", 0, 3e3), g(e.flashLight ?? 1, "flashLight", 0, 100), g(e.shutter ?? .5, "shutter", 0, 1), g(e.extinction ?? 3, "extinction", 0, 100), g(e.dispersion ?? .5, "dispersion", 0, 5), g(e.smokeLife ?? 600, "smokeLife", 1, 7200), g(e.stability ?? 1e-4, "stability", 0, 1), g(e.heatFraction ?? .4, "heatFraction", 0, 1), g(e.entrainment ?? .25, "entrainment", .05, 1), g(e.sparks ?? 1, "sparks", 0, 10), g(e.sparkRadiance ?? 30, "sparkRadiance", 0, 3e3), g(e.sparkSize ?? .3, "sparkSize", .01, 2), g(e.grain ?? .003, "grain", 5e-4, .02), g(e.splinters ?? 1, "splinters", 0, 10), e.targets !== void 0 && !Array.isArray(e.targets)) throw TypeError("Battery targets must be a list of {ship, length, beam}");
|
|
582
|
+
if (e.smokeColor) {
|
|
583
|
+
n(e.smokeColor, 3, "Battery smokeColor");
|
|
584
|
+
for (let t of e.smokeColor) g(t, "smokeColor channel", 0, 1);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
resetTime() {
|
|
588
|
+
if (this.disposed) return;
|
|
589
|
+
this.clock = this.cursor = this.hitCursor = 0, this.lastDelta = 1 / 30, this.drift[0] = this.drift[1] = 0, this.queue.length = 0, this.queue.push(...this.options.shots ?? []), this.queue.sort((e, t) => e.time - t.time || e.gun - t.gun), this.fired.length = 0, this.pendingHits.length = 0, this.puffs.clear(), this.point.along = this.point.rise = this.point.radius = this.point.speed = 0;
|
|
590
|
+
for (let e of this.banks) e.shot = e.puff = null, e.cloud.options.opacity = 0, e.cloud.matrix.set(ne);
|
|
591
|
+
this.clouds.resetTime();
|
|
592
|
+
for (let e of [
|
|
593
|
+
...this.flashes,
|
|
594
|
+
...this.sparks,
|
|
595
|
+
this.splinters
|
|
596
|
+
]) e.resetTime();
|
|
597
|
+
for (let e of this.lights) e.position.splice(0, 3, 0, -1e6, 0), e.intensity = 0;
|
|
598
|
+
this.target?.setLights(this.lights);
|
|
599
|
+
let e = /* @__PURE__ */ new Set();
|
|
600
|
+
for (let t of this.options.targets ?? []) {
|
|
601
|
+
if (!t.mask || e.has(t.mask)) continue;
|
|
602
|
+
e.add(t.mask);
|
|
603
|
+
let n = Q(t.mask).data;
|
|
604
|
+
for (let e = 2; e < n.length; e += 4) n[e] = 0;
|
|
605
|
+
t.mask.update();
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
fire(e, t = this.clock) {
|
|
609
|
+
let n = {
|
|
610
|
+
gun: e,
|
|
611
|
+
time: t
|
|
612
|
+
};
|
|
613
|
+
this.checkShot(n);
|
|
614
|
+
let r = this.queue.length;
|
|
615
|
+
for (; r > this.cursor && this.queue[r - 1].time > t;) r--;
|
|
616
|
+
return this.queue.splice(Math.max(r, this.cursor), 0, n), this;
|
|
617
|
+
}
|
|
618
|
+
broadside(e, t = .25, n) {
|
|
619
|
+
return g(t, "broadside interval", 0, 60), (n ?? this.options.guns.map((e, t) => t)).forEach((n, r) => this.fire(n, e + r * t)), this;
|
|
620
|
+
}
|
|
621
|
+
puffOf(e) {
|
|
622
|
+
let t = this.options, n = t.guns[e], r = this.worldDirection(n), i = Math.asin(Math.max(-1, Math.min(1, r[1]))), a = [
|
|
623
|
+
n.charge ?? 4.5,
|
|
624
|
+
n.muzzleVelocity ?? 490,
|
|
625
|
+
i.toFixed(4),
|
|
626
|
+
t.stability ?? 1e-4,
|
|
627
|
+
t.heatFraction ?? .4,
|
|
628
|
+
t.entrainment ?? .25,
|
|
629
|
+
t.smokeLife ?? 600
|
|
630
|
+
].join("|"), o = this.puffs.get(a);
|
|
631
|
+
return o || (o = new C({
|
|
632
|
+
charge: n.charge ?? 4.5,
|
|
633
|
+
muzzleVelocity: n.muzzleVelocity ?? 490,
|
|
634
|
+
elevation: i,
|
|
635
|
+
stability: t.stability ?? 1e-4,
|
|
636
|
+
heatFraction: t.heatFraction ?? .4,
|
|
637
|
+
entrainment: t.entrainment ?? .25,
|
|
638
|
+
duration: t.smokeLife ?? 600
|
|
639
|
+
}), this.puffs.size > 64 && this.puffs.clear(), this.puffs.set(a, o)), o;
|
|
640
|
+
}
|
|
641
|
+
worldDirection(e) {
|
|
642
|
+
let t = this.options.ship ? K(this.options.ship.matrix(), e.direction) : [
|
|
643
|
+
e.direction[0],
|
|
644
|
+
e.direction[1],
|
|
645
|
+
e.direction[2]
|
|
646
|
+
], n = Math.hypot(t[0], t[1], t[2]);
|
|
647
|
+
return [
|
|
648
|
+
t[0] / n,
|
|
649
|
+
t[1] / n,
|
|
650
|
+
t[2] / n
|
|
651
|
+
];
|
|
652
|
+
}
|
|
653
|
+
wind() {
|
|
654
|
+
let e = this.options.wind ?? this.flashes[0]?.options.wind, t = this.options.guns[0].position;
|
|
655
|
+
return q(e, this.options.ship ? G(this.options.ship.matrix(), t) : t, this.clock);
|
|
656
|
+
}
|
|
657
|
+
impacts() {
|
|
658
|
+
return this.fired.flatMap((e) => e.impact ? [e.impact] : []);
|
|
659
|
+
}
|
|
660
|
+
get time() {
|
|
661
|
+
return this.clock;
|
|
662
|
+
}
|
|
663
|
+
setup(e) {
|
|
664
|
+
this.engine = e;
|
|
665
|
+
}
|
|
666
|
+
onPreUpdate(e) {
|
|
667
|
+
this.advanceTime(e);
|
|
668
|
+
}
|
|
669
|
+
advanceTime(e) {
|
|
670
|
+
if (this.disposed) return;
|
|
671
|
+
let t = e > 0 ? e : 0;
|
|
672
|
+
t > 0 && (this.lastDelta = t);
|
|
673
|
+
let n = this.wind();
|
|
674
|
+
this.drift[0] += n[0] * t, this.drift[1] += n[1] * t, this.clock += t, this.checkLive();
|
|
675
|
+
let r = this.options;
|
|
676
|
+
for (; this.cursor < this.queue.length && this.queue[this.cursor].time <= this.clock;) {
|
|
677
|
+
let e = this.queue[this.cursor++], t = r.guns[e.gun], i = r.ship?.matrix(), a = i ? G(i, t.position) : [
|
|
678
|
+
t.position[0],
|
|
679
|
+
t.position[1],
|
|
680
|
+
t.position[2]
|
|
681
|
+
], o = this.worldDirection(t), s = this.clock - e.time, c = {
|
|
682
|
+
gun: e.gun,
|
|
683
|
+
time: e.time,
|
|
684
|
+
muzzle: a,
|
|
685
|
+
direction: o,
|
|
686
|
+
drift: [this.drift[0] - n[0] * s, this.drift[1] - n[1] * s],
|
|
687
|
+
hits: []
|
|
688
|
+
}, l = r.wind ?? this.flashes[0]?.options.wind, u = R(a, o, t.muzzleVelocity ?? 490, t.shot ?? {}, {
|
|
689
|
+
fireTime: e.time,
|
|
690
|
+
seaLevel: r.seaLevel ?? 0,
|
|
691
|
+
...r.water ? { water: r.water } : {},
|
|
692
|
+
...l ? { wind: l } : {},
|
|
693
|
+
...r.targets?.length ? { targets: r.targets } : {}
|
|
694
|
+
});
|
|
695
|
+
u.impact && (c.impact = u.impact), c.hits = u.hits;
|
|
696
|
+
for (let e of u.hits) {
|
|
697
|
+
let t = this.pendingHits.length;
|
|
698
|
+
for (; t > this.hitCursor && this.pendingHits[t - 1].time > e.time;) t--;
|
|
699
|
+
this.pendingHits.splice(t, 0, e);
|
|
700
|
+
}
|
|
701
|
+
this.fired.push(c);
|
|
702
|
+
let d = this.banks.find((e) => !e.shot);
|
|
703
|
+
d ||= this.banks.reduce((e, t) => e.shot.time <= t.shot.time ? e : t), d.shot = c, d.puff = this.puffOf(e.gun);
|
|
704
|
+
let f = this.flashes[e.gun], p = f.options, m = b(t.charge ?? 4.5, r.flashDuration ?? .04).radius * (r.flashSize ?? 1);
|
|
705
|
+
p.position = [
|
|
706
|
+
a[0] + o[0] * m * .8,
|
|
707
|
+
a[1] + o[1] * m * .8,
|
|
708
|
+
a[2] + o[2] * m * .8
|
|
709
|
+
], p.emissionExtent = [
|
|
710
|
+
m * .45,
|
|
711
|
+
m * .45,
|
|
712
|
+
m * .45
|
|
713
|
+
], p.velocity = [
|
|
714
|
+
o[0] * m * 4,
|
|
715
|
+
o[1] * m * 4,
|
|
716
|
+
o[2] * m * 4
|
|
717
|
+
], p.spread = m * 1.5, p.size = m * 1.6, f.burst(24);
|
|
718
|
+
let h = t.muzzleVelocity ?? 490, g = H(t.charge ?? 4.5, r.grain ?? .003, h), _ = this.sparks[e.gun], v = _.options;
|
|
719
|
+
v.position = [
|
|
720
|
+
a[0] + o[0] * m * .5,
|
|
721
|
+
a[1] + o[1] * m * .5,
|
|
722
|
+
a[2] + o[2] * m * .5
|
|
723
|
+
], v.velocity = [
|
|
724
|
+
o[0] * h,
|
|
725
|
+
o[1] * h,
|
|
726
|
+
o[2] * h
|
|
727
|
+
], v.spread = .1 * h, v.emissionExtent = [
|
|
728
|
+
m * .3,
|
|
729
|
+
m * .3,
|
|
730
|
+
m * .3
|
|
731
|
+
], v.lifetime = [.7 * g.burnTime, 1.3 * g.burnTime], v.overLife = { speed: g.speeds };
|
|
732
|
+
let y = Math.round(Math.min(2048, g.count * (r.sparks ?? 1)));
|
|
733
|
+
y > 0 && _.burst(y);
|
|
734
|
+
}
|
|
735
|
+
for (; this.hitCursor < this.pendingHits.length && this.pendingHits[this.hitCursor].time <= this.clock;) this.strike(this.pendingHits[this.hitCursor++]);
|
|
736
|
+
this.place();
|
|
737
|
+
}
|
|
738
|
+
hits() {
|
|
739
|
+
return this.pendingHits.slice(0, this.hitCursor);
|
|
740
|
+
}
|
|
741
|
+
strike(e) {
|
|
742
|
+
let t = this.options, n = e.normal, r = Math.hypot(e.velocity[0], e.velocity[1], e.velocity[2]), i = {
|
|
743
|
+
position: [...e.position],
|
|
744
|
+
emissionExtent: [
|
|
745
|
+
e.hole + .05,
|
|
746
|
+
e.hole + .05,
|
|
747
|
+
e.hole + .05
|
|
748
|
+
],
|
|
749
|
+
velocity: [
|
|
750
|
+
0,
|
|
751
|
+
0,
|
|
752
|
+
0
|
|
753
|
+
],
|
|
754
|
+
spread: 0
|
|
755
|
+
};
|
|
756
|
+
if (e.kind === "through" || e.kind === "exit") {
|
|
757
|
+
let t = Math.min(150, .5 * r) / (r || 1);
|
|
758
|
+
i.velocity = [
|
|
759
|
+
e.velocity[0] * t,
|
|
760
|
+
e.velocity[1] * t,
|
|
761
|
+
e.velocity[2] * t
|
|
762
|
+
], i.spread = .6 * Math.min(150, .5 * r);
|
|
763
|
+
} else i.velocity = [
|
|
764
|
+
n[0] * 15,
|
|
765
|
+
n[1] * 15 + 3,
|
|
766
|
+
n[2] * 15
|
|
767
|
+
], i.spread = 10;
|
|
768
|
+
let a = Math.round(Math.min(2048, e.splinters * (t.splinters ?? 1)));
|
|
769
|
+
a > 0 && this.splinters.burst(a, i);
|
|
770
|
+
let o = t.targets?.[e.target];
|
|
771
|
+
o?.mask && e.hole > 0 && le(o.mask, e.local, e.hole, o);
|
|
772
|
+
}
|
|
773
|
+
place() {
|
|
774
|
+
let e = this.options, t = this.clock, n = (e.shutter ?? .5) * this.lastDelta, r = e.flashDuration ?? .04, i = e.flashRadiance ?? 40, a = /* @__PURE__ */ new Map();
|
|
775
|
+
for (let n = this.fired.length - 1; n >= 0 && a.size < e.guns.length; n--) {
|
|
776
|
+
let e = this.fired[n];
|
|
777
|
+
if (a.has(e.gun) || a.set(e.gun, e), t - e.time > 1) break;
|
|
778
|
+
}
|
|
779
|
+
for (let o = 0; o < e.guns.length; o++) {
|
|
780
|
+
let s = a.get(o), c = s ? x(t - s.time, n, r) : 0, l = e.guns[o], u = b(l.charge ?? 4.5, r).radius * (e.flashSize ?? 1);
|
|
781
|
+
this.flashes[o].options.intensity = Math.min(65504, i * c / y);
|
|
782
|
+
let d = this.sparks[o].options;
|
|
783
|
+
d.intensity = e.sparkRadiance ?? 30, d.size = e.sparkSize ?? .3, d.stretch = { factor: Math.min(10, n) };
|
|
784
|
+
let f = this.lights[o];
|
|
785
|
+
if (f && s) {
|
|
786
|
+
let t = f.position;
|
|
787
|
+
t[0] = s.muzzle[0] + s.direction[0] * u, t[1] = s.muzzle[1] + s.direction[1] * u, t[2] = s.muzzle[2] + s.direction[2] * u, f.radius = u, f.range = 60 * Math.max(u, .5), f.intensity = c > 1e-4 ? Math.PI * u * u * i * c * (e.flashLight ?? 1) : 0;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
this.target && this.target.setLights(this.lights);
|
|
791
|
+
let o = (e.extinction ?? 3) * 1e3, s = e.smokeLife ?? 600, c = Math.hypot(...this.wind()), l = e.smokeColor ?? U(0), u = this.point, d = 0, f = 0;
|
|
792
|
+
for (let n of this.banks) {
|
|
793
|
+
let r = n.shot, i = n.cloud;
|
|
794
|
+
if (!r || !n.puff) {
|
|
795
|
+
i.options.opacity = 0;
|
|
796
|
+
continue;
|
|
797
|
+
}
|
|
798
|
+
let a = t - r.time;
|
|
799
|
+
if (a < 0) {
|
|
800
|
+
i.options.opacity = 0;
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
if (a > s) {
|
|
804
|
+
n.shot = null, i.options.opacity = 0;
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
n.puff.at(a, u);
|
|
808
|
+
let p = w(a, c, Math.max(2, r.muzzle[1] + u.rise), e.dispersion ?? .5), m = Math.sqrt(u.radius * u.radius + 2 * p * p), h = e.guns[r.gun], g = o * _(h.charge ?? 4.5).smoke / (Math.PI * m * m), v = Math.hypot(r.direction[0], r.direction[2]) || 1, y = r.direction[0] / v, b = r.direction[2] / v, x = r.muzzle[0] + y * u.along + (this.drift[0] - r.drift[0]), S = r.muzzle[1] + u.rise, C = r.muzzle[2] + b * u.along + (this.drift[1] - r.drift[1]), T = 1 + Math.min(1.5, u.along / Math.max(.001, 4 * m));
|
|
809
|
+
i.matrix.set([
|
|
810
|
+
y * m * T,
|
|
811
|
+
0,
|
|
812
|
+
b * m * T,
|
|
813
|
+
0,
|
|
814
|
+
0,
|
|
815
|
+
m,
|
|
816
|
+
0,
|
|
817
|
+
0,
|
|
818
|
+
-b * m,
|
|
819
|
+
0,
|
|
820
|
+
y * m,
|
|
821
|
+
0,
|
|
822
|
+
x,
|
|
823
|
+
S,
|
|
824
|
+
C,
|
|
825
|
+
1
|
|
826
|
+
]);
|
|
827
|
+
let E = g / Math.max(1, i.options.segments * Math.PI * .36 / (1.6 * 1.6));
|
|
828
|
+
i.options.opacity = Math.min(1, 1 - Math.exp(-E)), i.options.color = [
|
|
829
|
+
l[0],
|
|
830
|
+
l[1],
|
|
831
|
+
l[2]
|
|
832
|
+
], g < .01 ? (n.shot = null, i.options.opacity = 0) : (d += Math.min(8, E), f++);
|
|
833
|
+
}
|
|
834
|
+
this.clouds.options.density = f > 0 ? d / f : 1;
|
|
835
|
+
let p = e.clouds ?? {};
|
|
836
|
+
for (let e of Object.keys(p)) this.clouds.options[e] = p[e];
|
|
837
|
+
}
|
|
838
|
+
static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
839
|
+
if (!n || typeof n != "object") throw TypeError("Invalid Battery options; pass {guns: [{position, direction}]}");
|
|
840
|
+
return new e(t, n);
|
|
841
|
+
}
|
|
842
|
+
dispose() {
|
|
843
|
+
if (!this.disposed) {
|
|
844
|
+
this.disposed = !0, this.engine?.sceneOf(this)?.removePlugin(this.name), this.engine = void 0;
|
|
845
|
+
for (let e of this.flashes) e.dispose();
|
|
846
|
+
for (let e of this.sparks) e.dispose();
|
|
847
|
+
this.splinters.dispose(), this.clouds.dispose(), this.group ? this.group.dispose() : this.target && this.target.setLights([]);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
[Symbol.dispose]() {
|
|
851
|
+
this.dispose();
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
function J(e, t) {
|
|
855
|
+
return g(e, "vent area", 0, 1e4), g(t, "vent height", 0, 100), .09 * e * Math.sqrt(t);
|
|
856
|
+
}
|
|
857
|
+
function Y(e, t, n) {
|
|
858
|
+
return g(e, "burning rate", 0, 1e5), g(t, "vent width", 0, 100, !0), g(n, "vent height", 0, 100), Math.max(0, 12.8 * Math.cbrt((e / t) ** 2) - n);
|
|
859
|
+
}
|
|
860
|
+
var X = 16e6, Z = 24, ie = 1.5, ae = .5, Q = (e) => {
|
|
861
|
+
let t = e?.source;
|
|
862
|
+
if (!t || !(t.data instanceof Uint8Array || t.data instanceof Uint8ClampedArray) || !Number.isInteger(t.width) || !Number.isInteger(t.height) || t.data.length !== t.width * t.height * 4 || typeof e.update != "function") throw TypeError("Gunfire hull mask needs a Texture of raw RGBA8 data: new Texture(hullMaskImage(), {colorSpace: \"linear\"})");
|
|
863
|
+
return t;
|
|
864
|
+
};
|
|
865
|
+
function oe(e = 256, t = 64) {
|
|
866
|
+
if (!Number.isInteger(e) || !Number.isInteger(t) || e < 4 || t < 2 || e > 4096 || t > 4096 || e % 2) throw RangeError("hullMaskImage needs an even whole width 4..4096 and a whole height 2..4096");
|
|
867
|
+
let n = new Uint8Array(e * t * 4);
|
|
868
|
+
for (let e = 3; e < n.length; e += 4) n[e] = 255;
|
|
869
|
+
return {
|
|
870
|
+
data: n,
|
|
871
|
+
width: e,
|
|
872
|
+
height: t
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
function se(e, t = {}) {
|
|
876
|
+
if (!e || e.length % 3) throw TypeError("hullMaskUVs needs x, y, z for each vertex");
|
|
877
|
+
let n = g(t.length ?? 50, "hull length", 1, 500), r = g(t.deck ?? 6, "hull deck", 0, 50), i = g(t.draft ?? 5, "hull draft", 0, 50), a = new Float32Array(e.length / 3 * 2);
|
|
878
|
+
for (let t = 0, o = 0; t < e.length; t += 3, o += 2) {
|
|
879
|
+
let s = e[t], c = e[t + 1], l = e[t + 2], u = Math.min(1, Math.max(0, l / n + .5));
|
|
880
|
+
a[o] = .5 * u * .999 + (s >= 0 ? .5 : 0), a[o + 1] = Math.min(1, Math.max(0, (c + i) / (r + i || 1)));
|
|
881
|
+
}
|
|
882
|
+
return a;
|
|
883
|
+
}
|
|
884
|
+
var ce = (e, t, n, r, i) => {
|
|
885
|
+
let a = e.width / 2;
|
|
886
|
+
return [Math.min(1, Math.max(0, t[2] / n + .5)) * a + (t[0] >= 0 ? a : 0), (t[1] + i) / (r + i || 1) * e.height];
|
|
887
|
+
};
|
|
888
|
+
function le(e, t, n, r) {
|
|
889
|
+
let i = Q(e), a = r.length ?? 50, o = r.height ?? 6, s = r.draft ?? 5, [c, l] = ce(i, t, a, o, s), u = i.width / 2 / a, d = i.height / (o + s || 1), f = t[0] >= 0 ? i.width / 2 : 0;
|
|
890
|
+
for (let e = Math.floor(l - n * d - 1); e <= Math.ceil(l + n * d + 1); e++) for (let t = Math.floor(c - n * u - 1); t <= Math.ceil(c + n * u + 1); t++) e < 0 || e >= i.height || t < f || t >= f + i.width / 2 || ((t + .5 - c) / u) ** 2 + ((e + .5 - l) / d) ** 2 > n * n || (i.data[(e * i.width + t) * 4 + 2] = 255);
|
|
891
|
+
let p = Math.min(f + i.width / 2 - 1, Math.max(f, Math.floor(c))), m = Math.min(i.height - 1, Math.max(0, Math.floor(l)));
|
|
892
|
+
i.data[(m * i.width + p) * 4 + 2] = 255, e.update();
|
|
893
|
+
}
|
|
894
|
+
var ue = .02;
|
|
895
|
+
function $(e, t, n = 6) {
|
|
896
|
+
let r = g(e, "mast height", 1, 120), i = g(t, "seconds", 0, 1e7), a = g(n, "deck", 0, 50), o = Math.acos(Math.max(-1, Math.min(1, -a / r))), s = 3 * u / (2 * r), c = ue, l = 0, d = 0;
|
|
897
|
+
for (; d < i;) {
|
|
898
|
+
let e = Math.min(.001, i - d), t = s * Math.sin(c), n = s * Math.sin(c + .5 * e * l), r = s * Math.sin(c + .5 * e * (l + .5 * e * t)), a = s * Math.sin(c + e * (l + .5 * e * n));
|
|
899
|
+
if (c += e * l + e * e / 6 * (t + n + r), l += e / 6 * (t + 2 * n + 2 * r + a), d += e, c >= o) return {
|
|
900
|
+
angle: o,
|
|
901
|
+
rate: 0,
|
|
902
|
+
down: !0
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
return {
|
|
906
|
+
angle: c,
|
|
907
|
+
rate: l,
|
|
908
|
+
down: !1
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
var de = class e {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
|
|
912
|
+
constructor(e, n) {
|
|
913
|
+
this.name = "vfx-hull-fire:" + W++, this.flameVolumes = [], this.smokeColumns = [], this.disposed = !1, this.clock = 0, this.options = n, this.checkLive();
|
|
914
|
+
let r = g(n.flames ?? 10, "flames", 0, 64), i = g(n.columns ?? 2, "columns", 0, 16);
|
|
915
|
+
if (!Number.isInteger(r) || !Number.isInteger(i)) throw RangeError("HullFire flames and columns must be whole numbers");
|
|
916
|
+
t(e).use(this);
|
|
917
|
+
let a = this.toWorld([
|
|
918
|
+
0,
|
|
919
|
+
-1e6,
|
|
920
|
+
0
|
|
921
|
+
]), o = n.lights, l = o && "clustered" in o ? o.clustered : o;
|
|
922
|
+
for (let t = 0; t < i; t++) this.smokeColumns.push(c.attach(e, {
|
|
923
|
+
position: a,
|
|
924
|
+
heat: 0,
|
|
925
|
+
radius: 3,
|
|
926
|
+
color: U(n.soot ?? .35),
|
|
927
|
+
opacity: n.opacity ?? .7,
|
|
928
|
+
rate: 18,
|
|
929
|
+
lifetime: 240,
|
|
930
|
+
stability: 1e-4,
|
|
931
|
+
...n.wind ? { wind: n.wind } : {},
|
|
932
|
+
...l ? { lights: l } : {}
|
|
933
|
+
}));
|
|
934
|
+
for (let t = 0; t < r; t++) this.flameVolumes.push(s.attach(e, {
|
|
935
|
+
position: a,
|
|
936
|
+
length: 0,
|
|
937
|
+
footprint: [1, 1],
|
|
938
|
+
...n.lights ? { lights: n.lights } : {}
|
|
939
|
+
}));
|
|
940
|
+
this.place();
|
|
941
|
+
}
|
|
942
|
+
checkLive() {
|
|
943
|
+
let e = this.options;
|
|
944
|
+
if (!e || typeof e != "object" || !e.ship) throw TypeError("HullFire needs {ship}: a Floater or a world matrix");
|
|
945
|
+
if (typeof e.ship.matrix != "function" && e.ship.length !== 16) throw TypeError("HullFire ship must have matrix() (a Floater) or be 16 numbers");
|
|
946
|
+
let t = e.hull ?? {};
|
|
947
|
+
g(t.length ?? 50, "hull length", 1, 500), g(t.beam ?? 13, "hull beam", .5, 100), g(t.deck ?? 6, "hull deck", 0, 50), g(e.spread ?? .03, "spread", 0, 10), g(e.burnTime ?? 2400, "burnTime", 1, 1e6), g(e.deckHeat ?? 25e4, "deckHeat", 0, 5e6), g(e.soot ?? .35, "soot", 0, 1), g(e.opacity ?? .7, "opacity", 0, 1), g(e.ignition?.time ?? 0, "ignition time", 0, 1e7), g(t.draft ?? 5, "hull draft", 0, 50), g(e.charRate ?? .5, "charRate", 0, 5), g(e.mastFall ?? 600, "mastFall", 0, 1e6), e.mask && Q(e.mask);
|
|
948
|
+
for (let t of e.masts ?? []) {
|
|
949
|
+
n(t.position, 3, "HullFire mast position"), g(t.height, "mast height", 1, 120), t.falls && n(t.falls, 3, "HullFire mast falls"), t.fallAt !== void 0 && g(t.fallAt, "mast fallAt", 0, 1e7);
|
|
950
|
+
for (let e of t.yards ?? []) g(e.at, "yard at", 0, t.height), g(e.length, "yard length", .1, 100);
|
|
951
|
+
}
|
|
952
|
+
e.ignition?.at && n(e.ignition.at, 3, "HullFire ignition");
|
|
953
|
+
for (let t of e.ports ?? []) if (n(t.position, 3, "HullFire port position"), t.size) for (let e of t.size) g(e, "port size", .05, 20);
|
|
954
|
+
}
|
|
955
|
+
matrix() {
|
|
956
|
+
let e = this.options.ship;
|
|
957
|
+
return typeof e.matrix == "function" ? e.matrix() : e;
|
|
958
|
+
}
|
|
959
|
+
toWorld(e) {
|
|
960
|
+
return G(this.matrix(), e);
|
|
961
|
+
}
|
|
962
|
+
burning(e) {
|
|
963
|
+
let t = this.options, n = t.ignition?.time ?? 0, r = t.ignition?.at?.[2] ?? 0, i = t.spread ?? .03, a = i > 0 ? Math.abs(e - r) / i : Math.abs(e - r) < 1e-9 ? 0 : Infinity, o = this.clock - n - a;
|
|
964
|
+
if (o <= 0) return 0;
|
|
965
|
+
let s = t.burnTime ?? 2400;
|
|
966
|
+
return Math.min(1, o / (.05 * s)) * (o > s ? Math.max(0, 1 - (o - s) / (.33 * s)) : 1);
|
|
967
|
+
}
|
|
968
|
+
reach(e) {
|
|
969
|
+
let t = this.options, n = t.ignition?.at?.[2] ?? 0, r = t.spread ?? .03;
|
|
970
|
+
return r > 0 ? Math.abs(e - n) / r : Math.abs(e - n) < 1e-9 ? 0 : Infinity;
|
|
971
|
+
}
|
|
972
|
+
exposure(e) {
|
|
973
|
+
let t = this.options, n = this.clock - (t.ignition?.time ?? 0) - this.reach(e);
|
|
974
|
+
if (!(n > 0)) return 0;
|
|
975
|
+
let r = t.burnTime ?? 2400, i = .05 * r, a = .33 * r;
|
|
976
|
+
if (n <= i) return n * n / (2 * i);
|
|
977
|
+
if (n <= r) return i / 2 + (n - i);
|
|
978
|
+
let o = Math.min(n - r, a);
|
|
979
|
+
return i / 2 + (r - i) + o - o * o / (2 * a);
|
|
980
|
+
}
|
|
981
|
+
charDepth(e) {
|
|
982
|
+
n(e, 3, "HullFire char point");
|
|
983
|
+
let t = this.options, r = (t.charRate ?? .5) / 60, i = t.hull?.deck ?? 6, a = e[1] >= i - ie ? this.exposure(e[2]) : 0;
|
|
984
|
+
for (let n of t.ports ?? []) {
|
|
985
|
+
if (Math.sign(n.position[0] || 1) !== Math.sign(e[0] || 1)) continue;
|
|
986
|
+
let [t, r] = n.size ?? [.8, .7], i = n.position[1] - r / 2, o = n.position[1] + r / 2 + Y(J(t * r, r), t, r), s = Math.max(0, e[1] - i);
|
|
987
|
+
e[1] < i || e[1] > o || Math.abs(e[2] - n.position[2]) > t / 2 + .12 * s || (a = Math.max(a, this.exposure(n.position[2])));
|
|
988
|
+
}
|
|
989
|
+
return r * a;
|
|
990
|
+
}
|
|
991
|
+
paint() {
|
|
992
|
+
let e = this.options.mask;
|
|
993
|
+
if (!e) return;
|
|
994
|
+
let t = Q(e), n = this.options.hull ?? {}, r = n.length ?? 50, i = n.deck ?? 6, a = n.draft ?? 5, o = t.width / 2, s = [
|
|
995
|
+
0,
|
|
996
|
+
0,
|
|
997
|
+
0
|
|
998
|
+
], c = t.data, l = !1;
|
|
999
|
+
for (let e = 0; e < t.width; e++) {
|
|
1000
|
+
s[0] = (e < o ? -1 : 1) * .5 * (n.beam ?? 13), s[2] = ((e % o + .5) / o - .5) * r;
|
|
1001
|
+
let u = this.burning(s[2]);
|
|
1002
|
+
for (let n = 0; n < t.height; n++) {
|
|
1003
|
+
s[1] = (n + .5) / t.height * (i + a) - a;
|
|
1004
|
+
let r = this.charDepth(s), o = Math.round(255 * (1 - Math.exp(-r / ae))), d = r > 0 ? Math.round(255 * u) : 0, f = (n * t.width + e) * 4;
|
|
1005
|
+
(c[f] !== o || c[f + 1] !== d) && (c[f] = o, c[f + 1] = d, l = !0);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
l && e.update();
|
|
1009
|
+
}
|
|
1010
|
+
mastFallTime(e) {
|
|
1011
|
+
let t = this.options, n = t.masts?.[e];
|
|
1012
|
+
if (!n) throw RangeError("HullFire mast index is out of range; pass an index into masts");
|
|
1013
|
+
return n.fallAt ?? (t.ignition?.time ?? 0) + this.reach(n.position[2]) + (t.mastFall ?? 600);
|
|
1014
|
+
}
|
|
1015
|
+
rigging() {
|
|
1016
|
+
let e = this.options, t = this.matrix(), n = [];
|
|
1017
|
+
return (e.masts ?? []).forEach((e, r) => {
|
|
1018
|
+
let i = this.mastFallTime(r), a = this.clock > i ? $(e.height, this.clock - i, Math.min(50, Math.max(0, e.position[1]))).angle : 0, o = e.falls ?? [
|
|
1019
|
+
1,
|
|
1020
|
+
0,
|
|
1021
|
+
0
|
|
1022
|
+
], s = Math.hypot(o[0], o[2]) || 1, c = o[0] / s, l = o[2] / s, u = Math.cos(a), d = Math.sin(a), f = [
|
|
1023
|
+
d * c,
|
|
1024
|
+
u,
|
|
1025
|
+
d * l
|
|
1026
|
+
], p = [
|
|
1027
|
+
u * c,
|
|
1028
|
+
-d,
|
|
1029
|
+
u * l
|
|
1030
|
+
], m = [
|
|
1031
|
+
-l,
|
|
1032
|
+
0,
|
|
1033
|
+
c
|
|
1034
|
+
], h = (e, n, r, i) => {
|
|
1035
|
+
let a = [
|
|
1036
|
+
e[0],
|
|
1037
|
+
e[1],
|
|
1038
|
+
e[2],
|
|
1039
|
+
0,
|
|
1040
|
+
n[0],
|
|
1041
|
+
n[1],
|
|
1042
|
+
n[2],
|
|
1043
|
+
0,
|
|
1044
|
+
r[0],
|
|
1045
|
+
r[1],
|
|
1046
|
+
r[2],
|
|
1047
|
+
0,
|
|
1048
|
+
i[0],
|
|
1049
|
+
i[1],
|
|
1050
|
+
i[2],
|
|
1051
|
+
1
|
|
1052
|
+
], o = /* @__PURE__ */ new Float32Array(16);
|
|
1053
|
+
for (let e = 0; e < 4; e++) for (let n = 0; n < 4; n++) {
|
|
1054
|
+
let r = 0;
|
|
1055
|
+
for (let i = 0; i < 4; i++) r += t[i * 4 + n] * a[e * 4 + i];
|
|
1056
|
+
o[e * 4 + n] = r;
|
|
1057
|
+
}
|
|
1058
|
+
return o;
|
|
1059
|
+
}, g = [
|
|
1060
|
+
e.position[0],
|
|
1061
|
+
e.position[1],
|
|
1062
|
+
e.position[2]
|
|
1063
|
+
];
|
|
1064
|
+
n.push({
|
|
1065
|
+
kind: "mast",
|
|
1066
|
+
mast: r,
|
|
1067
|
+
matrix: h(p, f, m, g),
|
|
1068
|
+
length: e.height,
|
|
1069
|
+
angle: a
|
|
1070
|
+
});
|
|
1071
|
+
for (let t of e.yards ?? []) {
|
|
1072
|
+
let e = [
|
|
1073
|
+
g[0] + f[0] * t.at,
|
|
1074
|
+
g[1] + f[1] * t.at,
|
|
1075
|
+
g[2] + f[2] * t.at
|
|
1076
|
+
];
|
|
1077
|
+
n.push({
|
|
1078
|
+
kind: "yard",
|
|
1079
|
+
mast: r,
|
|
1080
|
+
matrix: h(m, f, [
|
|
1081
|
+
-p[0],
|
|
1082
|
+
-p[1],
|
|
1083
|
+
-p[2]
|
|
1084
|
+
], e),
|
|
1085
|
+
length: t.length,
|
|
1086
|
+
angle: a
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
}), n;
|
|
1090
|
+
}
|
|
1091
|
+
get heat() {
|
|
1092
|
+
return this.flames().reduce((e, t) => e + t.heat, 0);
|
|
1093
|
+
}
|
|
1094
|
+
flames() {
|
|
1095
|
+
let e = this.options, t = e.hull ?? {}, n = t.length ?? 50, r = t.beam ?? 13, i = t.deck ?? 6, a = e.deckHeat ?? 25e4, o = [], s = n / Z;
|
|
1096
|
+
for (let e = 0; e < Z; e++) {
|
|
1097
|
+
let t = -n / 2 + (e + .5) * s, c = this.burning(t);
|
|
1098
|
+
if (c <= 0) continue;
|
|
1099
|
+
let l = a * s * r * .8 * c, u = Math.sqrt(4 * s * r * .8 / Math.PI), d = Math.max(0, .235 * (l / 1e3) ** .4 - 1.02 * u);
|
|
1100
|
+
o.push({
|
|
1101
|
+
kind: "deck",
|
|
1102
|
+
position: this.toWorld([
|
|
1103
|
+
0,
|
|
1104
|
+
i,
|
|
1105
|
+
t
|
|
1106
|
+
]),
|
|
1107
|
+
length: d,
|
|
1108
|
+
footprint: [s, r * .8],
|
|
1109
|
+
heat: l
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
for (let t of e.ports ?? []) {
|
|
1113
|
+
let e = this.burning(t.position[2]);
|
|
1114
|
+
if (e <= 0) continue;
|
|
1115
|
+
let [n, r] = t.size ?? [.8, .7], i = J(n * r, r) * e, a = Y(i, n, r), s = t.normal ?? [
|
|
1116
|
+
Math.sign(t.position[0]) || 1,
|
|
1117
|
+
0,
|
|
1118
|
+
0
|
|
1119
|
+
], c = [
|
|
1120
|
+
t.position[0] + s[0] * .4,
|
|
1121
|
+
t.position[1] + r / 2,
|
|
1122
|
+
t.position[2] + s[2] * .4
|
|
1123
|
+
];
|
|
1124
|
+
o.push({
|
|
1125
|
+
kind: "port",
|
|
1126
|
+
position: this.toWorld(c),
|
|
1127
|
+
length: a + r,
|
|
1128
|
+
footprint: [n, .6 * n],
|
|
1129
|
+
heat: i * X
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
return o;
|
|
1133
|
+
}
|
|
1134
|
+
get time() {
|
|
1135
|
+
return this.clock;
|
|
1136
|
+
}
|
|
1137
|
+
setup(e) {
|
|
1138
|
+
this.engine = e;
|
|
1139
|
+
}
|
|
1140
|
+
onPreUpdate(e) {
|
|
1141
|
+
this.advanceTime(e);
|
|
1142
|
+
}
|
|
1143
|
+
resetTime() {
|
|
1144
|
+
if (!this.disposed) {
|
|
1145
|
+
this.clock = 0, this.place();
|
|
1146
|
+
for (let e of [...this.flameVolumes, ...this.smokeColumns]) e.resetTime();
|
|
1147
|
+
this.paint();
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
advanceTime(e) {
|
|
1151
|
+
this.disposed || (this.clock += e > 0 ? e : 0, this.checkLive(), this.place(), this.paint());
|
|
1152
|
+
}
|
|
1153
|
+
windNow() {
|
|
1154
|
+
return this.options.wind ?? this.smokeColumns[0]?.effect.options.wind;
|
|
1155
|
+
}
|
|
1156
|
+
place() {
|
|
1157
|
+
let e = this.options, t = this.flames().sort((e, t) => t.heat - e.heat), n = this.windNow(), r = this.flameVolumes;
|
|
1158
|
+
for (let e = 0; e < r.length; e++) {
|
|
1159
|
+
let i = t[e], a = r[e].options;
|
|
1160
|
+
if (!i) {
|
|
1161
|
+
a.length = 0;
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
a.position = i.position, a.length = Math.min(1e3, i.length), a.footprint = i.footprint;
|
|
1165
|
+
let o = this.matrix();
|
|
1166
|
+
a.yaw = Math.atan2(-o[10], o[8]), n ? a.wind = n : delete a.wind;
|
|
1167
|
+
}
|
|
1168
|
+
let i = this.smokeColumns;
|
|
1169
|
+
if (i.length === 0) return;
|
|
1170
|
+
t.reduce((e, t) => e + t.heat, 0);
|
|
1171
|
+
let a = e.hull?.length ?? 50, o = e.hull?.deck ?? 6, s = U(e.soot ?? .35);
|
|
1172
|
+
i.forEach((n, r) => {
|
|
1173
|
+
let c = -a / 2 + (r + .5) * a / i.length, l = -a / 2 + r * a / i.length, u = r === i.length - 1 ? Infinity : l + a / i.length, d = t.filter((e) => {
|
|
1174
|
+
let t = this.localZ(e.position);
|
|
1175
|
+
return (r === 0 || t >= l) && t < u;
|
|
1176
|
+
}).reduce((e, t) => e + t.heat, 0), f = n.options;
|
|
1177
|
+
f.position = this.toWorld([
|
|
1178
|
+
0,
|
|
1179
|
+
o + 4,
|
|
1180
|
+
c
|
|
1181
|
+
]), f.heat = Math.max(0, .7 * d), f.rate = d > 0 ? 18 : .001, f.radius = Math.max(1, Math.min(30, (e.hull?.beam ?? 13) * .5)), f.color = s, f.opacity = d > 0 ? e.opacity ?? .7 : 0, e.wind !== void 0 && f.wind !== e.wind && n.setWind(e.wind);
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
localZ(e) {
|
|
1185
|
+
let t = this.matrix(), n = t[8], r = t[9], i = t[10], a = n * n + r * r + i * i;
|
|
1186
|
+
return ((e[0] - t[12]) * n + (e[1] - t[13]) * r + (e[2] - t[14]) * i) / (a || 1);
|
|
1187
|
+
}
|
|
1188
|
+
static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
1189
|
+
if (!n || typeof n != "object") throw TypeError("Invalid HullFire options; pass {ship}");
|
|
1190
|
+
return new e(t, n);
|
|
1191
|
+
}
|
|
1192
|
+
dispose() {
|
|
1193
|
+
if (!this.disposed) {
|
|
1194
|
+
this.disposed = !0, this.engine?.sceneOf(this)?.removePlugin(this.name), this.engine = void 0;
|
|
1195
|
+
for (let e of this.flameVolumes) e.dispose();
|
|
1196
|
+
for (let e of this.smokeColumns) e.dispose();
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
[Symbol.dispose]() {
|
|
1200
|
+
this.dispose();
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
//#endregion
|
|
1204
|
+
export { h as BLACK_POWDER, re as Battery, y as FLASH_ALPHA, v as FLASH_DURATION, B as GRAIN_DENSITY, X as HULL_FUEL_HEAT, de as HullFire, D as OAK, z as POWDER_BURN_RATE, C as PowderPuff, V as UNBURNT_FRACTION, x as flashExposure, oe as hullMaskImage, se as hullMaskUVs, $ as mastTopple, b as muzzleFlash, H as powderGrains, _ as powderProducts, te as shotFlight, R as shotPath, U as smokeColor, w as smokeDispersion, T as sphereDrag, J as ventBurningRate, Y as ventFlameHeight, A as woodExitSpeed, k as woodPenetration };
|