@adatechnology/game-vehicles-three 0.14.3 → 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.
@@ -24146,13 +24146,13 @@ var GameVehiclesThree = (() => {
24146
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")
24147
24147
  });
24148
24148
  const rr = tr * 0.5, fz = zs * (ww / 2 - 0.05);
24149
- const disc = new THREE.Mesh(
24149
+ const disc2 = new THREE.Mesh(
24150
24150
  new THREE.CylinderGeometry(rr * 0.97, rr * 0.97, 0.03, 32),
24151
24151
  CM("#2b2e31", { metalness: 0.6, roughness: 0.35 })
24152
24152
  );
24153
- disc.rotation.x = PI / 2;
24154
- disc.position.z = fz;
24155
- wg.add(disc);
24153
+ disc2.rotation.x = PI / 2;
24154
+ disc2.position.z = fz;
24155
+ wg.add(disc2);
24156
24156
  const bead = new THREE.Mesh(new THREE.TorusGeometry(rr * 0.98, 0.04, 10, 40), rim);
24157
24157
  bead.position.z = fz + zs * 0.02;
24158
24158
  wg.add(bead);
@@ -28434,7 +28434,7 @@ var GameVehiclesThree = (() => {
28434
28434
  });
28435
28435
  return { acc, pruned };
28436
28436
  }
