@adatechnology/game-vehicles 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2788,6 +2788,7 @@ function installLights(kit) {
2788
2788
  kit.halo = halo;
2789
2789
  function lampKit(g, d, inner, lens, lensMat, refl) {
2790
2790
  refl = refl || MATERIALS.reflector;
2791
+ let nProj = 0;
2791
2792
  return {
2792
2793
  housing: function(w, h, y, z, geoFn) {
2793
2794
  const geo = roundedBoxGeometry(d, h, w, Math.min(0.03, h * 0.4));
@@ -2808,7 +2809,7 @@ function installLights(kit) {
2808
2809
  return m;
2809
2810
  },
2810
2811
  proj: function(y, z, r, mat) {
2811
- const bz = gm(g, new THREE.CylinderGeometry(r * 1.3, r * 1.45, 0.03, 18), refl, d / 2 - 0.03, y, z);
2812
+ 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);
2812
2813
  bz.rotation.z = -PI / 2;
2813
2814
  if (refl !== MATERIALS.reflector) inner.push(bz);
2814
2815
  const e = gm(g, new THREE.SphereGeometry(r, 14, 10), mat, d / 2 - 0.022, y, z);
@@ -2988,10 +2989,10 @@ function installLights(kit) {
2988
2989
  (parent || c.vehicle).add(g);
2989
2990
  const d1 = gm(g, new THREE.CylinderGeometry(r, r, 0.012, 24), MATERIALS.chrome);
2990
2991
  d1.rotation.z = PI / 2;
2991
- const d2 = gm(g, new THREE.CylinderGeometry(r * 0.78, r * 0.78, 0.014, 24), MATERIALS.trim);
2992
+ const d2 = gm(g, new THREE.CylinderGeometry(r * 0.78, r * 0.78, 0.018, 24), MATERIALS.trim);
2992
2993
  d2.rotation.z = PI / 2;
2993
- gm(g, roundedBoxGeometry(0.016, r * 0.32, r * 1.4, 5e-3), MATERIALS.chrome);
2994
- gm(g, roundedBoxGeometry(0.016, r * 1, r * 0.22, 5e-3), MATERIALS.chrome, 0, 0, r * 0.25).rotation.x = 0.5;
2994
+ gm(g, roundedBoxGeometry(0.024, r * 0.32, r * 1.4, 5e-3), MATERIALS.chrome);
2995
+ gm(g, roundedBoxGeometry(0.03, r * 1, r * 0.22, 5e-3), MATERIALS.chrome, 0, 0, r * 0.25).rotation.x = 0.5;
2995
2996
  return g;
2996
2997
  };
2997
2998
  kit.grille = function(c, o) {
@@ -3044,7 +3045,7 @@ function installLights(kit) {
3044
3045
  g.children.forEach(function(m) {
3045
3046
  m.castShadow = true;
3046
3047
  });
3047
- if (o.emblem !== false) kit.emblem(c, 0.05, st === "closed" ? h * 0.12 : 0, 0, Math.min(0.05, h * 0.3), g);
3048
+ 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);
3048
3049
  return g;
3049
3050
  };
3050
3051
  const shared = { lampGroup, gm, wedgeY, haloTex, glowTexture, haloMats, halo, lampKit };
@@ -3291,7 +3292,7 @@ function installInterior(kit) {
3291
3292
  } 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" });
3292
3293
  const trimLen = Math.min(0.8, (o.rowPitch ?? 0.88) - 0.06);
3293
3294
  [-1, 1].forEach(function(s) {
3294
- c.roundBox(trimLen, belt - fl - 0.08, 0.035, 0.015, trim, x + 0.12, (belt + fl) / 2 + 0.02, s * (zi + 0.02));
3295
+ 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));
3295
3296
  c.roundBox(0.3, 0.05, 0.07, 0.02, fab, x + 0.16, fl + seatH + 0.16, s * (zi - 0.015));
3296
3297
  c.roundBox(0.08, 0.025, 0.02, 8e-3, MATERIALS.chrome, x + 0.36, belt - 0.11, s * (zi - 5e-3));
3297
3298
  });
@@ -3716,15 +3717,15 @@ function installHood(kit) {
3716
3717
  const cx = (x0 + x1) / 2;
3717
3718
  const paint = c.paint(o.col || c.meta.color || "#666");
3718
3719
  const out = {};
3719
- c.roundBox(L, 0.03, 2 * zw, 0.01, MATERIALS.bay, cx, fl, 0);
3720
+ c.roundBox(L - 0.03, 0.03, 2 * zw, 0.01, MATERIALS.bay, cx + 0.015, fl, 0);
3720
3721
  c.roundBox(0.03, H + 0.04, 2 * zw, 0.01, MATERIALS.bay, x0 + 0.015, fl + H / 2, 0);
3721
3722
  [1, -1].forEach(function(s) {
3722
- c.roundBox(L, H * 0.75, 0.03, 0.01, MATERIALS.bay, cx, fl + H * 0.37, s * zw);
3723
+ 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);
3723
3724
  });
3724
3725
  const rx = x1 - 0.06;
3725
3726
  const rh = H * 0.82;
3726
3727
  const rad = c.roundBox(0.05, rh, zw * 1.5, 0.012, MATERIALS.radiator, rx, fl + rh / 2 + 0.02, 0);
3727
- 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);
3728
+ 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);
3728
3729
  c.roundBox(0.07, 0.04, zw * 1.5, 0.015, MATERIALS.plastic, rx, fl + rh + 0.03, 0);
