@threenative/core 0.3.11 → 0.3.13
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/README.md +1 -1
- package/capabilities.json +1988 -204
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/chunk-4SRAQFTU.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DIPIJICH.js +8916 -0
- package/dist/chunk-EEABDLUC.js +2237 -0
- package/dist/chunk-EFWZWLPY.js +1895 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-GYUZJQ7U.js +280 -0
- package/dist/chunk-H4J6IAJE.js +504 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-SV4QVUTQ.js +31 -0
- package/dist/chunk-U4YHUKKL.js +615 -0
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/chunk-XDTZ4QMO.js +160 -0
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -52
- package/dist/index.d.ts +633 -1351
- package/dist/index.js +12873 -23068
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +25 -75
- package/dist/quality-BYqKGAwo.d.ts +868 -0
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +3 -2
- package/dist/render-environment.d.ts +170 -0
- package/dist/render-environment.js +352 -0
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
- package/dist/spells/index.d.ts +643 -0
- package/dist/spells/index.js +1558 -0
- package/dist/spells/ultra/index.d.ts +1600 -0
- package/dist/spells/ultra/index.js +6804 -0
- package/dist/terrain-jobs-worker.js +1 -123
- package/dist/two-sided-foliage-W523J3UM.js +1 -0
- package/dist/ui-layer.js +6 -384
- package/dist/worker.js +13 -43
- package/dist/world.d.ts +988 -268
- package/dist/world.js +17464 -18290
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +245 -52
- package/mcp/servers.mjs +10 -3
- package/mcp/terrain.mjs +8 -0
- package/package.json +19 -7
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/animation-batch.ts +193 -0
- package/src/animation-layers.ts +7 -3
- package/src/animation.ts +209 -29
- package/src/asset-cache.ts +3 -3
- package/src/asset-memo.ts +202 -0
- package/src/assets.ts +437 -125
- package/src/auto-batch.ts +190 -44
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +103 -22
- package/src/dev-global.ts +54 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +50 -23
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +86 -0
- package/src/game-frame-loop.ts +958 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1076 -0
- package/src/game-ui.ts +84 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +198 -2264
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +13 -0
- package/src/geometry-capture.ts +28 -4
- package/src/gpu-readings.ts +98 -0
- package/src/gpu-scene-bvh.ts +149 -36
- package/src/hot.ts +4 -7
- package/src/index.ts +141 -9
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +25 -0
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/local-exposure.ts +2 -7
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +14 -5
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +113 -103
- package/src/loop.ts +29 -0
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +139 -17
- package/src/particle-kinds.ts +515 -0
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/picking.ts +17 -3
- package/src/platform.ts +23 -4
- package/src/playtest.ts +27 -1
- package/src/profiling/FrameStages.ts +5 -6
- package/src/profiling/Spans.ts +3 -17
- package/src/profiling/debug-telemetry.ts +2 -6
- package/src/profiling/render-list-validate.ts +6 -15
- package/src/projection-apply.ts +4 -1
- package/src/projection-marker.ts +2 -1
- package/src/projection-plan.ts +9 -6
- package/src/quiet-markers.ts +3 -10
- package/src/render/cpu-bvh.ts +100 -0
- package/src/render/depth-pyramid.ts +6 -14
- package/src/render/environment/environmentContribution.ts +202 -0
- package/src/render/environment/environmentRadiance.ts +44 -0
- package/src/render/environment/environmentSampleCache.ts +56 -0
- package/src/render/environment/environmentSampling.ts +201 -0
- package/src/render/environment/environmentSnapshot.ts +71 -0
- package/src/render/environment/gate.ts +57 -0
- package/src/render/mesh-pool.ts +4 -20
- package/src/render/probe-trace.ts +872 -0
- package/src/render/probe-volume.ts +780 -34
- package/src/render/radiance-cache.ts +17 -0
- package/src/render/resolution-subrect.ts +2 -0
- package/src/render/rough-diffuse.ts +46 -12
- package/src/render/soft-shadow.ts +27 -12
- package/src/render/virtual-shadow-adaptive.ts +55 -0
- package/src/render/virtual-shadow-casters.ts +175 -0
- package/src/render/virtual-shadow-layers.ts +76 -0
- package/src/render/virtual-shadow-level.ts +224 -0
- package/src/render/virtual-shadow-markers.ts +193 -0
- package/src/render/virtual-shadow-options.ts +370 -0
- package/src/render/virtual-shadow-pages.ts +5 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +231 -1008
- package/src/render/world-impostor-surface.ts +402 -40
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +98 -3
- package/src/render-environment.ts +41 -0
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +144 -65
- package/src/resolution-scaler.ts +3 -2
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +2 -1
- package/src/spells/cast-pool.ts +361 -0
- package/src/spells/index.ts +177 -0
- package/src/spells/mechanisms.ts +295 -0
- package/src/spells/reaction-field.ts +415 -0
- package/src/spells/spell-lights.ts +139 -0
- package/src/spells/spell-world.ts +187 -0
- package/src/spells/spell.ts +397 -0
- package/src/spells/spells.ts +283 -0
- package/src/spells/ultra/engine/camera.ts +184 -0
- package/src/spells/ultra/engine/quality.ts +96 -0
- package/src/spells/ultra/index.ts +52 -0
- package/src/spells/ultra/main.ts +305 -0
- package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
- package/src/spells/ultra/spells/cast.ts +233 -0
- package/src/spells/ultra/spells/fire.ts +1267 -0
- package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
- package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
- package/src/spells/ultra/vfx/FxTarget.ts +61 -0
- package/src/spells/ultra/vfx/GroundField.ts +1399 -0
- package/src/spells/ultra/vfx/Particles.ts +1475 -0
- package/src/spells/ultra/vfx/Ribbons.ts +645 -0
- package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
- package/src/spells/ultra/vfx/Volumes.ts +489 -0
- package/src/spells/ultra/vfx/common.ts +1195 -0
- package/src/spells/ultra/vfx/noise.ts +441 -0
- package/src/startup-offscreen-bytes.ts +78 -0
- package/src/startup-readiness.ts +128 -34
- package/src/static-transform.ts +25 -19
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +446 -0
- package/src/world-cell-batches.ts +1178 -0
- package/src/world-cell-chunks.ts +1128 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1461 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +177 -0
- package/src/world-cell-placements.ts +798 -0
- package/src/world-cell-prewarm.ts +592 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +710 -0
- package/src/world-cell-render-main-cull.ts +540 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +259 -0
- package/src/world-cell-render.ts +1501 -0
- package/src/world-cell-residency.ts +754 -0
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +1335 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +131 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +524 -0
- package/src/world-gpu-scene.ts +256 -2286
- package/src/world-gpu-shadow.ts +203 -0
- package/src/world-gpu-types.ts +409 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +111 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-noise.ts +241 -0
- package/src/world-package.ts +42 -0
- package/src/world-region.ts +1 -1
- package/src/world-river-ribbon.ts +282 -0
- package/src/world-root-frame.ts +39 -0
- package/src/world-shore-field.ts +91 -0
- package/src/world-static-pose.ts +163 -0
- package/src/world-surface-sampler.ts +48 -0
- package/src/world-terrain-splat.ts +361 -153
- package/src/world-tile-budget.ts +249 -0
- package/src/world-tile-geometry.ts +469 -0
- package/src/world-tile-lod.ts +408 -0
- package/src/world-tile-observation.ts +566 -0
- package/src/world-tile-stitch.ts +166 -0
- package/src/world-tiles.ts +247 -1755
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +48 -741
|
@@ -0,0 +1,1558 @@
|
|
|
1
|
+
import { CameraShake, GPUParticles3D } from '../chunk-H4J6IAJE.js';
|
|
2
|
+
import '../chunk-QWJEMUUT.js';
|
|
3
|
+
import { Vector3, PointLight, Vector2, Vector4 } from 'three';
|
|
4
|
+
import * as three from 'three/webgpu';
|
|
5
|
+
import { Vector3 as Vector3$1, Color, SpriteNodeMaterial, MeshBasicNodeMaterial, DoubleSide, Mesh, SphereGeometry, Sprite, PlaneGeometry } from 'three/webgpu';
|
|
6
|
+
import { uniform, normalize, vec3, abs, cross, uv, pow, oneMinus, vec4, length, float, smoothstep, mix, vec2, Fn, If, instanceIndex, uint, time, exp, varying, step, cos, sin, hash } from 'three/tsl';
|
|
7
|
+
|
|
8
|
+
var PHASES = ["charge", "travel", "impact", "linger", "done"];
|
|
9
|
+
var finite = (value, label) => {
|
|
10
|
+
if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite`);
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
var mixSeed = (seed, salt) => {
|
|
14
|
+
let x = seed ^ salt * 2654435761 | 0;
|
|
15
|
+
x = Math.imul(x ^ x >>> 16, 569420461);
|
|
16
|
+
x = Math.imul(x ^ x >>> 15, 1935289751);
|
|
17
|
+
return (x ^ x >>> 15) >>> 0;
|
|
18
|
+
};
|
|
19
|
+
var IDLE_SPELL = { name: "idle", shape: "self" };
|
|
20
|
+
function emptyRecord(index) {
|
|
21
|
+
return {
|
|
22
|
+
age: 0,
|
|
23
|
+
data: {},
|
|
24
|
+
dir: new Vector3(),
|
|
25
|
+
durations: { charge: 0.5, impact: 0.2, linger: 2, travel: 4 },
|
|
26
|
+
from: new Vector3(),
|
|
27
|
+
held: false,
|
|
28
|
+
index,
|
|
29
|
+
phase: "done",
|
|
30
|
+
pos: new Vector3(),
|
|
31
|
+
seed: 0,
|
|
32
|
+
shape: "projectile",
|
|
33
|
+
spell: IDLE_SPELL,
|
|
34
|
+
t: 0,
|
|
35
|
+
to: new Vector3(),
|
|
36
|
+
radius: 0.3,
|
|
37
|
+
travelled: 0,
|
|
38
|
+
vel: new Vector3()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
var scratch = new Vector3();
|
|
42
|
+
var ORIGIN = new Vector3();
|
|
43
|
+
var CastPool = class {
|
|
44
|
+
/** Every slot, alive or not. Read `phase !== "done"` for the live ones. */
|
|
45
|
+
casts;
|
|
46
|
+
#groundAt;
|
|
47
|
+
#focus;
|
|
48
|
+
/** The newest live cast, or undefined. */
|
|
49
|
+
#last;
|
|
50
|
+
#seed = 0;
|
|
51
|
+
constructor(world = {}) {
|
|
52
|
+
const capacity = world.castSlots ?? 16;
|
|
53
|
+
if (!Number.isInteger(capacity) || capacity < 1 || capacity > 256)
|
|
54
|
+
throw new RangeError("CastPool capacity must be an integer in 1..256");
|
|
55
|
+
this.#groundAt = world.groundAt;
|
|
56
|
+
this.#focus = world.focus;
|
|
57
|
+
this.casts = Array.from({ length: capacity }, (_, index) => emptyRecord(index));
|
|
58
|
+
}
|
|
59
|
+
/** The newest live cast. What a HUD reads for the phase strip. */
|
|
60
|
+
get active() {
|
|
61
|
+
return this.#last?.phase === "done" ? void 0 : this.#last;
|
|
62
|
+
}
|
|
63
|
+
get count() {
|
|
64
|
+
let live = 0;
|
|
65
|
+
for (const cast of this.casts) live += cast.phase === "done" ? 0 : 1;
|
|
66
|
+
return live;
|
|
67
|
+
}
|
|
68
|
+
/** Start a spell. Returns the record, which the caller may read but the pool advances. */
|
|
69
|
+
cast(spell, to, options = {}) {
|
|
70
|
+
const record = this.#reserve();
|
|
71
|
+
const from = options.from ?? this.#focus ?? ORIGIN;
|
|
72
|
+
this.#validate(spell, to, from);
|
|
73
|
+
this.#arm(record, spell, to, from, options);
|
|
74
|
+
this.#enter(record, "charge");
|
|
75
|
+
this.#last = record;
|
|
76
|
+
return record;
|
|
77
|
+
}
|
|
78
|
+
/** The record this cast will use: a free slot, else the stale one, never a held beam if avoidable. */
|
|
79
|
+
#reserve() {
|
|
80
|
+
const free = this.casts.find((candidate) => candidate.phase === "done");
|
|
81
|
+
if (free !== void 0) return free;
|
|
82
|
+
const unheld = this.casts.filter((candidate) => !candidate.held);
|
|
83
|
+
const pool = unheld.length > 0 ? unheld : this.casts;
|
|
84
|
+
const oldest = pool.reduce((a, b) => b.age > a.age ? b : a);
|
|
85
|
+
this.#enter(oldest, "done");
|
|
86
|
+
return oldest;
|
|
87
|
+
}
|
|
88
|
+
/** Reject a cast the pool cannot honour, before any record is touched. */
|
|
89
|
+
#validate(spell, to, from) {
|
|
90
|
+
finite(to.x, "to.x");
|
|
91
|
+
finite(to.y, "to.y");
|
|
92
|
+
finite(to.z, "to.z");
|
|
93
|
+
finite(from.x, "from.x");
|
|
94
|
+
finite(from.y, "from.y");
|
|
95
|
+
finite(from.z, "from.z");
|
|
96
|
+
const radius = spell.radius ?? 0.3;
|
|
97
|
+
if (!Number.isFinite(radius) || radius < 0)
|
|
98
|
+
throw new RangeError(`${spell.name}.radius must be finite and non-negative`);
|
|
99
|
+
}
|
|
100
|
+
/** Fill a reserved record for a new cast. */
|
|
101
|
+
#arm(record, spell, to, from, options) {
|
|
102
|
+
const durations = record.durations;
|
|
103
|
+
const timing = spell.timing ?? {};
|
|
104
|
+
durations.charge = finite(timing.charge ?? 0.5, "timing.charge");
|
|
105
|
+
durations.travel = finite(timing.travel ?? 4, "timing.travel");
|
|
106
|
+
durations.impact = finite(timing.impact ?? 0.2, "timing.impact");
|
|
107
|
+
durations.linger = finite(timing.linger ?? 2, "timing.linger");
|
|
108
|
+
record.spell = spell;
|
|
109
|
+
record.shape = options.shape ?? spell.shape ?? "projectile";
|
|
110
|
+
record.radius = spell.radius ?? 0.3;
|
|
111
|
+
record.held = options.held ?? false;
|
|
112
|
+
record.t = 0;
|
|
113
|
+
record.age = 0;
|
|
114
|
+
record.travelled = 0;
|
|
115
|
+
record.seed = options.seed ?? mixSeed(++this.#seed, 20973);
|
|
116
|
+
record.from.copy(from);
|
|
117
|
+
record.to.copy(to);
|
|
118
|
+
record.pos.copy(from);
|
|
119
|
+
record.dir.subVectors(to, from);
|
|
120
|
+
if (record.dir.lengthSq() > 0) record.dir.normalize();
|
|
121
|
+
else record.dir.set(0, 0, 1);
|
|
122
|
+
record.vel.set(0, 0, 0);
|
|
123
|
+
}
|
|
124
|
+
/** End every held beam. A game calls this when the button comes up. */
|
|
125
|
+
releaseHeld() {
|
|
126
|
+
for (const cast of this.casts) cast.held = false;
|
|
127
|
+
}
|
|
128
|
+
/** Retire every live cast without running linger. */
|
|
129
|
+
clear() {
|
|
130
|
+
for (const cast of this.casts) if (cast.phase !== "done") this.#enter(cast, "done");
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Advance every live cast. A projectile lands on the target, on the world's floor, or when its
|
|
134
|
+
* travel time runs out, whichever comes first.
|
|
135
|
+
*/
|
|
136
|
+
update(dt) {
|
|
137
|
+
if (!Number.isFinite(dt) || dt < 0)
|
|
138
|
+
throw new RangeError("CastPool.update delta must be finite and non-negative");
|
|
139
|
+
for (const cast of this.casts) {
|
|
140
|
+
if (cast.phase === "done") continue;
|
|
141
|
+
cast.t += dt;
|
|
142
|
+
cast.age += dt;
|
|
143
|
+
const state = this.#advanceBeat(cast, dt);
|
|
144
|
+
if (state === "retired") continue;
|
|
145
|
+
cast.spell.update?.(cast, dt);
|
|
146
|
+
if (state === "landed") this.#enter(cast, "impact");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** Advance one record's beat: still running, landed on the spell's own word, or retired. */
|
|
150
|
+
#advanceBeat(cast, dt) {
|
|
151
|
+
if (cast.phase === "charge") this.#advanceCharge(cast);
|
|
152
|
+
else if (cast.phase === "travel") return this.#advanceTravel(cast, dt) ? "landed" : "running";
|
|
153
|
+
else if (cast.phase === "impact") {
|
|
154
|
+
if (cast.t >= cast.durations.impact) this.#enter(cast, "linger");
|
|
155
|
+
} else if (cast.t >= cast.durations.linger) {
|
|
156
|
+
this.#enter(cast, "done");
|
|
157
|
+
return "retired";
|
|
158
|
+
}
|
|
159
|
+
return "running";
|
|
160
|
+
}
|
|
161
|
+
#advanceCharge(cast) {
|
|
162
|
+
cast.pos.copy(cast.from);
|
|
163
|
+
if (cast.t < cast.durations.charge) return;
|
|
164
|
+
const spell = cast.spell;
|
|
165
|
+
if (cast.shape === "projectile") {
|
|
166
|
+
cast.vel.copy(cast.dir).multiplyScalar(finite(spell.speed ?? 15, `${spell.name}.speed`));
|
|
167
|
+
this.#enter(cast, "travel");
|
|
168
|
+
} else if (cast.shape === "beam") this.#enter(cast, "travel");
|
|
169
|
+
else {
|
|
170
|
+
if (cast.shape !== "self") cast.pos.copy(cast.to);
|
|
171
|
+
this.#enter(cast, "impact");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** True only when the spell's own travel hook says it landed; the pool lands its own shots. */
|
|
175
|
+
#advanceTravel(cast, dt) {
|
|
176
|
+
const spell = cast.spell;
|
|
177
|
+
if (cast.shape !== "projectile") {
|
|
178
|
+
if (!cast.held && cast.t >= cast.durations.travel) this.#enter(cast, "impact");
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
if (spell.travel !== void 0) return spell.travel(cast, dt) === true;
|
|
182
|
+
cast.pos.addScaledVector(cast.vel, dt);
|
|
183
|
+
cast.travelled += cast.vel.length() * dt;
|
|
184
|
+
const radius = cast.radius;
|
|
185
|
+
const past = scratch.subVectors(cast.to, cast.pos).dot(cast.dir) <= 0;
|
|
186
|
+
const groundAt = this.#groundAt;
|
|
187
|
+
const floor = groundAt === void 0 ? Number.NEGATIVE_INFINITY : groundAt(cast.pos.x, cast.pos.z);
|
|
188
|
+
const buried = Number.isFinite(floor) && cast.travelled > 1 && cast.pos.y < floor + radius;
|
|
189
|
+
if (past) {
|
|
190
|
+
cast.pos.copy(cast.to);
|
|
191
|
+
this.#enter(cast, "impact");
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
if (buried || cast.t >= cast.durations.travel) this.#enter(cast, "impact");
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
#enter(cast, phase) {
|
|
198
|
+
if (!PHASES.includes(phase)) throw new RangeError(`unknown cast phase ${phase}`);
|
|
199
|
+
cast.phase = phase;
|
|
200
|
+
cast.t = 0;
|
|
201
|
+
cast.spell.phase?.(cast, phase);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/spells/reaction-field.ts
|
|
206
|
+
var REACTION_CHANNELS = [
|
|
207
|
+
/** Fire, lightning and lava: what a floor reads as "still burning". */
|
|
208
|
+
"heat",
|
|
209
|
+
/** Burnt floor. Decays far slower than heat and is what a scorch looks like. */
|
|
210
|
+
"char",
|
|
211
|
+
/** Water and ice melt: a puddle a lightning spell spreads across. */
|
|
212
|
+
"wet",
|
|
213
|
+
/** Ice. Reads cold, and a fire spell wants to melt it back. */
|
|
214
|
+
"frost",
|
|
215
|
+
/** A fissure or a shattered floor: a crack pattern whose strength fades. */
|
|
216
|
+
"crack",
|
|
217
|
+
/** Residual magic light, for a floor that glows after impact. */
|
|
218
|
+
"glow"
|
|
219
|
+
];
|
|
220
|
+
var DEFAULT_HALF_LIFE = {
|
|
221
|
+
// ponytail: one half-life per channel and no wave transport. Upgrade to a GPU solve with
|
|
222
|
+
// advection if a game needs fire to spread uphill or water to run across a floor.
|
|
223
|
+
heat: 3.5,
|
|
224
|
+
char: 24,
|
|
225
|
+
crack: 40,
|
|
226
|
+
frost: 8,
|
|
227
|
+
glow: 1.6,
|
|
228
|
+
wet: 12
|
|
229
|
+
};
|
|
230
|
+
var clamp01 = (value) => value < 0 ? 0 : value > 1 ? 1 : value;
|
|
231
|
+
var finite2 = (value, label) => {
|
|
232
|
+
if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite`);
|
|
233
|
+
return value;
|
|
234
|
+
};
|
|
235
|
+
var hash2 = (x, y, seed) => {
|
|
236
|
+
let h = Math.imul(x, 668265261) ^ Math.imul(y, 374761393) ^ Math.imul(seed, 2654435761);
|
|
237
|
+
h = Math.imul(h ^ h >>> 15, 625341585);
|
|
238
|
+
return (h ^ h >>> 13) >>> 0;
|
|
239
|
+
};
|
|
240
|
+
var ReactionField = class {
|
|
241
|
+
resolution;
|
|
242
|
+
size;
|
|
243
|
+
dx;
|
|
244
|
+
/** Patch centre in world metres. */
|
|
245
|
+
centerX = 0;
|
|
246
|
+
centerZ = 0;
|
|
247
|
+
/** Bumped whenever any cell changes, so an upload can skip an unchanged frame. */
|
|
248
|
+
version = 0;
|
|
249
|
+
#channels;
|
|
250
|
+
#halfLife;
|
|
251
|
+
#dirty;
|
|
252
|
+
#empty = true;
|
|
253
|
+
constructor(options = {}) {
|
|
254
|
+
const resolution = options.resolution ?? 96;
|
|
255
|
+
if (!Number.isInteger(resolution) || resolution < 16 || resolution > 512)
|
|
256
|
+
throw new RangeError("resolution must be an integer in 16..512");
|
|
257
|
+
const size = options.size ?? 120;
|
|
258
|
+
if (!Number.isFinite(size) || size <= 0) throw new RangeError("size must be a positive length");
|
|
259
|
+
this.resolution = resolution;
|
|
260
|
+
this.size = size;
|
|
261
|
+
this.dx = size / resolution;
|
|
262
|
+
const count = resolution * resolution;
|
|
263
|
+
this.#channels = {};
|
|
264
|
+
this.#halfLife = { ...DEFAULT_HALF_LIFE };
|
|
265
|
+
for (const channel of REACTION_CHANNELS) {
|
|
266
|
+
this.#channels[channel] = new Float32Array(count);
|
|
267
|
+
const halfLife = options.halfLife?.[channel];
|
|
268
|
+
if (halfLife !== void 0) {
|
|
269
|
+
if (!Number.isFinite(halfLife) || halfLife <= 0)
|
|
270
|
+
throw new RangeError(`halfLife.${channel} must be positive and finite`);
|
|
271
|
+
this.#halfLife[channel] = halfLife;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/** The live values of one channel, row-major from the patch's -x/-z corner. Read-only to a game. */
|
|
276
|
+
data(channel) {
|
|
277
|
+
return this.#channels[channel];
|
|
278
|
+
}
|
|
279
|
+
/** True while every cell of every channel is exactly zero. */
|
|
280
|
+
get empty() {
|
|
281
|
+
return this.#empty;
|
|
282
|
+
}
|
|
283
|
+
/** True while the point is inside the patch, `margin` metres in from its rim. */
|
|
284
|
+
contains(x, z, margin = 0) {
|
|
285
|
+
const half = this.size / 2 - margin;
|
|
286
|
+
return Math.abs(x - this.centerX) < half && Math.abs(z - this.centerZ) < half;
|
|
287
|
+
}
|
|
288
|
+
/** Nearest-neighbour read at a world point, 0 outside the patch. Cheap enough for a combo check. */
|
|
289
|
+
sample(channel, x, z) {
|
|
290
|
+
if (!this.contains(x, z)) return 0;
|
|
291
|
+
const n = this.resolution;
|
|
292
|
+
const i = Math.min(n - 1, Math.max(0, Math.floor(((x - this.centerX) / this.size + 0.5) * n)));
|
|
293
|
+
const j = Math.min(n - 1, Math.max(0, Math.floor(((z - this.centerZ) / this.size + 0.5) * n)));
|
|
294
|
+
return this.#channels[channel][j * n + i];
|
|
295
|
+
}
|
|
296
|
+
/** Strongest channel at a point, for a game that only asks "is anything happening here". */
|
|
297
|
+
strongest(x, z) {
|
|
298
|
+
let best;
|
|
299
|
+
let bestValue = 0;
|
|
300
|
+
for (const channel of REACTION_CHANNELS) {
|
|
301
|
+
const value = this.sample(channel, x, z);
|
|
302
|
+
if (value > bestValue) {
|
|
303
|
+
bestValue = value;
|
|
304
|
+
best = channel;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return best;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Lay a mark on the patch. Every channel is additive and saturates at 1, so two fireballs on the
|
|
311
|
+
* same cell burn hotter than one but never past the top of the range. Off-patch splats return
|
|
312
|
+
* false and change nothing.
|
|
313
|
+
*/
|
|
314
|
+
splat(splat) {
|
|
315
|
+
const radius = validateSplat(splat);
|
|
316
|
+
if (!this.contains(splat.x, splat.z)) return false;
|
|
317
|
+
const amounts = amountsOf(splat);
|
|
318
|
+
if (amounts === void 0) return true;
|
|
319
|
+
const { cells, hiX, hiZ, ix, iz, loX, loZ } = this.#cellRect(splat, radius);
|
|
320
|
+
const seed = splat.seed ?? 0;
|
|
321
|
+
const shape = {
|
|
322
|
+
angleCos: Math.cos(splat.angle ?? 0),
|
|
323
|
+
angleSin: Math.sin(splat.angle ?? 0),
|
|
324
|
+
cells,
|
|
325
|
+
pattern: splat.pattern ?? "radial"
|
|
326
|
+
};
|
|
327
|
+
const n = this.resolution;
|
|
328
|
+
for (let j = loZ; j <= hiZ; j++) {
|
|
329
|
+
for (let i = loX; i <= hiX; i++) {
|
|
330
|
+
const shaped = cellShape(shape, i - ix, j - iz);
|
|
331
|
+
if (shaped <= 2e-3) continue;
|
|
332
|
+
const grain = 0.7 + 0.6 * ((hash2(i, j, seed) & 65535) / 65535);
|
|
333
|
+
const index = j * n + i;
|
|
334
|
+
for (const [channel, amount] of amounts) {
|
|
335
|
+
const data = this.#channels[channel];
|
|
336
|
+
data[index] = clamp01(data[index] + amount * shaped * grain);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
this.#markDirty(loX, loZ, hiX, hiZ);
|
|
341
|
+
this.#empty = false;
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
/** Forget everything now, and report one last full-patch upload. */
|
|
345
|
+
clear() {
|
|
346
|
+
for (const channel of REACTION_CHANNELS) this.#channels[channel].fill(0);
|
|
347
|
+
this.#empty = true;
|
|
348
|
+
this.#markDirty(0, 0, this.resolution - 1, this.resolution - 1);
|
|
349
|
+
}
|
|
350
|
+
/** Move the patch with the action. Newly exposed cells arrive clean. */
|
|
351
|
+
recenter(x, z) {
|
|
352
|
+
finite2(x, "x");
|
|
353
|
+
finite2(z, "z");
|
|
354
|
+
const di = Math.round((x - this.centerX) / this.dx);
|
|
355
|
+
const dj = Math.round((z - this.centerZ) / this.dx);
|
|
356
|
+
if (di === 0 && dj === 0) return;
|
|
357
|
+
this.centerX += di * this.dx;
|
|
358
|
+
this.centerZ += dj * this.dx;
|
|
359
|
+
if (this.#empty) return;
|
|
360
|
+
if (Math.abs(di) >= this.resolution || Math.abs(dj) >= this.resolution) {
|
|
361
|
+
for (const channel of REACTION_CHANNELS) this.#channels[channel].fill(0);
|
|
362
|
+
this.#empty = true;
|
|
363
|
+
} else {
|
|
364
|
+
const scratch2 = new Float32Array(this.resolution * this.resolution);
|
|
365
|
+
for (const channel of REACTION_CHANNELS)
|
|
366
|
+
shift(this.#channels[channel], this.resolution, di, dj, scratch2);
|
|
367
|
+
}
|
|
368
|
+
this.#markDirty(0, 0, this.resolution - 1, this.resolution - 1);
|
|
369
|
+
}
|
|
370
|
+
/** Decay every channel on its own half-life. Time passing on a clean patch changes no cell. */
|
|
371
|
+
update(dt) {
|
|
372
|
+
if (!Number.isFinite(dt) || dt < 0)
|
|
373
|
+
throw new RangeError("ReactionField.update delta must be finite and non-negative");
|
|
374
|
+
if (this.#empty || dt === 0) return;
|
|
375
|
+
let live = false;
|
|
376
|
+
for (const channel of REACTION_CHANNELS) live = this.#decay(channel, dt) || live;
|
|
377
|
+
if (!live) this.#empty = true;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Hand back the cells that changed since the last call, and forget them.
|
|
381
|
+
* `undefined` means nothing changed, so an upload can be skipped whole.
|
|
382
|
+
*/
|
|
383
|
+
consumeDirty() {
|
|
384
|
+
const dirty = this.#dirty;
|
|
385
|
+
this.#dirty = void 0;
|
|
386
|
+
if (dirty === void 0) return void 0;
|
|
387
|
+
return {
|
|
388
|
+
height: dirty.maxZ - dirty.minZ + 1,
|
|
389
|
+
width: dirty.maxX - dirty.minX + 1,
|
|
390
|
+
x: dirty.minX,
|
|
391
|
+
z: dirty.minZ
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/** The cells a splat can reach, and the splat's centre in grid coordinates. */
|
|
395
|
+
#cellRect(splat, radius) {
|
|
396
|
+
const n = this.resolution;
|
|
397
|
+
const ix = ((splat.x - this.centerX) / this.size + 0.5) * n - 0.5;
|
|
398
|
+
const iz = ((splat.z - this.centerZ) / this.size + 0.5) * n - 0.5;
|
|
399
|
+
const cells = Math.max(0.75, radius / this.dx);
|
|
400
|
+
const reach = 2.2 * cells * (splat.pattern === "streak" ? 2.4 : 1);
|
|
401
|
+
return {
|
|
402
|
+
cells,
|
|
403
|
+
hiX: Math.min(n - 1, Math.ceil(ix + reach)),
|
|
404
|
+
hiZ: Math.min(n - 1, Math.ceil(iz + reach)),
|
|
405
|
+
ix,
|
|
406
|
+
iz,
|
|
407
|
+
loX: Math.max(0, Math.floor(ix - reach)),
|
|
408
|
+
loZ: Math.max(0, Math.floor(iz - reach))
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
/** Decay one channel for a step. True while any cell is still lit. */
|
|
412
|
+
#decay(channel, dt) {
|
|
413
|
+
const data = this.#channels[channel];
|
|
414
|
+
const keep = 2 ** (-dt / this.#halfLife[channel]);
|
|
415
|
+
const extent = { hiX: -1, hiZ: -1, loX: this.resolution, loZ: this.resolution };
|
|
416
|
+
const live = decayCells(data, keep, this.resolution, extent);
|
|
417
|
+
if (extent.hiX >= 0) this.#markDirty(extent.loX, extent.loZ, extent.hiX, extent.hiZ);
|
|
418
|
+
return live;
|
|
419
|
+
}
|
|
420
|
+
#markDirty(minX, minZ, maxX, maxZ) {
|
|
421
|
+
this.version += 1;
|
|
422
|
+
const dirty = this.#dirty;
|
|
423
|
+
if (dirty === void 0) this.#dirty = { maxX, maxZ, minX, minZ };
|
|
424
|
+
else {
|
|
425
|
+
dirty.minX = Math.min(dirty.minX, minX);
|
|
426
|
+
dirty.minZ = Math.min(dirty.minZ, minZ);
|
|
427
|
+
dirty.maxX = Math.max(dirty.maxX, maxX);
|
|
428
|
+
dirty.maxZ = Math.max(dirty.maxZ, maxZ);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
function decayCells(data, keep, n, extent) {
|
|
433
|
+
let live = false;
|
|
434
|
+
for (let index = 0; index < data.length; index++) {
|
|
435
|
+
const value = data[index];
|
|
436
|
+
if (value === 0) continue;
|
|
437
|
+
const next = value * keep;
|
|
438
|
+
data[index] = next < 1e-4 ? 0 : next;
|
|
439
|
+
const i = index % n;
|
|
440
|
+
const j = (index - i) / n;
|
|
441
|
+
if (i < extent.loX) extent.loX = i;
|
|
442
|
+
if (i > extent.hiX) extent.hiX = i;
|
|
443
|
+
if (j < extent.loZ) extent.loZ = j;
|
|
444
|
+
if (j > extent.hiZ) extent.hiZ = j;
|
|
445
|
+
if (data[index] !== 0) live = true;
|
|
446
|
+
}
|
|
447
|
+
return live;
|
|
448
|
+
}
|
|
449
|
+
function validateSplat(splat) {
|
|
450
|
+
const radius = finite2(splat.radius, "splat.radius");
|
|
451
|
+
if (!(radius > 0)) throw new RangeError("splat.radius must be positive");
|
|
452
|
+
if (!Number.isFinite(splat.x)) throw new TypeError("splat.x must be finite");
|
|
453
|
+
if (!Number.isFinite(splat.z)) throw new TypeError("splat.z must be finite");
|
|
454
|
+
if (splat.angle !== void 0 && !Number.isFinite(splat.angle))
|
|
455
|
+
throw new TypeError("splat.angle must be finite");
|
|
456
|
+
for (const channel of REACTION_CHANNELS) {
|
|
457
|
+
const amount = splat[channel];
|
|
458
|
+
if (amount !== void 0 && !Number.isFinite(amount))
|
|
459
|
+
throw new TypeError(`splat.${channel} must be finite`);
|
|
460
|
+
}
|
|
461
|
+
return radius;
|
|
462
|
+
}
|
|
463
|
+
function amountsOf(splat) {
|
|
464
|
+
const amounts = [];
|
|
465
|
+
for (const channel of REACTION_CHANNELS) {
|
|
466
|
+
const amount = splat[channel] ?? 0;
|
|
467
|
+
if (amount !== 0) amounts.push([channel, amount]);
|
|
468
|
+
}
|
|
469
|
+
return amounts.length === 0 ? void 0 : amounts;
|
|
470
|
+
}
|
|
471
|
+
function cellShape(shape, ddx, ddz) {
|
|
472
|
+
const { cells, pattern } = shape;
|
|
473
|
+
if (pattern === "streak") {
|
|
474
|
+
const along = (ddx * shape.angleCos + ddz * shape.angleSin) / 2.4;
|
|
475
|
+
const across = (-ddx * shape.angleSin + ddz * shape.angleCos) / 0.8;
|
|
476
|
+
return Math.exp(-((along * along + across * across) / (cells * cells)));
|
|
477
|
+
}
|
|
478
|
+
const q = (ddx * ddx + ddz * ddz) / (cells * cells);
|
|
479
|
+
return pattern === "ring" ? Math.exp(-((Math.sqrt(q) - 0.8) ** 2) * 6) : Math.exp(-q);
|
|
480
|
+
}
|
|
481
|
+
function shift(data, n, di, dj, scratch2) {
|
|
482
|
+
scratch2.fill(0);
|
|
483
|
+
const i0 = Math.max(0, -di);
|
|
484
|
+
const i1 = Math.min(n, n - di);
|
|
485
|
+
const j0 = Math.max(0, -dj);
|
|
486
|
+
const j1 = Math.min(n, n - dj);
|
|
487
|
+
for (let j = j0; j < j1; j++) {
|
|
488
|
+
const source = (j + dj) * n + i0 + di;
|
|
489
|
+
scratch2.set(data.subarray(source, source + (i1 - i0)), j * n + i0);
|
|
490
|
+
}
|
|
491
|
+
data.set(scratch2);
|
|
492
|
+
}
|
|
493
|
+
var finite3 = (value, label) => {
|
|
494
|
+
if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite`);
|
|
495
|
+
return value;
|
|
496
|
+
};
|
|
497
|
+
var SpellLights = class {
|
|
498
|
+
lights;
|
|
499
|
+
#slots;
|
|
500
|
+
constructor(options) {
|
|
501
|
+
if (options.parent === void 0 || options.parent === null)
|
|
502
|
+
throw new Error("SpellLights.parent is required.");
|
|
503
|
+
const count = options.count ?? 4;
|
|
504
|
+
if (!Number.isInteger(count) || count < 1 || count > 32)
|
|
505
|
+
throw new RangeError("SpellLights.count must be an integer in 1..32");
|
|
506
|
+
this.lights = Array.from({ length: count }, (_, index) => {
|
|
507
|
+
const light = new PointLight(16777215, 0, 10, 2);
|
|
508
|
+
light.name = `spell-light-${index}`;
|
|
509
|
+
light.intensity = 0;
|
|
510
|
+
light.castShadow = options.shadows ?? false;
|
|
511
|
+
options.parent.add(light);
|
|
512
|
+
return light;
|
|
513
|
+
});
|
|
514
|
+
this.#slots = this.lights.map(() => ({ duration: 1, peak: 0, remaining: 0 }));
|
|
515
|
+
}
|
|
516
|
+
/** True while at least one light is lit, so a game can skip its own light bookkeeping. */
|
|
517
|
+
get active() {
|
|
518
|
+
return this.#slots.some((slot) => slot.remaining > 0);
|
|
519
|
+
}
|
|
520
|
+
/** The light this flash took, or undefined when the pool was full. */
|
|
521
|
+
flash(request) {
|
|
522
|
+
const seconds = finite3(request.seconds, "flash.seconds");
|
|
523
|
+
if (seconds <= 0) throw new RangeError("flash.seconds must be positive");
|
|
524
|
+
const intensity = finite3(request.intensity, "flash.intensity");
|
|
525
|
+
const range = finite3(request.range, "flash.range");
|
|
526
|
+
const x = finite3(request.x, "flash.x");
|
|
527
|
+
const y = finite3(request.y, "flash.y");
|
|
528
|
+
const z = finite3(request.z, "flash.z");
|
|
529
|
+
const index = this.#slots.findIndex((slot2) => slot2.remaining <= 0);
|
|
530
|
+
if (index < 0) return void 0;
|
|
531
|
+
const light = this.lights[index];
|
|
532
|
+
const slot = this.#slots[index];
|
|
533
|
+
slot.peak = Math.max(0, intensity);
|
|
534
|
+
slot.duration = seconds;
|
|
535
|
+
slot.remaining = seconds;
|
|
536
|
+
light.position.set(x, y, z);
|
|
537
|
+
light.color.copy(request.color);
|
|
538
|
+
light.distance = Math.max(0, range);
|
|
539
|
+
light.intensity = slot.peak;
|
|
540
|
+
return light;
|
|
541
|
+
}
|
|
542
|
+
/** Put every light out now, without waiting for its decay. */
|
|
543
|
+
clear() {
|
|
544
|
+
for (let index = 0; index < this.#slots.length; index++) {
|
|
545
|
+
const slot = this.#slots[index];
|
|
546
|
+
slot.remaining = 0;
|
|
547
|
+
slot.peak = 0;
|
|
548
|
+
this.lights[index].intensity = 0;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
update(dt) {
|
|
552
|
+
if (!Number.isFinite(dt) || dt < 0)
|
|
553
|
+
throw new RangeError("SpellLights.update delta must be finite and non-negative");
|
|
554
|
+
for (let index = 0; index < this.#slots.length; index++) {
|
|
555
|
+
const slot = this.#slots[index];
|
|
556
|
+
if (slot.remaining <= 0) continue;
|
|
557
|
+
const light = this.lights[index];
|
|
558
|
+
slot.remaining -= dt;
|
|
559
|
+
if (slot.remaining <= 0) {
|
|
560
|
+
slot.remaining = 0;
|
|
561
|
+
slot.peak = 0;
|
|
562
|
+
light.intensity = 0;
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
light.intensity = slot.peak * (slot.remaining / slot.duration);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
var DEFAULT_SHAKE = {
|
|
570
|
+
amplitude: 0.12,
|
|
571
|
+
decay: 5,
|
|
572
|
+
frequency: 11,
|
|
573
|
+
rotationAmplitude: 0.012
|
|
574
|
+
};
|
|
575
|
+
var DEFAULT_CURVE = (phase) => Math.sin(phase) * Math.cos(phase * 1.7);
|
|
576
|
+
var SpellWorld = class {
|
|
577
|
+
scene;
|
|
578
|
+
camera;
|
|
579
|
+
groundAt;
|
|
580
|
+
castSlots;
|
|
581
|
+
lights;
|
|
582
|
+
reaction;
|
|
583
|
+
shake;
|
|
584
|
+
reducedFlashes;
|
|
585
|
+
/** Where a spell with no `from` starts: the caster's hand, in world metres. */
|
|
586
|
+
focus = new Vector3();
|
|
587
|
+
/** Parent a spell's pooled object. See `ISpellWorldOptions.add`. */
|
|
588
|
+
add;
|
|
589
|
+
/** Everything a spell has parented through `add`, in creation order. */
|
|
590
|
+
objects = [];
|
|
591
|
+
/** Seconds since the world was created. */
|
|
592
|
+
time = 0;
|
|
593
|
+
/** Flashes the limiter refused, so a game can see its own accessibility setting working. */
|
|
594
|
+
suppressedFlashes = 0;
|
|
595
|
+
/** Millisecond stamps of the flashes that were allowed, newest last, at most `FLASH_WINDOW`. */
|
|
596
|
+
#flashes = [];
|
|
597
|
+
constructor(options) {
|
|
598
|
+
if (options.scene === void 0 || options.scene === null)
|
|
599
|
+
throw new Error("SpellWorld.scene is required.");
|
|
600
|
+
this.scene = options.scene;
|
|
601
|
+
this.camera = options.camera;
|
|
602
|
+
this.groundAt = options.groundAt;
|
|
603
|
+
this.castSlots = options.castSlots ?? 16;
|
|
604
|
+
this.add = (object) => {
|
|
605
|
+
if (this.objects.includes(object)) return;
|
|
606
|
+
this.objects.push(object);
|
|
607
|
+
if (options.add === void 0) options.scene.add(object);
|
|
608
|
+
else options.add(object);
|
|
609
|
+
};
|
|
610
|
+
this.reducedFlashes = options.reducedFlashes ?? false;
|
|
611
|
+
this.lights = new SpellLights({ count: options.lightCount ?? 4, parent: options.scene });
|
|
612
|
+
this.reaction = options.reaction === false ? void 0 : new ReactionField(options.reaction ?? {});
|
|
613
|
+
if (options.shake === false) this.shake = void 0;
|
|
614
|
+
else {
|
|
615
|
+
const shake = options.shake ?? {};
|
|
616
|
+
const amplitude = shake.amplitude ?? DEFAULT_SHAKE.amplitude;
|
|
617
|
+
const rotationAmplitude = shake.rotationAmplitude ?? DEFAULT_SHAKE.rotationAmplitude;
|
|
618
|
+
const settings = {
|
|
619
|
+
amplitude: new Vector3(amplitude, amplitude * 0.6, amplitude),
|
|
620
|
+
curve: shake.curve ?? DEFAULT_CURVE,
|
|
621
|
+
decay: shake.decay ?? DEFAULT_SHAKE.decay,
|
|
622
|
+
frequency: shake.frequency ?? DEFAULT_SHAKE.frequency,
|
|
623
|
+
rotationAmplitude: new Vector3(
|
|
624
|
+
rotationAmplitude,
|
|
625
|
+
rotationAmplitude,
|
|
626
|
+
rotationAmplitude * 0.5
|
|
627
|
+
)
|
|
628
|
+
};
|
|
629
|
+
this.shake = new CameraShake(settings);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Ask the limiter whether a flash may be shown.
|
|
634
|
+
*
|
|
635
|
+
* With reduced flashes on, a fourth flash inside one second is refused and the spell draws its
|
|
636
|
+
* impact without one. Returning a boolean rather than quietly dimming keeps the spell honest:
|
|
637
|
+
* the spell still happens, the flash does not.
|
|
638
|
+
*/
|
|
639
|
+
flash() {
|
|
640
|
+
if (!this.reducedFlashes) return true;
|
|
641
|
+
const now = this.time * 1e3;
|
|
642
|
+
this.#flashes = this.#flashes.filter((at2) => now - at2 < 1e3);
|
|
643
|
+
if (this.#flashes.length >= FLASH_PER_SECOND) {
|
|
644
|
+
this.suppressedFlashes += 1;
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
this.#flashes.push(now);
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
/** Surface height of the floor under a point, or 0 when the game supplied none. */
|
|
651
|
+
floorAt(x, z) {
|
|
652
|
+
return this.groundAt?.(x, z) ?? 0;
|
|
653
|
+
}
|
|
654
|
+
update(dt) {
|
|
655
|
+
if (!Number.isFinite(dt) || dt < 0)
|
|
656
|
+
throw new RangeError("SpellWorld.update delta must be finite and non-negative");
|
|
657
|
+
this.time += dt;
|
|
658
|
+
this.lights.update(dt);
|
|
659
|
+
this.reaction?.update(dt);
|
|
660
|
+
this.shake?.update(dt);
|
|
661
|
+
}
|
|
662
|
+
/** Put out every light, clear the floor and stop the shake, keeping every pool warm. */
|
|
663
|
+
clear() {
|
|
664
|
+
this.lights.clear();
|
|
665
|
+
this.reaction?.clear();
|
|
666
|
+
this.shake?.stop();
|
|
667
|
+
this.#flashes = [];
|
|
668
|
+
this.suppressedFlashes = 0;
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
var FLASH_PER_SECOND = 3;
|
|
672
|
+
var PARTICLE_KINDS = [
|
|
673
|
+
"flame",
|
|
674
|
+
"ember",
|
|
675
|
+
"spark",
|
|
676
|
+
"smoke",
|
|
677
|
+
"ice",
|
|
678
|
+
"arc",
|
|
679
|
+
"mote",
|
|
680
|
+
"debris"
|
|
681
|
+
];
|
|
682
|
+
var KIND_DEFAULTS = {
|
|
683
|
+
// A small fast-cooling lick: rides off the ball, drags hard and stops short.
|
|
684
|
+
flame: {
|
|
685
|
+
alpha: [0.95, 0],
|
|
686
|
+
buoyancy: 3.8,
|
|
687
|
+
colour: [1, 0.72, 0.34],
|
|
688
|
+
cone: 0.9,
|
|
689
|
+
drag: 3.6,
|
|
690
|
+
gravity: 0,
|
|
691
|
+
highlight: [1, 0.24, 0.04],
|
|
692
|
+
lifetime: [0.16, 0.36],
|
|
693
|
+
size: [0.32, 0.09],
|
|
694
|
+
speed: [0.8, 2.6]
|
|
695
|
+
},
|
|
696
|
+
// A glowing chip that skitters and burns in.
|
|
697
|
+
ember: {
|
|
698
|
+
alpha: [1, 0],
|
|
699
|
+
buoyancy: 1.7,
|
|
700
|
+
colour: [1, 0.82, 0.4],
|
|
701
|
+
cone: 1.2,
|
|
702
|
+
drag: 0.6,
|
|
703
|
+
gravity: 1.2,
|
|
704
|
+
highlight: [1, 0.3, 0.05],
|
|
705
|
+
lifetime: [1, 2.6],
|
|
706
|
+
size: [0.035, 0.01],
|
|
707
|
+
speed: [1.4, 4.2]
|
|
708
|
+
},
|
|
709
|
+
// Fast, heavy, gone in a fifth of a second.
|
|
710
|
+
spark: {
|
|
711
|
+
alpha: [1, 0],
|
|
712
|
+
buoyancy: 0,
|
|
713
|
+
colour: [1, 0.95, 0.82],
|
|
714
|
+
cone: 1.4,
|
|
715
|
+
drag: 0.35,
|
|
716
|
+
gravity: 9.8,
|
|
717
|
+
highlight: [1, 0.34, 0.06],
|
|
718
|
+
lifetime: [0.4, 1.3],
|
|
719
|
+
size: [0.04, 0.01],
|
|
720
|
+
speed: [4, 9]
|
|
721
|
+
},
|
|
722
|
+
// Rises and swells: long-lived and slow.
|
|
723
|
+
smoke: {
|
|
724
|
+
alpha: [0.55, 0],
|
|
725
|
+
buoyancy: 1.6,
|
|
726
|
+
colour: [0.16, 0.15, 0.14],
|
|
727
|
+
cone: 0.6,
|
|
728
|
+
drag: 1.3,
|
|
729
|
+
gravity: 0,
|
|
730
|
+
highlight: [0.09, 0.085, 0.08],
|
|
731
|
+
lifetime: [2.2, 4.5],
|
|
732
|
+
size: [0.4, 1.9],
|
|
733
|
+
speed: [0.3, 1.2]
|
|
734
|
+
},
|
|
735
|
+
// Cold: falls, and drags the air with it.
|
|
736
|
+
ice: {
|
|
737
|
+
alpha: [0.9, 0],
|
|
738
|
+
buoyancy: -0.4,
|
|
739
|
+
colour: [0.72, 0.95, 1],
|
|
740
|
+
cone: 0.8,
|
|
741
|
+
drag: 0.9,
|
|
742
|
+
gravity: 6.5,
|
|
743
|
+
highlight: [0.36, 0.62, 1],
|
|
744
|
+
lifetime: [0.6, 1.8],
|
|
745
|
+
size: [0.08, 0.22],
|
|
746
|
+
speed: [2, 6]
|
|
747
|
+
},
|
|
748
|
+
// An ionised filament: nearly straight, very fast, over almost before it is read.
|
|
749
|
+
arc: {
|
|
750
|
+
alpha: [1, 0],
|
|
751
|
+
buoyancy: 0,
|
|
752
|
+
colour: [0.85, 0.93, 1],
|
|
753
|
+
cone: 0.25,
|
|
754
|
+
drag: 0.2,
|
|
755
|
+
gravity: 0,
|
|
756
|
+
highlight: [0.36, 0.44, 1],
|
|
757
|
+
lifetime: [0.08, 0.24],
|
|
758
|
+
size: [0.06, 0.02],
|
|
759
|
+
speed: [10, 20]
|
|
760
|
+
},
|
|
761
|
+
// A charge mote: slow, converging, drawn in rather than thrown out.
|
|
762
|
+
mote: {
|
|
763
|
+
alpha: [0, 1],
|
|
764
|
+
buoyancy: 0.3,
|
|
765
|
+
colour: [0.72, 0.82, 1],
|
|
766
|
+
cone: 0.5,
|
|
767
|
+
drag: 1.2,
|
|
768
|
+
gravity: 0,
|
|
769
|
+
highlight: [1, 0.95, 1],
|
|
770
|
+
lifetime: [0.35, 0.7],
|
|
771
|
+
size: [0.02, 0.05],
|
|
772
|
+
speed: [0.2, 0.9]
|
|
773
|
+
},
|
|
774
|
+
// Lit rock: heavy, and it lies where it lands.
|
|
775
|
+
debris: {
|
|
776
|
+
alpha: [1, 0.9],
|
|
777
|
+
buoyancy: 0,
|
|
778
|
+
colour: [0.16, 0.13, 0.12],
|
|
779
|
+
cone: 1.1,
|
|
780
|
+
drag: 0.25,
|
|
781
|
+
gravity: 9.8,
|
|
782
|
+
highlight: [1, 0.35, 0.06],
|
|
783
|
+
lifetime: [1.6, 3.2],
|
|
784
|
+
size: [0.085, 0.085],
|
|
785
|
+
speed: [3, 7]
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
var TAU = Math.PI * 2;
|
|
789
|
+
var ParticleKindTable = class {
|
|
790
|
+
kinds;
|
|
791
|
+
#nodes = /* @__PURE__ */ new Map();
|
|
792
|
+
constructor(kinds = PARTICLE_KINDS) {
|
|
793
|
+
const seen = /* @__PURE__ */ new Set();
|
|
794
|
+
for (const kind of kinds) {
|
|
795
|
+
if (!PARTICLE_KINDS.includes(kind))
|
|
796
|
+
throw new RangeError(`unknown particle kind ${kind}`);
|
|
797
|
+
if (seen.has(kind)) throw new RangeError(`particle kind ${kind} listed twice`);
|
|
798
|
+
seen.add(kind);
|
|
799
|
+
this.#nodes.set(kind, nodesFor(KIND_DEFAULTS[kind]));
|
|
800
|
+
}
|
|
801
|
+
this.kinds = [...kinds];
|
|
802
|
+
}
|
|
803
|
+
has(kind) {
|
|
804
|
+
return this.#nodes.has(kind);
|
|
805
|
+
}
|
|
806
|
+
/** Read one kind's current values. */
|
|
807
|
+
get(kind) {
|
|
808
|
+
const nodes = this.nodes(kind);
|
|
809
|
+
return {
|
|
810
|
+
alpha: [nodes.alpha.value.x, nodes.alpha.value.y],
|
|
811
|
+
buoyancy: nodes.shape.value.w,
|
|
812
|
+
colour: [nodes.colour.value.x, nodes.colour.value.y, nodes.colour.value.z],
|
|
813
|
+
cone: nodes.shape.value.x,
|
|
814
|
+
drag: nodes.shape.value.z,
|
|
815
|
+
gravity: nodes.shape.value.y,
|
|
816
|
+
highlight: [nodes.highlight.value.x, nodes.highlight.value.y, nodes.highlight.value.z],
|
|
817
|
+
lifetime: [nodes.lifetime.value.x, nodes.lifetime.value.y],
|
|
818
|
+
size: [nodes.size.value.x, nodes.size.value.y],
|
|
819
|
+
speed: [nodes.speed.value.x, nodes.speed.value.y]
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Retune a kind. Every field is optional, every value must be finite, and a partial patch leaves
|
|
824
|
+
* the rest alone. No kernel is rebuilt and no material is replaced.
|
|
825
|
+
*/
|
|
826
|
+
set(kind, patch) {
|
|
827
|
+
const nodes = this.nodes(kind);
|
|
828
|
+
if (patch.lifetime !== void 0)
|
|
829
|
+
writePair(nodes.lifetime.value, patch.lifetime, `${kind}.lifetime`);
|
|
830
|
+
if (patch.size !== void 0) writePair(nodes.size.value, patch.size, `${kind}.size`);
|
|
831
|
+
if (patch.speed !== void 0) writePair(nodes.speed.value, patch.speed, `${kind}.speed`);
|
|
832
|
+
if (patch.alpha !== void 0) writePair(nodes.alpha.value, patch.alpha, `${kind}.alpha`);
|
|
833
|
+
if (patch.colour !== void 0) writeTriple(nodes.colour.value, patch.colour, `${kind}.colour`);
|
|
834
|
+
if (patch.highlight !== void 0)
|
|
835
|
+
writeTriple(nodes.highlight.value, patch.highlight, `${kind}.highlight`);
|
|
836
|
+
const shape = nodes.shape.value;
|
|
837
|
+
if (patch.cone !== void 0) shape.x = atLeast(`${kind}.cone`, patch.cone, 0);
|
|
838
|
+
if (patch.gravity !== void 0)
|
|
839
|
+
shape.y = atLeast(`${kind}.gravity`, patch.gravity, Number.NEGATIVE_INFINITY);
|
|
840
|
+
if (patch.drag !== void 0) shape.z = atLeast(`${kind}.drag`, patch.drag, 0);
|
|
841
|
+
if (patch.buoyancy !== void 0)
|
|
842
|
+
shape.w = atLeast(`${kind}.buoyancy`, patch.buoyancy, Number.NEGATIVE_INFINITY);
|
|
843
|
+
return this;
|
|
844
|
+
}
|
|
845
|
+
/** The TSL nodes one kind's kernel and material read. Stable for the table's lifetime. */
|
|
846
|
+
nodes(kind) {
|
|
847
|
+
const nodes = this.#nodes.get(kind);
|
|
848
|
+
if (nodes === void 0) throw new RangeError(`particle kind ${kind} is not in this table`);
|
|
849
|
+
return nodes;
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
function createParticleKindEmitter(options) {
|
|
853
|
+
const nodes = options.table.nodes(options.kind);
|
|
854
|
+
const seed = options.seed ?? 0;
|
|
855
|
+
const capacity = options.amount;
|
|
856
|
+
const style = options.style ?? "glow";
|
|
857
|
+
const direction = normalize(vec3(...options.direction ?? [0, 1, 0]));
|
|
858
|
+
const tangent = abs(direction.y).greaterThan(0.9) ? vec3(1, 0, 0) : vec3(0, 1, 0);
|
|
859
|
+
const bitangent = normalize(cross(direction, tangent));
|
|
860
|
+
const material = new SpriteNodeMaterial({
|
|
861
|
+
blending: options.blending ?? three.AdditiveBlending,
|
|
862
|
+
depthWrite: false,
|
|
863
|
+
toneMapped: false,
|
|
864
|
+
transparent: true
|
|
865
|
+
});
|
|
866
|
+
const random = (salt, key) => hash(instanceIndex.add(seed + salt).add(key));
|
|
867
|
+
const launch = (key) => {
|
|
868
|
+
const cone = nodes.shape.x.mul(random(29, key).sqrt());
|
|
869
|
+
const azimuth = random(31, key).mul(TAU);
|
|
870
|
+
return normalize(
|
|
871
|
+
direction.mul(cos(cone)).add(tangent.mul(cos(azimuth)).mul(sin(cone))).add(bitangent.mul(sin(azimuth)).mul(sin(cone)))
|
|
872
|
+
).mul(mix(nodes.speed.x, nodes.speed.y, random(23, key)));
|
|
873
|
+
};
|
|
874
|
+
const bindMaterial = (born) => {
|
|
875
|
+
const key = born.max(0).mul(1e3).toUint();
|
|
876
|
+
const age = time.sub(born);
|
|
877
|
+
const life = mix(nodes.lifetime.x, nodes.lifetime.y, random(13, key));
|
|
878
|
+
varying(step(0, age).mul(step(age, life)));
|
|
879
|
+
const phase = varying(age.div(life).clamp(0, 1));
|
|
880
|
+
mix(nodes.size.x, nodes.size.y, phase);
|
|
881
|
+
const stock = KIND_DEFAULTS[options.kind];
|
|
882
|
+
const rgb = options.look?.colour ?? stock.colour;
|
|
883
|
+
const opacity = Math.min(0.34, Math.max(0.16, (options.look?.alpha ?? stock.alpha[0]) * 0.32));
|
|
884
|
+
const spriteSize = Math.max(0.26, (options.look?.size ?? stock.size[0]) * 0.8);
|
|
885
|
+
material.scaleNode = vec2(spriteSize, spriteSize);
|
|
886
|
+
material.colorNode = vec4(rgb[0], rgb[1], rgb[2], opacity).mul(mask(style));
|
|
887
|
+
};
|
|
888
|
+
const spawn = ({
|
|
889
|
+
positions,
|
|
890
|
+
velocities,
|
|
891
|
+
births
|
|
892
|
+
}, request) => {
|
|
893
|
+
bindMaterial(births.toAttribute());
|
|
894
|
+
return Fn(() => {
|
|
895
|
+
If(instanceIndex.lessThan(request.count), () => {
|
|
896
|
+
const slot = request.first.add(instanceIndex).mod(uint(capacity));
|
|
897
|
+
velocities.element(slot).assign(request.origin);
|
|
898
|
+
positions.element(slot).assign(request.origin);
|
|
899
|
+
});
|
|
900
|
+
})().compute(capacity);
|
|
901
|
+
};
|
|
902
|
+
const process = ({
|
|
903
|
+
positions,
|
|
904
|
+
velocities,
|
|
905
|
+
births
|
|
906
|
+
}) => Fn(() => {
|
|
907
|
+
const born = births.element(instanceIndex);
|
|
908
|
+
const key = born.max(0).mul(1e3).toUint();
|
|
909
|
+
const age = time.sub(born).max(0);
|
|
910
|
+
const drag = nodes.shape.z.max(1e-3);
|
|
911
|
+
const travel = float(1).sub(exp(drag.mul(age).negate())).div(drag);
|
|
912
|
+
const fall = nodes.shape.y.mul(age.mul(age)).mul(0.5);
|
|
913
|
+
const lift = nodes.shape.w.mul(age.mul(age)).mul(0.5);
|
|
914
|
+
const local = launch(key).mul(travel).add(vec3(0, float(lift.sub(fall)), 0));
|
|
915
|
+
positions.element(instanceIndex).assign(velocities.element(instanceIndex).add(local));
|
|
916
|
+
})().compute(capacity);
|
|
917
|
+
return {
|
|
918
|
+
amount: capacity,
|
|
919
|
+
lifetime: Math.max(nodes.lifetime.value.y, 0.01),
|
|
920
|
+
material,
|
|
921
|
+
onCull: "pause",
|
|
922
|
+
process,
|
|
923
|
+
spawn
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
function mask(style) {
|
|
927
|
+
const point = uv().sub(0.5);
|
|
928
|
+
const radius = point.length();
|
|
929
|
+
if (style === "spark") {
|
|
930
|
+
const streak = float(1).sub(smoothstep(0.02, 0.1, abs(point.y))).mul(float(1).sub(smoothstep(0.14, 0.5, abs(point.x))));
|
|
931
|
+
return float(1).sub(smoothstep(0.06, 0.5, radius)).max(streak);
|
|
932
|
+
}
|
|
933
|
+
if (style === "media") return float(1).sub(smoothstep(0.02, 0.5, radius));
|
|
934
|
+
return float(1).sub(smoothstep(0.06, 0.54, radius)).add(float(0.22).mul(float(1).sub(smoothstep(0.01, 0.22, radius))));
|
|
935
|
+
}
|
|
936
|
+
function nodesFor(values) {
|
|
937
|
+
return {
|
|
938
|
+
alpha: uniform(new Vector2(values.alpha[0], values.alpha[1])),
|
|
939
|
+
colour: uniform(new Vector3(...values.colour)),
|
|
940
|
+
highlight: uniform(new Vector3(...values.highlight)),
|
|
941
|
+
lifetime: uniform(new Vector2(values.lifetime[0], values.lifetime[1])),
|
|
942
|
+
shape: uniform(new Vector4(values.cone, values.gravity, values.drag, values.buoyancy)),
|
|
943
|
+
size: uniform(new Vector2(values.size[0], values.size[1])),
|
|
944
|
+
speed: uniform(new Vector2(values.speed[0], values.speed[1]))
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
function writePair(target, pair, label) {
|
|
948
|
+
if (!Number.isFinite(pair[0]) || !Number.isFinite(pair[1]))
|
|
949
|
+
throw new TypeError(`${label} must be finite`);
|
|
950
|
+
if (pair[0] > pair[1]) throw new RangeError(`${label} must be ordered low then high`);
|
|
951
|
+
target.set(pair[0], pair[1]);
|
|
952
|
+
}
|
|
953
|
+
function writeTriple(target, triple, label) {
|
|
954
|
+
if (!triple.every(Number.isFinite)) throw new TypeError(`${label} must be finite`);
|
|
955
|
+
target.set(triple[0], triple[1], triple[2]);
|
|
956
|
+
}
|
|
957
|
+
function atLeast(label, value, minimum) {
|
|
958
|
+
if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite`);
|
|
959
|
+
if (value < minimum) throw new RangeError(`${label} must be at least ${minimum}`);
|
|
960
|
+
return value;
|
|
961
|
+
}
|
|
962
|
+
var TAU2 = Math.PI * 2;
|
|
963
|
+
var finite4 = (label, value) => {
|
|
964
|
+
if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite`);
|
|
965
|
+
return value;
|
|
966
|
+
};
|
|
967
|
+
var SpellCore = class {
|
|
968
|
+
sprite = new Sprite();
|
|
969
|
+
#colour = uniform(new Color(1, 0.72, 0.34));
|
|
970
|
+
#highlight = uniform(new Color(1, 0.95, 0.72));
|
|
971
|
+
#radius = uniform(0.35);
|
|
972
|
+
#intensity = uniform(1);
|
|
973
|
+
#material;
|
|
974
|
+
constructor(parent) {
|
|
975
|
+
this.#material = new SpriteNodeMaterial({
|
|
976
|
+
depthWrite: false,
|
|
977
|
+
toneMapped: false,
|
|
978
|
+
transparent: true
|
|
979
|
+
});
|
|
980
|
+
const point = uv().sub(0.5);
|
|
981
|
+
const radius = length(point);
|
|
982
|
+
const core = float(1).sub(smoothstep(0.04, 0.44, radius));
|
|
983
|
+
const rim = pow(oneMinus(smoothstep(0.3, 0.5, radius)), 2.5);
|
|
984
|
+
this.#material.colorNode = vec4(
|
|
985
|
+
mix(this.#colour, this.#highlight, core.mul(0.85).add(0.15)),
|
|
986
|
+
core.add(rim.mul(0.55)).mul(this.#intensity)
|
|
987
|
+
);
|
|
988
|
+
this.#material.scaleNode = vec2(this.#radius, this.#radius).mul(2.6);
|
|
989
|
+
this.sprite.material = this.#material;
|
|
990
|
+
this.sprite.frustumCulled = false;
|
|
991
|
+
this.sprite.visible = false;
|
|
992
|
+
parent.add(this.sprite);
|
|
993
|
+
}
|
|
994
|
+
/** Metres across, the tint, and how hard it burns. */
|
|
995
|
+
show(position, radius, colour2, highlight, intensity) {
|
|
996
|
+
this.sprite.position.copy(position);
|
|
997
|
+
this.#radius.value = Math.max(1e-3, finite4("core.radius", radius));
|
|
998
|
+
this.#colour.value.copy(colour2);
|
|
999
|
+
this.#highlight.value.copy(highlight);
|
|
1000
|
+
this.#intensity.value = Math.max(0, finite4("core.intensity", intensity));
|
|
1001
|
+
this.sprite.visible = true;
|
|
1002
|
+
}
|
|
1003
|
+
hide() {
|
|
1004
|
+
this.sprite.visible = false;
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
var ShockShell = class {
|
|
1008
|
+
mesh;
|
|
1009
|
+
#colour = uniform(new Color(1, 0.7, 0.3));
|
|
1010
|
+
#progress = uniform(0);
|
|
1011
|
+
#strength = uniform(0);
|
|
1012
|
+
#material;
|
|
1013
|
+
constructor(parent) {
|
|
1014
|
+
this.#material = new MeshBasicNodeMaterial({
|
|
1015
|
+
depthWrite: false,
|
|
1016
|
+
side: DoubleSide,
|
|
1017
|
+
toneMapped: false,
|
|
1018
|
+
transparent: true
|
|
1019
|
+
});
|
|
1020
|
+
const rim = pow(oneMinus(abs(uv().sub(0.5).length().mul(2).sub(1))), 3);
|
|
1021
|
+
this.#material.colorNode = vec4(this.#colour, rim.mul(this.#strength));
|
|
1022
|
+
this.mesh = new Mesh(new SphereGeometry(1, 24, 16), this.#material);
|
|
1023
|
+
this.mesh.frustumCulled = false;
|
|
1024
|
+
this.mesh.visible = false;
|
|
1025
|
+
parent.add(this.mesh);
|
|
1026
|
+
}
|
|
1027
|
+
/** `progress` 0..1 drives both the radius and the fade, so a shell cannot outlive its impact. */
|
|
1028
|
+
show(centre, progress, radius, colour2, strength, fade = 1 - Math.min(1, Math.max(0, progress))) {
|
|
1029
|
+
this.mesh.position.copy(centre);
|
|
1030
|
+
this.#progress.value = Math.min(1, Math.max(0, progress));
|
|
1031
|
+
const scale = Math.max(1e-3, finite4("shell.radius", radius)) * Math.max(0.02, this.#progress.value);
|
|
1032
|
+
this.mesh.scale.setScalar(scale);
|
|
1033
|
+
this.#colour.value.copy(colour2);
|
|
1034
|
+
this.#strength.value = Math.max(0, finite4("shell.strength", strength)) * Math.max(0, fade);
|
|
1035
|
+
this.mesh.visible = this.#strength.value > 1e-3;
|
|
1036
|
+
}
|
|
1037
|
+
hide() {
|
|
1038
|
+
this.mesh.visible = false;
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
var BoltColumn = class {
|
|
1042
|
+
mesh;
|
|
1043
|
+
#colour = uniform(new Color(0.85, 0.93, 1));
|
|
1044
|
+
#core = uniform(new Color(1, 1, 1));
|
|
1045
|
+
#strength = uniform(0);
|
|
1046
|
+
#seed = uniform(0);
|
|
1047
|
+
#material;
|
|
1048
|
+
#up = new Vector3$1(0, 1, 0);
|
|
1049
|
+
constructor(parent, segments = 28) {
|
|
1050
|
+
this.#material = new MeshBasicNodeMaterial({
|
|
1051
|
+
depthWrite: false,
|
|
1052
|
+
side: DoubleSide,
|
|
1053
|
+
toneMapped: false,
|
|
1054
|
+
transparent: true
|
|
1055
|
+
});
|
|
1056
|
+
const across = uv().x.sub(0.5);
|
|
1057
|
+
const along = uv().y;
|
|
1058
|
+
const jag = along.mul(41.7).add(this.#seed).fract().sub(0.5).mul(0.055).add(along.mul(97.3).add(this.#seed.mul(1.7)).fract().sub(0.5).mul(0.022));
|
|
1059
|
+
const coreWidth = float(0.16).mul(oneMinus(smoothstep(0, 0.5, across.abs().mul(2))));
|
|
1060
|
+
const glowWidth = oneMinus(smoothstep(0, 0.5, across.abs().mul(2).sub(coreWidth)));
|
|
1061
|
+
this.#material.colorNode = vec4(
|
|
1062
|
+
mix(this.#colour, this.#core, coreWidth),
|
|
1063
|
+
glowWidth.mul(this.#strength).mul(oneMinus(along.mul(0.25)))
|
|
1064
|
+
);
|
|
1065
|
+
this.#material.positionNode = vec3(across.add(jag), along, 0);
|
|
1066
|
+
this.mesh = new Mesh(new PlaneGeometry(1, 1, 1, segments), this.#material);
|
|
1067
|
+
this.mesh.frustumCulled = false;
|
|
1068
|
+
this.mesh.visible = false;
|
|
1069
|
+
parent.add(this.mesh);
|
|
1070
|
+
}
|
|
1071
|
+
/** Stretch the ribbon from `from` to `to`, facing the camera enough to read from any angle. */
|
|
1072
|
+
show(from, to, width, colour2, core, strength, seed, camera) {
|
|
1073
|
+
const direction = new Vector3$1().subVectors(to, from);
|
|
1074
|
+
const span = direction.length();
|
|
1075
|
+
if (!(span > 1e-4)) {
|
|
1076
|
+
this.hide();
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
this.mesh.position.copy(from).addScaledVector(direction, 0.5);
|
|
1080
|
+
const axis = direction.clone().normalize();
|
|
1081
|
+
this.mesh.quaternion.setFromUnitVectors(this.#up, axis);
|
|
1082
|
+
if (camera !== void 0) {
|
|
1083
|
+
const toCamera = new Vector3$1().subVectors(camera.position, this.mesh.position);
|
|
1084
|
+
toCamera.addScaledVector(axis, -toCamera.dot(axis));
|
|
1085
|
+
if (toCamera.lengthSq() > 1e-6) {
|
|
1086
|
+
const basis = new Vector3$1(1, 0, 0).applyQuaternion(this.mesh.quaternion);
|
|
1087
|
+
this.mesh.rotateY(
|
|
1088
|
+
Math.atan2(new Vector3$1().crossVectors(basis, toCamera).dot(axis), basis.dot(toCamera))
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
this.mesh.scale.set(Math.max(0.01, finite4("bolt.width", width)), span, 1);
|
|
1093
|
+
this.#colour.value.copy(colour2);
|
|
1094
|
+
this.#core.value.copy(core);
|
|
1095
|
+
this.#strength.value = Math.max(0, finite4("bolt.strength", strength));
|
|
1096
|
+
this.#seed.value = seed % 1;
|
|
1097
|
+
this.mesh.visible = this.#strength.value > 1e-3;
|
|
1098
|
+
}
|
|
1099
|
+
hide() {
|
|
1100
|
+
this.mesh.visible = false;
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
var ShieldBubble = class {
|
|
1104
|
+
mesh;
|
|
1105
|
+
#colour = uniform(new Color(1, 0.4, 0.9));
|
|
1106
|
+
#strength = uniform(0);
|
|
1107
|
+
#pulse = uniform(0);
|
|
1108
|
+
#material;
|
|
1109
|
+
constructor(parent) {
|
|
1110
|
+
this.#material = new MeshBasicNodeMaterial({
|
|
1111
|
+
depthWrite: false,
|
|
1112
|
+
side: DoubleSide,
|
|
1113
|
+
toneMapped: false,
|
|
1114
|
+
transparent: true
|
|
1115
|
+
});
|
|
1116
|
+
const cells = uv().mul(TAU2 * 6);
|
|
1117
|
+
const facet = abs(cells.x.sin().mul(cells.y.sin())).mul(0.5).add(0.5);
|
|
1118
|
+
const rim = pow(oneMinus(abs(uv().x.mul(2).sub(1)).mul(0.6)), 1.6);
|
|
1119
|
+
this.#material.colorNode = vec4(
|
|
1120
|
+
this.#colour,
|
|
1121
|
+
facet.mul(0.85).add(rim.mul(0.9)).mul(this.#strength).mul(this.#pulse.add(0.75))
|
|
1122
|
+
);
|
|
1123
|
+
this.mesh = new Mesh(new SphereGeometry(1, 32, 24), this.#material);
|
|
1124
|
+
this.mesh.frustumCulled = false;
|
|
1125
|
+
this.mesh.visible = false;
|
|
1126
|
+
parent.add(this.mesh);
|
|
1127
|
+
}
|
|
1128
|
+
show(centre, radius, colour2, strength, pulse) {
|
|
1129
|
+
this.mesh.position.copy(centre);
|
|
1130
|
+
this.mesh.scale.setScalar(Math.max(1e-3, finite4("shield.radius", radius)));
|
|
1131
|
+
this.#colour.value.copy(colour2);
|
|
1132
|
+
this.#strength.value = Math.max(0, finite4("shield.strength", strength));
|
|
1133
|
+
this.#pulse.value = Math.min(1, Math.max(0, pulse));
|
|
1134
|
+
this.mesh.visible = this.#strength.value > 1e-3;
|
|
1135
|
+
}
|
|
1136
|
+
hide() {
|
|
1137
|
+
this.mesh.visible = false;
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
function createDrawables(parent) {
|
|
1141
|
+
return {
|
|
1142
|
+
bolt: new BoltColumn(parent),
|
|
1143
|
+
core: new SpellCore(parent),
|
|
1144
|
+
shell: new ShockShell(parent),
|
|
1145
|
+
shield: new ShieldBubble(parent)
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// src/spells/spell.ts
|
|
1150
|
+
function createSpell(world, recipe2) {
|
|
1151
|
+
const built = build(world, recipe2);
|
|
1152
|
+
const position = new Vector3$1();
|
|
1153
|
+
const sky = new Vector3$1();
|
|
1154
|
+
const lightColour = new Color();
|
|
1155
|
+
const shellColour = new Color();
|
|
1156
|
+
return {
|
|
1157
|
+
name: recipe2.name,
|
|
1158
|
+
radius: recipe2.radius,
|
|
1159
|
+
shape: recipe2.shape,
|
|
1160
|
+
speed: recipe2.speed,
|
|
1161
|
+
timing: recipe2.timing,
|
|
1162
|
+
phase(cast, phase) {
|
|
1163
|
+
const scratch2 = at(built.scratch, cast);
|
|
1164
|
+
const drawables = at(built.drawables, cast);
|
|
1165
|
+
if (phase === "charge") {
|
|
1166
|
+
scratch2.sinceImpact = 0;
|
|
1167
|
+
scratch2.emitTimer = 0;
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
if (phase === "impact") {
|
|
1171
|
+
scratch2.sinceImpact = 0;
|
|
1172
|
+
scratch2.emitTimer = 0;
|
|
1173
|
+
land(world, drawables, recipe2, cast, sky, lightColour, shellColour);
|
|
1174
|
+
emit(built.burst, recipe2.burst, cast.pos, recipe2.burst?.burst ?? 0);
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
if (phase === "linger") {
|
|
1178
|
+
emit(built.linger, recipe2.linger, cast.pos, recipe2.linger?.burst ?? 0);
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
drawables.core.hide();
|
|
1182
|
+
drawables.shell.hide();
|
|
1183
|
+
drawables.bolt.hide();
|
|
1184
|
+
},
|
|
1185
|
+
update(cast, dt) {
|
|
1186
|
+
const scratch2 = at(built.scratch, cast);
|
|
1187
|
+
const drawables = at(built.drawables, cast);
|
|
1188
|
+
if (cast.phase === "charge") {
|
|
1189
|
+
position.copy(cast.from);
|
|
1190
|
+
chargeUp(drawables, recipe2, position, cast.t / Math.max(1e-4, cast.durations.charge));
|
|
1191
|
+
emit(built.charge, recipe2.charge, position, (recipe2.charge?.burst ?? 0) * dt * 60);
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
if (cast.phase === "travel") {
|
|
1195
|
+
position.copy(cast.pos);
|
|
1196
|
+
drawBall(drawables, recipe2, position);
|
|
1197
|
+
emit(built.trail, recipe2.trail, position, (recipe2.trail?.burst ?? 0) * dt * 60);
|
|
1198
|
+
if (recipe2.bolt !== void 0) {
|
|
1199
|
+
sky.copy(cast.pos).setY(cast.pos.y + recipe2.bolt.height);
|
|
1200
|
+
drawBolt(drawables, recipe2, sky, cast.pos, 1, world.camera);
|
|
1201
|
+
}
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
scratch2.sinceImpact += dt;
|
|
1205
|
+
stepImpact(drawables, recipe2, cast, scratch2.sinceImpact, world.camera);
|
|
1206
|
+
if (cast.phase === "linger") {
|
|
1207
|
+
scratch2.emitTimer += dt;
|
|
1208
|
+
const interval = Math.max(0.02, recipe2.linger?.interval ?? 0.12);
|
|
1209
|
+
if (scratch2.emitTimer >= interval) {
|
|
1210
|
+
scratch2.emitTimer = 0;
|
|
1211
|
+
emit(built.linger, recipe2.linger, cast.pos, recipe2.linger?.burst ?? 0);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
function build(world, recipe2) {
|
|
1218
|
+
const table = new ParticleKindTable(
|
|
1219
|
+
uniqueKinds([recipe2.charge, recipe2.trail, recipe2.burst, recipe2.linger])
|
|
1220
|
+
);
|
|
1221
|
+
for (const kind of table.kinds) {
|
|
1222
|
+
table.set(kind, {
|
|
1223
|
+
colour: [recipe2.tint.colour.r, recipe2.tint.colour.g, recipe2.tint.colour.b],
|
|
1224
|
+
highlight: [recipe2.tint.highlight.r, recipe2.tint.highlight.g, recipe2.tint.highlight.b]
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
return {
|
|
1228
|
+
burst: buildEmitter(world, table, recipe2.burst, recipe2.name, 1, recipe2.tint),
|
|
1229
|
+
charge: buildEmitter(world, table, recipe2.charge, recipe2.name, 2, recipe2.tint),
|
|
1230
|
+
drawables: Array.from({ length: world.castSlots }, () => createDrawables(world.scene)),
|
|
1231
|
+
linger: buildEmitter(world, table, recipe2.linger, recipe2.name, 3, recipe2.tint),
|
|
1232
|
+
scratch: Array.from({ length: world.castSlots }, () => ({ emitTimer: 0, sinceImpact: 0 })),
|
|
1233
|
+
trail: buildEmitter(world, table, recipe2.trail, recipe2.name, 4, recipe2.tint)
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
function land(world, drawables, recipe2, cast, sky, lightColour, shellColour) {
|
|
1237
|
+
const impact = recipe2.impact;
|
|
1238
|
+
if (impact.light !== void 0) {
|
|
1239
|
+
const light = impact.light;
|
|
1240
|
+
if (world.flash()) {
|
|
1241
|
+
lightColour.copy(recipe2.tint.colour).lerp(recipe2.tint.highlight, 0.4);
|
|
1242
|
+
world.lights.flash({
|
|
1243
|
+
color: lightColour,
|
|
1244
|
+
intensity: light.intensity,
|
|
1245
|
+
range: light.range,
|
|
1246
|
+
seconds: light.seconds,
|
|
1247
|
+
x: cast.pos.x,
|
|
1248
|
+
y: cast.pos.y,
|
|
1249
|
+
z: cast.pos.z
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
if (impact.splat !== void 0) {
|
|
1254
|
+
const splat = impact.splat;
|
|
1255
|
+
world.reaction?.splat({
|
|
1256
|
+
char: splat.char,
|
|
1257
|
+
crack: splat.crack,
|
|
1258
|
+
frost: splat.frost,
|
|
1259
|
+
glow: splat.glow,
|
|
1260
|
+
heat: splat.heat,
|
|
1261
|
+
pattern: splat.pattern ?? "radial",
|
|
1262
|
+
radius: splat.radius,
|
|
1263
|
+
seed: cast.seed,
|
|
1264
|
+
wet: splat.wet,
|
|
1265
|
+
x: cast.pos.x,
|
|
1266
|
+
z: cast.pos.z
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
if (impact.shake !== void 0 && impact.shake > 0) world.shake?.trigger();
|
|
1270
|
+
if (recipe2.bolt !== void 0) {
|
|
1271
|
+
sky.copy(cast.pos).setY(cast.pos.y + recipe2.bolt.height);
|
|
1272
|
+
drawBolt(drawables, recipe2, sky, cast.pos, 1, world.camera);
|
|
1273
|
+
}
|
|
1274
|
+
if (impact.shell !== void 0) {
|
|
1275
|
+
shellColour.copy(recipe2.tint.colour).lerp(recipe2.tint.highlight, 0.5);
|
|
1276
|
+
drawables.shell.show(cast.pos, 0.02, impact.shell.radius, shellColour, impact.shell.strength);
|
|
1277
|
+
}
|
|
1278
|
+
drawables.core.hide();
|
|
1279
|
+
}
|
|
1280
|
+
function stepImpact(drawables, recipe2, cast, sinceImpact, camera) {
|
|
1281
|
+
const shell = recipe2.impact.shell;
|
|
1282
|
+
if (shell !== void 0) {
|
|
1283
|
+
const colour2 = recipe2.tint.colour.clone().lerp(recipe2.tint.highlight, 0.5);
|
|
1284
|
+
if (shell.hold === true) {
|
|
1285
|
+
const pulse = 0.9 + 0.1 * Math.sin(sinceImpact * 9);
|
|
1286
|
+
drawables.shell.show(cast.pos, 0.999, shell.radius, colour2, shell.strength * pulse, 1);
|
|
1287
|
+
} else {
|
|
1288
|
+
const progress = Math.min(1, sinceImpact / Math.max(0.05, shell.seconds));
|
|
1289
|
+
drawables.shell.show(cast.pos, progress, shell.radius, colour2, shell.strength);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
const bolt = recipe2.bolt;
|
|
1293
|
+
if (bolt !== void 0) {
|
|
1294
|
+
const life = Math.min(1, sinceImpact / Math.max(0.05, bolt.seconds));
|
|
1295
|
+
const sky = new Vector3$1(cast.pos.x, cast.pos.y + bolt.height, cast.pos.z);
|
|
1296
|
+
drawBolt(drawables, recipe2, sky, cast.pos, 1 - life, camera);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
function drawBall(drawables, recipe2, at2) {
|
|
1300
|
+
const core = recipe2.core;
|
|
1301
|
+
if (core === void 0) return;
|
|
1302
|
+
drawables.core.show(at2, core.radius, recipe2.tint.colour, recipe2.tint.highlight, core.intensity);
|
|
1303
|
+
}
|
|
1304
|
+
function chargeUp(drawables, recipe2, at2, progress) {
|
|
1305
|
+
const core = recipe2.core;
|
|
1306
|
+
if (core === void 0) return;
|
|
1307
|
+
const eased = Math.min(1, Math.max(0, progress));
|
|
1308
|
+
drawables.core.show(
|
|
1309
|
+
at2,
|
|
1310
|
+
core.radius * (0.25 + 0.75 * eased),
|
|
1311
|
+
recipe2.tint.colour,
|
|
1312
|
+
recipe2.tint.highlight,
|
|
1313
|
+
core.intensity * eased
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
function drawBolt(drawables, recipe2, from, to, strength, camera) {
|
|
1317
|
+
const bolt = recipe2.bolt;
|
|
1318
|
+
if (bolt === void 0 || strength <= 1e-3) {
|
|
1319
|
+
drawables.bolt.hide();
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
drawables.bolt.show(
|
|
1323
|
+
from,
|
|
1324
|
+
to,
|
|
1325
|
+
bolt.width,
|
|
1326
|
+
recipe2.tint.highlight,
|
|
1327
|
+
recipe2.tint.colour,
|
|
1328
|
+
strength,
|
|
1329
|
+
0.37,
|
|
1330
|
+
camera
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
function buildEmitter(world, table, role, name, seedOffset, tint) {
|
|
1334
|
+
if (role === void 0) return void 0;
|
|
1335
|
+
const options = createParticleKindEmitter({
|
|
1336
|
+
// burst is particles per emission and may be fractional (a trail emits 2.4 per frame), but a
|
|
1337
|
+
// ring capacity is a whole number of slots.
|
|
1338
|
+
amount: Math.max(64, Math.ceil(role.burst * 64)),
|
|
1339
|
+
kind: role.kind,
|
|
1340
|
+
seed: seedOffset * 1013 + hashName(name),
|
|
1341
|
+
style: role.style,
|
|
1342
|
+
table
|
|
1343
|
+
});
|
|
1344
|
+
const particles = new GPUParticles3D(options);
|
|
1345
|
+
particles.name = `${name}-${role.kind}-${seedOffset}`;
|
|
1346
|
+
world.add(particles);
|
|
1347
|
+
return particles;
|
|
1348
|
+
}
|
|
1349
|
+
function emit(emitter, role, at2, count) {
|
|
1350
|
+
if (emitter === void 0 || role === void 0) return;
|
|
1351
|
+
emitter.emitParticle({ count: Math.max(1, Math.round(count)), origin: at2 });
|
|
1352
|
+
}
|
|
1353
|
+
function uniqueKinds(roles) {
|
|
1354
|
+
const kinds = [];
|
|
1355
|
+
for (const role of roles) {
|
|
1356
|
+
if (role !== void 0 && !kinds.includes(role.kind)) kinds.push(role.kind);
|
|
1357
|
+
}
|
|
1358
|
+
return kinds.length > 0 ? kinds : ["spark"];
|
|
1359
|
+
}
|
|
1360
|
+
function at(list, cast) {
|
|
1361
|
+
const value = list[cast.index];
|
|
1362
|
+
if (value === void 0) throw new RangeError(`cast slot ${cast.index} is outside the pool`);
|
|
1363
|
+
return value;
|
|
1364
|
+
}
|
|
1365
|
+
function hashName(name) {
|
|
1366
|
+
let hash3 = 2166136261;
|
|
1367
|
+
for (let index = 0; index < name.length; index++) {
|
|
1368
|
+
hash3 ^= name.charCodeAt(index);
|
|
1369
|
+
hash3 = Math.imul(hash3, 16777619);
|
|
1370
|
+
}
|
|
1371
|
+
return hash3 >>> 8;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// src/spells/spells.ts
|
|
1375
|
+
var colour = (value) => new Color(value);
|
|
1376
|
+
function recipe(base, overrides) {
|
|
1377
|
+
const tint = {
|
|
1378
|
+
colour: colour(overrides.core ?? `#${base.tint.colour.getHexString()}`),
|
|
1379
|
+
highlight: colour(overrides.highlight ?? `#${base.tint.highlight.getHexString()}`)
|
|
1380
|
+
};
|
|
1381
|
+
const withBurst = (role, burst) => role === void 0 || burst === void 0 ? role : { ...role, burst };
|
|
1382
|
+
return {
|
|
1383
|
+
...base,
|
|
1384
|
+
burst: withBurst(base.burst, overrides.burst),
|
|
1385
|
+
core: base.core === void 0 ? void 0 : { ...base.core, intensity: overrides.light ?? base.core.intensity },
|
|
1386
|
+
impact: {
|
|
1387
|
+
...base.impact,
|
|
1388
|
+
shake: overrides.shake ?? base.impact.shake,
|
|
1389
|
+
splat: base.impact.splat === void 0 ? void 0 : { ...base.impact.splat, char: overrides.scorch ?? base.impact.splat.char }
|
|
1390
|
+
},
|
|
1391
|
+
linger: withBurst(base.linger, overrides.lingerBurst),
|
|
1392
|
+
radius: overrides.radius ?? base.radius,
|
|
1393
|
+
speed: overrides.speed ?? base.speed,
|
|
1394
|
+
timing: {
|
|
1395
|
+
charge: overrides.charge ?? base.timing.charge,
|
|
1396
|
+
impact: overrides.impact ?? base.timing.impact,
|
|
1397
|
+
linger: overrides.linger ?? base.timing.linger,
|
|
1398
|
+
travel: base.timing.travel
|
|
1399
|
+
},
|
|
1400
|
+
tint,
|
|
1401
|
+
trail: withBurst(base.trail, overrides.trail)
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
function createFireball(world, overrides = {}) {
|
|
1405
|
+
return createSpell(
|
|
1406
|
+
world,
|
|
1407
|
+
recipe(
|
|
1408
|
+
{
|
|
1409
|
+
burst: { burst: 26, kind: "spark", style: "spark" },
|
|
1410
|
+
core: { intensity: 1.3, radius: 0.34 },
|
|
1411
|
+
impact: {
|
|
1412
|
+
light: { intensity: 60, range: 14, seconds: 0.45 },
|
|
1413
|
+
shake: 0.11,
|
|
1414
|
+
shell: { radius: 2.6, seconds: 0.42, strength: 0.85 },
|
|
1415
|
+
splat: { char: 0.75, heat: 1, radius: 2.6 }
|
|
1416
|
+
},
|
|
1417
|
+
linger: { burst: 3, interval: 0.1, kind: "flame", style: "media" },
|
|
1418
|
+
name: "fireball",
|
|
1419
|
+
radius: 0.35,
|
|
1420
|
+
shape: "projectile",
|
|
1421
|
+
speed: 18,
|
|
1422
|
+
timing: { charge: 0.7, impact: 0.25, linger: 2.6, travel: 2.6 },
|
|
1423
|
+
tint: { colour: colour("#ff8a2a"), highlight: colour("#fff2dc") },
|
|
1424
|
+
trail: { burst: 2.4, kind: "flame", style: "media" }
|
|
1425
|
+
},
|
|
1426
|
+
overrides
|
|
1427
|
+
)
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
function createThunderstrike(world, overrides = {}) {
|
|
1431
|
+
return createSpell(
|
|
1432
|
+
world,
|
|
1433
|
+
recipe(
|
|
1434
|
+
{
|
|
1435
|
+
bolt: { height: 22, seconds: 0.8, width: 0.55 },
|
|
1436
|
+
burst: { burst: 30, kind: "spark", style: "spark" },
|
|
1437
|
+
charge: { burst: 2, kind: "mote" },
|
|
1438
|
+
impact: {
|
|
1439
|
+
light: { intensity: 120, range: 20, seconds: 0.5 },
|
|
1440
|
+
shake: 0.16,
|
|
1441
|
+
shell: { radius: 3.4, seconds: 0.36, strength: 1 },
|
|
1442
|
+
splat: { char: 0.9, glow: 0.8, heat: 0.7, pattern: "ring", radius: 3.2 }
|
|
1443
|
+
},
|
|
1444
|
+
linger: { burst: 1.6, interval: 0.16, kind: "arc", style: "glow" },
|
|
1445
|
+
name: "thunderstrike",
|
|
1446
|
+
radius: 0.2,
|
|
1447
|
+
shape: "strike",
|
|
1448
|
+
timing: { charge: 0.6, impact: 0.8, linger: 1.6, travel: 1.8 },
|
|
1449
|
+
tint: { colour: colour("#5b78ff"), highlight: colour("#d6e6ff") }
|
|
1450
|
+
},
|
|
1451
|
+
overrides
|
|
1452
|
+
)
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
function createGlacialSpike(world, overrides = {}) {
|
|
1456
|
+
return createSpell(
|
|
1457
|
+
world,
|
|
1458
|
+
recipe(
|
|
1459
|
+
{
|
|
1460
|
+
burst: { burst: 28, kind: "ice", style: "glow" },
|
|
1461
|
+
charge: { burst: 2, kind: "mote" },
|
|
1462
|
+
core: { intensity: 1.1, radius: 0.22 },
|
|
1463
|
+
impact: {
|
|
1464
|
+
light: { intensity: 40, range: 11, seconds: 0.35 },
|
|
1465
|
+
shake: 0.07,
|
|
1466
|
+
shell: { radius: 2.2, seconds: 0.38, strength: 0.7 },
|
|
1467
|
+
splat: { crack: 0.4, frost: 1, radius: 2.8 }
|
|
1468
|
+
},
|
|
1469
|
+
linger: { burst: 2, interval: 0.14, kind: "ice", style: "glow" },
|
|
1470
|
+
name: "glacial-spike",
|
|
1471
|
+
radius: 0.12,
|
|
1472
|
+
shape: "projectile",
|
|
1473
|
+
speed: 26,
|
|
1474
|
+
timing: { charge: 0.8, impact: 0.3, linger: 2.4, travel: 1.4 },
|
|
1475
|
+
tint: { colour: colour("#4f9bff"), highlight: colour("#c9f4ff") },
|
|
1476
|
+
trail: { burst: 1.8, kind: "ice", style: "glow" }
|
|
1477
|
+
},
|
|
1478
|
+
overrides
|
|
1479
|
+
)
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
function createArcaneBarrage(world, overrides = {}) {
|
|
1483
|
+
return createSpell(
|
|
1484
|
+
world,
|
|
1485
|
+
recipe(
|
|
1486
|
+
{
|
|
1487
|
+
burst: { burst: 18, kind: "spark", style: "glow" },
|
|
1488
|
+
charge: { burst: 3, kind: "mote" },
|
|
1489
|
+
core: { intensity: 1.4, radius: 0.19 },
|
|
1490
|
+
impact: {
|
|
1491
|
+
light: { intensity: 34, range: 9, seconds: 0.28 },
|
|
1492
|
+
shake: 0.05,
|
|
1493
|
+
shell: { radius: 1.6, seconds: 0.28, strength: 0.6 },
|
|
1494
|
+
splat: { glow: 0.7, heat: 0.2, radius: 1.8 }
|
|
1495
|
+
},
|
|
1496
|
+
linger: { burst: 1.4, interval: 0.12, kind: "spark", style: "glow" },
|
|
1497
|
+
name: "arcane-barrage",
|
|
1498
|
+
radius: 0.2,
|
|
1499
|
+
shape: "projectile",
|
|
1500
|
+
speed: 24,
|
|
1501
|
+
timing: { charge: 0.55, impact: 0.12, linger: 1.1, travel: 1.6 },
|
|
1502
|
+
tint: { colour: colour("#ff4fd8"), highlight: colour("#ffd8f6") },
|
|
1503
|
+
trail: { burst: 2, kind: "spark", style: "glow" }
|
|
1504
|
+
},
|
|
1505
|
+
overrides
|
|
1506
|
+
)
|
|
1507
|
+
);
|
|
1508
|
+
}
|
|
1509
|
+
function createAegis(world, overrides = {}) {
|
|
1510
|
+
return createSpell(
|
|
1511
|
+
world,
|
|
1512
|
+
recipe(
|
|
1513
|
+
{
|
|
1514
|
+
burst: { burst: 22, kind: "mote", style: "glow" },
|
|
1515
|
+
charge: { burst: 3, kind: "mote" },
|
|
1516
|
+
impact: {
|
|
1517
|
+
light: { intensity: 26, range: 8, seconds: 0.3 },
|
|
1518
|
+
shell: { hold: true, radius: 1.9, seconds: 0.6, strength: 1 },
|
|
1519
|
+
splat: { glow: 0.4, radius: 1.6 }
|
|
1520
|
+
},
|
|
1521
|
+
linger: { burst: 1.2, interval: 0.2, kind: "mote", style: "glow" },
|
|
1522
|
+
name: "aegis",
|
|
1523
|
+
radius: 0.3,
|
|
1524
|
+
shape: "self",
|
|
1525
|
+
timing: { charge: 0.45, impact: 0.15, linger: 3.4, travel: 0 },
|
|
1526
|
+
tint: { colour: colour("#ff4fd8"), highlight: colour("#c9a8ff") }
|
|
1527
|
+
},
|
|
1528
|
+
overrides
|
|
1529
|
+
)
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
function createInferno(world, overrides = {}) {
|
|
1533
|
+
return createSpell(
|
|
1534
|
+
world,
|
|
1535
|
+
recipe(
|
|
1536
|
+
{
|
|
1537
|
+
burst: { burst: 40, kind: "flame", style: "media" },
|
|
1538
|
+
charge: { burst: 4, kind: "ember" },
|
|
1539
|
+
impact: {
|
|
1540
|
+
light: { intensity: 90, range: 18, seconds: 0.9 },
|
|
1541
|
+
shake: 0.14,
|
|
1542
|
+
shell: { radius: 4.2, seconds: 0.6, strength: 0.9 },
|
|
1543
|
+
splat: { char: 1, heat: 1, radius: 4.4 }
|
|
1544
|
+
},
|
|
1545
|
+
linger: { burst: 5, interval: 0.08, kind: "flame", style: "media" },
|
|
1546
|
+
name: "inferno",
|
|
1547
|
+
radius: 0.4,
|
|
1548
|
+
shape: "area",
|
|
1549
|
+
timing: { charge: 0.9, impact: 0.3, linger: 5, travel: 0 },
|
|
1550
|
+
tint: { colour: colour("#ff5a12"), highlight: colour("#ffd9a0") },
|
|
1551
|
+
trail: { burst: 3, kind: "smoke", style: "media" }
|
|
1552
|
+
},
|
|
1553
|
+
overrides
|
|
1554
|
+
)
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
export { CastPool, ParticleKindTable, REACTION_CHANNELS, ReactionField, SpellLights, SpellWorld, createAegis, createArcaneBarrage, createFireball, createGlacialSpike, createInferno, createSpell, createThunderstrike };
|