28437
- function liteMeshes(THREE, fusion, materials) {
28437
+ function liteMeshes(THREE, fusion, materials2) {
28438
28438
  const meshes = [];
28439
28439
  for (const name of LITE_CLASSES) {
28440
28440
  const A = fusion.acc[name];
@@ -28447,7 +28447,7 @@ var GameVehiclesThree = (() => {
28447
28447
  g.setIndex(A.nv > 65535 ? new THREE.Uint32BufferAttribute(A.I, 1) : new THREE.Uint16BufferAttribute(A.I, 1));
28448
28448
  g.computeBoundingBox();
28449
28449
  g.computeBoundingSphere();
28450
- let mt = materials[name];
28450
+ let mt = materials2[name];
28451
28451
  if (name === "plate") {
28452
28452
  mt = mt.clone();
28453
28453
  mt.map = A.map;
@@ -30934,7 +30934,7 @@ var GameVehiclesThree = (() => {
30934
30934
  }
30935
30935
  function collect(roots) {
30936
30936
  const geometries = /* @__PURE__ */ new Set();
30937
- const materials = /* @__PURE__ */ new Set();
30937
+ const materials2 = /* @__PURE__ */ new Set();
30938
30938
  const textures = /* @__PURE__ */ new Set();
30939
30939
  const skeletons = /* @__PURE__ */ new Set();
30940
30940
  for (const root of roots) {
@@ -30945,12 +30945,12 @@ var GameVehiclesThree = (() => {
30945
30945
  const list2 = Array.isArray(o.material) ? o.material : o.material ? [o.material] : [];
30946
30946
  for (const m of list2) {
30947
30947
  if (!m || typeof m.dispose !== "function") continue;
30948
- materials.add(m);
30948
+ materials2.add(m);
30949
30949
  texturesOf(m, textures);
30950
30950
  }
30951
30951
  });
30952
30952
  }
30953
- return { geometries, materials, textures, skeletons };
30953
+ return { geometries, materials: materials2, textures, skeletons };
30954
30954
  }
30955
30955
  var marked = /* @__PURE__ */ new WeakSet();
30956
30956
  var shared = (r) => r.userData?.shared === true || marked.has(r);
@@ -42219,8 +42219,8 @@ var GameVehiclesThree = (() => {
42219
42219
  };
42220
42220
  }
42221
42221
  kit.lodHiddenMaterials = function() {
42222
- const materials = kit.materials;
42223
- 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));
42224
42224
  };
42225
42225
  }
42226
42226
  var defaultDamageableKinds = {
@@ -42546,6 +42546,50 @@ var GameVehiclesThree = (() => {
42546
42546
  (plugins || []).forEach(kit.plugin);
42547
42547
  return kit;
42548
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
+ }
42549
42593
  var END_DEPTH = 0.45;
42550
42594
  var LAMP_EMISSIVE_MIN = 0.25;
42551
42595
  var LAMP_INTENSITY_MIN = 0.2;
@@ -42725,6 +42769,24 @@ var GameVehiclesThree = (() => {
42725
42769
  if (meta.armor === "IIIA" || meta.armor === "III") return meta.armor;
42726
42770
  return meta.armored || meta.bullet ? "III" : null;
42727
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
+ }
42728
42790
  var JOINT_RULES = {
42729
42791
  hinge: { strength: 5e3, tools: ["wrench", "screwdriver"], seconds: 3 },
42730
42792
  bolt: { strength: 3e3, tools: ["wrench"], seconds: 4 },
@@ -43003,12 +43065,15 @@ var GameVehiclesThree = (() => {
43003
43065
  }
43004
43066
  if (!hubZone) {
43005
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);
43006
43070
  add2({
43007
43071
  id: hubId,
43008
43072
  role: "frame",
43009
43073
  name: t("mechanics.chassis"),
43010
43074
  material: "steel",
43011
- 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]] } : {},
43012
43077
  mass: mass * 0.25,
43013
43078
  hp: 15e4 * armour,
43014
43079
  visual: false,
@@ -43601,7 +43666,182 @@ var GameVehiclesThree = (() => {
43601
43666
  }
43602
43667
  return [tub, seal];
43603
43668
  }
43604
- 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;
43605
43845
  var HOLE_BATCH_CAPACITY = 64;
43606
43846
  var DOOR_DEPTH = 0.07;
43607
43847
  var DOOR_SKIN_DEPTH = 0.09;
@@ -43624,7 +43864,6 @@ var GameVehiclesThree = (() => {
43624
43864
  var DOOR_SILL = 0.25;
43625
43865
  var DOOR_STRIP_OVER = 0.05;
43626
43866
  var DOOR_TOP_OVER_PANE = 0.03;
43627
- var HOLE_TEXTURE_SIZE = 64;
43628
43867
  var LAMP_BOX_MARGIN = 0.03;
43629
43868
  var GLOW_MIN_EMISSIVE = 0.05;
43630
43869
  var MIRROR_MIN_METALNESS = 0.8;
@@ -43677,46 +43916,6 @@ var GameVehiclesThree = (() => {
43677
43916
  var SIDEWALL_SHARE = 0.3;
43678
43917
  var MIRROR_GLASS_MIN = 0.05;
43679
43918
  var MIRROR_GLASS_COLOR = "#59636a";
43680
- var HOLE_RIM = { steel: "#b7bcc0", aluminium: "#d3d6d8", plastic: "#d9d6cc", rubber: "#141414", glass: "#eef3f5" };
43681
- var holeMaterials = /* @__PURE__ */ new WeakMap();
43682
- var holeDisc = null;
43683
- function holeDiscGeometry(THREE) {
43684
- holeDisc = holeDisc ?? new THREE.CircleGeometry(1, 12);
43685
- return holeDisc;
43686
- }
43687
- function holeMaterial(kit, material) {
43688
- const key = kit;
43689
- const cache2 = holeMaterials.get(key) ?? /* @__PURE__ */ new Map();
43690
- holeMaterials.set(key, cache2);
43691
- const known = cache2.get(material);
43692
- if (known) return known;
43693
- const I = kit._;
43694
- const THREE = kit.THREE;
43695
- const canvas = kit.document?.createElement?.("canvas");
43696
- const x = canvas?.getContext?.("2d");
43697
- let made = I.MATERIALS.dark;
43698
- if (x) {
43699
- canvas.width = canvas.height = HOLE_TEXTURE_SIZE;
43700
- const mid = HOLE_TEXTURE_SIZE / 2;
43701
- x.fillStyle = HOLE_RIM[material] ?? HOLE_RIM.steel;
43702
- x.beginPath();
43703
- for (let i = 0; i < 18; i++) {
43704
- const a = i / 18 * Math.PI * 2;
43705
- const r = mid * (i % 2 ? 0.98 : 0.76);
43706
- x.lineTo(mid + Math.cos(a) * r, mid + Math.sin(a) * r);
43707
- }
43708
- x.closePath();
43709
- x.fill();
43710
- x.fillStyle = "#050505";
43711
- x.beginPath();
43712
- x.arc(mid, mid, mid * 0.42, 0, Math.PI * 2);
43713
- x.fill();
43714
- const map = new THREE.CanvasTexture(canvas);
43715
- made = new THREE.MeshStandardMaterial({ map, transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, roughness: 0.55, metalness: material === "steel" || material === "aluminium" ? 0.6 : 0 });
43716
- }
43717
- cache2.set(material, made);
43718
- return made;
43719
- }
43720
43919
  function isGlowing(material) {
43721
43920
  const { emissive, emissiveIntensity } = material;
43722
43921
  return !!emissive && (emissiveIntensity ?? 0) > 0 && emissive.r + emissive.g + emissive.b >= GLOW_MIN_EMISSIVE;
@@ -44734,31 +44933,24 @@ var GameVehiclesThree = (() => {
44734
44933
  this.extra.set(p.id, [g]);
44735
44934
  }
44736
44935
  // ---- marks -------------------------------------------------------------------------------------------------------------------------------
44737
- /** A bullet hole: a dark disc lying on the surface at `point` (`c.vehicle` coordinates). */
44738
- 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) {
44739
44941
  const THREE = this.THREE;
44740
44942
  const pane = part?.role === "glass" ? this.panesOf(part).find((g) => g.visible) : void 0;
44741
44943
  if (part?.role === "glass" && (!pane || pane.userData.glass?.broken)) return;
44742
- const radius = Math.max(6e-3, diameter / 2) * HOLE_DECAL_SCALE;
44743
- 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();
44744
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);
44745
44947
  const parent = carrier ?? this.c.vehicle;
44746
- const material = holeMaterial(this.kit, part?.material ?? "steel");
44948
+ const material = holeMarkMaterial(this.kit, part?.material ?? "steel", shape.style);
44747
44949
  const key = `${parent.uuid}|${material.uuid}`;
44748
44950
  let batches = this.holes.get(key);
44749
44951
  let batch = batches?.[batches.length - 1];
44750
44952
  if (!batch || batch.count >= HOLE_BATCH_CAPACITY) {
44751
- batch = new THREE.InstancedMesh(holeDiscGeometry(THREE), material, HOLE_BATCH_CAPACITY);
44752
- batch.count = 0;
44753
- batch.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
44754
- batch.castShadow = false;
44755
- batch.receiveShadow = false;
44756
- batch.userData.decal = true;
44757
- batch.userData.noFollow = true;
44758
- batch.renderOrder = 3;
44759
- batch.raycast = () => {
44760
- };
44761
- batch.frustumCulled = false;
44953
+ batch = this.holeBatch(material);
44762
44954
  parent.add(batch);
44763
44955
  if (!batches) {
44764
44956
  batches = [];
@@ -44766,19 +44958,33 @@ var GameVehiclesThree = (() => {
44766
44958
  }
44767
44959
  batches.push(batch);
44768
44960
  }
44769
- const at = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 3e-3));
44770
- const toward = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 1.003));
44771
- const pose = new THREE.Object3D();
44772
- pose.position.copy(at);
44773
- pose.scale.set(radius, radius, 1);
44774
- pose.lookAt(toward);
44775
- 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);
44776
44967
  parent.updateWorldMatrix(true, false);
44777
- 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);
44778
44969
  batch.setMatrixAt(batch.count, instance);
44779
44970
  batch.count += 1;
44780
44971
  batch.instanceMatrix.needsUpdate = true;
44781
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
+ }
44782
44988
  /** The door or lid a hinge group stands for. */
44783
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. */
44784
44990
  extraIdOf(o) {
@@ -45216,6 +45422,44 @@ var GameVehiclesThree = (() => {
45216
45422
  pair("trunk", lid, "trunk");
45217
45423
  return clips;
45218
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
+ }
45219
45463
  var RESIST = { steel: 380, aluminium: 220, glass: 90, plastic: 70, rubber: 120 };
45220
45464
  var ROLE_RESIST = {
45221
45465
  frame: 6,
@@ -45730,6 +45974,8 @@ var GameVehiclesThree = (() => {
45730
45974
  if (near && igniteRand() < 1 - Math.exp(-chancePerSecond * dt)) light(tank, out);
45731
45975
  };
45732
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;
45733
45979
  const ballistic = (h, out) => {
45734
45980
  sync();
45735
45981
  const M = toFrameMatrix();
@@ -45747,15 +45993,17 @@ var GameVehiclesThree = (() => {
45747
45993
  const cosInc = Math.abs(dir.dot(n));
45748
45994
  const metal = d.material === "steel" || d.material === "aluminium";
45749
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 });
45750
45999
  if (metal && !through && cosInc < 0.3 && E > 40) {
45751
46000
  const refl = dir.clone().addScaledVector(n, -2 * dir.dot(n));
45752
46001
  out.push(ev({ type: "ricochet", part: d.id, point: worldPoint, direction: r3(dirToWorld(refl)), energy: r2(E * 0.4) }));
45753
46002
  damage(p, E * 0.05, "ballistic", h.source, out, worldPoint, pieces);
45754
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]);
45755
46005
  return;
45756
46006
  }
45757
- const opens = (h.piercing ?? 1) < SOFT_LEAD ? EXPANDED_HOLE : 1;
45758
- const holeDiam = Math.max(6e-3, cal / 1e3 * (d.material === "glass" ? 1.4 : 1) * opens);
45759
46007
  const energyLeft = () => {
45760
46008
  const metal2 = d.material === "steel" || d.material === "aluminium";
45761
46009
  const mm = h.penetration?.steel;
@@ -45766,8 +46014,8 @@ var GameVehiclesThree = (() => {
45766
46014
  if (!hole) return;
45767
46015
  const hp = { point: r3(fromVehicle(v, M)), normal: r3(fromVehicle(n, new THREE.Matrix4().extractRotation(M))), diameter: r2(holeDiam), through };
45768
46016
  p.holes.push(hp);
45769
- 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])))))) } : {} }));
45770
- 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]);
45771
46019
  if (d.role === "mirror") vis?.shatterMirror(d.id);
45772
46020
  startLeak(p, v, cal, out, dir);
45773
46021
  };