3729
3730
  out.rad = new V3(rx, fl + rh / 2, 0);
3730
3731
  const fanR = Math.min(rh * 0.42, zw * 0.45);
@@ -3763,8 +3764,9 @@ function installHood(kit) {
3763
3764
  }
3764
3765
  function battery(x, y, z, sc) {
3765
3766
  sc = sc || 1;
3767
+ x = Math.max(x, x0 + 0.034 + 0.1 * sc);
3766
3768
  c.roundBox(0.2 * sc, 0.15 * sc, 0.15 * sc, 0.015, makeMaterial("#1a1b1c", { roughness: 0.5 }), x, y, z);
3767
- c.roundBox(0.2 * sc, 0.012, 0.15 * sc, 5e-3, makeMaterial("#2e3a6a", { roughness: 0.5 }), x, y + 0.04 * sc, z);
3769
+ 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);
3768
3770
  c.cylinder(0.016, 0.018, 0.03, MATERIALS.postRed, x + 0.06 * sc, y + 0.09 * sc, z + 0.045 * sc);
3769
3771
  c.cylinder(0.016, 0.018, 0.03, MATERIALS.postBlack, x + 0.06 * sc, y + 0.09 * sc, z - 0.045 * sc);
3770
3772
  c.tube(
@@ -3783,7 +3785,7 @@ function installHood(kit) {
3783
3785
  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);
3784
3786
  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);
3785
3787
  c.roundBox(0.12, 0.07, 0.13, 0.015, MATERIALS.plastic, x0 + 0.18, uy - 0.02, -zw * 0.78);
3786
- c.roundBox(0.12, 6e-3, 0.13, 3e-3, MATERIALS.dark, x0 + 0.18, uy + 0.017, -zw * 0.78);
3788
+ c.roundBox(0.116, 6e-3, 0.126, 3e-3, MATERIALS.dark, x0 + 0.18, uy + 0.017, -zw * 0.78);
3787
3789
  if (mot === "electric") {
3788
3790
  const fx0 = x0 + L * 0.4;
3789
3791
  const fx1 = x1 - 0.14;
@@ -3936,7 +3938,7 @@ function installHood(kit) {
3936
3938
  const afx = x1 - L * 0.32;
3937
3939
  const afy = Math.min(top - 0.07, fl + H * 0.7);
3938
3940
  c.roundBox(0.22, 0.1, 0.26, 0.03, MATERIALS.plastic, afx, afy, zw * 0.5);
3939
- c.roundBox(0.22, 0.012, 0.26, 4e-3, MATERIALS.dark, afx, afy + 0.01, zw * 0.5);
3941
+ c.roundBox(0.224, 0.012, 0.264, 4e-3, MATERIALS.dark, afx, afy + 0.01, zw * 0.5);
3940
3942
  c.tube(
3941
3943
  [
3942
3944
  [afx - 0.11, afy, zw * 0.4],
@@ -4276,7 +4278,7 @@ function installCar(kit) {
4276
4278
  const gr = Object.assign({ style: "bars", w: W * 0.44, h: Math.max(0.08, hy - bumperY - 0.12) }, s.grille || {});
4277
4279
  const gy = gr.y || (bumperY + hy) / 2 + 0.02;
4278
4280
  const gx = I.profX(it, gy, true);
4279
- kit.grille(c, { style: gr.style, x: gx + 0.025, y: gy, w: gr.w, h: gr.h, col: s.col, emblem: gr.emblem });
4281
+ 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 });
4280
4282
  } else kit.emblem(c, I.profX(it, hy + 0.02, true) + 0.055, hy + 0.02, 0, 0.04);
4281
4283
  const tl = Object.assign({ style: "wrap", w: s.tailW || 0.3, h: s.tailH || 0.14, in: 0.05 }, s.tl || {});
4282
4284
  const ty = tl.y || s.tailLightY || s.tailY - 0.05;
@@ -11312,8 +11314,8 @@ function installLod(kit) {
11312
11314
  };
11313
11315
  }
11314
11316
  kit.lodHiddenMaterials = function() {
11315
- const materials = kit.materials;
11316
- return new Set(lod.hiddenMaterials.map((name) => materials[name]).filter(Boolean));
11317
+ const materials2 = kit.materials;
11318
+ return new Set(lod.hiddenMaterials.map((name) => materials2[name]).filter(Boolean));
11317
11319
  };
11318
11320
  }
11319
11321
 
@@ -11644,6 +11646,52 @@ function createVehicleKit(options) {
11644
11646
  return kit;
11645
11647
  }
11646
11648
 
