@adatechnology/game-vfx 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/index.d.ts +342 -1
- package/dist/index.global.js +680 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +680 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -48,6 +48,11 @@ var GameVfx = (() => {
|
|
|
48
48
|
SpriteKindSystem: () => SpriteKindSystem,
|
|
49
49
|
VFX_LAYERS: () => VFX_LAYERS,
|
|
50
50
|
VIEWMODEL_EFFECTS: () => VIEWMODEL_EFFECTS,
|
|
51
|
+
WATER_BLASTS: () => WATER_BLASTS,
|
|
52
|
+
WATER_BLAST_KINDS: () => WATER_BLAST_KINDS,
|
|
53
|
+
WATER_LIMITS: () => WATER_LIMITS,
|
|
54
|
+
WATER_SHOT_BY_CALIBER: () => WATER_SHOT_BY_CALIBER,
|
|
55
|
+
WATER_SHOT_PROFILES: () => WATER_SHOT_PROFILES,
|
|
51
56
|
WORKSHOP_BEHAVIORS: () => WORKSHOP_BEHAVIORS,
|
|
52
57
|
WORKSHOP_EFFECTS: () => WORKSHOP_EFFECTS,
|
|
53
58
|
WORKSHOP_PUDDLES: () => WORKSHOP_PUDDLES,
|
|
@@ -60,6 +65,7 @@ var GameVfx = (() => {
|
|
|
60
65
|
createSchedule: () => createSchedule,
|
|
61
66
|
createScreenState: () => createScreenState,
|
|
62
67
|
createVfx: () => createVfx,
|
|
68
|
+
createWaterEffects: () => createWaterEffects,
|
|
63
69
|
createWorkshopBehaviors: () => createWorkshopBehaviors,
|
|
64
70
|
effectForEvent: () => effectForEvent,
|
|
65
71
|
estimateCost: () => estimateCost,
|
|
@@ -73,10 +79,16 @@ var GameVfx = (() => {
|
|
|
73
79
|
patchEffects: () => patchEffects,
|
|
74
80
|
patchExplosions: () => patchExplosions,
|
|
75
81
|
patchSpriteKinds: () => patchSpriteKinds,
|
|
82
|
+
patchWaterShotProfiles: () => patchWaterShotProfiles,
|
|
83
|
+
planWaterBlast: () => planWaterBlast,
|
|
84
|
+
planWaterShot: () => planWaterShot,
|
|
76
85
|
resolveStrings: () => resolveStrings,
|
|
86
|
+
resolveWaterBlast: () => resolveWaterBlast,
|
|
87
|
+
resolveWaterShotProfile: () => resolveWaterShotProfile,
|
|
77
88
|
slideAlong: () => slideAlong,
|
|
78
89
|
streamFor: () => streamFor,
|
|
79
90
|
updateScreen: () => updateScreen,
|
|
91
|
+
waterShotClassOf: () => waterShotClassOf,
|
|
80
92
|
workshopGround: () => workshopGround
|
|
81
93
|
});
|
|
82
94
|
|
|
@@ -9036,6 +9048,674 @@ var GameVfx = (() => {
|
|
|
9036
9048
|
reset
|
|
9037
9049
|
};
|
|
9038
9050
|
}
|
|
9051
|
+
|
|
9052
|
+
// src/water/motion.ts
|
|
9053
|
+
var WATER_GRAVITY = 9.81;
|
|
9054
|
+
var DROP_DRAG = 0.25;
|
|
9055
|
+
var MIST_DRAG = 1.2;
|
|
9056
|
+
function moveDrop(drop, context) {
|
|
9057
|
+
const { dt } = context;
|
|
9058
|
+
drop.age += dt;
|
|
9059
|
+
const keep = Math.exp(-DROP_DRAG * dt);
|
|
9060
|
+
drop.vx *= keep;
|
|
9061
|
+
drop.vz *= keep;
|
|
9062
|
+
drop.vy = drop.vy * keep - WATER_GRAVITY * dt;
|
|
9063
|
+
drop.x += drop.vx * dt;
|
|
9064
|
+
drop.y += drop.vy * dt;
|
|
9065
|
+
drop.z += drop.vz * dt;
|
|
9066
|
+
if (drop.vy < 0 && drop.y <= drop.level) {
|
|
9067
|
+
context.landed(drop);
|
|
9068
|
+
return false;
|
|
9069
|
+
}
|
|
9070
|
+
return drop.age < drop.life;
|
|
9071
|
+
}
|
|
9072
|
+
function ageRing(ring2, dt) {
|
|
9073
|
+
if (ring2.delay > 0) {
|
|
9074
|
+
ring2.delay -= dt;
|
|
9075
|
+
ring2.alpha = 0;
|
|
9076
|
+
return true;
|
|
9077
|
+
}
|
|
9078
|
+
ring2.age += dt;
|
|
9079
|
+
const t = Math.min(1, ring2.age / ring2.life);
|
|
9080
|
+
const spread = ring2.kind === 2 ? t : ring2.kind === 1 ? 1 - (1 - t) ** 4 : 1 - (1 - t) ** 2;
|
|
9081
|
+
ring2.radius = ring2.startRadius + (ring2.maxRadius - ring2.startRadius) * spread;
|
|
9082
|
+
ring2.alpha = ring2.strength * (1 - t) * (ring2.kind === 1 ? 1 - t : 1);
|
|
9083
|
+
return ring2.age < ring2.life;
|
|
9084
|
+
}
|
|
9085
|
+
function ageFoam(foam, dt) {
|
|
9086
|
+
foam.age += dt;
|
|
9087
|
+
const t = Math.min(1, foam.age / foam.life);
|
|
9088
|
+
foam.radius = foam.startRadius + (foam.maxRadius - foam.startRadius) * (1 - (1 - t) ** 3);
|
|
9089
|
+
foam.alpha = t < 0.5 ? 0.85 : 0.85 * (1 - (t - 0.5) / 0.5);
|
|
9090
|
+
return foam.age < foam.life;
|
|
9091
|
+
}
|
|
9092
|
+
function ageColumn(column, dt) {
|
|
9093
|
+
if (column.delay > 0) {
|
|
9094
|
+
column.delay -= dt;
|
|
9095
|
+
column.height = 0;
|
|
9096
|
+
column.alpha = 0;
|
|
9097
|
+
return true;
|
|
9098
|
+
}
|
|
9099
|
+
column.age += dt;
|
|
9100
|
+
const t = column.age;
|
|
9101
|
+
const fall = Math.max(1e-3, column.life - column.rise);
|
|
9102
|
+
column.height = t < column.rise ? column.peak * (1 - (1 - t / column.rise) ** 2) : column.peak * Math.max(0, 1 - ((t - column.rise) / fall) ** 1.6);
|
|
9103
|
+
column.radius = column.baseRadius * (1 + (column.dome ? 0.4 : 1.2) * Math.min(1, t / column.life));
|
|
9104
|
+
const share = t / column.life;
|
|
9105
|
+
column.alpha = share < 0.6 ? 0.9 : 0.9 * Math.max(0, 1 - (share - 0.6) / 0.4);
|
|
9106
|
+
return t < column.life;
|
|
9107
|
+
}
|
|
9108
|
+
function ageBubble(bubble, dt) {
|
|
9109
|
+
if (bubble.delay > 0) {
|
|
9110
|
+
bubble.delay -= dt;
|
|
9111
|
+
bubble.alpha = 0;
|
|
9112
|
+
return true;
|
|
9113
|
+
}
|
|
9114
|
+
bubble.age += dt;
|
|
9115
|
+
bubble.y += bubble.rise * dt;
|
|
9116
|
+
bubble.size *= 1 + 0.15 * dt;
|
|
9117
|
+
bubble.alpha = 0.7 * (1 - bubble.age / bubble.life);
|
|
9118
|
+
return bubble.age < bubble.life && bubble.y < bubble.level - bubble.size;
|
|
9119
|
+
}
|
|
9120
|
+
function ageMist(mist, dt) {
|
|
9121
|
+
mist.age += dt;
|
|
9122
|
+
const keep = Math.exp(-MIST_DRAG * dt);
|
|
9123
|
+
mist.vx *= keep;
|
|
9124
|
+
mist.vy = mist.vy * keep - 0.15 * dt;
|
|
9125
|
+
mist.vz *= keep;
|
|
9126
|
+
mist.x += mist.vx * dt;
|
|
9127
|
+
mist.y += mist.vy * dt;
|
|
9128
|
+
mist.z += mist.vz * dt;
|
|
9129
|
+
mist.size *= 1 + 0.35 * dt;
|
|
9130
|
+
const t = mist.age / mist.life;
|
|
9131
|
+
mist.alpha = t < 0.15 ? t / 0.15 * 0.45 : 0.45 * (1 - (t - 0.15) / 0.85);
|
|
9132
|
+
return mist.age < mist.life;
|
|
9133
|
+
}
|
|
9134
|
+
function ageWave(wave, dt) {
|
|
9135
|
+
if (wave.delay > 0) {
|
|
9136
|
+
wave.delay -= dt;
|
|
9137
|
+
return true;
|
|
9138
|
+
}
|
|
9139
|
+
wave.age += dt;
|
|
9140
|
+
return wave.age < wave.life && wave.speed * wave.age < wave.reach + wave.width;
|
|
9141
|
+
}
|
|
9142
|
+
function stepWaterPools(pools, context) {
|
|
9143
|
+
const { dt } = context;
|
|
9144
|
+
pools.drops.compact(moveDrop, context);
|
|
9145
|
+
pools.rings.compact(ageRing, dt);
|
|
9146
|
+
pools.foam.compact(ageFoam, dt);
|
|
9147
|
+
pools.columns.compact(ageColumn, dt);
|
|
9148
|
+
pools.bubbles.compact(ageBubble, dt);
|
|
9149
|
+
pools.mist.compact(ageMist, dt);
|
|
9150
|
+
pools.waves.compact(ageWave, dt);
|
|
9151
|
+
}
|
|
9152
|
+
|
|
9153
|
+
// src/water/profiles.ts
|
|
9154
|
+
var WATER_SHOT_PROFILES = {
|
|
9155
|
+
rimfire: { speed: 350, columnHeight: 0.25, columnRadius: 0.02, drops: 8, dropSpeed: [0.9, 1.8], dropSize: 9e-3, ringRadius: 0.32, rings: 1, ringLife: 1.2, foamRadius: 0.06, foamLife: 0.7, slowing: 0.35, bubblesPerMetre: 20, ricochetBelowDeg: 9 },
|
|
9156
|
+
pistol: { speed: 360, columnHeight: 0.45, columnRadius: 0.035, drops: 14, dropSpeed: [1.2, 2.6], dropSize: 0.012, ringRadius: 0.45, rings: 2, ringLife: 1.4, foamRadius: 0.09, foamLife: 0.9, slowing: 0.55, bubblesPerMetre: 30, ricochetBelowDeg: 8 },
|
|
9157
|
+
magnum: { speed: 450, columnHeight: 0.7, columnRadius: 0.045, drops: 20, dropSpeed: [1.5, 3.2], dropSize: 0.014, ringRadius: 0.6, rings: 2, ringLife: 1.6, foamRadius: 0.12, foamLife: 1.1, slowing: 0.7, bubblesPerMetre: 30, ricochetBelowDeg: 7 },
|
|
9158
|
+
rifle: { speed: 800, columnHeight: 1.1, columnRadius: 0.03, drops: 26, dropSpeed: [2.5, 4.5], dropSize: 0.011, ringRadius: 0.7, rings: 3, ringLife: 1.6, foamRadius: 0.11, foamLife: 1, slowing: 0.35, bubblesPerMetre: 45, ricochetBelowDeg: 6 },
|
|
9159
|
+
battle_rifle: { speed: 850, columnHeight: 1.4, columnRadius: 0.035, drops: 30, dropSpeed: [2.8, 5], dropSize: 0.012, ringRadius: 0.85, rings: 3, ringLife: 1.8, foamRadius: 0.13, foamLife: 1.1, slowing: 0.45, bubblesPerMetre: 45, ricochetBelowDeg: 6 },
|
|
9160
|
+
sniper: { speed: 900, columnHeight: 2.2, columnRadius: 0.06, drops: 48, dropSpeed: [3.5, 6.5], dropSize: 0.016, ringRadius: 1.4, rings: 4, ringLife: 2.2, foamRadius: 0.22, foamLife: 1.6, slowing: 0.9, bubblesPerMetre: 50, ricochetBelowDeg: 5 },
|
|
9161
|
+
buckshot: { speed: 400, columnHeight: 0.28, columnRadius: 0.025, drops: 7, dropSpeed: [1, 2], dropSize: 0.01, ringRadius: 0.3, rings: 1, ringLife: 1.1, foamRadius: 0.13, foamLife: 1.3, slowing: 0.3, bubblesPerMetre: 25, ricochetBelowDeg: 9 },
|
|
9162
|
+
birdshot: { speed: 400, columnHeight: 0.1, columnRadius: 0.012, drops: 2, dropSpeed: [0.6, 1.2], dropSize: 6e-3, ringRadius: 0.14, rings: 1, ringLife: 0.8, foamRadius: 0.06, foamLife: 0.9, slowing: 0.08, bubblesPerMetre: 10, ricochetBelowDeg: 10 },
|
|
9163
|
+
slug: { speed: 460, columnHeight: 0.8, columnRadius: 0.07, drops: 24, dropSpeed: [1.6, 3], dropSize: 0.016, ringRadius: 0.75, rings: 2, ringLife: 1.7, foamRadius: 0.18, foamLife: 1.3, slowing: 0.8, bubblesPerMetre: 35, ricochetBelowDeg: 8 },
|
|
9164
|
+
arrow: { speed: 100, columnHeight: 0.18, columnRadius: 0.02, drops: 5, dropSpeed: [0.6, 1.2], dropSize: 0.01, ringRadius: 0.3, rings: 1, ringLife: 1.2, foamRadius: 0.05, foamLife: 0.6, slowing: 2.5, bubblesPerMetre: 6, ricochetBelowDeg: 4 },
|
|
9165
|
+
// a thrown thing the size of a grenade or a can falling in: a plop, a crown and wide rings, and it sinks
|
|
9166
|
+
object: { speed: 12, columnHeight: 0.5, columnRadius: 0.07, drops: 18, dropSpeed: [1, 2.4], dropSize: 0.015, ringRadius: 0.9, rings: 3, ringLife: 2, foamRadius: 0.14, foamLife: 1.2, slowing: 0.5, bubblesPerMetre: 25, ricochetBelowDeg: 3 },
|
|
9167
|
+
fragment: { speed: 600, columnHeight: 0.35, columnRadius: 0.02, drops: 6, dropSpeed: [1, 2.4], dropSize: 0.01, ringRadius: 0.3, rings: 1, ringLife: 1, foamRadius: 0.05, foamLife: 0.6, slowing: 0.15, bubblesPerMetre: 15, ricochetBelowDeg: 7 }
|
|
9168
|
+
};
|
|
9169
|
+
var WATER_SHOT_BY_CALIBER = {
|
|
9170
|
+
"22lr": "rimfire",
|
|
9171
|
+
"380acp": "pistol",
|
|
9172
|
+
"9x18": "pistol",
|
|
9173
|
+
"9x19": "pistol",
|
|
9174
|
+
"40sw": "pistol",
|
|
9175
|
+
"45acp": "pistol",
|
|
9176
|
+
"5_7x28": "pistol",
|
|
9177
|
+
"38spl": "pistol",
|
|
9178
|
+
"32acp": "pistol",
|
|
9179
|
+
"7_62x25": "pistol",
|
|
9180
|
+
"4_6x30": "pistol",
|
|
9181
|
+
"357mag": "magnum",
|
|
9182
|
+
"44mag": "magnum",
|
|
9183
|
+
"50ae": "magnum",
|
|
9184
|
+
"45_70_bp": "magnum",
|
|
9185
|
+
"12ga_00buck": "buckshot",
|
|
9186
|
+
"20ga_buck": "buckshot",
|
|
9187
|
+
"12ga_birdshot": "birdshot",
|
|
9188
|
+
"12ga_slug": "slug",
|
|
9189
|
+
"5_56x45": "rifle",
|
|
9190
|
+
"5_45x39": "rifle",
|
|
9191
|
+
"7_62x39": "rifle",
|
|
9192
|
+
"30_30": "rifle",
|
|
9193
|
+
"9x39": "rifle",
|
|
9194
|
+
"7_62x51": "battle_rifle",
|
|
9195
|
+
"7_62x54r": "battle_rifle",
|
|
9196
|
+
"30_06": "battle_rifle",
|
|
9197
|
+
"7_92x57": "battle_rifle",
|
|
9198
|
+
"300wm": "battle_rifle",
|
|
9199
|
+
"338lapua": "sniper",
|
|
9200
|
+
"408cheytac": "sniper",
|
|
9201
|
+
"50bmg": "sniper",
|
|
9202
|
+
arrow: "arrow",
|
|
9203
|
+
crossbow_bolt: "arrow"
|
|
9204
|
+
};
|
|
9205
|
+
function waterShotClassOf(round2) {
|
|
9206
|
+
const joules = 0.5 * (round2.grams / 1e3) * round2.speed * round2.speed;
|
|
9207
|
+
if (round2.speed < 150) return "arrow";
|
|
9208
|
+
if (round2.pellet) return round2.grams < 0.5 ? "birdshot" : "buckshot";
|
|
9209
|
+
if ((round2.diameter ?? 0) >= 15) return "slug";
|
|
9210
|
+
if (joules >= 6e3) return "sniper";
|
|
9211
|
+
if (joules >= 2800) return "battle_rifle";
|
|
9212
|
+
if (joules >= 1200) return "rifle";
|
|
9213
|
+
if (joules >= 900) return "magnum";
|
|
9214
|
+
return joules < 200 ? "rimfire" : "pistol";
|
|
9215
|
+
}
|
|
9216
|
+
var WATER_BLAST_KINDS = {
|
|
9217
|
+
blast: { brisance: 1, columnWidth: 1, fragments: 0, mist: 1, fireballUnderwater: false },
|
|
9218
|
+
fragmentation: { brisance: 0.9, columnWidth: 1, fragments: 16, mist: 1, fireballUnderwater: false },
|
|
9219
|
+
shaped_charge: { brisance: 0.8, columnWidth: 0.6, fragments: 6, mist: 0.8, fireballUnderwater: false },
|
|
9220
|
+
directional: { brisance: 0.7, columnWidth: 0.9, fragments: 24, mist: 0.8, fireballUnderwater: false },
|
|
9221
|
+
fuel: { brisance: 0.25, columnWidth: 1.4, fragments: 4, mist: 2.2, fireballUnderwater: false },
|
|
9222
|
+
incendiary: { brisance: 0.05, columnWidth: 1.2, fragments: 0, mist: 1.5, fireballUnderwater: false },
|
|
9223
|
+
flash: { brisance: 0.1, columnWidth: 1, fragments: 0, mist: 0.6, fireballUnderwater: false }
|
|
9224
|
+
};
|
|
9225
|
+
var WATER_BLASTS = {
|
|
9226
|
+
m67: { tnt: 0.24, kind: "fragmentation" },
|
|
9227
|
+
pipe_bomb: { tnt: 0.15, kind: "fragmentation" },
|
|
9228
|
+
m79_40mm: { tnt: 0.045, kind: "fragmentation" },
|
|
9229
|
+
vog_25: { tnt: 0.045, kind: "fragmentation" },
|
|
9230
|
+
dynamite: { tnt: 0.25, kind: "blast" },
|
|
9231
|
+
c4: { tnt: 0.76, kind: "blast" },
|
|
9232
|
+
semtex: { tnt: 0.83, kind: "blast" },
|
|
9233
|
+
claymore: { tnt: 0.9, kind: "directional" },
|
|
9234
|
+
m72_66mm: { tnt: 0.45, kind: "shaped_charge" },
|
|
9235
|
+
at4_84mm: { tnt: 0.7, kind: "shaped_charge" },
|
|
9236
|
+
pg7v: { tnt: 0.45, kind: "shaped_charge" },
|
|
9237
|
+
carl_gustaf_84mm: { tnt: 0.7, kind: "shaped_charge" },
|
|
9238
|
+
propane_p13: { tnt: 1.5, kind: "fuel" },
|
|
9239
|
+
fuel_barrel: { tnt: 1, kind: "fuel" },
|
|
9240
|
+
car_fuel_tank: { tnt: 0.5, kind: "fuel" },
|
|
9241
|
+
fuel_pump: { tnt: 0.5, kind: "fuel" },
|
|
9242
|
+
fuel_station_tank: { tnt: 20, kind: "fuel" },
|
|
9243
|
+
molotov: { tnt: 0.02, kind: "incendiary" },
|
|
9244
|
+
flashbang: { tnt: 0.01, kind: "flash" }
|
|
9245
|
+
};
|
|
9246
|
+
function resolveWaterShotProfile(profile, table = WATER_SHOT_PROFILES) {
|
|
9247
|
+
if (typeof profile !== "string") return profile;
|
|
9248
|
+
return table[profile] ?? WATER_SHOT_PROFILES.pistol;
|
|
9249
|
+
}
|
|
9250
|
+
function patchWaterShotProfiles(base, changes) {
|
|
9251
|
+
const out = { ...base };
|
|
9252
|
+
for (const [id, change] of Object.entries(changes)) {
|
|
9253
|
+
if (change === null) delete out[id];
|
|
9254
|
+
else out[id] = { ...base[id] ?? WATER_SHOT_PROFILES.pistol, ...change };
|
|
9255
|
+
}
|
|
9256
|
+
return out;
|
|
9257
|
+
}
|
|
9258
|
+
|
|
9259
|
+
// src/water/plan.ts
|
|
9260
|
+
var DEGREES = 180 / Math.PI;
|
|
9261
|
+
var SPENT_SPEED = 15;
|
|
9262
|
+
var DEFAULT_DEPTH = 2;
|
|
9263
|
+
var RICOCHET_SPEED_SHARE = 0.6;
|
|
9264
|
+
var RICOCHET_YAW_DEG = 6;
|
|
9265
|
+
var BLAST_COLUMN_PER_QUARTIC_KG = 10;
|
|
9266
|
+
var AIRBURST_SCALED_HEIGHT = 2.5;
|
|
9267
|
+
var BEST_SCALED_DEPTH = 0.6;
|
|
9268
|
+
var DEEP_FALL = 1.6;
|
|
9269
|
+
var UNDERWATER_SCALED_DEPTH = 0.15;
|
|
9270
|
+
var clamp5 = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
9271
|
+
function planWaterShot(params, random, table) {
|
|
9272
|
+
const profile = resolveWaterShotProfile(params.profile, table);
|
|
9273
|
+
const [dx, dy, dz] = params.direction;
|
|
9274
|
+
const sine = clamp5(-dy, 0, 1);
|
|
9275
|
+
const angleDeg = Math.asin(sine) * DEGREES;
|
|
9276
|
+
const speed = params.speed ?? profile.speed;
|
|
9277
|
+
const strength = clamp5(speed / profile.speed, 0.3, 1.25);
|
|
9278
|
+
const flat = Math.hypot(dx, dz) || 1;
|
|
9279
|
+
const forward = [dx / flat, dz / flat];
|
|
9280
|
+
const ricochet = angleDeg < profile.ricochetBelowDeg ? skipOff(params.direction, angleDeg, random) : null;
|
|
9281
|
+
const lean = (1 - sine) * (ricochet ? 1.2 : 0.6);
|
|
9282
|
+
const columnHeight = profile.columnHeight * strength * (ricochet ? 0.35 : 0.35 + 0.65 * sine);
|
|
9283
|
+
const depth = params.depth ?? DEFAULT_DEPTH;
|
|
9284
|
+
const trail = ricochet ? null : trailUnder(params, profile, speed, depth, sine);
|
|
9285
|
+
return {
|
|
9286
|
+
profile,
|
|
9287
|
+
angleDeg,
|
|
9288
|
+
ricochet,
|
|
9289
|
+
columnHeight,
|
|
9290
|
+
columnRadius: profile.columnRadius * Math.sqrt(strength),
|
|
9291
|
+
tilt: [forward[0] * lean, forward[1] * lean],
|
|
9292
|
+
drops: Math.round(profile.drops * strength),
|
|
9293
|
+
ringRadius: profile.ringRadius * Math.sqrt(strength),
|
|
9294
|
+
rings: profile.rings,
|
|
9295
|
+
foamRadius: profile.foamRadius * (ricochet ? 1.4 : 1),
|
|
9296
|
+
trailEnd: trail?.end ?? params.point,
|
|
9297
|
+
trailLength: trail?.length ?? 0,
|
|
9298
|
+
bedSpeed: trail?.bedSpeed ?? 0
|
|
9299
|
+
};
|
|
9300
|
+
}
|
|
9301
|
+
function skipOff(direction, angleDeg, random) {
|
|
9302
|
+
const yaw = random.between(-RICOCHET_YAW_DEG, RICOCHET_YAW_DEG) / DEGREES;
|
|
9303
|
+
const cos2 = Math.cos(yaw);
|
|
9304
|
+
const sin2 = Math.sin(yaw);
|
|
9305
|
+
const [dx, dy, dz] = direction;
|
|
9306
|
+
const up = Math.abs(dy) * (0.5 + 0.3 * random.next());
|
|
9307
|
+
const x = dx * cos2 - dz * sin2;
|
|
9308
|
+
const z = dx * sin2 + dz * cos2;
|
|
9309
|
+
const length = Math.hypot(x, up, z) || 1;
|
|
9310
|
+
return { direction: [x / length, up / length, z / length], speedShare: RICOCHET_SPEED_SHARE * (1 - angleDeg / 30) };
|
|
9311
|
+
}
|
|
9312
|
+
function trailUnder(params, profile, speed, depth, sine) {
|
|
9313
|
+
const spentAfter = profile.slowing * Math.log(Math.max(1, speed / SPENT_SPEED));
|
|
9314
|
+
const toBed = sine > 1e-3 ? depth / sine : Infinity;
|
|
9315
|
+
const length = Math.min(spentAfter, toBed);
|
|
9316
|
+
const [px, py, pz] = params.point;
|
|
9317
|
+
const [dx, dy, dz] = params.direction;
|
|
9318
|
+
const bedSpeed = toBed <= spentAfter ? speed * Math.exp(-toBed / profile.slowing) : 0;
|
|
9319
|
+
return { end: [px + dx * length, py + dy * length, pz + dz * length], length, bedSpeed };
|
|
9320
|
+
}
|
|
9321
|
+
function resolveWaterBlast(params) {
|
|
9322
|
+
const known = params.explosive ? WATER_BLASTS[params.explosive] : void 0;
|
|
9323
|
+
const tnt = Math.max(1e-3, params.tnt ?? known?.tnt ?? 0.25);
|
|
9324
|
+
const kindId = params.kind ?? known?.kind ?? "blast";
|
|
9325
|
+
const kind = WATER_BLAST_KINDS[kindId] ?? WATER_BLAST_KINDS.blast;
|
|
9326
|
+
return { tnt, kind };
|
|
9327
|
+
}
|
|
9328
|
+
function planWaterBlast(params) {
|
|
9329
|
+
const { tnt, kind } = resolveWaterBlast(params);
|
|
9330
|
+
const scale = Math.cbrt(tnt);
|
|
9331
|
+
const quartic = Math.sqrt(Math.sqrt(tnt));
|
|
9332
|
+
const burstDepth = params.level - params.point[1];
|
|
9333
|
+
const scaledDepth = burstDepth / scale;
|
|
9334
|
+
const airburst = -scaledDepth > AIRBURST_SCALED_HEIGHT;
|
|
9335
|
+
const underwater = scaledDepth > UNDERWATER_SCALED_DEPTH && !kind.fireballUnderwater;
|
|
9336
|
+
const surface = scaledDepth <= 0 ? Math.max(0, 1 + scaledDepth / AIRBURST_SCALED_HEIGHT) : 1;
|
|
9337
|
+
const depthShape = scaledDepth <= 0 ? 0.6 * surface : scaledDepth <= BEST_SCALED_DEPTH ? 0.6 + 0.4 * (scaledDepth / BEST_SCALED_DEPTH) : Math.exp(-(scaledDepth - BEST_SCALED_DEPTH) / DEEP_FALL);
|
|
9338
|
+
const shallow = clamp5(0.35 + params.depth / (1.2 * scale), 0.35, 1);
|
|
9339
|
+
const power = kind.brisance;
|
|
9340
|
+
const columnHeight = airburst ? 0 : BLAST_COLUMN_PER_QUARTIC_KG * quartic * power * depthShape * shallow;
|
|
9341
|
+
const domed = scaledDepth > 0 && !airburst;
|
|
9342
|
+
const domeRadius = domed ? 1.6 * scale * Math.cbrt(power) : 0;
|
|
9343
|
+
const fragments = scaledDepth < UNDERWATER_SCALED_DEPTH ? kind.fragments : 0;
|
|
9344
|
+
return {
|
|
9345
|
+
tnt,
|
|
9346
|
+
kind,
|
|
9347
|
+
burstDepth,
|
|
9348
|
+
underwater,
|
|
9349
|
+
airburst,
|
|
9350
|
+
columnHeight,
|
|
9351
|
+
columnRadius: 0.35 * scale * kind.columnWidth * (1 + 0.5 * clamp5(scaledDepth, 0, 1)),
|
|
9352
|
+
domeRadius,
|
|
9353
|
+
domeHeight: domed ? domeRadius * 0.6 * (scaledDepth < 1 ? 1 : Math.exp(1 - scaledDepth)) : 0,
|
|
9354
|
+
shockRadius: (scaledDepth >= 0 ? 5 : 4 * surface) * scale,
|
|
9355
|
+
waveAmplitude: 0.12 * scale * power * (scaledDepth >= 0 ? 1 : surface) * shallow,
|
|
9356
|
+
waveSpeed: 2.5 + 1.5 * scale,
|
|
9357
|
+
drops: airburst ? Math.round(20 * scale) : Math.round((60 + 140 * scale) * Math.max(0.3, depthShape) * Math.max(0.3, power)),
|
|
9358
|
+
mist: Math.round((6 + 10 * scale) * kind.mist * (airburst ? 0.4 : 1)),
|
|
9359
|
+
fragments,
|
|
9360
|
+
foamRadius: 2.5 * scale * Math.max(0.4, Math.cbrt(power)) * (airburst ? 0.3 : 1),
|
|
9361
|
+
bubbles: scaledDepth > 0 ? Math.round(30 + 50 * scale) : 0
|
|
9362
|
+
};
|
|
9363
|
+
}
|
|
9364
|
+
|
|
9365
|
+
// src/water/records.ts
|
|
9366
|
+
var WATER_LIMITS = { drops: 700, rings: 220, foam: 60, columns: 32, bubbles: 500, mist: 90, waves: 16 };
|
|
9367
|
+
function createWaterPools(limits) {
|
|
9368
|
+
return {
|
|
9369
|
+
drops: new OrderedPool(limits.drops, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, size: 0, age: 0, life: 0, level: 0 })),
|
|
9370
|
+
rings: new OrderedPool(limits.rings, () => ({ x: 0, y: 0, z: 0, kind: 0, radius: 0, startRadius: 0, maxRadius: 0, delay: 0, age: 0, life: 0, strength: 0, alpha: 0 })),
|
|
9371
|
+
foam: new OrderedPool(limits.foam, () => ({ x: 0, y: 0, z: 0, radius: 0, startRadius: 0, maxRadius: 0, age: 0, life: 0, alpha: 0 })),
|
|
9372
|
+
columns: new OrderedPool(limits.columns, () => ({ x: 0, y: 0, z: 0, dome: false, peak: 0, baseRadius: 0, tiltX: 0, tiltZ: 0, rise: 0, delay: 0, age: 0, life: 0, height: 0, radius: 0, alpha: 0 })),
|
|
9373
|
+
bubbles: new OrderedPool(limits.bubbles, () => ({ x: 0, y: 0, z: 0, size: 0, rise: 0, delay: 0, age: 0, life: 0, level: 0, alpha: 0 })),
|
|
9374
|
+
mist: new OrderedPool(limits.mist, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, size: 0, age: 0, life: 0, alpha: 0 })),
|
|
9375
|
+
waves: new OrderedPool(limits.waves, () => ({ x: 0, z: 0, speed: 0, amplitude: 0, width: 0, reach: 0, delay: 0, age: 0, life: 0 }))
|
|
9376
|
+
};
|
|
9377
|
+
}
|
|
9378
|
+
|
|
9379
|
+
// src/water/spawn.ts
|
|
9380
|
+
var TRAIL_BUBBLES_MAX = 40;
|
|
9381
|
+
var BLAST_FOAM_LIFE = 8;
|
|
9382
|
+
var BLAST_WAVE_CRESTS = 3;
|
|
9383
|
+
var BLAST_WAVE_GAP = 0.35;
|
|
9384
|
+
var BLAST_WAVE_LIFE = 6;
|
|
9385
|
+
var BLAST_SIDE_JETS = 4;
|
|
9386
|
+
function addRing(context, spec) {
|
|
9387
|
+
const ring2 = context.pools.rings.acquire();
|
|
9388
|
+
ring2.x = spec.x;
|
|
9389
|
+
ring2.y = spec.y;
|
|
9390
|
+
ring2.z = spec.z;
|
|
9391
|
+
ring2.kind = spec.kind;
|
|
9392
|
+
ring2.startRadius = spec.start;
|
|
9393
|
+
ring2.radius = spec.start;
|
|
9394
|
+
ring2.maxRadius = Math.max(spec.start, Math.min(spec.max, context.reach(spec.x, spec.z, spec.max)));
|
|
9395
|
+
ring2.delay = spec.delay;
|
|
9396
|
+
ring2.age = 0;
|
|
9397
|
+
ring2.life = spec.life;
|
|
9398
|
+
ring2.strength = spec.strength;
|
|
9399
|
+
ring2.alpha = 0;
|
|
9400
|
+
}
|
|
9401
|
+
function addFoam(context, at3, radius, life) {
|
|
9402
|
+
const foam = context.pools.foam.acquire();
|
|
9403
|
+
foam.x = at3[0];
|
|
9404
|
+
foam.y = at3[1];
|
|
9405
|
+
foam.z = at3[2];
|
|
9406
|
+
foam.maxRadius = Math.min(radius, Math.max(0.05, context.reach(at3[0], at3[2], radius)));
|
|
9407
|
+
foam.startRadius = foam.maxRadius * 0.35;
|
|
9408
|
+
foam.radius = foam.startRadius;
|
|
9409
|
+
foam.age = 0;
|
|
9410
|
+
foam.life = life;
|
|
9411
|
+
foam.alpha = 0.85;
|
|
9412
|
+
}
|
|
9413
|
+
function addColumn(context, spec) {
|
|
9414
|
+
if (spec.peak < 0.02) return;
|
|
9415
|
+
const column = context.pools.columns.acquire();
|
|
9416
|
+
column.x = spec.at[0];
|
|
9417
|
+
column.y = spec.at[1];
|
|
9418
|
+
column.z = spec.at[2];
|
|
9419
|
+
column.dome = spec.dome;
|
|
9420
|
+
column.peak = spec.peak;
|
|
9421
|
+
column.baseRadius = spec.radius;
|
|
9422
|
+
column.tiltX = spec.tilt[0];
|
|
9423
|
+
column.tiltZ = spec.tilt[1];
|
|
9424
|
+
const flight = Math.sqrt(2 * spec.peak / WATER_GRAVITY);
|
|
9425
|
+
column.rise = spec.rise ?? Math.max(0.06, flight * 0.6);
|
|
9426
|
+
column.life = column.rise + Math.max(0.2, flight * 1.3) + 0.15;
|
|
9427
|
+
column.delay = spec.delay;
|
|
9428
|
+
column.age = 0;
|
|
9429
|
+
column.height = 0;
|
|
9430
|
+
column.radius = spec.radius;
|
|
9431
|
+
column.alpha = 0;
|
|
9432
|
+
}
|
|
9433
|
+
function addDrop(context, spec) {
|
|
9434
|
+
const drop = context.pools.drops.acquire();
|
|
9435
|
+
drop.x = spec.at[0];
|
|
9436
|
+
drop.y = spec.at[1];
|
|
9437
|
+
drop.z = spec.at[2];
|
|
9438
|
+
drop.vx = spec.velocity[0];
|
|
9439
|
+
drop.vy = spec.velocity[1];
|
|
9440
|
+
drop.vz = spec.velocity[2];
|
|
9441
|
+
drop.size = spec.size;
|
|
9442
|
+
drop.level = spec.level;
|
|
9443
|
+
drop.age = 0;
|
|
9444
|
+
drop.life = 6;
|
|
9445
|
+
}
|
|
9446
|
+
function addBubble(context, at3, level, delay, size) {
|
|
9447
|
+
const { random } = context;
|
|
9448
|
+
const bubble = context.pools.bubbles.acquire();
|
|
9449
|
+
bubble.x = at3[0];
|
|
9450
|
+
bubble.y = at3[1];
|
|
9451
|
+
bubble.z = at3[2];
|
|
9452
|
+
bubble.size = size;
|
|
9453
|
+
bubble.rise = random.between(0.2, 0.45);
|
|
9454
|
+
bubble.delay = delay;
|
|
9455
|
+
bubble.age = 0;
|
|
9456
|
+
bubble.life = random.between(0.8, 2.2);
|
|
9457
|
+
bubble.level = level;
|
|
9458
|
+
bubble.alpha = 0;
|
|
9459
|
+
}
|
|
9460
|
+
function spawnShot(context, point, plan) {
|
|
9461
|
+
const { random, detail } = context;
|
|
9462
|
+
const [x, y, z] = point;
|
|
9463
|
+
const profile = plan.profile;
|
|
9464
|
+
addColumn(context, { at: point, peak: plan.columnHeight, radius: plan.columnRadius, tilt: plan.tilt, dome: false, delay: 0 });
|
|
9465
|
+
const drops = Math.round(plan.drops * detail);
|
|
9466
|
+
const steep = plan.ricochet ? 0.3 : 0.4 + 0.6 * Math.sin(plan.angleDeg * Math.PI / 180);
|
|
9467
|
+
for (let index = 0; index < drops; index++) {
|
|
9468
|
+
const angle = random.next() * Math.PI * 2;
|
|
9469
|
+
const speed = random.between(profile.dropSpeed[0], profile.dropSpeed[1]);
|
|
9470
|
+
const out = speed * random.between(0.2, 0.55);
|
|
9471
|
+
const lean = speed * random.between(0.3, 0.9);
|
|
9472
|
+
addDrop(context, {
|
|
9473
|
+
at: [x + Math.cos(angle) * plan.columnRadius, y, z + Math.sin(angle) * plan.columnRadius],
|
|
9474
|
+
velocity: [Math.cos(angle) * out + plan.tilt[0] * lean, speed * steep * random.between(0.7, 1), Math.sin(angle) * out + plan.tilt[1] * lean],
|
|
9475
|
+
size: profile.dropSize * random.between(0.6, 1.4),
|
|
9476
|
+
level: y
|
|
9477
|
+
});
|
|
9478
|
+
}
|
|
9479
|
+
for (let index = 0; index < plan.rings; index++) {
|
|
9480
|
+
addRing(context, { x, y, z, kind: 0, start: plan.columnRadius, max: plan.ringRadius * (1 - index * 0.22), life: profile.ringLife * (1 - index * 0.15), delay: index * 0.12, strength: 0.6 });
|
|
9481
|
+
}
|
|
9482
|
+
if (plan.ricochet) {
|
|
9483
|
+
for (let step = 1; step <= 2; step++) {
|
|
9484
|
+
const sx = x + plan.tilt[0] * 0.3 * step;
|
|
9485
|
+
const sz = z + plan.tilt[1] * 0.3 * step;
|
|
9486
|
+
addRing(context, { x: sx, y, z: sz, kind: 0, start: plan.columnRadius, max: plan.ringRadius * 0.6, life: profile.ringLife * 0.8, delay: 0.02 * step, strength: 0.45 });
|
|
9487
|
+
}
|
|
9488
|
+
}
|
|
9489
|
+
addFoam(context, point, plan.foamRadius, profile.foamLife);
|
|
9490
|
+
spawnTrail(context, point, plan);
|
|
9491
|
+
}
|
|
9492
|
+
function spawnTrail(context, point, plan) {
|
|
9493
|
+
if (plan.trailLength <= 0) return;
|
|
9494
|
+
const { random } = context;
|
|
9495
|
+
const count = Math.min(TRAIL_BUBBLES_MAX, Math.round(plan.profile.bubblesPerMetre * plan.trailLength * context.detail));
|
|
9496
|
+
const [ex, ey, ez] = plan.trailEnd;
|
|
9497
|
+
for (let index = 0; index < count; index++) {
|
|
9498
|
+
const along = random.next() ** 1.6;
|
|
9499
|
+
const jitter = 0.01 + 0.02 * along;
|
|
9500
|
+
const at3 = [point[0] + (ex - point[0]) * along + random.between(-jitter, jitter), point[1] + (ey - point[1]) * along, point[2] + (ez - point[2]) * along + random.between(-jitter, jitter)];
|
|
9501
|
+
addBubble(context, at3, point[1], along * 0.05, random.between(3e-3, 0.01));
|
|
9502
|
+
}
|
|
9503
|
+
}
|
|
9504
|
+
function spawnBlast(context, point, level, plan) {
|
|
9505
|
+
const { random, detail } = context;
|
|
9506
|
+
const surface = [point[0], level, point[2]];
|
|
9507
|
+
const scale = Math.cbrt(plan.tnt);
|
|
9508
|
+
addColumn(context, { at: surface, peak: plan.columnHeight, radius: plan.columnRadius, tilt: [0, 0], dome: false, delay: plan.domeRadius > 0 ? 0.08 : 0 });
|
|
9509
|
+
for (let index = 0; index < BLAST_SIDE_JETS && plan.columnHeight > 0; index++) {
|
|
9510
|
+
const angle = index / BLAST_SIDE_JETS * Math.PI * 2 + random.next();
|
|
9511
|
+
const off = plan.columnRadius * random.between(0.6, 1.1);
|
|
9512
|
+
const lean = random.between(0.1, 0.25);
|
|
9513
|
+
addColumn(context, { at: [surface[0] + Math.cos(angle) * off, level, surface[2] + Math.sin(angle) * off], peak: plan.columnHeight * random.between(0.45, 0.75), radius: plan.columnRadius * 0.45, tilt: [Math.cos(angle) * lean, Math.sin(angle) * lean], dome: false, delay: 0.05 + random.next() * 0.08 });
|
|
9514
|
+
}
|
|
9515
|
+
if (plan.domeRadius > 0) addColumn(context, { at: surface, peak: plan.domeHeight, radius: plan.domeRadius, tilt: [0, 0], dome: true, delay: 0, rise: 0.25 });
|
|
9516
|
+
addRing(context, { x: surface[0], y: level, z: surface[2], kind: 1, start: 0.2, max: plan.shockRadius, life: 0.45, delay: 0, strength: 0.95 });
|
|
9517
|
+
spawnWaves(context, surface, plan);
|
|
9518
|
+
spawnRain(context, surface, plan, detail);
|
|
9519
|
+
spawnSpray(context, surface, plan, scale);
|
|
9520
|
+
addFoam(context, surface, plan.foamRadius, BLAST_FOAM_LIFE);
|
|
9521
|
+
const bubbles = Math.round(plan.bubbles * detail);
|
|
9522
|
+
for (let index = 0; index < bubbles; index++) {
|
|
9523
|
+
const at3 = [point[0] + random.between(-0.5, 0.5) * scale, Math.min(level - 0.02, point[1] + random.between(-0.2, 0.3) * scale), point[2] + random.between(-0.5, 0.5) * scale];
|
|
9524
|
+
addBubble(context, at3, level, random.next() * 1.2, random.between(0.01, 0.04) * Math.max(1, scale));
|
|
9525
|
+
}
|
|
9526
|
+
}
|
|
9527
|
+
function spawnWaves(context, surface, plan) {
|
|
9528
|
+
if (plan.waveAmplitude <= 0) return;
|
|
9529
|
+
const reach = context.reach(surface[0], surface[2], plan.waveSpeed * BLAST_WAVE_LIFE);
|
|
9530
|
+
for (let crest = 0; crest < BLAST_WAVE_CRESTS; crest++) {
|
|
9531
|
+
const wave = context.pools.waves.acquire();
|
|
9532
|
+
wave.x = surface[0];
|
|
9533
|
+
wave.z = surface[2];
|
|
9534
|
+
wave.speed = plan.waveSpeed;
|
|
9535
|
+
wave.amplitude = plan.waveAmplitude * (1 - crest * 0.3);
|
|
9536
|
+
wave.width = 0.25 + 0.3 * Math.cbrt(plan.tnt);
|
|
9537
|
+
wave.reach = reach;
|
|
9538
|
+
wave.delay = crest * BLAST_WAVE_GAP;
|
|
9539
|
+
wave.age = 0;
|
|
9540
|
+
wave.life = BLAST_WAVE_LIFE;
|
|
9541
|
+
addRing(context, { x: surface[0], y: surface[1], z: surface[2], kind: 2, start: 0.1, max: plan.waveSpeed * BLAST_WAVE_LIFE, life: BLAST_WAVE_LIFE, delay: wave.delay, strength: 0.5 * (1 - crest * 0.3) });
|
|
9542
|
+
}
|
|
9543
|
+
}
|
|
9544
|
+
function spawnRain(context, surface, plan, detail) {
|
|
9545
|
+
const { random } = context;
|
|
9546
|
+
const drops = Math.round(plan.drops * detail);
|
|
9547
|
+
const top = Math.max(0.5, plan.columnHeight);
|
|
9548
|
+
const launch = Math.sqrt(2 * WATER_GRAVITY * top);
|
|
9549
|
+
const scale = Math.cbrt(plan.tnt);
|
|
9550
|
+
for (let index = 0; index < drops; index++) {
|
|
9551
|
+
const angle = random.next() * Math.PI * 2;
|
|
9552
|
+
const out = random.between(0.4, 3) * scale;
|
|
9553
|
+
const r = random.next() * plan.columnRadius;
|
|
9554
|
+
addDrop(context, {
|
|
9555
|
+
at: [surface[0] + Math.cos(angle) * r, surface[1] + random.next() * top * 0.2, surface[2] + Math.sin(angle) * r],
|
|
9556
|
+
velocity: [Math.cos(angle) * out, launch * random.between(0.45, 1.02), Math.sin(angle) * out],
|
|
9557
|
+
size: random.between(0.012, 0.035),
|
|
9558
|
+
level: surface[1]
|
|
9559
|
+
});
|
|
9560
|
+
}
|
|
9561
|
+
}
|
|
9562
|
+
function spawnSpray(context, surface, plan, scale) {
|
|
9563
|
+
const { random } = context;
|
|
9564
|
+
const top = Math.max(0.4, plan.columnHeight);
|
|
9565
|
+
for (let index = 0; index < plan.mist; index++) {
|
|
9566
|
+
const mist = context.pools.mist.acquire();
|
|
9567
|
+
const angle = random.next() * Math.PI * 2;
|
|
9568
|
+
const r = random.next() * (plan.columnRadius + 0.5 * scale);
|
|
9569
|
+
mist.x = surface[0] + Math.cos(angle) * r;
|
|
9570
|
+
mist.y = surface[1] + random.next() * top * 0.6;
|
|
9571
|
+
mist.z = surface[2] + Math.sin(angle) * r;
|
|
9572
|
+
const out = random.between(0.5, 1.8) * scale;
|
|
9573
|
+
mist.vx = Math.cos(angle) * out;
|
|
9574
|
+
mist.vy = random.between(0.3, 1);
|
|
9575
|
+
mist.vz = Math.sin(angle) * out;
|
|
9576
|
+
mist.size = random.between(0.4, 1.2) * scale;
|
|
9577
|
+
mist.age = 0;
|
|
9578
|
+
mist.life = random.between(2.5, 4.5);
|
|
9579
|
+
mist.alpha = 0;
|
|
9580
|
+
}
|
|
9581
|
+
}
|
|
9582
|
+
|
|
9583
|
+
// src/water/effects.ts
|
|
9584
|
+
var STEP_LIMIT = 0.05;
|
|
9585
|
+
var SHORE_DIRECTIONS = 8;
|
|
9586
|
+
var SHORE_HALVINGS = 5;
|
|
9587
|
+
var SAME_WATER = 0.2;
|
|
9588
|
+
var DROP_RING_SHARE = 0.75;
|
|
9589
|
+
var WAVE_PUSH = 2;
|
|
9590
|
+
function createWaterEffects(options = {}) {
|
|
9591
|
+
const limits = { ...WATER_LIMITS, ...options.limits };
|
|
9592
|
+
const pools = createWaterPools(limits);
|
|
9593
|
+
const random = lehmer(options.seed ?? 1);
|
|
9594
|
+
const lod = options.lod ?? LOD_GAME;
|
|
9595
|
+
const camera2 = [0, 0, 0];
|
|
9596
|
+
let hasCamera = false;
|
|
9597
|
+
const reach = (x, z, limit) => {
|
|
9598
|
+
const levelAt = options.levelAt;
|
|
9599
|
+
if (!levelAt) return limit;
|
|
9600
|
+
const here = levelAt(x, z);
|
|
9601
|
+
if (here === null) return 0;
|
|
9602
|
+
const step = Math.max(0.05, limit / 10);
|
|
9603
|
+
const isWater = (cos2, sin2, distance) => {
|
|
9604
|
+
const level = levelAt(x + cos2 * distance, z + sin2 * distance);
|
|
9605
|
+
return level !== null && Math.abs(level - here) <= SAME_WATER;
|
|
9606
|
+
};
|
|
9607
|
+
let nearest = limit;
|
|
9608
|
+
for (let index = 0; index < SHORE_DIRECTIONS; index++) {
|
|
9609
|
+
const angle = index / SHORE_DIRECTIONS * Math.PI * 2;
|
|
9610
|
+
const cos2 = Math.cos(angle);
|
|
9611
|
+
const sin2 = Math.sin(angle);
|
|
9612
|
+
for (let distance = step; distance < nearest; distance += step) {
|
|
9613
|
+
if (isWater(cos2, sin2, distance)) continue;
|
|
9614
|
+
let wet = distance - step;
|
|
9615
|
+
let dry = distance;
|
|
9616
|
+
for (let halving = 0; halving < SHORE_HALVINGS; halving++) {
|
|
9617
|
+
const middle = (wet + dry) / 2;
|
|
9618
|
+
if (isWater(cos2, sin2, middle)) wet = middle;
|
|
9619
|
+
else dry = middle;
|
|
9620
|
+
}
|
|
9621
|
+
nearest = Math.min(nearest, wet);
|
|
9622
|
+
break;
|
|
9623
|
+
}
|
|
9624
|
+
}
|
|
9625
|
+
return nearest;
|
|
9626
|
+
};
|
|
9627
|
+
const detailAt = (point, radius) => hasCamera ? lodScale(lod, Math.hypot(point[0] - camera2[0], point[1] - camera2[1], point[2] - camera2[2]), radius) : 1;
|
|
9628
|
+
const contextAt = (point, radius) => ({ pools, random, detail: detailAt(point, radius), reach });
|
|
9629
|
+
const motion = {
|
|
9630
|
+
dt: 0,
|
|
9631
|
+
landed: (drop) => {
|
|
9632
|
+
if (pools.rings.count >= limits.rings * DROP_RING_SHARE) return;
|
|
9633
|
+
const level = options.levelAt ? options.levelAt(drop.x, drop.z) : drop.level;
|
|
9634
|
+
if (level === null || Math.abs(level - drop.level) > SAME_WATER) return;
|
|
9635
|
+
addRing({ pools, random, detail: 1, reach }, { x: drop.x, y: level, z: drop.z, kind: 0, start: drop.size, max: 0.04 + drop.size * 6, life: 0.5, delay: 0, strength: 0.35 });
|
|
9636
|
+
}
|
|
9637
|
+
};
|
|
9638
|
+
const shot = (params) => {
|
|
9639
|
+
const plan = planWaterShot(params, random, options.profiles);
|
|
9640
|
+
spawnShot(contextAt(params.point, plan.ringRadius), params.point, plan);
|
|
9641
|
+
return plan;
|
|
9642
|
+
};
|
|
9643
|
+
const pepper = (params, plan) => {
|
|
9644
|
+
const spread = 1.5 + 3 * Math.cbrt(plan.tnt);
|
|
9645
|
+
for (let index = 0; index < plan.fragments; index++) {
|
|
9646
|
+
const angle = random.next() * Math.PI * 2;
|
|
9647
|
+
const distance = random.between(0.6, spread);
|
|
9648
|
+
const x = params.point[0] + Math.cos(angle) * distance;
|
|
9649
|
+
const z = params.point[2] + Math.sin(angle) * distance;
|
|
9650
|
+
const level = options.levelAt ? options.levelAt(x, z) : params.level;
|
|
9651
|
+
if (level === null || Math.abs(level - params.level) > SAME_WATER) continue;
|
|
9652
|
+
const fall = random.between(0.4, 1);
|
|
9653
|
+
const length = Math.hypot(Math.cos(angle), fall, Math.sin(angle));
|
|
9654
|
+
const point = [x, level, z];
|
|
9655
|
+
const fragment = planWaterShot({ point, direction: [Math.cos(angle) / length, -fall / length, Math.sin(angle) / length], profile: "fragment", depth: params.depth }, random, options.profiles);
|
|
9656
|
+
spawnShot(contextAt(point, fragment.ringRadius), point, fragment);
|
|
9657
|
+
}
|
|
9658
|
+
};
|
|
9659
|
+
const blast = (params) => {
|
|
9660
|
+
const plan = planWaterBlast(params);
|
|
9661
|
+
spawnBlast(contextAt(params.point, plan.shockRadius), params.point, params.level, plan);
|
|
9662
|
+
pepper(params, plan);
|
|
9663
|
+
return plan;
|
|
9664
|
+
};
|
|
9665
|
+
const waveAt = (x, z) => {
|
|
9666
|
+
let height = 0;
|
|
9667
|
+
let pushX = 0;
|
|
9668
|
+
let pushZ = 0;
|
|
9669
|
+
for (const wave of pools.waves.items) {
|
|
9670
|
+
if (wave.delay > 0) continue;
|
|
9671
|
+
const dx = x - wave.x;
|
|
9672
|
+
const dz = z - wave.z;
|
|
9673
|
+
const r = Math.hypot(dx, dz);
|
|
9674
|
+
if (r > wave.reach) continue;
|
|
9675
|
+
const off = (r - wave.speed * wave.age) / wave.width;
|
|
9676
|
+
if (Math.abs(off) > 3) continue;
|
|
9677
|
+
const crest = wave.amplitude * Math.exp(-off * off) * (1 - wave.age / wave.life) / Math.sqrt(Math.max(1, r));
|
|
9678
|
+
height += crest;
|
|
9679
|
+
if (r > 1e-3) {
|
|
9680
|
+
const push = crest * wave.speed * WAVE_PUSH;
|
|
9681
|
+
pushX += dx / r * push;
|
|
9682
|
+
pushZ += dz / r * push;
|
|
9683
|
+
}
|
|
9684
|
+
}
|
|
9685
|
+
return { height, push: [pushX, pushZ] };
|
|
9686
|
+
};
|
|
9687
|
+
return {
|
|
9688
|
+
shot,
|
|
9689
|
+
blast,
|
|
9690
|
+
update(dt) {
|
|
9691
|
+
let left = Math.max(0, dt);
|
|
9692
|
+
while (left > 1e-6) {
|
|
9693
|
+
motion.dt = Math.min(STEP_LIMIT, left);
|
|
9694
|
+
stepWaterPools(pools, motion);
|
|
9695
|
+
left -= motion.dt;
|
|
9696
|
+
}
|
|
9697
|
+
},
|
|
9698
|
+
setCamera(position) {
|
|
9699
|
+
camera2[0] = position[0];
|
|
9700
|
+
camera2[1] = position[1];
|
|
9701
|
+
camera2[2] = position[2];
|
|
9702
|
+
hasCamera = true;
|
|
9703
|
+
},
|
|
9704
|
+
waveAt,
|
|
9705
|
+
drops: pools.drops.items,
|
|
9706
|
+
rings: pools.rings.items,
|
|
9707
|
+
foam: pools.foam.items,
|
|
9708
|
+
columns: pools.columns.items,
|
|
9709
|
+
bubbles: pools.bubbles.items,
|
|
9710
|
+
mist: pools.mist.items,
|
|
9711
|
+
waves: pools.waves.items,
|
|
9712
|
+
limits,
|
|
9713
|
+
stats: () => ({ drops: pools.drops.count, rings: pools.rings.count, foam: pools.foam.count, columns: pools.columns.count, bubbles: pools.bubbles.count, mist: pools.mist.count, waves: pools.waves.count }),
|
|
9714
|
+
clear() {
|
|
9715
|
+
for (const pool of Object.values(pools)) pool.clear();
|
|
9716
|
+
}
|
|
9717
|
+
};
|
|
9718
|
+
}
|
|
9039
9719
|
return __toCommonJS(index_exports);
|
|
9040
9720
|
})();
|
|
9041
9721
|
//# sourceMappingURL=index.global.js.map
|