@adatechnology/game-weapons-three 0.28.0 → 0.29.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.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,29 @@ ${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
+ },
17286
+ {
17287
+ id: "two_hand_swing",
17288
+ 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",
17289
+ weapons: [
17275
17290
  "axe",
17276
- "sledgehammer",
17277
17291
  "pickaxe",
17278
17292
  "katana"
17279
17293
  ],
@@ -50894,7 +50908,44 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50894
50908
  consumes: false,
50895
50909
  items: [
50896
50910
  "flashlight"
50897
- ]
50911
+ ],
50912
+ params: {
50913
+ clip: "toggle_flashlight"
50914
+ }
50915
+ },
50916
+ {
50917
+ id: "ignite",
50918
+ effect: "ignite",
50919
+ consumes: false,
50920
+ items: [
50921
+ "lighter"
50922
+ ],
50923
+ params: {
50924
+ clip: "light_lighter"
50925
+ }
50926
+ },
50927
+ {
50928
+ id: "radio_call",
50929
+ effect: "radio_call",
50930
+ consumes: false,
50931
+ items: [
50932
+ "portable_radio",
50933
+ "walkie_talkies"
50934
+ ],
50935
+ params: {
50936
+ clip: "use_radio"
50937
+ }
50938
+ },
50939
+ {
50940
+ id: "turn_key",
50941
+ effect: "turn_key",
50942
+ consumes: false,
50943
+ category: [
50944
+ "keys"
50945
+ ],
50946
+ params: {
50947
+ clip: "turn_key"
50948
+ }
50898
50949
  },
50899
50950
  {
50900
50951
  id: "swap_bag",
@@ -82823,20 +82874,33 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
82823
82874
  ]
82824
82875
  };
82825
82876
  var KNIFE_SLASH = {
82877
+ pivot: "grip",
82826
82878
  keys: [
82827
82879
  { 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] },
82880
+ { at: 0.28, offset: [0.07, 0.2, 0.05], turn: [0.5, -0.9, 0] },
82881
+ { at: 0.43, offset: [-0.14, 0.06, -0.07], turn: [0.1, 0.9, 0] },
82882
+ { at: 0.62, offset: [-0.2, -0.08, 0], turn: [-0.2, 1.3, 0] },
82831
82883
  { at: 1, ...HOLD }
82832
82884
  ]
82833
82885
  };
82834
82886
  var KNIFE_STAB = {
82887
+ pivot: "grip",
82835
82888
  keys: [
82836
82889
  { 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] },
82890
+ { at: 0.28, offset: [0.03, -0.05, 0.08], turn: [0.15, -0.1, 0] },
82891
+ { at: 0.43, offset: [-0.1, 0.07, -0.12], turn: [0.1, 0.55, 0] },
82892
+ { at: 0.6, offset: [-0.1, 0.07, -0.11], turn: [0.1, 0.52, 0] },
82893
+ { at: 1, ...HOLD }
82894
+ ]
82895
+ };
82896
+ var BAT_SWING = {
82897
+ pivot: "grip",
82898
+ keys: [
82899
+ { at: 0, ...HOLD },
82900
+ { at: 0.29, offset: [0.12, 0.12, 0.1], turn: [1.9, -0.6, 0] },
82901
+ { at: 0.43, offset: [-0.1, 0.04, -0.07], turn: [-0.3, 1.2, 0] },
82902
+ { at: 0.64, offset: [-0.28, 0.1, 0], turn: [2, 1, 0] },
82903
+ { at: 0.8, offset: [-0.2, 0.06, 0.02], turn: [1.8, 0.8, 0] },
82840
82904
  { at: 1, ...HOLD }
82841
82905
  ]
82842
82906
  };