11649
+ // src/hole-shape.ts
11650
+ var GOUGE_COS = 0.45;
11651
+ var RIFLE_SPEED = 600;
11652
+ var RIFLE_ENERGY_DENSITY = 35;
11653
+ var HEAVY_CALIBER_MM = 12;
11654
+ var LONGEST_GOUGE = 4;
11655
+ var SHORTEST_GOUGE = 1.5;
11656
+ var SHEET_METALS = /* @__PURE__ */ new Set(["steel", "aluminium"]);
11657
+ function speedOf(input) {
11658
+ const mass = input.massGrams;
11659
+ if (!mass || mass <= 0 || input.energy <= 0) return void 0;
11660
+ return Math.sqrt(2 * input.energy / (mass / 1e3));
11661
+ }
11662
+ function isRifleRound(input) {
11663
+ const speed = speedOf(input);
11664
+ if (speed !== void 0) return speed >= RIFLE_SPEED;
11665
+ const area = Math.PI * (input.caliberMm / 2) ** 2;
11666
+ return area > 0 && input.energy / area >= RIFLE_ENERGY_DENSITY;
11667
+ }
11668
+ function holeStyleOf(input) {
11669
+ const sheet = SHEET_METALS.has(input.material);
11670
+ if (sheet && input.cosIncidence < GOUGE_COS) return "gouge";
11671
+ if (!input.through) return "dimple";
11672
+ if (input.caliberMm >= HEAVY_CALIBER_MM) return "ragged";
11673
+ return sheet && isRifleRound(input) ? "petalled" : "round";
11674
+ }
11675
+ function bulletHoleShape(input) {
11676
+ const style = holeStyleOf(input);
11677
+ const bore = Math.max(3e-3, input.boreDiameter);
11678
+ const caliber = input.caliberMm / 1e3;
11679
+ switch (style) {
11680
+ case "gouge": {
11681
+ const elongation = Math.min(LONGEST_GOUGE, Math.max(SHORTEST_GOUGE, 1 / Math.max(input.cosIncidence, 0.05)));
11682
+ return { style, boreDiameter: input.through ? bore * 0.6 : 0, markDiameter: caliber * 1.8, dentDepth: caliber * 0.12, elongation, petals: 0 };
11683
+ }
11684
+ case "dimple":
11685
+ return { style, boreDiameter: 0, markDiameter: caliber * 1.9, dentDepth: caliber * 0.25, elongation: 1, petals: 0 };
11686
+ case "ragged":
11687
+ return { style, boreDiameter: bore * 1.15, markDiameter: bore * 2.6, dentDepth: caliber * 0.35, elongation: 1, petals: 7 };
11688
+ case "petalled":
11689
+ return { style, boreDiameter: bore, markDiameter: bore * 3.4, dentDepth: caliber * 0.18, elongation: 1, petals: 5 };
11690
+ default:
11691
+ return { style, boreDiameter: bore, markDiameter: bore * 2.2, dentDepth: caliber * 0.15, elongation: 1, petals: 0 };
11692
+ }
11693
+ }
11694
+
11647
11695
  // src/stray-lamps.ts
11648
11696
  var END_DEPTH = 0.45;
11649
11697
  var LAMP_EMISSIVE_MIN = 0.25;
@@ -11836,6 +11884,26 @@ function armourLevelOf(meta, option) {
11836
11884
  // src/destructible/impl.ts
11837
11885
  import { chargeFireball, DEFAULT_BLAST_IMPULSE, fireballDose, waveWork, ignitionChance, ignitionDose, resolveIgnitionRules, sparkTargetFactor } from "@adatechnology/game-contracts";
11838
11886
 
11887
+ // src/destructible/support-span.ts
11888
+ var SUPPORT_BAND_M = 0.12;
11889
+ function supportSpanOf(vehicle, inverse) {
11890
+ const boxes = [];
11891
+ vehicle.traverse((node) => {
11892
+ const mesh = node;
11893
+ if (!mesh.isMesh || mesh.userData.decal || !mesh.geometry) return;
11894
+ mesh.geometry.computeBoundingBox();
11895
+ const bounds = mesh.geometry.boundingBox;
11896
+ if (!bounds) return;
11897
+ const box = bounds.clone().applyMatrix4(mesh.matrixWorld).applyMatrix4(inverse);
11898
+ if (box.isEmpty()) return;
11899
+ boxes.push({ minX: box.min.x, maxX: box.max.x, minY: box.min.y });
11900
+ });
11901
+ if (boxes.length === 0) return void 0;
11902
+ const ground = Math.min(...boxes.map((box) => box.minY));
11903
+ const resting = boxes.filter((box) => box.minY <= ground + SUPPORT_BAND_M);
11904
+ return { rear: Math.min(...resting.map((box) => box.minX)), front: Math.max(...resting.map((box) => box.maxX)) };
11905
+ }
11906
+
11839
11907
  // src/destructible/model.ts
11840
11908
  var JOINT_RULES = {
11841
11909
  hinge: { strength: 5e3, tools: ["wrench", "screwdriver"], seconds: 3 },
@@ -12115,12 +12183,15 @@ function buildVehicleModel(kit, c, options = {}) {
12115
12183
  }
12116
12184
  if (!hubZone) {
12117
12185
  const h = Math.max(0.15, belt - clearance);
12186
+ const 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)] });
12187
+ const support = supportSpanOf(c.vehicle, inverse);
12118
12188
  add({
12119
12189
  id: hubId,
12120
12190
  role: "frame",
12121
12191
  name: t("mechanics.chassis"),
12122
12192
  material: "steel",
12123
- 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)] }),
12193
+ box,
12194
+ ...support ? { massCentre: [(support.front + support.rear) / 2, box.center[1], box.center[2]] } : {},
12124
12195
  mass: mass * 0.25,
12125
12196
  hp: 15e4 * armour,
12126
12197
  visual: false,
@@ -12723,8 +12794,185 @@ function buildTrunkBay(THREE, params) {
12723
12794
  return [tub, seal];
12724
12795
  }
12725
12796
 
