@adatechnology/game-vfx 0.16.0 → 0.18.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
@@ -1395,8 +1395,61 @@ function streamFor(eventSeed) {
1395
1395
  return lehmer(mixEventSeed(eventSeed));
1396
1396
  }
1397
1397
 
1398
- // src/enclosures.ts
1398
+ // src/solids.ts
1399
1399
  var SKIN = 5e-3;
1400
+ var Solids = class {
1401
+ constructor() {
1402
+ __publicField(this, "queries", /* @__PURE__ */ new Map());
1403
+ __publicField(this, "list", []);
1404
+ __publicField(this, "hit", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
1405
+ }
1406
+ get empty() {
1407
+ return this.list.length === 0;
1408
+ }
1409
+ /** Declares or (with `null`) ends the solids `id` answers for. */
1410
+ set(id, query2) {
1411
+ if (query2) this.queries.set(id, query2);
1412
+ else this.queries.delete(id);
1413
+ this.list = [...this.queries.values()];
1414
+ }
1415
+ clear() {
1416
+ this.queries.clear();
1417
+ this.list = [];
1418
+ }
1419
+ /**
1420
+ * Stops a step that goes into a solid: `out` gets the nearest hit, put back `pad` metres off the surface (never behind where the step began) and
1421
+ * the surface's normal. Answers whether the step was stopped.
1422
+ */
1423
+ stop(move, pad, out) {
1424
+ const dx = move.x1 - move.x0;
1425
+ const dy = move.y1 - move.y0;
1426
+ const dz = move.z1 - move.z0;
1427
+ const length = Math.hypot(dx, dy, dz);
1428
+ if (!(length > 0)) return false;
1429
+ let nearest = Infinity;
1430
+ for (const query2 of this.list) {
1431
+ if (!query2(move, this.hit)) continue;
1432
+ const reached = ((this.hit.x - move.x0) * dx + (this.hit.y - move.y0) * dy + (this.hit.z - move.z0) * dz) / length;
1433
+ if (reached >= nearest) continue;
1434
+ nearest = reached;
1435
+ out.x = this.hit.x;
1436
+ out.y = this.hit.y;
1437
+ out.z = this.hit.z;
1438
+ out.nx = this.hit.nx;
1439
+ out.ny = this.hit.ny;
1440
+ out.nz = this.hit.nz;
1441
+ }
1442
+ if (nearest === Infinity) return false;
1443
+ const back = Math.min(Math.max(pad, 0) + SKIN, Math.max(nearest, 0));
1444
+ out.x -= dx / length * back;
1445
+ out.y -= dy / length * back;
1446
+ out.z -= dz / length * back;
1447
+ return true;
1448
+ }
1449
+ };
1450
+
1451
+ // src/enclosures.ts
1452
+ var SKIN2 = 5e-3;
1400
1453
  var MAX_PAD = 0.45;
1401
1454
  function rotation(q) {
1402
1455
  const [x, y, z, w] = q ?? [0, 0, 0, 1];
@@ -1428,10 +1481,15 @@ var Enclosures = class {
1428
1481
  __publicField(this, "q", new Float64Array(3));
1429
1482
  __publicField(this, "h", new Float64Array(3));
1430
1483
  __publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 });
1484
+ __publicField(this, "solids", new Solids());
1431
1485
  this.random = lehmer(seed);
1432
1486
  }
1433
1487
  get empty() {
1434
- return this.list.length === 0;
1488
+ return this.list.length === 0 && this.solids.empty;
1489
+ }
1490
+ /** Declares or (with `null`) ends the host solids `id` answers for (a destruction world's walls): what is carried stops at them and passes only their holes. */
1491
+ solid(id, query2) {
1492
+ this.solids.set(id, query2);
1435
1493
  }
1436
1494
  get size() {
1437
1495
  return this.list.length;
@@ -1514,6 +1572,10 @@ var Enclosures = class {
1514
1572
  return this.confineMove(move, dt);
1515
1573
  }
1516
1574
  confineMove(move, dt) {
1575
+ if (this.confineSpaces(move, dt)) return true;
1576
+ return !this.solids.empty && this.solids.stop(move, Math.min(Math.max(0, move.pad), MAX_PAD), this.out);
1577
+ }
1578
+ confineSpaces(move, dt) {
1517
1579
  const list = this.list;
1518
1580
  if (list.length === 0) return false;
1519
1581
  const { x0, y0, z0, x1, y1, z1 } = move;
@@ -1554,7 +1616,7 @@ var Enclosures = class {
1554
1616
  }
1555
1617
  }
1556
1618
  sign = l1[axis2] < 0 ? -1 : 1;
1557
- for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN, Math.max(-(h[a] - SKIN), l1[a]));
1619
+ for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN2, Math.max(-(h[a] - SKIN2), l1[a]));
1558
1620
  sign = -sign;
