@threenative/core 0.3.11 → 0.3.12
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/capabilities.json +1096 -26
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-CWuFRT7G.d.ts} +1 -1
- package/dist/chunk-2Z44XSI2.js +35 -0
- package/dist/chunk-5O73CDMR.js +1849 -0
- package/dist/chunk-6KLNISRJ.js +153 -0
- package/dist/chunk-7UUT3TY5.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DBELTTTM.js +615 -0
- package/dist/chunk-GMHATRPW.js +7701 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-N5LRP4BR.js +220 -0
- package/dist/chunk-OKXUCASC.js +2238 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-VAZM36TV.js +497 -0
- package/dist/{game-DzMcitDO.d.ts → game-D7pAzZUY.d.ts} +15 -3
- package/dist/hot.d.ts +3 -3
- package/dist/hot.js +2 -46
- package/dist/index.d.ts +329 -302
- package/dist/index.js +10566 -22552
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-B6BMqS1r.d.ts} +33 -3
- package/dist/playtest.d.ts +3 -3
- package/dist/playtest.js +24 -75
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-DvFVoAgj.d.ts} +13 -4
- 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 +5 -384
- package/dist/worker.js +4 -41
- package/dist/world.d.ts +725 -259
- package/dist/world.js +16714 -18284
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +142 -47
- package/mcp/servers.mjs +9 -2
- package/mcp/terrain.mjs +8 -0
- package/package.json +14 -6
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/assets.ts +9 -2
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/frame-budget.ts +31 -20
- package/src/game-dev-tools.ts +93 -0
- package/src/game-frame-loop.ts +995 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1001 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +253 -1935
- package/src/index.ts +27 -2
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +24 -0
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quality.ts +10 -5
- package/src/look/world-environment.ts +76 -9
- package/src/loop.ts +29 -0
- package/src/model-lod.ts +42 -3
- package/src/particle-kinds.ts +515 -0
- package/src/picking.ts +17 -3
- package/src/playtest.ts +27 -1
- package/src/projection-apply.ts +4 -1
- package/src/projection-plan.ts +9 -6
- package/src/render/mesh-pool.ts +1 -1
- 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.ts +213 -992
- package/src/render/world-impostor-surface.ts +293 -34
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer.ts +92 -37
- package/src/snow-field.ts +1 -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-readiness.ts +128 -34
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/world-bundle-safety.ts +401 -0
- package/src/world-cell-batches.ts +1216 -0
- package/src/world-cell-chunks.ts +1132 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1449 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +189 -0
- package/src/world-cell-placements.ts +694 -0
- package/src/world-cell-prewarm.ts +557 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +714 -0
- package/src/world-cell-render-main-cull.ts +484 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +246 -0
- package/src/world-cell-render.ts +1493 -0
- package/src/world-cell-residency.ts +745 -0
- package/src/world-cells.ts +1318 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +163 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +510 -0
- package/src/world-gpu-scene.ts +214 -2264
- package/src/world-gpu-shadow.ts +190 -0
- package/src/world-gpu-types.ts +381 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +106 -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-terrain-splat.ts +365 -149
- package/src/world-tile-budget.ts +256 -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 +170 -1745
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +35 -741
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spells: a timeline that changes the world it lands in.
|
|
3
|
+
*
|
|
4
|
+
* A spell is not an emitter. It charges, releases, travels, impacts and lingers, and each beat
|
|
5
|
+
* drives several systems at once. This subpath holds that machinery.
|
|
6
|
+
*
|
|
7
|
+
* Kept off the main entry on purpose: `@threenative/core` declares `sideEffects: false` and this is
|
|
8
|
+
* its own module, so a game that never casts a spell ships none of it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Step a spell's timeline: charge, release, travel, impact, linger, done.
|
|
13
|
+
* @situation a fireball or a lightning bolt that charges, flies, lands and lingers
|
|
14
|
+
* @situation several spells mid-flight, with no allocation per cast
|
|
15
|
+
* @constraint the pool is fixed and recycles the cast alive longest; it never grows
|
|
16
|
+
* @constraint a ball that has passed its target lands on the target, however late the frame notices
|
|
17
|
+
* @override timing, shape, speed and radius come from the spell; a cast may override shape and seed
|
|
18
|
+
* @example const casts = new CastPool(world);
|
|
19
|
+
* casts.cast(fireball, target, { from: hand });
|
|
20
|
+
* casts.update(dt);
|
|
21
|
+
*/
|
|
22
|
+
export { CastPool } from "./cast-pool.js";
|
|
23
|
+
export type {
|
|
24
|
+
CastPhase,
|
|
25
|
+
CastShape,
|
|
26
|
+
ICast,
|
|
27
|
+
ICastEnvironment,
|
|
28
|
+
ICastOptions,
|
|
29
|
+
ICastTiming,
|
|
30
|
+
ISpell,
|
|
31
|
+
} from "./cast-pool.js";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The marks a spell leaves on the floor: heat, char, wet, frost, crack and glow.
|
|
35
|
+
* @situation a fireball impact that leaves a scorch and fades over time
|
|
36
|
+
* @situation ice that melts where lightning spread, or a lava geyser's crack
|
|
37
|
+
* @constraint it draws nothing; the game decides what a mark looks like
|
|
38
|
+
* @constraint the patch is finite and every channel decays on its own half-life
|
|
39
|
+
* @override halfLife, resolution and size tune the patch; pattern, radius, seed and angle set each mark
|
|
40
|
+
* @example field.splat({ heat: 1, char: 0.6, radius: 2.5, x: hit.x, z: hit.z });
|
|
41
|
+
* field.update(dt);
|
|
42
|
+
*/
|
|
43
|
+
export { REACTION_CHANNELS, ReactionField } from "./reaction-field.js";
|
|
44
|
+
export type {
|
|
45
|
+
IReactionDirty,
|
|
46
|
+
IReactionFieldOptions,
|
|
47
|
+
IReactionSplat,
|
|
48
|
+
ReactionChannel,
|
|
49
|
+
ReactionPattern,
|
|
50
|
+
} from "./reaction-field.js";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A fixed pool of spell lights, created once at zero intensity.
|
|
54
|
+
* @situation a spell impact that glows without changing the light count
|
|
55
|
+
* @situation a charge glow or a falling meteor lighting what it passes
|
|
56
|
+
* @constraint the whole pool exists before the first cast; a cast changes intensity, never the list
|
|
57
|
+
* @constraint flash returns undefined when the pool is busy; a spell carries on without one
|
|
58
|
+
* @override count is the pool size; each flash supplies position, colour, intensity, range and seconds
|
|
59
|
+
* @example lights.flash({ x, y, z, color, intensity: 40, range: 12, seconds: 0.35 });
|
|
60
|
+
*/
|
|
61
|
+
export { SpellLights } from "./spell-lights.js";
|
|
62
|
+
export type { ISpellLightFlash, ISpellLightsOptions } from "./spell-lights.js";
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Everything a spell may touch: the scene, the floor, the light pool, the surface field, one shake
|
|
66
|
+
* and one flash limiter.
|
|
67
|
+
* @situation cast an engine spell without passing a scene into every call
|
|
68
|
+
* @situation honour an accessibility setting that limits flashing
|
|
69
|
+
* @constraint damage, mana, cooldowns and who the target is stay in the game
|
|
70
|
+
* @constraint with reducedFlashes on, a fourth flash inside one second is refused, never dimmed
|
|
71
|
+
* @override groundAt, castSlots, lightCount, reaction, shake and reducedFlashes are named options
|
|
72
|
+
* @example const world = new SpellWorld({ scene, groundAt });
|
|
73
|
+
* const casts = new CastPool(world);
|
|
74
|
+
*/
|
|
75
|
+
export { SpellWorld } from "./spell-world.js";
|
|
76
|
+
export type { ISpellWorldOptions, ISpellWorldShakeOptions } from "./spell-world.js";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A ball of fire that charges, crosses the room and leaves the floor burning.
|
|
80
|
+
* @situation a fireball spell the player casts at an enemy
|
|
81
|
+
* @situation a burning projectile that explodes and scorches the ground
|
|
82
|
+
* @situation a wizard's fire attack with a wind-up, a flight and an aftermath
|
|
83
|
+
* @situation make a fireball
|
|
84
|
+
* @constraint every colour, size, count and timing is a named override on the call
|
|
85
|
+
* @constraint the first cast costs what the hundredth does: nothing is built at cast time
|
|
86
|
+
* @override core, highlight, speed, charge, impact, linger, radius, burst, trail, lingerBurst, light, shake, scorch
|
|
87
|
+
* @example const fireball = createFireball(world);
|
|
88
|
+
* casts.cast(fireball, target);
|
|
89
|
+
*/
|
|
90
|
+
export { createFireball, type IFireSpellOverrides } from "./spells.js";
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A bolt out of the sky: it charges, strikes the point instantly, and the ground remembers it.
|
|
94
|
+
* @situation a lightning strike spell that hits a point immediately
|
|
95
|
+
* @situation a thunderbolt with a wind-up and a burnt mark where it lands
|
|
96
|
+
* @situation make a lightning spell
|
|
97
|
+
* @constraint every colour, size, count and timing is a named override on the call
|
|
98
|
+
* @override core, highlight, charge, impact, linger, radius, light, shake, scorch
|
|
99
|
+
* @example const bolt = createThunderstrike(world);
|
|
100
|
+
* casts.cast(bolt, target);
|
|
101
|
+
*/
|
|
102
|
+
export { createThunderstrike } from "./spells.js";
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A shard of ice that flies flat and fast, and freezes the ground it breaks on.
|
|
106
|
+
* @situation an ice spike spell that flies at a target and shatters
|
|
107
|
+
* @situation a freezing projectile that leaves frost on the floor
|
|
108
|
+
* @situation make an ice spell
|
|
109
|
+
* @constraint every colour, size, count and timing is a named override on the call
|
|
110
|
+
* @override core, highlight, speed, charge, impact, linger, radius, burst, trail, light
|
|
111
|
+
* @example const spike = createGlacialSpike(world);
|
|
112
|
+
* casts.cast(spike, target);
|
|
113
|
+
*/
|
|
114
|
+
export { createGlacialSpike } from "./spells.js";
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A volley of arcane missiles: fast, precise, and each one pops on arrival.
|
|
118
|
+
* @situation an arcane missile spell that fires projectiles at a target
|
|
119
|
+
* @situation a magic barrage a mage class spams
|
|
120
|
+
* @situation a magic missile spell
|
|
121
|
+
* @situation make an arcane bolt spell
|
|
122
|
+
* @constraint every colour, size, count and timing is a named override on the call
|
|
123
|
+
* @override core, highlight, speed, charge, impact, linger, radius, burst, light
|
|
124
|
+
* @example const barrage = createArcaneBarrage(world);
|
|
125
|
+
* casts.cast(barrage, target);
|
|
126
|
+
*/
|
|
127
|
+
export { createArcaneBarrage } from "./spells.js";
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* A ward around the caster: it forms, holds, and breaks outward when it expires.
|
|
131
|
+
* @situation a shield spell a player casts on themselves
|
|
132
|
+
* @situation a magic barrier that forms around the caster
|
|
133
|
+
* @situation make a protective bubble spell
|
|
134
|
+
* @constraint every colour, size, count and timing is a named override on the call
|
|
135
|
+
* @override core, highlight, charge, impact, linger, radius, light
|
|
136
|
+
* @example const aegis = createAegis(world);
|
|
137
|
+
* casts.cast(aegis, world.focus);
|
|
138
|
+
*/
|
|
139
|
+
export { createAegis } from "./spells.js";
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A pillar of fire that erupts where it lands and keeps burning.
|
|
143
|
+
* @situation a fire area spell that erupts at a point and burns there
|
|
144
|
+
* @situation an inferno column a boss drops on the arena
|
|
145
|
+
* @situation make a sustained fire area spell
|
|
146
|
+
* @constraint every colour, size, count and timing is a named override on the call
|
|
147
|
+
* @override core, highlight, charge, impact, linger, radius, burst, trail, light, shake, scorch
|
|
148
|
+
* @example const inferno = createInferno(world);
|
|
149
|
+
* casts.cast(inferno, target);
|
|
150
|
+
*/
|
|
151
|
+
export { createInferno } from "./spells.js";
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Build a spell from a recipe: four beats, a tint, and the numbers between them.
|
|
155
|
+
* @situation author a spell the catalog does not cover, out of the same beats
|
|
156
|
+
* @constraint read the world through SpellWorld only, so a game can swap the scene and the floor
|
|
157
|
+
* @example const spell = createSpell(world, recipe);
|
|
158
|
+
*/
|
|
159
|
+
export {
|
|
160
|
+
createSpell,
|
|
161
|
+
type ISpellEmitter,
|
|
162
|
+
type ISpellImpact,
|
|
163
|
+
type ISpellRecipe,
|
|
164
|
+
type ISpellTint,
|
|
165
|
+
} from "./spell.js";
|
|
166
|
+
/**
|
|
167
|
+
* Tune what a particle kind does, as data rather than a shader.
|
|
168
|
+
* @situation retune a spell's particles at run time from a settings screen
|
|
169
|
+
* @situation change how long, how fast or how heavy a kind of particle is without a new pipeline
|
|
170
|
+
* @constraint set writes uniforms; no kernel, material or pipeline is rebuilt
|
|
171
|
+
* @constraint a table knows only the kinds it was asked for, so an unused kind costs nothing
|
|
172
|
+
* @override lifetime, size, speed, cone, gravity, drag, buoyancy, alpha, colour and highlight
|
|
173
|
+
* @example const kinds = new ParticleKindTable(["flame", "smoke"]);
|
|
174
|
+
* kinds.set("flame", { lifetime: [0.3, 0.6], colour: [0.4, 0.8, 1] });
|
|
175
|
+
*/
|
|
176
|
+
export { type IParticleKindValues, ParticleKindTable } from "../particle-kinds.js";
|
|
177
|
+
export type { ParticleKindName } from "../particle-kinds.js";
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four things a spell draws besides particles.
|
|
3
|
+
*
|
|
4
|
+
* Each is pooled and reused: a spell allocates its drawables once at `create`, and a cast only
|
|
5
|
+
* moves uniforms and a transform. Nothing here is added to the scene at cast time, because an
|
|
6
|
+
* object added mid-frame changes the frame's draw list and, in Three.js, can cost a program.
|
|
7
|
+
*
|
|
8
|
+
* All shader code is TSL. There is no GLSL string in this package.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
abs,
|
|
13
|
+
float,
|
|
14
|
+
length,
|
|
15
|
+
mix,
|
|
16
|
+
oneMinus,
|
|
17
|
+
pow,
|
|
18
|
+
smoothstep,
|
|
19
|
+
uniform,
|
|
20
|
+
uv,
|
|
21
|
+
vec2,
|
|
22
|
+
vec3,
|
|
23
|
+
vec4,
|
|
24
|
+
} from "three/tsl";
|
|
25
|
+
import {
|
|
26
|
+
Color,
|
|
27
|
+
DoubleSide,
|
|
28
|
+
Mesh,
|
|
29
|
+
MeshBasicNodeMaterial,
|
|
30
|
+
type Object3D,
|
|
31
|
+
PlaneGeometry,
|
|
32
|
+
SphereGeometry,
|
|
33
|
+
Sprite,
|
|
34
|
+
SpriteNodeMaterial,
|
|
35
|
+
Vector3,
|
|
36
|
+
} from "three/webgpu";
|
|
37
|
+
|
|
38
|
+
const TAU = Math.PI * 2;
|
|
39
|
+
|
|
40
|
+
const finite = (label: string, value: number): number => {
|
|
41
|
+
if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite`);
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** A hot, soft ball: the thing the player is actually aiming. */
|
|
46
|
+
export class SpellCore {
|
|
47
|
+
readonly sprite = new Sprite();
|
|
48
|
+
readonly #colour = uniform(new Color(1, 0.72, 0.34));
|
|
49
|
+
readonly #highlight = uniform(new Color(1, 0.95, 0.72));
|
|
50
|
+
readonly #radius = uniform(0.35);
|
|
51
|
+
readonly #intensity = uniform(1);
|
|
52
|
+
readonly #material: SpriteNodeMaterial;
|
|
53
|
+
|
|
54
|
+
constructor(parent: Object3D) {
|
|
55
|
+
this.#material = new SpriteNodeMaterial({
|
|
56
|
+
depthWrite: false,
|
|
57
|
+
toneMapped: false,
|
|
58
|
+
transparent: true,
|
|
59
|
+
});
|
|
60
|
+
const point = uv().sub(0.5);
|
|
61
|
+
const radius = length(point);
|
|
62
|
+
// A flat core inside a hot rim: the eye reads a sphere, not a disc.
|
|
63
|
+
const core = float(1).sub(smoothstep(0.04, 0.44, radius));
|
|
64
|
+
const rim = pow(oneMinus(smoothstep(0.3, 0.5, radius)), 2.5);
|
|
65
|
+
this.#material.colorNode = vec4(
|
|
66
|
+
mix(this.#colour, this.#highlight, core.mul(0.85).add(0.15)),
|
|
67
|
+
core.add(rim.mul(0.55)).mul(this.#intensity),
|
|
68
|
+
);
|
|
69
|
+
this.#material.scaleNode = vec2(this.#radius, this.#radius).mul(2.6);
|
|
70
|
+
this.sprite.material = this.#material;
|
|
71
|
+
this.sprite.frustumCulled = false;
|
|
72
|
+
this.sprite.visible = false;
|
|
73
|
+
parent.add(this.sprite);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Metres across, the tint, and how hard it burns. */
|
|
77
|
+
show(
|
|
78
|
+
position: Vector3,
|
|
79
|
+
radius: number,
|
|
80
|
+
colour: Color,
|
|
81
|
+
highlight: Color,
|
|
82
|
+
intensity: number,
|
|
83
|
+
): void {
|
|
84
|
+
this.sprite.position.copy(position);
|
|
85
|
+
this.#radius.value = Math.max(0.001, finite("core.radius", radius));
|
|
86
|
+
this.#colour.value.copy(colour);
|
|
87
|
+
this.#highlight.value.copy(highlight);
|
|
88
|
+
this.#intensity.value = Math.max(0, finite("core.intensity", intensity));
|
|
89
|
+
this.sprite.visible = true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
hide(): void {
|
|
93
|
+
this.sprite.visible = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** An expanding shell: the pressure wave of an impact, and the edge of a shield. */
|
|
98
|
+
export class ShockShell {
|
|
99
|
+
readonly mesh: Mesh;
|
|
100
|
+
readonly #colour = uniform(new Color(1, 0.7, 0.3));
|
|
101
|
+
readonly #progress = uniform(0);
|
|
102
|
+
readonly #strength = uniform(0);
|
|
103
|
+
readonly #material: MeshBasicNodeMaterial;
|
|
104
|
+
|
|
105
|
+
constructor(parent: Object3D) {
|
|
106
|
+
this.#material = new MeshBasicNodeMaterial({
|
|
107
|
+
depthWrite: false,
|
|
108
|
+
side: DoubleSide,
|
|
109
|
+
toneMapped: false,
|
|
110
|
+
transparent: true,
|
|
111
|
+
});
|
|
112
|
+
// Rim-bright: the silhouette carries the wave, the middle stays clear.
|
|
113
|
+
const rim = pow(oneMinus(abs(uv().sub(0.5).length().mul(2).sub(1))), 3);
|
|
114
|
+
this.#material.colorNode = vec4(this.#colour, rim.mul(this.#strength));
|
|
115
|
+
this.mesh = new Mesh(new SphereGeometry(1, 24, 16), this.#material);
|
|
116
|
+
this.mesh.frustumCulled = false;
|
|
117
|
+
this.mesh.visible = false;
|
|
118
|
+
parent.add(this.mesh);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** `progress` 0..1 drives both the radius and the fade, so a shell cannot outlive its impact. */
|
|
122
|
+
show(
|
|
123
|
+
centre: Vector3,
|
|
124
|
+
progress: number,
|
|
125
|
+
radius: number,
|
|
126
|
+
colour: Color,
|
|
127
|
+
strength: number,
|
|
128
|
+
fade = 1 - Math.min(1, Math.max(0, progress)),
|
|
129
|
+
): void {
|
|
130
|
+
this.mesh.position.copy(centre);
|
|
131
|
+
this.#progress.value = Math.min(1, Math.max(0, progress));
|
|
132
|
+
// A wave at progress 0 is a point; keep a floor so the first frame is not an empty sphere.
|
|
133
|
+
const scale =
|
|
134
|
+
Math.max(0.001, finite("shell.radius", radius)) * Math.max(0.02, this.#progress.value);
|
|
135
|
+
this.mesh.scale.setScalar(scale);
|
|
136
|
+
this.#colour.value.copy(colour);
|
|
137
|
+
this.#strength.value = Math.max(0, finite("shell.strength", strength)) * Math.max(0, fade);
|
|
138
|
+
this.mesh.visible = this.#strength.value > 0.001;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
hide(): void {
|
|
142
|
+
this.mesh.visible = false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** A crackling column from the sky to a point, or from a hand to a point. */
|
|
147
|
+
export class BoltColumn {
|
|
148
|
+
readonly mesh: Mesh;
|
|
149
|
+
readonly #colour = uniform(new Color(0.85, 0.93, 1));
|
|
150
|
+
readonly #core = uniform(new Color(1, 1, 1));
|
|
151
|
+
readonly #strength = uniform(0);
|
|
152
|
+
readonly #seed = uniform(0);
|
|
153
|
+
readonly #material: MeshBasicNodeMaterial;
|
|
154
|
+
readonly #up = new Vector3(0, 1, 0);
|
|
155
|
+
|
|
156
|
+
constructor(parent: Object3D, segments = 28) {
|
|
157
|
+
this.#material = new MeshBasicNodeMaterial({
|
|
158
|
+
depthWrite: false,
|
|
159
|
+
side: DoubleSide,
|
|
160
|
+
toneMapped: false,
|
|
161
|
+
transparent: true,
|
|
162
|
+
});
|
|
163
|
+
// The jitter is evaluated per vertex from a hash of the segment and the seed, so a bolt's shape
|
|
164
|
+
// is a number the spell can hold still or re-roll without rebuilding the geometry.
|
|
165
|
+
const across = uv().x.sub(0.5);
|
|
166
|
+
const along = uv().y;
|
|
167
|
+
const jag = along
|
|
168
|
+
.mul(41.7)
|
|
169
|
+
.add(this.#seed)
|
|
170
|
+
.fract()
|
|
171
|
+
.sub(0.5)
|
|
172
|
+
.mul(0.055)
|
|
173
|
+
.add(along.mul(97.3).add(this.#seed.mul(1.7)).fract().sub(0.5).mul(0.022));
|
|
174
|
+
const coreWidth = float(0.16).mul(oneMinus(smoothstep(0.0, 0.5, across.abs().mul(2))));
|
|
175
|
+
const glowWidth = oneMinus(smoothstep(0.0, 0.5, across.abs().mul(2).sub(coreWidth)));
|
|
176
|
+
this.#material.colorNode = vec4(
|
|
177
|
+
mix(this.#colour, this.#core, coreWidth),
|
|
178
|
+
glowWidth.mul(this.#strength).mul(oneMinus(along.mul(0.25))),
|
|
179
|
+
);
|
|
180
|
+
this.#material.positionNode = vec3(across.add(jag), along, 0);
|
|
181
|
+
this.mesh = new Mesh(new PlaneGeometry(1, 1, 1, segments), this.#material);
|
|
182
|
+
this.mesh.frustumCulled = false;
|
|
183
|
+
this.mesh.visible = false;
|
|
184
|
+
parent.add(this.mesh);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Stretch the ribbon from `from` to `to`, facing the camera enough to read from any angle. */
|
|
188
|
+
show(
|
|
189
|
+
from: Vector3,
|
|
190
|
+
to: Vector3,
|
|
191
|
+
width: number,
|
|
192
|
+
colour: Color,
|
|
193
|
+
core: Color,
|
|
194
|
+
strength: number,
|
|
195
|
+
seed: number,
|
|
196
|
+
camera?: { position: Vector3 },
|
|
197
|
+
): void {
|
|
198
|
+
const direction = new Vector3().subVectors(to, from);
|
|
199
|
+
const span = direction.length();
|
|
200
|
+
if (!(span > 1e-4)) {
|
|
201
|
+
this.hide();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
this.mesh.position.copy(from).addScaledVector(direction, 0.5);
|
|
205
|
+
const axis = direction.clone().normalize();
|
|
206
|
+
this.mesh.quaternion.setFromUnitVectors(this.#up, axis);
|
|
207
|
+
// A flat column disappears edge-on, so the ribbon twists about its own axis to face the camera.
|
|
208
|
+
if (camera !== undefined) {
|
|
209
|
+
const toCamera = new Vector3().subVectors(camera.position, this.mesh.position);
|
|
210
|
+
toCamera.addScaledVector(axis, -toCamera.dot(axis));
|
|
211
|
+
if (toCamera.lengthSq() > 1e-6) {
|
|
212
|
+
const basis = new Vector3(1, 0, 0).applyQuaternion(this.mesh.quaternion);
|
|
213
|
+
this.mesh.rotateY(
|
|
214
|
+
Math.atan2(new Vector3().crossVectors(basis, toCamera).dot(axis), basis.dot(toCamera)),
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
this.mesh.scale.set(Math.max(0.01, finite("bolt.width", width)), span, 1);
|
|
219
|
+
this.#colour.value.copy(colour);
|
|
220
|
+
this.#core.value.copy(core);
|
|
221
|
+
this.#strength.value = Math.max(0, finite("bolt.strength", strength));
|
|
222
|
+
this.#seed.value = seed % 1;
|
|
223
|
+
this.mesh.visible = this.#strength.value > 0.001;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
hide(): void {
|
|
227
|
+
this.mesh.visible = false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** A shield: a bubble whose rim brightens as it takes a hit. */
|
|
232
|
+
export class ShieldBubble {
|
|
233
|
+
readonly mesh: Mesh;
|
|
234
|
+
readonly #colour = uniform(new Color(1, 0.4, 0.9));
|
|
235
|
+
readonly #strength = uniform(0);
|
|
236
|
+
readonly #pulse = uniform(0);
|
|
237
|
+
readonly #material: MeshBasicNodeMaterial;
|
|
238
|
+
|
|
239
|
+
constructor(parent: Object3D) {
|
|
240
|
+
this.#material = new MeshBasicNodeMaterial({
|
|
241
|
+
depthWrite: false,
|
|
242
|
+
side: DoubleSide,
|
|
243
|
+
toneMapped: false,
|
|
244
|
+
transparent: true,
|
|
245
|
+
});
|
|
246
|
+
// A six-fold cell pattern on the sphere reads as a faceted ward, not a soap bubble.
|
|
247
|
+
const cells = uv().mul(TAU * 6);
|
|
248
|
+
const facet = abs(cells.x.sin().mul(cells.y.sin())).mul(0.5).add(0.5);
|
|
249
|
+
const rim = pow(oneMinus(abs(uv().x.mul(2).sub(1)).mul(0.6)), 1.6);
|
|
250
|
+
this.#material.colorNode = vec4(
|
|
251
|
+
this.#colour,
|
|
252
|
+
facet.mul(0.85).add(rim.mul(0.9)).mul(this.#strength).mul(this.#pulse.add(0.75)),
|
|
253
|
+
);
|
|
254
|
+
this.mesh = new Mesh(new SphereGeometry(1, 32, 24), this.#material);
|
|
255
|
+
this.mesh.frustumCulled = false;
|
|
256
|
+
this.mesh.visible = false;
|
|
257
|
+
parent.add(this.mesh);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
show(centre: Vector3, radius: number, colour: Color, strength: number, pulse: number): void {
|
|
261
|
+
this.mesh.position.copy(centre);
|
|
262
|
+
this.mesh.scale.setScalar(Math.max(0.001, finite("shield.radius", radius)));
|
|
263
|
+
this.#colour.value.copy(colour);
|
|
264
|
+
this.#strength.value = Math.max(0, finite("shield.strength", strength));
|
|
265
|
+
this.#pulse.value = Math.min(1, Math.max(0, pulse));
|
|
266
|
+
this.mesh.visible = this.#strength.value > 0.001;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
hide(): void {
|
|
270
|
+
this.mesh.visible = false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** The pool of drawables one spell owns. */
|
|
275
|
+
export interface ISpellDrawables {
|
|
276
|
+
readonly core: SpellCore;
|
|
277
|
+
readonly shell: ShockShell;
|
|
278
|
+
readonly bolt: BoltColumn;
|
|
279
|
+
readonly shield: ShieldBubble;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Build a spell's drawables and add them to the world's scene.
|
|
284
|
+
*
|
|
285
|
+
* A spell builds these at `create`; a cast only shows and hides them. That is the whole reason the
|
|
286
|
+
* first cast of a spell is not slower than its hundredth.
|
|
287
|
+
*/
|
|
288
|
+
export function createDrawables(parent: Object3D): ISpellDrawables {
|
|
289
|
+
return {
|
|
290
|
+
bolt: new BoltColumn(parent),
|
|
291
|
+
core: new SpellCore(parent),
|
|
292
|
+
shell: new ShockShell(parent),
|
|
293
|
+
shield: new ShieldBubble(parent),
|
|
294
|
+
};
|
|
295
|
+
}
|