12797
+ // src/destructible/hole-mark.ts
12798
+ var TEXTURE_SIZE = 128;
12799
+ var DISC_RINGS = [0, 0.18, 0.34, 0.5, 0.66, 0.82, 1];
12800
+ var DISC_SPOKES = 24;
12801
+ var BOWL_LEAN = 0.85;
12802
+ var BOWL_REACH = 0.9;
12803
+ var BARE = { steel: "#a9aeb2", aluminium: "#cfd3d6", plastic: "#d9d6cc", rubber: "#141414", glass: "#eef3f5" };
12804
+ var STEEL_BARE = "#a9aeb2";
12805
+ var PRIMER = "#7d8285";
12806
+ var PETAL_TIP = 0.62;
12807
+ var PETAL_WIDTH = 0.42;
12808
+ var PETAL_SHADE = "#6f7478";
12809
+ var BORE_SHARE = { round: 0.45, petalled: 0.3, ragged: 0.44, dimple: 0, gouge: 0.2 };
12810
+ var materials = /* @__PURE__ */ new WeakMap();
12811
+ var disc = null;
12812
+ function holeMarkGeometry(THREE) {
12813
+ if (disc) return disc;
12814
+ const positions = [];
12815
+ const normals = [];
12816
+ const uvs = [];
12817
+ for (const r of DISC_RINGS) {
12818
+ const spokes = r === 0 ? 1 : DISC_SPOKES;
12819
+ const lean = r > 0 && r < BOWL_REACH ? BOWL_LEAN * Math.sin(Math.PI * r / BOWL_REACH) / r : 0;
12820
+ for (let k = 0; k < spokes; k++) {
12821
+ const a = k / DISC_SPOKES * Math.PI * 2;
12822
+ const x = Math.cos(a) * r;
12823
+ const y = Math.sin(a) * r;
12824
+ const n = new THREE.Vector3(-x * lean, -y * lean, 1).normalize();
12825
+ positions.push(x, y, 0);
12826
+ normals.push(n.x, n.y, n.z);
12827
+ uvs.push(0.5 + x / 2, 0.5 + y / 2);
12828
+ }
12829
+ }
12830
+ const geometry = new THREE.BufferGeometry();
12831
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
12832
+ geometry.setAttribute("normal", new THREE.Float32BufferAttribute(normals, 3));
12833
+ geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
12834
+ geometry.setIndex(discIndices());
12835
+ disc = geometry;
12836
+ return geometry;
12837
+ }
12838
+ function discIndices() {
12839
+ const indices = [];
12840
+ const start2 = (ring) => 1 + (ring - 1) * DISC_SPOKES;
12841
+ for (let k = 0; k < DISC_SPOKES; k++) indices.push(0, start2(1) + k, start2(1) + (k + 1) % DISC_SPOKES);
12842
+ for (let ring = 1; ring < DISC_RINGS.length - 1; ring++) {
12843
+ for (let k = 0; k < DISC_SPOKES; k++) {
12844
+ const a = start2(ring) + k;
12845
+ const b = start2(ring) + (k + 1) % DISC_SPOKES;
12846
+ const c = start2(ring + 1) + k;
12847
+ const d = start2(ring + 1) + (k + 1) % DISC_SPOKES;
12848
+ indices.push(a, c, d, a, d, b);
12849
+ }
12850
+ }
12851
+ return indices;
12852
+ }
12853
+ function jagged(x, options) {
12854
+ const mid = TEXTURE_SIZE / 2;
12855
+ x.beginPath();
12856
+ for (let i = 0; i <= options.points; i++) {
12857
+ const a = i / options.points * Math.PI * 2;
12858
+ const wobble = Math.sin(i * 12.9898 + options.seed * 78.233) * 43758.5453;
12859
+ const r = mid * options.radius * (1 - options.jag + 2 * options.jag * (wobble - Math.floor(wobble)));
12860
+ x.lineTo(mid + Math.cos(a) * r, mid + Math.sin(a) * r);
12861
+ }
12862
+ x.closePath();
12863
+ }
12864
+ function drawBore(x, share, bare) {
12865
+ const mid = TEXTURE_SIZE / 2;
12866
+ const r = mid * share;
12867
+ const wall = x.createRadialGradient(mid, mid, 0, mid, mid, r);
12868
+ wall.addColorStop(0, "#000000");
12869
+ wall.addColorStop(0.6, "#050505");
12870
+ wall.addColorStop(1, "#2a2b2c");
12871
+ x.fillStyle = wall;
12872
+ x.beginPath();
12873
+ x.arc(mid, mid, r, 0, Math.PI * 2);
12874
+ x.fill();
12875
+ x.strokeStyle = bare;
12876
+ x.lineWidth = Math.max(1, mid * 0.05);
12877
+ x.beginPath();
12878
+ x.arc(mid, mid, r, 0, Math.PI * 2);
12879
+ x.stroke();
12880
+ }
12881
+ function drawPetals(x, share, petals) {
12882
+ const mid = TEXTURE_SIZE / 2;
12883
+ x.fillStyle = PETAL_SHADE;
12884
+ for (let i = 0; i < petals; i++) {
12885
+ const a = i / petals * Math.PI * 2 + 0.4;
12886
+ const half = Math.PI / petals * PETAL_WIDTH;
12887
+ x.beginPath();
12888
+ x.moveTo(mid + Math.cos(a - half) * mid * share, mid + Math.sin(a - half) * mid * share);
12889
+ x.lineTo(mid + Math.cos(a) * mid * share * PETAL_TIP, mid + Math.sin(a) * mid * share * PETAL_TIP);
12890
+ x.lineTo(mid + Math.cos(a + half) * mid * share, mid + Math.sin(a + half) * mid * share);
12891
+ x.closePath();
12892
+ x.fill();
12893
+ }
12894
+ }
12895
+ function drawRing(x, material, style) {
12896
+ const mid = TEXTURE_SIZE / 2;
12897
+ const bare = BARE[material] ?? STEEL_BARE;
12898
+ const share = BORE_SHARE[style];
12899
+ if (material === "steel" || material === "aluminium") {
12900
+ x.fillStyle = PRIMER;
12901
+ jagged(x, { radius: style === "petalled" ? 0.9 : 0.86, jag: 0.12, points: 22, seed: style.length });
12902
+ x.fill();
12903
+ }
12904
+ x.fillStyle = bare;
12905
+ jagged(x, { radius: Math.max(share + 0.18, style === "dimple" ? 0.55 : 0.6), jag: 0.08, points: 18, seed: style.length + 3 });
12906
+ x.fill();
12907
+ x.strokeStyle = "rgba(70, 72, 74, 0.55)";
12908
+ x.lineWidth = 1;
12909
+ for (let i = 0; i < 14; i++) {
12910
+ const a = i / 14 * Math.PI * 2 + 0.2;
12911
+ x.beginPath();
12912
+ x.moveTo(mid + Math.cos(a) * mid * (share + 0.05), mid + Math.sin(a) * mid * (share + 0.05));
12913
+ x.lineTo(mid + Math.cos(a) * mid * (share + 0.2), mid + Math.sin(a) * mid * (share + 0.2));
12914
+ x.stroke();
12915
+ }
12916
+ }
12917
+ function drawDimple(x) {
12918
+ const mid = TEXTURE_SIZE / 2;
12919
+ const hollow = x.createRadialGradient(mid * 0.92, mid * 0.92, 0, mid, mid, mid * 0.4);
12920
+ hollow.addColorStop(0, "#3c3e40");
12921
+ hollow.addColorStop(1, "rgba(60, 62, 64, 0)");
12922
+ x.fillStyle = hollow;
12923
+ x.beginPath();
12924
+ x.arc(mid, mid, mid * 0.4, 0, Math.PI * 2);
12925
+ x.fill();
12926
+ }
12927
+ function drawCrease(x) {
12928
+ const mid = TEXTURE_SIZE / 2;
12929
+ const crease = x.createLinearGradient(0, mid * 0.75, 0, mid * 1.25);
12930
+ crease.addColorStop(0, "rgba(20, 20, 20, 0)");
12931
+ crease.addColorStop(0.5, "#141414");
12932
+ crease.addColorStop(1, "rgba(20, 20, 20, 0)");
12933
+ x.fillStyle = crease;
12934
+ x.fillRect(mid * 0.15, mid * 0.75, mid * 1.7, mid * 0.5);
12935
+ }
12936
+ function drawMark(x, material, style) {
12937
+ const bare = BARE[material] ?? STEEL_BARE;
12938
+ const share = BORE_SHARE[style];
12939
+ drawRing(x, material, style);
12940
+ if (style === "dimple") return drawDimple(x);
12941
+ if (style === "gouge") drawCrease(x);
12942
+ drawBore(x, share, bare);
12943
+ if (style === "petalled") drawPetals(x, share, 5);
12944
+ if (style !== "ragged") return;
12945
+ x.fillStyle = "#030303";
12946
+ jagged(x, { radius: share, jag: 0.22, points: 11, seed: 7 });
12947
+ x.fill();
12948
+ drawPetals(x, share, 7);
12949
+ }
12950
+ function holeMarkMaterial(kit, material, style) {
12951
+ const key = kit;
12952
+ const cache2 = materials.get(key) ?? /* @__PURE__ */ new Map();
12953
+ materials.set(key, cache2);
12954
+ const id = `${material}|${style}`;
12955
+ const known = cache2.get(id);
12956
+ if (known) return known;
12957
+ const shared = kit._;
12958
+ const THREE = kit.THREE;
12959
+ const canvas = kit.document?.createElement?.("canvas");
12960
+ const context = canvas?.getContext?.("2d");
12961
+ let made = shared.MATERIALS.dark;
12962
+ if (canvas && context) {
12963
+ canvas.width = canvas.height = TEXTURE_SIZE;
12964
+ drawMark(context, material, style);
12965
+ const map = new THREE.CanvasTexture(canvas);
12966
+ const metal = material === "steel" || material === "aluminium";
12967
+ made = new THREE.MeshStandardMaterial({ map, transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -1, polygonOffsetUnits: -2, roughness: 0.5, metalness: metal ? 0.55 : 0 });
12968
+ }
12969
+ cache2.set(id, made);
12970
+ return made;
12971
+ }
12972
+
12726
12973
  // src/destructible/visual.ts
