@adatechnology/game-weapons-three 0.27.6 → 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.
@@ -9559,6 +9559,7 @@ var oneHandHold = (hold, hand) => {
9559
9559
  };
9560
9560
 
9561
9561
  // src/fx/tool-motion.ts
9562
+ import { MELEE_FAMILIES } from "@adatechnology/game-weapons";
9562
9563
  var HOLD = { offset: [0, 0, 0], turn: [0, 0, 0] };
9563
9564
  var SHOVEL_DIG = {
9564
9565
  keys: [
@@ -9589,8 +9590,59 @@ var SHOVEL_SWING = {
9589
9590
  { at: 1, ...HOLD }
9590
9591
  ]
9591
9592
  };
9592
- var TOOL_MOTIONS = /* @__PURE__ */ new Map([
9593
- ["shovel", /* @__PURE__ */ new Map([["dig", SHOVEL_DIG], ["fill", SHOVEL_FILL], ["swing", SHOVEL_SWING]])]
9593
+ var KNIFE_SLASH = {
9594
+ pivot: "grip",
9595
+ keys: [
9596
+ { at: 0, ...HOLD },
9597
+ { at: 0.28, offset: [0.07, 0.2, 0.05], turn: [0.5, -0.9, 0] },
9598
+ { at: 0.43, offset: [-0.14, 0.06, -0.07], turn: [0.1, 0.9, 0] },
9599
+ { at: 0.62, offset: [-0.2, -0.08, 0], turn: [-0.2, 1.3, 0] },
9600
+ { at: 1, ...HOLD }
9601
+ ]
9602
+ };
9603
+ var KNIFE_STAB = {
9604
+ pivot: "grip",
9605
+ keys: [
9606
+ { at: 0, ...HOLD },
9607
+ { at: 0.28, offset: [0.03, -0.05, 0.08], turn: [0.15, -0.1, 0] },
9608
+ { at: 0.43, offset: [-0.1, 0.07, -0.12], turn: [0.1, 0.55, 0] },
9609
+ { at: 0.6, offset: [-0.1, 0.07, -0.11], turn: [0.1, 0.52, 0] },
9610
+ { at: 1, ...HOLD }
9611
+ ]
9612
+ };
9613
+ var BAT_SWING = {
9614
+ pivot: "grip",
9615
+ keys: [
9616
+ { at: 0, ...HOLD },
9617
+ { at: 0.29, offset: [0.12, 0.12, 0.1], turn: [1.9, -0.6, 0] },
9618
+ { at: 0.43, offset: [-0.1, 0.04, -0.07], turn: [-0.3, 1.2, 0] },
9619
+ { at: 0.64, offset: [-0.28, 0.1, 0], turn: [2, 1, 0] },
9620
+ { at: 0.8, offset: [-0.2, 0.06, 0.02], turn: [1.8, 0.8, 0] },
9621
+ { at: 1, ...HOLD }
9622
+ ]
9623
+ };
9624
+ var ONE_HAND_CHOP = {
9625
+ keys: [
9626
+ { at: 0, ...HOLD },
9627
+ { at: 0.3, offset: [0.04, 0.4, 0.04], turn: [0.5, 0, -0.2] },
9628
+ { at: 0.43, offset: [-0.03, 0.18, -0.22], turn: [-0.6, 0, 0.1] },
9629
+ { at: 0.62, offset: [-0.05, -0.03, -0.18], turn: [-1.1, 0, 0.2] },
9630
+ { at: 1, ...HOLD }
9631
+ ]
9632
+ };
9633
+ var FAMILY_MOTIONS = /* @__PURE__ */ new Map([
9634
+ ["short_blade", /* @__PURE__ */ new Map([["slash", KNIFE_SLASH], ["stab", KNIFE_STAB]])],
9635
+ ["one_hand_swing", /* @__PURE__ */ new Map([["chop", ONE_HAND_CHOP]])],
9636
+ ["bat_swing", /* @__PURE__ */ new Map([["bat_swing", BAT_SWING]])],
9637
+ // an axe or a pickaxe swung with both hands goes as the shovel's swing
9638
+ ["two_hand_swing", /* @__PURE__ */ new Map([["swing", SHOVEL_SWING]])]
9639
+ ]);
9640
+ var TOOL_MOTIONS = new Map([
9641
+ ["shovel", /* @__PURE__ */ new Map([["dig", SHOVEL_DIG], ["fill", SHOVEL_FILL], ["swing", SHOVEL_SWING]])],
9642
+ ...MELEE_FAMILIES.flatMap((family) => {
9643
+ const motions = FAMILY_MOTIONS.get(family.id);
9644
+ return motions ? family.weapons.map((weapon) => [weapon, motions]) : [];
9645
+ })
9594
9646
  ]);
9595
9647
  var ease2 = (s) => s * s * (3 - 2 * s);
9596
9648
  function sampleToolMotion(motion, at2) {
@@ -9881,7 +9933,13 @@ var SHIPPED_WEAPON_ITEM_MODELS = [
9881
9933
  // 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
9882
9934
  ["kabar", { flip: true }],
9883
9935
  ["katana", { flip: true, grips: { handle: -0.35, support: -0.4622 } }],
9884
- ["brass_knuckles", { turn: 1, roll: 1, grips: { handle: -0.35, handleAt: [-0.045, 0.03] } }]
9936
+ ["brass_knuckles", { turn: 1, roll: 1, grips: { handle: -0.35, handleAt: [-0.045, 0.03] } }],
9937
+ // 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)
9938
+ ["baseball_bat", { grips: { handle: -0.3, support: -0.41 } }],
9939
+ ["nail_bat", { grips: { handle: -0.3, support: -0.41 } }],
9940
+ ["iron_pipe", { grips: { handle: -0.29, support: -0.41 } }],
9941
+ ["crowbar", { grips: { handle: -0.3, support: -0.42 } }],
9942
+ ["sledgehammer", { grips: { handle: -0.22, support: -0.42 } }]
9885
9943
  ];
9886
9944
  var hasThrowableModel = (def) => def.action?.kind === "throwable" && def.action.explosive !== void 0 && hasExplosiveModel(def.action.explosive);
9887
9945
  var buildThrowableModel = (THREE, def) => def.action?.kind === "throwable" && def.action.explosive !== void 0 ? buildExplosiveModel(THREE, def.action.explosive) : void 0;
@@ -9912,6 +9970,7 @@ var buildItemWeaponModel = (THREE, def, items) => defaultWeaponProps().buildItem
9912
9970
  var buildWeaponModel = (THREE, def, items) => defaultWeaponProps().buildModel(THREE, def, items);
9913
9971
 
9914
9972
  // src/box-fx.ts
9973
+ var TOOL_REACH = 0.47;
9915
9974
  var EJECTS_ON_SHOT = /* @__PURE__ */ new Set(["pistol", "smg", "carbine", "rifle", "sniper", "shotgun"]);
9916
9975
  var SPOUTS = /* @__PURE__ */ new Set(["firearm", "flame", "heat", "extinguisher"]);
9917
9976
  var DROPS_MAGAZINE = /* @__PURE__ */ new Set(["pistol", "smg", "carbine", "rifle", "sniper"]);
@@ -9942,8 +10001,27 @@ function createBoxFx(options) {
9942
10001
  const applyMotion = (frame) => {
9943
10002
  if (!motion) return;
9944
10003
  const at2 = sampleToolMotion(motion.clip, motion.elapsed / motion.duration);
9945
- hand.position.add(v.set(at2.offset[0], at2.offset[1], at2.offset[2]).applyQuaternion(frame));
10004
+ const anchor = motion.clip.pivot === "grip" ? heldAnchor(heldHold()) : null;
10005
+ if (anchor) {
10006
+ hand.updateMatrixWorld(true);
10007
+ anchor.part.localToWorld(gripBefore.copy(anchor.offset));
10008
+ }
9946
10009
  hand.quaternion.multiply(q.setFromEuler(new THREE.Euler(at2.turn[0], at2.turn[1], at2.turn[2])));
10010
+ if (anchor) {
10011
+ hand.updateMatrixWorld(true);
10012
+ hand.position.add(gripBefore.sub(anchor.part.localToWorld(gripAfter.copy(anchor.offset))));
10013
+ }
10014
+ hand.position.add(v.set(at2.offset[0], at2.offset[1], at2.offset[2]).applyQuaternion(frame));
10015
+ };
10016
+ const keepInReach = (shoulder) => {
10017
+ const anchor = heldAnchor(heldHold());
10018
+ if (!anchor) return;
10019
+ hand.updateMatrixWorld(true);
10020
+ const away = anchor.part.localToWorld(gripAfter.copy(anchor.offset)).sub(gripBefore.set(shoulder[0], shoulder[1], shoulder[2]));
10021
+ const distance = away.length();
10022
+ if (distance <= TOOL_REACH) return;
10023
+ hand.position.sub(away.multiplyScalar(1 - TOOL_REACH / distance));
10024
+ hand.updateMatrixWorld(true);
9947
10025
  };
9948
10026
  let dip = 0;
9949
10027
  let reloading = false;
@@ -9963,6 +10041,8 @@ function createBoxFx(options) {
9963
10041
  const frontOf = new THREE.Vector3();
9964
10042
  const restBox = new THREE.Box3();
9965
10043
  const noMotion = new THREE.Vector3();
10044
+ const gripBefore = new THREE.Vector3();
10045
+ const gripAfter = new THREE.Vector3();
9966
10046
  let inLens = false;
9967
10047
  const setLens = (on) => {
9968
10048
  if (on !== inLens) options.viewmodelFov?.(on ? VIEW_HOLD.tool.fov : null);
@@ -10162,8 +10242,9 @@ function createBoxFx(options) {
10162
10242
  hand.position.add(v.set(0, -0.12 * dip, 0.05 * kick).applyQuaternion(camera.quaternion));
10163
10243
  q.setFromEuler(new THREE.Euler(0.14 * kick - 0.25 * dip, 0, 0.6 * dip));
10164
10244
  hand.quaternion.multiply(q);
10165
- const body = (options.bodyHold?.() ?? eyeFrame()).quaternion;
10166
- applyMotion(bodyFrame.set(body[0], body[1], body[2], body[3]));
10245
+ const body = options.bodyHold?.() ?? eyeFrame();
10246
+ applyMotion(bodyFrame.set(body.quaternion[0], body.quaternion[1], body.quaternion[2], body.quaternion[3]));
10247
+ if (motion) keepInReach(body.position);
10167
10248
  }
10168
10249
  stow(dt);
10169
10250
  for (const body of [...bodies]) {
@@ -15991,6 +16072,7 @@ export {
15991
16072
  createWeaponAudio,
15992
16073
  VIEW_HOLD,
15993
16074
  toWorldLens,
16075
+ FAMILY_MOTIONS,
15994
16076
  TOOL_MOTIONS,
15995
16077
  sampleToolMotion,
15996
16078
  BODY_ACTIONS,
@@ -16060,4 +16142,4 @@ export {
16060
16142
  DEFAULT_EXPLOSIVES_SCENE,
16061
16143
  createExplosivesTestModule
16062
16144
  };
16063
- //# sourceMappingURL=chunk-GXZM4CE6.js.map
16145
+ //# sourceMappingURL=chunk-5IW5LQG6.js.map