@adatechnology/game-weapons-three 0.21.2 → 0.21.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.
@@ -11320,9 +11320,13 @@ function createEffects(THREE, sink, random) {
11320
11320
  const seed = () => 1 + Math.floor(random() * 2147483646);
11321
11321
  const barrel = (orientation) => vec(new THREE.Vector3(1, 0, 0).applyQuaternion(orientation));
11322
11322
  return {
11323
- muzzleFlash(position, orientation, size, profile = MUZZLE_SMOKE.smokeless) {
11323
+ muzzleFlash(position, orientation, size, profile = MUZZLE_SMOKE.smokeless, track) {
11324
11324
  if (profile.puffs <= 0 && profile.flash <= 0) return;
11325
- sink?.play({ effect: VIEWMODEL_EFFECT_IDS.flash, point: vec(position), direction: barrel(orientation), orientation: quaternion(orientation), seed: seed(), values: { size, ...profile } });
11325
+ const follow = track ? () => {
11326
+ const pose = track();
11327
+ return pose ? { point: vec(pose.position), orientation: quaternion(pose.orientation) } : null;
11328
+ } : void 0;
11329
+ sink?.play({ effect: VIEWMODEL_EFFECT_IDS.flash, point: vec(position), direction: barrel(orientation), orientation: quaternion(orientation), seed: seed(), values: { size, ...profile }, ...follow ? { track: follow } : {} });
11326
11330
  },
11327
11331
  smoke(position, velocity, size, life, opacity) {
11328
11332
  sink?.play({ effect: VIEWMODEL_EFFECT_IDS.smoke, point: vec(position), seed: seed(), values: { vx: velocity.x, vy: velocity.y, vz: velocity.z, radius: size, life, opacity } });
@@ -11719,17 +11723,19 @@ function createClipEventHandler(world, session) {
11719
11723
  particles.spawn(round2.group, toWorld(session, vector(-0.2, 1.1, 1.2)), { kind: "round", life: 25, radius: round2.radius, bounce: 0.3, spin: vector(8, 12, 6), onRest: restFlat, ownsGeometry: true });
11720
11724
  } else ejectFromPort(false);
11721
11725
  };
11726
+ const trackOf = (mark) => () => root.parent ? { position: positionOf(mark), orientation: root.getWorldQuaternion(new THREE.Quaternion()) } : null;
11722
11727
  return (event) => {
11723
11728
  const data = event.data ?? {};
11724
11729
  switch (event.type) {
11725
11730
  case "muzzle_flash":
11726
11731
  if (data.at === "ugl") {
11727
- if (parts.uglMuzzle && world.layers.muzzleFlash) world.afterPose(() => parts.uglMuzzle && effects.muzzleFlash(positionOf(parts.uglMuzzle), root.getWorldQuaternion(new THREE.Quaternion()), UGL_FLASH));
11732
+ const ugl = parts.uglMuzzle;
11733
+ if (ugl && world.layers.muzzleFlash) world.afterPose(() => effects.muzzleFlash(positionOf(ugl), root.getWorldQuaternion(new THREE.Quaternion()), UGL_FLASH, void 0, trackOf(ugl)));
11728
11734
  } else if (parts.muzzle && world.layers.muzzleFlash && (session.def.action.kind === "firearm" || session.def.action.kind === "launcher")) {
11729
11735
  const profile = muzzleSmokeOf({ caliber: session.caliber, weapon: session.def, suppressed: session.suppressed });
11730
11736
  const size = session.def.action.kind === "launcher" ? 2.2 : FLASH_BY_CASE[session.caseType];
11731
11737
  const muzzle = parts.muzzle;
11732
- world.afterPose(() => effects.muzzleFlash(positionOf(muzzle), root.getWorldQuaternion(new THREE.Quaternion()), size, profile));
11738
+ world.afterPose(() => effects.muzzleFlash(positionOf(muzzle), root.getWorldQuaternion(new THREE.Quaternion()), size, profile, trackOf(muzzle)));
11733
11739
  }
11734
11740
  break;
11735
11741
  case "eject_casing":
@@ -12321,11 +12327,17 @@ function createViewmodel(options) {
12321
12327
  play: (request) => {
12322
12328
  if (!lens || !request.point) return worldSink.play(request);
12323
12329
  const at2 = toWorldLens(camera, lensPoint.set(...request.point), worldFovOf(), lens.fov);
12324
- return worldSink.play({ ...request, point: [at2.x, at2.y, at2.z] });
12330
+ const track = request.track;
12331
+ return worldSink.play({ ...request, point: [at2.x, at2.y, at2.z], ...track ? { track: () => seenThroughLens(track()) } : {} });
12325
12332
  },
12326
12333
  stop: (handle) => worldSink.stop(handle)
12327
12334
  } : void 0;
12328
12335
  const effects = createEffects(THREE, lensSink, random);
12336
+ function seenThroughLens(pose) {
12337
+ if (!pose || !lens) return pose;
12338
+ const at2 = toWorldLens(camera, trackPoint.set(...pose.point), worldFovOf(), lens.fov);
12339
+ return { ...pose, point: [at2.x, at2.y, at2.z] };
12340
+ }
12329
12341
  const hand = new THREE.Group();
12330
12342
  hand.name = VIEWMODEL_NODE_NAME;
12331
12343
  scene.add(hand);
@@ -12492,6 +12504,7 @@ function createViewmodel(options) {
12492
12504
  let lens = null;
12493
12505
  let lensLayer = -1;
12494
12506
  const lensPoint = new THREE.Vector3();
12507
+ const trackPoint = new THREE.Vector3();
12495
12508
  const worldFovOf = () => camera.fov ?? 72;
12496
12509
  const setLens = (kind) => {
12497
12510
  const fov = kind ? VIEW_HOLD[kind].fov : null;
@@ -15546,4 +15559,4 @@ export {
15546
15559
  DEFAULT_EXPLOSIVES_SCENE,
15547
15560
  createExplosivesTestModule
15548
15561
  };
15549
- //# sourceMappingURL=chunk-7WOQSHOL.js.map
15562
+ //# sourceMappingURL=chunk-O5SQTNFW.js.map