@adatechnology/game-vehicles-three 0.14.2 → 0.14.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.
@@ -7993,7 +7993,7 @@ var GameVehiclesThree = (() => {
7993
7993
  frameR: 9e-3
7994
7994
  });
7995
7995
  const e = K.grid(1, 0, { z1: 0.1, y0: 0.64, y1: 0.72, du: 0.03, dv: 0.03 }).at(0.5, 0.67);
7996
- kit.emblem(c2, e.p.x + 0.025, 0.67, 0, 0.045);
7996
+ kit.emblem(c2, e.p.x + 0.018, 0.67, 0, 0.045);
7997
7997
  const bg = c2.meta.frontBumper.userData.grid;
7998
7998
  c2.deform.push(K.skin(bg, MT.rubber, { u0: 0.02, u1: 0.98, yb: 0.37, yt: 0.405, off: 0.02, nv: 1 }));
7999
7999
  },
@@ -18992,8 +18992,8 @@ var GameVehiclesThree = (() => {
18992
18992
  return b;
18993
18993
  }
18994
18994
  function plateMoto(c, x, y, txt) {
18995
- c.roundBox(0.02, 0.15, 0.2, 8e-3, MT.trim, x + 9e-3, y, 0);
18996
- c.text(txt || kit.config.plate.slice(0, 5), 0.2, 0.135, x - 3e-3, y, 0, "-x", {
18995
+ c.roundBox(0.02, 0.15, 0.2, 8e-3, MT.trim, x + 7e-3, y, 0);
18996
+ c.text(txt || kit.config.plate.slice(0, 5), 0.2, 0.135, x - 5e-3, y, 0, "-x", {
18997
18997
  w: 300,
18998
18998
  h: 220,
18999
18999
  bg: "#f2f2ee",
@@ -19107,8 +19107,8 @@ var GameVehiclesThree = (() => {
19107
19107
  d.position.z = s * hw * 0.72;
19108
19108
  g.add(d);
19109
19109
  for (let q = 0; q < 12; q++) {
19110
- const a2 = q / 12 * PI * 2, sl = new THREE.Mesh(G2.roundedBox(rimR * 0.42, 0.016, 6e-3, 5e-3), o.slot || CM("#1c1e21", { metalness: 0.5, roughness: 0.4 }));
19111
- sl.position.set(Math.cos(a2) * rimR * 0.62, Math.sin(a2) * rimR * 0.62, s * (hw * 0.72 + 0.0105));
19110
+ const a2 = q / 12 * PI * 2, sl = new THREE.Mesh(G2.roundedBox(rimR * 0.42, 0.016, 6e-3, 2e-3), o.slot || CM("#1c1e21", { metalness: 0.5, roughness: 0.4 }));
19111
+ sl.position.set(Math.cos(a2) * rimR * 0.62, Math.sin(a2) * rimR * 0.62, s * (hw * 0.72 + 0.013));
19112
19112
  sl.rotation.z = a2;
19113
19113
  g.add(sl);
19114
19114
  }
@@ -24078,7 +24078,8 @@ var GameVehiclesThree = (() => {
24078
24078
  tailLightY: 2.06,
24079
24079
  noAntenna: true,
24080
24080
  hl: { style: "round", w: 0.2, h: 0.2, y: 2.03, in: 0.12, yaw: 0 },
24081
- grille: { style: "bars", w: 1, h: 0.3, y: 2 },
24081
+ /* the badge is this truck's foremost point: 9 mm back, where it was before its layers grew 7 mm and the grille came 2 mm ahead (the length the team measured) */
24082
+ grille: { style: "bars", w: 1, h: 0.3, y: 2, emblemBack: 9e-3 },
24082
24083
  tl: { style: "vertical", w: 0.12, h: 0.28, y: 2.06, in: 0 },
24083
24084
  interior: { rows: 1, col: "#202224", trim: "#141516", front: "bench" },
24084
24085
  hood: { motor: "v8" },
@@ -24145,13 +24146,13 @@ var GameVehiclesThree = (() => {
24145
24146
  label: x > 0 ? zs > 0 ? trl("labels.front_right_tire") : trl("labels.front_left_tire") : zs > 0 ? trl("labels.rear_right_tire") : trl("labels.rear_left_tire")
24146
24147
  });
24147
24148
  const rr = tr * 0.5, fz = zs * (ww / 2 - 0.05);
24148
- const disc = new THREE.Mesh(
24149
+ const disc2 = new THREE.Mesh(
24149
24150
  new THREE.CylinderGeometry(rr * 0.97, rr * 0.97, 0.03, 32),
24150
24151
  CM("#2b2e31", { metalness: 0.6, roughness: 0.35 })
24151
24152
  );
24152
- disc.rotation.x = PI / 2;
24153
- disc.position.z = fz;
24154
- wg.add(disc);
24153
+ disc2.rotation.x = PI / 2;
24154
+ disc2.position.z = fz;
24155
+ wg.add(disc2);
24155
24156
  const bead = new THREE.Mesh(new THREE.TorusGeometry(rr * 0.98, 0.04, 10, 40), rim);
24156
24157
  bead.position.z = fz + zs * 0.02;
24157
24158
  wg.add(bead);
@@ -28433,7 +28434,7 @@ var GameVehiclesThree = (() => {
28433
28434
  });
28434
28435
  return { acc, pruned };
28435
28436
  }
28436
- function liteMeshes(THREE, fusion, materials) {
28437
+ function liteMeshes(THREE, fusion, materials2) {
28437
28438
  const meshes = [];
28438
28439
  for (const name of LITE_CLASSES) {
28439
28440
  const A = fusion.acc[name];
@@ -28446,7 +28447,7 @@ var GameVehiclesThree = (() => {
28446
28447
  g.setIndex(A.nv > 65535 ? new THREE.Uint32BufferAttribute(A.I, 1) : new THREE.Uint16BufferAttribute(A.I, 1));
28447
28448
  g.computeBoundingBox();
28448
28449
  g.computeBoundingSphere();
28449
- let mt = materials[name];
28450
+ let mt = materials2[name];
28450
28451
  if (name === "plate") {
28451
28452
  mt = mt.clone();
28452
28453
  mt.map = A.map;
@@ -29158,7 +29159,7 @@ var GameVehiclesThree = (() => {
29158
29159
  warmup: WARMUP
29159
29160
  });
29160
29161
 
29161
- // ../game-shapes/dist/chunk-E3X7UDDV.js
29162
+ // ../game-shapes/dist/chunk-QETSTM6M.js
29162
29163
  function canonicalJson(value) {
29163
29164
  if (value === null) return "null";
29164
29165
  if (typeof value === "number") return Object.is(value, -0) ? "-0" : Number.isFinite(value) ? String(value) : JSON.stringify(String(value));
@@ -30933,7 +30934,7 @@ var GameVehiclesThree = (() => {
30933
30934
  }
30934
30935
  function collect(roots) {
30935
30936
  const geometries = /* @__PURE__ */ new Set();
30936
- const materials = /* @__PURE__ */ new Set();
30937
+ const materials2 = /* @__PURE__ */ new Set();
30937
30938
  const textures = /* @__PURE__ */ new Set();
30938
30939
  const skeletons = /* @__PURE__ */ new Set();
30939
30940
  for (const root of roots) {
@@ -30944,12 +30945,12 @@ var GameVehiclesThree = (() => {
30944
30945
  const list2 = Array.isArray(o.material) ? o.material : o.material ? [o.material] : [];
30945
30946
  for (const m of list2) {
30946
30947
  if (!m || typeof m.dispose !== "function") continue;
30947
- materials.add(m);
30948
+ materials2.add(m);
30948
30949
  texturesOf(m, textures);
30949
30950
  }
30950
30951
  });
30951
30952
  }
30952
- return { geometries, materials, textures, skeletons };
30953
+ return { geometries, materials: materials2, textures, skeletons };
30953
30954
  }
30954
30955
  var marked = /* @__PURE__ */ new WeakSet();
30955
30956
  var shared = (r) => r.userData?.shared === true || marked.has(r);
@@ -33749,6 +33750,7 @@ var GameVehiclesThree = (() => {
33749
33750
  kit.halo = halo;
33750
33751
  function lampKit(g, d, inner, lens, lensMat, refl) {
33751
33752
  refl = refl || MATERIALS.reflector;
33753
+ let nProj = 0;
33752
33754
  return {
33753
33755
  housing: function(w, h, y, z, geoFn) {
33754
33756
  const geo = roundedBoxGeometry(d, h, w, Math.min(0.03, h * 0.4));
@@ -33769,7 +33771,7 @@ var GameVehiclesThree = (() => {
33769
33771
  return m;
33770
33772
  },
33771
33773
  proj: function(y, z, r, mat) {
33772
- const bz = gm(g, new THREE.CylinderGeometry(r * 1.3, r * 1.45, 0.03, 18), refl, d / 2 - 0.03, y, z);
33774
+ const bz = gm(g, new THREE.CylinderGeometry(r * 1.3, r * 1.45, 0.03, 18), refl, d / 2 - 0.03 - nProj++ * 2e-3, y, z);
33773
33775
  bz.rotation.z = -PI / 2;
33774
33776
  if (refl !== MATERIALS.reflector) inner.push(bz);
33775
33777
  const e = gm(g, new THREE.SphereGeometry(r, 14, 10), mat, d / 2 - 0.022, y, z);
@@ -33949,10 +33951,10 @@ var GameVehiclesThree = (() => {
33949
33951
  (parent || c.vehicle).add(g);
33950
33952
  const d1 = gm(g, new THREE.CylinderGeometry(r, r, 0.012, 24), MATERIALS.chrome);
33951
33953
  d1.rotation.z = PI / 2;
33952
- const d2 = gm(g, new THREE.CylinderGeometry(r * 0.78, r * 0.78, 0.014, 24), MATERIALS.trim);
33954
+ const d2 = gm(g, new THREE.CylinderGeometry(r * 0.78, r * 0.78, 0.018, 24), MATERIALS.trim);
33953
33955
  d2.rotation.z = PI / 2;
33954
- gm(g, roundedBoxGeometry(0.016, r * 0.32, r * 1.4, 5e-3), MATERIALS.chrome);
33955
- gm(g, roundedBoxGeometry(0.016, r * 1, r * 0.22, 5e-3), MATERIALS.chrome, 0, 0, r * 0.25).rotation.x = 0.5;
33956
+ gm(g, roundedBoxGeometry(0.024, r * 0.32, r * 1.4, 5e-3), MATERIALS.chrome);
33957
+ gm(g, roundedBoxGeometry(0.03, r * 1, r * 0.22, 5e-3), MATERIALS.chrome, 0, 0, r * 0.25).rotation.x = 0.5;
33956
33958
  return g;
33957
33959
  };
33958
33960
  kit.grille = function(c, o) {
@@ -34005,7 +34007,7 @@ var GameVehiclesThree = (() => {
34005
34007
  g.children.forEach(function(m) {
34006
34008
  m.castShadow = true;
34007
34009
  });
34008
- if (o.emblem !== false) kit.emblem(c, 0.05, st === "closed" ? h * 0.12 : 0, 0, Math.min(0.05, h * 0.3), g);
34010
+ if (o.emblem !== false) kit.emblem(c, 0.05 - (o.emblemBack ?? 0), st === "closed" ? h * 0.12 : 0, 0, Math.min(0.05, h * 0.3), g);
34009
34011
  return g;
34010
34012
  };
34011
34013
  const shared2 = { lampGroup, gm, wedgeY, haloTex, glowTexture, haloMats, halo, lampKit };
@@ -34250,7 +34252,7 @@ var GameVehiclesThree = (() => {
34250
34252
  } else kit.seat(c, x, fl, 0, { w: zi * 2 - 0.1, n: r === 2 ? 2 : 3, mat: fab, back, lean, h: seatH * 0.95, role: "rear" });
34251
34253
  const trimLen = Math.min(0.8, (o.rowPitch ?? 0.88) - 0.06);
34252
34254
  [-1, 1].forEach(function(s) {
34253
- c.roundBox(trimLen, belt - fl - 0.08, 0.035, 0.015, trim, x + 0.12, (belt + fl) / 2 + 0.02, s * (zi + 0.02));
34255
+ c.roundBox(trimLen, belt - fl - 0.08, 0.035, 0.015, trim, x + 0.12, (belt + fl) / 2 + 0.02, s * (zi + 0.02 + r % 2 * 2e-3));
34254
34256
  c.roundBox(0.3, 0.05, 0.07, 0.02, fab, x + 0.16, fl + seatH + 0.16, s * (zi - 0.015));
34255
34257
  c.roundBox(0.08, 0.025, 0.02, 8e-3, MATERIALS.chrome, x + 0.36, belt - 0.11, s * (zi - 5e-3));
34256
34258
  });
@@ -34671,15 +34673,15 @@ var GameVehiclesThree = (() => {
34671
34673
  const cx = (x0 + x1) / 2;
34672
34674
  const paint = c.paint(o.col || c.meta.color || "#666");
34673
34675
  const out = {};
34674
- c.roundBox(L, 0.03, 2 * zw, 0.01, MATERIALS.bay, cx, fl, 0);
34676
+ c.roundBox(L - 0.03, 0.03, 2 * zw, 0.01, MATERIALS.bay, cx + 0.015, fl, 0);
34675
34677
  c.roundBox(0.03, H + 0.04, 2 * zw, 0.01, MATERIALS.bay, x0 + 0.015, fl + H / 2, 0);
34676
34678
  [1, -1].forEach(function(s) {
34677
- c.roundBox(L, H * 0.75, 0.03, 0.01, MATERIALS.bay, cx, fl + H * 0.37, s * zw);
34679
+ c.roundBox(L - 0.034, H * 0.75, 0.03, 0.01, MATERIALS.bay, x0 + 0.03 + (L - 0.034) / 2, fl + H * 0.37, s * zw);
34678
34680
  });
34679
34681
  const rx = x1 - 0.06;
34680
34682
  const rh = H * 0.82;
34681
34683
  const rad = c.roundBox(0.05, rh, zw * 1.5, 0.012, MATERIALS.radiator, rx, fl + rh / 2 + 0.02, 0);
34682
- for (let f = 0; f < 6; f++) c.roundBox(0.054, 6e-3, zw * 1.46, 2e-3, MATERIALS.steel, rx, fl + 0.06 + f * (rh - 0.06) / 6, 0);
34684
+ for (let f = 0; f < 6; f++) c.roundBox(0.062, 6e-3, zw * 1.46, 2e-3, MATERIALS.steel, rx, fl + 0.06 + f * (rh - 0.06) / 6, 0);
34683
34685
  c.roundBox(0.07, 0.04, zw * 1.5, 0.015, MATERIALS.plastic, rx, fl + rh + 0.03, 0);
34684
34686
  out.rad = new V3(rx, fl + rh / 2, 0);
34685
34687
  const fanR = Math.min(rh * 0.42, zw * 0.45);
@@ -34718,8 +34720,9 @@ var GameVehiclesThree = (() => {
34718
34720
  }
34719
34721
  function battery(x, y, z, sc) {
34720
34722
  sc = sc || 1;
34723
+ x = Math.max(x, x0 + 0.034 + 0.1 * sc);
34721
34724
  c.roundBox(0.2 * sc, 0.15 * sc, 0.15 * sc, 0.015, makeMaterial("#1a1b1c", { roughness: 0.5 }), x, y, z);
34722
- c.roundBox(0.2 * sc, 0.012, 0.15 * sc, 5e-3, makeMaterial("#2e3a6a", { roughness: 0.5 }), x, y + 0.04 * sc, z);
34725
+ c.roundBox(0.2 * sc + 8e-3, 0.012, 0.15 * sc + 8e-3, 5e-3, makeMaterial("#2e3a6a", { roughness: 0.5 }), x, y + 0.04 * sc, z);
34723
34726
  c.cylinder(0.016, 0.018, 0.03, MATERIALS.postRed, x + 0.06 * sc, y + 0.09 * sc, z + 0.045 * sc);
34724
34727
  c.cylinder(0.016, 0.018, 0.03, MATERIALS.postBlack, x + 0.06 * sc, y + 0.09 * sc, z - 0.045 * sc);
34725
34728
  c.tube(
@@ -34738,7 +34741,7 @@ var GameVehiclesThree = (() => {
34738
34741
  reservoir(x0 + 0.12, uy - 0.04, -zw * 0.55, 0.07, 0.06, 0.07, MATERIALS.coolant, makeMaterial("#c9b26a", { roughness: 0.3 }), MATERIALS.yellow);
34739
34742
  reservoir(x1 - 0.2, fl + H * 0.45, zw * 0.72, 0.12, 0.13, 0.1, MATERIALS.washer, makeMaterial("#3f8fc0", { roughness: 0.3 }), MATERIALS.capBlue);
34740
34743
  c.roundBox(0.12, 0.07, 0.13, 0.015, MATERIALS.plastic, x0 + 0.18, uy - 0.02, -zw * 0.78);
34741
- c.roundBox(0.12, 6e-3, 0.13, 3e-3, MATERIALS.dark, x0 + 0.18, uy + 0.017, -zw * 0.78);
34744
+ c.roundBox(0.116, 6e-3, 0.126, 3e-3, MATERIALS.dark, x0 + 0.18, uy + 0.017, -zw * 0.78);
34742
34745
  if (mot === "electric") {
34743
34746
  const fx0 = x0 + L * 0.4;
34744
34747
  const fx1 = x1 - 0.14;
@@ -34891,7 +34894,7 @@ var GameVehiclesThree = (() => {
34891
34894
  const afx = x1 - L * 0.32;
34892
34895
  const afy = Math.min(top - 0.07, fl + H * 0.7);
34893
34896
  c.roundBox(0.22, 0.1, 0.26, 0.03, MATERIALS.plastic, afx, afy, zw * 0.5);
34894
- c.roundBox(0.22, 0.012, 0.26, 4e-3, MATERIALS.dark, afx, afy + 0.01, zw * 0.5);
34897
+ c.roundBox(0.224, 0.012, 0.264, 4e-3, MATERIALS.dark, afx, afy + 0.01, zw * 0.5);
34895
34898
  c.tube(
34896
34899
  [
34897
34900
  [afx - 0.11, afy, zw * 0.4],
@@ -35229,7 +35232,7 @@ var GameVehiclesThree = (() => {
35229
35232
  const gr = Object.assign({ style: "bars", w: W * 0.44, h: Math.max(0.08, hy - bumperY - 0.12) }, s.grille || {});
35230
35233
  const gy = gr.y || (bumperY + hy) / 2 + 0.02;
35231
35234
  const gx = I.profX(it, gy, true);
35232
- kit.grille(c, { style: gr.style, x: gx + 0.025, y: gy, w: gr.w, h: gr.h, col: s.col, emblem: gr.emblem });
35235
+ kit.grille(c, { style: gr.style, x: gx + 0.027, y: gy, w: gr.w, h: gr.h, col: s.col, emblem: gr.emblem, emblemBack: gr.emblemBack });
35233
35236
  } else kit.emblem(c, I.profX(it, hy + 0.02, true) + 0.055, hy + 0.02, 0, 0.04);
35234
35237
  const tl = Object.assign({ style: "wrap", w: s.tailW || 0.3, h: s.tailH || 0.14, in: 0.05 }, s.tl || {});
35235
35238
  const ty = tl.y || s.tailLightY || s.tailY - 0.05;
@@ -42216,8 +42219,8 @@ var GameVehiclesThree = (() => {
42216
42219
  };
42217
42220
  }
42218
42221
  kit.lodHiddenMaterials = function() {
42219
- const materials = kit.materials;
42220
- return new Set(lod.hiddenMaterials.map((name) => materials[name]).filter(Boolean));
42222
+ const materials2 = kit.materials;
42223
+ return new Set(lod.hiddenMaterials.map((name) => materials2[name]).filter(Boolean));
42221
42224
  };
42222
42225
  }
42223
42226
  var defaultDamageableKinds = {
@@ -42543,6 +42546,50 @@ var GameVehiclesThree = (() => {
42543
42546
  (plugins || []).forEach(kit.plugin);
42544
42547
  return kit;
42545
42548
  }
42549
+ var GOUGE_COS = 0.45;
42550
+ var RIFLE_SPEED = 600;
42551
+ var RIFLE_ENERGY_DENSITY = 35;
42552
+ var HEAVY_CALIBER_MM = 12;
42553
+ var LONGEST_GOUGE = 4;
42554
+ var SHORTEST_GOUGE = 1.5;
42555
+ var SHEET_METALS = /* @__PURE__ */ new Set(["steel", "aluminium"]);
42556
+ function speedOf(input) {
42557
+ const mass = input.massGrams;
42558
+ if (!mass || mass <= 0 || input.energy <= 0) return void 0;
42559
+ return Math.sqrt(2 * input.energy / (mass / 1e3));
42560
+ }
42561
+ function isRifleRound(input) {
42562
+ const speed = speedOf(input);
42563
+ if (speed !== void 0) return speed >= RIFLE_SPEED;
42564
+ const area3 = Math.PI * (input.caliberMm / 2) ** 2;
42565
+ return area3 > 0 && input.energy / area3 >= RIFLE_ENERGY_DENSITY;
42566
+ }
42567
+ function holeStyleOf(input) {
42568
+ const sheet = SHEET_METALS.has(input.material);
42569
+ if (sheet && input.cosIncidence < GOUGE_COS) return "gouge";
42570
+ if (!input.through) return "dimple";
42571
+ if (input.caliberMm >= HEAVY_CALIBER_MM) return "ragged";
42572
+ return sheet && isRifleRound(input) ? "petalled" : "round";
42573
+ }
42574
+ function bulletHoleShape(input) {
42575
+ const style = holeStyleOf(input);
42576
+ const bore = Math.max(3e-3, input.boreDiameter);
42577
+ const caliber = input.caliberMm / 1e3;
42578
+ switch (style) {
42579
+ case "gouge": {
42580
+ const elongation = Math.min(LONGEST_GOUGE, Math.max(SHORTEST_GOUGE, 1 / Math.max(input.cosIncidence, 0.05)));
42581
+ return { style, boreDiameter: input.through ? bore * 0.6 : 0, markDiameter: caliber * 1.8, dentDepth: caliber * 0.12, elongation, petals: 0 };
42582
+ }
42583
+ case "dimple":
42584
+ return { style, boreDiameter: 0, markDiameter: caliber * 1.9, dentDepth: caliber * 0.25, elongation: 1, petals: 0 };
42585
+ case "ragged":
42586
+ return { style, boreDiameter: bore * 1.15, markDiameter: bore * 2.6, dentDepth: caliber * 0.35, elongation: 1, petals: 7 };
42587
+ case "petalled":
42588
+ return { style, boreDiameter: bore, markDiameter: bore * 3.4, dentDepth: caliber * 0.18, elongation: 1, petals: 5 };
42589
+ default:
42590
+ return { style, boreDiameter: bore, markDiameter: bore * 2.2, dentDepth: caliber * 0.15, elongation: 1, petals: 0 };
42591
+ }
42592
+ }
42546
42593
  var END_DEPTH = 0.45;
42547
42594
  var LAMP_EMISSIVE_MIN = 0.25;
42548
42595
  var LAMP_INTENSITY_MIN = 0.2;
@@ -42722,6 +42769,24 @@ var GameVehiclesThree = (() => {
42722
42769
  if (meta.armor === "IIIA" || meta.armor === "III") return meta.armor;
42723
42770
  return meta.armored || meta.bullet ? "III" : null;
42724
42771
  }
42772
+ var SUPPORT_BAND_M = 0.12;
42773
+ function supportSpanOf(vehicle, inverse) {
42774
+ const boxes = [];
42775
+ vehicle.traverse((node) => {
42776
+ const mesh2 = node;
42777
+ if (!mesh2.isMesh || mesh2.userData.decal || !mesh2.geometry) return;
42778
+ mesh2.geometry.computeBoundingBox();
42779
+ const bounds = mesh2.geometry.boundingBox;
42780
+ if (!bounds) return;
42781
+ const box2 = bounds.clone().applyMatrix4(mesh2.matrixWorld).applyMatrix4(inverse);
42782
+ if (box2.isEmpty()) return;
42783
+ boxes.push({ minX: box2.min.x, maxX: box2.max.x, minY: box2.min.y });
42784
+ });
42785
+ if (boxes.length === 0) return void 0;
42786
+ const ground = Math.min(...boxes.map((box2) => box2.minY));
42787
+ const resting = boxes.filter((box2) => box2.minY <= ground + SUPPORT_BAND_M);
42788
+ return { rear: Math.min(...resting.map((box2) => box2.minX)), front: Math.max(...resting.map((box2) => box2.maxX)) };
42789
+ }
42725
42790
  var JOINT_RULES = {
42726
42791
  hinge: { strength: 5e3, tools: ["wrench", "screwdriver"], seconds: 3 },
42727
42792
  bolt: { strength: 3e3, tools: ["wrench"], seconds: 4 },
@@ -43000,12 +43065,15 @@ var GameVehiclesThree = (() => {
43000
43065
  }
43001
43066
  if (!hubZone) {
43002
43067
  const h = Math.max(0.15, belt - clearance);
43068
+ const box2 = floorPan({ center: [(F + R) / 2, clearance + h * 0.45, 0], size: [Math.max(0.4, L * 0.8), h * 0.7, Math.max(0.2, W * 0.9)] });
43069
+ const support = supportSpanOf(c.vehicle, inverse);
43003
43070
  add2({
43004
43071
  id: hubId,
43005
43072
  role: "frame",
43006
43073
  name: t("mechanics.chassis"),
43007
43074
  material: "steel",
43008
- box: floorPan({ center: [(F + R) / 2, clearance + h * 0.45, 0], size: [Math.max(0.4, L * 0.8), h * 0.7, Math.max(0.2, W * 0.9)] }),
43075
+ box: box2,
43076
+ ...support ? { massCentre: [(support.front + support.rear) / 2, box2.center[1], box2.center[2]] } : {},
43009
43077
  mass: mass * 0.25,
43010
43078
  hp: 15e4 * armour,
43011
43079
  visual: false,
@@ -43598,7 +43666,182 @@ var GameVehiclesThree = (() => {
43598
43666
  }
43599
43667
  return [tub, seal];
43600
43668
  }
43601
- var HOLE_DECAL_SCALE = 2.4;
43669
+ var TEXTURE_SIZE = 128;
43670
+ var DISC_RINGS = [0, 0.18, 0.34, 0.5, 0.66, 0.82, 1];
43671
+ var DISC_SPOKES = 24;
43672
+ var BOWL_LEAN = 0.85;
43673
+ var BOWL_REACH = 0.9;
43674
+ var BARE = { steel: "#a9aeb2", aluminium: "#cfd3d6", plastic: "#d9d6cc", rubber: "#141414", glass: "#eef3f5" };
43675
+ var STEEL_BARE = "#a9aeb2";
43676
+ var PRIMER = "#7d8285";
43677
+ var PETAL_TIP = 0.62;
43678
+ var PETAL_WIDTH = 0.42;
43679
+ var PETAL_SHADE = "#6f7478";
43680
+ var BORE_SHARE = { round: 0.45, petalled: 0.3, ragged: 0.44, dimple: 0, gouge: 0.2 };
43681
+ var materials = /* @__PURE__ */ new WeakMap();
43682
+ var disc = null;
43683
+ function holeMarkGeometry(THREE) {
43684
+ if (disc) return disc;
43685
+ const positions = [];
43686
+ const normals = [];
43687
+ const uvs = [];
43688
+ for (const r of DISC_RINGS) {
43689
+ const spokes = r === 0 ? 1 : DISC_SPOKES;
43690
+ const lean = r > 0 && r < BOWL_REACH ? BOWL_LEAN * Math.sin(Math.PI * r / BOWL_REACH) / r : 0;
43691
+ for (let k = 0; k < spokes; k++) {
43692
+ const a = k / DISC_SPOKES * Math.PI * 2;
43693
+ const x = Math.cos(a) * r;
43694
+ const y = Math.sin(a) * r;
43695
+ const n = new THREE.Vector3(-x * lean, -y * lean, 1).normalize();
43696
+ positions.push(x, y, 0);
43697
+ normals.push(n.x, n.y, n.z);
43698
+ uvs.push(0.5 + x / 2, 0.5 + y / 2);
43699
+ }
43700
+ }
43701
+ const geometry = new THREE.BufferGeometry();
43702
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
43703
+ geometry.setAttribute("normal", new THREE.Float32BufferAttribute(normals, 3));
43704
+ geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
43705
+ geometry.setIndex(discIndices());
43706
+ disc = geometry;
43707
+ return geometry;
43708
+ }
43709
+ function discIndices() {
43710
+ const indices = [];
43711
+ const start2 = (ring2) => 1 + (ring2 - 1) * DISC_SPOKES;
43712
+ for (let k = 0; k < DISC_SPOKES; k++) indices.push(0, start2(1) + k, start2(1) + (k + 1) % DISC_SPOKES);
43713
+ for (let ring2 = 1; ring2 < DISC_RINGS.length - 1; ring2++) {
43714
+ for (let k = 0; k < DISC_SPOKES; k++) {
43715
+ const a = start2(ring2) + k;
43716
+ const b = start2(ring2) + (k + 1) % DISC_SPOKES;
43717
+ const c = start2(ring2 + 1) + k;
43718
+ const d = start2(ring2 + 1) + (k + 1) % DISC_SPOKES;
43719
+ indices.push(a, c, d, a, d, b);
43720
+ }
43721
+ }
43722
+ return indices;
43723
+ }
43724
+ function jagged(x, options) {
43725
+ const mid = TEXTURE_SIZE / 2;
43726
+ x.beginPath();
43727
+ for (let i = 0; i <= options.points; i++) {
43728
+ const a = i / options.points * Math.PI * 2;
43729
+ const wobble = Math.sin(i * 12.9898 + options.seed * 78.233) * 43758.5453;
43730
+ const r = mid * options.radius * (1 - options.jag + 2 * options.jag * (wobble - Math.floor(wobble)));
43731
+ x.lineTo(mid + Math.cos(a) * r, mid + Math.sin(a) * r);
43732
+ }
43733
+ x.closePath();
43734
+ }
43735
+ function drawBore(x, share, bare) {
43736
+ const mid = TEXTURE_SIZE / 2;
43737
+ const r = mid * share;
43738
+ const wall = x.createRadialGradient(mid, mid, 0, mid, mid, r);
43739
+ wall.addColorStop(0, "#000000");
43740
+ wall.addColorStop(0.6, "#050505");
43741
+ wall.addColorStop(1, "#2a2b2c");
43742
+ x.fillStyle = wall;
43743
+ x.beginPath();
43744
+ x.arc(mid, mid, r, 0, Math.PI * 2);
43745
+ x.fill();
43746
+ x.strokeStyle = bare;
43747
+ x.lineWidth = Math.max(1, mid * 0.05);
43748
+ x.beginPath();
43749
+ x.arc(mid, mid, r, 0, Math.PI * 2);
43750
+ x.stroke();
43751
+ }
43752
+ function drawPetals(x, share, petals) {
43753
+ const mid = TEXTURE_SIZE / 2;
43754
+ x.fillStyle = PETAL_SHADE;
43755
+ for (let i = 0; i < petals; i++) {
43756
+ const a = i / petals * Math.PI * 2 + 0.4;
43757
+ const half = Math.PI / petals * PETAL_WIDTH;
43758
+ x.beginPath();
43759
+ x.moveTo(mid + Math.cos(a - half) * mid * share, mid + Math.sin(a - half) * mid * share);
43760
+ x.lineTo(mid + Math.cos(a) * mid * share * PETAL_TIP, mid + Math.sin(a) * mid * share * PETAL_TIP);
43761
+ x.lineTo(mid + Math.cos(a + half) * mid * share, mid + Math.sin(a + half) * mid * share);
43762
+ x.closePath();
43763
+ x.fill();
43764
+ }
43765
+ }
43766
+ function drawRing(x, material, style) {
43767
+ const mid = TEXTURE_SIZE / 2;
43768
+ const bare = BARE[material] ?? STEEL_BARE;
43769
+ const share = BORE_SHARE[style];
43770
+ if (material === "steel" || material === "aluminium") {
43771
+ x.fillStyle = PRIMER;
43772
+ jagged(x, { radius: style === "petalled" ? 0.9 : 0.86, jag: 0.12, points: 22, seed: style.length });
43773
+ x.fill();
43774
+ }
43775
+ x.fillStyle = bare;
43776
+ jagged(x, { radius: Math.max(share + 0.18, style === "dimple" ? 0.55 : 0.6), jag: 0.08, points: 18, seed: style.length + 3 });
43777
+ x.fill();
43778
+ x.strokeStyle = "rgba(70, 72, 74, 0.55)";
43779
+ x.lineWidth = 1;
43780
+ for (let i = 0; i < 14; i++) {
43781
+ const a = i / 14 * Math.PI * 2 + 0.2;
43782
+ x.beginPath();
43783
+ x.moveTo(mid + Math.cos(a) * mid * (share + 0.05), mid + Math.sin(a) * mid * (share + 0.05));
43784
+ x.lineTo(mid + Math.cos(a) * mid * (share + 0.2), mid + Math.sin(a) * mid * (share + 0.2));
43785
+ x.stroke();
43786
+ }
43787
+ }
43788
+ function drawDimple(x) {
43789
+ const mid = TEXTURE_SIZE / 2;
43790
+ const hollow = x.createRadialGradient(mid * 0.92, mid * 0.92, 0, mid, mid, mid * 0.4);
43791
+ hollow.addColorStop(0, "#3c3e40");
43792
+ hollow.addColorStop(1, "rgba(60, 62, 64, 0)");
43793
+ x.fillStyle = hollow;
43794
+ x.beginPath();
43795
+ x.arc(mid, mid, mid * 0.4, 0, Math.PI * 2);
43796
+ x.fill();
43797
+ }
43798
+ function drawCrease(x) {
43799
+ const mid = TEXTURE_SIZE / 2;
43800
+ const crease = x.createLinearGradient(0, mid * 0.75, 0, mid * 1.25);
43801
+ crease.addColorStop(0, "rgba(20, 20, 20, 0)");
43802
+ crease.addColorStop(0.5, "#141414");
43803
+ crease.addColorStop(1, "rgba(20, 20, 20, 0)");
43804
+ x.fillStyle = crease;
43805
+ x.fillRect(mid * 0.15, mid * 0.75, mid * 1.7, mid * 0.5);
43806
+ }
43807
+ function drawMark(x, material, style) {
43808
+ const bare = BARE[material] ?? STEEL_BARE;
43809
+ const share = BORE_SHARE[style];
43810
+ drawRing(x, material, style);
43811
+ if (style === "dimple") return drawDimple(x);
43812
+ if (style === "gouge") drawCrease(x);
43813
+ drawBore(x, share, bare);
43814
+ if (style === "petalled") drawPetals(x, share, 5);
43815
+ if (style !== "ragged") return;
43816
+ x.fillStyle = "#030303";
43817
+ jagged(x, { radius: share, jag: 0.22, points: 11, seed: 7 });
43818
+ x.fill();
43819
+ drawPetals(x, share, 7);
43820
+ }
43821
+ function holeMarkMaterial(kit, material, style) {
43822
+ const key = kit;
43823
+ const cache2 = materials.get(key) ?? /* @__PURE__ */ new Map();
43824
+ materials.set(key, cache2);
43825
+ const id = `${material}|${style}`;
43826
+ const known = cache2.get(id);
43827
+ if (known) return known;
43828
+ const shared2 = kit._;
43829
+ const THREE = kit.THREE;
43830
+ const canvas = kit.document?.createElement?.("canvas");
43831
+ const context = canvas?.getContext?.("2d");
43832
+ let made = shared2.MATERIALS.dark;
43833
+ if (canvas && context) {
43834
+ canvas.width = canvas.height = TEXTURE_SIZE;
43835
+ drawMark(context, material, style);
43836
+ const map = new THREE.CanvasTexture(canvas);
43837
+ const metal = material === "steel" || material === "aluminium";
43838
+ made = new THREE.MeshStandardMaterial({ map, transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -1, polygonOffsetUnits: -2, roughness: 0.5, metalness: metal ? 0.55 : 0 });
43839
+ }
43840
+ cache2.set(id, made);
43841
+ return made;
43842
+ }
43843
+ var HOLE_LIFT = 1e-3;
43844
+ var HOLE_MIN_MARK = 4e-3;
43602
43845
  var HOLE_BATCH_CAPACITY = 64;
43603
43846
  var DOOR_DEPTH = 0.07;
43604
43847
  var DOOR_SKIN_DEPTH = 0.09;
@@ -43621,7 +43864,6 @@ var GameVehiclesThree = (() => {
43621
43864
  var DOOR_SILL = 0.25;
43622
43865
  var DOOR_STRIP_OVER = 0.05;
43623
43866
  var DOOR_TOP_OVER_PANE = 0.03;
43624
- var HOLE_TEXTURE_SIZE = 64;
43625
43867
  var LAMP_BOX_MARGIN = 0.03;
43626
43868
  var GLOW_MIN_EMISSIVE = 0.05;
43627
43869
  var MIRROR_MIN_METALNESS = 0.8;
@@ -43674,46 +43916,6 @@ var GameVehiclesThree = (() => {
43674
43916
  var SIDEWALL_SHARE = 0.3;
43675
43917
  var MIRROR_GLASS_MIN = 0.05;
43676
43918
  var MIRROR_GLASS_COLOR = "#59636a";
43677
- var HOLE_RIM = { steel: "#b7bcc0", aluminium: "#d3d6d8", plastic: "#d9d6cc", rubber: "#141414", glass: "#eef3f5" };
43678
- var holeMaterials = /* @__PURE__ */ new WeakMap();
43679
- var holeDisc = null;
43680
- function holeDiscGeometry(THREE) {
43681
- holeDisc = holeDisc ?? new THREE.CircleGeometry(1, 12);
43682
- return holeDisc;
43683
- }
43684
- function holeMaterial(kit, material) {
43685
- const key = kit;
43686
- const cache2 = holeMaterials.get(key) ?? /* @__PURE__ */ new Map();
43687
- holeMaterials.set(key, cache2);
43688
- const known = cache2.get(material);
43689
- if (known) return known;
43690
- const I = kit._;
43691
- const THREE = kit.THREE;
43692
- const canvas = kit.document?.createElement?.("canvas");
43693
- const x = canvas?.getContext?.("2d");
43694
- let made = I.MATERIALS.dark;
43695
- if (x) {
43696
- canvas.width = canvas.height = HOLE_TEXTURE_SIZE;
43697
- const mid = HOLE_TEXTURE_SIZE / 2;
43698
- x.fillStyle = HOLE_RIM[material] ?? HOLE_RIM.steel;
43699
- x.beginPath();
43700
- for (let i = 0; i < 18; i++) {
43701
- const a = i / 18 * Math.PI * 2;
43702
- const r = mid * (i % 2 ? 0.98 : 0.76);
43703
- x.lineTo(mid + Math.cos(a) * r, mid + Math.sin(a) * r);
43704
- }
43705
- x.closePath();
43706
- x.fill();
43707
- x.fillStyle = "#050505";
43708
- x.beginPath();
43709
- x.arc(mid, mid, mid * 0.42, 0, Math.PI * 2);
43710
- x.fill();
43711
- const map = new THREE.CanvasTexture(canvas);
43712
- made = new THREE.MeshStandardMaterial({ map, transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, roughness: 0.55, metalness: material === "steel" || material === "aluminium" ? 0.6 : 0 });
43713
- }
43714
- cache2.set(material, made);
43715
- return made;
43716
- }
43717
43919
  function isGlowing(material) {
43718
43920
  const { emissive, emissiveIntensity } = material;
43719
43921
  return !!emissive && (emissiveIntensity ?? 0) > 0 && emissive.r + emissive.g + emissive.b >= GLOW_MIN_EMISSIVE;
@@ -44731,31 +44933,24 @@ var GameVehiclesThree = (() => {
44731
44933
  this.extra.set(p.id, [g]);
44732
44934
  }
44733
44935
  // ---- marks -------------------------------------------------------------------------------------------------------------------------------
44734
- /** A bullet hole: a dark disc lying on the surface at `point` (`c.vehicle` coordinates). */
44735
- holeDecal(point, normal, diameter, part) {
44936
+ /**
44937
+ * A bullet mark lying on the panel at `point` (`c.vehicle` coordinates), facing out along `normal`: its look and size come from `shape` (`bulletHoleShape`), its
44938
+ * long axis lies along `along` (the round's path) over the panel, and it is a child of the part's carrier so it goes where the panel goes.
44939
+ */
44940
+ holeDecal(point, normal, shape, part, along) {
44736
44941
  const THREE = this.THREE;
44737
44942
  const pane = part?.role === "glass" ? this.panesOf(part).find((g) => g.visible) : void 0;
44738
44943
  if (part?.role === "glass" && (!pane || pane.userData.glass?.broken)) return;
44739
- const radius = Math.max(6e-3, diameter / 2) * HOLE_DECAL_SCALE;
44740
- const n = new THREE.Vector3(...normal);
44944
+ const across = Math.max(HOLE_MIN_MARK, shape.markDiameter) / 2;
44945
+ const n = new THREE.Vector3(...normal).normalize();
44741
44946
  const carrier = (part && (this.plates.get(part.id) ?? (part.id === this.hood?.id ? this.c.hood?.piv : void 0))) ?? (pane && pane.parent !== this.c.vehicle ? pane.parent : null);
44742
44947
  const parent = carrier ?? this.c.vehicle;
44743
- const material = holeMaterial(this.kit, part?.material ?? "steel");
44948
+ const material = holeMarkMaterial(this.kit, part?.material ?? "steel", shape.style);
44744
44949
  const key = `${parent.uuid}|${material.uuid}`;
44745
44950
  let batches = this.holes.get(key);
44746
44951
  let batch = batches?.[batches.length - 1];
44747
44952
  if (!batch || batch.count >= HOLE_BATCH_CAPACITY) {
44748
- batch = new THREE.InstancedMesh(holeDiscGeometry(THREE), material, HOLE_BATCH_CAPACITY);
44749
- batch.count = 0;
44750
- batch.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
44751
- batch.castShadow = false;
44752
- batch.receiveShadow = false;
44753
- batch.userData.decal = true;
44754
- batch.userData.noFollow = true;
44755
- batch.renderOrder = 3;
44756
- batch.raycast = () => {
44757
- };
44758
- batch.frustumCulled = false;
44953
+ batch = this.holeBatch(material);
44759
44954
  parent.add(batch);
44760
44955
  if (!batches) {
44761
44956
  batches = [];
@@ -44763,19 +44958,33 @@ var GameVehiclesThree = (() => {
44763
44958
  }
44764
44959
  batches.push(batch);
44765
44960
  }
44766
- const at = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 3e-3));
44767
- const toward = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 1.003));
44768
- const pose = new THREE.Object3D();
44769
- pose.position.copy(at);
44770
- pose.scale.set(radius, radius, 1);
44771
- pose.lookAt(toward);
44772
- pose.updateMatrix();
44961
+ const u = new THREE.Vector3(...along ?? [0, 0, 0]).addScaledVector(n, -new THREE.Vector3(...along ?? [0, 0, 0]).dot(n));
44962
+ if (u.lengthSq() < 1e-8) u.crossVectors(n, Math.abs(n.y) < 0.9 ? new THREE.Vector3(0, 1, 0) : new THREE.Vector3(1, 0, 0));
44963
+ u.normalize();
44964
+ const w = new THREE.Vector3().crossVectors(n, u);
44965
+ const at = new THREE.Vector3(...point).addScaledVector(n, HOLE_LIFT);
44966
+ const local = new THREE.Matrix4().makeBasis(u.multiplyScalar(across * shape.elongation), w.multiplyScalar(across), n).setPosition(at);
44773
44967
  parent.updateWorldMatrix(true, false);
44774
- const instance = new THREE.Matrix4().copy(parent.matrixWorld).invert().multiply(pose.matrix);
44968
+ const instance = new THREE.Matrix4().copy(parent.matrixWorld).invert().multiply(this.c.vehicle.matrixWorld).multiply(local);
44775
44969
  batch.setMatrixAt(batch.count, instance);
44776
44970
  batch.count += 1;
44777
44971
  batch.instanceMatrix.needsUpdate = true;
44778
44972
  }
44973
+ /** A new batch of marks of one material (a door full of holes still draws as one). */
44974
+ holeBatch(material) {
44975
+ const batch = new this.THREE.InstancedMesh(holeMarkGeometry(this.THREE), material, HOLE_BATCH_CAPACITY);
44976
+ batch.count = 0;
44977
+ batch.instanceMatrix.setUsage(this.THREE.DynamicDrawUsage);
44978
+ batch.castShadow = false;
44979
+ batch.receiveShadow = false;
44980
+ batch.userData.decal = true;
44981
+ batch.userData.noFollow = true;
44982
+ batch.renderOrder = 3;
44983
+ batch.raycast = () => {
44984
+ };
44985
+ batch.frustumCulled = false;
44986
+ return batch;
44987
+ }
44779
44988
  /** The door or lid a hinge group stands for. */
44780
44989
  /** The part a separately drawn piece stands for (a mirror on the door, a battery under the hood), so a shot at it lands on that part. */
44781
44990
  extraIdOf(o) {
@@ -45213,6 +45422,44 @@ var GameVehiclesThree = (() => {
45213
45422
  pair("trunk", lid, "trunk");
45214
45423
  return clips;
45215
45424
  }
45425
+ var MARK_PROBE = 0.02;
45426
+ var MARK_FALL = 2e-3;
45427
+ var MARK_RISE = 15e-4;
45428
+ var MARK_RIM_SAMPLES = 12;
45429
+ var MARK_SHRINK = 0.7;
45430
+ var MARK_FIT_TRIES = 7;
45431
+ function createMarkFitter(deps) {
45432
+ const axesOf2 = (n, along) => {
45433
+ const u = along.clone().addScaledVector(n, -along.dot(n));
45434
+ if (u.lengthSq() < 1e-8) u.crossVectors(n, Math.abs(n.y) < 0.9 ? deps.vector(0, 1, 0) : deps.vector(1, 0, 0));
45435
+ u.normalize();
45436
+ return { u, w: deps.vector(0, 0, 0).crossVectors(n, u).normalize() };
45437
+ };
45438
+ const rimOnSurface = (at, axes, half) => {
45439
+ const inward = deps.dirToWorld(at.normal.clone().negate());
45440
+ for (let k = 0; k < MARK_RIM_SAMPLES; k++) {
45441
+ const a = k / MARK_RIM_SAMPLES * Math.PI * 2;
45442
+ const q = at.point.clone().addScaledVector(axes.u, Math.cos(a) * half.along).addScaledVector(axes.w, Math.sin(a) * half.across).addScaledVector(at.normal, MARK_PROBE);
45443
+ const hit = deps.surfaceRay({ origin: deps.toWorld(q), direction: inward, maxDistance: MARK_PROBE * 2 });
45444
+ const fall = hit ? hit.distance - MARK_PROBE : Infinity;
45445
+ if (fall > MARK_FALL || fall < -MARK_RISE) return false;
45446
+ }
45447
+ return true;
45448
+ };
45449
+ return (shape, at) => {
45450
+ const placed = { ...at, normal: at.normal.clone().normalize() };
45451
+ const axes = axesOf2(placed.normal, at.along);
45452
+ let scale = 1;
45453
+ for (let tries = 0; tries < MARK_FIT_TRIES; tries++) {
45454
+ const across = shape.markDiameter / 2 * scale;
45455
+ if (rimOnSurface(placed, axes, { along: across * shape.elongation, across })) break;
45456
+ scale *= MARK_SHRINK;
45457
+ }
45458
+ if (scale === 1) return shape;
45459
+ const markDiameter = shape.markDiameter * scale;
45460
+ return { ...shape, markDiameter, boreDiameter: Math.min(shape.boreDiameter, markDiameter * 0.8) };
45461
+ };
45462
+ }
45216
45463
  var RESIST = { steel: 380, aluminium: 220, glass: 90, plastic: 70, rubber: 120 };
45217
45464
  var ROLE_RESIST = {
45218
45465
  frame: 6,
@@ -45727,6 +45974,8 @@ var GameVehiclesThree = (() => {
45727
45974
  if (near && igniteRand() < 1 - Math.exp(-chancePerSecond * dt)) light(tank, out);
45728
45975
  };
45729
45976
  const normalOf = (d, v) => faceNormal(d, v);
45977
+ const fitter = createMarkFitter({ vector: (x, y, z) => new V3(x, y, z), surfaceRay: (ray) => surfaceRay(ray), toWorld, dirToWorld });
45978
+ const fitMark = (v, n, shape, along) => vis ? fitter(shape, { point: v, normal: n, along }) : shape;
45730
45979
  const ballistic = (h, out) => {
45731
45980
  sync();
45732
45981
  const M = toFrameMatrix();
@@ -45744,15 +45993,17 @@ var GameVehiclesThree = (() => {
45744
45993
  const cosInc = Math.abs(dir.dot(n));
45745
45994
  const metal = d.material === "steel" || d.material === "aluminium";
45746
45995
  const worldPoint = toWorld(v);
45996
+ const opens = (h.piercing ?? 1) < SOFT_LEAD ? EXPANDED_HOLE : 1;
45997
+ const holeDiam = Math.max(6e-3, cal / 1e3 * (d.material === "glass" ? 1.4 : 1) * opens);
45998
+ const shapeOf = (pierced) => bulletHoleShape({ caliberMm: cal, energy: E, ...h.mass !== void 0 ? { massGrams: h.mass } : {}, cosIncidence: cosInc, through: pierced, material: d.material, boreDiameter: holeDiam });
45747
45999
  if (metal && !through && cosInc < 0.3 && E > 40) {
45748
46000
  const refl = dir.clone().addScaledVector(n, -2 * dir.dot(n));
45749
46001
  out.push(ev({ type: "ricochet", part: d.id, point: worldPoint, direction: r3(dirToWorld(refl)), energy: r2(E * 0.4) }));
45750
46002
  damage(p, E * 0.05, "ballistic", h.source, out, worldPoint, pieces);
45751
46003
  vis?.spark([v.x, v.y, v.z], [refl.x, refl.y, refl.z], 6);
46004
+ vis?.holeDecal([v.x, v.y, v.z], [n.x, n.y, n.z], fitMark(v, n, shapeOf(false), dir), d, [dir.x, dir.y, dir.z]);
45752
46005
  return;
45753
46006
  }
45754
- const opens = (h.piercing ?? 1) < SOFT_LEAD ? EXPANDED_HOLE : 1;
45755
- const holeDiam = Math.max(6e-3, cal / 1e3 * (d.material === "glass" ? 1.4 : 1) * opens);
45756
46007
  const energyLeft = () => {
45757
46008
  const metal2 = d.material === "steel" || d.material === "aluminium";
45758
46009
  const mm = h.penetration?.steel;
@@ -45763,8 +46014,8 @@ var GameVehiclesThree = (() => {
45763
46014
  if (!hole) return;
45764
46015
  const hp = { point: r3(fromVehicle(v, M)), normal: r3(fromVehicle(n, new THREE.Matrix4().extractRotation(M))), diameter: r2(holeDiam), through };
45765
46016
  p.holes.push(hp);
45766
- out.push(ev({ type: "hole", part: d.id, hole: hp, worldPoint, ...through ? { energyLeft: r2(energyLeft()) } : {}, ...through ? { exitPoint: add3(worldPoint, r3(dirToWorld(dir.clone().multiplyScalar(Math.max(0.02, Math.min(d.box.size[0], d.box.size[1], d.box.size[2])))))) } : {} }));
45767
- vis?.holeDecal([v.x, v.y, v.z], [n.x, n.y, n.z], holeDiam, d);
46017
+ out.push(ev({ type: "hole", part: d.id, hole: hp, worldPoint, worldNormal: r3(dirToWorld(n.clone().normalize())), direction: r3(dirToWorld(dir)), ...through ? { energyLeft: r2(energyLeft()) } : {}, ...through ? { exitPoint: add3(worldPoint, r3(dirToWorld(dir.clone().multiplyScalar(Math.max(0.02, Math.min(d.box.size[0], d.box.size[1], d.box.size[2])))))) } : {} }));
46018
+ vis?.holeDecal([v.x, v.y, v.z], [n.x, n.y, n.z], d.material === "glass" ? shapeOf(through) : fitMark(v, n, shapeOf(through), dir), d, [dir.x, dir.y, dir.z]);
45768
46019
  if (d.role === "mirror") vis?.shatterMirror(d.id);
45769
46020
  startLeak(p, v, cal, out, dir);
45770
46021
  };
@@ -45797,6 +46048,7 @@ var GameVehiclesThree = (() => {
45797
46048
  const dent = { point: r3(fromVehicle(v, M)), normal: r3(fromVehicle(n, new THREE.Matrix4().extractRotation(M))), radius: r2(Math.max(0.02, holeDiam * 2)), depth: r2(Math.min(0.03, E / 6e4 + 2e-3)) };
45798
46049
  p.dents.push(dent);
45799
46050
  out.push(ev({ type: "dent", part: d.id, dent, worldPoint }));
46051
+ vis?.holeDecal([v.x, v.y, v.z], [n.x, n.y, n.z], fitMark(v, n, shapeOf(false), dir), d, [dir.x, dir.y, dir.z]);
45800
46052
  }
45801
46053
  vis?.spark([v.x, v.y, v.z], [dir.x, dir.y, dir.z], through ? 4 : 8);
45802
46054
  let amount = through ? E * 0.6 : E * 0.25;
@@ -51318,8 +51570,8 @@ var GameVehiclesThree = (() => {
51318
51570
  full.traverse((node) => {
51319
51571
  const object2 = node;
51320
51572
  if (!object2.isMesh || object2.userData.skipLite || !isShown2(object2, full)) return;
51321
- const materials = Array.isArray(object2.material) ? object2.material : [object2.material];
51322
- if (materials.some((material) => material?.map && !/plate/i.test(material.name ?? "")) && !/plate/i.test(object2.name ?? "")) textured.push(object2);
51573
+ const materials2 = Array.isArray(object2.material) ? object2.material : [object2.material];
51574
+ if (materials2.some((material) => material?.map && !/plate/i.test(material.name ?? "")) && !/plate/i.test(object2.name ?? "")) textured.push(object2);
51323
51575
  });
51324
51576
  for (const mesh2 of textured) mesh2.userData.skipLite = true;
51325
51577
  const fusion = fuse(THREE, { ...context, vehicle: full }, inverse, null, primaryPaint(context), kit.lodHiddenMaterials());
@@ -51389,6 +51641,26 @@ var GameVehiclesThree = (() => {
51389
51641
  return api;
51390
51642
  }
51391
51643
 
51644
+ // src/test-area/bodywork-effect.ts
51645
+ function bodyworkValues(event, paint) {
51646
+ const direction = event.direction;
51647
+ return {
51648
+ ...event.hole ? { bore: event.hole.diameter } : {},
51649
+ ...paint !== void 0 ? { paint } : {},
51650
+ ...direction ? { dx: direction[0], dy: direction[1], dz: direction[2] } : {}
51651
+ };
51652
+ }
51653
+ var HEAVY_BORE = 0.012;
51654
+ var PISTOL_BORE = 9e-3;
51655
+ var PISTOL_LEVEL = 0.6;
51656
+ var LOUDEST = 1;
51657
+ var QUIETEST = 0.35;
51658
+ function skinHitSound(bore, ids) {
51659
+ const size = bore ?? 0;
51660
+ const volume = Math.min(LOUDEST, Math.max(QUIETEST, PISTOL_LEVEL * (size > 0 ? size / PISTOL_BORE : 0.6)));
51661
+ return { sound: size >= HEAVY_BORE ? ids.skinHitHeavy : ids.skinHit, volume };
51662
+ }
51663
+
51392
51664
  // src/test-area/lane-damage.ts
51393
51665
  var LANE_DAMAGE = ["none", "into_wall", "flat_tyre", "torn_tyre", "run_flat", "no_brake_fluid"];
51394
51666
  var RIFLE = { energy: 3500, caliber: 7.8, penetration: { steel: 18 } };
@@ -51583,13 +51855,24 @@ var GameVehiclesThree = (() => {
51583
51855
  };
51584
51856
  var bodyMassOf = (parts) => {
51585
51857
  const mass = parts.reduce((sum, part) => sum + part.mass, 0);
51586
- const centre = [0, 1, 2].map((k) => parts.reduce((sum, part) => sum + part.mass * part.box.center[k], 0) / mass);
51858
+ const at = (part) => part.massCentre ?? part.box.center;
51859
+ const centre = [0, 1, 2].map((k) => parts.reduce((sum, part) => sum + part.mass * at(part)[k], 0) / mass);
51587
51860
  const inertia = [0, 1, 2].map((k) => parts.reduce((sum, part) => {
51588
- const offset = [part.box.center[0] - centre[0], part.box.center[1] - centre[1], part.box.center[2] - centre[2]];
51861
+ const offset = [at(part)[0] - centre[0], at(part)[1] - centre[1], at(part)[2] - centre[2]];
51589
51862
  return sum + boxInertia(part.mass, part.box.size)[k] + lever(part.mass, offset, k);
51590
51863
  }, 0));
51591
51864
  return { mass, centre, inertia };
51592
51865
  };
51866
+ var partsInFrame = (parts, toFrame) => {
51867
+ const m = toFrame;
51868
+ const at = (row, column) => m[column * 4 + row];
51869
+ const moved = ([x, y, z]) => [0, 1, 2].map((row) => at(row, 0) * x + at(row, 1) * y + at(row, 2) * z + at(row, 3));
51870
+ return parts.map((part) => {
51871
+ const [sx, sy, sz] = part.box.size;
51872
+ const size = [0, 1, 2].map((row) => Math.abs(at(row, 0)) * sx + Math.abs(at(row, 1)) * sy + Math.abs(at(row, 2)) * sz);
51873
+ return { ...part, box: { ...part.box, center: moved(part.box.center), size }, ...part.massCentre ? { massCentre: moved(part.massCentre) } : {} };
51874
+ });
51875
+ };
51593
51876
 
51594
51877
  // src/crash-parts-bodies.ts
51595
51878
  var CLEAR_CHECK_STEPS = 30;
@@ -51901,11 +52184,61 @@ var GameVehiclesThree = (() => {
51901
52184
  var HALF_TURN = Math.SQRT1_2;
51902
52185
  var wheelChildOf = (size, center) => {
51903
52186
  const axis = size[0] <= size[1] && size[0] <= size[2] ? 0 : size[2] <= size[1] ? 2 : 1;
51904
- const radius = Math.max(...size.filter((_, side2) => side2 !== axis)) / 2;
52187
+ const radius = axis === 1 ? Math.max(size[0], size[2]) / 2 : size[1] / 2;
51905
52188
  const shape = { kind: "cylinder", halfHeight: size[axis] / 2, radius };
51906
52189
  if (axis === 1) return { shape, position: center };
51907
52190
  return { shape, position: center, rotation: axis === 0 ? [0, 0, HALF_TURN, HALF_TURN] : [HALF_TURN, 0, 0, HALF_TURN] };
51908
52191
  };
52192
+ var lowestOf = (shape) => {
52193
+ if (shape.kind !== "compound") return 0;
52194
+ let lowest = Infinity;
52195
+ for (const child of shape.children) {
52196
+ const own = child.shape;
52197
+ if (own.kind === "convex") for (let index = 1; index < own.points.length; index += 3) lowest = Math.min(lowest, own.points[index] + child.position[1]);
52198
+ else if (own.kind === "cylinder") lowest = Math.min(lowest, child.position[1] - (child.rotation ? own.radius : own.halfHeight));
52199
+ }
52200
+ return Number.isFinite(lowest) ? lowest : 0;
52201
+ };
52202
+ var tyreBoxesOf = (THREE, objects, toFrame) => {
52203
+ const merged = [];
52204
+ for (const object2 of objects) {
52205
+ const box2 = frameBoxOf(THREE, object2, toFrame);
52206
+ if (box2.isEmpty()) continue;
52207
+ const same = merged.find((other) => other.intersectsBox(box2) && overlapShare(THREE, other, box2) > TYRE_SAME_SHARE);
52208
+ if (same) same.union(box2);
52209
+ else merged.push(box2);
52210
+ }
52211
+ return merged.map((box2) => ({ size: box2.getSize(new THREE.Vector3()).toArray(), center: box2.getCenter(new THREE.Vector3()).toArray() }));
52212
+ };
52213
+ var frameBoxOf = (THREE, object2, toFrame) => {
52214
+ const box2 = new THREE.Box3();
52215
+ const matrix = new THREE.Matrix4();
52216
+ const vertex = new THREE.Vector3();
52217
+ object2.updateWorldMatrix(true, true);
52218
+ object2.traverse((child) => {
52219
+ const position = child.isMesh ? child.geometry.getAttribute("position") : void 0;
52220
+ if (!position) return;
52221
+ matrix.multiplyMatrices(toFrame, child.matrixWorld);
52222
+ for (let index = 0; index < position.count; index++) box2.expandByPoint(vertex.fromBufferAttribute(position, index).applyMatrix4(matrix));
52223
+ });
52224
+ return box2;
52225
+ };
52226
+ var TYRE_SAME_SHARE = 0.5;
52227
+ var overlapShare = (THREE, a, b) => {
52228
+ const shared2 = a.clone().intersect(b).getSize(new THREE.Vector3());
52229
+ const volume = (box2) => {
52230
+ const size = box2.getSize(new THREE.Vector3());
52231
+ return size.x * size.y * size.z;
52232
+ };
52233
+ return shared2.x * shared2.y * shared2.z / Math.max(1e-9, Math.min(volume(a), volume(b)));
52234
+ };
52235
+ var framePartsOf = (THREE, vehicle, root) => {
52236
+ const drawn = vehicle.vehicle.vehicle;
52237
+ root.updateWorldMatrix(true, false);
52238
+ drawn.updateWorldMatrix(true, false);
52239
+ const toFrame = new THREE.Matrix4().copy(root.matrixWorld).invert().multiply(drawn.matrixWorld);
52240
+ return partsInFrame(vehicle.model.parts, toFrame.elements);
52241
+ };
51909
52242
  var runOverHalfOf = (parts) => {
51910
52243
  const half = [0, 0, 0];
51911
52244
  for (const { box: box2 } of parts) {
@@ -51935,21 +52268,32 @@ var GameVehiclesThree = (() => {
51935
52268
  let crash;
51936
52269
  let chassis;
51937
52270
  let stopRunOver;
52271
+ let tyres;
52272
+ const tyresOf = () => {
52273
+ if (tyres) return tyres;
52274
+ root.updateWorldMatrix(true, true);
52275
+ const inverse = new THREE.Matrix4().copy(root.matrixWorld).invert();
52276
+ tyres = new Map(vehicle.model.parts.filter((part) => part.role === "tyre").map((part) => [part, tyreBoxesOf(THREE, vehicle.objectsOf(part.id), inverse)]));
52277
+ return tyres;
52278
+ };
52279
+ const standOnTyres = () => {
52280
+ let lowest = 0;
52281
+ for (const boxes of tyresOf().values()) for (const box2 of boxes) lowest = Math.min(lowest, box2.center[1] - box2.size[1] / 2);
52282
+ if (lowest === 0) return;
52283
+ root.position.add(new THREE.Vector3(0, -lowest, 0).applyQuaternion(root.quaternion));
52284
+ root.updateMatrixWorld(true);
52285
+ };
51938
52286
  const withWheels = (hulls) => {
51939
52287
  if (hulls.kind !== "compound") return hulls;
51940
- const tyres = vehicle.model.parts.filter((part) => part.role === "tyre");
51941
- tyres.forEach((part, index) => wheelHandles.set(part.id, hulls.children.length + index));
51942
- const inverse = new THREE.Matrix4().copy(root.matrixWorld).invert();
51943
- const drawn = new THREE.Box3();
51944
- const piece = new THREE.Box3();
51945
- const centre = new THREE.Vector3();
51946
- const size = new THREE.Vector3();
51947
- const children = tyres.map((part) => {
51948
- drawn.makeEmpty();
51949
- for (const object2 of vehicle.objectsOf(part.id)) drawn.union(piece.setFromObject(object2).applyMatrix4(inverse));
51950
- if (drawn.isEmpty()) return wheelChildOf(part.box.size, part.box.center);
51951
- return wheelChildOf(drawn.getSize(size).toArray(), drawn.getCenter(centre).toArray());
51952
- });
52288
+ const children = [];
52289
+ for (const [part, boxes] of tyresOf()) {
52290
+ const handles = [];
52291
+ for (const box2 of boxes.length > 0 ? boxes : [{ size: part.box.size, center: part.box.center }]) {
52292
+ handles.push(hulls.children.length + children.length);
52293
+ children.push(wheelChildOf(box2.size, box2.center));
52294
+ }
52295
+ wheelHandles.set(part.id, handles);
52296
+ }
51953
52297
  return { ...hulls, children: [...hulls.children, ...children] };
51954
52298
  };
51955
52299
  const build = () => {
@@ -51960,7 +52304,8 @@ var GameVehiclesThree = (() => {
51960
52304
  if (colliders.isHullPending()) return;
51961
52305
  root.updateWorldMatrix(true, false);
51962
52306
  root.matrixWorld.decompose(position, rotation, unusedScale);
51963
- const mass = bodyMassOf(vehicle.model.parts);
52307
+ const parts = framePartsOf(THREE, vehicle, root);
52308
+ const mass = bodyMassOf(parts);
51964
52309
  crash = createCrashParts({
51965
52310
  THREE,
51966
52311
  world,
@@ -51969,22 +52314,24 @@ var GameVehiclesThree = (() => {
51969
52314
  colliders,
51970
52315
  mass,
51971
52316
  onPartLost: (part) => {
51972
- const handle = wheelHandles.get(part.id);
51973
- if (handle !== void 0 && chassis !== void 0) world.setChildShape(chassis, handle, null);
52317
+ if (chassis === void 0) return;
52318
+ for (const handle of wheelHandles.get(part.id) ?? []) world.setChildShape(chassis, handle, null);
51974
52319
  }
51975
52320
  });
52321
+ const shape = withWheels(crash.shape());
52322
+ const lift = new THREE.Vector3(0, Math.max(0, -lowestOf(shape)), 0).applyQuaternion(rotation);
51976
52323
  chassis = world.createBody({
51977
- shape: withWheels(crash.shape()),
52324
+ shape,
51978
52325
  motion: "dynamic",
51979
52326
  mass: mass.mass,
51980
52327
  inertia: mass.inertia,
51981
52328
  layer: "vehicle",
51982
52329
  user: 0,
51983
- position: [position.x, position.y, position.z],
52330
+ position: [position.x + lift.x, position.y + lift.y, position.z + lift.z],
51984
52331
  rotation: [rotation.x, rotation.y, rotation.z, rotation.w]
51985
52332
  });
51986
52333
  crash.bind(chassis);
51987
- stopRunOver = runOver2?.track({ body: chassis, half: runOverHalfOf(vehicle.model.parts) });
52334
+ stopRunOver = runOver2?.track({ body: chassis, half: runOverHalfOf(parts) });
51988
52335
  };
51989
52336
  const follow = () => {
51990
52337
  world.readPose(chassis, pose, 0);
@@ -51997,6 +52344,7 @@ var GameVehiclesThree = (() => {
51997
52344
  };
51998
52345
  const stopPhase = services.loop.add({
51999
52346
  afterSteps: (_dt, frame) => {
52347
+ if (!chassis && root.parent && !tyres) standOnTyres();
52000
52348
  if (!chassis) return build();
52001
52349
  if (frame.steps > 0 && root.parent) follow();
52002
52350
  }
@@ -52457,12 +52805,12 @@ var GameVehiclesThree = (() => {
52457
52805
  ignite: "volumetric_fire",
52458
52806
  explode: "car_fuel_tank",
52459
52807
  glass: "glass_burst",
52460
- sparks: "impact_metal",
52808
+ sparks: "impact_bodywork",
52461
52809
  leak: "vehicle_leak",
52462
52810
  leakIgnited: "vehicle_leak_ignited",
52463
52811
  exhaust: "vehicle_exhaust"
52464
52812
  };
52465
- var defaultSoundIds = { horn: "horn_car", ...DEFAULT_VEHICLE_SOUND_KEYS };
52813
+ var defaultSoundIds = { horn: "horn_car", skinHit: "metal_thin", skinHitHeavy: "metal_bullet", ...DEFAULT_VEHICLE_SOUND_KEYS };
52466
52814
  var DEFAULT_TEST_WRECKS = [
52467
52815
  { key: "sedan_burnt", vehicle: "midsize_sedan", scenario: "burnt" },
52468
52816
  { key: "hatch_burnt", vehicle: "compact_hatch", scenario: "burnt" }
@@ -52570,7 +52918,10 @@ var GameVehiclesThree = (() => {
52570
52918
  const r = root;
52571
52919
  const kit = r.userData.kit;
52572
52920
  const d = createVehicleDestructible(kit, r.userData.vehicle, { id, frame: root, name: text.items[itemKey] ?? key, creaseQueue, puddles: false });
52573
- tapEffects(d);
52921
+ tapEffects(d, () => {
52922
+ const entry = placed.get(root.uuid);
52923
+ return (entry?.paint ?? primaryPaint(r.userData.vehicle))?.color.getHex();
52924
+ });
52574
52925
  const services = physicsServicesOf(host);
52575
52926
  if (services) {
52576
52927
  const colliders = physicalCarColliders(kit.THREE, d, root, { budget: COLLIDER_BUDGET, fleetKey: key, hullCeilingOf: fleet.hullCeilingOf, planCache, workers: host?.workers });
@@ -52631,8 +52982,8 @@ var GameVehiclesThree = (() => {
52631
52982
  }
52632
52983
  return clipCache.get(key);
52633
52984
  };
52634
- const tapEffects = (d) => {
52635
- const request = (events) => {
52985
+ const tapEffects = (d, paint) => {
52986
+ const request = (events, ballistic = false) => {
52636
52987
  const fx = effects();
52637
52988
  if (!fx) return;
52638
52989
  for (const e of events) {
@@ -52642,13 +52993,17 @@ var GameVehiclesThree = (() => {
52642
52993
  else if (e.type === "explode") fx.play({ effect: effectIds.explode, point: position });
52643
52994
  else if (e.type === "leak") fx.play({ effect: effectIds.leak, point: position });
52644
52995
  else if (e.type === "fracture" && /glass|window|windshield/.test(e.part ?? "")) fx.play({ effect: effectIds.glass, point: position });
52645
- else if (e.type === "hole") fx.play({ effect: /glass|window|windshield/.test(e.part ?? "") ? effectIds.glass : effectIds.sparks, point: position });
52996
+ else if (e.type === "hole" && /glass|window|windshield/.test(e.part ?? "")) fx.play({ effect: effectIds.glass, point: position });
52997
+ else if (e.type === "hole") {
52998
+ fx.play({ effect: effectIds.sparks, point: position, ...e.worldNormal ? { normal: e.worldNormal } : {}, values: bodyworkValues(e, paint()) });
52999
+ audio()?.play({ ...skinHitSound(e.hole?.diameter, soundIds), position, urgent: true });
53000
+ } else if (e.type === "dent" && ballistic) audio()?.play({ ...skinHitSound(void 0, soundIds), position, urgent: true });
52646
53001
  }
52647
53002
  };
52648
53003
  const hit = d.hit.bind(d);
52649
53004
  d.hit = (h) => {
52650
53005
  const events = hit(h);
52651
- request(events);
53006
+ request(events, h.type === "ballistic");
52652
53007
  return events;
52653
53008
  };
52654
53009
  if (d.update) {