@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/fire.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
|
|
4
|
+
import type { Clustered } from '@margoengine/clustered';
|
|
5
|
+
import { type LineLight } from '@margoengine/clustered/line';
|
|
6
|
+
import type { LightGroups } from '@margoengine/clustered/groups';
|
|
7
|
+
import { VFX, type VFXWind } from '@margoengine/vfx/base';
|
|
8
|
+
import { Flame } from '@margoengine/vfx/flame';
|
|
9
|
+
import { Smoke, type SmokeOptions } from '@margoengine/vfx/smoke';
|
|
10
|
+
import { type KitHearth } from '@margoengine/sky/scene-kits';
|
|
11
|
+
type Vec3 = readonly [number, number, number];
|
|
12
|
+
/** `Fire.attach` settings. Only `position` is required. */
|
|
13
|
+
export interface FireOptions {
|
|
14
|
+
/** Where the flames are born, on top of the fuel (the logs' tops), world units. */
|
|
15
|
+
position: Vec3;
|
|
16
|
+
/**
|
|
17
|
+
* The fire's data: its light, flames, embers and steam. Default `snowNight().hearth` from `@margoengine/sky/scene-kits`,
|
|
18
|
+
* a wood fire of about 1,900 K; pass another kit's `hearth` (or your own) to change the look.
|
|
19
|
+
*/
|
|
20
|
+
hearth?: KitHearth;
|
|
21
|
+
/** Scales the firelight's intensity and the flames' and embers' radiance together, 0 or more. Default 1. */
|
|
22
|
+
power?: number;
|
|
23
|
+
/** Length of the flame line along `axis`, metres, above 0. Default `hearth.light.length` (0.62), or the flame length with `flameLength`. */
|
|
24
|
+
width?: number;
|
|
25
|
+
/** Direction the flames run along (the logs), nonzero. Default [1, 0, 0]. */
|
|
26
|
+
axis?: Vec3;
|
|
27
|
+
/**
|
|
28
|
+
* Where the firelight goes: a `LightGroups` (the fire takes a group of its own, `fire`, `fire 2`, ...) or a
|
|
29
|
+
* `Clustered` (the fire then owns its whole list: use groups to keep lights of your own), attached to the same scene.
|
|
30
|
+
* Omitted: the fire gives no light.
|
|
31
|
+
*/
|
|
32
|
+
lights?: Clustered | LightGroups;
|
|
33
|
+
/**
|
|
34
|
+
* The firelight's soft shadows (`LocalShadows` from `@margoengine/clustered/shadows`, attached to the same
|
|
35
|
+
* `Clustered` first). Default true.
|
|
36
|
+
*/
|
|
37
|
+
castShadow?: boolean;
|
|
38
|
+
/** Points on the flame line (`lineLights` samples), 1 to 8. Default 2. */
|
|
39
|
+
samples?: number;
|
|
40
|
+
/**
|
|
41
|
+
* The scene depth (`DepthTexture` of `@margoengine/post/depth`), for flames, embers and steam that fade 0.08 m before
|
|
42
|
+
* the logs and the grate instead of cutting into them. Default: none, hard-edged particles.
|
|
43
|
+
*/
|
|
44
|
+
depth?: () => GPUTexture | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The flame length, metres, 0.05 to 1,000: the fire's flames become a `Flame` volume of `@margoengine/vfx/flame` that
|
|
47
|
+
* long (house fires, burning ships, crowns): tapering tongues that puff at the Cetegen and Ahmed frequency, a
|
|
48
|
+
* yellow-white core that cannot blow out, and, with `lights`, the flame's own light, which flickers with the puffing.
|
|
49
|
+
* The embers' size, speed and life scale by the square root of the length over the hearth's
|
|
50
|
+
* ({@link HEARTH_FLAME_LENGTH}). Set it later with `fire.flame.setLength`. Read at attach. Default: the hearth's own
|
|
51
|
+
* flames (billboards) and firelight.
|
|
52
|
+
*/
|
|
53
|
+
flameLength?: number;
|
|
54
|
+
/** Size of the fire across its `axis`, metres, above 0, with `flameLength`. Default 0.6 of `width`. */
|
|
55
|
+
breadth?: number;
|
|
56
|
+
/** Sparks that rise from the fire. Default true. */
|
|
57
|
+
embers?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* A smoke column over the flames (`Smoke` of `@margoengine/vfx/smoke`, as `fire.smoke`): true stands one on the flame
|
|
60
|
+
* tips with the fire's convective heat (Heskestad's flame length turned back into a heat release, 70% of it
|
|
61
|
+
* convective; Heskestad 1983, Drysdale 2011 ch. 4) over the flames' width, lit by the fire's `lights`; an object
|
|
62
|
+
* gives it options of its own (colour, opacity, rate, lifetime, ...); false makes none. Read at attach. Default true
|
|
63
|
+
* with `flameLength` (a large fire always smokes), false for the hearth's own flames (a wood hearth's thin smoke is
|
|
64
|
+
* its `steam`).
|
|
65
|
+
*/
|
|
66
|
+
smoke?: boolean | Omit<SmokeOptions, 'fire' | 'position' | 'heat'>;
|
|
67
|
+
/** A kettle spout or pot: steam rises from this point. Default: no steam. */
|
|
68
|
+
steam?: Vec3;
|
|
69
|
+
/**
|
|
70
|
+
* The wind, `[x, z]` m/s or `{sample(x, y, z, t)}` (a `WindField` fits): flames, embers and steam lean with it, by
|
|
71
|
+
* `VFXOptions.wind` (a plume rising at w in a wind U leans atan(U / w)). Default none.
|
|
72
|
+
*/
|
|
73
|
+
wind?: VFXWind;
|
|
74
|
+
}
|
|
75
|
+
/** The fire's particle effects. */
|
|
76
|
+
export interface FireParticles {
|
|
77
|
+
/** The hearth's flame billboards; none with `flameLength` (the flames are then `Fire.flame`). */
|
|
78
|
+
readonly flames?: VFX;
|
|
79
|
+
readonly embers?: VFX;
|
|
80
|
+
readonly steam?: VFX;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A wood fire from one call: flames, embers and optional steam (`@margoengine/vfx`), and its light as a flickering
|
|
84
|
+
* flame line of soft-shadowed points (`lineLights` of `@margoengine/clustered/line`) sized from the same data, so the
|
|
85
|
+
* light, its shadows and the flames agree with no tuning. `power` sets the light and the flames' radiance together.
|
|
86
|
+
* @throws TypeError for a position, axis or steam point that is not three finite numbers; RangeError for a power,
|
|
87
|
+
* width or sample count out of range.
|
|
88
|
+
* @throws MargoError `'state'` when the fire casts shadows and its `Clustered` has no `LocalShadows` attached.
|
|
89
|
+
* A plugin of the scene it is attached to: disposing that scene disposes the fire.
|
|
90
|
+
*/
|
|
91
|
+
export declare class Fire implements EnginePlugin {
|
|
92
|
+
readonly name: string;
|
|
93
|
+
/** The firelight's points as last set (steady intensities; the flicker scales them each frame). */
|
|
94
|
+
readonly lights: readonly LineLight[];
|
|
95
|
+
readonly particles: FireParticles;
|
|
96
|
+
/** The flame volume of a fire with a `flameLength` (its light is the flame's); undefined for hearth flames. */
|
|
97
|
+
readonly flame?: Flame;
|
|
98
|
+
/** The smoke column over the flames ({@link FireOptions.smoke}); undefined without one. */
|
|
99
|
+
readonly smoke?: Smoke;
|
|
100
|
+
private readonly target?;
|
|
101
|
+
/** The group the fire made in a `LightGroups`, disposed with it. */
|
|
102
|
+
private readonly group?;
|
|
103
|
+
private engine?;
|
|
104
|
+
private readonly stopFlicker?;
|
|
105
|
+
private disposed;
|
|
106
|
+
private constructor();
|
|
107
|
+
setup(engine: Engine): void;
|
|
108
|
+
/** Sets the wind of the flames, embers and steam (see {@link FireOptions.wind}); undefined removes it. */
|
|
109
|
+
setWind(wind: VFXWind | undefined): this;
|
|
110
|
+
/** Lights and particles for a fire at `options.position`; see {@link FireOptions}. */
|
|
111
|
+
static attach(engine: EngineKernel, options: FireOptions): Fire;
|
|
112
|
+
/**
|
|
113
|
+
* Removes the particles and the firelight (a group the fire made goes with it; a `Clustered` it lit is left empty
|
|
114
|
+
* unless it was disposed first).
|
|
115
|
+
*/
|
|
116
|
+
dispose(): void;
|
|
117
|
+
[Symbol.dispose](): void;
|
|
118
|
+
}
|
|
119
|
+
export {};
|
package/dist/fire.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
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 { finiteVector as t } from "@margoengine/math/validate";
|
|
6
|
+
import { MargoError as n } from "@margoengine/math/errors";
|
|
7
|
+
import { lineLights as r } from "@margoengine/clustered/line";
|
|
8
|
+
import { animateFlicker as i } from "@margoengine/clustered/flicker";
|
|
9
|
+
import { VFX as a } from "@margoengine/vfx/base";
|
|
10
|
+
import { curves as o } from "@margoengine/vfx/curves";
|
|
11
|
+
import { shapes as s } from "@margoengine/vfx/shapes";
|
|
12
|
+
import { soft as c } from "@margoengine/vfx/soft";
|
|
13
|
+
import { stretch as l } from "@margoengine/vfx/stretch";
|
|
14
|
+
import { overLife as u } from "@margoengine/vfx/over-life";
|
|
15
|
+
import { Flame as d, HEARTH_FLAME_LENGTH as f, puffingDiameter as p, scaleHearthEmbers as m } from "@margoengine/vfx/flame";
|
|
16
|
+
import { Smoke as h } from "@margoengine/vfx/smoke";
|
|
17
|
+
import { schedule as g } from "@margoengine/vfx/schedule";
|
|
18
|
+
import { snowNight as _ } from "@margoengine/sky/scene-kits";
|
|
19
|
+
//#region src/fire.ts
|
|
20
|
+
var v = (e) => .2126 * e[0] + .7152 * e[1] + .0722 * e[2];
|
|
21
|
+
function y(e) {
|
|
22
|
+
let t = e.color.slice(0, 3), n = e.curves.color.length ? e.curves.color.map((e) => e.color) : [[
|
|
23
|
+
1,
|
|
24
|
+
1,
|
|
25
|
+
1
|
|
26
|
+
]];
|
|
27
|
+
return e.intensity * Math.max(...n.map((e) => v(e.map((e, n) => e * t[n]))));
|
|
28
|
+
}
|
|
29
|
+
var b = .08, x = 0, S = class S {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
|
|
30
|
+
constructor(e, S) {
|
|
31
|
+
this.name = "vfx-fire:" + x++, this.disposed = !1;
|
|
32
|
+
let C = S.flameLength;
|
|
33
|
+
if (C !== void 0 && !(Number.isFinite(C) && C >= .05 && C <= 1e3)) throw RangeError("Fire flameLength must be a finite length from 0.05 to 1000 (metres)");
|
|
34
|
+
let w = S.hearth ?? _().hearth, T = S.width ?? (C === void 0 ? w.light.length : Math.max(w.light.length, C)), E = S.breadth ?? .6 * T, D = C === void 0 ? w : {
|
|
35
|
+
...w,
|
|
36
|
+
embers: m(w.embers, C, [T, E]),
|
|
37
|
+
emberHeight: w.emberHeight * Math.max(C / f, 1)
|
|
38
|
+
}, { light: O } = D, k = S.power ?? 1, A = S.axis ?? [
|
|
39
|
+
1,
|
|
40
|
+
0,
|
|
41
|
+
0
|
|
42
|
+
], j = S.castShadow ?? !0;
|
|
43
|
+
if (t(S.position, 3, "Fire position"), t(A, 3, "Fire axis"), S.steam && t(S.steam, 3, "Fire steam point"), !(k >= 0 && Number.isFinite(k))) throw RangeError("Fire power must be a finite number of 0 or more");
|
|
44
|
+
if (!(T > 0 && Number.isFinite(T))) throw RangeError("Fire width must be a finite length above 0 (metres)");
|
|
45
|
+
if (!(E > 0 && Number.isFinite(E))) throw RangeError("Fire breadth must be a finite length above 0 (metres)");
|
|
46
|
+
let M = Math.hypot(A[0], A[1], A[2]);
|
|
47
|
+
if (!M) throw RangeError("Fire axis must be nonzero");
|
|
48
|
+
let [N, P, F] = S.position, I = A.map((e) => e / M * (T / 2)), L = [
|
|
49
|
+
N,
|
|
50
|
+
P + O.height,
|
|
51
|
+
F
|
|
52
|
+
], R = v(O.color) / (Math.PI * y(D.fire));
|
|
53
|
+
this.lights = Object.freeze(C === void 0 ? r({
|
|
54
|
+
start: [
|
|
55
|
+
L[0] - I[0],
|
|
56
|
+
L[1] - I[1],
|
|
57
|
+
L[2] - I[2]
|
|
58
|
+
],
|
|
59
|
+
end: [
|
|
60
|
+
L[0] + I[0],
|
|
61
|
+
L[1] + I[1],
|
|
62
|
+
L[2] + I[2]
|
|
63
|
+
],
|
|
64
|
+
range: O.range,
|
|
65
|
+
intensity: O.intensity * k,
|
|
66
|
+
color: [...O.color],
|
|
67
|
+
samples: S.samples ?? (C === void 0 ? 2 : Math.min(8, Math.max(2, Math.ceil(T / (.5 * C))))),
|
|
68
|
+
radius: O.radius * T / O.length,
|
|
69
|
+
castShadow: j,
|
|
70
|
+
flicker: { ...O.flicker }
|
|
71
|
+
}).map((e) => ({
|
|
72
|
+
...e,
|
|
73
|
+
radius: Math.max(e.radius ?? 0, Math.sqrt(((e.intensity ?? 0) / k || 0) * R) || 0)
|
|
74
|
+
})) : []);
|
|
75
|
+
let z = S.lights, B = z && "names" in z && "clustered" in z ? z : void 0, V = B ? B.clustered : z && "maxLights" in z ? z : void 0;
|
|
76
|
+
if (z && !V) throw TypeError("Invalid Fire lights; pass a Clustered from @margoengine/clustered or its LightGroups");
|
|
77
|
+
if (C === void 0 && j && V && !V.shadow) throw new n("state", "Fire casts soft shadows through LocalShadows; attach LocalShadows to its Clustered first, or pass castShadow: false");
|
|
78
|
+
let H = (t, n, r) => a.attach(e, {
|
|
79
|
+
...structuredClone(t),
|
|
80
|
+
intensity: t.intensity * r,
|
|
81
|
+
...S.wind ? { wind: S.wind } : {},
|
|
82
|
+
position: [...n],
|
|
83
|
+
...S.depth ? {
|
|
84
|
+
softness: Math.max(b, .1 * t.size),
|
|
85
|
+
depth: S.depth
|
|
86
|
+
} : {}
|
|
87
|
+
}, {
|
|
88
|
+
curves: o,
|
|
89
|
+
emitter: s,
|
|
90
|
+
soft: c,
|
|
91
|
+
stretch: l,
|
|
92
|
+
schedule: g,
|
|
93
|
+
overLife: u
|
|
94
|
+
});
|
|
95
|
+
C !== void 0 && (this.flame = d.attach(e, {
|
|
96
|
+
position: S.position,
|
|
97
|
+
length: C,
|
|
98
|
+
footprint: [T, E],
|
|
99
|
+
yaw: Math.atan2(-A[2], A[0]),
|
|
100
|
+
lightPower: k,
|
|
101
|
+
...S.wind ? { wind: S.wind } : {},
|
|
102
|
+
...S.depth ? { depth: S.depth } : {},
|
|
103
|
+
...S.lights ? { lights: S.lights } : {}
|
|
104
|
+
}));
|
|
105
|
+
let U = C === void 0 ? H(D.fire, S.position, k) : void 0, W = S.embers === !1 ? void 0 : H(D.embers, [
|
|
106
|
+
N,
|
|
107
|
+
P + D.emberHeight,
|
|
108
|
+
F
|
|
109
|
+
], k), G = S.steam ? H(D.steam, S.steam, 1) : void 0;
|
|
110
|
+
this.particles = Object.freeze({
|
|
111
|
+
flames: U,
|
|
112
|
+
embers: W,
|
|
113
|
+
steam: G
|
|
114
|
+
});
|
|
115
|
+
let K = S.smoke ?? C !== void 0;
|
|
116
|
+
if (K && typeof K != "boolean" && typeof K != "object") throw TypeError("Invalid Fire smoke; pass true, false or Smoke options");
|
|
117
|
+
if (K) {
|
|
118
|
+
let t = C ?? f, n = p([T, E]), r = 700 * (Math.max(t + 1.02 * n, 0) / .235) ** 2.5;
|
|
119
|
+
this.smoke = h.attach(e, {
|
|
120
|
+
radius: n / 2,
|
|
121
|
+
...V ? { lights: V } : {},
|
|
122
|
+
...typeof K == "object" ? K : {},
|
|
123
|
+
fire: this,
|
|
124
|
+
position: [
|
|
125
|
+
N,
|
|
126
|
+
P + t,
|
|
127
|
+
F
|
|
128
|
+
],
|
|
129
|
+
heat: r
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (V && C === void 0) {
|
|
133
|
+
if (B) {
|
|
134
|
+
let e = "fire";
|
|
135
|
+
for (let t = 2; B.names.includes(e); t++) e = `fire ${t}`;
|
|
136
|
+
this.target = this.group = B.group(e);
|
|
137
|
+
} else this.target = V;
|
|
138
|
+
this.stopFlicker = i(e, this.target, this.lights);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
setup(e) {
|
|
142
|
+
this.engine = e;
|
|
143
|
+
}
|
|
144
|
+
setWind(e) {
|
|
145
|
+
for (let t of [
|
|
146
|
+
this.particles.flames,
|
|
147
|
+
this.particles.embers,
|
|
148
|
+
this.particles.steam
|
|
149
|
+
]) t?.setWind(e);
|
|
150
|
+
return this.flame?.setWind(e), this;
|
|
151
|
+
}
|
|
152
|
+
static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
153
|
+
if (!n || typeof n != "object") throw TypeError("Invalid Fire options; pass an object with a position [x, y, z]");
|
|
154
|
+
let r = new S(t, n);
|
|
155
|
+
return e(t).use(r), r;
|
|
156
|
+
}
|
|
157
|
+
dispose() {
|
|
158
|
+
if (!this.disposed) {
|
|
159
|
+
this.disposed = !0, this.engine?.sceneOf(this)?.removePlugin(this.name), this.engine = void 0, this.stopFlicker?.(), this.group ? this.group.dispose() : this.target && !this.target.isDisposed && this.target.setLights([]);
|
|
160
|
+
for (let e of [
|
|
161
|
+
this.particles.flames,
|
|
162
|
+
this.particles.embers,
|
|
163
|
+
this.particles.steam
|
|
164
|
+
]) e?.dispose();
|
|
165
|
+
this.flame?.dispose(), this.smoke?.dispose();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
[Symbol.dispose]() {
|
|
169
|
+
this.dispose();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
//#endregion
|
|
173
|
+
export { S as Fire };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/flame-ramp.ts
|
|
2
|
+
var e = 1, t = [
|
|
3
|
+
0,
|
|
4
|
+
.12,
|
|
5
|
+
.25,
|
|
6
|
+
.4,
|
|
7
|
+
.6,
|
|
8
|
+
.8,
|
|
9
|
+
1
|
|
10
|
+
], n = .01438776877, r = (e, t, n, r) => {
|
|
11
|
+
let i = (e - t) / (e < t ? n : r);
|
|
12
|
+
return Math.exp(-.5 * i * i);
|
|
13
|
+
};
|
|
14
|
+
function i(e) {
|
|
15
|
+
return [
|
|
16
|
+
1.056 * r(e, 599.8, 37.9, 31) + .362 * r(e, 442, 16, 26.7) - .065 * r(e, 501.1, 20.4, 26.2),
|
|
17
|
+
.821 * r(e, 568.8, 46.9, 40.5) + .286 * r(e, 530.9, 16.3, 31.1),
|
|
18
|
+
1.217 * r(e, 437, 11.8, 36) + .681 * r(e, 459, 26, 13.8)
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
var a = (e) => {
|
|
22
|
+
if (!(Number.isFinite(e) && e >= 500 && e <= 4e4)) throw RangeError(`Blackbody temperature is ${e}; pass kelvin from 500 to 40000`);
|
|
23
|
+
return e;
|
|
24
|
+
};
|
|
25
|
+
function o(e) {
|
|
26
|
+
let t = 0, r = 0, a = 0;
|
|
27
|
+
for (let o = 360; o <= 830; o += 5) {
|
|
28
|
+
let s = o * 1e-9, c = 1 / (s ** 5 * Math.expm1(n / (s * e))), [l, u, d] = i(o);
|
|
29
|
+
t += c * l, r += c * u, a += c * d;
|
|
30
|
+
}
|
|
31
|
+
return [
|
|
32
|
+
t,
|
|
33
|
+
r,
|
|
34
|
+
a
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
function s(e) {
|
|
38
|
+
let [t, n, r] = o(a(e)), i = t + n + r;
|
|
39
|
+
return [t / i, n / i];
|
|
40
|
+
}
|
|
41
|
+
function c(e, t) {
|
|
42
|
+
return o(a(e))[1] / o(a(t))[1];
|
|
43
|
+
}
|
|
44
|
+
function l(e) {
|
|
45
|
+
let t = a(e), r = 0;
|
|
46
|
+
for (let e = 360; e <= 830; e++) {
|
|
47
|
+
let a = e * 1e-9;
|
|
48
|
+
r += 1191042972e-25 / (a ** 5 * Math.expm1(n / (a * t))) * i(e)[1] * 1e-9;
|
|
49
|
+
}
|
|
50
|
+
return 683 * r / (5.670374419e-8 * t ** 4 / Math.PI);
|
|
51
|
+
}
|
|
52
|
+
function u(e) {
|
|
53
|
+
let [t, n, r] = o(a(e)), i = [
|
|
54
|
+
3.2406 * t - 1.5372 * n - .4986 * r,
|
|
55
|
+
-.9689 * t + 1.8758 * n + .0415 * r,
|
|
56
|
+
.0557 * t - .204 * n + 1.057 * r
|
|
57
|
+
].map((e) => Math.max(e, 0)), s = Math.max(...i);
|
|
58
|
+
return i.map((e) => e / s);
|
|
59
|
+
}
|
|
60
|
+
var d = (e, t, n, r) => {
|
|
61
|
+
if (!(Number.isFinite(e) && e >= n && e <= r)) throw RangeError(`Flame ramp ${t} is ${e}; pass a finite number from ${n} to ${r}`);
|
|
62
|
+
return e;
|
|
63
|
+
};
|
|
64
|
+
function f(e = {}) {
|
|
65
|
+
let n = d(e.core ?? 2600, "core", 800, 3e3), r = d(e.edge ?? 1e3, "edge", 600, n), i = d(e.cooling ?? 1.2, "cooling", .2, 5), a = d(e.exposure ?? .3, "exposure", 0, 1), s = d(e.peak ?? 1, "peak", 1e-6, 1e3), c = o(n)[1];
|
|
66
|
+
return t.map((e) => {
|
|
67
|
+
let t = r + (n - r) * (1 - e) ** i, l = s * Math.min(1, (o(t)[1] / c) ** a);
|
|
68
|
+
return {
|
|
69
|
+
at: e,
|
|
70
|
+
color: u(t).map((e) => e * l)
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { l as a, d as c, c as i, s as n, o, u as r, f as s, e as t };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** The brightest channel a flame pixel may show, scene-linear (1 is the display's white at the exposure of the scene). */
|
|
2
|
+
export declare const FLAME_PEAK = 1;
|
|
3
|
+
/** The XYZ of a blackbody at `kelvin`, in the units of the spectral radiance integrated over 360 to 830 nm. */
|
|
4
|
+
export declare function blackbodyXYZ(kelvin: number): [number, number, number];
|
|
5
|
+
/**
|
|
6
|
+
* The CIE 1931 chromaticity `[x, y]` of a blackbody (Planck's law through the Wyman fits of the observer).
|
|
7
|
+
* @throws RangeError for a temperature outside 500 to 40,000 K.
|
|
8
|
+
* @example blackbodyChromaticity(2000); // [0.527, 0.413]
|
|
9
|
+
*/
|
|
10
|
+
export declare function blackbodyChromaticity(kelvin: number): [number, number];
|
|
11
|
+
/**
|
|
12
|
+
* The luminance of a blackbody at `kelvin` relative to one at `reference` (the Y of Planck's law over the observer's
|
|
13
|
+
* luminous efficiency): it falls by a factor of thousands from 1,900 K to 1,000 K, which a camera's exposure cannot hold.
|
|
14
|
+
*/
|
|
15
|
+
export declare function blackbodyLuminanceRatio(kelvin: number, reference: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* The luminous efficacy of a blackbody's radiation at `kelvin`, lumens per radiant watt: 683 lm/W times Planck's
|
|
18
|
+
* spectral radiance weighted by the photopic curve (the Wyman fit of y-bar, 360 to 830 nm), over the total radiance
|
|
19
|
+
* sigma T^4 / pi (Stefan-Boltzmann). About 0.5 lm/W at 1,760 K (a flame's radiating soot), 16 at 2,856 K (CIE
|
|
20
|
+
* illuminant A), 55 at 4,000 K and 95 at 7,000 K, the published blackbody efficacies.
|
|
21
|
+
* @throws RangeError for a temperature outside 500 to 40,000 K.
|
|
22
|
+
* @example blackbodyLuminousEfficacy(4000); // about 54.8
|
|
23
|
+
*/
|
|
24
|
+
export declare function blackbodyLuminousEfficacy(kelvin: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* The linear sRGB colour of a blackbody at `kelvin`, scaled so its largest channel is 1 and negative channels (colours
|
|
27
|
+
* outside the sRGB gamut, the blues of a cool flame) cut to 0.
|
|
28
|
+
* @throws RangeError for a temperature outside 500 to 40,000 K.
|
|
29
|
+
* @example blackbodyColor(1500); // [1, 0.32, 0]
|
|
30
|
+
*/
|
|
31
|
+
export declare function blackbodyColor(kelvin: number): [number, number, number];
|
|
32
|
+
/** What {@link flameRamp} takes; every field has a default. */
|
|
33
|
+
export interface FlameRampOptions {
|
|
34
|
+
/** Temperature of the hot core where a flame is born, kelvin, 800 to 3000. Default 2200 (a `Flame`; 2600 in `flameRamp`) (the colour a luminous wood flame looks, once the eye and a camera's white balance have moved a 1,500 K blackbody toward warm white). */
|
|
35
|
+
core?: number;
|
|
36
|
+
/** Temperature at the end of a flame's life, the cool edge, kelvin, 600 to the core. Default 1000 (glowing soot). */
|
|
37
|
+
edge?: number;
|
|
38
|
+
/** How fast the flame cools: T(t) = edge + (core - edge) (1 - t)^cooling, 0.2 to 5. Default 1.2. */
|
|
39
|
+
cooling?: number;
|
|
40
|
+
/**
|
|
41
|
+
* How much of the blackbody's luminance fall is kept, 0 to 1: a stop shows (L(T) / L(core))^exposure of the peak, as
|
|
42
|
+
* an exposure maps the flame's radiance (Nguyen et al. 2002). 0 keeps every stop at the peak (no ramp in
|
|
43
|
+
* brightness), 1 is the physical fall, which is black at the edge. Default 0.3.
|
|
44
|
+
*/
|
|
45
|
+
exposure?: number;
|
|
46
|
+
/** The brightest channel any stop may show, scene-linear, above 0. Default {@link FLAME_PEAK}. */
|
|
47
|
+
peak?: number;
|
|
48
|
+
}
|
|
49
|
+
/** One stop of a colour ramp: the fraction of the particle's life and its linear RGB. */
|
|
50
|
+
export interface FlameStop {
|
|
51
|
+
at: number;
|
|
52
|
+
color: [number, number, number];
|
|
53
|
+
}
|
|
54
|
+
export declare const rampIn: (v: number, name: string, min: number, max: number) => number;
|
|
55
|
+
/**
|
|
56
|
+
* The colour of a flame over its life, from the core's temperature to the edge's: each stop is the blackbody colour of
|
|
57
|
+
* its temperature, as bright as the exposure keeps it, and none passes `peak`, so the volume has a clear core-to-edge
|
|
58
|
+
* ramp and cannot blow out. Seven stops (the colour curve holds eight).
|
|
59
|
+
* @throws RangeError for an option out of range.
|
|
60
|
+
*/
|
|
61
|
+
export declare function flameRamp(options?: FlameRampOptions): FlameStop[];
|