@adatechnology/game-weapons-three 0.24.3 → 0.24.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.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { I as ItemModels, W as WeaponProps, a as WeaponItemModel, M as ModelOptions, b as WeaponModel, c as ModelKit, d as ModelParts, e as ModelFamily, A as AttachmentModelRegistry, L as LaserRaycast } from './testing-eyLz_C6A.js';
2
2
  export { f as AttachmentBuildContext, g as AttachmentModel, h as AttachmentModelBuilder, C as CLASS_REFERENCE_ENERGY, i as COUNTER_ITEM_ID, j as CUES_IN_SAMPLE, k as CasingSound, l as CuePlayed, D as DEFAULT_ENERGY_CURVE, m as DEFAULT_EXPLOSIVES_SCENE, n as DistanceCurve, E as EXPLOSIVES_AREA_ID, o as EXPLOSIVES_TEXT, p as EnergyCurve, q as ExplosivesRoom, r as ExplosivesScene, s as ExplosivesTestModuleOptions, t as ExplosivesText, F as FlybySound, u as FxLayers, G as GAME_DISTANCE_CURVE, v as GAME_SOUND_CLASSES, w as GUNSHOT_PROFILES, x as GUNSHOT_SAMPLE, y as GUNSHOT_SAMPLE_IDS, z as Gunshot, B as GunshotInput, H as GunshotPlayed, J as ItemModelRequest, K as LAUNCH_SAMPLE, N as LAUNCH_SOUND_IDS, O as LaunchKind, P as MECHANICAL_SOUNDS, Q as MOUNTED_M134_ITEM_ID, R as MechanicalSoundId, S as ModelMaterials, T as MountFrame, U as RELOAD_SAMPLE, V as RELOAD_SAMPLE_HITS, X as ShotExtras, Y as ShotSound, Z as ShotSoundClass, _ as ShotSoundInput, $ as ShotSoundOptions, a0 as SoundClassDef, a1 as SoundStep, a2 as WEAPON_ITEM_PREFIX, a3 as WEIGHT_INTENSITY, a4 as WeaponAudio, a5 as WeaponAudioOptions, a6 as WeaponFx, a7 as WeaponFxOptions, a8 as WeaponModelDef, a9 as WeaponSampleOptions, aa as WeaponsTestModuleOptions, ab as buildItemWeaponModel, ac as buildThrowableModel, ad as buildWeaponModel, ae as computeCasingSound, af as computeFlyby, ag as computeGunshot, ah as computeShotSound, ai as createExplosivesTestModule, aj as createWeaponAudio, ak as createWeaponFx, al as createWeaponsTestModule, am as defaultWeaponProps, an as deriveFrames, ao as explosivesTextOf, ap as hasThrowableModel, aq as itemModelOfWeapon, ar as mechanicalSoundOf, as as modelKit, at as mountFrame, au as registerWeaponItemModel, av as weaponSampleBank, aw as weaponSampleDefaults, ax as weaponsLayout } from './testing-eyLz_C6A.js';
3
3
  import * as THREE_NS from 'three';
4
- import { TestableItem, Vec3, HostEvent, EffectSink, DestructibleSpec, DeepPartial, ToolClipSet, HandPose } from '@adatechnology/game-contracts';
4
+ import { TestableItem, Vec3, HostEvent, EffectSink, DestructibleSpec, DeepPartial, ToolClipSet, HandPose, HandTargets } from '@adatechnology/game-contracts';
5
5
  import { ExplosiveDef, Arsenal, WeaponDef, CartridgeDims, CaliberDef, CaseType, ReloadFamily, FittedAttachment, AttachmentDef } from '@adatechnology/game-weapons';
6
6
  import { LightBudget } from '@adatechnology/game-render-three';
7
7
  import '@adatechnology/game-audio';
@@ -308,19 +308,62 @@ declare const TOOL_MOTIONS: ReadonlyMap<string, ReadonlyMap<string, ToolMotion>>
308
308
  declare function sampleToolMotion(motion: ToolMotion, at: number): Omit<ToolMotionKey, 'at'>;
309
309
 
310
310
  /**
311
- * The weapons put away on the body (`HostEvent` `holster`): each is drawn at the place of the body that took it (`ModuleHost.bodySlot`: `hip` a holster, `back` a sling) for as long
312
- * as it is away, the pistol muzzle down against the hip, the long gun across the back with the muzzle over the off shoulder; drawn back in hand, it is hidden. The model is the
313
- * weapon's own (the gallery's, or the item model), at its real size; one per weapon, kept for the next time.
311
+ * What a weapon put away on the body is made of (`createHolsteredWeapons`): the holder that rides the place of the body, the weapon's model laid in it, the point of its grip the
312
+ * hand holds while it moves there (the same point the weapon in the hands gives the right hand, `holdOfModel`), and for a long gun on its sling the swinging part and the strap.
314
313
  */
315
314
 
316
315
  /**
317
316
  * How a weapon lies in each place, in the frame of the body's socket (+z the body's front, -x the weapon side, y up): `muzzle` the way the barrel points, `out` the way off the body
318
- * the weapon's side faces. The model's muzzle is its +x, its top +y, its side z.
317
+ * the weapon's side faces. The model's muzzle is its +x, its top +y, its side z. On the sling the barrel hangs down and toward the off side, its side flat on the chest.
319
318
  */