12727
- var HOLE_DECAL_SCALE = 2.4;
12974
+ var HOLE_LIFT = 1e-3;
12975
+ var HOLE_MIN_MARK = 4e-3;
12728
12976
  var HOLE_BATCH_CAPACITY = 64;
12729
12977
  var DOOR_DEPTH = 0.07;
12730
12978
  var DOOR_SKIN_DEPTH = 0.09;
@@ -12747,7 +12995,6 @@ var DOOR_STRIP_VERTICES = 6e4;
12747
12995
  var DOOR_SILL = 0.25;
12748
12996
  var DOOR_STRIP_OVER = 0.05;
12749
12997
  var DOOR_TOP_OVER_PANE = 0.03;
12750
- var HOLE_TEXTURE_SIZE = 64;
12751
12998
  var LAMP_BOX_MARGIN = 0.03;
12752
12999
  var GLOW_MIN_EMISSIVE = 0.05;
12753
13000
  var MIRROR_MIN_METALNESS = 0.8;
@@ -12800,46 +13047,6 @@ var DEFAULT_WHEEL_RADIUS = 0.3;
12800
13047
  var SIDEWALL_SHARE = 0.3;
12801
13048
  var MIRROR_GLASS_MIN = 0.05;
12802
13049
  var MIRROR_GLASS_COLOR = "#59636a";
