@adatechnology/game-vfx 0.15.0 → 0.16.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/dist/index.js CHANGED
@@ -1426,6 +1426,8 @@ var Enclosures = class {
1426
1426
  __publicField(this, "l0", new Float64Array(3));
1427
1427
  __publicField(this, "l1", new Float64Array(3));
1428
1428
  __publicField(this, "q", new Float64Array(3));
1429
+ __publicField(this, "h", new Float64Array(3));
1430
+ __publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 });
1429
1431
  this.random = lehmer(seed);
1430
1432
  }
1431
1433
  get empty() {
@@ -1501,9 +1503,21 @@ var Enclosures = class {
1501
1503
  return this.chance(s.leak, dt);
1502
1504
  }
1503
1505
  confine(x0, y0, z0, x1, y1, z1, pad, dt) {
1506
+ const move = this.move;
1507
+ move.x0 = x0;
1508
+ move.y0 = y0;
1509
+ move.z0 = z0;
1510
+ move.x1 = x1;
1511
+ move.y1 = y1;
1512
+ move.z1 = z1;
1513
+ move.pad = pad;
1514
+ return this.confineMove(move, dt);
1515
+ }
1516
+ confineMove(move, dt) {
1504
1517
  const list = this.list;
1505
1518
  if (list.length === 0) return false;
1506
- const p = Math.min(Math.max(0, pad), MAX_PAD);
1519
+ const { x0, y0, z0, x1, y1, z1 } = move;
1520
+ const p = Math.min(Math.max(0, move.pad), MAX_PAD);
1507
1521
  const l0 = this.l0;
1508
1522
  const l1 = this.l1;
1509
1523
  const q = this.q;
@@ -1520,7 +1534,10 @@ var Enclosures = class {
1520
1534
  }
1521
1535
  this.toLocal(s, x0, y0, z0, l0);
1522
1536
  this.toLocal(s, x1, y1, z1, l1);
1523
- const h = [s.hx, s.hy, s.hz];
1537
+ const h = this.h;
1538
+ h[0] = s.hx;
1539
+ h[1] = s.hy;
1540
+ h[2] = s.hz;
1524
1541
  const in0 = Math.abs(l0[0]) <= s.hx && Math.abs(l0[1]) <= s.hy && Math.abs(l0[2]) <= s.hz;
1525
1542
  let axis2 = 0;
1526
1543
  let sign = 1;
@@ -1569,6 +1586,13 @@ var Enclosures = class {
1569
1586
  return false;
1570
1587
  }
1571
1588
  };
1589
+ function slideInto(out, velocity) {
1590
+ const into = velocity.vx * out.nx + velocity.vy * out.ny + velocity.vz * out.nz;
1591
+ if (into >= 0) return;
1592
+ velocity.vx -= into * out.nx;
1593
+ velocity.vy -= into * out.ny;
1594
+ velocity.vz -= into * out.nz;
1595
+ }
1572
1596
  function slideAlong(out, vx2, vy2, vz2) {
1573
1597
  const into = vx2 * out.nx + vy2 * out.ny + vz2 * out.nz;
1574
1598
  if (into >= 0) return [vx2, vy2, vz2];
@@ -1583,6 +1607,7 @@ var ARRIVAL_BASE = 0.3;
1583
1607
  var GROWTH_CAP_SECONDS = 3.5;
1584
1608
  var CARRIED_KINDS = [true, true, false, true, false];
1585
1609
  var PAD_OF_SIZE = 0.35;
1610
+ var MOVE = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
1586
1611
  function createPuffPool(capacity) {
1587
1612
  const placeholder = { next: () => 0, between: (min2) => min2, direction: (out) => out, state: 0 };
1588
1613
  return new OrderedPool(capacity, () => ({
@@ -1679,23 +1704,30 @@ function moveFree(puff3, dt, age, heat, wind) {
1679
1704
  if (puff3.vy < 0) puff3.vy *= FLOOR_BOUNCE;
1680
1705
  }
1681
1706
  }
1707
+ function confine(confiner, puff3, dt) {
1708
+ MOVE.x1 = puff3.x;
1709
+ MOVE.y1 = puff3.y;
1710
+ MOVE.z1 = puff3.z;
1711
+ MOVE.pad = puff3.size * PAD_OF_SIZE;
1712
+ return confiner.confineMove(MOVE, dt);
1713
+ }
1682
1714
  function updatePuffs(pool, dt, wind, confiner) {
1683
1715
  pool.compact(ageOrKeep2, dt);
1684
1716
  const confining = confiner !== void 0 && !confiner.empty;
1685
1717
  for (const puff3 of pool.items) {
1686
1718
  const age = puff3.t / puff3.life;
1687
1719
  const heat = puff3.h0 > 0 ? puff3.h0 * Math.pow(Math.max(0, 1 - puff3.t / puff3.hl), 1.25) : 0;
1688
- const x0 = puff3.x;
1689
- const y0 = puff3.y;
1690
- const z0 = puff3.z;
1720
+ MOVE.x0 = puff3.x;
1721
+ MOVE.y0 = puff3.y;
1722
+ MOVE.z0 = puff3.z;
1691
1723
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
1692
1724
  else moveFree(puff3, dt, age, heat, wind);
1693
- if (confining && CARRIED_KINDS[puff3.kind] && confiner.confine(x0, y0, z0, puff3.x, puff3.y, puff3.z, puff3.size * PAD_OF_SIZE, dt)) {
1725
+ if (confining && CARRIED_KINDS[puff3.kind] && confine(confiner, puff3, dt)) {
1694
1726
  const out = confiner.out;
1695
1727
  puff3.x = out.x;
1696
1728
  puff3.y = out.y;
1697
1729
  puff3.z = out.z;
1698
- [puff3.vx, puff3.vy, puff3.vz] = slideAlong(out, puff3.vx, puff3.vy, puff3.vz);
1730
+ slideInto(out, puff3);
1699
1731
  }
1700
1732
  const size = puff3.s0 + (puff3.s1 - puff3.s0) * (1 - Math.exp(-puff3.t * puff3.gk)) + puff3.sg * Math.min(puff3.t, GROWTH_CAP_SECONDS);
1701
1733
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
@@ -3702,6 +3734,8 @@ var COUGH_AND_BREATH = {
3702
3734
  var DEBRIS_EFFECT_FAMILIES = ["wood", "masonry", "glass", "metal", "soft", "soil"];
3703
3735
  var DEBRIS_COLOR_VARIABLE = "debrisColor";
3704
3736
  var DUST_COLOR_VARIABLE = "dustColor";
3737
+ var PIECES_DRAWN_VARIABLE = "piecesDrawn";
3738
+ var standIns = (...steps) => when(not(variable(PIECES_DRAWN_VARIABLE)), steps);
3705
3739
  var FAMILIES = {
3706
3740
  wood: { debris: 8017200, dust: 10127986, piece: [0.015, 0.015, 0.1], spin: 6, cloud: 0.5, sparks: false, glints: false },
3707
3741
  masonry: { debris: 10197652, dust: 11052187, piece: [0.035, 0.028, 0.035], spin: 4, cloud: 1, sparks: false, glints: false },
@@ -3748,7 +3782,7 @@ function breachDust(family) {
3748
3782
  ...sparks(look, 14),
3749
3783
  ...glints(look, 20),
3750
3784
  burst("normal", Math.round(30 * look.cloud), { p: ORIGIN, box: [1.4, 0.8, 0.2], sp: [0.3, 1.2], drag: 1.5, life: [1.5, 2.6], size: [0.4, 0.7], grow: 3, c0: dustTone(look), c1: 4867648, a: 0.45 }),
3751
- repeat(scaled(16), debris({ p: ORIGIN, box: [1.3, 0.8, 0.1], sp: [1, 3], size: grow(look.piece, 2.2), k: [0.5, 1.5], spin: look.spin, c: debrisTone(look), life: 20 })),
3785
+ standIns(repeat(scaled(16), debris({ p: ORIGIN, box: [1.3, 0.8, 0.1], sp: [1, 3], size: grow(look.piece, 2.2), k: [0.5, 1.5], spin: look.spin, c: debrisTone(look), life: 20 }))),
3752
3786
  repeat(
3753
3787
  scaled(Math.round(60 * look.cloud)),
3754
3788
  spawn("normal", local("angle", rnd(0, 6.283), {
@@ -3780,8 +3814,10 @@ function collapseDust(family) {
3780
3814
  timeline: [
3781
3815
  screen({ add: { shake: 0.45 } }),
3782
3816
  ...sparks(look, 20),
3783
- repeat(6, debris({ p: ORIGIN, box: [2, 0.05, 0.6], v: [rnd(-0.5, 0.5), rnd(-0.5, 0), rnd(0, 0.8)], sp: 0, size: [rnd(0.5, 1.1), look.piece[1] > 0.01 ? 0.25 : 0.03, rnd(0.4, 0.8)], c: debrisTone(look), spin: 3, life: 30, bounce: 0.1 })),
3784
- repeat(scaled(20), debris({ p: ORIGIN, box: [2.1, 0.1, 0.7], v: [rnd(-1, 1), rnd(-1, 1), rnd(0, 1.5)], sp: 0, size: grow(look.piece, 3.4), k: [0.5, 1.5], spin: look.spin, c: debrisTone(look), life: 30 })),
3817
+ standIns(
3818
+ repeat(6, debris({ p: ORIGIN, box: [2, 0.05, 0.6], v: [rnd(-0.5, 0.5), rnd(-0.5, 0), rnd(0, 0.8)], sp: 0, size: [rnd(0.5, 1.1), look.piece[1] > 0.01 ? 0.25 : 0.03, rnd(0.4, 0.8)], c: debrisTone(look), spin: 3, life: 30, bounce: 0.1 })),
3819
+ repeat(scaled(20), debris({ p: ORIGIN, box: [2.1, 0.1, 0.7], v: [rnd(-1, 1), rnd(-1, 1), rnd(0, 1.5)], sp: 0, size: grow(look.piece, 3.4), k: [0.5, 1.5], spin: look.spin, c: debrisTone(look), life: 30 }))
3820
+ ),
3785
3821
  repeat(
3786
3822
  scaled(Math.round(70 * look.cloud)),
3787
3823
  spawn("normal", local("angle", rnd(-0.4, 3.5), {
@@ -7524,6 +7560,7 @@ var QUALITY_MULTIPLIERS = [1, 0.5, 0.2];
7524
7560
  var FIRE_FLICKER_SWAY = 0.25;
7525
7561
  var FIRE_FLICKER_JITTER = 0.08;
7526
7562
  var LENS_FADE = 0.16;
7563
+ var FLOOR_NORMAL_Y = 0.9;
7527
7564
  function rotate2(q, v) {
7528
7565
  const [qx, qy, qz, qw] = q;
7529
7566
  const ix = qw * v[0] + qy * v[2] - qz * v[1];
@@ -7652,7 +7689,9 @@ var WorkshopEngine = class {
7652
7689
  if (this.placement) {
7653
7690
  const [x, y, z] = this.place([recipe[0], recipe[1], recipe[2]]);
7654
7691
  const options = recipe[5];
7655
- args = [x, y, z, recipe[3], recipe[4], options?.n ? { ...options, n: this.turn(options.n) } : options];
7692
+ const normal = options?.n ? this.turn(options.n) : void 0;
7693
+ const onFloor = !normal || normal[1] > FLOOR_NORMAL_Y;
7694
+ args = [x, onFloor ? this.context.groundAt(x, z) : y, z, recipe[3], recipe[4], normal ? { ...options, n: normal } : options];
7656
7695
  }
7657
7696
  this.context.trace?.("decal", args);
7658
7697
  this.decals.add(args[0], args[1], args[2], args[3], args[4], args[5]);
@@ -7834,6 +7873,21 @@ function createVfx(options = {}) {
7834
7873
  return {
7835
7874
  hostGroundAt: options.groundAt,
7836
7875
  play(id, point, playOptions = {}) {
7876
+ if (id === "volumetric_fire") {
7877
+ const values = playOptions.values;
7878
+ const handle = ++handles.next;
7879
+ addFire(core, streamOf(playOptions.seed), {
7880
+ x: point[0],
7881
+ y: point[1],
7882
+ z: point[2],
7883
+ r: values?.radius ?? 0.55,
7884
+ life: values?.life ?? 24,
7885
+ ...values?.rate !== void 0 ? { rate: values.rate } : {},
7886
+ ...values?.smoke !== void 0 ? { smoke: values.smoke } : {},
7887
+ ...values?.smokeColor !== void 0 ? { color: hexToLinearRgb(values.smokeColor) } : {}
7888
+ }, handle);
7889
+ return handle;
7890
+ }
7837
7891
  if (!(id in effects)) return null;
7838
7892
  const seed = playOptions.seed ?? (randomMode === "shared" ? void 0 : Math.imul(++handles.events, AUTO_SEED) + (options.seed ?? 0));
7839
7893
  return effectPlayer().play(id, [point[0], point[1], point[2]], { ...playOptions, ...seed !== void 0 ? { seed } : {} });
@@ -7850,7 +7904,7 @@ function createVfx(options = {}) {
7850
7904
  sprites: () => spriteSystem,
7851
7905
  workshop,
7852
7906
  peekWorkshop: () => engine,
7853
- effectIds: () => Object.keys(effects),
7907
+ effectIds: () => "volumetric_fire" in effects ? Object.keys(effects) : [...Object.keys(effects), "volumetric_fire"],
7854
7908
  explosion(id, point, explosionOptions = {}) {
7855
7909
  const base = definitionOf(id);
7856
7910
  if (!base) return null;
@@ -9760,6 +9814,7 @@ export {
9760
9814
  MATERIAL_EVENT_EFFECTS,
9761
9815
  MeshPool,
9762
9816
  OrderedPool,
9817
+ PIECES_DRAWN_VARIABLE,
9763
9818
  PROFILES,
9764
9819
  RAIN_CAPACITY,
9765
9820
  RainField,
@@ -9809,6 +9864,7 @@ export {
9809
9864
  resolveWaterBlast,
9810
9865
  resolveWaterShotProfile,
9811
9866
  slideAlong,
9867
+ slideInto,
9812
9868
  streamFor,
9813
9869
  updateScreen,
9814
9870
  waterShotClassOf,