@@ -45800,6 +46048,7 @@ var GameVehiclesThree = (() => {
45800
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)) };
45801
46049
  p.dents.push(dent);
45802
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]);
45803
46052
  }
45804
46053
  vis?.spark([v.x, v.y, v.z], [dir.x, dir.y, dir.z], through ? 4 : 8);
45805
46054
  let amount = through ? E * 0.6 : E * 0.25;
@@ -51321,8 +51570,8 @@ var GameVehiclesThree = (() => {
51321
51570
  full.traverse((node) => {
51322
51571
  const object2 = node;
51323
51572
  if (!object2.isMesh || object2.userData.skipLite || !isShown2(object2, full)) return;
51324
- const materials = Array.isArray(object2.material) ? object2.material : [object2.material];
51325
- 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);
51326
51575
  });
51327
51576
  for (const mesh2 of textured) mesh2.userData.skipLite = true;
51328
51577
  const fusion = fuse(THREE, { ...context, vehicle: full }, inverse, null, primaryPaint(context), kit.lodHiddenMaterials());
@@ -51392,6 +51641,26 @@ var GameVehiclesThree = (() => {
51392
51641
  return api;
51393
51642
  }
51394
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
+
51395
51664
  // src/test-area/lane-damage.ts
51396
51665
  var LANE_DAMAGE = ["none", "into_wall", "flat_tyre", "torn_tyre", "run_flat", "no_brake_fluid"];
51397
51666
  var RIFLE = { energy: 3500, caliber: 7.8, penetration: { steel: 18 } };
@@ -51586,13 +51855,24 @@ var GameVehiclesThree = (() => {
51586
51855
  };
51587
51856
  var bodyMassOf = (parts) => {
51588
51857
  const mass = parts.reduce((sum, part) => sum + part.mass, 0);
51589
- 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);
51590
51860
  const inertia = [0, 1, 2].map((k) => parts.reduce((sum, part) => {
51591
- 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]];
51592
51862
  return sum + boxInertia(part.mass, part.box.size)[k] + lever(part.mass, offset, k);
51593
51863
  }, 0));
51594
51864
  return { mass, centre, inertia };
51595
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
+ };
51596
51876
 