320
319
  declare const HOLSTER_PLACEMENT: Readonly<Record<string, {
321
320
  readonly muzzle: Vec3;
322
321
  readonly out: Vec3;
323
322
  }>>;
323
+ /** A long gun on its sling: its sling point this share of its length behind its middle; the front swivel this share ahead; the strap over the off shoulder (socket frame, m). */
324
+ declare const SLING_HANG: {
325
+ readonly pivotBehind: 0.3;
326
+ readonly frontSwivel: 0.3;
327
+ readonly shoulder: Vec3;
328
+ readonly strapRadius: 0.008;
329
+ readonly sag: 0.03;
330
+ readonly color: 4146217;
331
+ };
332
+ interface HolsterRig {
333
+ /** Rides the place of the body (world space; its parent is the scene). */
334
+ readonly holder: THREE_NS.Group;
335
+ /** Turned by the swing of a gun on its sling; the holder itself otherwise. */
336
+ readonly swing: THREE_NS.Object3D;
337
+ /** The right hand on the grip, in the holder's frame at rest. */
338
+ readonly grip: {
339
+ readonly position: THREE_NS.Vector3;
340
+ readonly quaternion: THREE_NS.Quaternion;
341
+ };
342
+ readonly strap: readonly THREE_NS.Mesh[];
343
+ }
344
+ /** A weapon's model laid in a place of the body, with the hand's grip on it. Undefined for a place this does not know or a weapon with no model. */
345
+ declare const buildHolsterRig: (THREE: typeof THREE_NS, weapon: string, slot: string, options?: {
346
+ readonly items?: ItemModels;
347
+ readonly strapMaterial?: THREE_NS.Material;
348
+ }) => HolsterRig | undefined;
349
+
350
+ /**
351
+ * The weapons put away on the body (`HostEvent` `holster`): each is drawn at the place of the body that took it (`ModuleHost.bodySlot`: `hip` a holster, `back` across the back,
352
+ * `sling` hanging on its sling) for as long as it is away, and hidden once it is back in hand. With `seconds` the move is seen (owner, 2026-11-25): the weapon goes from the hand
353
+ * (`from`) to its place with the right hand on its grip (`handTargets`), and back the same way; `ground` tosses it, the hand letting go on the way down, for the host to drop the
354
+ * weapon's world item where it lands. A long gun on its sling hangs from the chest and swings with the body (`createSlingSwing` of game-weapons). One model per weapon and place, kept
355
+ * for the next time.
356
+ */
357
+
358
+ /** The place a tossed weapon goes: down to the floor. */
359
+ declare const GROUND_SLOT = "ground";
360
+ /** A toss: the weapon falls this far (m) and this far ahead of the hand, turning by `turn` (radians); the hand lets go at `release` of the way. */
361
+ declare const HOLSTER_TOSS: {
362
+ readonly drop: 0.8;
363
+ readonly ahead: 0.3;
364
+ readonly turn: 1.3;
365
+ readonly release: 0.4;
366
+ };
324
367
  /** A weapon's model laid in a place of the body: its side on the socket, its middle over it. Undefined for a place this does not know or a weapon with no model. */
325
368
  declare const holsteredModel: (THREE: typeof THREE_NS, weapon: string, slot: string, items?: ItemModels) => THREE_NS.Group | undefined;
