@adatechnology/game-weapons-three 0.28.0 → 0.29.1

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.d.ts CHANGED
@@ -334,15 +334,19 @@ declare const VIEW_MOTION: {
334
334
  * right, y up, z back towards the eye) and turned about its own grip. The hands close on the tool's grips, so they follow it: one motion moves the tool and
335
335
  * the arms alike, in the first-person view and on the body.
336
336
  */
337
- /** One key of a motion: the share of its time (0..1), the offset from the hold (metres) and the turn about the grip (radians, x then y then z). */
337
+ /** One key of a motion: the share of its time (0..1), the offset from the hold (metres) and the turn (radians, Euler x then y then z: x raises the point, y swings it to the left, z rolls it about itself). */
338
338
  interface ToolMotionKey {
339
339
  readonly at: number;
340
340
  readonly offset: readonly [number, number, number];
341
341
  readonly turn: readonly [number, number, number];
342
342
  }
343
- /** A motion of a tool: its keys, from the hold back to the hold. */
343
+ /**
344
+ * A motion of a tool: its keys, from the hold back to the hold. `pivot: 'grip'` turns the tool about the hand that holds it (a wrist's cut, a bat's swing written as
345
+ * the hands' path); left out, the turn is about where the hold hangs from (the eye in first person, the shoulder on the body), as the shovel's motions were written.
346
+ */
344
347
  interface ToolMotion {
345
348
  readonly keys: readonly ToolMotionKey[];
349
+ readonly pivot?: 'grip';
346
350
  }
347
351
  /** The motions of each family of melee blows (`MELEE_FAMILIES` of game-weapons), by the motion names of its blows. */
348
352
  declare const FAMILY_MOTIONS: ReadonlyMap<string, ReadonlyMap<string, ToolMotion>>;
@@ -17265,15 +17265,30 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
17265
17265
  reset: 1.2
17266
17266
  },
17267
17267
  {
17268
- id: "two_hand_swing",
17269
- note: "a long weapon in both hands (bat, pipe, crowbar, axe, sledgehammer, katana): swung flat from the right shoulder across the body, the hips leading, as the shovel's swing",
17268
+ id: "bat_swing",
17269
+ note: "a club in both hands (bat, pipe, crowbar, sledgehammer): drawn back behind the right shoulder, swung level through the chest with the hips and shoulders turning, and carried round over the left shoulder (follow-through)",
17270
17270
  weapons: [
17271
17271
  "baseball_bat",
17272
17272
  "nail_bat",
17273
17273
  "iron_pipe",
17274
17274
  "crowbar",
17275
+ "sledgehammer"
17276
+ ],
17277
+ blows: [
17278
+ {
17279
+ clip: "bat_swing",
17280
+ motion: "bat_swing",
17281
+ seconds: 0.7
17282
+ }
17283
+ ],
17284
+ reset: 1.2,
17285
+ contactLength: 0.3
17286
+ },
17287
+ {
17288
+ id: "two_hand_swing",
17289
+ note: "a long weapon in both hands with its weight at the head or an edge (axe, pickaxe, katana): swung flat and low from the right shoulder across the body, the hips leading, as the shovel's swing",
17290
+ weapons: [
17275
17291
  "axe",
17276
- "sledgehammer",
17277
17292
  "pickaxe",
17278
17293
  "katana"
17279
17294
  ],
@@ -28193,9 +28208,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28193
28208
  at4[p.thin] = Math.sign(lp[p.thin]) * p.dims[p.thin] / 2;
28194
28209
  const r = vec.distance(toWorld(p.pos, p.q, at4), centre);
28195
28210
  const side = sideOnOverpressure(tnt, r);
28196
- const reflected = 2 * side + 6 * side * side / (side + 7 * 101325);
28211
+ const reflected2 = 2 * side + 6 * side * side / (side + 7 * 101325);
28197
28212
  const impulse = bodyImpulse(tnt, r);
28198
- if (reflected > PANEL_PRESSURE && impulse > PANEL_IMPULSE && (reflected - PANEL_PRESSURE) * (impulse - PANEL_IMPULSE) >= PANEL_PI) loaded++;
28213
+ if (reflected2 > PANEL_PRESSURE && impulse > PANEL_IMPULSE && (reflected2 - PANEL_PRESSURE) * (impulse - PANEL_IMPULSE) >= PANEL_PI) loaded++;
28199
28214
  }
