@adatechnology/game-weapons-three 0.24.4 → 0.25.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.
@@ -43,6 +43,7 @@ var GameWeaponsThree = (() => {
43
43
  HOLSTER_TOSS: () => HOLSTER_TOSS,
44
44
  LAUNCH_SAMPLE: () => LAUNCH_SAMPLE,
45
45
  LAUNCH_SOUND_IDS: () => LAUNCH_SOUND_IDS,
46
+ LOOSE_ROLLING_RESISTANCE: () => LOOSE_ROLLING_RESISTANCE,
46
47
  MECHANICAL_SOUNDS: () => MECHANICAL_SOUNDS,
47
48
  MODEL_ENTRIES: () => MODEL_ENTRIES,
48
49
  MOUNTED_M134_ITEM_ID: () => MOUNTED_M134_ITEM_ID,
@@ -74,6 +75,7 @@ var GameWeaponsThree = (() => {
74
75
  buildWeaponModel: () => buildWeaponModel,
75
76
  buildWeaponModelById: () => buildWeaponModelById,
76
77
  cartridgeShape: () => cartridgeShape,
78
+ casingCollider: () => casingCollider,
77
79
  computeCasingSound: () => computeCasingSound,
78
80
  computeFlyby: () => computeFlyby,
79
81
  computeGunshot: () => computeGunshot,
@@ -88,6 +90,7 @@ var GameWeaponsThree = (() => {
88
90
  createWorldExplosiveShells: () => createWorldExplosiveShells,
89
91
  defaultWeaponProps: () => defaultWeaponProps,
90
92
  deriveFrames: () => deriveFrames,
93
+ dropLoose: () => dropLoose,
91
94
  explosivesTextOf: () => explosivesTextOf,
92
95
  fitAttachmentModels: () => fitAttachmentModels,
93
96
  hasExplosiveModel: () => hasExplosiveModel,
@@ -105,6 +108,8 @@ var GameWeaponsThree = (() => {
105
108
  rigStock: () => rigStock,
106
109
  rigUnderbarrel: () => rigUnderbarrel,
107
110
  sampleToolMotion: () => sampleToolMotion,
111
+ spawnLoose: () => spawnLoose,
112
+ syncLoose: () => syncLoose,
108
113
  toWorldLens: () => toWorldLens,
109
114
  weaponProp: () => weaponProp,
110
115
  weaponSampleBank: () => weaponSampleBank,
@@ -435,8 +440,8 @@ var GameWeaponsThree = (() => {
435
440
  ];
436
441
  var sampleClip = (clip, partId, time) => {
437
442
  const points = clip.keys.map((key2) => {
438
- const pose = partId === void 0 ? key2 : key2.parts?.[partId];
439
- return { t: key2.t, position: pose?.position ?? ZERO, rotation: pose?.rotation ?? ZERO };
443
+ const pose2 = partId === void 0 ? key2 : key2.parts?.[partId];
444
+ return { t: key2.t, position: pose2?.position ?? ZERO, rotation: pose2?.rotation ?? ZERO };
440
445
  });
441
446
  const first = points[0];
442
447
  if (!first || first.t > 0) points.unshift({ t: 0, position: ZERO, rotation: ZERO });
@@ -15415,16 +15420,16 @@ var GameWeaponsThree = (() => {
15415
15420
  var EPS = 1e-9;
15416
15421
  var STILL_STEPS = 2;
15417
15422
  var STILL_SHARE = 0.05;
15418
- var bounce = (velocity, normal, ground, rules) => {
15419
- const along2 = dot(velocity, normal);
15420
- if (along2 >= 0) return velocity;
15423
+ var bounce = (velocity2, normal, ground, rules) => {
15424
+ const along2 = dot(velocity2, normal);
15425
+ if (along2 >= 0) return velocity2;
15421
15426
  const restitution = ground ? rules.groundRestitution : rules.wallRestitution;
15422
15427
  const friction = ground ? rules.groundFriction : 1;
15423
15428
  const normalPart = [normal[0] * along2, normal[1] * along2, normal[2] * along2];
15424
15429
  return [
15425
- (velocity[0] - normalPart[0]) * friction - normalPart[0] * restitution,
15426
- (velocity[1] - normalPart[1]) * friction - normalPart[1] * restitution,
15427
- (velocity[2] - normalPart[2]) * friction - normalPart[2] * restitution
15430
+ (velocity2[0] - normalPart[0]) * friction - normalPart[0] * restitution,
15431
+ (velocity2[1] - normalPart[1]) * friction - normalPart[1] * restitution,
15432
+ (velocity2[2] - normalPart[2]) * friction - normalPart[2] * restitution
15428
15433
  ];
15429
15434
  };
15430
15435
  var ExplosiveBody = class {
@@ -15605,13 +15610,13 @@ var GameWeaponsThree = (() => {
15605
15610
  return range3[0] + (range3[1] - range3[0]) * random();
15606
15611
  };
15607
15612
  var launcherUses = ({ action, explosive, origin, direction, armDistance }) => {
15608
- const velocity = [direction[0] * action.speed, direction[1] * action.speed, direction[2] * action.speed];
15613
+ const velocity2 = [direction[0] * action.speed, direction[1] * action.speed, direction[2] * action.speed];
15609
15614
  const projectile = {
15610
15615
  kind: "throw",
15611
15616
  energy: explosive?.energy ?? 0,
15612
15617
  radius: explosive?.lethalRadius ?? 0,
15613
15618
  fuse: 0,
15614
- velocity,
15619
+ velocity: velocity2,
15615
15620
  origin,
15616
15621
  explosive: action.projectile,
15617
15622
  trigger: "impact",
@@ -15643,8 +15648,8 @@ var GameWeaponsThree = (() => {
15643
15648
  var throwableUse = (params) => {
15644
15649
  const { action, explosive, origin, direction, fuse, cooked, inHand } = params;
15645
15650
  if (explosive && isPlaced(explosive, fuse, params.rules)) return placedUse({ ...params, explosive });
15646
- const velocity = inHand ? [0, 0, 0] : [direction[0] * action.throwSpeed, direction[1] * action.throwSpeed + action.throwSpeed * THROW_LIFT, direction[2] * action.throwSpeed];
15647
- const use = { kind: "throw", energy: action.energy, radius: action.radius, fuse, velocity, origin };
15651
+ const velocity2 = inHand ? [0, 0, 0] : [direction[0] * action.throwSpeed, direction[1] * action.throwSpeed + action.throwSpeed * THROW_LIFT, direction[2] * action.throwSpeed];
15652
+ const use = { kind: "throw", energy: action.energy, radius: action.radius, fuse, velocity: velocity2, origin };
15648
15653
  if (cooked !== void 0) use.cooked = cooked;
15649
15654
  if (inHand) use.inHand = true;
15650
15655
  if (action.fire) use.fire = { ...action.fire };
@@ -24726,37 +24731,37 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
24726
24731
  if (shape.kind === "cylinder") return [shape.radius, shape.height / 2, shape.radius];
24727
24732
  return [shape.radius, shape.radius, shape.radius];
24728
24733
  };
24729
- var hostedSolids = (spec, state, pose) => {
24734
+ var hostedSolids = (spec, state, pose2) => {
24730
24735
  const byId = new Map((state?.parts ?? []).map((p) => [p.id, p]));
24731
24736
  const out = [];
24732
24737
  for (const ps of spec.parts) {
24733
24738
  const st = byId.get(ps.id);
24734
24739
  if (st && (GONE.has(st.status) || st.group !== 0)) continue;
24735
- const ov = pose.poses.get(ps.id);
24736
- const center = toWorld(pose.position, pose.rotation, ov?.pos ?? ps.position);
24737
- const rotation2 = quat.mul(pose.rotation, ov?.q ?? quatFromEuler(...ps.rotation ?? [0, 0, 0]));
24740
+ const ov = pose2.poses.get(ps.id);
24741
+ const center = toWorld(pose2.position, pose2.rotation, ov?.pos ?? ps.position);
24742
+ const rotation2 = quat.mul(pose2.rotation, ov?.q ?? quatFromEuler(...ps.rotation ?? [0, 0, 0]));
24738
24743
  out.push({ center, half: halfOf(ps.shape), rotation: rotation2 });
24739
24744
  }
24740
24745
  return out;
24741
24746
  };
24742
24747
  var placedPieces = /* @__PURE__ */ new WeakMap();
24743
24748
  var isSamePose = ({ known, position, rotation: rotation2 }) => known.position[0] === position[0] && known.position[1] === position[1] && known.position[2] === position[2] && known.rotation[0] === rotation2[0] && known.rotation[1] === rotation2[1] && known.rotation[2] === rotation2[2] && known.rotation[3] === rotation2[3];
24744
- var hostedPieces = (pieces, pose) => pieces.map((piece2, index) => {
24749
+ var hostedPieces = (pieces, pose2) => pieces.map((piece2, index) => {
24745
24750
  const known = placedPieces.get(piece2);
24746
- const p = pose.position, q = pose.rotation;
24751
+ const p = pose2.position, q = pose2.rotation;
24747
24752
  const isSamePlace = known !== void 0 && (piece2.key !== void 0 || known.index === index) && isSamePose({ known, position: p, rotation: q });
24748
24753
  if (known && isSamePlace) return known.solid;
24749
- const solid2 = placedPiece(piece2, index, pose);
24754
+ const solid2 = placedPiece(piece2, index, pose2);
24750
24755
  placedPieces.set(piece2, { position: [p[0], p[1], p[2]], rotation: [q[0], q[1], q[2], q[3]], index, solid: solid2 });
24751
24756
  return solid2;
24752
24757
  });
24753
- var placedPiece = (piece2, index, pose) => {
24754
- const base = { center: toWorld(pose.position, pose.rotation, piece2.center), half: piece2.half, rotation: quat.mul(pose.rotation, piece2.rotation), key: piece2.key ?? `${piece2.id}:${index}` };
24758
+ var placedPiece = (piece2, index, pose2) => {
24759
+ const base = { center: toWorld(pose2.position, pose2.rotation, piece2.center), half: piece2.half, rotation: quat.mul(pose2.rotation, piece2.rotation), key: piece2.key ?? `${piece2.id}:${index}` };
24755
24760
  if (!piece2.mesh) return base;
24756
24761
  const source = piece2.mesh.vertices;
24757
24762
  const vertices = new Float32Array(source.length);
24758
24763
  for (let i = 0; i < source.length; i += 3) {
24759
- const world = toWorld(pose.position, pose.rotation, [source[i], source[i + 1], source[i + 2]]);
24764
+ const world = toWorld(pose2.position, pose2.rotation, [source[i], source[i + 1], source[i + 2]]);
24760
24765
  vertices[i] = world[0];
24761
24766
  vertices[i + 1] = world[1];
24762
24767
  vertices[i + 2] = world[2];
@@ -53681,8 +53686,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
53681
53686
  }
53682
53687
  }
53683
53688
  connect(e, spec, valves);
53684
- const pose = at(e.item);
53685
- world.add(e.id, spec, { x: pose.x, y: e.floorY, z: pose.z, ry: pose.ry });
53689
+ const pose2 = at(e.item);
53690
+ world.add(e.id, spec, { x: pose2.x, y: e.floorY, z: pose2.z, ry: pose2.ry });
53686
53691
  out.added++;
53687
53692
  if (!isBlocked2) continue;
53688
53693
  for (const p of spec.parts || []) {
@@ -81214,9 +81219,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
81214
81219
  hold.works?.forEach((work, index) => {
81215
81220
  const k = weights2?.[index] ?? 0;
81216
81221
  if (k <= 0) return;
81217
- const pose = poseOf(work.anchor, rootQuaternion);
81218
- if (work.hand === "R") right = right ? blendPose(THREE, right, pose, k) : pose;
81219
- else left = left ? blendPose(THREE, left, pose, k) : pose;
81222
+ const pose2 = poseOf(work.anchor, rootQuaternion);
81223
+ if (work.hand === "R") right = right ? blendPose(THREE, right, pose2, k) : pose2;
81224
+ else left = left ? blendPose(THREE, left, pose2, k) : pose2;
81220
81225
  });
81221
81226
  const targets = { R: right, L: left, grip: hold.grip, gripL: hold.gripLeft, scale: hold.scale };
81222
81227
  if (hold.slideLeft && left) {
@@ -81973,13 +81978,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
81973
81978
  }
81974
81979
  var REGION_NAMES = ["wall", "sidewalk", "curb", "road"];
81975
81980
  var dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
81976
- function impactOf(region, position, velocity, cellSize) {
81981
+ function impactOf(region, position, velocity2, cellSize) {
81977
81982
  const local2 = [position[0] - region.origin[0], position[1] - region.origin[1], position[2] - region.origin[2]];
81978
81983
  return {
81979
81984
  row: region.firstRow + dot3(local2, region.rowAxis) / cellSize,
81980
81985
  column: dot3(local2, region.columnAxis) / cellSize,
81981
- along: [dot3(velocity, region.columnAxis), dot3(velocity, region.rowAxis)],
81982
- normalSpeed: -dot3(velocity, region.normal)
81986
+ along: [dot3(velocity2, region.columnAxis), dot3(velocity2, region.rowAxis)],
81987
+ normalSpeed: -dot3(velocity2, region.normal)
81983
81988
  };
81984
81989
  }
81985
81990
  function cellToWorldOf(regions, cellSize, row, column) {
@@ -82079,7 +82084,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
82079
82084
  }
82080
82085
  return -1;
82081
82086
  },
82082
- impact: (region, position, velocity) => impactOf(regions[region], position, velocity, cellSize),
82087
+ impact: (region, position, velocity2) => impactOf(regions[region], position, velocity2, cellSize),
82083
82088
  contains: (position) => position[0] > originX && position[0] < maxX && (!rules.clipRoadEnd || position[2] < roadEndZ),
82084
82089
  escaped(position) {
82085
82090
  if (position[1] < -1) return true;
@@ -88722,11 +88727,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
88722
88727
  }
88723
88728
 
88724
88729
  // src/models/explosives.ts
88730
+ var M67_PARTS = {
88731
+ bodyRadius: 0.032,
88732
+ fuze: { radius: 0.011, height: 0.022, y: 0.04 },
88733
+ spoon: { size: [0.012, 0.07, 6e-3], x: 0.016, y: 0.018, tilt: 0.2 }
88734
+ };
88725
88735
  var grenade = (kit, group) => {
88726
88736
  const { M, sphere: sphere2, cylinderY, box: box5, torus: torus2, THREE } = kit;
88727
- sphere2(group, 0.032, M.olive, 0, 0.032, 0, 1);
88728
- cylinderY(group, 0.011, 0.022, M.metal, 0, 0.072, 0);
88729
- box5(group, 0.012, 0.07, 6e-3, M.metal, 0.016, 0.05, 0, 0.2);
88737
+ const { bodyRadius, fuze, spoon } = M67_PARTS;
88738
+ sphere2(group, bodyRadius, M.olive, 0, bodyRadius, 0, 1);
88739
+ cylinderY(group, fuze.radius, fuze.height, M.metal, 0, bodyRadius + fuze.y, 0);
88740
+ box5(group, ...spoon.size, M.metal, spoon.x, bodyRadius + spoon.y, 0, spoon.tilt);
88730
88741
  torus2(group, new THREE.TorusGeometry(85e-4, 16e-4, 6, 12), M.steel, -0.012, 0.082, 0);
88731
88742
  kit.mark(group, 0, 0.032, 0).name = "handle";
88732
88743
  };
@@ -88966,7 +88977,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
88966
88977
  model.position.lerpVectors(holderAt, model.position, k);
88967
88978
  hand.updateMatrixWorld(true);
88968
88979
  };
88969
- const throwBody = (kind, mesh3, from, velocity, radius) => {
88980
+ const throwBody = (kind, mesh3, from, velocity2, radius) => {
88970
88981
  if (!(kind === "casing" ? layers.casings : layers.magazines)) {
88971
88982
  mesh3.geometry.dispose();
88972
88983
  return;
@@ -88977,7 +88988,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
88977
88988
  mesh3.position.copy(from);
88978
88989
  mesh3.castShadow = true;
88979
88990
  scene.add(mesh3);
88980
- bodies.push({ mesh: mesh3, velocity, spin: new THREE.Vector3(random() * 20 - 10, random() * 30 - 15, random() * 20 - 10), radius, age: 0, resting: false, bounces: 0, kind });
88991
+ bodies.push({ mesh: mesh3, velocity: velocity2, spin: new THREE.Vector3(random() * 20 - 10, random() * 30 - 15, random() * 20 - 10), radius, age: 0, resting: false, bounces: 0, kind });
88981
88992
  };
88982
88993
  const ejectCasing = (caliberMm, isShell, downward) => {
88983
88994
  const radius = isShell ? 0.0105 : Math.max(3e-3, caliberMm / 1e3 * 0.6);
@@ -88987,8 +88998,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
88987
88998
  const from = handPoint(0.03, 0.03, 0.05, new THREE.Vector3());
88988
88999
  const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera2.quaternion);
88989
89000
  const up = new THREE.Vector3(0, 1, 0);
88990
- const velocity = downward ? up.clone().multiplyScalar(-0.5).addScaledVector(right, (random() - 0.5) * 0.4) : right.multiplyScalar(1.6 + random() * 0.8).addScaledVector(up, 1.4 + random() * 0.8);
88991
- throwBody("casing", mesh3, from, velocity, radius);
89001
+ const velocity2 = downward ? up.clone().multiplyScalar(-0.5).addScaledVector(right, (random() - 0.5) * 0.4) : right.multiplyScalar(1.6 + random() * 0.8).addScaledVector(up, 1.4 + random() * 0.8);
89002
+ throwBody("casing", mesh3, from, velocity2, radius);
88992
89003
  };
88993
89004
  const dropMagazine = (category) => {
88994
89005
  const long = category === "rifle" || category === "sniper" || category === "carbine";
@@ -89189,14 +89200,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
89189
89200
  const poses = /* @__PURE__ */ new Map();
89190
89201
  for (const [key2, list2] of channels) {
89191
89202
  const [part, channel, axis2] = key2.split("|");
89192
- const pose = poses.get(part) ?? { position: [0, 0, 0], rotation: [0, 0, 0] };
89193
- pose[channel][AXIS_INDEX[axis2]] = round3(valueAt(list2, t, includeInstants));
89194
- poses.set(part, pose);
89203
+ const pose2 = poses.get(part) ?? { position: [0, 0, 0], rotation: [0, 0, 0] };
89204
+ pose2[channel][AXIS_INDEX[axis2]] = round3(valueAt(list2, t, includeInstants));
89205
+ poses.set(part, pose2);
89195
89206
  }
89196
89207
  const root = poses.get(ROOT2);
89197
89208
  poses.delete(ROOT2);
89198
89209
  const parts2 = {};
89199
- for (const [part, pose] of poses) parts2[part] = pose;
89210
+ for (const [part, pose2] of poses) parts2[part] = pose2;
89200
89211
  return { t, ...root ? { position: root.position, rotation: root.rotation } : {}, ...poses.size ? { parts: parts2 } : {} };
89201
89212
  };
89202
89213
  const keys = [];
@@ -91795,12 +91806,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
91795
91806
  return false;
91796
91807
  }
91797
91808
  };
91798
- function slideInto(out, velocity) {
91799
- const into = velocity.vx * out.nx + velocity.vy * out.ny + velocity.vz * out.nz;
91809
+ function slideInto(out, velocity2) {
91810
+ const into = velocity2.vx * out.nx + velocity2.vy * out.ny + velocity2.vz * out.nz;
91800
91811
  if (into >= 0) return;
91801
- velocity.vx -= into * out.nx;
91802
- velocity.vy -= into * out.ny;
91803
- velocity.vz -= into * out.nz;
91812
+ velocity2.vx -= into * out.nx;
91813
+ velocity2.vy -= into * out.ny;
91814
+ velocity2.vz -= into * out.nz;
91804
91815
  }
91805
91816
  function slideAlong(out, vx2, vy2, vz2) {
91806
91817
  const into = vx2 * out.nx + vy2 * out.ny + vz2 * out.nz;
@@ -94034,10 +94045,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94034
94045
  var FLASH_SCALE = variable("flash");
94035
94046
  var fallback = (name, defaultValue) => ite(ne(variable(name), void 0), variable(name), defaultValue);
94036
94047
  var wide = (width) => mul(sub(rand(), 0.5), width);
94037
- var puff2 = (point, velocity, world, radius, life, opacity, growth = SMOKE.growth) => mesh2({
94048
+ var puff2 = (point, velocity2, world, radius, life, opacity, growth = SMOKE.growth) => mesh2({
94038
94049
  shape: "sphere",
94039
94050
  p: point,
94040
- v: velocity,
94051
+ v: velocity2,
94041
94052
  wv: world,
94042
94053
  r: radius,
94043
94054
  seg: SMOKE.width,
@@ -94051,9 +94062,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94051
94062
  drag: SMOKE.drag,
94052
94063
  grow: growth
94053
94064
  });
94054
- var flameBit = (point, velocity, world, radius, life) => [
94065
+ var flameBit = (point, velocity2, world, radius, life) => [
94055
94066
  set("bitPoint", point),
94056
- set("bitVelocity", velocity),
94067
+ set("bitVelocity", velocity2),
94057
94068
  set("bitWorld", world),
94058
94069
  set("bitRadius", radius),
94059
94070
  set("bitLife", life),
@@ -94484,7 +94495,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94484
94495
  var clamp32 = (value, low, high) => value < low ? low : value > high ? high : value;
94485
94496
  function createCylinderBehavior() {
94486
94497
  let position = SPOT2;
94487
- let velocity = [0, 0, 0];
94498
+ let velocity2 = [0, 0, 0];
94488
94499
  let rotationZ = 0;
94489
94500
  let angle = 0;
94490
94501
  let spin = 0;
@@ -94493,7 +94504,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94493
94504
  let direction = [1, 0, 0];
94494
94505
  const clear = () => {
94495
94506
  position = SPOT2;
94496
- velocity = [0, 0, 0];
94507
+ velocity2 = [0, 0, 0];
94497
94508
  rotationZ = 0;
94498
94509
  angle = 0;
94499
94510
  spin = 0;
@@ -94508,7 +94519,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94508
94519
  oxygen = args.oxygen;
94509
94520
  } else if (action === "puncture") {
94510
94521
  live = true;
94511
- if (oxygen) velocity = [-5, 0, -0.3];
94522
+ if (oxygen) velocity2 = [-5, 0, -0.3];
94512
94523
  else spin = 9;
94513
94524
  } else if (action === "step") {
94514
94525
  if (!live) return;
@@ -94522,18 +94533,18 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94522
94533
  position = [position[0] + direction[0] * (-0.6 * k * dt), y + direction[1] * (-0.6 * k * dt), position[2] + direction[2] * (-0.6 * k * dt)];
94523
94534
  return;
94524
94535
  }
94525
- let [vx2, vy2, vz2] = velocity;
94536
+ let [vx2, vy2, vz2] = velocity2;
94526
94537
  if (k > 0) vx2 -= 4 * k * dt;
94527
94538
  const damping = Math.exp(-dt * (k > 0 ? 0.3 : 3));
94528
94539
  vx2 *= damping;
94529
94540
  vy2 *= damping;
94530
94541
  vz2 *= damping;
94531
- velocity = [vx2, vy2, vz2];
94542
+ velocity2 = [vx2, vy2, vz2];
94532
94543
  rotationZ = lerp3(rotationZ, -QUARTER_TURN2, dt * 10);
94533
94544
  position = [position[0] + vx2 * dt, lerp3(position[1], 0.12, dt * 10) + vy2 * dt, position[2] + vz2 * dt];
94534
94545
  if (position[0] < WALL_X) {
94535
94546
  position = [WALL_X, position[1], position[2]];
94536
- velocity = [velocity[0] * -0.3, velocity[1], velocity[2]];
94547
+ velocity2 = [velocity2[0] * -0.3, velocity2[1], velocity2[2]];
94537
94548
  host.engine.screen.shake += 0.08;
94538
94549
  sparkAt(host.engine, position, normalized([1, 0.5, 0]), 16, 1);
94539
94550
  }
@@ -94550,7 +94561,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
94550
94561
  case "direction":
94551
94562
  return direction;
94552
94563
  case "speed_x":
94553
- return velocity[0];
94564
+ return velocity2[0];
94554
94565
  case "rotation_z":
94555
94566
  return rotationZ;
94556
94567
  case "tip":
@@ -95321,10 +95332,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
95321
95332
  return { origin, anchor: entry2.anchor, yaw: entry2.yaw, ...entry2.orientation ? { orientation: entry2.orientation } : {} };
95322
95333
  }
95323
95334
  function moveCarrier(entry2) {
95324
- const pose = entry2.track?.();
95325
- if (!pose || !entry2.carrier) return;
95326
- entry2.carrier.origin = [pose.point[0], pose.point[1], pose.point[2]];
95327
- if (pose.orientation) entry2.carrier.orientation = pose.orientation;
95335
+ const pose2 = entry2.track?.();
95336
+ if (!pose2 || !entry2.carrier) return;
95337
+ entry2.carrier.origin = [pose2.point[0], pose2.point[1], pose2.point[2]];
95338
+ if (pose2.orientation) entry2.carrier.orientation = pose2.orientation;
95328
95339
  }
95329
95340
  function drawing(entry2, action) {
95330
95341
  const context = engine.context;
@@ -96743,9 +96754,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
96743
96754
  return { index, def: this.defs[index] };
96744
96755
  }
96745
96756
  /** One sprite with an explicit velocity. */
96746
- spawn(kind, point, velocity, options) {
96757
+ spawn(kind, point, velocity2, options) {
96747
96758
  const { index, def } = this.kindOf(kind);
96748
- (def.additive ? this.additive : this.normal).spawn(index, point, velocity, this.random, options);
96759
+ (def.additive ? this.additive : this.normal).spawn(index, point, velocity2, this.random, options);
96749
96760
  }
96750
96761
  /** `count` sprites leaving `point` around `normal` at about `speed` m/s. */
96751
96762
  burst(kind, point, normal, count, speed = 1, options) {
@@ -97065,7 +97076,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97065
97076
  return this.particles.length;
97066
97077
  }
97067
97078
  spawn(options, frame2 = IDENTITY2, carried) {
97068
- const velocity = options.v ?? [0, 0, 0];
97079
+ const velocity2 = options.v ?? [0, 0, 0];
97069
97080
  const world = options.wv ?? [0, 0, 0];
97070
97081
  const particle = {
97071
97082
  id: ++this.serial,
@@ -97092,9 +97103,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97092
97103
  opacity: options.a,
97093
97104
  age: 0,
97094
97105
  life: options.life,
97095
- vx: velocity[0] + world[0],
97096
- vy: velocity[1] + world[1],
97097
- vz: velocity[2] + world[2],
97106
+ vx: velocity2[0] + world[0],
97107
+ vy: velocity2[1] + world[1],
97108
+ vz: velocity2[2] + world[2],
97098
97109
  spin: options.spin ?? [0, 0, 0],
97099
97110
  gravity: options.g ?? 0,
97100
97111
  drag: options.drag ?? 0,
@@ -97274,7 +97285,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97274
97285
  this.count = 0;
97275
97286
  }
97276
97287
  update(dt, leaveDecal) {
97277
- const { position, velocity } = this;
97288
+ const { position, velocity: velocity2 } = this;
97278
97289
  const confiner = this.context.confiner;
97279
97290
  for (let index = this.count - 1; index >= 0; index--) {
97280
97291
  this.life[index] -= dt;
@@ -97284,17 +97295,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97284
97295
  }
97285
97296
  const offset = index * FLOATS_PER_VECTOR;
97286
97297
  const age = 1 - this.life[index] / this.maxLife[index];
97287
- velocity[offset + 1] -= this.gravity[index] * dt;
97298
+ velocity2[offset + 1] -= this.gravity[index] * dt;
97288
97299
  const factor = Math.max(0, 1 - this.drag[index] * dt);
97289
- velocity[offset] *= factor;
97290
- velocity[offset + 1] *= factor;
97291
- velocity[offset + 2] *= factor;
97300
+ velocity2[offset] *= factor;
97301
+ velocity2[offset + 1] *= factor;
97302
+ velocity2[offset + 2] *= factor;
97292
97303
  const x0 = position[offset];
97293
97304
  const y0 = position[offset + 1];
97294
97305
  const z0 = position[offset + 2];
97295
- position[offset] += velocity[offset] * dt;
97296
- position[offset + 1] += velocity[offset + 1] * dt;
97297
- position[offset + 2] += velocity[offset + 2] * dt;
97306
+ position[offset] += velocity2[offset] * dt;
97307
+ position[offset + 1] += velocity2[offset + 1] * dt;
97308
+ position[offset + 2] += velocity2[offset + 2] * dt;
97298
97309
  if (this.carried && confiner && !confiner.empty && Math.abs(this.gravity[index]) < CARRIED_GRAVITY) {
97299
97310
  const size = this.startSize[index] * (1 + (this.growth[index] - 1) * age);
97300
97311
  if (confiner.confine(x0, y0, z0, position[offset], position[offset + 1], position[offset + 2], size * PAD_OF_SIZE3, dt)) {
@@ -97302,10 +97313,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97302
97313
  position[offset] = out.x;
97303
97314
  position[offset + 1] = out.y;
97304
97315
  position[offset + 2] = out.z;
97305
- const [vx2, vy2, vz2] = slideAlong(out, velocity[offset], velocity[offset + 1], velocity[offset + 2]);
97306
- velocity[offset] = vx2;
97307
- velocity[offset + 1] = vy2;
97308
- velocity[offset + 2] = vz2;
97316
+ const [vx2, vy2, vz2] = slideAlong(out, velocity2[offset], velocity2[offset + 1], velocity2[offset + 2]);
97317
+ velocity2[offset] = vx2;
97318
+ velocity2[offset + 1] = vy2;
97319
+ velocity2[offset + 2] = vz2;
97309
97320
  }
97310
97321
  }
97311
97322
  const mode = this.groundMode[index];
@@ -97318,9 +97329,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97318
97329
  }
97319
97330
  if (mode === 2) {
97320
97331
  position[offset + 1] = groundHeight + 1e-3;
97321
- velocity[offset + 1] *= -0.3;
97322
- velocity[offset] *= 0.55;
97323
- velocity[offset + 2] *= 0.55;
97332
+ velocity2[offset + 1] *= -0.3;
97333
+ velocity2[offset] *= 0.55;
97334
+ velocity2[offset + 2] *= 0.55;
97324
97335
  }
97325
97336
  if (mode === 3) {
97326
97337
  if (this.context.quality.level < 2) {
@@ -97426,7 +97437,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97426
97437
  this.count = 0;
97427
97438
  }
97428
97439
  update(dt) {
97429
- const { point, velocity } = this;
97440
+ const { point, velocity: velocity2 } = this;
97430
97441
  for (let index = this.count - 1; index >= 0; index--) {
97431
97442
  this.life[index] -= dt;
97432
97443
  if (this.life[index] <= 0) {
@@ -97435,14 +97446,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97435
97446
  }
97436
97447
  const offset = index * FLOATS_PER_VECTOR2;
97437
97448
  const age = 1 - this.life[index] / this.maxLife[index];
97438
- velocity[offset + 1] -= this.gravity[index] * dt;
97449
+ velocity2[offset + 1] -= this.gravity[index] * dt;
97439
97450
  const factor = Math.max(0, 1 - this.drag[index] * dt);
97440
- velocity[offset] *= factor;
97441
- velocity[offset + 1] *= factor;
97442
- velocity[offset + 2] *= factor;
97443
- point[offset] += velocity[offset] * dt;
97444
- point[offset + 1] += velocity[offset + 1] * dt;
97445
- point[offset + 2] += velocity[offset + 2] * dt;
97451
+ velocity2[offset] *= factor;
97452
+ velocity2[offset + 1] *= factor;
97453
+ velocity2[offset + 2] *= factor;
97454
+ point[offset] += velocity2[offset] * dt;
97455
+ point[offset + 1] += velocity2[offset + 1] * dt;
97456
+ point[offset + 2] += velocity2[offset + 2] * dt;
97446
97457
  if (this.groundMode[index]) {
97447
97458
  const groundHeight = this.context.groundAt(point[offset], point[offset + 2]);
97448
97459
  if (point[offset + 1] < groundHeight) {
@@ -97451,9 +97462,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97451
97462
  continue;
97452
97463
  }
97453
97464
  point[offset + 1] = groundHeight + 1e-3;
97454
- velocity[offset + 1] *= -0.35;
97455
- velocity[offset] *= 0.6;
97456
- velocity[offset + 2] *= 0.6;
97465
+ velocity2[offset + 1] *= -0.35;
97466
+ velocity2[offset] *= 0.6;
97467
+ velocity2[offset + 2] *= 0.6;
97457
97468
  }
97458
97469
  }
97459
97470
  const length2 = this.length[index];
@@ -97462,9 +97473,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97462
97473
  this.segment[at32] = point[offset];
97463
97474
  this.segment[at32 + 1] = point[offset + 1];
97464
97475
  this.segment[at32 + 2] = point[offset + 2];
97465
- this.segment[at32 + 3] = point[offset] - velocity[offset] * length2;
97466
- this.segment[at32 + 4] = point[offset + 1] - velocity[offset + 1] * length2;
97467
- this.segment[at32 + 5] = point[offset + 2] - velocity[offset + 2] * length2;
97476
+ this.segment[at32 + 3] = point[offset] - velocity2[offset] * length2;
97477
+ this.segment[at32 + 4] = point[offset + 1] - velocity2[offset + 1] * length2;
97478
+ this.segment[at32 + 5] = point[offset + 2] - velocity2[offset + 2] * length2;
97468
97479
  for (let channel = 0; channel < FLOATS_PER_VECTOR2; channel++) {
97469
97480
  const shade3 = lerp2(this.colorStart[offset + channel], this.colorEnd[offset + channel], age) * alpha;
97470
97481
  this.segmentColor[at32 + channel] = shade3;
@@ -97896,7 +97907,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
97896
97907
  return true;
97897
97908
  },
97898
97909
  burst: (kind, point, normal, count, speed, spriteOptions) => spriteSystem.burst(kind, point, normal, count, speed, spriteOptions),
97899
- spawn: (kind, point, velocity, spriteOptions) => spriteSystem.spawn(kind, point, velocity, spriteOptions),
97910
+ spawn: (kind, point, velocity2, spriteOptions) => spriteSystem.spawn(kind, point, velocity2, spriteOptions),
97900
97911
  onLand: (owner, listener) => spriteSystem.onLand(owner, listener),
97901
97912
  sprites: () => spriteSystem,
97902
97913
  workshop,
@@ -98202,9 +98213,9 @@ void main(){
98202
98213
  geometry.setAttribute("position", new THREE.Float32BufferAttribute([-0.5, 0, 0, 0.5, 0, 0, 0.5, 1, 0, -0.5, 1, 0], 3));
98203
98214
  geometry.setIndex([0, 1, 2, 0, 2, 3]);
98204
98215
  const position = new Float32Array(capacity * 3);
98205
- const velocity = new Float32Array(capacity * 3);
98216
+ const velocity2 = new Float32Array(capacity * 3);
98206
98217
  const extra = new Float32Array(capacity * 4);
98207
- const attributes = [dynamic(THREE, position, 3), dynamic(THREE, velocity, 3), dynamic(THREE, extra, 4)];
98218
+ const attributes = [dynamic(THREE, position, 3), dynamic(THREE, velocity2, 3), dynamic(THREE, extra, 4)];
98208
98219
  geometry.setAttribute("aPos", attributes[0]);
98209
98220
  geometry.setAttribute("aVel", attributes[1]);
98210
98221
  geometry.setAttribute("aE", attributes[2]);
@@ -98222,9 +98233,9 @@ void main(){
98222
98233
  position[n * 3] = s.x;
98223
98234
  position[n * 3 + 1] = s.y;
98224
98235
  position[n * 3 + 2] = s.z;
98225
- velocity[n * 3] = s.vx;
98226
- velocity[n * 3 + 1] = s.vy;
98227
- velocity[n * 3 + 2] = s.vz;
98236
+ velocity2[n * 3] = s.vx;
98237
+ velocity2[n * 3 + 1] = s.vy;
98238
+ velocity2[n * 3 + 2] = s.vz;
98228
98239
  extra[n * 4] = s.age;
98229
98240
  extra[n * 4 + 1] = s.w;
98230
98241
  extra[n * 4 + 2] = s.st;
@@ -99619,13 +99630,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99619
99630
  muzzleFlash(position, orientation, size, profile = MUZZLE_SMOKE.smokeless, track) {
99620
99631
  if (profile.puffs <= 0 && profile.flash <= 0) return;
99621
99632
  const follow = track ? () => {
99622
- const pose = track();
99623
- return pose ? { point: vec4(pose.position), orientation: quaternion(pose.orientation) } : null;
99633
+ const pose2 = track();
99634
+ return pose2 ? { point: vec4(pose2.position), orientation: quaternion(pose2.orientation) } : null;
99624
99635
  } : void 0;
99625
99636
  sink?.play({ effect: VIEWMODEL_EFFECT_IDS.flash, point: vec4(position), direction: barrel(orientation), orientation: quaternion(orientation), seed: seed(), values: { size, ...profile }, ...follow ? { track: follow } : {} });
99626
99637
  },
99627
- smoke(position, velocity, size, life, opacity) {
99628
- sink?.play({ effect: VIEWMODEL_EFFECT_IDS.smoke, point: vec4(position), seed: seed(), values: { vx: velocity.x, vy: velocity.y, vz: velocity.z, radius: size, life, opacity } });
99638
+ smoke(position, velocity2, size, life, opacity) {
99639
+ sink?.play({ effect: VIEWMODEL_EFFECT_IDS.smoke, point: vec4(position), seed: seed(), values: { vx: velocity2.x, vy: velocity2.y, vz: velocity2.z, radius: size, life, opacity } });
99629
99640
  },
99630
99641
  backblast(rear, orientation) {
99631
99642
  sink?.play({ effect: VIEWMODEL_EFFECT_IDS.backblast, point: vec4(rear), direction: barrel(orientation), orientation: quaternion(orientation), seed: seed() });
@@ -99789,6 +99800,61 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99789
99800
  return { geometry, material };
99790
99801
  }
99791
99802
 
99803
+ // src/engine-loose.ts
99804
+ var LOOSE_ROLLING_RESISTANCE = 0.015;
99805
+ var CASING_FILL = 0.25;
99806
+ var BRASS_DENSITY = 8500;
99807
+ var LOOSE_USER = { casing: 100 };
99808
+ var BOUNCE_FALL_SPEED = 0.5;
99809
+ var BOUNCE_RISE_SPEED = 0.2;
99810
+ var QUARTER_TURN_Z = [0, 0, Math.SQRT1_2, Math.SQRT1_2];
99811
+ var CASING_MATERIAL = { frictionStatic: 0.4, frictionDynamic: 0.3, restitution: 0.4 };
99812
+ function casingCollider(radius, length2) {
99813
+ return {
99814
+ shape: { kind: "compound", children: [{ shape: { kind: "cylinder", halfHeight: length2 / 2, radius }, position: [0, 0, 0], rotation: QUARTER_TURN_Z }] },
99815
+ mass: Math.PI * radius * radius * length2 * BRASS_DENSITY * CASING_FILL,
99816
+ material: CASING_MATERIAL,
99817
+ rolling: { coefficient: LOOSE_ROLLING_RESISTANCE, radius },
99818
+ user: LOOSE_USER.casing
99819
+ };
99820
+ }
99821
+ function spawnLoose(world, collider, launch) {
99822
+ const desc = {
99823
+ shape: collider.shape,
99824
+ motion: "dynamic",
99825
+ mass: collider.mass,
99826
+ position: [launch.position.x, launch.position.y, launch.position.z],
99827
+ rotation: [launch.rotation.x, launch.rotation.y, launch.rotation.z, launch.rotation.w],
99828
+ material: collider.material,
99829
+ layer: "debris",
99830
+ continuous: true,
99831
+ rolling: collider.rolling,
99832
+ linearVelocity: [launch.velocity.x, launch.velocity.y, launch.velocity.z],
99833
+ angularVelocity: [launch.spin.x, launch.spin.y, launch.spin.z],
99834
+ user: collider.user
99835
+ };
99836
+ return { id: world.createBody(desc), bounces: 0, fallSpeed: 0 };
99837
+ }
99838
+ var scratchReading = { asleep: false, bounceSpeed: void 0 };
99839
+ var pose = new Float64Array(7);
99840
+ var velocity = new Float64Array(6);
99841
+ function syncLoose(world, body, object2) {
99842
+ world.readPose(body.id, pose, 0);
99843
+ world.readVelocity(body.id, velocity, 0);
99844
+ object2.position.set(pose[0] ?? 0, pose[1] ?? 0, pose[2] ?? 0);
99845
+ object2.quaternion.set(pose[3] ?? 0, pose[4] ?? 0, pose[5] ?? 0, pose[6] ?? 1);
99846
+ const vertical = velocity[1] ?? 0;
99847
+ const bounced = body.fallSpeed > BOUNCE_FALL_SPEED && vertical > BOUNCE_RISE_SPEED;
99848
+ scratchReading.bounceSpeed = bounced ? body.fallSpeed : void 0;
99849
+ body.fallSpeed = vertical < 0 ? -vertical : 0;
99850
+ if (bounced) body.bounces++;
99851
+ scratchReading.asleep = world.isSleeping(body.id);
99852
+ return scratchReading;
99853
+ }
99854
+ function dropLoose(world, body) {
99855
+ world.removeBody(body.id);
99856
+ }
99857
+
99792
99858
  // src/fx/particles.ts
99793
99859
  var MAX_PARTICLES = 900;
99794
99860
  var FLOOR_FRICTION = 0.45;
@@ -99803,7 +99869,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99803
99869
  if (mesh3.isMesh) mesh3.geometry.dispose();
99804
99870
  });
99805
99871
  };
99806
- function createParticles(THREE, scene, groundAt, limit, surface) {
99872
+ function createParticles(THREE, scene, groundAt, limit, surface, physics) {
99807
99873
  const from = new THREE.Vector3();
99808
99874
  const step = new THREE.Vector3();
99809
99875
  let list2 = [];
@@ -99813,6 +99879,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99813
99879
  });
99814
99880
  particle.object.removeFromParent();
99815
99881
  if (particle.ownsGeometry) disposeOwned(particle.object);
99882
+ if (particle.body && physics) dropLoose(physics, particle.body);
99816
99883
  particle.onRemove?.();
99817
99884
  if (particle.fadeFrom !== void 0) particle.object.material.dispose();
99818
99885
  list2 = list2.filter((other) => other !== particle);
@@ -99828,24 +99895,24 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99828
99895
  if (!hit) return;
99829
99896
  const at4 = origin.y + travel.y * hit.distance;
99830
99897
  if (at4 <= groundAt(origin.x + travel.x * hit.distance, origin.z + travel.z * hit.distance) + radius + FLOOR_EPSILON) return;
99831
- const { velocity } = particle;
99832
- const impact3 = Math.abs(velocity.dot(hit.normal));
99898
+ const { velocity: velocity2 } = particle;
99899
+ const impact3 = Math.abs(velocity2.dot(hit.normal));
99833
99900
  object2.position.copy(origin).addScaledVector(travel, Math.max(0, hit.distance - radius));
99834
- velocity.addScaledVector(hit.normal, -(1 + particle.bounce) * velocity.dot(hit.normal));
99835
- velocity.multiplyScalar(FLOOR_FRICTION);
99901
+ velocity2.addScaledVector(hit.normal, -(1 + particle.bounce) * velocity2.dot(hit.normal));
99902
+ velocity2.multiplyScalar(FLOOR_FRICTION);
99836
99903
  particle.spin.multiplyScalar(FLOOR_FRICTION);
99837
99904
  if (particle.bounces < 4) api.onBounce?.(particle.kind, { object: object2, speed: impact3, bounce: particle.bounces });
99838
99905
  particle.bounces++;
99839
99906
  };
99840
99907
  const api = {
99841
- spawn(object2, velocity, options = {}) {
99908
+ spawn(object2, velocity2, options = {}) {
99842
99909
  object2.traverse((node) => {
99843
99910
  node.userData[PARTICLE_USERDATA_KEY] = true;
99844
99911
  });
99845
99912
  scene.add(object2);
99846
99913
  list2.push({
99847
99914
  object: object2,
99848
- velocity,
99915
+ velocity: velocity2,
99849
99916
  spin: options.spin ?? new THREE.Vector3(),
99850
99917
  age: 0,
99851
99918
  resting: false,
@@ -99861,7 +99928,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99861
99928
  onGround: options.onGround,
99862
99929
  ownsGeometry: options.ownsGeometry ?? false,
99863
99930
  onRemove: options.onRemove,
99864
- bounces: 0
99931
+ bounces: 0,
99932
+ body: options.collider && physics ? spawnLoose(physics, options.collider, { position: object2.position, rotation: object2.quaternion, velocity: velocity2, spin: options.spin ?? new THREE.Vector3() }) : void 0
99865
99933
  });
99866
99934
  const hostLimit = limit?.();
99867
99935
  const oldest = list2[0];
@@ -99878,6 +99946,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99878
99946
  const { object: object2 } = particle;
99879
99947
  if (particle.fadeFrom !== void 0) object2.material.opacity = Math.max(0, particle.fadeFrom * (1 - particle.age / particle.life));
99880
99948
  if (particle.resting) continue;
99949
+ if (particle.body && physics) {
99950
+ const reading = syncLoose(physics, particle.body, object2);
99951
+ if (reading.bounceSpeed !== void 0 && particle.bounces < 4) api.onBounce?.(particle.kind, { object: object2, speed: reading.bounceSpeed, bounce: particle.bounces });
99952
+ if (reading.bounceSpeed !== void 0) particle.bounces++;
99953
+ if (reading.asleep) particle.resting = true;
99954
+ continue;
99955
+ }
99881
99956
  particle.velocity.y -= particle.gravity * dt;
99882
99957
  if (particle.drag) particle.velocity.multiplyScalar(Math.max(0, 1 - particle.drag * dt));
99883
99958
  const probed = surface !== void 0 && SOLID_KINDS.has(particle.kind) && probes < MAX_PROBES_PER_FRAME && particle.velocity.lengthSq() > PROBE_MIN_SPEED * PROBE_MIN_SPEED;
@@ -99926,20 +100001,20 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99926
100001
  const registry = partRegistry(model.parts);
99927
100002
  const rest2 = /* @__PURE__ */ new Map();
99928
100003
  for (const part of [...registry.values(), model.root]) rest2.set(part, { position: part.position.clone(), rotation: part.rotation.clone() });
99929
- const apply = (object2, pose) => {
100004
+ const apply = (object2, pose2) => {
99930
100005
  const base = rest2.get(object2);
99931
100006
  if (!base) return;
99932
- const [dx, dy, dz] = pose.position ?? [0, 0, 0];
99933
- const [rx, ry, rz] = pose.rotation ?? [0, 0, 0];
100007
+ const [dx, dy, dz] = pose2.position ?? [0, 0, 0];
100008
+ const [rx, ry, rz] = pose2.rotation ?? [0, 0, 0];
99934
100009
  object2.position.set(base.position.x + dx, base.position.y + dy, base.position.z + dz);
99935
100010
  object2.rotation.set(base.rotation.x + rx, base.rotation.y + ry, base.rotation.z + rz);
99936
100011
  };
99937
100012
  return {
99938
- setPartPose(partId, pose) {
100013
+ setPartPose(partId, pose2) {
99939
100014
  const part = registry.get(partId);
99940
- if (part) apply(part, pose);
100015
+ if (part) apply(part, pose2);
99941
100016
  },
99942
- setRootPose: (pose) => apply(model.root, pose)
100017
+ setRootPose: (pose2) => apply(model.root, pose2)
99943
100018
  };
99944
100019
  }
99945
100020
 
@@ -99968,13 +100043,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99968
100043
  const vector2 = (x, y, z) => new THREE.Vector3(x, y, z);
99969
100044
  const positionOf3 = (part) => worldPositionOf(session, part, new THREE.Vector3());
99970
100045
  const reach2 = Math.max(0.55, Math.min(1.2, session.lengthMetres));
99971
- const throwCase = (mark, velocity, spin, tilt = 0) => {
100046
+ const throwCase = (mark, velocity2, spin, tilt = 0) => {
99972
100047
  if (!session.cartridge || !world.layers.casings) return;
99973
100048
  const casing2 = buildCasing(kit, session.cartridge.dims, session.cartridge.shape);
99974
100049
  casing2.group.position.copy(positionOf3(mark));
99975
100050
  casing2.group.rotation.set(0, random() * 0.6 - 0.3, tilt);
99976
100051
  if (session.cartridge.caseType) casing2.group.userData["caseType"] = session.cartridge.caseType;
99977
- particles.spawn(casing2.group, velocity, { kind: "casing", life: 25, radius: casing2.radius, bounce: 0.35, spin, onRest: restFlat, ownsGeometry: true });
100052
+ particles.spawn(casing2.group, velocity2, { kind: "casing", life: 25, radius: casing2.radius, bounce: 0.35, spin, onRest: restFlat, ownsGeometry: true, collider: casingCollider(casing2.radius, casing2.length) });
99978
100053
  };
99979
100054
  const ejectFromPort = (down2) => {
99980
100055
  if (!parts2.eject) return;
@@ -99983,8 +100058,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
99983
100058
  };
99984
100059
  const ejectAll = (marks, spent) => {
99985
100060
  marks?.forEach((mark, index) => {
99986
- const { velocity, spin, tilt } = spent(index);
99987
- throwCase(mark, toWorld3(session, velocity), spin, tilt);
100061
+ const { velocity: velocity2, spin, tilt } = spent(index);
100062
+ throwCase(mark, toWorld3(session, velocity2), spin, tilt);
99988
100063
  });
99989
100064
  };
99990
100065
  const moveIn = (from, to, tilt) => {
@@ -100633,11 +100708,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
100633
100708
  const random = createRng(options.seed ?? 1);
100634
100709
  const layers = options.layers ?? createLayers();
100635
100710
  const distance4 = () => options.soundDistance?.() ?? 0;
100636
- const particles = createParticles(THREE, scene, groundAt, options.particleLimit, createSurfaceRaycast(THREE, scene));
100711
+ const particles = createParticles(THREE, scene, groundAt, options.particleLimit, createSurfaceRaycast(THREE, scene), options.physics);
100637
100712
  const spawnParticle = particles.spawn.bind(particles);
100638
- particles.spawn = (object2, velocity, particleOptions) => {
100713
+ particles.spawn = (object2, velocity2, particleOptions) => {
100639
100714
  if (lens2) toWorldLens(camera2, object2.position, worldFovOf(), lens2.fov);
100640
- spawnParticle(object2, velocity, particleOptions);
100715
+ spawnParticle(object2, velocity2, particleOptions);
100641
100716
  };
100642
100717
  particles.onBounce = (kind, hit) => {
100643
100718
  if (!audio || kind !== "casing" && kind !== "magazine") return;
@@ -100662,10 +100737,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
100662
100737
  stop: (handle) => worldSink.stop(handle)
100663
100738
  } : void 0;
100664
100739
  const effects = createEffects(THREE, lensSink, random);
100665
- function seenThroughLens(pose) {
100666
- if (!pose || !lens2) return pose;
100667
- const at4 = toWorldLens(camera2, trackPoint.set(...pose.point), worldFovOf(), lens2.fov);
100668
- return { ...pose, point: [at4.x, at4.y, at4.z] };
100740
+ function seenThroughLens(pose2) {
100741
+ if (!pose2 || !lens2) return pose2;
100742
+ const at4 = toWorldLens(camera2, trackPoint.set(...pose2.point), worldFovOf(), lens2.fov);
100743
+ return { ...pose2, point: [at4.x, at4.y, at4.z] };
100669
100744
  }
100670
100745
  const hand = new THREE.Group();
100671
100746
  hand.name = VIEWMODEL_NODE_NAME;
@@ -100891,9 +100966,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
100891
100966
  eyeTurn.copy(camera2.quaternion).invert();
100892
100967
  const rest2 = targetsOf(THREE, held, session.model.root.getWorldQuaternion(rootQuaternion), 0);
100893
100968
  let needed = 0;
100894
- for (const [anchor, pose] of [[held.right, rest2.R], [held.left, rest2.L]]) {
100895
- if (!anchor || !pose || anchor.part !== session.model.root) continue;
100896
- seen.set(...pose.position).sub(camera2.position).applyQuaternion(eyeTurn);
100969
+ for (const [anchor, pose2] of [[held.right, rest2.R], [held.left, rest2.L]]) {
100970
+ if (!anchor || !pose2 || anchor.part !== session.model.root) continue;
100971
+ seen.set(...pose2.position).sub(camera2.position).applyQuaternion(eyeTurn);
100897
100972
  if (-seen.z > 0.05) needed = Math.max(needed, HAND_IN_VIEW.floor * -seen.z * tanHalf - seen.y);
100898
100973
  }
100899
100974
  return Math.max(0, Math.min(HAND_IN_VIEW.max, needed));
@@ -101144,6 +101219,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
101144
101219
  ...options.condition ? { condition: options.condition } : {},
101145
101220
  ...options.attachmentModels ? { attachmentModels: options.attachmentModels } : {},
101146
101221
  ...options.raycast ? { raycast: options.raycast } : {},
101222
+ ...options.physics ? { physics: options.physics } : {},
101147
101223
  ...options.contact ? { contact: options.contact } : {},
101148
101224
  ...options.bodyHold ? { bodyHold: options.bodyHold } : {},
101149
101225
  ...options.firstPerson ? { firstPerson: options.firstPerson } : {},
@@ -101384,7 +101460,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
101384
101460
  const rigs = /* @__PURE__ */ new Map();
101385
101461
  const away = /* @__PURE__ */ new Map();
101386
101462
  const strapMaterial = new THREE.MeshStandardMaterial({ color: SLING_HANG.color, roughness: 0.85, metalness: 0 });
101387
- const frameOf2 = (pose) => ({ position: new THREE.Vector3(...pose.position), quaternion: new THREE.Quaternion(...pose.quaternion) });
101463
+ const frameOf2 = (pose2) => ({ position: new THREE.Vector3(...pose2.position), quaternion: new THREE.Quaternion(...pose2.quaternion) });
101388
101464
  const scratch3 = { position: new THREE.Vector3(), quaternion: new THREE.Quaternion(), inverse: new THREE.Quaternion(), acceleration: new THREE.Vector3(), velocity: new THREE.Vector3() };
101389
101465
  const holderOnHand = (rig, hand) => {
101390
101466
  const quaternion2 = hand.quaternion.clone().multiply(rig.grip.quaternion.clone().invert());
@@ -101396,8 +101472,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
101396
101472
  };
101397
101473
  const inFrame = (local2, base) => ({ position: local2.position.clone().applyQuaternion(base.quaternion).add(base.position), quaternion: base.quaternion.clone().multiply(local2.quaternion) });
101398
101474
  const holdFrame = () => {
101399
- const pose = options.holdFrame?.();
101400
- return pose ? frameOf2(pose) : null;
101475
+ const pose2 = options.holdFrame?.();
101476
+ return pose2 ? frameOf2(pose2) : null;
101401
101477
  };
101402
101478
  const goal = (entry2) => {
101403
101479
  if (entry2.motion?.kind === "toss") {
@@ -101410,9 +101486,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
101410
101486
  const base = holdFrame();
101411
101487
  return base && entry2.taken ? inFrame(entry2.taken, base) : null;
101412
101488
  }
101413
- const pose = options.bodySlot(entry2.slot);
101414
- if (!pose) return null;
101415
- return entry2.swing ? hanging(entry2, frameOf2(pose)) : frameOf2(pose);
101489
+ const pose2 = options.bodySlot(entry2.slot);
101490
+ if (!pose2) return null;
101491
+ return entry2.swing ? hanging(entry2, frameOf2(pose2)) : frameOf2(pose2);
101416
101492
  };
101417
101493
  const hanging = (entry2, frame2) => {
101418
101494
  const forward = new THREE.Vector3(0, 0, 1).applyQuaternion(frame2.quaternion);
@@ -101430,11 +101506,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
101430
101506
  };
101431
101507
  const swingOf = (entry2, frame2, dt) => {
101432
101508
  if (!entry2.swing || dt <= 0) return;
101433
- const { velocity, acceleration, inverse } = scratch3;
101434
- velocity.copy(frame2.position).sub(entry2.last ?? frame2.position).divideScalar(dt);
101435
- acceleration.copy(velocity).sub(entry2.last ? entry2.speed : velocity).divideScalar(dt).clampLength(0, MAX_SWING_ACCELERATION);
101509
+ const { velocity: velocity2, acceleration, inverse } = scratch3;
101510
+ velocity2.copy(frame2.position).sub(entry2.last ?? frame2.position).divideScalar(dt);
101511
+ acceleration.copy(velocity2).sub(entry2.last ? entry2.speed : velocity2).divideScalar(dt).clampLength(0, MAX_SWING_ACCELERATION);
101436
101512
  entry2.last = (entry2.last ?? new THREE.Vector3()).copy(frame2.position);
101437
- entry2.speed.copy(velocity);
101513
+ entry2.speed.copy(velocity2);
101438
101514
  acceleration.applyQuaternion(inverse.copy(frame2.quaternion).invert());
101439
101515
  const state = entry2.swing.step(dt, [-acceleration.x, acceleration.y, acceleration.z]);
101440
101516
  entry2.rig.swing.rotation.set(-(state.forward + Math.max(0, -entry2.lean)), 0, -state.side);