326
369
  interface HolsteredWeaponsOptions {
@@ -330,19 +373,27 @@ interface HolsteredWeaponsOptions {
330
373
  readonly items?: ItemModels;
331
374
  /** The host's places of the body (`ModuleHost.bodySlot`). */
332
375
  readonly bodySlot: (slot: string) => HandPose | null;
376
+ /** The frame the weapon in the hands is held in (`ModuleHost.holdFrame`): a weapon drawn back goes to where it was taken from in this frame. */
377
+ readonly holdFrame?: (() => HandPose | null) | undefined;
333
378
  }
334
379
  interface HolsteredWeapons {
335
380
  handle(event: {
336
381
  readonly weapon: string;
337
382
  readonly slot: string;
338
383
  readonly on: boolean;
384
+ readonly from?: HandPose | undefined;
385
+ readonly seconds?: number | undefined;
339
386
  }): void;
340
- /** Puts each weapon away where its place of the body is now. */
341
- update(): void;
387
+ /** The weapon now in the hands (`tool` events): it is not on the body any more. */
388
+ inHand(weapon: string): void;
389
+ /** Puts each weapon where its place of the body is now, moves the ones on their way and swings the slung ones. */
390
+ update(dt?: number): void;
391
+ /** The right hand on a weapon on its way between the hand and the body, or null with none moving. */
392
+ handTargets(): HandTargets | null;
342
393
  /** The weapons drawn on the body now. */
343
394
  readonly drawn: readonly string[];
344
395
  dispose(): void;
345
396
  }
346
397
  declare const createHolsteredWeapons: (options: HolsteredWeaponsOptions) => HolsteredWeapons;
347
398
 
348
- export { ARCHETYPE_MODELS, ATTACHMENT_MODELS, AttachmentModelRegistry, type AttachmentRig, BODY_ACTIONS, type CartridgeShape, type ClipContext, DEFAULT_THUMBNAIL_BASE, EXPLOSIVE_MODEL_IDS, type FitAttachmentOptions, HOLSTER_PLACEMENT, type HolsteredWeapons, type HolsteredWeaponsOptions, ItemModels, LaserRaycast, MODEL_ENTRIES, type ModelEntry, ModelFamily, ModelKit, ModelOptions, ModelParts, P13_VALVE_MESH, type ProjectileModel, type ProjectileQuery, TOOL_MOTIONS, type ToolMotion, type ToolMotionKey, VIEW_HOLD, VIEW_MOTION, type ViewHoldKind, WEAPON_THUMBNAILS, WORLD_EFFECTS, WORLD_EXPLOSIVE_IDS, WORLD_EXPLOSIVE_PREFIX, WeaponItemModel, WeaponModel, type WeaponProp, WeaponProps, type WeaponPropsOptions, type WeaponThumbnailEntry, type WorldEffectIds, type WorldEffectsOptions, type WorldExplosiveOptions, type WorldExplosiveShells, applyCondition, buildCartridge, buildCasing, buildExplosiveModel, buildModeledProp, buildProp, buildRound, buildToolClips, buildTripodMountedProp, buildWeaponModelById, cartridgeShape, createHolsteredWeapons, createWeaponProps, createWorldEffects, createWorldExplosiveShells, fitAttachmentModels, hasExplosiveModel, hasWeaponModel, holsteredModel, modeledPropSpec, partRegistry, projectileModel, rigStock, rigUnderbarrel, sampleToolMotion, toWorldLens, weaponProp, weaponThumbnailCredit, weaponThumbnailUrl, worldExplosiveItem, worldExplosiveShell, worldExplosiveValve };
399
+ export { ARCHETYPE_MODELS, ATTACHMENT_MODELS, AttachmentModelRegistry, type AttachmentRig, BODY_ACTIONS, type CartridgeShape, type ClipContext, DEFAULT_THUMBNAIL_BASE, EXPLOSIVE_MODEL_IDS, type FitAttachmentOptions, GROUND_SLOT, HOLSTER_PLACEMENT, HOLSTER_TOSS, type HolsterRig, type HolsteredWeapons, type HolsteredWeaponsOptions, ItemModels, LaserRaycast, MODEL_ENTRIES, type ModelEntry, ModelFamily, ModelKit, ModelOptions, ModelParts, P13_VALVE_MESH, type ProjectileModel, type ProjectileQuery, SLING_HANG, TOOL_MOTIONS, type ToolMotion, type ToolMotionKey, VIEW_HOLD, VIEW_MOTION, type ViewHoldKind, WEAPON_THUMBNAILS, WORLD_EFFECTS, WORLD_EXPLOSIVE_IDS, WORLD_EXPLOSIVE_PREFIX, WeaponItemModel, WeaponModel, type WeaponProp, WeaponProps, type WeaponPropsOptions, type WeaponThumbnailEntry, type WorldEffectIds, type WorldEffectsOptions, type WorldExplosiveOptions, type WorldExplosiveShells, applyCondition, buildCartridge, buildCasing, buildExplosiveModel, buildHolsterRig, buildModeledProp, buildProp, buildRound, buildToolClips, buildTripodMountedProp, buildWeaponModelById, cartridgeShape, createHolsteredWeapons, createWeaponProps, createWorldEffects, createWorldExplosiveShells, fitAttachmentModels, hasExplosiveModel, hasWeaponModel, holsteredModel, modeledPropSpec, partRegistry, projectileModel, rigStock, rigUnderbarrel, sampleToolMotion, toWorldLens, weaponProp, weaponThumbnailCredit, weaponThumbnailUrl, worldExplosiveItem, worldExplosiveShell, worldExplosiveValve };
@@ -35,10 +35,12 @@ var GameWeaponsThree = (() => {
35
35
  EXPLOSIVE_MODEL_IDS: () => EXPLOSIVE_MODEL_IDS,
36
36
  GAME_DISTANCE_CURVE: () => GAME_DISTANCE_CURVE,
37
37
  GAME_SOUND_CLASSES: () => GAME_SOUND_CLASSES,
38
+ GROUND_SLOT: () => GROUND_SLOT,
38
39
  GUNSHOT_PROFILES: () => GUNSHOT_PROFILES,
39
40
  GUNSHOT_SAMPLE: () => GUNSHOT_SAMPLE,
40
41
  GUNSHOT_SAMPLE_IDS: () => GUNSHOT_SAMPLE_IDS,
41
42
  HOLSTER_PLACEMENT: () => HOLSTER_PLACEMENT,
43
+ HOLSTER_TOSS: () => HOLSTER_TOSS,
42
44
  LAUNCH_SAMPLE: () => LAUNCH_SAMPLE,
43
45
  LAUNCH_SOUND_IDS: () => LAUNCH_SOUND_IDS,
44
46
  MECHANICAL_SOUNDS: () => MECHANICAL_SOUNDS,
@@ -47,6 +49,7 @@ var GameWeaponsThree = (() => {
47
49
  P13_VALVE_MESH: () => P13_VALVE_MESH,
48
50
  RELOAD_SAMPLE: () => RELOAD_SAMPLE,
49
51
  RELOAD_SAMPLE_HITS: () => RELOAD_SAMPLE_HITS,
52
+ SLING_HANG: () => SLING_HANG,
50
53
  TOOL_MOTIONS: () => TOOL_MOTIONS,
51
54
  VIEW_HOLD: () => VIEW_HOLD,
52
55
  VIEW_MOTION: () => VIEW_MOTION,
@@ -60,6 +63,7 @@ var GameWeaponsThree = (() => {
60
63
  buildCartridge: () => buildCartridge,
61
64
  buildCasing: () => buildCasing,
62
65
  buildExplosiveModel: () => buildExplosiveModel,
66
+ buildHolsterRig: () => buildHolsterRig,
63
67
  buildItemWeaponModel: () => buildItemWeaponModel,
64
68
  buildModeledProp: () => buildModeledProp,
65
69
  buildProp: () => buildProp,
@@ -15373,10 +15377,10 @@ var GameWeaponsThree = (() => {
15373
15377
  // tucking a pistol in the belt and drawing it back is a short motion of one hand
15374
15378
  stowSeconds: 0.45
15375
15379
  },
15376
- // as mãos de cada arma e onde ela vai quando as mãos são pedidas (decisão do dono, 2026-11-24): arma longa pede as duas mãos; a de cinto vai no coldre, a longa na bandoleira ou nas costas
15380
+ // as mãos de cada arma e onde ela vai quando as mãos são pedidas (decisão do dono, 2026-11-24): arma longa pede as duas mãos; a de cinto vai no coldre, a longa na bandoleira ou nas costas; o fuzil e a espingarda pendem da bandoleira (dono, 2026-11-25): sem bandoleira vão para as costas (SLOT_FALLBACKS do game-player)
15377
15381
  hands: {
15378
15382
  twoHanded: { categories: ["smg", "rifle", "carbine", "sniper", "dmr", "hunting", "machine_gun", "launcher", "shotgun", "bow", "crossbow", "extinguisher"], weapons: ["flamethrower"] },
15379
- slots: { pistol: "hip", revolver: "hip", melee_blade: "hip", melee_blunt: "hip", tool: "hip", throwable: "hip", heat: "hip", smg: "back", rifle: "back", carbine: "back", sniper: "back", dmr: "back", hunting: "back", shotgun: "back", bow: "back", crossbow: "back", machine_gun: "back", launcher: "back" },
15383
+ slots: { pistol: "hip", revolver: "hip", melee_blade: "hip", melee_blunt: "hip", tool: "hip", throwable: "hip", heat: "hip", smg: "sling", rifle: "sling", carbine: "sling", sniper: "sling", dmr: "sling", hunting: "sling", shotgun: "sling", bow: "back", crossbow: "back", machine_gun: "back", launcher: "back" },
15380
15384
  // the long-handled tools and the long blade hang across the back; a chainsaw has no place on the body
15381
15385
  weaponSlots: { lighter: "hip", flamethrower: "back", axe: "back", sledgehammer: "back", pickaxe: "back", shovel: "back", katana: "back", chainsaw: null },
15382
15386
  bare: ["kick", "shove", "fists"]
@@ -17059,6 +17063,44 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
17059
17063
  if (optic) return optic.zoom[0];
17060
17064
  return arsenal.rules.aim.ironSightZoom[def.category] ?? 1;
17061
17065
  }
17066
+ var SLING_SWING_DEFAULTS = { length: 0.34, damping: 2.6, limits: { forward: 0.9, side: 0.75 }, restitution: 0.25, maxStep: 1 / 240, gravity: 9.81 };
17067
+ function createSlingSwing(rules = SLING_SWING_DEFAULTS) {
17068
+ let forward = 0;
17069
+ let side = 0;
17070
+ let forwardSpeed = 0;
17071
+ let sideSpeed = 0;
17072
+ const bounce22 = (angle, speed, min2, max2) => {
17073
+ if (angle < min2) return [min2, speed < 0 ? -speed * rules.restitution : speed];
17074
+ if (angle > max2) return [max2, speed > 0 ? -speed * rules.restitution : speed];
17075
+ return [angle, speed];
17076
+ };
17077
+ const substep = (h, acceleration) => {
17078
+ const gravity = Math.max(0.5, rules.gravity + acceleration[1]);
17079
+ const forwardAccel = (-gravity * Math.sin(forward) - acceleration[2] * Math.cos(forward)) / rules.length - rules.damping * forwardSpeed;
17080
+ const sideAccel = (-gravity * Math.sin(side) - acceleration[0] * Math.cos(side)) / rules.length - rules.damping * sideSpeed;
17081
+ forwardSpeed += forwardAccel * h;
17082
+ sideSpeed += sideAccel * h;
17083
+ [forward, forwardSpeed] = bounce22(forward + forwardSpeed * h, forwardSpeed, 0, rules.limits.forward);
17084
+ [side, sideSpeed] = bounce22(side + sideSpeed * h, sideSpeed, -rules.limits.side, rules.limits.side);
17085
+ };
17086
+ return {
17087
+ step(dt, acceleration) {
17088
+ let left = Math.max(0, Math.min(dt, 0.25));
17089
+ while (left > 1e-9) {
17090
+ const h = Math.min(rules.maxStep, left);
17091
+ substep(h, acceleration);
17092
+ left -= h;
17093
+ }
17094
+ return { forward, side };
17095
+ },
17096
+ get state() {
17097
+ return { forward, side };
17098
+ },
17099
+ reset() {
17100
+ forward = side = forwardSpeed = sideSpeed = 0;
17101
+ }
17102
+ };
17103
+ }
17062
17104
  var isGenericKind = (kind, category) => kind === "firearm" && category !== "bow" && category !== "crossbow" || kind === "flame";
17063
17105
  function genericWeapons(arsenal) {
17064
17106
  const archetypes = new Set(ARCHETYPE_IDS);
@@ -54847,7 +54889,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54847
54889
  }
54848
54890
  var residentialTower = residentialTowerTemplate();
54849
54891
 
54850
- // ../game-floorplan-three/dist/chunk-ZVCG4IGR.js
54892
+ // ../game-floorplan-three/dist/chunk-W4VG2X7N.js
54851
54893
  var __defProp4 = Object.defineProperty;
54852
54894
  var __defNormalProp2 = (obj, key2, value) => key2 in obj ? __defProp4(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
54853
54895
  var __publicField2 = (obj, key2, value) => __defNormalProp2(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -67243,7 +67285,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67243
67285
  if (LOOSE.has(part.material) || part.shape.kind !== "box" || part.rotation) continue;
67244
67286
  const [x, y, z] = part.shape.size;
67245
67287
  if (y >= x && y >= z) {
67246
- if (z < x && x >= 0.6 * width) continue;
67288
+ if (z < x && x >= 0.6 * width) {
67289
+ part.anchored = false;
67290
+ part.structure = { role: "beam", maxSpan: SHELF_SPAN * x };
67291
+ continue;
67292
+ }
67247
67293
  part.structure = { role: "column" };
67248
67294
  } else if (y <= x && y <= z) part.structure = { role: "beam", maxSpan: SHELF_SPAN * Math.max(x, z) };
67249
67295
  }
@@ -101266,67 +101312,224 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
101266
101312
  return { name, parts: [{ id: MODEL_BODY, material: "steel", shape: { kind: "box", size }, position: [0, size[1] / 2, 0], mass: def.mass }], joints: [], tags: ["weapon"] };
101267
101313
  }
101268
101314
 
101269
- // src/fx/holstered.ts
101315
+ // src/fx/holster-rig.ts
101270
101316
  var HOLSTER_PLACEMENT = {
101271
101317
  hip: { muzzle: [0, -1, 0], out: [-1, 0, 0] },
101272
- back: { muzzle: [0.55, 0.835, 0], out: [0, 0, -1] }
101318
+ back: { muzzle: [0.55, 0.835, 0], out: [0, 0, -1] },
101319
+ sling: { muzzle: [0.32, -0.947, 0], out: [0, 0, 1] }
101320
+ };
101321
+ var SLING_HANG = { pivotBehind: 0.3, frontSwivel: 0.3, shoulder: [0.19, 0.2, -0.04], strapRadius: 8e-3, sag: 0.03, color: 4146217 };
101322
+ var gripOfProp = (THREE, weapon2, footprint) => {
101323
+ const model = buildWeaponModelById(THREE, weapon2);
101324
+ const right = model ? holdOfModel(THREE, model, 1).right : null;
101325
+ if (!model || !right) return { position: new THREE.Vector3(-footprint[0] * 0.15, footprint[1] * 0.3, 0), quaternion: new THREE.Quaternion() };
101326
+ const box5 = new THREE.Box3().setFromObject(model.root);
101327
+ const center = box5.getCenter(new THREE.Vector3());
101328
+ const frame2 = new THREE.Group();
101329
+ frame2.add(model.root);
101330
+ model.root.position.set(-center.x, -box5.min.y, -center.z);
101331
+ frame2.updateMatrixWorld(true);
101332
+ return { position: right.part.localToWorld(right.offset.clone()), quaternion: right.quaternion.clone() };
101273
101333
  };
101274
- var holsteredModel = (THREE, weapon2, slot, items) => {
101275
- const place = HOLSTER_PLACEMENT[slot];
101276
- const model = place ? buildModeledProp(THREE, { id: weapon2 }, weapon2, void 0, items) : void 0;
101277
- if (!place || !model) return void 0;
101334
+ var placeModel = (THREE, model, place, middle) => {
101278
101335
  const [, height, thickness] = model.userData.footprint ?? [0, 0, 0];
101279
101336
  const muzzle2 = new THREE.Vector3(...place.muzzle).normalize();
101280
101337
  const out = new THREE.Vector3(...place.out).normalize();
101281
101338
  const top = new THREE.Vector3().crossVectors(out, muzzle2).normalize();
101282
101339
  model.quaternion.setFromRotationMatrix(new THREE.Matrix4().makeBasis(muzzle2, top, out));
101283
- model.position.copy(top.multiplyScalar(-height / 2)).addScaledVector(out, thickness / 2);
101340
+ model.position.copy(middle).addScaledVector(top, -height / 2).addScaledVector(out, thickness / 2);
101341
+ };
101342
+ var buildHolsterRig = (THREE, weapon2, slot, options = {}) => {
101343
+ const place = HOLSTER_PLACEMENT[slot];
101344
+ const model = place ? buildModeledProp(THREE, { id: weapon2 }, weapon2, void 0, options.items) : void 0;
101345
+ if (!place || !model) return void 0;
101346
+ const footprint = model.userData.footprint ?? [0, 0, 0];
101284
101347
  const holder = new THREE.Group();
101285
101348
  holder.name = `holstered_${weapon2}`;
101286
- holder.add(model);
101287
- return holder;
101349
+ const slung = slot === "sling" && options.strapMaterial !== void 0;
101350
+ const swing = slung ? new THREE.Group() : holder;
101351
+ if (slung) holder.add(swing);
101352
+ const muzzle2 = new THREE.Vector3(...place.muzzle).normalize();
101353
+ const middle = slung ? muzzle2.clone().multiplyScalar(footprint[0] * SLING_HANG.pivotBehind) : new THREE.Vector3();
101354
+ placeModel(THREE, model, place, middle);
101355
+ swing.add(model);
101356
+ const strap = [];
101357
+ if (slung && options.strapMaterial) {
101358
+ const out = new THREE.Vector3(...place.out).normalize();
101359
+ const front = middle.clone().addScaledVector(muzzle2, footprint[0] * SLING_HANG.frontSwivel).addScaledVector(out, footprint[2] / 2);
101360
+ strap.push(createCord(THREE, catenary([0, 0, 0], SLING_HANG.shoulder, SLING_HANG.sag, 8), SLING_HANG.strapRadius, options.strapMaterial));
101361
+ strap.push(createCord(THREE, catenary([front.x, front.y, front.z], [0, 0, 0], SLING_HANG.sag, 8), SLING_HANG.strapRadius, options.strapMaterial));
101362
+ holder.add(strap[0]);
101363
+ swing.add(strap[1]);
101364
+ }
101365
+ holder.updateMatrixWorld(true);
101366
+ const inProp = gripOfProp(THREE, weapon2, footprint);
101367
+ const position = model.localToWorld(inProp.position.clone());
101368
+ const quaternion2 = model.quaternion.clone().multiply(inProp.quaternion);
101369
+ return { holder, swing, grip: { position, quaternion: quaternion2 }, strap };
101370
+ };
101371
+
101372
+ // src/fx/holstered.ts
101373
+ var GROUND_SLOT = "ground";
101374
+ var HOLSTER_TOSS = { drop: 0.8, ahead: 0.3, turn: 1.3, release: 0.4 };
101375
+ var MOVE_GRIP = 0.9;
101376
+ var MAX_SWING_ACCELERATION = 40;
101377
+ var holsteredModel = (THREE, weapon2, slot, items) => buildHolsterRig(THREE, weapon2, slot, items ? { items } : {})?.holder;
101378
+ var ease5 = (t) => {
101379
+ const k = Math.min(1, Math.max(0, t));
101380
+ return k * k * (3 - 2 * k);
101288
101381
  };
101289
101382
  var createHolsteredWeapons = (options) => {
101290
101383
  const { THREE } = options;
101291
- const models = /* @__PURE__ */ new Map();
101384
+ const rigs = /* @__PURE__ */ new Map();
101292
101385
  const away = /* @__PURE__ */ new Map();
101293
- const place = (weapon2, slot) => {
101294
- const holder = models.get(`${weapon2}@${slot}`);
101295
- const pose = options.bodySlot(slot);
101296
- if (!holder) return;
101297
- holder.visible = pose !== null;
101298
- if (!pose) return;
101299
- holder.position.set(pose.position[0], pose.position[1], pose.position[2]);
101300
- holder.quaternion.set(pose.quaternion[0], pose.quaternion[1], pose.quaternion[2], pose.quaternion[3]);
101386
+ 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) });
101388
+ const scratch3 = { position: new THREE.Vector3(), quaternion: new THREE.Quaternion(), inverse: new THREE.Quaternion(), acceleration: new THREE.Vector3(), velocity: new THREE.Vector3() };
101389
+ const holderOnHand = (rig, hand) => {
101390
+ const quaternion2 = hand.quaternion.clone().multiply(rig.grip.quaternion.clone().invert());
101391
+ return { position: hand.position.clone().sub(rig.grip.position.clone().applyQuaternion(quaternion2)), quaternion: quaternion2 };
101392
+ };
101393
+ const relativeTo = (frame2, base) => {
101394
+ const inverse = base.quaternion.clone().invert();
101395
+ return { position: frame2.position.clone().sub(base.position).applyQuaternion(inverse), quaternion: inverse.multiply(frame2.quaternion) };
101396
+ };
101397
+ const inFrame = (local2, base) => ({ position: local2.position.clone().applyQuaternion(base.quaternion).add(base.position), quaternion: base.quaternion.clone().multiply(local2.quaternion) });
101398
+ const holdFrame = () => {
101399
+ const pose = options.holdFrame?.();
101400
+ return pose ? frameOf2(pose) : null;
101401
+ };
101402
+ const goal = (entry2) => {
101403
+ if (entry2.motion?.kind === "toss") {
101404
+ const start = entry2.motion.start;
101405
+ const ahead = new THREE.Vector3(0, 0, -1).applyQuaternion(holdFrame()?.quaternion ?? start.quaternion).setY(0).normalize();
101406
+ const turn2 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3().crossVectors(ahead, new THREE.Vector3(0, 1, 0)).normalize(), HOLSTER_TOSS.turn);
101407
+ return { position: start.position.clone().addScaledVector(ahead, HOLSTER_TOSS.ahead).add(new THREE.Vector3(0, -HOLSTER_TOSS.drop, 0)), quaternion: turn2.multiply(start.quaternion.clone()) };
101408
+ }
101409
+ if (entry2.motion?.kind === "back") {
101410
+ const base = holdFrame();
101411
+ return base && entry2.taken ? inFrame(entry2.taken, base) : null;
101412
+ }
101413
+ const pose = options.bodySlot(entry2.slot);
101414
+ if (!pose) return null;
101415
+ return entry2.swing ? hanging(entry2, frameOf2(pose)) : frameOf2(pose);
101416
+ };
101417
+ const hanging = (entry2, frame2) => {
101418
+ const forward = new THREE.Vector3(0, 0, 1).applyQuaternion(frame2.quaternion);
101419
+ const up = new THREE.Vector3(0, 1, 0).applyQuaternion(frame2.quaternion);
101420
+ forward.y = 0;
101421
+ if (forward.lengthSq() < 1e-8) return frame2;
101422
+ forward.normalize();
101423
+ entry2.lean = Math.atan2(up.dot(forward), up.y);
101424
+ return { position: frame2.position, quaternion: new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 0, 1), forward) };
101425
+ };
101426
+ const place = (entry2, frame2) => {
101427
+ entry2.rig.holder.position.copy(frame2.position);
101428
+ entry2.rig.holder.quaternion.copy(frame2.quaternion);
101429
+ entry2.rig.holder.updateMatrixWorld(true);
101430
+ };
101431
+ const swingOf = (entry2, frame2, dt) => {
101432
+ 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);
101436
+ entry2.last = (entry2.last ?? new THREE.Vector3()).copy(frame2.position);
101437
+ entry2.speed.copy(velocity);
101438
+ acceleration.applyQuaternion(inverse.copy(frame2.quaternion).invert());
101439
+ const state = entry2.swing.step(dt, [-acceleration.x, acceleration.y, acceleration.z]);
101440
+ entry2.rig.swing.rotation.set(-(state.forward + Math.max(0, -entry2.lean)), 0, -state.side);
101441
+ entry2.rig.holder.updateMatrixWorld(true);
101442
+ };
101443
+ const hide = (weapon2) => {
101444
+ const entry2 = away.get(weapon2);
101445
+ if (!entry2) return;
101446
+ entry2.rig.holder.visible = false;
101447
+ away.delete(weapon2);
101448
+ };
101449
+ const step = (entry2, dt) => {
101450
+ const motion = entry2.motion;
101451
+ const target = goal(entry2);
101452
+ entry2.rig.holder.visible = target !== null;
101453
+ const body = entry2.rig.strap[0];
101454
+ if (body) body.visible = motion === null;
101455
+ if (!target) return;
101456
+ if (!motion) {
101457
+ place(entry2, target);
101458
+ swingOf(entry2, target, dt);
101459
+ return;
101460
+ }
101461
+ motion.time = Math.min(motion.seconds, motion.time + dt);
101462
+ const k = ease5(motion.time / motion.seconds);
101463
+ place(entry2, { position: motion.start.position.clone().lerp(target.position, k), quaternion: motion.start.quaternion.clone().slerp(target.quaternion, k) });
101464
+ if (motion.time < motion.seconds) return;
101465
+ if (motion.kind === "away") {
101466
+ entry2.motion = null;
101467
+ if (body) body.visible = true;
101468
+ }
101469
+ if (motion.kind === "toss") hide(entry2.weapon);
101470
+ };
101471
+ const rigOf = (weapon2, slot) => {
101472
+ const key2 = `${weapon2}@${slot}`;
101473
+ const known = rigs.get(key2);
101474
+ if (known) return known;
101475
+ const rig = buildHolsterRig(THREE, weapon2, slot === GROUND_SLOT ? "hip" : slot, { ...options.items ? { items: options.items } : {}, strapMaterial });
101476
+ if (!rig) return void 0;
101477
+ options.scene.add(rig.holder);
101478
+ rig.holder.visible = false;
101479
+ rigs.set(key2, rig);
101480
+ return rig;
101481
+ };
101482
+ const putAway = (event, seconds) => {
101483
+ if (!options.arsenal.weapons.has(event.weapon)) return;
101484
+ hide(event.weapon);
101485
+ const rig = rigOf(event.weapon, event.slot);
101486
+ if (!rig) return;
101487
+ rig.swing.rotation.set(0, 0, 0);
101488
+ const entry2 = { weapon: event.weapon, slot: event.slot, rig, motion: null, taken: null, swing: event.slot === "sling" ? createSlingSwing() : null, last: null, speed: new THREE.Vector3(), lean: 0 };
101489
+ if (event.from && seconds > 0) {
101490
+ const start = holderOnHand(rig, frameOf2(event.from));
101491
+ const base = holdFrame();
101492
+ entry2.taken = base ? relativeTo(start, base) : null;
101493
+ entry2.motion = { kind: event.slot === GROUND_SLOT ? "toss" : "away", time: 0, seconds, start };
101494
+ } else if (event.slot === GROUND_SLOT) return;
101495
+ away.set(event.weapon, entry2);
101496
+ step(entry2, 0);
101301
101497
  };
101302
101498
  return {
101303
101499
  handle(event) {
101304
- const key2 = `${event.weapon}@${event.slot}`;
101305
- if (!event.on) {
101306
- away.delete(event.weapon);
101307
- const holder = models.get(key2);
101308
- if (holder) holder.visible = false;
101309
- return;
101310
- }
101311
- if (!options.arsenal.weapons.has(event.weapon)) return;
101312
- if (!models.has(key2)) {
101313
- const holder = holsteredModel(THREE, event.weapon, event.slot, options.items);
101314
- if (!holder) return;
101315
- options.scene.add(holder);
101316
- models.set(key2, holder);
101317
- }
101318
- away.set(event.weapon, event.slot);
101319
- place(event.weapon, event.slot);
101500
+ const seconds = event.seconds ?? 0;
101501
+ if (event.on) return putAway(event, seconds);
101502
+ const entry2 = away.get(event.weapon);
101503
+ if (!entry2 || seconds <= 0 || !entry2.taken || !holdFrame()) return hide(event.weapon);
101504
+ entry2.motion = { kind: "back", time: 0, seconds, start: { position: entry2.rig.holder.position.clone(), quaternion: entry2.rig.holder.quaternion.clone() } };
101505
+ entry2.swing?.reset();
101506
+ entry2.rig.swing.rotation.set(0, 0, 0);
101320
101507
  },
101321
- update() {
101322
- for (const [weapon2, slot] of away) place(weapon2, slot);
101508
+ inHand(weapon2) {
101509
+ if (away.get(weapon2)?.motion?.kind !== "toss") hide(weapon2);
101510
+ },
101511
+ update(dt = 0) {
101512
+ for (const entry2 of [...away.values()]) step(entry2, dt);
101513
+ },
101514
+ handTargets() {
101515
+ for (const entry2 of away.values()) {
101516
+ const motion = entry2.motion;
101517
+ if (!motion || !entry2.rig.holder.visible) continue;
101518
+ if (motion.kind === "toss" && motion.time / motion.seconds > HOLSTER_TOSS.release) continue;
101519
+ const { position, quaternion: quaternion2 } = scratch3;
101520
+ position.copy(entry2.rig.grip.position).applyMatrix4(entry2.rig.holder.matrixWorld);
101521
+ quaternion2.copy(entry2.rig.holder.quaternion).multiply(entry2.rig.grip.quaternion);
101522
+ return { R: { position: [position.x, position.y, position.z], quaternion: [quaternion2.x, quaternion2.y, quaternion2.z, quaternion2.w] }, grip: MOVE_GRIP };
101523
+ }
101524
+ return null;
101323
101525
  },
101324
101526
  get drawn() {
101325
- return [...away.keys()];
101527
+ return [...away.values()].filter((entry2) => entry2.motion?.kind !== "toss").map((entry2) => entry2.weapon);
101326
101528
  },
101327
101529
  dispose() {
101328
- discardObject3D([...models.values()]);
101329
- models.clear();
101530
+ discardObject3D([...rigs.values()].map((rig) => rig.holder));
101531
+ strapMaterial.dispose();
101532
+ rigs.clear();
101330
101533
  away.clear();
101331
101534
  }
101332
101535
  };
@@ -102792,7 +102995,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
102792
102995
  });
102793
102996
  const worldEffects = createWorldEffects({ arsenal });
102794
102997
  const bodySlot = lent.bodySlot?.bind(lent);
102795
- const holstered = bodySlot ? createHolsteredWeapons({ THREE: lent.THREE, scene: lent.scene, arsenal, ...options.items ? { items: options.items } : {}, bodySlot }) : null;
102998
+ const holstered = bodySlot ? createHolsteredWeapons({ THREE: lent.THREE, scene: lent.scene, arsenal, ...options.items ? { items: options.items } : {}, bodySlot, holdFrame: () => lent.holdFrame?.("R") ?? null }) : null;
102796
102999
  const offEvents = lent.on((event) => {
102797
103000
  worldEffects.handle(event, lent.effects);
102798
103001
  if (event.type === "holster") {
@@ -102806,6 +103009,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
102806
103009
  return;
102807
103010
  }
102808
103011
  const tool2 = lent.tool();
103012
+ if (event.type === "tool") holstered?.inHand(event.weapon);
102809
103013
  created.handle(event, tool2);
102810
103014
  if (event.type === "reload" && event.phase === "start") {
102811
103015
  const clip = created.clips.find((entry2) => entry2.name.startsWith("reload"));
@@ -102818,9 +103022,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
102818
103022
  });
102819
103023
  const offFrame = lent.onFrame((dt) => {
102820
103024
  created.update(dt);
102821
- holstered?.update();
103025
+ holstered?.update(dt);
102822
103026
  });
102823
- const offHands = lent.setHandTargets?.(() => created.handTargets());
103027
+ const offHands = lent.setHandTargets?.(() => holstered?.handTargets() ?? created.handTargets());
102824
103028
  const offMuzzle = lent.setMuzzleSource?.((hand) => created.muzzle(hand));
102825
103029
  created.handle({ type: "tool", weapon: lent.tool().weapon }, lent.tool());
102826
103030
  return () => {