@adatechnology/game-vehicles 0.8.1 → 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
@@ -11314,8 +11314,8 @@ function installLod(kit) {
11314
11314
  };
11315
11315
  }
11316
11316
  kit.lodHiddenMaterials = function() {
11317
- const materials = kit.materials;
11318
- 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));
11319
11319
  };
11320
11320
  }
11321
11321
 
@@ -11646,6 +11646,52 @@ function createVehicleKit(options) {
11646
11646
  return kit;
11647
11647
  }
11648
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
+
11649
11695
  // src/stray-lamps.ts
11650
11696
  var END_DEPTH = 0.45;
11651
11697
  var LAMP_EMISSIVE_MIN = 0.25;
@@ -11838,6 +11884,26 @@ function armourLevelOf(meta, option) {
11838
11884
  // src/destructible/impl.ts
11839
11885
  import { chargeFireball, DEFAULT_BLAST_IMPULSE, fireballDose, waveWork, ignitionChance, ignitionDose, resolveIgnitionRules, sparkTargetFactor } from "@adatechnology/game-contracts";
11840
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
+
11841
11907
  // src/destructible/model.ts
11842
11908
  var JOINT_RULES = {
11843
11909
  hinge: { strength: 5e3, tools: ["wrench", "screwdriver"], seconds: 3 },
@@ -12117,12 +12183,15 @@ function buildVehicleModel(kit, c, options = {}) {
12117
12183
  }
12118
12184
  if (!hubZone) {
12119
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);
12120
12188
  add({
12121
12189
  id: hubId,
12122
12190
  role: "frame",
12123
12191
  name: t("mechanics.chassis"),
12124
12192
  material: "steel",
12125
- 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]] } : {},
12126
12195
  mass: mass * 0.25,
12127
12196
  hp: 15e4 * armour,
12128
12197
  visual: false,
@@ -12725,8 +12794,185 @@ function buildTrunkBay(THREE, params) {
12725
12794
  return [tub, seal];
12726
12795
  }
12727
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
+
12728
12973
  // src/destructible/visual.ts
12729
- var HOLE_DECAL_SCALE = 2.4;
12974
+ var HOLE_LIFT = 1e-3;
12975
+ var HOLE_MIN_MARK = 4e-3;
12730
12976
  var HOLE_BATCH_CAPACITY = 64;
12731
12977
  var DOOR_DEPTH = 0.07;
12732
12978
  var DOOR_SKIN_DEPTH = 0.09;
@@ -12749,7 +12995,6 @@ var DOOR_STRIP_VERTICES = 6e4;
12749
12995
  var DOOR_SILL = 0.25;
12750
12996
  var DOOR_STRIP_OVER = 0.05;
12751
12997
  var DOOR_TOP_OVER_PANE = 0.03;
12752
- var HOLE_TEXTURE_SIZE = 64;
12753
12998
  var LAMP_BOX_MARGIN = 0.03;
12754
12999
  var GLOW_MIN_EMISSIVE = 0.05;
12755
13000
  var MIRROR_MIN_METALNESS = 0.8;
@@ -12802,46 +13047,6 @@ var DEFAULT_WHEEL_RADIUS = 0.3;
12802
13047
  var SIDEWALL_SHARE = 0.3;
12803
13048
  var MIRROR_GLASS_MIN = 0.05;
12804
13049
  var MIRROR_GLASS_COLOR = "#59636a";
12805
- var HOLE_RIM = { steel: "#b7bcc0", aluminium: "#d3d6d8", plastic: "#d9d6cc", rubber: "#141414", glass: "#eef3f5" };
12806
- var holeMaterials = /* @__PURE__ */ new WeakMap();
12807
- var holeDisc = null;
12808
- function holeDiscGeometry(THREE) {
12809
- holeDisc = holeDisc ?? new THREE.CircleGeometry(1, 12);
12810
- return holeDisc;
12811
- }
12812
- function holeMaterial(kit, material) {
12813
- const key = kit;
12814
- const cache2 = holeMaterials.get(key) ?? /* @__PURE__ */ new Map();
12815
- holeMaterials.set(key, cache2);
12816
- const known = cache2.get(material);
12817
- if (known) return known;
12818
- const I = kit._;
12819
- const THREE = kit.THREE;
12820
- const canvas = kit.document?.createElement?.("canvas");
12821
- const x = canvas?.getContext?.("2d");
12822
- let made = I.MATERIALS.dark;
12823
- if (x) {
12824
- canvas.width = canvas.height = HOLE_TEXTURE_SIZE;
12825
- const mid = HOLE_TEXTURE_SIZE / 2;
12826
- x.fillStyle = HOLE_RIM[material] ?? HOLE_RIM.steel;
12827
- x.beginPath();
12828
- for (let i = 0; i < 18; i++) {
12829
- const a = i / 18 * Math.PI * 2;
12830
- const r = mid * (i % 2 ? 0.98 : 0.76);
12831
- x.lineTo(mid + Math.cos(a) * r, mid + Math.sin(a) * r);
12832
- }
12833
- x.closePath();
12834
- x.fill();
12835
- x.fillStyle = "#050505";
12836
- x.beginPath();
12837
- x.arc(mid, mid, mid * 0.42, 0, Math.PI * 2);
12838
- x.fill();
12839
- const map = new THREE.CanvasTexture(canvas);
12840
- made = new THREE.MeshStandardMaterial({ map, transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, roughness: 0.55, metalness: material === "steel" || material === "aluminium" ? 0.6 : 0 });
12841
- }
12842
- cache2.set(material, made);
12843
- return made;
12844
- }
12845
13050
  function isGlowing(material) {
12846
13051
  const { emissive, emissiveIntensity } = material;
12847
13052
  return !!emissive && (emissiveIntensity ?? 0) > 0 && emissive.r + emissive.g + emissive.b >= GLOW_MIN_EMISSIVE;
@@ -13874,31 +14079,24 @@ var VehicleVisuals = class {
13874
14079
  this.extra.set(p.id, [g]);
13875
14080
  }
13876
14081
  // ---- marks -------------------------------------------------------------------------------------------------------------------------------
13877
- /** A bullet hole: a dark disc lying on the surface at `point` (`c.vehicle` coordinates). */
13878
- 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) {
13879
14087
  const THREE = this.THREE;
13880
14088
  const pane = part?.role === "glass" ? this.panesOf(part).find((g) => g.visible) : void 0;
13881
14089
  if (part?.role === "glass" && (!pane || pane.userData.glass?.broken)) return;
13882
- const radius = Math.max(6e-3, diameter / 2) * HOLE_DECAL_SCALE;
13883
- 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();
13884
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);
13885
14093
  const parent = carrier ?? this.c.vehicle;
13886
- const material = holeMaterial(this.kit, part?.material ?? "steel");
14094
+ const material = holeMarkMaterial(this.kit, part?.material ?? "steel", shape.style);
13887
14095
  const key = `${parent.uuid}|${material.uuid}`;
13888
14096
  let batches = this.holes.get(key);
13889
14097
  let batch = batches?.[batches.length - 1];
13890
14098
  if (!batch || batch.count >= HOLE_BATCH_CAPACITY) {
13891
- batch = new THREE.InstancedMesh(holeDiscGeometry(THREE), material, HOLE_BATCH_CAPACITY);
13892
- batch.count = 0;
13893
- batch.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
13894
- batch.castShadow = false;
13895
- batch.receiveShadow = false;
13896
- batch.userData.decal = true;
13897
- batch.userData.noFollow = true;
13898
- batch.renderOrder = 3;
13899
- batch.raycast = () => {
13900
- };
13901
- batch.frustumCulled = false;
14099
+ batch = this.holeBatch(material);
13902
14100
  parent.add(batch);
13903
14101
  if (!batches) {
13904
14102
  batches = [];
@@ -13906,19 +14104,33 @@ var VehicleVisuals = class {
13906
14104
  }
13907
14105
  batches.push(batch);
13908
14106
  }
13909
- const at = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 3e-3));
13910
- const toward = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 1.003));
13911
- const pose = new THREE.Object3D();
13912
- pose.position.copy(at);
13913
- pose.scale.set(radius, radius, 1);
13914
- pose.lookAt(toward);
13915
- 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);
13916
14113
  parent.updateWorldMatrix(true, false);