1559
1621
  } else {
1560
1622
  const padded0 = Math.abs(l0[0]) <= s.hx + p && Math.abs(l0[1]) <= s.hy + p && Math.abs(l0[2]) <= s.hz + p;
@@ -1571,7 +1633,7 @@ var Enclosures = class {
1571
1633
  }
1572
1634
  }
1573
1635
  sign = l0[axis2] < 0 ? -1 : 1;
1574
- l1[axis2] = sign * (h[axis2] + bound + SKIN);
1636
+ l1[axis2] = sign * (h[axis2] + bound + SKIN2);
1575
1637
  }
1576
1638
  const r = s.r;
1577
1639
  const out = this.out;
@@ -1830,6 +1892,7 @@ function createFirePool(capacity, placeholder) {
1830
1892
  y: 0,
1831
1893
  z: 0,
1832
1894
  r: 0.6,
1895
+ h: 0,
1833
1896
  r0: 0.6,
1834
1897
  grow: 0,
1835
1898
  life: 6,
@@ -1855,6 +1918,7 @@ function spawnFire(pool, random, init, handle) {
1855
1918
  fire.y = init.y ?? 0;
1856
1919
  fire.z = init.z ?? 0;
1857
1920
  fire.r = init.r ?? 0.6;
1921
+ fire.h = init.h ?? 0;
1858
1922
  fire.r0 = init.startRadius ?? fire.r;
1859
1923
  fire.grow = init.grow ?? 0;
1860
1924
  fire.life = init.life ?? 6;
@@ -1879,19 +1943,23 @@ function addFire(core, random, init, handle) {
1879
1943
  core.trace?.fire?.(fire);
1880
1944
  return fire;
1881
1945
  }
1946
+ var FLAMES_PER_HEIGHT = 1.5;
1947
+ var SMOKE_PER_HEIGHT = 2;
1882
1948
  function positionOf(follow) {
1883
1949
  return "position" in follow ? follow.position : follow;
1884
1950
  }
1951
+ var heightOf = (fire) => fire.h > 0 ? fire.rng.next() * fire.h : 0;
1952
+ var isBody = (follow) => "radius" in follow && "height" in follow;
1885
1953
  function emitFlames(core, fire, radius, dt) {
1886
1954
  const random = fire.rng;
1887
- fire.acc += dt * fire.rate * (0.5 + radius * 0.9) * fire.fade * core.clock.lod;
1955
+ fire.acc += dt * fire.rate * (0.5 + radius * 0.9) * (1 + fire.h * FLAMES_PER_HEIGHT) * fire.fade * core.clock.lod;
1888
1956
  while (fire.acc >= 1) {
1889
1957
  fire.acc -= 1;
1890
1958
  const angle = random.next() * Math.PI * 2;
1891
1959
  const distance = Math.sqrt(random.next()) * radius;
1892
1960
  addPuff(core, random, {
1893
1961
  x: fire.x + Math.cos(angle) * distance,
1894
- y: fire.y + 0.05,
1962
+ y: fire.y + 0.05 + heightOf(fire),
1895
1963
  z: fire.z + Math.sin(angle) * distance,
1896
1964
  vx: random.between(-0.2, 0.2),
1897
1965
  vy: random.between(0.6, 1.4),
@@ -1913,12 +1981,12 @@ function emitFlames(core, fire, radius, dt) {
1913
1981
  }
1914
1982
  function emitSmoke(core, fire, radius, dt) {
1915
1983
  const random = fire.rng;
1916
- fire.smokeAcc += dt * fire.smoke * (1 + radius * 0.8) * fire.fade * core.clock.lod;
1984
+ fire.smokeAcc += dt * fire.smoke * (1 + radius * 0.8) * (1 + fire.h * SMOKE_PER_HEIGHT) * fire.fade * core.clock.lod;
1917
1985
  while (fire.smokeAcc >= 1 && core.layers.smoke) {
1918
1986
  fire.smokeAcc -= 1;
1919
1987
  addPuff(core, random, {
1920
1988
  x: fire.x + random.between(-radius, radius) * 0.5,
1921
- y: fire.y + 0.6 + radius * 0.3,
1989
+ y: fire.y + fire.h + 0.6 + radius * 0.3,
1922
1990
  z: fire.z + random.between(-radius, radius) * 0.5,
1923
1991
  vy: random.between(0.8, 1.5),
1924
1992
  s0: 0.25,
@@ -1940,7 +2008,7 @@ function emitEmber(core, fire, radius, dt) {
1940
2008
  if (!(random.next() < dt * 6 * fire.fade && core.layers.shrapnel)) return;
1941
2009
  addSpark(core, {
1942
2010
  x: fire.x + random.between(-radius, radius) * 0.6,
1943
- y: fire.y + 0.4,
2011
+ y: fire.y + 0.4 + heightOf(fire),
1944
2012
  z: fire.z + random.between(-radius, radius) * 0.6,
1945
2013
  vx: random.between(-0.4, 0.4),
1946
2014
  vy: random.between(1.5, 3.2),
@@ -1964,6 +2032,10 @@ function updateFires(core, dt) {
1964
2032
  fire.x = point.x + fire.fx;
1965
2033
  fire.y = point.y + fire.fy;
1966
2034
  fire.z = point.z + fire.fz;
2035
+ if (isBody(fire.follow)) {
2036
+ fire.r = fire.follow.radius;
2037
+ fire.h = fire.follow.height;
2038
+ }
1967
2039
  }
1968
2040
  const radius = fire.grow ? lerp(fire.r0, fire.r, Math.min(1, fire.t / fire.grow)) : fire.r;
1969
2041
  fire.fade = fire.t < fire.life - 1.5 ? Math.min(1, fire.t * 3) : Math.max(0, (fire.life - fire.t) / 1.5);
@@ -2038,6 +2110,7 @@ var INDEX = { $: "index" };
2038
2110
  var QUALITY = { $: "quality" };
2039
2111
  var FRESH = { $: "fresh" };
2040
2112
  var DIRECTION = { $: "direction" };
2113
+ var NORMAL = { $: "normal" };
2041
2114
  var CAMERA_POSITION = { $: "cameraPosition" };
2042
2115
 
2043
2116
  // src/effects/steps.ts
@@ -2593,7 +2666,7 @@ var WEAPONS = ["glock", "ak", "r870", "barrett"];
2593
2666
  var TIP2 = [-0.8, 1.38, 3.4 - 0.78];
2594
2667
  var PORT2 = [-0.76, 1.4, 3.32];
2595
2668
  var FORWARD3 = [0, 0, -1];
2596
- var NORMAL = [0, 0, 1];
2669
+ var NORMAL2 = [0, 0, 1];
2597
2670
  var WALL_Z2 = -4.45;
2598
2671
  var SHOTS = [[0, 0.45, 0.9], [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6], [0], [0]];
2599
2672
  var SHOT_TIME = pick(pick(SHOTS, PARAM), INDEX);
@@ -2618,8 +2691,8 @@ var MUZZLE_FLASH = {
2618
2691
  set("target", [add(-0.8, rnd(-0.4, 0.4)), add(1.4, rnd(-0.3, 0.3)), WALL_Z2]),
2619
2692
  when(
2620
2693
  eq(PARAM, SHOTGUN),
2621
- [repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2], NORMAL, 0.35))],
2622
- [call2("impact", "concrete", variable("target"), NORMAL, ite(eq(PARAM, BARRETT), 2, 1))]
2694
+ [repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2], NORMAL2, 0.35))],
2695
+ [call2("impact", "concrete", variable("target"), NORMAL2, ite(eq(PARAM, BARRETT), 2, 1))]
2623
2696
  ),
2624
2697
  when(and(eq(PARAM, AK), eq(mod(round(mul(SHOT_TIME, 10)), 3), 0)), [spawn("streak", { p: TIP2, dir: FORWARD3, cone: 0, sp: 90, life: 0.09, len: 0.025, c0: 16752704, a: 1 })])
2625
2698
  )
@@ -3177,6 +3250,8 @@ var RainField = class {
3177
3250
  __publicField(this, "puddles", WORKSHOP_PUDDLES);
3178
3251
  /** Replaces the puddle test (a game knows its own wet spots). */
3179
3252
  __publicField(this, "puddleAt");
3253
+ /** Top (world y) of the roof or slab over (x, z), `undefined` for open sky: a streak that falls under it is gone, with no splash and no ring. Unset: nothing is roofed. */
3254
+ __publicField(this, "coverTopAt");
3180
3255
  }
3181
3256
  /** `initRain` (W321): `count` streaks (thinned by the quality), each drawn at a random place in the box. */
3182
3257
  init(count, wind) {
@@ -3222,6 +3297,13 @@ var RainField = class {
3222
3297
  positions[o + 3] += slant;
3223
3298
  positions[o + 1] -= fall;
3224
3299
  positions[o + 4] -= fall;
3300
+ if (this.coverTopAt) {
3301
+ const top = this.coverTopAt(positions[o], positions[o + 2]);
3302
+ if (top !== void 0 && positions[o + 4] < top) {
3303
+ this.restart(o);
3304
+ continue;
3305
+ }
3306
+ }
3225
3307
  const ground = context.groundAt(positions[o], positions[o + 2]);
3226
3308
  if (positions[o + 4] < ground) {
3227
3309
  const x = positions[o];
@@ -3237,10 +3319,7 @@ var RainField = class {
3237
3319
  }
3238
3320
  }
3239
3321
  }
3240
- const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
3241
- const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
3242
- const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
3243
- this.set(o, nx, ny, nz);
3322
+ this.restart(o);
3244
3323
  }
3245
3324
  }
3246
3325
  }
@@ -3248,6 +3327,13 @@ var RainField = class {
3248
3327
  clear() {
3249
3328
  this.on = false;
3250
3329
  }
3330
+ restart(offset) {
3331
+ const { random } = this.engine;
3332
+ const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
3333
+ const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
3334
+ const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
3335
+ this.set(offset, nx, ny, nz);
3336
+ }
3251
3337
  set(offset, x, y, z) {
3252
3338
  const positions = this.positions;
3253
3339
  positions[offset] = x;
@@ -3857,7 +3943,6 @@ var MATERIAL_EVENT_EFFECTS = [
3857
3943
  ];
3858
3944
 
3859
3945
  // src/effects/events.ts
3860
- var FACING5 = [0, 0, 1];
3861
3946
  var ORIGIN2 = [0, 0, 0];
3862
3947
  var FORWARD4 = [0, 0, -1];
3863
3948
  var IMPACT_MATERIALS = ["concrete", "metal", "wood", "glass", "flesh", "water"];
@@ -3867,7 +3952,7 @@ var impactEffect = (material) => ({
3867
3952
  team: "weapons",
3868
3953
  budget: { particles: 40, decals: 1 },
3869
3954
  loop: 2,
3870
- timeline: [call2("impact", material, ORIGIN2, FACING5, 1, 0)]
3955
+ timeline: [call2("impact", material, ORIGIN2, NORMAL, 1, 0)]
3871
3956
  });
3872
3957
  var muzzleEffect = (weapon) => ({
3873
3958
  id: `muzzle_${weapon}`,
@@ -4073,13 +4158,25 @@ var VIEWMODEL_EFFECTS = [MUZZLE_FLASH2, SMOKE_PUFF, BACKBLAST, FLAME_JET];
4073
4158
 
4074
4159
  // src/effects/vehicles/game-effects.ts
4075
4160
  var aliasOf = (base, id, changes) => ({ ...base, id, pageId: `vehicle:${id}`, anchor: CAR_ORIGIN2, ...changes });
4161
+ var BODYWORK_IMPACT = {
4162
+ id: "impact_bodywork",
4163
+ pageId: "vehicle:impact_bodywork",
4164
+ team: "vehicles",
4165
+ budget: { particles: 80, debris: 20, lights: 1 },
4166
+ loop: 2,
4167
+ timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
4168
+ };
4076
4169
  var VEHICLE_EFFECTS = [
4170
+ BODYWORK_IMPACT,
4077
4171
  /** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
4078
4172
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
4079
4173
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
4080
4174
  aliasOf(ENGINE_SMOKE, "vehicle_exhaust", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 0 }, loop: 0.5 }),
4081
- /** A hole in the tank: the page's petrol leak without the fire and the blast (the pool and the drips). A normal bullet does only this. */
4082
- aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", {}),
4175
+ /**
4176
+ * A hole in a tank: the page's drips, falling from the point it is played at (the hole). No pool of its own: the pool is the liquid that came out, laid by the
4177
+ * host's fluid world as it leaks (it grows with the volume and spreads by the liquid's own kind), not a drawing of a size the page chose.
4178
+ */
4179
+ aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", { anchor: TANK, timeline: [] }),
4083
4180
  /** The leak caught fire (an incendiary or tracer round, a spark, a fire near): the page's whole sequence, the fire running along the pool to the tank and the blast. */
4084
4181
  aliasOf(FUEL_LEAK, "vehicle_leak_ignited", {})
4085
4182
  ];
@@ -4817,6 +4914,48 @@ function resolve(value, context) {
4817
4914
  }
4818
4915
  }
4819
4916
 
4917
+ // src/effects/builders/bodywork.ts
4918
+ var PISTOL_BORE = 9e-3;
4919
+ var BARE_STEEL = 11778236;
4920
+ var DEFAULT_PAINT = 9147290;
4921
+ var DEFAULT_DIRECTION = [0, 0, -1];
4922
+ var MAX_SCALE = 3;
4923
+ var MIN_SCALE = 0.6;
4924
+ function reflected(direction, normal) {
4925
+ const along = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
4926
+ const out = [direction[0] - 2 * along * normal[0], direction[1] - 2 * along * normal[1], direction[2] - 2 * along * normal[2]];
4927
+ const length = Math.hypot(out[0], out[1], out[2]);
4928
+ if (length < 1e-6 || Math.abs(along) > 0.98) return normal;
4929
+ return [out[0] / length, out[1] / length, out[2] / length];
4930
+ }
4931
+ var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
4932
+ function bodyworkHitOf(values) {
4933
+ const raw = Array.isArray(values.direction) ? values.direction : [];
4934
+ const direction = raw.length === 3 && raw.every((entry) => typeof entry === "number" && Number.isFinite(entry)) ? [raw[0], raw[1], raw[2]] : DEFAULT_DIRECTION;
4935
+ return { direction, bore: numberOr(values.bore, PISTOL_BORE), paint: numberOr(values.paint, DEFAULT_PAINT), metal: numberOr(values.metal, BARE_STEEL) };
4936
+ }
4937
+ function bodyworkScale(bore) {
4938
+ return Math.min(MAX_SCALE, Math.max(MIN_SCALE, bore / PISTOL_BORE));
4939
+ }
4940
+ function bodyworkImpact(engine, point, normal, hit) {
4941
+ const scale = bodyworkScale(hit.bore);
4942
+ const off = reflected(hit.direction, normal);
4943
+ if (engine.quality < 2) {
4944
+ engine.burst("streak", Math.round(14 * scale), { p: point, dir: off, cone: 0.75, sp: [4, 12], life: [0.08, 0.3], len: 0.03, c0: 16774352, c1: 16738840, g: 9.8, gnd: 2 });
4945
+ engine.burst("add", 2, { p: plusScaled(point, normal, 0.01), size: [0.06 * scale, 0.12 * scale], life: 0.05, c0: 16770736, fi: 0 });
4946
+ engine.flash([plusScaled(point, normal, 0.15), 16760432, 1.6 * scale, 0.05, 4]);
4947
+ }
4948
+ const flakes = engine.scaled(Math.round(5 * scale));
4949
+ for (let index = 0; index < flakes; index++) {
4950
+ engine.debrisPiece({ p: point, dir: normal, cone: 0.9, sp: [1.2, 3.5], size: [8e-3 * scale, 12e-4, 6e-3 * scale], k: [0.5, 1.4], c: hit.paint, life: 6, bounce: 0.2 });
4951
+ }
4952
+ const slivers = engine.scaled(Math.round(2 * scale));
4953
+ for (let index = 0; index < slivers; index++) {
4954
+ engine.debrisPiece({ p: point, dir: off, cone: 0.6, sp: [2.5, 6], size: [25e-4, 15e-4, 0.01 * scale], k: [0.6, 1.3], c: hit.metal, life: 6, bounce: 0.35 });
4955
+ }
4956
+ engine.burst("normal", Math.round(6 * scale), { p: point, dir: normal, cone: 0.7, sp: [0.4, 1.4], drag: 2.5, life: [0.4, 0.9], size: [0.03, 0.07], grow: 3, c0: hit.paint, a: 0.45, g: -0.05 });
4957
+ }
4958
+
4820
4959
  // src/effects/builders/fire.ts
4821
4960
  var UP12 = [0, 1, 0];
4822
4961
  var ZERO = [0, 0, 0];
@@ -4971,11 +5110,12 @@ var MACROS = {
4971
5110
  casing: ({ engine }, [port, type]) => casing(engine, port, type),
4972
5111
  chips: ({ engine }, [point, direction, count, spread]) => chips(engine, point, direction, count, spread),
4973
5112
  spark_at: ({ engine }, [point, direction, count, spread]) => sparkAt(engine, point, direction, count, spread),
4974
- rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count)
5113
+ rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count),
5114
+ bodywork_impact: ({ engine }, [point, normal, direction, bore, paint, metal]) => bodyworkImpact(engine, point, normal, bodyworkHitOf({ direction, bore, paint, metal }))
4975
5115
  };
4976
5116
 
4977
5117
  // src/effects/instance.ts
4978
- var DEFAULT_DIRECTION = [0, 0, -1];
5118
+ var DEFAULT_DIRECTION2 = [0, 0, -1];
4979
5119
  var DEFAULT_NORMAL = [0, 1, 0];
4980
5120
  var SCREEN_FIELDS = {
4981
5121
  shake: "shake",
@@ -5044,7 +5184,7 @@ var EffectInstance = class {
5044
5184
  return instance().fresh;
5045
5185
  },
5046
5186
  get direction() {
5047
- return instance().setup.direction ?? DEFAULT_DIRECTION;
5187
+ return instance().setup.direction ?? DEFAULT_DIRECTION2;
5048
5188
  },
5049
5189
  get normal() {
5050
5190
  return instance().setup.normal ?? DEFAULT_NORMAL;
@@ -5664,6 +5804,24 @@ function composeFlash(context) {
5664
5804
  screen2.flashDecay = 0.5;
5665
5805
  }
5666
5806
  }
5807
+ var BIRTH = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
5808
+ function bornFrom(core, puff3, ox, oy, oz) {
5809
+ const confiner = core.confiner;
5810
+ if (confiner.empty) return;
5811
+ BIRTH.x0 = ox;
5812
+ BIRTH.y0 = oy;
5813
+ BIRTH.z0 = oz;
5814
+ BIRTH.x1 = puff3.x;
5815
+ BIRTH.y1 = puff3.y;
5816
+ BIRTH.z1 = puff3.z;
5817
+ BIRTH.pad = puff3.s0 * PAD_OF_SIZE;
5818
+ if (!confiner.confineMove(BIRTH, 0)) return;
5819
+ const out = confiner.out;
5820
+ puff3.x = out.x;
5821
+ puff3.y = out.y;
5822
+ puff3.z = out.z;
5823
+ slideInto(out, puff3);
5824
+ }
5667
5825
  function composeFireballs(context) {
5668
5826
  const { core, def, random, x, y, z, size, scale, direction } = context;
5669
5827
  if (!core.layers.fire || !def.fireballs) return;
@@ -5680,7 +5838,7 @@ function composeFireballs(context) {
5680
5838
  const life = random.between(def.smoke.life * 0.7, def.smoke.life);
5681
5839
  const h0 = random.between(1.05, 1.35) * heat;
5682
5840
  const hl = fuel ? random.between(0.8, 1.4) * (def.heatLifeScale ?? 1) : random.between(0.22, 0.42);
5683
- addPuff(core, random, {
5841
+ const fireball = addPuff(core, random, {
5684
5842
  x: x + d.x * size * 0.15,
5685
5843
  y: y + size * 0.25 + d.y * size * 0.1,
5686
5844
  z: z + d.z * size * 0.15,
@@ -5699,6 +5857,7 @@ function composeFireballs(context) {
5699
5857
  color: context.smokeColor,
5700
5858
  kind: 0
5701
5859
  });
5860
+ bornFrom(core, fireball, x, y, z);
5702
5861
  }
5703
5862
  }
5704
5863
  function composeSmoke(context) {
@@ -5712,7 +5871,7 @@ function composeSmoke(context) {
5712
5871
  const s1 = size * random.between(0.55, 0.85);
5713
5872
  const sg = size * random.between(0.18, 0.3);
5714
5873
  const life = random.between(def.smoke.life * 0.7, def.smoke.life * 1.1);
5715
- addPuff(core, random, {
5874
+ const smoke = addPuff(core, random, {
5716
5875
  x: x + d.x * size * 0.6,
5717
5876
  y: y + size * 0.4 + d.y * size * 0.5,
5718
5877
  z: z + d.z * size * 0.6,
@@ -5731,6 +5890,7 @@ function composeSmoke(context) {
5731
5890
  color: context.smokeColor,
5732
5891
  kind: def.smoke.kind ?? 0
5733
5892
  });
5893
+ bornFrom(core, smoke, x, y, z);
5734
5894
  }
5735
5895
  }
5736
5896
  function composeShock(context) {
@@ -5755,7 +5915,7 @@ function composeDust(context) {
5755
5915
  const s1 = size * random.between(0.5, 0.8);
5756
5916
  const sg = size * random.between(0.2, 0.35);
5757
5917
  const life = random.between(2.2, 4);
5758
- addPuff(core, random, {
5918
+ const dust = addPuff(core, random, {
5759
5919
  x: x + Math.cos(angle) * 0.3,
5760
5920
  y: 0.15,
5761
5921
  z: z + Math.sin(angle) * 0.3,
@@ -5772,6 +5932,7 @@ function composeDust(context) {
5772
5932
  color,
5773
5933
  kind: 1
5774
5934
  });
5935
+ bornFrom(core, dust, x, 0.15, z);
5775
5936
  }
5776
5937
  }
5777
5938
  function coneAngle(context) {
@@ -6841,6 +7002,71 @@ function coneDirection(random, direction, cone, out) {
6841
7002
  return out;
6842
7003
  }
6843
7004
 
7005
+ // src/workshop/debris-contact.ts
7006
+ var CELL = 0.12;
7007
+ var OBSTACLE_BOUNCE = 0.3;
7008
+ var radiusOf = (piece) => Math.max(piece.sx, piece.sz) * 0.5;
7009
+ var thicknessOf = (piece) => Math.min(piece.sx, piece.sy, piece.sz);
7010
+ var cellKey = (i, k) => (i + 4096) * 8192 + (k + 4096);
7011
+ var RestingGrid = class {
7012
+ constructor() {
7013
+ __publicField(this, "cells", /* @__PURE__ */ new Map());
7014
+ }
7015
+ clear() {
7016
+ for (const list of this.cells.values()) list.length = 0;
7017
+ }
7018
+ rebuild(pieces) {
7019
+ this.clear();
7020
+ for (const piece of pieces) {
7021
+ if (!piece.on || !piece.rest) continue;
7022
+ const key = cellKey(Math.floor(piece.x / CELL), Math.floor(piece.z / CELL));
7023
+ const list = this.cells.get(key);
7024
+ if (list) list.push(piece);
7025
+ else this.cells.set(key, [piece]);
7026
+ }
7027
+ }
7028
+ /** The height a piece at `piece`'s place lands at on the pieces under it (the top of the highest one it overlaps), or `-Infinity` over none. */
7029
+ supportUnder(piece) {
7030
+ const i = Math.floor(piece.x / CELL);
7031
+ const k = Math.floor(piece.z / CELL);
7032
+ const reach = radiusOf(piece);
7033
+ let top = -Infinity;
7034
+ for (let di = -1; di <= 1; di++) {
7035
+ for (let dk = -1; dk <= 1; dk++) {
7036
+ for (const other of this.cells.get(cellKey(i + di, k + dk)) ?? []) {
7037
+ if (other === piece) continue;
7038
+ if (Math.hypot(other.x - piece.x, other.z - piece.z) > reach + radiusOf(other)) continue;
7039
+ const otherTop = other.y + thicknessOf(other) * 0.5;
7040
+ if (otherTop <= piece.y + thicknessOf(piece) * 0.5) top = Math.max(top, otherTop + thicknessOf(piece) * 0.5);
7041
+ }
7042
+ }
7043
+ }
7044
+ return top;
7045
+ }
7046
+ };
7047
+ function pushOutOfObstacles(piece, obstacles) {
7048
+ let moved = false;
7049
+ for (const body of obstacles) {
7050
+ if (piece.y < body.bottom || piece.y > body.top) continue;
7051
+ const dx = piece.x - body.x;
7052
+ const dz = piece.z - body.z;
7053
+ const distance = Math.hypot(dx, dz);
7054
+ const reach = body.radius + radiusOf(piece);
7055
+ if (distance >= reach) continue;
7056
+ const nx = distance > 1e-6 ? dx / distance : 1;
7057
+ const nz = distance > 1e-6 ? dz / distance : 0;
7058
+ piece.x = body.x + nx * reach;
7059
+ piece.z = body.z + nz * reach;
7060
+ const into = piece.vx * nx + piece.vz * nz;
7061
+ if (into < 0) {
7062
+ piece.vx -= (1 + OBSTACLE_BOUNCE) * into * nx;
7063
+ piece.vz -= (1 + OBSTACLE_BOUNCE) * into * nz;
7064
+ }
7065
+ moved = true;
7066
+ }
7067
+ return moved;
7068
+ }
7069
+
6844
7070
  // src/workshop/debris.ts
6845
7071
  var CAPACITY = 500;
6846
7072
  var GRAVITY2 = 9.8;
@@ -6862,6 +7088,7 @@ var DebrisPool = class {
6862
7088
  __publicField(this, "count", 0);
6863
7089
  __publicField(this, "next", 0);
6864
7090
  __publicField(this, "direction", { x: 0, y: 0, z: 0 });
7091
+ __publicField(this, "resting", new RestingGrid());
6865
7092
  }
6866
7093
  spawn(options) {
6867
7094
  const random = this.context.random;
@@ -6899,14 +7126,21 @@ var DebrisPool = class {
6899
7126
  }
6900
7127
  update(dt) {
6901
7128
  this.count = 0;
7129
+ const contacts = this.context.debrisContacts;
7130
+ const obstacles = contacts?.obstacles() ?? [];
7131
+ let moving = false;
6902
7132
  for (const piece of this.pieces) {
6903
7133
  if (!piece.on) continue;
6904
- this.count++;
6905
7134
  piece.life -= dt;
6906
- if (piece.life <= 0) {
6907
- piece.on = false;
6908
- continue;
6909
- }
7135
+ if (piece.life <= 0) piece.on = false;
7136
+ else if (!piece.rest) moving = true;
7137
+ }
7138
+ if (moving && contacts) this.resting.rebuild(this.pieces);
7139
+ else this.resting.clear();
7140
+ for (const piece of this.pieces) {
7141
+ if (!piece.on) continue;
7142
+ this.count++;
7143
+ if (obstacles.length > 0 && pushOutOfObstacles(piece, obstacles)) piece.rest = false;
6910
7144
  if (!piece.rest) this.move(piece, dt);
6911
7145
  }
6912
7146
  }
@@ -6922,7 +7156,7 @@ var DebrisPool = class {
6922
7156
  piece.rx += piece.ax * dt;
6923
7157
  piece.ry += piece.ay * dt;
6924
7158
  piece.rz += piece.az * dt;
6925
- const groundHeight = this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5;
7159
+ const groundHeight = Math.max(this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5, this.resting.supportUnder(piece));
6926
7160
  if (piece.y >= groundHeight) return;
6927
7161
  piece.y = groundHeight;
6928
7162
  piece.vy *= -piece.bounce;
@@ -7560,7 +7794,6 @@ var QUALITY_MULTIPLIERS = [1, 0.5, 0.2];
7560
7794
  var FIRE_FLICKER_SWAY = 0.25;
7561
7795
  var FIRE_FLICKER_JITTER = 0.08;
7562
7796
  var LENS_FADE = 0.16;
7563
- var FLOOR_NORMAL_Y = 0.9;
7564
7797
  function rotate2(q, v) {
7565
7798
  const [qx, qy, qz, qw] = q;
7566
7799
  const ix = qw * v[0] + qy * v[2] - qz * v[1];
@@ -7599,6 +7832,14 @@ var WorkshopEngine = class {
7599
7832
  this.decals = new DecalPool(this.context);
7600
7833
  this.lights = new FlashLightPool(this.context);
7601
7834
  }
7835
+ /**
7836
+ * Turns on the touch of the debris pieces (a game's world; the Workshop page's recording has none): they pile on the pieces at rest under them, and the
7837
+ * upright bodies `obstacles` answers (the player, asked once a frame while a piece moves) stop them and push them. `null` turns it off.
7838
+ */
7839
+ setDebrisContacts(obstacles) {
7840
+ if (obstacles) this.context.debrisContacts = { obstacles };
7841
+ else delete this.context.debrisContacts;
7842
+ }
7602
7843
  get random() {
7603
7844
  return this.context.random;
7604
7845
  }
@@ -7690,7 +7931,7 @@ var WorkshopEngine = class {
7690
7931
  const [x, y, z] = this.place([recipe[0], recipe[1], recipe[2]]);
7691
7932
  const options = recipe[5];
7692
7933
  const normal = options?.n ? this.turn(options.n) : void 0;
7693
- const onFloor = !normal || normal[1] > FLOOR_NORMAL_Y;
7934
+ const onFloor = !normal;
7694
7935
  args = [x, onFloor ? this.context.groundAt(x, z) : y, z, recipe[3], recipe[4], normal ? { ...options, n: normal } : options];
7695
7936
  }
7696
7937
  this.context.trace?.("decal", args);
@@ -7811,6 +8052,7 @@ function createVfx(options = {}) {
7811
8052
  });
7812
8053
  const core = {
7813
8054
  profile,
8055
+ confiner: enclosures,
7814
8056
  puffs: createPuffPool(profile.puffs),
7815
8057
  sparks: createSparkPool(profile.sparks),
7816
8058
  glows: createGlowPool(profile.glows),
@@ -7919,10 +8161,11 @@ function createVfx(options = {}) {
7919
8161
  },
7920
8162
  fire(fireOptions) {
7921
8163
  const handle = ++handles.next;
7922
- const { point, offset, seed, radius, smokeColor, ...rest } = fireOptions;
8164
+ const { point, offset, seed, radius, height, smokeColor, ...rest } = fireOptions;
7923
8165
  addFire(core, streamOf(seed), {
7924
8166
  ...rest,
7925
8167
  r: radius,
8168
+ ...height !== void 0 ? { h: height } : {},
7926
8169
  x: point[0],
7927
8170
  y: point[1],
7928
8171
  z: point[2],
@@ -7950,6 +8193,9 @@ function createVfx(options = {}) {
7950
8193
  enclose(id, enclosure) {
7951
8194
  enclosures.set(id, enclosure);
7952
8195
  },
8196
+ solid(id, query2) {
8197
+ enclosures.solid(id, query2);
8198
+ },
7953
8199
  enclosures: () => enclosures,
7954
8200
  stop(handle) {
7955
8201
  player?.stop(handle);