28200
28215
  if (loaded < PANEL_POINTS_LOADED) return false;
28201
28216
  const grid = gridOf(p);
@@ -50894,7 +50909,44 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50894
50909
  consumes: false,
50895
50910
  items: [
50896
50911
  "flashlight"
50897
- ]
50912
+ ],
50913
+ params: {
50914
+ clip: "toggle_flashlight"
50915
+ }
50916
+ },
50917
+ {
50918
+ id: "ignite",
50919
+ effect: "ignite",
50920
+ consumes: false,
50921
+ items: [
50922
+ "lighter"
50923
+ ],
50924
+ params: {
50925
+ clip: "light_lighter"
50926
+ }
50927
+ },
50928
+ {
50929
+ id: "radio_call",
50930
+ effect: "radio_call",
50931
+ consumes: false,
50932
+ items: [
50933
+ "portable_radio",
50934
+ "walkie_talkies"
50935
+ ],
50936
+ params: {
50937
+ clip: "use_radio"
50938
+ }
50939
+ },
50940
+ {
50941
+ id: "turn_key",
50942
+ effect: "turn_key",
50943
+ consumes: false,
50944
+ category: [
50945
+ "keys"
50946
+ ],
50947
+ params: {
50948
+ clip: "turn_key"
50949
+ }
50898
50950
  },