13917
- 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);
13918
14115
  batch.setMatrixAt(batch.count, instance);
13919
14116
  batch.count += 1;
13920
14117
  batch.instanceMatrix.needsUpdate = true;
13921
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
+ }
13922
14134
  /** The door or lid a hinge group stands for. */
13923
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. */
13924
14136
  extraIdOf(o) {
@@ -14359,6 +14571,46 @@ function createVehicleClips(model, vis, kit, c) {
14359
14571
  return clips;
14360
14572
  }
14361
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
+
14362
14614
  // src/destructible/impl.ts
14363
14615
  var RESIST = { steel: 380, aluminium: 220, glass: 90, plastic: 70, rubber: 120 };
14364
14616
  var ROLE_RESIST = {
@@ -14874,6 +15126,8 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14874
15126
  if (near && igniteRand() < 1 - Math.exp(-chancePerSecond * dt)) light(tank, out);
14875
15127
  };
14876
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;
14877
15131
  const ballistic = (h, out) => {
14878
15132
  sync();
14879
15133
  const M = toFrameMatrix();
@@ -14891,15 +15145,17 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14891
15145
  const cosInc = Math.abs(dir.dot(n));
14892
15146
  const metal = d.material === "steel" || d.material === "aluminium";
14893
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 });
14894
15151
  if (metal && !through && cosInc < 0.3 && E > 40) {
14895
15152
  const refl = dir.clone().addScaledVector(n, -2 * dir.dot(n));
14896
15153
  out.push(ev({ type: "ricochet", part: d.id, point: worldPoint, direction: r3(dirToWorld(refl)), energy: r2(E * 0.4) }));
14897
15154
  damage(p, E * 0.05, "ballistic", h.source, out, worldPoint, pieces);
14898
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]);
14899
15157
  return;
