@adatechnology/game-vfx 0.10.1 → 0.12.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 +3 -1
- package/dist/index.d.ts +74 -7
- package/dist/index.global.js +121 -15
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +121 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5164,9 +5164,17 @@ function createEffectPlayer(options) {
|
|
|
5164
5164
|
});
|
|
5165
5165
|
}
|
|
5166
5166
|
function placementOf(entry) {
|
|
5167
|
+
const carrier = entry.carrier;
|
|
5168
|
+
if (carrier) return { origin: carrier.origin, anchor: entry.anchor, yaw: entry.yaw, carrier, ...carrier.orientation ? { orientation: carrier.orientation } : {} };
|
|
5167
5169
|
const origin = entry.follow ? [entry.origin[0] + positionOf2(entry.follow)[0], entry.origin[1] + positionOf2(entry.follow)[1], entry.origin[2] + positionOf2(entry.follow)[2]] : entry.origin;
|
|
5168
5170
|
return { origin, anchor: entry.anchor, yaw: entry.yaw, ...entry.orientation ? { orientation: entry.orientation } : {} };
|
|
5169
5171
|
}
|
|
5172
|
+
function moveCarrier(entry) {
|
|
5173
|
+
const pose = entry.track?.();
|
|
5174
|
+
if (!pose || !entry.carrier) return;
|
|
5175
|
+
entry.carrier.origin = [pose.point[0], pose.point[1], pose.point[2]];
|
|
5176
|
+
if (pose.orientation) entry.carrier.orientation = pose.orientation;
|
|
5177
|
+
}
|
|
5170
5178
|
function drawing(entry, action) {
|
|
5171
5179
|
const context = engine.context;
|
|
5172
5180
|
const shared = context.random;
|
|
@@ -5192,7 +5200,9 @@ function createEffectPlayer(options) {
|
|
|
5192
5200
|
anchor: def.anchor ?? ORIGIN5,
|
|
5193
5201
|
yaw: yawOf(heading, playOptions.direction),
|
|
5194
5202
|
orientation: playOptions.orientation,
|
|
5195
|
-
seconds: playOptions.seconds ?? (def.loop && def.loop > 0 ? def.loop : ENDLESS_SECONDS)
|
|
5203
|
+
seconds: playOptions.seconds ?? (def.loop && def.loop > 0 ? def.loop : ENDLESS_SECONDS),
|
|
5204
|
+
track: playOptions.track,
|
|
5205
|
+
carrier: playOptions.track ? { origin: point, orientation: playOptions.orientation } : void 0
|
|
5196
5206
|
};
|
|
5197
5207
|
playing.push(entry);
|
|
5198
5208
|
drawing(
|
|
@@ -5214,11 +5224,21 @@ function createEffectPlayer(options) {
|
|
|
5214
5224
|
for (let index = playing.length - 1; index >= 0; index--) {
|
|
5215
5225
|
const entry = playing[index];
|
|
5216
5226
|
const instance = entry.instance;
|
|
5227
|
+
moveCarrier(entry);
|
|
5217
5228
|
instance.setup = { ...instance.setup, placement: placementOf(entry) };
|
|
5218
5229
|
drawing(entry, () => instance.step(dt));
|
|
5219
5230
|
if (instance.time >= entry.seconds) playing.splice(index, 1);
|
|
5220
5231
|
}
|
|
5221
5232
|
},
|
|
5233
|
+
retrack() {
|
|
5234
|
+
let tracked = false;
|
|
5235
|
+
for (const entry of playing) {
|
|
5236
|
+
if (!entry.carrier) continue;
|
|
5237
|
+
moveCarrier(entry);
|
|
5238
|
+
tracked = true;
|
|
5239
|
+
}
|
|
5240
|
+
return tracked;
|
|
5241
|
+
},
|
|
5222
5242
|
clear() {
|
|
5223
5243
|
playing.length = 0;
|
|
5224
5244
|
},
|
|
@@ -5334,12 +5354,14 @@ function lodScale(bands, distance, visualRadius) {
|
|
|
5334
5354
|
|
|
5335
5355
|
// src/marks.ts
|
|
5336
5356
|
var BLOOD_LIMIT = 450;
|
|
5357
|
+
var SCRAPE_LIMIT = 400;
|
|
5337
5358
|
var SCORCH_VARIANTS = 3;
|
|
5338
5359
|
var RIM_COLORS = [2829359, 3815478];
|
|
5339
5360
|
function createMarkStore() {
|
|
5340
5361
|
const entries = [];
|
|
5341
5362
|
let version = 0;
|
|
5342
5363
|
let bloodCount = 0;
|
|
5364
|
+
let scrapeCount = 0;
|
|
5343
5365
|
const listeners = /* @__PURE__ */ new Set();
|
|
5344
5366
|
return {
|
|
5345
5367
|
entries,
|
|
@@ -5349,16 +5371,25 @@ function createMarkStore() {
|
|
|
5349
5371
|
get bloodCount() {
|
|
5350
5372
|
return bloodCount;
|
|
5351
5373
|
},
|
|
5374
|
+
get scrapeCount() {
|
|
5375
|
+
return scrapeCount;
|
|
5376
|
+
},
|
|
5352
5377
|
lift: 0,
|
|
5353
5378
|
add(mark) {
|
|
5379
|
+
if (mark.kind === "scrape" && scrapeCount >= SCRAPE_LIMIT) {
|
|
5380
|
+
entries.splice(entries.findIndex((m) => m.kind === "scrape"), 1);
|
|
5381
|
+
scrapeCount--;
|
|
5382
|
+
}
|
|
5354
5383
|
entries.push(mark);
|
|
5355
5384
|
if (mark.kind === "blood") bloodCount++;
|
|
5385
|
+
if (mark.kind === "scrape") scrapeCount++;
|
|
5356
5386
|
version++;
|
|
5357
5387
|
for (const listener of listeners) listener({ type: "add", mark });
|
|
5358
5388
|
},
|
|
5359
5389
|
clear() {
|
|
5360
5390
|
entries.length = 0;
|
|
5361
5391
|
bloodCount = 0;
|
|
5392
|
+
scrapeCount = 0;
|
|
5362
5393
|
this.lift = 0;
|
|
5363
5394
|
version++;
|
|
5364
5395
|
for (const listener of listeners) listener({ type: "clear" });
|
|
@@ -5418,6 +5449,9 @@ function addBloodSplat(store, ground, random, spec) {
|
|
|
5418
5449
|
const scaleZ = spec.radius * random.between(1.2, 2);
|
|
5419
5450
|
store.add({ kind: "blood", x: spec.x, y, z: spec.z, scaleX, scaleZ, rotation: random.next() * 6 });
|
|
5420
5451
|
}
|
|
5452
|
+
function addScrape(store, spec) {
|
|
5453
|
+
store.add({ kind: "scrape", ...spec, y: spec.y + 2e-3 + nextLift(store) * 2e-4 });
|
|
5454
|
+
}
|
|
5421
5455
|
|
|
5422
5456
|
// src/pools/rings.ts
|
|
5423
5457
|
function createRingPool(capacity) {
|
|
@@ -6857,6 +6891,21 @@ var DecalPool = class {
|
|
|
6857
6891
|
}
|
|
6858
6892
|
};
|
|
6859
6893
|
|
|
6894
|
+
// src/workshop/carrier.ts
|
|
6895
|
+
function rotate(q, v) {
|
|
6896
|
+
const [qx, qy, qz, qw] = q;
|
|
6897
|
+
const ix = qw * v[0] + qy * v[2] - qz * v[1];
|
|
6898
|
+
const iy = qw * v[1] + qz * v[0] - qx * v[2];
|
|
6899
|
+
const iz = qw * v[2] + qx * v[1] - qy * v[0];
|
|
6900
|
+
const iw = -qx * v[0] - qy * v[1] - qz * v[2];
|
|
6901
|
+
return [ix * qw + iw * -qx + iy * -qz - iz * -qy, iy * qw + iw * -qy + iz * -qx - ix * -qz, iz * qw + iw * -qz + ix * -qy - iy * -qx];
|
|
6902
|
+
}
|
|
6903
|
+
function carriedPoint(carried) {
|
|
6904
|
+
const { carrier, local: local2 } = carried;
|
|
6905
|
+
const turned = carrier.orientation ? rotate(carrier.orientation, local2) : local2;
|
|
6906
|
+
return [carrier.origin[0] + turned[0], carrier.origin[1] + turned[1], carrier.origin[2] + turned[2]];
|
|
6907
|
+
}
|
|
6908
|
+
|
|
6860
6909
|
// src/workshop/meshes.ts
|
|
6861
6910
|
var CAPACITY3 = 400;
|
|
6862
6911
|
var IDENTITY = [0, 0, 0, 1];
|
|
@@ -6875,7 +6924,7 @@ var MeshPool = class {
|
|
|
6875
6924
|
get count() {
|
|
6876
6925
|
return this.particles.length;
|
|
6877
6926
|
}
|
|
6878
|
-
spawn(options, frame = IDENTITY) {
|
|
6927
|
+
spawn(options, frame = IDENTITY, carried) {
|
|
6879
6928
|
const velocity = options.v ?? [0, 0, 0];
|
|
6880
6929
|
const world = options.wv ?? [0, 0, 0];
|
|
6881
6930
|
const particle = {
|
|
@@ -6892,6 +6941,9 @@ var MeshPool = class {
|
|
|
6892
6941
|
y: options.p[1],
|
|
6893
6942
|
z: options.p[2],
|
|
6894
6943
|
frame: options.roll ? multiply(frame, aboutX(options.roll)) : frame,
|
|
6944
|
+
roll: options.roll ? aboutX(options.roll) : void 0,
|
|
6945
|
+
carried,
|
|
6946
|
+
drift: [0, 0, 0],
|
|
6895
6947
|
at: options.at ?? [0, 0, 0],
|
|
6896
6948
|
rx: options.rot?.[0] ?? 0,
|
|
6897
6949
|
ry: options.rot?.[1] ?? 0,
|
|
@@ -6932,9 +6984,12 @@ var MeshPool = class {
|
|
|
6932
6984
|
particle.vy *= keep;
|
|
6933
6985
|
particle.vz *= keep;
|
|
6934
6986
|
}
|
|
6935
|
-
particle.
|
|
6936
|
-
|
|
6937
|
-
|
|
6987
|
+
if (particle.carried) this.ride(particle, dt);
|
|
6988
|
+
else {
|
|
6989
|
+
particle.x += particle.vx * dt;
|
|
6990
|
+
particle.y += particle.vy * dt;
|
|
6991
|
+
particle.z += particle.vz * dt;
|
|
6992
|
+
}
|
|
6938
6993
|
particle.rx += particle.spin[0] * dt;
|
|
6939
6994
|
particle.ry += particle.spin[1] * dt;
|
|
6940
6995
|
particle.rz += particle.spin[2] * dt;
|
|
@@ -6945,6 +7000,30 @@ var MeshPool = class {
|
|
|
6945
7000
|
clear() {
|
|
6946
7001
|
this.particles.length = 0;
|
|
6947
7002
|
}
|
|
7003
|
+
/** Puts every carried piece where its carrier is now (after the frame moved the thing it belongs to). */
|
|
7004
|
+
follow() {
|
|
7005
|
+
for (const particle of this.particles) if (particle.carried) this.place(particle);
|
|
7006
|
+
}
|
|
7007
|
+
/** A carried piece: how far its own velocity took it, then its place on the carrier. */
|
|
7008
|
+
ride(particle, dt) {
|
|
7009
|
+
const drift = particle.drift;
|
|
7010
|
+
drift[0] += particle.vx * dt;
|
|
7011
|
+
drift[1] += particle.vy * dt;
|
|
7012
|
+
drift[2] += particle.vz * dt;
|
|
7013
|
+
this.place(particle);
|
|
7014
|
+
}
|
|
7015
|
+
/** A carried piece's place on the carrier now plus its drift, turned with the carrier. */
|
|
7016
|
+
place(particle) {
|
|
7017
|
+
const carried = particle.carried;
|
|
7018
|
+
if (!carried) return;
|
|
7019
|
+
const drift = particle.drift;
|
|
7020
|
+
const [x, y, z] = carriedPoint(carried);
|
|
7021
|
+
particle.x = x + drift[0];
|
|
7022
|
+
particle.y = y + drift[1];
|
|
7023
|
+
particle.z = z + drift[2];
|
|
7024
|
+
const turn = carried.carrier.orientation;
|
|
7025
|
+
if (turn) particle.frame = particle.roll ? multiply(turn, particle.roll) : turn;
|
|
7026
|
+
}
|
|
6948
7027
|
};
|
|
6949
7028
|
|
|
6950
7029
|
// src/workshop/sprites.ts
|
|
@@ -7313,8 +7392,8 @@ var FlashLightPool = class {
|
|
|
7313
7392
|
}
|
|
7314
7393
|
flash(point, color, intensity, duration, distance, force, steady) {
|
|
7315
7394
|
const { level } = this.context.quality;
|
|
7316
|
-
if (level >= 1 && !force) return;
|
|
7317
|
-
if (level >= 2 && force !== "boom") return;
|
|
7395
|
+
if (level >= 1 && !force) return void 0;
|
|
7396
|
+
if (level >= 2 && force !== "boom") return void 0;
|
|
7318
7397
|
const light = this.lights[this.next++ % LIGHT_CAPACITY];
|
|
7319
7398
|
light.x = point[0];
|
|
7320
7399
|
light.y = point[1];
|
|
@@ -7326,17 +7405,24 @@ var FlashLightPool = class {
|
|
|
7326
7405
|
light.t = 0;
|
|
7327
7406
|
light.steady = steady === true;
|
|
7328
7407
|
light.intensity = intensity;
|
|
7408
|
+
light.carried = void 0;
|
|
7409
|
+
return light;
|
|
7329
7410
|
}
|
|
7330
7411
|
clear() {
|
|
7331
7412
|
for (const light of this.lights) light.intensity = 0;
|
|
7332
7413
|
for (const light of this.fire) light.intensity = 0;
|
|
7333
7414
|
}
|
|
7415
|
+
/** Puts every carried light that burns where its carrier is now. */
|
|
7416
|
+
follow() {
|
|
7417
|
+
for (const light of this.lights) if (light.intensity > 0 && light.carried) [light.x, light.y, light.z] = carriedPoint(light.carried);
|
|
7418
|
+
}
|
|
7334
7419
|
update(dt) {
|
|
7335
7420
|
for (const light of this.lights) {
|
|
7336
7421
|
if (light.intensity <= 0) continue;
|
|
7337
7422
|
light.t += dt;
|
|
7338
7423
|
const age = light.t / light.duration;
|
|
7339
7424
|
light.intensity = age >= 1 ? 0 : light.steady ? light.peak : light.peak * (1 - age) * (1 - age);
|
|
7425
|
+
if (light.carried) [light.x, light.y, light.z] = carriedPoint(light.carried);
|
|
7340
7426
|
}
|
|
7341
7427
|
}
|
|
7342
7428
|
};
|
|
@@ -7346,7 +7432,7 @@ var QUALITY_MULTIPLIERS = [1, 0.5, 0.2];
|
|
|
7346
7432
|
var FIRE_FLICKER_SWAY = 0.25;
|
|
7347
7433
|
var FIRE_FLICKER_JITTER = 0.08;
|
|
7348
7434
|
var LENS_FADE = 0.16;
|
|
7349
|
-
function
|
|
7435
|
+
function rotate2(q, v) {
|
|
7350
7436
|
const [qx, qy, qz, qw] = q;
|
|
7351
7437
|
const ix = qw * v[0] + qy * v[2] - qz * v[1];
|
|
7352
7438
|
const iy = qw * v[1] + qz * v[0] - qx * v[2];
|
|
@@ -7404,7 +7490,7 @@ var WorkshopEngine = class {
|
|
|
7404
7490
|
if (!placement) return point;
|
|
7405
7491
|
const { anchor, origin, yaw, orientation } = placement;
|
|
7406
7492
|
if (orientation) {
|
|
7407
|
-
const turned =
|
|
7493
|
+
const turned = rotate2(orientation, [point[0] - anchor[0], point[1] - anchor[1], point[2] - anchor[2]]);
|
|
7408
7494
|
return [origin[0] + turned[0], origin[1] + turned[1], origin[2] + turned[2]];
|
|
7409
7495
|
}
|
|
7410
7496
|
const x = point[0] - anchor[0];
|
|
@@ -7413,11 +7499,20 @@ var WorkshopEngine = class {
|
|
|
7413
7499
|
const sin2 = Math.sin(yaw);
|
|
7414
7500
|
return [origin[0] + cos2 * x + sin2 * z, origin[1] + point[1] - anchor[1], origin[2] - sin2 * x + cos2 * z];
|
|
7415
7501
|
}
|
|
7502
|
+
/** A point of the recipe's space from the anchor, turned by the placement's yaw when it has no orientation (the carrier turns the rest). */
|
|
7503
|
+
local(point) {
|
|
7504
|
+
const placement = this.placement;
|
|
7505
|
+
if (!placement) return point;
|
|
7506
|
+
const offset = [point[0] - placement.anchor[0], point[1] - placement.anchor[1], point[2] - placement.anchor[2]];
|
|
7507
|
+
if (placement.carrier?.orientation) return offset;
|
|
7508
|
+
const turned = this.place(point);
|
|
7509
|
+
return [turned[0] - placement.origin[0], turned[1] - placement.origin[1], turned[2] - placement.origin[2]];
|
|
7510
|
+
}
|
|
7416
7511
|
/** A direction or velocity of the recipe's space in the world. */
|
|
7417
7512
|
turn(vector2) {
|
|
7418
7513
|
const placement = this.placement;
|
|
7419
7514
|
if (!placement) return vector2;
|
|
7420
|
-
if (placement.orientation) return
|
|
7515
|
+
if (placement.orientation) return rotate2(placement.orientation, vector2);
|
|
7421
7516
|
const cos2 = Math.cos(placement.yaw);
|
|
7422
7517
|
const sin2 = Math.sin(placement.yaw);
|
|
7423
7518
|
return [cos2 * vector2[0] + sin2 * vector2[2], vector2[1], -sin2 * vector2[0] + cos2 * vector2[2]];
|
|
@@ -7452,7 +7547,8 @@ var WorkshopEngine = class {
|
|
|
7452
7547
|
const options = placement ? { ...recipe, p: this.place(recipe.p), ...recipe.v ? { v: this.turn(recipe.v) } : {} } : recipe;
|
|
7453
7548
|
this.context.trace?.("mesh", [options]);
|
|
7454
7549
|
const grouped = recipe.at !== void 0 || recipe.roll !== void 0;
|
|
7455
|
-
|
|
7550
|
+
const carried = placement?.carrier && grouped ? { carrier: placement.carrier, local: this.local(recipe.p) } : void 0;
|
|
7551
|
+
return this.meshes.spawn(options, placement && grouped ? placement.orientation ?? [0, Math.sin(placement.yaw / 2), 0, Math.cos(placement.yaw / 2)] : void 0, carried);
|
|
7456
7552
|
}
|
|
7457
7553
|
debrisPiece(recipe) {
|
|
7458
7554
|
const options = this.placed(recipe);
|
|
@@ -7476,9 +7572,11 @@ var WorkshopEngine = class {
|
|
|
7476
7572
|
}
|
|
7477
7573
|
/** `steady` (a seventh number): the light holds its intensity for its duration and goes out, where the Workshop's fades with the square of its age. */
|
|
7478
7574
|
flash(recipe) {
|
|
7479
|
-
const
|
|
7575
|
+
const placement = this.placement;
|
|
7576
|
+
const args = placement ? [this.place(recipe[0]), recipe[1], recipe[2], recipe[3], recipe[4], recipe[5], recipe[6]] : recipe;
|
|
7480
7577
|
this.context.trace?.("flash", args.slice(0, 6));
|
|
7481
|
-
this.lights.flash(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
|
|
7578
|
+
const light = this.lights.flash(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
|
|
7579
|
+
if (light && placement?.carrier) light.carried = { carrier: placement.carrier, local: this.local(recipe[0]) };
|
|
7482
7580
|
}
|
|
7483
7581
|
/** `fireLight` (W400): sways with the clock and flickers with one draw. */
|
|
7484
7582
|
fireLight(slot, recipe, intensity, time) {
|
|
@@ -7641,6 +7739,12 @@ function createVfx(options = {}) {
|
|
|
7641
7739
|
const seed = playOptions.seed ?? (randomMode === "shared" ? void 0 : Math.imul(++handles.events, AUTO_SEED) + (options.seed ?? 0));
|
|
7642
7740
|
return effectPlayer().play(id, [point[0], point[1], point[2]], { ...playOptions, ...seed !== void 0 ? { seed } : {} });
|
|
7643
7741
|
},
|
|
7742
|
+
follow() {
|
|
7743
|
+
if (!engine || !player?.retrack()) return false;
|
|
7744
|
+
engine.meshes.follow();
|
|
7745
|
+
engine.lights.follow();
|
|
7746
|
+
return true;
|
|
7747
|
+
},
|
|
7644
7748
|
burst: (kind, point, normal, count, speed, spriteOptions) => spriteSystem.burst(kind, point, normal, count, speed, spriteOptions),
|
|
7645
7749
|
spawn: (kind, point, velocity, spriteOptions) => spriteSystem.spawn(kind, point, velocity, spriteOptions),
|
|
7646
7750
|
onLand: (owner, listener) => spriteSystem.onLand(owner, listener),
|
|
@@ -7766,6 +7870,7 @@ function createVfx(options = {}) {
|
|
|
7766
7870
|
}),
|
|
7767
7871
|
fires: () => core.fires.items,
|
|
7768
7872
|
onMarks: (listener) => core.marks.subscribe(listener),
|
|
7873
|
+
scrape: (mark) => addScrape(core.marks, mark),
|
|
7769
7874
|
time: () => core.clock.time,
|
|
7770
7875
|
randomState: () => sharedRandom.state,
|
|
7771
7876
|
clear() {
|
|
@@ -8646,7 +8751,7 @@ function ease3(value) {
|
|
|
8646
8751
|
function mix(from, to, amount) {
|
|
8647
8752
|
return [from[0] + (to[0] - from[0]) * amount, from[1] + (to[1] - from[1]) * amount, from[2] + (to[2] - from[2]) * amount];
|
|
8648
8753
|
}
|
|
8649
|
-
function
|
|
8754
|
+
function rotate3(local2, x, y, z, w) {
|
|
8650
8755
|
const [vx2, vy2, vz2] = local2;
|
|
8651
8756
|
const ix = w * vx2 + y * vz2 - z * vy2;
|
|
8652
8757
|
const iy = w * vy2 + z * vx2 - x * vz2;
|
|
@@ -8704,7 +8809,7 @@ var EffectCamera = class {
|
|
|
8704
8809
|
/** A direction given in the camera's own axes, in world axes. */
|
|
8705
8810
|
forward(local2) {
|
|
8706
8811
|
const [x, y, z, w] = lookAtQuaternion(this.position, this.target);
|
|
8707
|
-
return
|
|
8812
|
+
return rotate3(local2, x, y, z, w);
|
|
8708
8813
|
}
|
|
8709
8814
|
};
|
|
8710
8815
|
|
|
@@ -8872,6 +8977,7 @@ export {
|
|
|
8872
8977
|
PROFILES,
|
|
8873
8978
|
RAIN_CAPACITY,
|
|
8874
8979
|
RainField,
|
|
8980
|
+
SCRAPE_LIMIT,
|
|
8875
8981
|
SMOKE_COLORS,
|
|
8876
8982
|
SPRITE_KINDS,
|
|
8877
8983
|
SpriteKindPool,
|