50899
50951
  {
50900
50952
  id: "swap_bag",
@@ -53142,7 +53194,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53142
53194
  d: 0.38,
53143
53195
  h: 0.3,
53144
53196
  y: 0.9,
53145
- solid: false,
53197
+ solid: true,
53146
53198
  massKg: 14,
53147
53199
  sounds: {
53148
53200
  leaves: {
@@ -54719,12 +54771,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54719
54771
  const zb = oz + inw * v1;
54720
54772
  return { floor: p.floor, x0: ox + u0, x1: ox + u1, z0: Math.min(za, zb), z1: Math.max(za, zb) };
54721
54773
  });
54722
- const CELL2 = 0.5;
54774
+ const CELL3 = 0.5;
54723
54775
  const grid = /* @__PURE__ */ new Map();
54724
54776
  const key2 = (a, i, j) => (a * 4096 + (i + 2048)) * 4096 + (j + 2048);
54725
54777
  for (const s of segs) {
54726
- for (let i = Math.floor(s.x0 / CELL2); i <= Math.floor(s.x1 / CELL2); i++) {
54727
- for (let j = Math.floor(s.z0 / CELL2); j <= Math.floor(s.z1 / CELL2); j++) {
54778
+ for (let i = Math.floor(s.x0 / CELL3); i <= Math.floor(s.x1 / CELL3); i++) {
54779
+ for (let j = Math.floor(s.z0 / CELL3); j <= Math.floor(s.z1 / CELL3); j++) {
54728
54780
  const k = key2(s.floor, i, j);
54729
54781
  if (!grid.has(k)) grid.set(k, []);
54730
54782
  grid.get(k).push(s);
@@ -54733,7 +54785,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54733
54785
  }
54734
54786
  return function blocked(x, z, floor2) {
54735
54787
  const a = floor2 == null || floor2 < 0 ? 0 : floor2;
54736
- const list2 = grid.get(key2(a, Math.floor(x / CELL2), Math.floor(z / CELL2)));
54788
+ const list2 = grid.get(key2(a, Math.floor(x / CELL3), Math.floor(z / CELL3)));
54737
54789
  if (!list2) return false;
54738
54790
  for (const s of list2) if (x > s.x0 && x < s.x1 && z > s.z0 && z < s.z1) return true;
54739
54791
  return false;
@@ -82823,20 +82875,33 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
82823
82875
  ]
82824
82876
  };
82825
82877
  var KNIFE_SLASH = {
82878
+ pivot: "grip",
82826
82879
  keys: [
82827
82880
  { at: 0, ...HOLD },
82828
- { at: 0.3, offset: [0.06, 0.3, 0.04], turn: [0.35, 0, -0.5] },
82829
- { at: 0.43, offset: [-0.1, 0.2, -0.2], turn: [-0.6, 0, 0.5] },
82830
- { at: 0.62, offset: [-0.24, 0.04, -0.12], turn: [-1, 0, 0.9] },
82881
+ { at: 0.28, offset: [0.07, 0.2, 0.05], turn: [0.5, -0.9, 0] },
82882
+ { at: 0.43, offset: [-0.14, 0.06, -0.07], turn: [0.1, 0.9, 0] },
82883
+ { at: 0.62, offset: [-0.2, -0.08, 0], turn: [-0.2, 1.3, 0] },
82831
82884
  { at: 1, ...HOLD }
82832
82885
  ]
82833
82886
  };
82834
82887
  var KNIFE_STAB = {
82888
+ pivot: "grip",
82889
+ keys: [
82890
+ { at: 0, ...HOLD },
82891
+ { at: 0.28, offset: [0.03, -0.05, 0.08], turn: [0.15, -0.1, 0] },
82892
+ { at: 0.43, offset: [-0.1, 0.07, -0.12], turn: [0.1, 0.55, 0] },
82893
+ { at: 0.6, offset: [-0.1, 0.07, -0.11], turn: [0.1, 0.52, 0] },
82894
+ { at: 1, ...HOLD }
82895
+ ]
82896
+ };
82897
+ var BAT_SWING = {
82898
+ pivot: "grip",
82835
82899
  keys: [
82836
82900
  { at: 0, ...HOLD },
82837
- { at: 0.28, offset: [0.02, 0.06, 0.08], turn: [0.15, 0, 0] },
82838
- { at: 0.43, offset: [-0.04, 0.12, -0.22], turn: [-0.5, 0, 0] },
82839
- { at: 0.6, offset: [-0.04, 0.11, -0.2], turn: [-0.45, 0, 0] },
82901
+ { at: 0.29, offset: [0.12, 0.12, 0.1], turn: [1.9, -0.6, 0] },
82902
+ { at: 0.43, offset: [-0.1, 0.04, -0.07], turn: [-0.3, 1.2, 0] },
82903
+ { at: 0.64, offset: [-0.28, 0.1, 0], turn: [2, 1, 0] },
82904
+ { at: 0.8, offset: [-0.2, 0.06, 0.02], turn: [1.8, 0.8, 0] },
82840
82905
  { at: 1, ...HOLD }
82841
82906
  ]
82842
82907
  };
@@ -82852,7 +82917,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
82852
82917
  var FAMILY_MOTIONS = /* @__PURE__ */ new Map([
82853
82918
  ["short_blade", /* @__PURE__ */ new Map([["slash", KNIFE_SLASH], ["stab", KNIFE_STAB]])],
82854
82919
  ["one_hand_swing", /* @__PURE__ */ new Map([["chop", ONE_HAND_CHOP]])],
82855
- // a bat, a pipe or an axe swung with both hands goes as the shovel's swing
82920
+ ["bat_swing", /* @__PURE__ */ new Map([["bat_swing", BAT_SWING]])],
82921
+ // an axe or a pickaxe swung with both hands goes as the shovel's swing
82856
82922
  ["two_hand_swing", /* @__PURE__ */ new Map([["swing", SHOVEL_SWING]])]
82857
82923
  ]);
82858
82924
  var TOOL_MOTIONS = new Map([
@@ -89656,7 +89722,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89656
89722
  // the blade of the KA-BAR and of the katana is the narrow end of the lying item, so the head is turned to +x; the katana is held with both hands on its long handle (the left 11 cm behind the right: 0.1122 of its 0.98 m); the brass knuckles lie with the ring row across the strike
89657
89723
  ["kabar", { flip: true }],
89658
89724
  ["katana", { flip: true, grips: { handle: -0.35, support: -0.4622 } }],
89659
- ["brass_knuckles", { turn: 1, roll: 1, grips: { handle: -0.35, handleAt: [-0.045, 0.03] } }]
89725
+ ["brass_knuckles", { turn: 1, roll: 1, grips: { handle: -0.35, handleAt: [-0.045, 0.03] } }],
89726
+ // a club is swung with both hands at the knob end as a batter holds it: the left hand below at the knob, the right just above it (a sledgehammer's right hand higher up the haft)
89727
+ ["baseball_bat", { grips: { handle: -0.3, support: -0.41 } }],
89728
+ ["nail_bat", { grips: { handle: -0.3, support: -0.41 } }],
89729
+ ["iron_pipe", { grips: { handle: -0.29, support: -0.41 } }],
89730
+ ["crowbar", { grips: { handle: -0.3, support: -0.42 } }],
89731
+ ["sledgehammer", { grips: { handle: -0.22, support: -0.42 } }]
89660
89732
  ];
89661
89733
  var hasThrowableModel = (def) => def.action?.kind === "throwable" && def.action.explosive !== void 0 && hasExplosiveModel(def.action.explosive);
89662
89734
  var buildThrowableModel = (THREE, def) => def.action?.kind === "throwable" && def.action.explosive !== void 0 ? buildExplosiveModel(THREE, def.action.explosive) : void 0;
@@ -89687,6 +89759,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89687
89759
  var buildWeaponModel = (THREE, def, items) => defaultWeaponProps().buildModel(THREE, def, items);
89688
89760
 
89689
89761
  // src/box-fx.ts
89762
+ var TOOL_REACH = 0.47;
89690
89763
  var EJECTS_ON_SHOT = /* @__PURE__ */ new Set(["pistol", "smg", "carbine", "rifle", "sniper", "shotgun"]);
89691
89764
  var SPOUTS = /* @__PURE__ */ new Set(["firearm", "flame", "heat", "extinguisher"]);
89692
89765
  var DROPS_MAGAZINE = /* @__PURE__ */ new Set(["pistol", "smg", "carbine", "rifle", "sniper"]);
@@ -89717,8 +89790,27 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89717
89790
  const applyMotion = (frame2) => {
89718
89791
  if (!motion) return;
89719
89792
  const at4 = sampleToolMotion(motion.clip, motion.elapsed / motion.duration);
89720
- hand.position.add(v.set(at4.offset[0], at4.offset[1], at4.offset[2]).applyQuaternion(frame2));
89793
+ const anchor = motion.clip.pivot === "grip" ? heldAnchor(heldHold()) : null;
89794
+ if (anchor) {
89795
+ hand.updateMatrixWorld(true);
89796
+ anchor.part.localToWorld(gripBefore.copy(anchor.offset));
89797
+ }
89721
89798
  hand.quaternion.multiply(q.setFromEuler(new THREE.Euler(at4.turn[0], at4.turn[1], at4.turn[2])));
89799
+ if (anchor) {
89800
+ hand.updateMatrixWorld(true);
89801
+ hand.position.add(gripBefore.sub(anchor.part.localToWorld(gripAfter.copy(anchor.offset))));
89802
+ }
89803
+ hand.position.add(v.set(at4.offset[0], at4.offset[1], at4.offset[2]).applyQuaternion(frame2));
89804
+ };
89805
+ const keepInReach = (shoulder) => {
89806
+ const anchor = heldAnchor(heldHold());
89807
+ if (!anchor) return;
89808
+ hand.updateMatrixWorld(true);
89809
+ const away = anchor.part.localToWorld(gripAfter.copy(anchor.offset)).sub(gripBefore.set(shoulder[0], shoulder[1], shoulder[2]));
89810
+ const distance4 = away.length();
89811
+ if (distance4 <= TOOL_REACH) return;
89812
+ hand.position.sub(away.multiplyScalar(1 - TOOL_REACH / distance4));
89813
+ hand.updateMatrixWorld(true);
89722
89814
  };
89723
89815
  let dip = 0;
89724
89816
  let reloading = false;
@@ -89738,6 +89830,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89738
89830
  const frontOf = new THREE.Vector3();
89739
89831
  const restBox2 = new THREE.Box3();
89740
89832
  const noMotion = new THREE.Vector3();
89833
+ const gripBefore = new THREE.Vector3();
89834
+ const gripAfter = new THREE.Vector3();
89741
89835
  let inLens = false;
89742
89836
  const setLens = (on) => {
89743
89837
  if (on !== inLens) options.viewmodelFov?.(on ? VIEW_HOLD.tool.fov : null);
@@ -89937,8 +90031,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89937
90031
  hand.position.add(v.set(0, -0.12 * dip, 0.05 * kick).applyQuaternion(camera2.quaternion));
89938
90032
  q.setFromEuler(new THREE.Euler(0.14 * kick - 0.25 * dip, 0, 0.6 * dip));
89939
90033
  hand.quaternion.multiply(q);
89940
- const body = (options.bodyHold?.() ?? eyeFrame()).quaternion;
89941
- applyMotion(bodyFrame.set(body[0], body[1], body[2], body[3]));
90034
+ const body = options.bodyHold?.() ?? eyeFrame();
90035
+ applyMotion(bodyFrame.set(body.quaternion[0], body.quaternion[1], body.quaternion[2], body.quaternion[3]));
90036
+ if (motion) keepInReach(body.position);
89942
90037
  }
89943
90038
  stow(dt);
89944
90039
  for (const body of [...bodies]) {
@@ -93058,6 +93153,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
93058
93153
  var QUALITY = { $: "quality" };
93059
93154
  var FRESH = { $: "fresh" };
93060
93155
  var DIRECTION = { $: "direction" };
93156
+ var NORMAL = { $: "normal" };
93061
93157
  var CAMERA_POSITION = { $: "cameraPosition" };
93062
93158
  var burst = (system, count, spawn2) => ({ op: "burst", system, count, spawn: spawn2 });
93063
93159
  var spawn = (system, options) => ({ op: "spawn", system, spawn: options });
@@ -93579,7 +93675,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
93579
93675
  var TIP22 = [-0.8, 1.38, 3.4 - 0.78];
93580
93676
  var PORT2 = [-0.76, 1.4, 3.32];
93581
93677
  var FORWARD3 = [0, 0, -1];
93582
- var NORMAL = [0, 0, 1];
93678
+ var NORMAL2 = [0, 0, 1];
93583
93679
  var WALL_Z2 = -4.45;
93584
93680
  var SHOTS = [[0, 0.45, 0.9], [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6], [0], [0]];
93585
93681
  var SHOT_TIME = pick2(pick2(SHOTS, PARAM), INDEX);
@@ -93604,8 +93700,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
93604
93700
  set("target", [add(-0.8, rnd(-0.4, 0.4)), add(1.4, rnd(-0.3, 0.3)), WALL_Z2]),
93605
93701
  when(
93606
93702
  eq(PARAM, SHOTGUN),
93607
- [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))],
93608
- [call2("impact", "concrete", variable("target"), NORMAL, ite(eq(PARAM, BARRETT), 2, 1))]
93703
+ [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))],
93704
+ [call2("impact", "concrete", variable("target"), NORMAL2, ite(eq(PARAM, BARRETT), 2, 1))]
93609
93705
  ),
93610
93706
  when(and(eq(PARAM, AK), eq(mod(round4(mul(SHOT_TIME, 10)), 3), 0)), [spawn("streak", { p: TIP22, dir: FORWARD3, cone: 0, sp: 90, life: 0.09, len: 0.025, c0: 16752704, a: 1 })])
93611
93707
  )
@@ -95000,7 +95096,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
95000
95096
  };