14900
15158
  }
14901
- const opens = (h.piercing ?? 1) < SOFT_LEAD ? EXPANDED_HOLE : 1;
14902
- const holeDiam = Math.max(6e-3, cal / 1e3 * (d.material === "glass" ? 1.4 : 1) * opens);
14903
15159
  const energyLeft = () => {
14904
15160
  const metal2 = d.material === "steel" || d.material === "aluminium";
14905
15161
  const mm = h.penetration?.steel;
@@ -14910,8 +15166,8 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14910
15166
  if (!hole) return;
14911
15167
  const hp = { point: r3(fromVehicle(v, M)), normal: r3(fromVehicle(n, new THREE.Matrix4().extractRotation(M))), diameter: r2(holeDiam), through };
14912
15168
  p.holes.push(hp);
14913
- 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])))))) } : {} }));
14914
- 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]);
14915
15171
  if (d.role === "mirror") vis?.shatterMirror(d.id);
14916
15172
  startLeak(p, v, cal, out, dir);
14917
15173
  };
@@ -14944,6 +15200,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14944
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)) };
14945
15201
  p.dents.push(dent);
14946
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]);
14947
15204
  }
14948
15205
  vis?.spark([v.x, v.y, v.z], [dir.x, dir.y, dir.z], through ? 4 : 8);
14949
15206
  let amount = through ? E * 0.6 : E * 0.25;
@@ -15964,6 +16221,8 @@ export {
15964
16221
  ENTRY_DUCK_FACTOR,
15965
16222
  FLAT_PAD,
15966
16223
  FLOATING_AREA,
16224
+ GOUGE_COS,
16225
+ HEAVY_CALIBER_MM,
15967
16226
  JOINT_RULES,
15968
16227
  LEGACY_STATES,
15969
16228
  LEGACY_ZONE_IDS,
@@ -15972,6 +16231,8 @@ export {
15972
16231
  RAIN_MOVE_STEP,
15973
16232
  RAIN_OPENING_DIAMETER,
15974
16233
  RAIN_TURN_STEP,
16234
+ RIFLE_ENERGY_DENSITY,
16235
+ RIFLE_SPEED,
15975
16236
  SEED_SALTS,
15976
16237
  SMOKE_LOOKS,
15977
16238
  SMOKE_WIND,
@@ -15979,6 +16240,7 @@ export {
15979
16240
  armourLevelOf,
15980
16241
  buildVehicleItem,
15981
16242
  buildVehicleModel,
16243
+ bulletHoleShape,
15982
16244
  cabinBoxOf,
15983
16245
  cabinEnclosure,
15984
16246
  cabinMinimumOf,
@@ -15999,6 +16261,7 @@ export {
15999
16261
  engineBayVent,
16000
16262
  format,
16001
16263
  hash,
16264
+ holeStyleOf,
16002
16265
  hullOf,
16003
16266
  hullPlanKind,
16004
16267
  hullVolume,