@adatechnology/game-weapons-three 0.24.2 → 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.
@@ -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);
@@ -28322,6 +28364,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28322
28364
  if (mat.ductility >= 0.5 && p.thickness <= THIN_SHEET_DISHING) addDent(o, p, entry2, n, Math.max(caliber * 3 / 1e3, 0.012), clamp2(E * 2e-5, 1e-3, 0.03), src);
28323
28365
  if (brittle && mat.fracture === "shatter") addCrack(o, p, entry2, n, crackLen, src);
28324
28366
  if (p.spec.contains && (p.st.liters ?? 0) > 1e-4) {
28367
+ o.active = true;
28325
28368
  emit2({
28326
28369
  ...base(o, src),
28327
28370
  type: "leak",
@@ -54846,7 +54889,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
54846
54889
  }
54847
54890
  var residentialTower = residentialTowerTemplate();
54848
54891
 
54849
- // ../game-floorplan-three/dist/chunk-FDMQUIRF.js
54892
+ // ../game-floorplan-three/dist/chunk-W4VG2X7N.js
54850
54893
  var __defProp4 = Object.defineProperty;
54851
54894
  var __defNormalProp2 = (obj, key2, value) => key2 in obj ? __defProp4(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
54852
54895
  var __publicField2 = (obj, key2, value) => __defNormalProp2(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -63581,11 +63624,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63581
63624
  }
63582
63625
  return seats;
63583
63626
  }
63627
+ var MAX_INTERIOR = 32;
63628
+ var INTERIOR_INSET = 0.01;
63584
63629
  var newGroup = (k, house, exterior) => ({ k, house, ls: [], exterior, pos: [0, 0, 0], color: 0, n: 0, range: 0, rects: [], y: [0, 0], exclusion: null, lumens: 0, dist: 0, decay: 0, floor: 0, roomId: null, dm: 0, d: 0 });
63585
63630
  function installLightsRoomLight(K, shared3) {
63586
63631
  const { THREE, rectsOf: rectsOf2, cfg } = K;
63587
63632
  const MAX_LIGHTS = 12, EMPTY = [1e9, 1e9, -1e9, -1e9];
63588
- const LZU = { uRB0: { value: new Float32Array(MAX_LIGHTS * 4) }, uRB1: { value: new Float32Array(MAX_LIGHTS * 4) }, uRB2: { value: new Float32Array(MAX_LIGHTS * 4) }, uRBY: { value: new Float32Array(MAX_LIGHTS * 2) }, uREx: { value: new Float32Array(MAX_LIGHTS * 4) }, uIndK: { value: 0.06 } };
63633
+ const LZU = { uRB0: { value: new Float32Array(MAX_LIGHTS * 4) }, uRB1: { value: new Float32Array(MAX_LIGHTS * 4) }, uRB2: { value: new Float32Array(MAX_LIGHTS * 4) }, uRBY: { value: new Float32Array(MAX_LIGHTS * 2) }, uREx: { value: new Float32Array(MAX_LIGHTS * 4) }, uROut: { value: new Float32Array(MAX_LIGHTS) }, uRIn: { value: new Float32Array(MAX_INTERIOR * 4) }, uRInY: { value: new Float32Array(MAX_INTERIOR * 2) }, uRInN: { value: 0 }, uIndK: { value: 0.06 } };
63589
63634
  for (let i = 0; i < MAX_LIGHTS; i++) for (const k of ["uRB0", "uRB1", "uRB2", "uREx"]) LZU[k].value.set(EMPTY, i * 4);
63590
63635
  function roomLightMask(material) {
63591
63636
  const m = material;
@@ -63598,23 +63643,31 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63598
63643
  if (!sh || !sh.fragmentShader) return;
63599
63644
  if (sh.uniforms) Object.assign(sh.uniforms, LZU);
63600
63645
  if (sh.vertexShader) sh.vertexShader = sh.vertexShader.replace("void main() {", "varying vec3 vRoomW;\nvoid main() {").replace("#include <begin_vertex>", "#include <begin_vertex>\n vRoomW = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;");
63646
+ const lightsBegin = THREE.ShaderChunk?.lights_fragment_begin;
63647
+ if (lightsBegin) sh.fragmentShader = sh.fragmentShader.replace("#include <lights_fragment_begin>", lightsBegin);
63601
63648
  sh.fragmentShader = sh.fragmentShader.replace("void main() {", `varying vec3 vRoomW;
63602
63649
  #if NUM_POINT_LIGHTS > 0
63603
- uniform vec4 uRB0[ NUM_POINT_LIGHTS ]; uniform vec4 uRB1[ NUM_POINT_LIGHTS ]; uniform vec4 uRB2[ NUM_POINT_LIGHTS ]; uniform vec2 uRBY[ NUM_POINT_LIGHTS ]; uniform vec4 uREx[ NUM_POINT_LIGHTS ];
63650
+ uniform vec4 uRB0[ NUM_POINT_LIGHTS ]; uniform vec4 uRB1[ NUM_POINT_LIGHTS ]; uniform vec4 uRB2[ NUM_POINT_LIGHTS ]; uniform vec2 uRBY[ NUM_POINT_LIGHTS ]; uniform vec4 uREx[ NUM_POINT_LIGHTS ]; uniform float uROut[ NUM_POINT_LIGHTS ];
63604
63651
  #endif
63652
+ uniform vec4 uRIn[ ${MAX_INTERIOR} ]; uniform vec2 uRInY[ ${MAX_INTERIOR} ]; uniform int uRInN;
63605
63653
  uniform float uIndK;
63606
63654
  bool inRoomR( vec4 r, vec3 p ) { return p.x >= r.x && p.x <= r.z && p.z >= r.y && p.z <= r.w; }
63607
- float roomMask( vec4 a, vec4 b, vec4 c, vec2 yy, vec4 ex ) {
63608
- vec3 p = vRoomW; float k = ( inRoomR( a, p ) || inRoomR( b, p ) || inRoomR( c, p ) ) ? 1.0 : 0.0;
63655
+ bool roomInside( vec3 p ) {
63656
+ for ( int j = 0; j < ${MAX_INTERIOR}; j ++ ) { if ( j >= uRInN ) break; if ( inRoomR( uRIn[ j ], p ) && p.y >= uRInY[ j ].x && p.y <= uRInY[ j ].y ) return true; }
63657
+ return false;
63658
+ }
63659
+ float roomMask( vec4 a, vec4 b, vec4 c, vec2 yy, vec4 ex, float outdoor, bool inside ) {
63660
+ vec3 p = vRoomW; if ( outdoor > 0.5 && outdoor < 1.5 && !inside ) return 1.0; float k = ( inRoomR( a, p ) || inRoomR( b, p ) || inRoomR( c, p ) ) ? 1.0 : 0.0;
63609
63661
  k *= ( p.y >= yy.x && p.y <= yy.y ) ? 1.0 : 0.0; if ( inRoomR( ex, p ) ) k = 0.0; return k;
63610
63662
  }
63611
- void main() {`).replace("getPointLightInfo( pointLight, geometryPosition, directLight );", `getPointLightInfo( pointLight, geometryPosition, directLight );
63612
- float rmk = roomMask( uRB0[ i ], uRB1[ i ], uRB2[ i ], uRBY[ i ], uREx[ i ] );
63663
+ void main() {
63664
+ bool rInside = roomInside( vRoomW ); float rmk = 1.0;`).replace("getPointLightInfo( pointLight, geometryPosition, directLight );", `getPointLightInfo( pointLight, geometryPosition, directLight );
63665
+ rmk = roomMask( uRB0[ i ], uRB1[ i ], uRB2[ i ], uRBY[ i ], uREx[ i ], uROut[ i ], rInside );
63613
63666
  directLight.color *= rmk;
63614
- reflectedLight.indirectDiffuse += BRDF_Lambert( material.diffuseColor ) * pointLight.color * ( rmk * uIndK * ( 1.0 - smoothstep( 0.0, max( pointLight.distance, 0.1 ), length( pointLight.position - geometryPosition ) ) ) );`);
63667
+ reflectedLight.indirectDiffuse += BRDF_Lambert( material.diffuseColor ) * pointLight.color * ( rmk * step( uROut[ i ], 0.5 ) * uIndK * ( 1.0 - smoothstep( 0.0, max( pointLight.distance, 0.1 ), length( pointLight.position - geometryPosition ) ) ) );`);
63615
63668
  };
63616
63669
  m.customProgramCacheKey = function() {
63617
- return (pk ? pk.call(this) : "") + "|rm1";
63670
+ return (pk ? pk.call(this) : "") + "|rm3";
63618
63671
  };
63619
63672
  m.needsUpdate = true;
63620
63673
  return material;
@@ -63626,7 +63679,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63626
63679
  for (const k of Object.keys(mats)) roomLightMask(mats[k]);
63627
63680
  const budget = o.budget, lease = budget ? budget.lease({ owner: "floorplan.rooms", point: N, shadows: NS }) : null;
63628
63681
  if (budget && !lease) throw new Error("lighting: the LightBudget has no " + N + " free point slots (" + NS + " with shadow) for the rooms");
63629
- if (budget) for (const [key2, width] of [["uRB0", 4], ["uRB1", 4], ["uRB2", 4], ["uRBY", 2], ["uREx", 4]]) {
63682
+ if (budget) for (const [key2, width] of [["uRB0", 4], ["uRB1", 4], ["uRB2", 4], ["uRBY", 2], ["uREx", 4], ["uROut", 1]]) {
63630
63683
  const next = new Float32Array(budget.sizes.point * width);
63631
63684
  if (width === 4) for (let i = 0; i < budget.sizes.point; i++) next.set(EMPTY, i * 4);
63632
63685
  LZU[key2].value = next;
@@ -63783,7 +63836,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63783
63836
  A.stats.external = Ne;
63784
63837
  let shadows = 0;
63785
63838
  for (let i = 0; i < N; i++) {
63786
- const g = asg[i], at4 = slotOf(i), b0 = LZU.uRB0.value, b1 = LZU.uRB1.value, b2 = LZU.uRB2.value, by = LZU.uRBY.value, ex = LZU.uREx.value;
63839
+ const g = asg[i], at4 = slotOf(i);
63840
+ LZU.uROut.value[at4] = 0;
63841
+ const b0 = LZU.uRB0.value, b1 = LZU.uRB1.value, b2 = LZU.uRB2.value, by = LZU.uRBY.value, ex = LZU.uREx.value;
63787
63842
  A.crates[i] = g ? { k: g.k, rects: g.rects, y: g.y, exterior: !!g.exterior, exclusion: g.exclusion || null, d: g.d } : null;
63788
63843
  if (!g) {
63789
63844
  put(i, { intensity: 0 });
@@ -63812,7 +63867,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63812
63867
  if (!lease) PL[i].shadow.camera.far = Math.max(4, lamp.distance);
63813
63868
  }
63814
63869
  }
63815
- if (effects) effects.update(houses);
63870
+ if (effects) effects.update(houses, _f);
63816
63871
  A.stats.shadows = shadows;
63817
63872
  return A.stats;
63818
63873
  };
@@ -63829,7 +63884,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63829
63884
  return A;
63830
63885
  }
63831
63886
  const effectsByBudget = /* @__PURE__ */ new WeakMap();
63832
- const OPENING_REACH = 2.5, OPENING_SIDE = 0.6;
63887
+ const OPENING_REACH = 2.5, OPENING_SIDE = 0.6, OUTDOOR_REACH = 30;
63888
+ const EFFECT_OUTDOORS = 1, EFFECT_INDOORS = 2;
63889
+ const boxesByHouse = /* @__PURE__ */ new WeakMap();
63890
+ const sameBoxMatrix = (a, b) => {
63891
+ for (let i = 0; i < 16; i++) if (a[i] !== b[i]) return false;
63892
+ return true;
63893
+ };
63833
63894
  function effectLights(options) {
63834
63895
  const o = options || {};
63835
63896
  const budget = o.budget;
@@ -63837,7 +63898,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63837
63898
  const known = effectsByBudget.get(budget);
63838
63899
  if (known && !o.ours) return known;
63839
63900
  const ours = new Set(o.ours || []), size = budget.sizes.point, _p = new THREE.Vector3(), P0 = new THREE.Vector3();
63840
- for (const [key2, width] of [["uRB0", 4], ["uRB1", 4], ["uRB2", 4], ["uRBY", 2], ["uREx", 4]]) {
63901
+ for (const [key2, width] of [["uRB0", 4], ["uRB1", 4], ["uRB2", 4], ["uRBY", 2], ["uREx", 4], ["uROut", 1]]) {
63841
63902
  const had = LZU[key2].value;
63842
63903
  if (had.length >= size * width) continue;
63843
63904
  const next = new Float32Array(size * width);
@@ -63845,11 +63906,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63845
63906
  next.set(had);
63846
63907
  LZU[key2].value = next;
63847
63908
  }
63909
+ const maskHouseMaterials = () => {
63910
+ const mats = shared3.mats;
63911
+ for (const k in mats) roomLightMask(mats[k]);
63912
+ };
63913
+ maskHouseMaterials();
63848
63914
  const roomBoxes = (house, M) => {
63849
63915
  const list2 = [];
63850
63916
  for (const c of house.r.rooms) {
63851
63917
  if (c.type === "void") continue;
63852
- const rs = [];
63918
+ const rs = [], inner = [];
63853
63919
  for (const [a, b, c2, d] of rectsOf2(c)) {
63854
63920
  let x0 = 1e9, z0 = 1e9, x1 = -1e9, z1 = -1e9;
63855
63921
  for (const [u, v] of [[a, b], [c2, b], [a, d], [c2, d]]) {
@@ -63860,9 +63926,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63860
63926
  z1 = Math.max(z1, _p.z);
63861
63927
  }
63862
63928
  rs.push([x0 - 0.08, z0 - 0.08, x1 + 0.08, z1 + 0.08]);
63929
+ inner.push([x0 + INTERIOR_INSET, z0 + INTERIOR_INSET, x1 - INTERIOR_INSET, z1 - INTERIOR_INSET]);
63863
63930
  }
63864
63931
  _p.set(0, house.y0(c.floor), 0).applyMatrix4(M);
63865
- list2.push({ c, rs, y: [_p.y - 0.06, _p.y + (c.ceiling || 2.8) + 0.3] });
63932
+ const ceiling = c.ceiling || 2.8;
63933
+ list2.push({ c, rs, y: [_p.y - 0.06, _p.y + ceiling + 0.3], inner, innerY: [_p.y - 0.06, _p.y + ceiling + 0.05] });
63866
63934
  }
63867
63935
  return list2;
63868
63936
  };
@@ -63884,9 +63952,28 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63884
63952
  reach2(house.r.doors, true);
63885
63953
  reach2(house.r.windows, false);
63886
63954
  };
63955
+ const openingsFacing = (house, M, boxes, into, reach2) => {
63956
+ const open = house.internal && house.internal.doorState || /* @__PURE__ */ new Map();
63957
+ const through = (list2, isDoor) => {
63958
+ for (const p of list2 || []) {
63959
+ if (isDoor && !(open.has(p.id) ? open.get(p.id) : !!p.open)) continue;
63960
+ const alongU = p.axis === "u", y = house.y0(p.floor) + (isDoor ? 1 : ((p.y0 != null ? p.y0 : 0.9) + (p.y1 != null ? p.y1 : 2)) / 2);
63961
+ const at4 = (side) => _p.set(alongU ? p.at : p.pos + side, y, alongU ? p.pos + side : p.at).applyMatrix4(M).clone();
63962
+ const centre = at4(0);
63963
+ if (centre.distanceTo(P0) > reach2) continue;
63964
+ const low = at4(-OPENING_SIDE), high = at4(OPENING_SIDE), lowRoom = boxAt(boxes, low.x, low.y, low.z), highRoom = boxAt(boxes, high.x, high.y, high.z);
63965
+ if (!lowRoom === !highRoom) continue;
63966
+ const room = lowRoom || highRoom, outside = lowRoom ? high : low;
63967
+ if ((P0.x - centre.x) * (outside.x - centre.x) + (P0.z - centre.z) * (outside.z - centre.z) > 0) into.set(room.c, room);
63968
+ }
63969
+ };
63970
+ through(house.r.doors, true);
63971
+ through(house.r.windows, false);
63972
+ };
63887
63973
  const clear = (at4) => {
63888
63974
  for (const key2 of ["uRB0", "uRB1", "uRB2", "uREx"]) LZU[key2].value.set(EMPTY, at4 * 4);
63889
63975
  LZU.uRBY.value.set([0, 0], at4 * 2);
63976
+ LZU.uROut.value[at4] = 0;
63890
63977
  };
63891
63978
  const write = (at4, into) => {
63892
63979
  const rs = [];
@@ -63903,13 +63990,55 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63903
63990
  LZU.uRB0.value.set(rs[0] || EMPTY, at4 * 4);
63904
63991
  LZU.uRB1.value.set(rs[1] || EMPTY, at4 * 4);
63905
63992
  LZU.uRB2.value.set(rs[2] || EMPTY, at4 * 4);
63906
- LZU.uRBY.value.set([lo, hi], at4 * 2);
63993
+ LZU.uRBY.value.set(rs.length ? [lo, hi] : [0, 0], at4 * 2);
63907
63994
  LZU.uREx.value.set(EMPTY, at4 * 4);
63908
63995
  };
63996
+ const nearHouses = [];
63997
+ const writeInteriors = (focus) => {
63998
+ if (focus) for (const h of nearHouses) {
63999
+ const b = h.entry.bounds;
64000
+ h.d = Math.hypot(Math.max(b[0] - focus.x, 0, focus.x - b[2]), Math.max(b[1] - focus.z, 0, focus.z - b[3]));
64001
+ }
64002
+ if (focus) nearHouses.sort((a, b) => a.d - b.d);
64003
+ const rects = LZU.uRIn.value, ys = LZU.uRInY.value;
64004
+ let n = 0;
64005
+ for (const { entry: entry2 } of nearHouses) for (const q of entry2.boxes) for (const r of q.inner) {
64006
+ if (n >= MAX_INTERIOR) break;
64007
+ rects.set(r, n * 4);
64008
+ ys.set(q.innerY, n * 2);
64009
+ n++;
64010
+ }
64011
+ LZU.uRInN.value = n;
64012
+ };
63909
64013
  const A = {
63910
64014
  /** Once per frame, after the budget's `present`: points the mask of every lit slot that is not the house's at the rooms its light reaches. */
63911
- update(houses) {
63912
- const indoors = cfg.effectLightsIndoors !== false, list2 = (Array.isArray(houses) ? houses : [houses]).filter((h) => !!h), cache2 = /* @__PURE__ */ new Map();
64015
+ update(houses, focus) {
64016
+ maskHouseMaterials();
64017
+ const indoors = cfg.effectLightsIndoors !== false, list2 = (Array.isArray(houses) ? houses : [houses]).filter((h) => !!h);
64018
+ const entries2 = list2.map((house) => {
64019
+ if (house.group && !house.group.visible) return void 0;
64020
+ let entry2 = boxesByHouse.get(house);
64021
+ if (!entry2 || !sameBoxMatrix(entry2.matrix, house.house.matrixWorld.elements)) {
64022
+ house.house.updateMatrixWorld(true);
64023
+ const M = house.house.matrixWorld, boxes = roomBoxes(house, M);
64024
+ let x0 = 1e9, z0 = 1e9, x1 = -1e9, z1 = -1e9, y0 = 1e9, y1 = -1e9;
64025
+ for (const q of boxes) {
64026
+ for (const r of q.rs) {
64027
+ x0 = Math.min(x0, r[0]);
64028
+ z0 = Math.min(z0, r[1]);
64029
+ x1 = Math.max(x1, r[2]);
64030
+ z1 = Math.max(z1, r[3]);
64031
+ }
64032
+ y0 = Math.min(y0, q.y[0]);
64033
+ y1 = Math.max(y1, q.y[1]);
64034
+ }
64035
+ entry2 = { matrix: Float64Array.from(M.elements), boxes, bounds: [x0, z0, x1, z1, y0, y1] };
64036
+ boxesByHouse.set(house, entry2);
64037
+ }
64038
+ return entry2;
64039
+ });
64040
+ const reach2 = OPENING_REACH + OPENING_SIDE;
64041
+ nearHouses.length = 0;
63913
64042
  for (let at4 = 0; at4 < size; at4++) {
63914
64043
  if (ours.has(at4)) continue;
63915
64044
  const light = budget.group.children[at4];
@@ -63917,21 +64046,36 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
63917
64046
  clear(at4);
63918
64047
  continue;
63919
64048
  }
63920
- const into = /* @__PURE__ */ new Map();
63921
64049
  P0.set(light.position.x, light.position.y, light.position.z);
63922
- for (const house of list2) {
63923
- if (house.group && !house.group.visible) continue;
63924
- house.house.updateMatrixWorld(true);
63925
- const M = house.house.matrixWorld;
63926
- let boxes = cache2.get(house);
63927
- if (!boxes) cache2.set(house, boxes = roomBoxes(house, M));
63928
- const here = boxAt(boxes, P0.x, P0.y, P0.z);
64050
+ let into, isIndoor = false;
64051
+ for (let i = 0; i < list2.length; i++) {
64052
+ const entry2 = entries2[i];
64053
+ if (entry2 && boxAt(entry2.boxes, P0.x, P0.y, P0.z)) {
64054
+ isIndoor = true;
64055
+ break;
64056
+ }
64057
+ }
64058
+ const lightReach = isIndoor ? reach2 : light.distance > 0 ? Math.min(light.distance, OUTDOOR_REACH) : OUTDOOR_REACH;
64059
+ for (let i = 0; i < list2.length; i++) {
64060
+ const entry2 = entries2[i], house = list2[i];
64061
+ if (!entry2) continue;
64062
+ const b = entry2.bounds;
64063
+ if (P0.x < b[0] - lightReach || P0.x > b[2] + lightReach || P0.z < b[1] - lightReach || P0.z > b[3] + lightReach || P0.y < b[4] - lightReach || P0.y > b[5] + lightReach) continue;
64064
+ into = into || /* @__PURE__ */ new Map();
64065
+ if (!isIndoor) {
64066
+ if (!nearHouses.some((h) => h.entry === entry2)) nearHouses.push({ entry: entry2, d: 0 });
64067
+ openingsFacing(house, house.house.matrixWorld, entry2.boxes, into, lightReach);
64068
+ continue;
64069
+ }
64070
+ const here = boxAt(entry2.boxes, P0.x, P0.y, P0.z);
63929
64071
  if (here) into.set(here.c, here);
63930
- openingSides(house, M, boxes, into);
64072
+ openingSides(house, house.house.matrixWorld, entry2.boxes, into);
63931
64073
  }
63932
- if (into.size) write(at4, into);
64074
+ if (into && into.size) write(at4, into);
63933
64075
  else clear(at4);
64076
+ LZU.uROut.value[at4] = isIndoor ? EFFECT_INDOORS : EFFECT_OUTDOORS;
63934
64077
  }
64078
+ writeInteriors(focus);
63935
64079
  }
63936
64080
  };
63937
64081
  if (!o.ours) effectsByBudget.set(budget, A);
@@ -67141,7 +67285,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
67141
67285
  if (LOOSE.has(part.material) || part.shape.kind !== "box" || part.rotation) continue;
67142
67286
  const [x, y, z] = part.shape.size;
67143
67287
  if (y >= x && y >= z) {
67144
- 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
+ }
67145
67293
  part.structure = { role: "column" };
67146
67294
  } else if (y <= x && y <= z) part.structure = { role: "beam", maxSpan: SHELF_SPAN * Math.max(x, z) };
67147
67295
  }
@@ -81700,6 +81848,28 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
81700
81848
  "corrosive"
81701
81849
  ]
81702
81850
  },
81851
+ {
81852
+ id: "sewage",
81853
+ color: 5921582,
81854
+ opacity: 0.92,
81855
+ stainColor: 3093273,
81856
+ viscosity: 4,
81857
+ density: 1010,
81858
+ dryTime: 1800,
81859
+ gloss: 0.8,
81860
+ leavesMark: true,
81861
+ drink: {
81862
+ thirst: 0,
81863
+ effects: [
81864
+ "disgust",
81865
+ "poison"
81866
+ ]
81867
+ },
81868
+ tags: [
81869
+ "organic",
81870
+ "waste"
81871
+ ]
81872
+ },
81703
81873
  {
81704
81874
  id: "honey",
81705
81875
  color: 14193162,
@@ -81731,6 +81901,46 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
81731
81901
  tags: [
81732
81902
  "dirty"
81733
81903
  ]
81904
+ },
81905
+ {
81906
+ id: "coolant",
81907
+ color: 3455050,
81908
+ opacity: 0.7,
81909
+ stainColor: 2783796,
81910
+ viscosity: 4,
81911
+ density: 1070,
81912
+ dryTime: 1200,
81913
+ gloss: 0.85,
81914
+ leavesMark: true,
81915
+ drink: {
81916
+ thirst: 0,
81917
+ effects: [
81918
+ "poison"
81919
+ ]
81920
+ },
81921
+ tags: [
81922
+ "coolant"
81923
+ ]
81924
+ },
81925
+ {
81926
+ id: "brake_fluid",
81927
+ color: 13145646,
81928
+ opacity: 0.8,
81929
+ stainColor: 9069600,
81930
+ viscosity: 8,
81931
+ density: 1050,
81932
+ dryTime: 3600,
81933
+ gloss: 0.9,
81934
+ leavesMark: true,
81935
+ drink: {
81936
+ thirst: 0,
81937
+ effects: [
81938
+ "poison"
81939
+ ]
81940
+ },
81941
+ tags: [
81942
+ "brake_fluid"
81943
+ ]
81734
81944
  }
81735
81945
  ];
81736
81946
  var LIQUIDS = liquids_default;
@@ -93099,6 +93309,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
93099
93309
  __publicField3(this, "centerZ", 0);
93100
93310
  __publicField3(this, "puddles", WORKSHOP_PUDDLES);
93101
93311
  __publicField3(this, "puddleAt");
93312
+ __publicField3(this, "coverTopAt");
93102
93313
  }
93103
93314
  /** `initRain` (W321): `count` streaks (thinned by the quality), each drawn at a random place in the box. */
93104
93315
  init(count, wind) {
@@ -93144,6 +93355,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
93144
93355
  positions2[o + 3] += slant;
93145
93356
  positions2[o + 1] -= fall;
93146
93357
  positions2[o + 4] -= fall;
93358
+ if (this.coverTopAt) {
93359
+ const top = this.coverTopAt(positions2[o], positions2[o + 2]);
93360
+ if (top !== void 0 && positions2[o + 4] < top) {
93361
+ this.restart(o);
93362
+ continue;
93363
+ }
93364
+ }
93147
93365
  const ground = context.groundAt(positions2[o], positions2[o + 2]);
93148
93366
  if (positions2[o + 4] < ground) {
93149
93367
  const x = positions2[o];
@@ -93159,10 +93377,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
93159
93377
  }
93160
93378
  }
93161
93379
  }
93162
- const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
93163
- const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
93164
- const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
93165
- this.set(o, nx, ny, nz);
93380
+ this.restart(o);
93166
93381
  }
93167
93382
  }
93168
93383
  }
@@ -93170,6 +93385,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
93170
93385
  clear() {
93171
93386
  this.on = false;
93172
93387
  }
93388
+ restart(offset) {
93389
+ const { random } = this.engine;
93390
+ const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
93391
+ const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
93392
+ const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
93393
+ this.set(offset, nx, ny, nz);
93394
+ }
93173
93395
  set(offset, x, y, z) {
93174
93396
  const positions2 = this.positions;
93175
93397
  positions2[offset] = x;
@@ -93962,8 +94184,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
93962
94184
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
93963
94185
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
93964
94186
  aliasOf(ENGINE_SMOKE, "vehicle_exhaust", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 0 }, loop: 0.5 }),
93965
- /** A hole in the tank: the page's petrol leak without the fire and the blast (the pool and the drips). A normal bullet does only this. */
93966
- aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", {}),
94187
+ /**
94188
+ * A hole in a tank: the page's drips, falling from the point it is played at (the hole). No pool of its own: the pool is the liquid that came out, laid by the
94189
+ * host's fluid world as it leaks (it grows with the volume and spreads by the liquid's own kind), not a drawing of a size the page chose.
94190
+ */
94191
+ aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", { anchor: TANK, timeline: [] }),
93967
94192
  /** The leak caught fire (an incendiary or tracer round, a spark, a fire near): the page's whole sequence, the fire running along the pool to the tank and the blast. */
93968
94193
  aliasOf(FUEL_LEAK, "vehicle_leak_ignited", {})
93969
94194
  ];
@@ -101087,67 +101312,224 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
101087
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"] };
101088
101313
  }
101089
101314
 
101090
- // src/fx/holstered.ts
101315
+ // src/fx/holster-rig.ts
101091
101316
  var HOLSTER_PLACEMENT = {
101092
101317
  hip: { muzzle: [0, -1, 0], out: [-1, 0, 0] },
101093
- 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() };
101094
101333
  };
101095
- var holsteredModel = (THREE, weapon2, slot, items) => {
101096
- const place = HOLSTER_PLACEMENT[slot];
101097
- const model = place ? buildModeledProp(THREE, { id: weapon2 }, weapon2, void 0, items) : void 0;
101098
- if (!place || !model) return void 0;
101334
+ var placeModel = (THREE, model, place, middle) => {
101099
101335
  const [, height, thickness] = model.userData.footprint ?? [0, 0, 0];
101100
101336
  const muzzle2 = new THREE.Vector3(...place.muzzle).normalize();
101101
101337
  const out = new THREE.Vector3(...place.out).normalize();
101102
101338
  const top = new THREE.Vector3().crossVectors(out, muzzle2).normalize();
101103
101339
  model.quaternion.setFromRotationMatrix(new THREE.Matrix4().makeBasis(muzzle2, top, out));
101104
- 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];
101105
101347
  const holder = new THREE.Group();
101106
101348
  holder.name = `holstered_${weapon2}`;
101107
- holder.add(model);
101108
- 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);
101109
101381
  };
101110
101382
  var createHolsteredWeapons = (options) => {
101111
101383
  const { THREE } = options;
101112
- const models = /* @__PURE__ */ new Map();
101384
+ const rigs = /* @__PURE__ */ new Map();
101113
101385
  const away = /* @__PURE__ */ new Map();
101114
- const place = (weapon2, slot) => {
101115
- const holder = models.get(`${weapon2}@${slot}`);
101116
- const pose = options.bodySlot(slot);
101117
- if (!holder) return;
101118
- holder.visible = pose !== null;
101119
- if (!pose) return;
101120
- holder.position.set(pose.position[0], pose.position[1], pose.position[2]);
101121
- 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);
101122
101497
  };
101123
101498
  return {
101124
101499
  handle(event) {
101125
- const key2 = `${event.weapon}@${event.slot}`;
101126
- if (!event.on) {
101127
- away.delete(event.weapon);
101128
- const holder = models.get(key2);
101129
- if (holder) holder.visible = false;
101130
- return;
101131
- }
101132
- if (!options.arsenal.weapons.has(event.weapon)) return;
101133
- if (!models.has(key2)) {
101134
- const holder = holsteredModel(THREE, event.weapon, event.slot, options.items);
101135
- if (!holder) return;
101136
- options.scene.add(holder);
101137
- models.set(key2, holder);
101138
- }
101139
- away.set(event.weapon, event.slot);
101140
- 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);
101141
101507
  },
101142
- update() {
101143
- 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;
101144
101525
  },
101145
101526
  get drawn() {
101146
- return [...away.keys()];
101527
+ return [...away.values()].filter((entry2) => entry2.motion?.kind !== "toss").map((entry2) => entry2.weapon);
101147
101528
  },
101148
101529
  dispose() {
101149
- discardObject3D([...models.values()]);
101150
- models.clear();
101530
+ discardObject3D([...rigs.values()].map((rig) => rig.holder));
101531
+ strapMaterial.dispose();
101532
+ rigs.clear();
101151
101533
  away.clear();
101152
101534
  }
101153
101535
  };
@@ -102613,7 +102995,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
102613
102995
  });
102614
102996
  const worldEffects = createWorldEffects({ arsenal });
102615
102997
  const bodySlot = lent.bodySlot?.bind(lent);
102616
- 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;
102617
102999
  const offEvents = lent.on((event) => {
102618
103000
  worldEffects.handle(event, lent.effects);
102619
103001
  if (event.type === "holster") {
@@ -102627,6 +103009,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
102627
103009
  return;
102628
103010
  }
102629
103011
  const tool2 = lent.tool();
103012
+ if (event.type === "tool") holstered?.inHand(event.weapon);
102630
103013
  created.handle(event, tool2);
102631
103014
  if (event.type === "reload" && event.phase === "start") {
102632
103015
  const clip = created.clips.find((entry2) => entry2.name.startsWith("reload"));
@@ -102639,9 +103022,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
102639
103022
  });
102640
103023
  const offFrame = lent.onFrame((dt) => {
102641
103024
  created.update(dt);
102642
- holstered?.update();
103025
+ holstered?.update(dt);
102643
103026
  });
102644
- const offHands = lent.setHandTargets?.(() => created.handTargets());
103027
+ const offHands = lent.setHandTargets?.(() => holstered?.handTargets() ?? created.handTargets());
102645
103028
  const offMuzzle = lent.setMuzzleSource?.((hand) => created.muzzle(hand));
102646
103029
  created.handle({ type: "tool", weapon: lent.tool().weapon }, lent.tool());
102647
103030
  return () => {