95001
95097
  var VIEWMODEL_EFFECTS = [MUZZLE_FLASH2, SMOKE_PUFF, BACKBLAST, FLAME_JET];
95002
95098
  var aliasOf = (base, id, changes) => ({ ...base, id, pageId: `vehicle:${id}`, anchor: CAR_ORIGIN2, ...changes });
95099
+ var BODYWORK_IMPACT = {
95100
+ id: "impact_bodywork",
95101
+ pageId: "vehicle:impact_bodywork",
95102
+ team: "vehicles",
95103
+ budget: { particles: 80, debris: 20, lights: 1 },
95104
+ loop: 2,
95105
+ timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
95106
+ };
95003
95107
  var VEHICLE_EFFECTS = [
95108
+ BODYWORK_IMPACT,
95004
95109
  /** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
95005
95110
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
95006
95111
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
@@ -95705,6 +95810,46 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
95705
95810
  return evaluateCall(value.$, args.map((entry2) => resolve(entry2, context)));
95706
95811
  }
95707
95812
  }
95813
+ var PISTOL_BORE = 9e-3;
95814
+ var BARE_STEEL = 11778236;
95815
+ var DEFAULT_PAINT = 9147290;
95816
+ var DEFAULT_DIRECTION = [0, 0, -1];
95817
+ var MAX_SCALE = 3;
95818
+ var MIN_SCALE = 0.6;
95819
+ function reflected(direction, normal) {
95820
+ const along2 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
95821
+ const out = [direction[0] - 2 * along2 * normal[0], direction[1] - 2 * along2 * normal[1], direction[2] - 2 * along2 * normal[2]];
95822
+ const length2 = Math.hypot(out[0], out[1], out[2]);
95823
+ if (length2 < 1e-6 || Math.abs(along2) > 0.98) return normal;
95824
+ return [out[0] / length2, out[1] / length2, out[2] / length2];
95825
+ }
95826
+ var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
95827
+ function bodyworkHitOf(values) {
95828
+ const raw = Array.isArray(values.direction) ? values.direction : [];
95829
+ const direction = raw.length === 3 && raw.every((entry2) => typeof entry2 === "number" && Number.isFinite(entry2)) ? [raw[0], raw[1], raw[2]] : DEFAULT_DIRECTION;
95830
+ return { direction, bore: numberOr(values.bore, PISTOL_BORE), paint: numberOr(values.paint, DEFAULT_PAINT), metal: numberOr(values.metal, BARE_STEEL) };
95831
+ }
95832
+ function bodyworkScale(bore) {
95833
+ return Math.min(MAX_SCALE, Math.max(MIN_SCALE, bore / PISTOL_BORE));
95834
+ }
95835
+ function bodyworkImpact(engine, point, normal, hit) {
95836
+ const scale = bodyworkScale(hit.bore);
95837
+ const off = reflected(hit.direction, normal);
95838
+ if (engine.quality < 2) {
95839
+ 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 });
95840
+ engine.burst("add", 2, { p: plusScaled(point, normal, 0.01), size: [0.06 * scale, 0.12 * scale], life: 0.05, c0: 16770736, fi: 0 });
95841
+ engine.flash([plusScaled(point, normal, 0.15), 16760432, 1.6 * scale, 0.05, 4]);
95842
+ }
95843
+ const flakes = engine.scaled(Math.round(5 * scale));
95844
+ for (let index = 0; index < flakes; index++) {
95845
+ 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 });
95846
+ }
95847
+ const slivers = engine.scaled(Math.round(2 * scale));
95848
+ for (let index = 0; index < slivers; index++) {
95849
+ 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 });
95850
+ }
95851
+ 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 });
95852
+ }
95708
95853
  var UP12 = [0, 1, 0];
95709
95854
  var ZERO2 = [0, 0, 0];
95710
95855
  var FULL_TURN_DRAWN = 6.283;
@@ -95854,9 +95999,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
95854
95999
  casing: ({ engine }, [port, type]) => casing(engine, port, type),
95855
96000
  chips: ({ engine }, [point, direction, count, spread2]) => chips(engine, point, direction, count, spread2),
95856
96001
  spark_at: ({ engine }, [point, direction, count, spread2]) => sparkAt(engine, point, direction, count, spread2),
95857
- rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count)
96002
+ rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count),
96003
+ bodywork_impact: ({ engine }, [point, normal, direction, bore, paint2, metal2]) => bodyworkImpact(engine, point, normal, bodyworkHitOf({ direction, bore, paint: paint2, metal: metal2 }))
95858
96004
  };
95859
- var DEFAULT_DIRECTION = [0, 0, -1];
96005
+ var DEFAULT_DIRECTION2 = [0, 0, -1];
95860
96006
  var DEFAULT_NORMAL = [0, 1, 0];
95861
96007
  var SCREEN_FIELDS = {
95862
96008
  shake: "shake",
@@ -95923,7 +96069,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
95923
96069
  return instance().fresh;
95924
96070
  },
95925
96071
  get direction() {
95926
- return instance().setup.direction ?? DEFAULT_DIRECTION;
96072
+ return instance().setup.direction ?? DEFAULT_DIRECTION2;
95927
96073
  },
95928
96074
  get normal() {
95929
96075
  return instance().setup.normal ?? DEFAULT_NORMAL;
@@ -97681,6 +97827,69 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97681
97827
  addScaled(out, tangentB, sinTilt * Math.sin(phase));
97682
97828
  return out;
97683
97829
  }
97830
+ var CELL2 = 0.12;
97831
+ var OBSTACLE_BOUNCE = 0.3;
97832
+ var radiusOf = (piece2) => Math.max(piece2.sx, piece2.sz) * 0.5;
97833
+ var thicknessOf2 = (piece2) => Math.min(piece2.sx, piece2.sy, piece2.sz);
97834
+ var cellKey2 = (i, k) => (i + 4096) * 8192 + (k + 4096);
97835
+ var RestingGrid = class {
97836
+ constructor() {
97837
+ __publicField3(this, "cells", /* @__PURE__ */ new Map());
97838
+ }
97839
+ clear() {
97840
+ for (const list2 of this.cells.values()) list2.length = 0;
97841
+ }
97842
+ rebuild(pieces) {
97843
+ this.clear();
97844
+ for (const piece2 of pieces) {
97845
+ if (!piece2.on || !piece2.rest) continue;
97846
+ const key2 = cellKey2(Math.floor(piece2.x / CELL2), Math.floor(piece2.z / CELL2));
97847
+ const list2 = this.cells.get(key2);
97848
+ if (list2) list2.push(piece2);
97849
+ else this.cells.set(key2, [piece2]);
97850
+ }
97851
+ }
97852
+ /** 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. */
97853
+ supportUnder(piece2) {
97854
+ const i = Math.floor(piece2.x / CELL2);
97855
+ const k = Math.floor(piece2.z / CELL2);
97856
+ const reach2 = radiusOf(piece2);
97857
+ let top = -Infinity;
97858
+ for (let di = -1; di <= 1; di++) {
97859
+ for (let dk = -1; dk <= 1; dk++) {
97860
+ for (const other of this.cells.get(cellKey2(i + di, k + dk)) ?? []) {
97861
+ if (other === piece2) continue;
97862
+ if (Math.hypot(other.x - piece2.x, other.z - piece2.z) > reach2 + radiusOf(other)) continue;
97863
+ const otherTop = other.y + thicknessOf2(other) * 0.5;
97864
+ if (otherTop <= piece2.y + thicknessOf2(piece2) * 0.5) top = Math.max(top, otherTop + thicknessOf2(piece2) * 0.5);
97865
+ }
97866
+ }
97867
+ }
97868
+ return top;
97869
+ }
97870
+ };
97871
+ function pushOutOfObstacles(piece2, obstacles) {
97872
+ let moved = false;
97873
+ for (const body of obstacles) {
97874
+ if (piece2.y < body.bottom || piece2.y > body.top) continue;
97875
+ const dx = piece2.x - body.x;
97876
+ const dz = piece2.z - body.z;
97877
+ const distance4 = Math.hypot(dx, dz);
97878
+ const reach2 = body.radius + radiusOf(piece2);
97879
+ if (distance4 >= reach2) continue;
97880
+ const nx = distance4 > 1e-6 ? dx / distance4 : 1;
97881
+ const nz = distance4 > 1e-6 ? dz / distance4 : 0;
97882
+ piece2.x = body.x + nx * reach2;
97883
+ piece2.z = body.z + nz * reach2;
97884
+ const into = piece2.vx * nx + piece2.vz * nz;
97885
+ if (into < 0) {
97886
+ piece2.vx -= (1 + OBSTACLE_BOUNCE) * into * nx;
97887
+ piece2.vz -= (1 + OBSTACLE_BOUNCE) * into * nz;
97888
+ }
97889
+ moved = true;
97890
+ }
97891
+ return moved;
97892
+ }
97684
97893
  var CAPACITY = 500;