12803
- var HOLE_RIM = { steel: "#b7bcc0", aluminium: "#d3d6d8", plastic: "#d9d6cc", rubber: "#141414", glass: "#eef3f5" };
12804
- var holeMaterials = /* @__PURE__ */ new WeakMap();
12805
- var holeDisc = null;
12806
- function holeDiscGeometry(THREE) {
12807
- holeDisc = holeDisc ?? new THREE.CircleGeometry(1, 12);
12808
- return holeDisc;
12809
- }
12810
- function holeMaterial(kit, material) {
12811
- const key = kit;
12812
- const cache2 = holeMaterials.get(key) ?? /* @__PURE__ */ new Map();
12813
- holeMaterials.set(key, cache2);
12814
- const known = cache2.get(material);
12815
- if (known) return known;
12816
- const I = kit._;
12817
- const THREE = kit.THREE;
12818
- const canvas = kit.document?.createElement?.("canvas");
12819
- const x = canvas?.getContext?.("2d");
12820
- let made = I.MATERIALS.dark;
12821
- if (x) {
12822
- canvas.width = canvas.height = HOLE_TEXTURE_SIZE;
12823
- const mid = HOLE_TEXTURE_SIZE / 2;
12824
- x.fillStyle = HOLE_RIM[material] ?? HOLE_RIM.steel;
12825
- x.beginPath();
12826
- for (let i = 0; i < 18; i++) {
12827
- const a = i / 18 * Math.PI * 2;
12828
- const r = mid * (i % 2 ? 0.98 : 0.76);
12829
- x.lineTo(mid + Math.cos(a) * r, mid + Math.sin(a) * r);
12830
- }
12831
- x.closePath();
12832
- x.fill();
12833
- x.fillStyle = "#050505";
12834
- x.beginPath();
12835
- x.arc(mid, mid, mid * 0.42, 0, Math.PI * 2);
12836
- x.fill();
12837
- const map = new THREE.CanvasTexture(canvas);
12838
- made = new THREE.MeshStandardMaterial({ map, transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, roughness: 0.55, metalness: material === "steel" || material === "aluminium" ? 0.6 : 0 });
12839
- }
12840
- cache2.set(material, made);
12841
- return made;
12842
- }
12843
13050
  function isGlowing(material) {
12844
13051
  const { emissive, emissiveIntensity } = material;
12845
13052
  return !!emissive && (emissiveIntensity ?? 0) > 0 && emissive.r + emissive.g + emissive.b >= GLOW_MIN_EMISSIVE;
@@ -13872,31 +14079,24 @@ var VehicleVisuals = class {
13872
14079
  this.extra.set(p.id, [g]);
13873
14080
  }
13874
14081
  // ---- marks -------------------------------------------------------------------------------------------------------------------------------
13875
- /** A bullet hole: a dark disc lying on the surface at `point` (`c.vehicle` coordinates). */
13876
- holeDecal(point, normal, diameter, part) {
14082
+ /**
14083
+ * 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
14084
+ * 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.
14085
+ */
14086
+ holeDecal(point, normal, shape, part, along) {
13877
14087
  const THREE = this.THREE;
13878
14088
  const pane = part?.role === "glass" ? this.panesOf(part).find((g) => g.visible) : void 0;
13879
14089
  if (part?.role === "glass" && (!pane || pane.userData.glass?.broken)) return;
13880
- const radius = Math.max(6e-3, diameter / 2) * HOLE_DECAL_SCALE;
13881
- const n = new THREE.Vector3(...normal);
14090
+ const across = Math.max(HOLE_MIN_MARK, shape.markDiameter) / 2;
14091
+ const n = new THREE.Vector3(...normal).normalize();
13882
14092
  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);
13883
14093
  const parent = carrier ?? this.c.vehicle;
13884
- const material = holeMaterial(this.kit, part?.material ?? "steel");
14094
+ const material = holeMarkMaterial(this.kit, part?.material ?? "steel", shape.style);
13885
14095
  const key = `${parent.uuid}|${material.uuid}`;
13886
14096
  let batches = this.holes.get(key);
13887
14097
  let batch = batches?.[batches.length - 1];
13888
14098
  if (!batch || batch.count >= HOLE_BATCH_CAPACITY) {
13889
- batch = new THREE.InstancedMesh(holeDiscGeometry(THREE), material, HOLE_BATCH_CAPACITY);
13890
- batch.count = 0;
13891
- batch.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
13892
- batch.castShadow = false;
13893
- batch.receiveShadow = false;
13894
- batch.userData.decal = true;
13895
- batch.userData.noFollow = true;
13896
- batch.renderOrder = 3;
13897
- batch.raycast = () => {
13898
- };
13899
- batch.frustumCulled = false;
14099
+ batch = this.holeBatch(material);
13900
14100
  parent.add(batch);
13901
14101
  if (!batches) {
13902
14102
  batches = [];
@@ -13904,19 +14104,33 @@ var VehicleVisuals = class {
13904
14104
  }
13905
14105
  batches.push(batch);
13906
14106
  }
13907
- const at = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 3e-3));
13908
- const toward = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 1.003));
13909
- const pose = new THREE.Object3D();
13910
- pose.position.copy(at);
13911
- pose.scale.set(radius, radius, 1);
13912
- pose.lookAt(toward);
13913
- pose.updateMatrix();
14107
+ const u = new THREE.Vector3(...along ?? [0, 0, 0]).addScaledVector(n, -new THREE.Vector3(...along ?? [0, 0, 0]).dot(n));
14108
+ 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));
14109
+ u.normalize();
14110
+ const w = new THREE.Vector3().crossVectors(n, u);
14111
+ const at = new THREE.Vector3(...point).addScaledVector(n, HOLE_LIFT);
14112
+ const local = new THREE.Matrix4().makeBasis(u.multiplyScalar(across * shape.elongation), w.multiplyScalar(across), n).setPosition(at);
13914
14113
  parent.updateWorldMatrix(true, false);
