@adatechnology/game-vfx-three 0.10.3 → 0.10.4

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.
@@ -57,15 +57,37 @@ var GameVfxThree = (() => {
57
57
  var DEFERRED_QUEUE_ID = {
58
58
  DESTRUCTION_EVENTS: "destruction.events",
59
59
  BREACH_PAINT: "floorplan.breach-paint",
60
+ BREACH_CUT: "floorplan.breach-cut",
60
61
  AUDIO_VOICES: "audio.voices",
61
- VEHICLE_CREASE: "vehicles.crease"
62
+ VEHICLE_CREASE: "vehicles.crease",
63
+ AUDIO_OCCLUSION: "audio.occlusion",
64
+ FLUID_FILM: "fluids.film",
65
+ VEHICLE_LOD_BATCH: "vehicles.lod-batch",
66
+ SETTLED_BATCH: "destruction.settled-batch",
67
+ STATIC_BATCH: "render.static-batch",
68
+ ANIMALS_STATIC_BATCH: "animals.static-batch",
69
+ CHARACTERS_STATIC_BATCH: "characters.static-batch",
70
+ HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
71
+ DESTRUCTION_PREFIT: "destruction.prefit"
62
72
  };
63
73
  var DEFERRED_PRIORITY = {
64
74
  [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
65
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
75
+ // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
76
+ [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
77
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
66
78
  [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
67
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
79
+ [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
80
+ [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
81
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
82
+ [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
83
+ [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
84
+ [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
85
+ [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
86
+ [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
87
+ [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
88
+ [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
68
89
  };
90
+ var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
69
91
  var KIT_ORIGIN_KEY = "kitOrigin";
70
92
  function markKitOrigin(object, origin) {
71
93
  const node = object;
@@ -109,6 +131,22 @@ var GameVfxThree = (() => {
109
131
  var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
110
132
  var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
111
133
  var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
134
+ var WORKER_KIND_ID = {
135
+ GROUND_TILES: "destruction.ground-tiles",
136
+ CROWD_PHYSICS: "crowd.physics",
137
+ PIECE_BOXES: "destruction.piece-boxes",
138
+ STATIC_COLLIDERS: "destruction.static-colliders",
139
+ SHAPES_GENERATE: "shapes.generate",
140
+ WORLD_REGION: "world.region"
141
+ };
142
+ var WORKER_KIND_DEFAULTS = {
143
+ [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
144
+ [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
145
+ [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
146
+ [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
147
+ [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
148
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
149
+ };
112
150
 
113
151
  // ../game-vfx/dist/index.js
114
152
  var __defProp2 = Object.defineProperty;
@@ -1475,6 +1513,8 @@ var GameVfxThree = (() => {
1475
1513
  __publicField(this, "l0", new Float64Array(3));
1476
1514
  __publicField(this, "l1", new Float64Array(3));
1477
1515
  __publicField(this, "q", new Float64Array(3));
1516
+ __publicField(this, "h", new Float64Array(3));
1517
+ __publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 });
1478
1518
  this.random = lehmer(seed);
1479
1519
  }
1480
1520
  get empty() {
@@ -1550,9 +1590,21 @@ var GameVfxThree = (() => {
1550
1590
  return this.chance(s.leak, dt);
1551
1591
  }
1552
1592
  confine(x0, y0, z0, x1, y1, z1, pad, dt) {
1593
+ const move = this.move;
1594
+ move.x0 = x0;
1595
+ move.y0 = y0;
1596
+ move.z0 = z0;
1597
+ move.x1 = x1;
1598
+ move.y1 = y1;
1599
+ move.z1 = z1;
1600
+ move.pad = pad;
1601
+ return this.confineMove(move, dt);
1602
+ }
1603
+ confineMove(move, dt) {
1553
1604
  const list = this.list;
1554
1605
  if (list.length === 0) return false;
1555
- const p = Math.min(Math.max(0, pad), MAX_PAD);
1606
+ const { x0, y0, z0, x1, y1, z1 } = move;
1607
+ const p = Math.min(Math.max(0, move.pad), MAX_PAD);
1556
1608
  const l0 = this.l0;
1557
1609
  const l1 = this.l1;
1558
1610
  const q = this.q;
@@ -1569,7 +1621,10 @@ var GameVfxThree = (() => {
1569
1621
  }
1570
1622
  this.toLocal(s, x0, y0, z0, l0);
1571
1623
  this.toLocal(s, x1, y1, z1, l1);
1572
- const h = [s.hx, s.hy, s.hz];
1624
+ const h = this.h;
1625
+ h[0] = s.hx;
1626
+ h[1] = s.hy;
1627
+ h[2] = s.hz;
1573
1628
  const in0 = Math.abs(l0[0]) <= s.hx && Math.abs(l0[1]) <= s.hy && Math.abs(l0[2]) <= s.hz;
1574
1629
  let axis2 = 0;
1575
1630
  let sign = 1;
@@ -1618,6 +1673,13 @@ var GameVfxThree = (() => {
1618
1673
  return false;
1619
1674
  }
1620
1675
  };
1676
+ function slideInto(out, velocity) {
1677
+ const into = velocity.vx * out.nx + velocity.vy * out.ny + velocity.vz * out.nz;
1678
+ if (into >= 0) return;
1679
+ velocity.vx -= into * out.nx;
1680
+ velocity.vy -= into * out.ny;
1681
+ velocity.vz -= into * out.nz;
1682
+ }
1621
1683
  function slideAlong(out, vx2, vy2, vz2) {
1622
1684
  const into = vx2 * out.nx + vy2 * out.ny + vz2 * out.nz;
1623
1685
  if (into >= 0) return [vx2, vy2, vz2];
@@ -1630,6 +1692,7 @@ var GameVfxThree = (() => {
1630
1692
  var GROWTH_CAP_SECONDS = 3.5;
1631
1693
  var CARRIED_KINDS = [true, true, false, true, false];
1632
1694
  var PAD_OF_SIZE = 0.35;
1695
+ var MOVE = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
1633
1696
  function createPuffPool(capacity) {
1634
1697
  const placeholder = { next: () => 0, between: (min2) => min2, direction: (out) => out, state: 0 };
1635
1698
  return new OrderedPool(capacity, () => ({
@@ -1726,23 +1789,30 @@ var GameVfxThree = (() => {
1726
1789
  if (puff3.vy < 0) puff3.vy *= FLOOR_BOUNCE;
1727
1790
  }
1728
1791
  }
1792
+ function confine(confiner, puff3, dt) {
1793
+ MOVE.x1 = puff3.x;
1794
+ MOVE.y1 = puff3.y;
1795
+ MOVE.z1 = puff3.z;
1796
+ MOVE.pad = puff3.size * PAD_OF_SIZE;
1797
+ return confiner.confineMove(MOVE, dt);
1798
+ }
1729
1799
  function updatePuffs(pool, dt, wind, confiner) {
1730
1800
  pool.compact(ageOrKeep2, dt);
1731
1801
  const confining = confiner !== void 0 && !confiner.empty;
1732
1802
  for (const puff3 of pool.items) {
1733
1803
  const age = puff3.t / puff3.life;
1734
1804
  const heat = puff3.h0 > 0 ? puff3.h0 * Math.pow(Math.max(0, 1 - puff3.t / puff3.hl), 1.25) : 0;
1735
- const x0 = puff3.x;
1736
- const y0 = puff3.y;
1737
- const z0 = puff3.z;
1805
+ MOVE.x0 = puff3.x;
1806
+ MOVE.y0 = puff3.y;
1807
+ MOVE.z0 = puff3.z;
1738
1808
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
1739
1809
  else moveFree(puff3, dt, age, heat, wind);
1740
- if (confining && CARRIED_KINDS[puff3.kind] && confiner.confine(x0, y0, z0, puff3.x, puff3.y, puff3.z, puff3.size * PAD_OF_SIZE, dt)) {
1810
+ if (confining && CARRIED_KINDS[puff3.kind] && confine(confiner, puff3, dt)) {
1741
1811
  const out = confiner.out;
1742
1812
  puff3.x = out.x;
1743
1813
  puff3.y = out.y;
1744
1814
  puff3.z = out.z;
1745
- [puff3.vx, puff3.vy, puff3.vz] = slideAlong(out, puff3.vx, puff3.vy, puff3.vz);
1815
+ slideInto(out, puff3);
1746
1816
  }
1747
1817
  const size = puff3.s0 + (puff3.s1 - puff3.s0) * (1 - Math.exp(-puff3.t * puff3.gk)) + puff3.sg * Math.min(puff3.t, GROWTH_CAP_SECONDS);
1748
1818
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
@@ -3642,6 +3712,8 @@ var GameVfxThree = (() => {
3642
3712
  var DEBRIS_EFFECT_FAMILIES = ["wood", "masonry", "glass", "metal", "soft", "soil"];
3643
3713
  var DEBRIS_COLOR_VARIABLE = "debrisColor";
3644
3714
  var DUST_COLOR_VARIABLE = "dustColor";
3715
+ var PIECES_DRAWN_VARIABLE = "piecesDrawn";
3716
+ var standIns = (...steps) => when(not(variable(PIECES_DRAWN_VARIABLE)), steps);
3645
3717
  var FAMILIES = {
3646
3718
  wood: { debris: 8017200, dust: 10127986, piece: [0.015, 0.015, 0.1], spin: 6, cloud: 0.5, sparks: false, glints: false },
3647
3719
  masonry: { debris: 10197652, dust: 11052187, piece: [0.035, 0.028, 0.035], spin: 4, cloud: 1, sparks: false, glints: false },
@@ -3688,7 +3760,7 @@ var GameVfxThree = (() => {
3688
3760
  ...sparks(look, 14),
3689
3761
  ...glints(look, 20),
3690
3762
  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 }),
3691
- 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 })),
3763
+ 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 }))),
3692
3764
  repeat(
3693
3765
  scaled(Math.round(60 * look.cloud)),
3694
3766
  spawn("normal", local("angle", rnd(0, 6.283), {
@@ -3720,8 +3792,10 @@ var GameVfxThree = (() => {
3720
3792
  timeline: [
3721
3793
  screen({ add: { shake: 0.45 } }),
3722
3794
  ...sparks(look, 20),
3723
- 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 })),
3724
- 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 })),
3795
+ standIns(
3796
+ 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 })),
3797
+ 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 }))
3798
+ ),
3725
3799
  repeat(
3726
3800
  scaled(Math.round(70 * look.cloud)),
3727
3801
  spawn("normal", local("angle", rnd(-0.4, 3.5), {
@@ -7351,6 +7425,7 @@ var GameVfxThree = (() => {
7351
7425
  var FIRE_FLICKER_SWAY = 0.25;
7352
7426
  var FIRE_FLICKER_JITTER = 0.08;
7353
7427
  var LENS_FADE = 0.16;
7428
+ var FLOOR_NORMAL_Y = 0.9;
7354
7429
  function rotate2(q, v) {
7355
7430
  const [qx, qy, qz, qw] = q;
7356
7431
  const ix = qw * v[0] + qy * v[2] - qz * v[1];
@@ -7478,7 +7553,9 @@ var GameVfxThree = (() => {
7478
7553
  if (this.placement) {
7479
7554
  const [x, y, z] = this.place([recipe[0], recipe[1], recipe[2]]);
7480
7555
  const options = recipe[5];
7481
- args = [x, y, z, recipe[3], recipe[4], options?.n ? { ...options, n: this.turn(options.n) } : options];
7556
+ const normal = options?.n ? this.turn(options.n) : void 0;
7557
+ const onFloor = !normal || normal[1] > FLOOR_NORMAL_Y;
7558
+ args = [x, onFloor ? this.context.groundAt(x, z) : y, z, recipe[3], recipe[4], normal ? { ...options, n: normal } : options];
7482
7559
  }
7483
7560
  this.context.trace?.("decal", args);
7484
7561
  this.decals.add(args[0], args[1], args[2], args[3], args[4], args[5]);
@@ -7656,6 +7733,21 @@ var GameVfxThree = (() => {
7656
7733
  return {
7657
7734
  hostGroundAt: options.groundAt,
7658
7735
  play(id, point, playOptions = {}) {
7736
+ if (id === "volumetric_fire") {
7737
+ const values = playOptions.values;
7738
+ const handle = ++handles.next;
7739
+ addFire(core, streamOf(playOptions.seed), {
7740
+ x: point[0],
7741
+ y: point[1],
7742
+ z: point[2],
7743
+ r: values?.radius ?? 0.55,
7744
+ life: values?.life ?? 24,
7745
+ ...values?.rate !== void 0 ? { rate: values.rate } : {},
7746
+ ...values?.smoke !== void 0 ? { smoke: values.smoke } : {},
7747
+ ...values?.smokeColor !== void 0 ? { color: hexToLinearRgb(values.smokeColor) } : {}
7748
+ }, handle);
7749
+ return handle;
7750
+ }
7659
7751
  if (!(id in effects)) return null;
7660
7752
  const seed = playOptions.seed ?? (randomMode === "shared" ? void 0 : Math.imul(++handles.events, AUTO_SEED) + (options.seed ?? 0));
7661
7753
  return effectPlayer().play(id, [point[0], point[1], point[2]], { ...playOptions, ...seed !== void 0 ? { seed } : {} });
@@ -7672,7 +7764,7 @@ var GameVfxThree = (() => {
7672
7764
  sprites: () => spriteSystem,
7673
7765
  workshop,
7674
7766
  peekWorkshop: () => engine,
7675
- effectIds: () => Object.keys(effects),
7767
+ effectIds: () => "volumetric_fire" in effects ? Object.keys(effects) : [...Object.keys(effects), "volumetric_fire"],
7676
7768
  explosion(id, point, explosionOptions = {}) {
7677
7769
  const base = definitionOf(id);
7678
7770
  if (!base) return null;
@@ -9722,6 +9814,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9722
9814
  }
9723
9815
  };
9724
9816
  }
9817
+ var REST_LAYER = 2e-3;
9818
+ var REST_LAYERS = 4;
9725
9819
  function debrisLayer(THREE, pool) {
9726
9820
  const geometry = new THREE.BoxGeometry(1, 1, 1);
9727
9821
  const material2 = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.45, metalness: 0.25, flatShading: true });
@@ -9752,7 +9846,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9752
9846
  const shrink = Math.min(1, piece.life / FADE_SECONDS2);
9753
9847
  euler.set(piece.rx, piece.ry, piece.rz);
9754
9848
  quaternion.setFromEuler(euler);
9755
- matrix.compose(position.set(piece.x, piece.y, piece.z), quaternion, scale.set(piece.sx * shrink, piece.sy * shrink, piece.sz * shrink));
9849
+ const lift = piece.rest ? index % REST_LAYERS * REST_LAYER : 0;
9850
+ matrix.compose(position.set(piece.x, piece.y + lift, piece.z), quaternion, scale.set(piece.sx * shrink, piece.sy * shrink, piece.sz * shrink));
9756
9851
  mesh2.setMatrixAt(index, matrix);
9757
9852
  mesh2.setColorAt(index, colour.setHex(piece.color));
9758
9853
  }
@@ -9874,7 +9969,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9874
9969
  }
9875
9970
  function ringLayer(THREE, pool) {
9876
9971
  const geometry = new THREE.RingGeometry(0.86, 1, 40);
9877
- const material2 = new THREE.MeshBasicMaterial({ color: 16777215, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide });
9972
+ const material2 = new THREE.MeshBasicMaterial({ color: 16777215, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide, forceSinglePass: true });
9878
9973
  const mesh2 = new THREE.InstancedMesh(geometry, material2, RING_CAPACITY3);
9879
9974
  mesh2.frustumCulled = false;
9880
9975
  mesh2.instanceMatrix.setUsage(THREE.DynamicDrawUsage);