@@ -82852,7 +82916,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
82852
82916
  var FAMILY_MOTIONS = /* @__PURE__ */ new Map([
82853
82917
  ["short_blade", /* @__PURE__ */ new Map([["slash", KNIFE_SLASH], ["stab", KNIFE_STAB]])],
82854
82918
  ["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
82919
+ ["bat_swing", /* @__PURE__ */ new Map([["bat_swing", BAT_SWING]])],
82920
+ // an axe or a pickaxe swung with both hands goes as the shovel's swing
82856
82921
  ["two_hand_swing", /* @__PURE__ */ new Map([["swing", SHOVEL_SWING]])]
82857
82922
  ]);
82858
82923
  var TOOL_MOTIONS = new Map([
@@ -89656,7 +89721,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89656
89721
  // 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
89722
  ["kabar", { flip: true }],
89658
89723
  ["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] } }]
89724
+ ["brass_knuckles", { turn: 1, roll: 1, grips: { handle: -0.35, handleAt: [-0.045, 0.03] } }],
89725
+ // 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)
89726
+ ["baseball_bat", { grips: { handle: -0.3, support: -0.41 } }],
89727
+ ["nail_bat", { grips: { handle: -0.3, support: -0.41 } }],
89728
+ ["iron_pipe", { grips: { handle: -0.29, support: -0.41 } }],
89729
+ ["crowbar", { grips: { handle: -0.3, support: -0.42 } }],
89730
+ ["sledgehammer", { grips: { handle: -0.22, support: -0.42 } }]
89660
89731
  ];
89661
89732
  var hasThrowableModel = (def) => def.action?.kind === "throwable" && def.action.explosive !== void 0 && hasExplosiveModel(def.action.explosive);
89662
89733
  var buildThrowableModel = (THREE, def) => def.action?.kind === "throwable" && def.action.explosive !== void 0 ? buildExplosiveModel(THREE, def.action.explosive) : void 0;
@@ -89687,6 +89758,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89687
89758
  var buildWeaponModel = (THREE, def, items) => defaultWeaponProps().buildModel(THREE, def, items);
89688
89759
 
89689
89760
  // src/box-fx.ts
89761
+ var TOOL_REACH = 0.47;
89690
89762
  var EJECTS_ON_SHOT = /* @__PURE__ */ new Set(["pistol", "smg", "carbine", "rifle", "sniper", "shotgun"]);
89691
89763
  var SPOUTS = /* @__PURE__ */ new Set(["firearm", "flame", "heat", "extinguisher"]);
89692
89764
  var DROPS_MAGAZINE = /* @__PURE__ */ new Set(["pistol", "smg", "carbine", "rifle", "sniper"]);
@@ -89717,8 +89789,27 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89717
89789
  const applyMotion = (frame2) => {
89718
89790
  if (!motion) return;
89719
89791
  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));
89792
+ const anchor = motion.clip.pivot === "grip" ? heldAnchor(heldHold()) : null;
89793
+ if (anchor) {
89794
+ hand.updateMatrixWorld(true);
89795
+ anchor.part.localToWorld(gripBefore.copy(anchor.offset));
89796
+ }
89721
89797
  hand.quaternion.multiply(q.setFromEuler(new THREE.Euler(at4.turn[0], at4.turn[1], at4.turn[2])));
89798
+ if (anchor) {
89799
+ hand.updateMatrixWorld(true);
89800
+ hand.position.add(gripBefore.sub(anchor.part.localToWorld(gripAfter.copy(anchor.offset))));
89801
+ }
89802
+ hand.position.add(v.set(at4.offset[0], at4.offset[1], at4.offset[2]).applyQuaternion(frame2));
89803
+ };
89804
+ const keepInReach = (shoulder) => {
89805
+ const anchor = heldAnchor(heldHold());
89806
+ if (!anchor) return;
89807
+ hand.updateMatrixWorld(true);
89808
+ const away = anchor.part.localToWorld(gripAfter.copy(anchor.offset)).sub(gripBefore.set(shoulder[0], shoulder[1], shoulder[2]));
89809
+ const distance4 = away.length();
89810
+ if (distance4 <= TOOL_REACH) return;
89811
+ hand.position.sub(away.multiplyScalar(1 - TOOL_REACH / distance4));
89812
+ hand.updateMatrixWorld(true);
89722
89813
  };
89723
89814
  let dip = 0;
89724
89815
  let reloading = false;
@@ -89738,6 +89829,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89738
89829
  const frontOf = new THREE.Vector3();
89739
89830
  const restBox2 = new THREE.Box3();
89740
89831
  const noMotion = new THREE.Vector3();
89832
+ const gripBefore = new THREE.Vector3();
89833
+ const gripAfter = new THREE.Vector3();
89741
89834
  let inLens = false;
89742
89835
  const setLens = (on) => {
89743
89836
  if (on !== inLens) options.viewmodelFov?.(on ? VIEW_HOLD.tool.fov : null);
@@ -89937,8 +90030,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89937
90030
  hand.position.add(v.set(0, -0.12 * dip, 0.05 * kick).applyQuaternion(camera2.quaternion));
89938
90031
  q.setFromEuler(new THREE.Euler(0.14 * kick - 0.25 * dip, 0, 0.6 * dip));
89939
90032
  hand.quaternion.multiply(q);
89940
- const body = (options.bodyHold?.() ?? eyeFrame()).quaternion;
89941
- applyMotion(bodyFrame.set(body[0], body[1], body[2], body[3]));
90033
+ const body = options.bodyHold?.() ?? eyeFrame();
90034
+ applyMotion(bodyFrame.set(body.quaternion[0], body.quaternion[1], body.quaternion[2], body.quaternion[3]));
90035
+ if (motion) keepInReach(body.position);
89942
90036
  }
89943
90037
  stow(dt);
89944
90038
  for (const body of [...bodies]) {