13915
- const instance = new THREE.Matrix4().copy(parent.matrixWorld).invert().multiply(pose.matrix);
14114
+ const instance = new THREE.Matrix4().copy(parent.matrixWorld).invert().multiply(this.c.vehicle.matrixWorld).multiply(local);
13916
14115
  batch.setMatrixAt(batch.count, instance);
13917
14116
  batch.count += 1;
13918
14117
  batch.instanceMatrix.needsUpdate = true;
13919
14118
  }
14119
+ /** A new batch of marks of one material (a door full of holes still draws as one). */
14120
+ holeBatch(material) {
14121
+ const batch = new this.THREE.InstancedMesh(holeMarkGeometry(this.THREE), material, HOLE_BATCH_CAPACITY);
14122
+ batch.count = 0;
14123
+ batch.instanceMatrix.setUsage(this.THREE.DynamicDrawUsage);
14124
+ batch.castShadow = false;
14125
+ batch.receiveShadow = false;
14126
+ batch.userData.decal = true;
14127
+ batch.userData.noFollow = true;
14128
+ batch.renderOrder = 3;
14129
+ batch.raycast = () => {
14130
+ };
14131
+ batch.frustumCulled = false;
14132
+ return batch;
14133
+ }
13920
14134
  /** The door or lid a hinge group stands for. */
13921
14135
  /** 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. */
13922
14136
  extraIdOf(o) {
@@ -14357,6 +14571,46 @@ function createVehicleClips(model, vis, kit, c) {
14357
14571
  return clips;
14358
14572
  }
14359
14573
 
14574
+ // src/destructible/mark-fit.ts
14575
+ var MARK_PROBE = 0.02;
14576
+ var MARK_FALL = 2e-3;
14577
+ var MARK_RISE = 15e-4;
14578
+ var MARK_RIM_SAMPLES = 12;
14579
+ var MARK_SHRINK = 0.7;
14580
+ var MARK_FIT_TRIES = 7;
14581
+ function createMarkFitter(deps) {
14582
+ const axesOf = (n, along) => {
14583
+ const u = along.clone().addScaledVector(n, -along.dot(n));
14584
+ if (u.lengthSq() < 1e-8) u.crossVectors(n, Math.abs(n.y) < 0.9 ? deps.vector(0, 1, 0) : deps.vector(1, 0, 0));
14585
+ u.normalize();
14586
+ return { u, w: deps.vector(0, 0, 0).crossVectors(n, u).normalize() };
14587
+ };
14588
+ const rimOnSurface = (at, axes, half) => {
14589
+ const inward = deps.dirToWorld(at.normal.clone().negate());
14590
+ for (let k = 0; k < MARK_RIM_SAMPLES; k++) {
14591
+ const a = k / MARK_RIM_SAMPLES * Math.PI * 2;
14592
+ 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);
14593
+ const hit = deps.surfaceRay({ origin: deps.toWorld(q), direction: inward, maxDistance: MARK_PROBE * 2 });
14594
+ const fall = hit ? hit.distance - MARK_PROBE : Infinity;
14595
+ if (fall > MARK_FALL || fall < -MARK_RISE) return false;
14596
+ }
14597
+ return true;
14598
+ };
14599
+ return (shape, at) => {
14600
+ const placed = { ...at, normal: at.normal.clone().normalize() };
14601
+ const axes = axesOf(placed.normal, at.along);
14602
+ let scale = 1;
14603
+ for (let tries = 0; tries < MARK_FIT_TRIES; tries++) {
14604
+ const across = shape.markDiameter / 2 * scale;
14605
+ if (rimOnSurface(placed, axes, { along: across * shape.elongation, across })) break;
14606
+ scale *= MARK_SHRINK;
14607
+ }
14608
+ if (scale === 1) return shape;
14609
+ const markDiameter = shape.markDiameter * scale;
14610
+ return { ...shape, markDiameter, boreDiameter: Math.min(shape.boreDiameter, markDiameter * 0.8) };
14611
+ };
14612
+ }
14613
+
14360
14614
  // src/destructible/impl.ts