51597
51877
  // src/crash-parts-bodies.ts
51598
51878
  var CLEAR_CHECK_STEPS = 30;
@@ -51904,11 +52184,61 @@ var GameVehiclesThree = (() => {
51904
52184
  var HALF_TURN = Math.SQRT1_2;
51905
52185
  var wheelChildOf = (size, center) => {
51906
52186
  const axis = size[0] <= size[1] && size[0] <= size[2] ? 0 : size[2] <= size[1] ? 2 : 1;
51907
- 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;
51908
52188
  const shape = { kind: "cylinder", halfHeight: size[axis] / 2, radius };
51909
52189
  if (axis === 1) return { shape, position: center };
51910
52190
  return { shape, position: center, rotation: axis === 0 ? [0, 0, HALF_TURN, HALF_TURN] : [HALF_TURN, 0, 0, HALF_TURN] };
51911
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
+ };
51912
52242
  var runOverHalfOf = (parts) => {
51913
52243
  const half = [0, 0, 0];
51914
52244
  for (const { box: box2 } of parts) {
@@ -51938,21 +52268,32 @@ var GameVehiclesThree = (() => {
51938
52268
  let crash;
51939
52269
  let chassis;
51940
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
+ };
51941
52286
  const withWheels = (hulls) => {
51942
52287
  if (hulls.kind !== "compound") return hulls;
51943
- const tyres = vehicle.model.parts.filter((part) => part.role === "tyre");
51944
- tyres.forEach((part, index) => wheelHandles.set(part.id, hulls.children.length + index));
51945
- const inverse = new THREE.Matrix4().copy(root.matrixWorld).invert();
51946
- const drawn = new THREE.Box3();
51947
- const piece = new THREE.Box3();
51948
- const centre = new THREE.Vector3();
51949
- const size = new THREE.Vector3();
51950
- const children = tyres.map((part) => {
51951
- drawn.makeEmpty();
51952
- for (const object2 of vehicle.objectsOf(part.id)) drawn.union(piece.setFromObject(object2).applyMatrix4(inverse));
51953
- if (drawn.isEmpty()) return wheelChildOf(part.box.size, part.box.center);
51954
- return wheelChildOf(drawn.getSize(size).toArray(), drawn.getCenter(centre).toArray());
51955
- });
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
+ }
51956
52297
  return { ...hulls, children: [...hulls.children, ...children] };
51957
52298
  };
51958
52299
  const build = () => {
@@ -51963,7 +52304,8 @@ var GameVehiclesThree = (() => {
51963
52304
  if (colliders.isHullPending()) return;
51964
52305
  root.updateWorldMatrix(true, false);
51965
52306
  root.matrixWorld.decompose(position, rotation, unusedScale);
51966
- const mass = bodyMassOf(vehicle.model.parts);
52307
+ const parts = framePartsOf(THREE, vehicle, root);
52308
+ const mass = bodyMassOf(parts);
51967
52309
  crash = createCrashParts({
51968
52310
  THREE,
51969
52311
  world,
@@ -51972,22 +52314,24 @@ var GameVehiclesThree = (() => {
51972
52314
  colliders,
51973
52315
  mass,
51974
52316
  onPartLost: (part) => {
51975
- const handle = wheelHandles.get(part.id);
51976
- 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);
51977
52319
  }
51978
52320
  });
52321
+ const shape = withWheels(crash.shape());
52322
+ const lift = new THREE.Vector3(0, Math.max(0, -lowestOf(shape)), 0).applyQuaternion(rotation);
51979
52323
  chassis = world.createBody({
51980
- shape: withWheels(crash.shape()),
52324
+ shape,
51981
52325
  motion: "dynamic",
51982
52326
  mass: mass.mass,
51983
52327
  inertia: mass.inertia,
51984
52328
  layer: "vehicle",
51985
52329
  user: 0,
51986
- position: [position.x, position.y, position.z],
52330
+ position: [position.x + lift.x, position.y + lift.y, position.z + lift.z],
51987
52331
  rotation: [rotation.x, rotation.y, rotation.z, rotation.w]
51988
52332
  });
51989
52333
  crash.bind(chassis);
51990
- stopRunOver = runOver2?.track({ body: chassis, half: runOverHalfOf(vehicle.model.parts) });
52334
+ stopRunOver = runOver2?.track({ body: chassis, half: runOverHalfOf(parts) });
51991
52335
  };
51992
52336
  const follow = () => {
51993
52337
  world.readPose(chassis, pose, 0);
@@ -52000,6 +52344,7 @@ var GameVehiclesThree = (() => {
52000
52344
  };
52001
52345
  const stopPhase = services.loop.add({
52002
52346
  afterSteps: (_dt, frame) => {
52347
+ if (!chassis && root.parent && !tyres) standOnTyres();
52003
52348
  if (!chassis) return build();
52004
52349
  if (frame.steps > 0 && root.parent) follow();
52005
52350
  }
@@ -52460,12 +52805,12 @@ var GameVehiclesThree = (() => {
52460
52805
  ignite: "volumetric_fire",
52461
52806
  explode: "car_fuel_tank",
52462
52807
  glass: "glass_burst",
52463
- sparks: "impact_metal",
52808
+ sparks: "impact_bodywork",
52464
52809
  leak: "vehicle_leak",
52465
52810
  leakIgnited: "vehicle_leak_ignited",
52466
52811
  exhaust: "vehicle_exhaust"
52467
52812
  };
52468
- 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 };
52469
52814
  var DEFAULT_TEST_WRECKS = [
52470
52815
  { key: "sedan_burnt", vehicle: "midsize_sedan", scenario: "burnt" },
52471
52816
  { key: "hatch_burnt", vehicle: "compact_hatch", scenario: "burnt" }
@@ -52573,7 +52918,10 @@ var GameVehiclesThree = (() => {
52573
52918
  const r = root;
52574
52919
  const kit = r.userData.kit;
52575
52920
  const d = createVehicleDestructible(kit, r.userData.vehicle, { id, frame: root, name: text.items[itemKey] ?? key, creaseQueue, puddles: false });
52576
- tapEffects(d);
52921
+ tapEffects(d, () => {
52922
+ const entry = placed.get(root.uuid);
52923
+ return (entry?.paint ?? primaryPaint(r.userData.vehicle))?.color.getHex();
52924
+ });
52577
52925
  const services = physicsServicesOf(host);
52578
52926
  if (services) {
52579
52927
  const colliders = physicalCarColliders(kit.THREE, d, root, { budget: COLLIDER_BUDGET, fleetKey: key, hullCeilingOf: fleet.hullCeilingOf, planCache, workers: host?.workers });
@@ -52634,8 +52982,8 @@ var GameVehiclesThree = (() => {
52634
52982
  }
52635
52983
  return clipCache.get(key);
52636
52984
  };
52637
- const tapEffects = (d) => {
52638
- const request = (events) => {
52985
+ const tapEffects = (d, paint) => {
52986
+ const request = (events, ballistic = false) => {
52639
52987
  const fx = effects();
52640
52988
  if (!fx) return;
52641
52989
  for (const e of events) {
@@ -52645,13 +52993,17 @@ var GameVehiclesThree = (() => {
52645
52993
  else if (e.type === "explode") fx.play({ effect: effectIds.explode, point: position });
52646
52994
  else if (e.type === "leak") fx.play({ effect: effectIds.leak, point: position });
52647
52995
  else if (e.type === "fracture" && /glass|window|windshield/.test(e.part ?? "")) fx.play({ effect: effectIds.glass, point: position });
52648
- 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 });
52649
53001
  }
52650
53002
  };
52651
53003
  const hit = d.hit.bind(d);
52652
53004
  d.hit = (h) => {
52653
53005
  const events = hit(h);
52654
- request(events);
53006
+ request(events, h.type === "ballistic");
52655
53007
  return events;
52656
53008
  };
52657
53009
  if (d.update) {