97685
97894
  var GRAVITY22 = 9.8;
97686
97895
  var QUARTER_TURN4 = 1.5708;
@@ -97701,6 +97910,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97701
97910
  __publicField3(this, "count", 0);
97702
97911
  __publicField3(this, "next", 0);
97703
97912
  __publicField3(this, "direction", { x: 0, y: 0, z: 0 });
97913
+ __publicField3(this, "resting", new RestingGrid());
97704
97914
  }
97705
97915
  spawn(options) {
97706
97916
  const random = this.context.random;
@@ -97738,14 +97948,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97738
97948
  }
97739
97949
  update(dt) {
97740
97950
  this.count = 0;
97951
+ const contacts = this.context.debrisContacts;
97952
+ const obstacles = contacts?.obstacles() ?? [];
97953
+ let moving = false;
97741
97954
  for (const piece2 of this.pieces) {
97742
97955
  if (!piece2.on) continue;
97743
- this.count++;
97744
97956
  piece2.life -= dt;
97745
- if (piece2.life <= 0) {
97746
- piece2.on = false;
97747
- continue;
97748
- }
97957
+ if (piece2.life <= 0) piece2.on = false;
97958
+ else if (!piece2.rest) moving = true;
97959
+ }
97960
+ if (moving && contacts) this.resting.rebuild(this.pieces);
97961
+ else this.resting.clear();
97962
+ for (const piece2 of this.pieces) {
97963
+ if (!piece2.on) continue;
97964
+ this.count++;
97965
+ if (obstacles.length > 0 && pushOutOfObstacles(piece2, obstacles)) piece2.rest = false;
97749
97966
  if (!piece2.rest) this.move(piece2, dt);
97750
97967
  }
97751
97968
  }