14361
14615
  var RESIST = { steel: 380, aluminium: 220, glass: 90, plastic: 70, rubber: 120 };
14362
14616
  var ROLE_RESIST = {
@@ -14872,6 +15126,8 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14872
15126
  if (near && igniteRand() < 1 - Math.exp(-chancePerSecond * dt)) light(tank, out);
14873
15127
  };
14874
15128
  const normalOf = (d, v) => faceNormal(d, v);
15129
+ const fitter = createMarkFitter({ vector: (x, y, z) => new V3(x, y, z), surfaceRay: (ray) => surfaceRay(ray), toWorld, dirToWorld });
15130
+ const fitMark = (v, n, shape, along) => vis ? fitter(shape, { point: v, normal: n, along }) : shape;
14875
15131
  const ballistic = (h, out) => {
14876
15132
  sync();
14877
15133
  const M = toFrameMatrix();
@@ -14889,15 +15145,17 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14889
15145
  const cosInc = Math.abs(dir.dot(n));
14890
15146
  const metal = d.material === "steel" || d.material === "aluminium";
14891
15147
  const worldPoint = toWorld(v);
15148
+ const opens = (h.piercing ?? 1) < SOFT_LEAD ? EXPANDED_HOLE : 1;
15149
+ const holeDiam = Math.max(6e-3, cal / 1e3 * (d.material === "glass" ? 1.4 : 1) * opens);
15150
+ const shapeOf = (pierced) => bulletHoleShape({ caliberMm: cal, energy: E, ...h.mass !== void 0 ? { massGrams: h.mass } : {}, cosIncidence: cosInc, through: pierced, material: d.material, boreDiameter: holeDiam });
14892
15151
  if (metal && !through && cosInc < 0.3 && E > 40) {
14893
15152
  const refl = dir.clone().addScaledVector(n, -2 * dir.dot(n));
14894
15153
  out.push(ev({ type: "ricochet", part: d.id, point: worldPoint, direction: r3(dirToWorld(refl)), energy: r2(E * 0.4) }));
14895
15154
  damage(p, E * 0.05, "ballistic", h.source, out, worldPoint, pieces);
14896
15155
  vis?.spark([v.x, v.y, v.z], [refl.x, refl.y, refl.z], 6);
15156
+ 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]);
14897
15157
  return;
14898
15158
  }
14899
- const opens = (h.piercing ?? 1) < SOFT_LEAD ? EXPANDED_HOLE : 1;
14900
- const holeDiam = Math.max(6e-3, cal / 1e3 * (d.material === "glass" ? 1.4 : 1) * opens);
14901
15159
  const energyLeft = () => {
14902
15160
  const metal2 = d.material === "steel" || d.material === "aluminium";
14903
15161
  const mm = h.penetration?.steel;
@@ -14908,8 +15166,8 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14908
15166
  if (!hole) return;
14909
15167
  const hp = { point: r3(fromVehicle(v, M)), normal: r3(fromVehicle(n, new THREE.Matrix4().extractRotation(M))), diameter: r2(holeDiam), through };
14910
15168
  p.holes.push(hp);
14911
- 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])))))) } : {} }));
14912
- vis?.holeDecal([v.x, v.y, v.z], [n.x, n.y, n.z], holeDiam, d);
15169
+ 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])))))) } : {} }));
15170
+ 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]);
14913
15171
  if (d.role === "mirror") vis?.shatterMirror(d.id);
14914
15172
  startLeak(p, v, cal, out, dir);
14915
15173
  };
@@ -14942,6 +15200,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14942
15200
  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)) };
14943
15201
  p.dents.push(dent);
14944
15202
  out.push(ev({ type: "dent", part: d.id, dent, worldPoint }));
15203
+ 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]);
14945
15204
  }
14946
15205
  vis?.spark([v.x, v.y, v.z], [dir.x, dir.y, dir.z], through ? 4 : 8);
14947
15206
  let amount = through ? E * 0.6 : E * 0.25;
@@ -15962,6 +16221,8 @@ export {
15962
16221
  ENTRY_DUCK_FACTOR,
15963
16222
  FLAT_PAD,
15964
16223
  FLOATING_AREA,
16224
+ GOUGE_COS,
16225
+ HEAVY_CALIBER_MM,
15965
16226
  JOINT_RULES,
15966
16227
  LEGACY_STATES,
15967
16228
  LEGACY_ZONE_IDS,
@@ -15970,6 +16231,8 @@ export {
15970
16231
  RAIN_MOVE_STEP,
15971
16232
  RAIN_OPENING_DIAMETER,
15972
16233
  RAIN_TURN_STEP,
16234
+ RIFLE_ENERGY_DENSITY,
16235
+ RIFLE_SPEED,
15973
16236
  SEED_SALTS,
15974
16237
  SMOKE_LOOKS,
15975
16238
  SMOKE_WIND,
@@ -15977,6 +16240,7 @@ export {
15977
16240
  armourLevelOf,
15978
16241
  buildVehicleItem,
15979
16242
  buildVehicleModel,
16243
+ bulletHoleShape,
15980
16244
  cabinBoxOf,
15981
16245
  cabinEnclosure,
15982
16246
  cabinMinimumOf,
@@ -15997,6 +16261,7 @@ export {
15997
16261
  engineBayVent,
15998
16262
  format,
15999
16263
  hash,
16264
+ holeStyleOf,
16000
16265
  hullOf,
16001
16266
  hullPlanKind,
16002
16267
  hullVolume,