@@ -97761,7 +97978,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97761
97978
  piece2.rx += piece2.ax * dt;
97762
97979
  piece2.ry += piece2.ay * dt;
97763
97980
  piece2.rz += piece2.az * dt;
97764
- const groundHeight = this.context.groundAt(piece2.x, piece2.z) + Math.min(piece2.sx, piece2.sy, piece2.sz) * 0.5;
97981
+ const groundHeight = Math.max(this.context.groundAt(piece2.x, piece2.z) + Math.min(piece2.sx, piece2.sy, piece2.sz) * 0.5, this.resting.supportUnder(piece2));
97765
97982
  if (piece2.y >= groundHeight) return;
97766
97983
  piece2.y = groundHeight;
97767
97984
  piece2.vy *= -piece2.bounce;
@@ -98421,6 +98638,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
98421
98638
  this.decals = new DecalPool(this.context);
98422
98639
  this.lights = new FlashLightPool(this.context);
98423
98640
  }
98641
+ /**
98642
+ * 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
98643
+ * upright bodies `obstacles` answers (the player, asked once a frame while a piece moves) stop them and push them. `null` turns it off.
98644
+ */
98645
+ setDebrisContacts(obstacles) {
98646
+ if (obstacles) this.context.debrisContacts = { obstacles };
98647
+ else delete this.context.debrisContacts;
98648
+ }
98424
98649
  get random() {
98425
98650
  return this.context.random;
98426
98651
  }