@adatechnology/game-vehicles 0.6.21 → 0.7.1

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.
@@ -29,11 +29,16 @@ var GameVehicles = (() => {
29
29
  CABIN_MINIMUMS: () => CABIN_MINIMUMS,
30
30
  CABIN_SOURCE: () => CABIN_SOURCE,
31
31
  CRASH_RULES: () => CRASH_RULES,
32
+ DOOR_SHELL_DEPTH: () => DOOR_SHELL_DEPTH,
33
+ DOOR_SHELL_MAX_DEPTH: () => DOOR_SHELL_MAX_DEPTH,
32
34
  ENTRY_DUCK_FACTOR: () => ENTRY_DUCK_FACTOR,
33
35
  JOINT_RULES: () => JOINT_RULES,
34
36
  LEGACY_STATES: () => LEGACY_STATES,
35
37
  LEGACY_ZONE_IDS: () => LEGACY_ZONE_IDS,
36
38
  PLUME_PUFFS: () => PLUME_PUFFS,
39
+ RAIN_MOVE_STEP: () => RAIN_MOVE_STEP,
40
+ RAIN_OPENING_DIAMETER: () => RAIN_OPENING_DIAMETER,
41
+ RAIN_TURN_STEP: () => RAIN_TURN_STEP,
37
42
  SEED_SALTS: () => SEED_SALTS,
38
43
  SMOKE_LOOKS: () => SMOKE_LOOKS,
39
44
  SMOKE_WIND: () => SMOKE_WIND,
@@ -53,8 +58,10 @@ var GameVehicles = (() => {
53
58
  createTranslate: () => createTranslate,
54
59
  createVehicleDestructible: () => createVehicleDestructible,
55
60
  createVehicleKit: () => createVehicleKit,
61
+ createVehicleRainCover: () => createVehicleRainCover,
56
62
  defaultDamageableKinds: () => defaultDamageableKinds,
57
63
  defaultLodSettings: () => defaultLodSettings,
64
+ doorShell: () => doorShell,
58
65
  engineBayVent: () => engineBayVent,
59
66
  format: () => format,
60
67
  hash: () => hash,
@@ -62,6 +69,7 @@ var GameVehicles = (() => {
62
69
  legacyLightId: () => legacyLightId,
63
70
  legacyZoneId: () => legacyZoneId,
64
71
  listLocales: () => listLocales,
72
+ openEdgeCount: () => openEdgeCount,
65
73
  registerLegacySeeds: () => registerLegacySeeds,
66
74
  registerLocale: () => registerLocale,
67
75
  resolveStrings: () => resolveStrings,
@@ -1646,6 +1654,50 @@ var GameVehicles = (() => {
1646
1654
  node.userData[KIT_ORIGIN_KEY] = { ...origin };
1647
1655
  return object2;
1648
1656
  }
1657
+ var prepare = (f) => ({ x: f.x, z: f.z, halfX: f.halfX, halfZ: f.halfZ, cos: Math.cos(f.yaw), sin: Math.sin(f.yaw), top: f.top });
1658
+ var insideTurned = (f, x, z) => {
1659
+ const dx = x - f.x;
1660
+ const dz = z - f.z;
1661
+ return Math.abs(dx * f.cos + dz * f.sin) <= f.halfX && Math.abs(-dx * f.sin + dz * f.cos) <= f.halfZ;
1662
+ };
1663
+ function createFootprintRainCover() {
1664
+ let roofs = [];
1665
+ let openings = [];
1666
+ let bounds = [0, 0, 0, 0];
1667
+ let revision = 0;
1668
+ return {
1669
+ bounds: () => bounds,
1670
+ version: () => revision,
1671
+ coverTopAt(x, z) {
1672
+ let top;
1673
+ for (const roof of roofs) {
1674
+ if (top !== void 0 && roof.top <= top || !insideTurned(roof, x, z)) continue;
1675
+ top = roof.top;
1676
+ }
1677
+ if (top === void 0) return void 0;
1678
+ for (const opening of openings) if (insideTurned(opening, x, z)) return void 0;
1679
+ return top;
1680
+ },
1681
+ set(footprints, cutouts, bumpVersion) {
1682
+ roofs = footprints.map(prepare);
1683
+ openings = cutouts.map(prepare);
1684
+ let x0 = Infinity;
1685
+ let z0 = Infinity;
1686
+ let x1 = -Infinity;
1687
+ let z1 = -Infinity;
1688
+ for (const roof of roofs) {
1689
+ const reach = Math.abs(roof.halfX * roof.cos) + Math.abs(roof.halfZ * roof.sin);
1690
+ const reachZ = Math.abs(roof.halfX * roof.sin) + Math.abs(roof.halfZ * roof.cos);
1691
+ x0 = Math.min(x0, roof.x - reach);
1692
+ x1 = Math.max(x1, roof.x + reach);
1693
+ z0 = Math.min(z0, roof.z - reachZ);
1694
+ z1 = Math.max(z1, roof.z + reachZ);
1695
+ }
1696
+ bounds = roofs.length === 0 ? [0, 0, 0, 0] : [x0, z0, x1, z1];
1697
+ if (bumpVersion) revision++;
1698
+ }
1699
+ };
1700
+ }
1649
1701
  var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
1650
1702
  var GAIT_IDS = ["walk", "run"];
1651
1703
  var LANDING_IDS = ["light", "heavy"];
@@ -3717,6 +3769,12 @@ var GameVehicles = (() => {
3717
3769
  this.particles = [];
3718
3770
  this.emitters = [];
3719
3771
  this.seatTops = [];
3772
+ this._seatsCache = null;
3773
+ this._doorsCache = null;
3774
+ this._rawSeats = [];
3775
+ this._explicitSeats = [];
3776
+ this._explicitDoors = [];
3777
+ this._noCabinRayObjs = /* @__PURE__ */ new Set();
3720
3778
  this.hood = null;
3721
3779
  this.rollState = null;
3722
3780
  this.flipped = false;
@@ -3918,6 +3976,32 @@ var GameVehicles = (() => {
3918
3976
  dirToEffects(d) {
3919
3977
  return d.clone().applyQuaternion(this.vehicle.quaternion);
3920
3978
  }
3979
+ /** Measured seat spaces in vehicle local coordinates (computed lazily on first read). */
3980
+ get seats() {
3981
+ if (this._seatsCache === null) kit.finalizeCabinSpaces(this);
3982
+ return this._seatsCache;
3983
+ }
3984
+ set seats(value) {
3985
+ this._seatsCache = value;
3986
+ }
3987
+ /** Measured door and hatch openings in vehicle local coordinates (computed lazily on first read). */
3988
+ get doors() {
3989
+ if (this._doorsCache === null) kit.finalizeCabinSpaces(this);
3990
+ return this._doorsCache;
3991
+ }
3992
+ set doors(value) {
3993
+ this._doorsCache = value;
3994
+ }
3995
+ /** Declares an explicit seat space (e.g. open motorcycle/quad saddle) preserved verbatim by cabin space finalisation. */
3996
+ addSeat(seat) {
3997
+ this._explicitSeats.push(seat);
3998
+ return seat;
3999
+ }
4000
+ /** Declares an explicit door or hatch opening preserved verbatim by cabin space finalisation. */
4001
+ addDoor(door) {
4002
+ this._explicitDoors.push(door);
4003
+ return door;
4004
+ }
3921
4005
  /** Declares or refines a damage zone: `c.zone(id, label, box, parts, options)`. Pass `label === false` to remove an auto-derived zone. */
3922
4006
  zone(id, label, box2, parts, o) {
3923
4007
  const d = Object.assign({ id }, o || {});
@@ -4849,7 +4933,8 @@ var GameVehicles = (() => {
4849
4933
  gp.userData.rigid = true;
4850
4934
  c.vehicle.add(gp);
4851
4935
  const n0 = c.seatTops.length;
4852
- kit.seat(c, 0, fl, 0, Object.assign({}, o, { face: null, parent: gp, dir: 1 }));
4936
+ const raw0 = c._rawSeats.length;
4937
+ kit.seat(c, 0, fl, 0, Object.assign({}, o, { face: void 0, parent: gp, dir: 1 }));
4853
4938
  const st = c.seatTops[n0];
4854
4939
  if (st) {
4855
4940
  st.x = x;
@@ -4858,6 +4943,17 @@ var GameVehicles = (() => {
4858
4943
  st.w = st.l;
4859
4944
  st.l = t;
4860
4945
  }
4946
+ const faceSign = o.face === "+z" ? 1 : -1;
4947
+ for (let idx = raw0; idx < c._rawSeats.length; idx++) {
4948
+ const entry = c._rawSeats[idx];
4949
+ const localZ = entry.hipPoint[2];
4950
+ c._rawSeats[idx] = {
4951
+ ...entry,
4952
+ hipPoint: [x - faceSign * localZ, entry.hipPoint[1], z],
4953
+ facing: [0, 0, faceSign],
4954
+ parent: null
4955
+ };
4956
+ }
4861
4957
  return gp;
4862
4958
  }
4863
4959
  const PR = o.parent;
@@ -4897,7 +4993,28 @@ var GameVehicles = (() => {
4897
4993
  });
4898
4994
  }
4899
4995
  }
4900
- c.seatTops.push({ x, y: fl + h + 0.01, z, w, l: cl });
4996
+ const hipY = fl + h + 0.01;
4997
+ c.seatTops.push({ x, y: hipY, z, w, l: cl });
4998
+ for (let j = 0; j < n; j++) {
4999
+ const zz = z + (j - (n - 1) / 2) * pw;
5000
+ c._rawSeats.push({
5001
+ id: o.id ? n > 1 ? `${o.id}_${j}` : o.id : void 0,
5002
+ role: o.role,
5003
+ hipPoint: [x, hipY, zz],
5004
+ seatWidth: pw,
5005
+ seatLen: cl,
5006
+ facing: [dir >= 0 ? 1 : -1, 0, 0],
5007
+ isBench: n > 1,
5008
+ benchIndex: j,
5009
+ benchCount: n,
5010
+ open: o.open,
5011
+ doorId: o.doorId,
5012
+ headroomMetres: o.headroomMetres,
5013
+ legroomMetres: o.legroomMetres,
5014
+ widthMetres: o.widthMetres,
5015
+ parent: PR ?? null
5016
+ });
5017
+ }
4901
5018
  };
4902
5019
  kit.steeringWheel = function(c, x, y, z, o) {
4903
5020
  o = o || {};
@@ -4920,6 +5037,9 @@ var GameVehicles = (() => {
4920
5037
  c.rod(new V3(5e-3, 0, 0), new V3(p[0], p[1] * 0.95, p[2] * 0.95), 0.016, mat, { parent: g, seg: 6 });
4921
5038
  });
4922
5039
  c.rod(new V3(0.03, 0, 0), new V3(o.col || 0.34, 0, 0), 0.032, mat, { parent: g, seg: 10 });
5040
+ g.traverse(function(node) {
5041
+ c._noCabinRayObjs.add(node);
5042
+ });
4923
5043
  return g;
4924
5044
  };
4925
5045
  kit.yoke = function(c, x, y, z, o) {
@@ -4986,8 +5106,8 @@ var GameVehicles = (() => {
4986
5106
  x: x0 - 0.07,
4987
5107
  y: belt + 0.04,
4988
5108
  w: zi * 2,
4989
- d: 0.5,
4990
- h: Math.min(0.42, belt + 0.04 - fl - 0.1),
5109
+ d: o.dashD ?? 0.5,
5110
+ h: o.dashH ?? Math.min(0.42, belt + 0.04 - fl - 0.1),
4991
5111
  drv: drv * zs,
4992
5112
  mat: trim,
4993
5113
  top: fab
@@ -5015,22 +5135,32 @@ var GameVehicles = (() => {
5015
5135
  if (r === 0) {
5016
5136
  if (o.front === "bench") {
5017
5137
  const wb = zi * 2 - 0.62;
5018
- kit.seat(c, x, fl, drv * zs, { w: 0.5, mat: fab, back, lean, h: seatH });
5019
- kit.seat(c, x, fl, -drv * (zi - wb / 2 - 0.03), { w: wb, n: 2, mat: fab, back, lean, h: seatH });
5138
+ kit.seat(c, x, fl, drv * zs, { w: 0.5, mat: fab, back, lean, h: seatH, id: "driver", role: "driver" });
5139
+ kit.seat(c, x, fl, -drv * (zi - wb / 2 - 0.03), { w: wb, n: 2, mat: fab, back, lean, h: seatH, role: "front_passenger" });
5020
5140
  } else {
5021
5141
  ;
5022
5142
  [-1, 1].forEach(function(s) {
5023
- kit.seat(c, x, fl, s * zs, { w: Math.min(0.52, zi - zs + 0.22), mat: fab, back, lean, h: seatH });
5143
+ const isDriver = s === drv;
5144
+ kit.seat(c, x, fl, s * zs, {
5145
+ w: Math.min(0.52, zi - zs + 0.22),
5146
+ mat: fab,
5147
+ back,
5148
+ lean,
5149
+ h: seatH,
5150
+ id: isDriver ? "driver" : void 0,
5151
+ role: isDriver ? "driver" : "front_passenger"
5152
+ });
5024
5153
  });
5025
5154
  if (!o.noConsole) consoleBox(c, x + 0.16, fl, Math.min(0.26, seatH), trim);
5026
5155
  }
5027
- } 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 });
5156
+ } 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" });
5157
+ const trimLen = Math.min(0.8, (o.rowPitch ?? 0.88) - 0.06);
5028
5158
  [-1, 1].forEach(function(s) {
5029
- c.roundBox(0.8, belt - fl - 0.08, 0.035, 0.015, trim, x + 0.12, (belt + fl) / 2 + 0.02, s * (zi + 0.02));
5159
+ c.roundBox(trimLen, belt - fl - 0.08, 0.035, 0.015, trim, x + 0.12, (belt + fl) / 2 + 0.02, s * (zi + 0.02));
5030
5160
  c.roundBox(0.3, 0.05, 0.07, 0.02, fab, x + 0.16, fl + seatH + 0.16, s * (zi - 0.015));
5031
5161
  c.roundBox(0.08, 0.025, 0.02, 8e-3, MATERIALS.chrome, x + 0.36, belt - 0.11, s * (zi - 5e-3));
5032
5162
  });
5033
- x -= r === 0 ? 0.88 : 0.8;
5163
+ x -= r === 0 ? o.rowPitch ?? 0.88 : 0.8;
5034
5164
  }
5035
5165
  if (o.ft != null) {
5036
5166
  const hx1 = o.ft - 0.04;
@@ -5040,7 +5170,11 @@ var GameVehicles = (() => {
5040
5170
  c.rod(new V3(o.ft - 0.1, roof - 0.02, 0), new V3(o.ft - 0.12, roof - 0.08, 0), 8e-3, MATERIALS.plastic, { seg: 5 });
5041
5171
  c.roundBox(0.03, 0.06, 0.22, 0.02, MATERIALS.plastic, o.ft - 0.12, roof - 0.11, 0);
5042
5172
  [-1, 1].forEach(function(s) {
5043
- c.roundBox(0.02, 0.15, 0.34, 0.01, MATERIALS.headliner, o.ft - 0.14, roof - 0.07, s * zs, { rot: [0, 0, 0.35] });
5173
+ if (o.visorUp) {
5174
+ c.roundBox(0.02, 0.07, 0.34, 0.01, MATERIALS.headliner, o.ft - 0.08, roof - 0.03, s * zs, { rot: [0, 0, 1.35] });
5175
+ } else {
5176
+ c.roundBox(0.02, 0.15, 0.34, 0.01, MATERIALS.headliner, o.ft - 0.14, roof - 0.07, s * zs, { rot: [0, 0, 0.35] });
5177
+ }
5044
5178
  });
5045
5179
  }
5046
5180
  };
@@ -5087,6 +5221,267 @@ var GameVehicles = (() => {
5087
5221
  return shared;
5088
5222
  }
5089
5223
 
5224
+ // src/cabin-space.ts
5225
+ var HEADROOM_RAY_OFFSETS = [
5226
+ [0, 0],
5227
+ [0.06, 0],
5228
+ [-0.06, 0],
5229
+ [0, -0.06],
5230
+ [0, 0.06]
5231
+ ];
5232
+ var HEADROOM_START_OFFSET = 0.02;
5233
+ var HEADROOM_MIN_HIT = 0.2;
5234
+ var LEGROOM_KNEE_OFFSET = 0.12;
5235
+ var LEGROOM_START_PAD = 0.02;
5236
+ var LEGROOM_MIN_HIT = 0.02;
5237
+ var SHOULDER_HEIGHT_OFFSET = 0.38;
5238
+ var SHOULDER_MIN_HIT = 0.14;
5239
+ var ROW_EPSILON = 0.25;
5240
+ var NEIGHBOR_ROW_TOLERANCE = 0.35;
5241
+ var DOOR_ROOF_TRIM = 0.05;
5242
+ var round4 = (value) => Number.isFinite(value) ? Math.round(value * 1e4) / 1e4 : value;
5243
+ function installCabinSpace(kit) {
5244
+ const THREE = kit.THREE;
5245
+ const V3 = THREE.Vector3;
5246
+ const raycaster = new THREE.Raycaster();
5247
+ const originVec = new V3();
5248
+ const dirVec = new V3();
5249
+ function castFirst(c, ox, oy, oz, dx, dy, dz, minDist) {
5250
+ originVec.set(ox, oy, oz);
5251
+ dirVec.set(dx, dy, dz);
5252
+ raycaster.set(originVec, dirVec);
5253
+ const hits = raycaster.intersectObject(c.vehicle, true);
5254
+ const ignored = c._noCabinRayObjs;
5255
+ for (let i = 0; i < hits.length; i++) {
5256
+ const h = hits[i];
5257
+ if (!h) continue;
5258
+ if (h.object.visible === false || h.object.userData?.noCabinRay === true || ignored?.has(h.object)) continue;
5259
+ if (h.distance >= minDist) return h.distance;
5260
+ }
5261
+ return Number.POSITIVE_INFINITY;
5262
+ }
5263
+ function measureHeadroom(c, hip) {
5264
+ let minClearance = Number.POSITIVE_INFINITY;
5265
+ for (let i = 0; i < HEADROOM_RAY_OFFSETS.length; i++) {
5266
+ const offset = HEADROOM_RAY_OFFSETS[i];
5267
+ const dist = castFirst(c, hip[0] + offset[0], hip[1] + HEADROOM_START_OFFSET, hip[2] + offset[1], 0, 1, 0, HEADROOM_MIN_HIT);
5268
+ const clear = Number.isFinite(dist) ? dist + HEADROOM_START_OFFSET : Number.POSITIVE_INFINITY;
5269
+ if (clear < minClearance) minClearance = clear;
5270
+ }
5271
+ return round4(minClearance);
5272
+ }
5273
+ function measureLegroom(c, hip, facing, seatLen) {
5274
+ const startOffset = seatLen / 2 + LEGROOM_START_PAD;
5275
+ const dist = castFirst(
5276
+ c,
5277
+ hip[0] + facing[0] * startOffset,
5278
+ hip[1] + LEGROOM_KNEE_OFFSET,
5279
+ hip[2] + facing[2] * startOffset,
5280
+ facing[0],
5281
+ 0,
5282
+ facing[2],
5283
+ LEGROOM_MIN_HIT
5284
+ );
5285
+ return Number.isFinite(dist) ? round4(startOffset + dist) : Number.POSITIVE_INFINITY;
5286
+ }
5287
+ function measureShoulderWidth(c, raw, allRaw, headroom) {
5288
+ const hip = raw.hipPoint;
5289
+ const fx = raw.facing[0];
5290
+ const fz = raw.facing[2];
5291
+ const lx = -fz;
5292
+ const lz = fx;
5293
+ const sy = hip[1] + SHOULDER_HEIGHT_OFFSET;
5294
+ const wallPos = castFirst(c, hip[0], sy, hip[2], lx, 0, lz, SHOULDER_MIN_HIT);
5295
+ const wallNeg = castFirst(c, hip[0], sy, hip[2], -lx, 0, -lz, SHOULDER_MIN_HIT);
5296
+ let neighborPos = Number.POSITIVE_INFINITY;
5297
+ let neighborNeg = Number.POSITIVE_INFINITY;
5298
+ for (let i = 0; i < allRaw.length; i++) {
5299
+ const other = allRaw[i];
5300
+ if (!other || other === raw) continue;
5301
+ const dx = other.hipPoint[0] - hip[0];
5302
+ const dy = Math.abs(other.hipPoint[1] - hip[1]);
5303
+ const dz = other.hipPoint[2] - hip[2];
5304
+ if (dy > NEIGHBOR_ROW_TOLERANCE) continue;
5305
+ const alongFacing = Math.abs(dx * fx + dz * fz);
5306
+ if (alongFacing > NEIGHBOR_ROW_TOLERANCE) continue;
5307
+ const alongLat = dx * lx + dz * lz;
5308
+ if (alongLat > 0.05 && alongLat / 2 < neighborPos) neighborPos = alongLat / 2;
5309
+ else if (alongLat < -0.05 && -alongLat / 2 < neighborNeg) neighborNeg = -alongLat / 2;
5310
+ }
5311
+ const halfFallback = Number.isFinite(headroom) ? raw.seatWidth / 2 : Number.POSITIVE_INFINITY;
5312
+ const posSpace = Math.min(wallPos, neighborPos);
5313
+ const negSpace = Math.min(wallNeg, neighborNeg);
5314
+ const leftAvail = Number.isFinite(posSpace) ? posSpace : halfFallback;
5315
+ const rightAvail = Number.isFinite(negSpace) ? negSpace : halfFallback;
5316
+ const total = leftAvail + rightAvail;
5317
+ return round4(total);
5318
+ }
5319
+ function collectDoors(c) {
5320
+ const records = [];
5321
+ const seen = /* @__PURE__ */ new Set();
5322
+ const explicit = c._explicitDoors || [];
5323
+ for (let i = 0; i < explicit.length; i++) {
5324
+ const d = explicit[i];
5325
+ if (seen.has(d.id)) continue;
5326
+ seen.add(d.id);
5327
+ const side2 = d.id.includes("left") ? -1 : d.id.includes("right") ? 1 : 0;
5328
+ records.push({ opening: d, center: [0, 0, side2], side: side2 });
5329
+ }
5330
+ const zones = c.zones || [];
5331
+ const cabin = c.meta?.cabin;
5332
+ const ghRoof = c.meta?.glasshouse?.roof;
5333
+ for (let i = 0; i < zones.length; i++) {
5334
+ const z = zones[i];
5335
+ if (!z || z.type !== "door" || !z.box || seen.has(z.id)) continue;
5336
+ seen.add(z.id);
5337
+ const b = z.box;
5338
+ const dx = Math.abs(b.x1 - b.x0);
5339
+ const dz = Math.abs(b.z1 - b.z0);
5340
+ const dy = Math.abs(b.y1 - b.y0);
5341
+ const isSideDoor = dx >= dz;
5342
+ const widthMetres = isSideDoor ? dx : dz;
5343
+ let heightMetres = dy;
5344
+ if (isSideDoor && ghRoof != null) {
5345
+ const floorY = cabin?.y0 != null ? cabin.y0 + 0.05 : b.y0;
5346
+ const roofY = ghRoof - DOOR_ROOF_TRIM;
5347
+ if (roofY - floorY > heightMetres) heightMetres = roofY - floorY;
5348
+ }
5349
+ const center = [(b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, (b.z0 + b.z1) / 2];
5350
+ const side2 = typeof z.side === "number" ? z.side : center[2] < -0.1 ? -1 : center[2] > 0.1 ? 1 : 0;
5351
+ records.push({
5352
+ opening: {
5353
+ id: z.id,
5354
+ widthMetres: round4(widthMetres),
5355
+ heightMetres: round4(heightMetres)
5356
+ },
5357
+ center,
5358
+ side: side2
5359
+ });
5360
+ }
5361
+ return records;
5362
+ }
5363
+ function pickDoorId(hip, doors) {
5364
+ if (doors.length === 0) return void 0;
5365
+ const seatSide = hip[2] < -0.05 ? -1 : hip[2] > 0.05 ? 1 : 0;
5366
+ let bestId;
5367
+ let bestScore = Number.POSITIVE_INFINITY;
5368
+ for (let i = 0; i < doors.length; i++) {
5369
+ const d = doors[i];
5370
+ const dx = d.center[0] - hip[0];
5371
+ const dz = d.center[2] - hip[2];
5372
+ const sidePenalty = seatSide !== 0 && d.side !== 0 && seatSide !== d.side ? 10 : 0;
5373
+ const score = dx * dx + dz * dz + sidePenalty;
5374
+ if (score < bestScore) {
5375
+ bestScore = score;
5376
+ bestId = d.opening.id;
5377
+ }
5378
+ }
5379
+ return bestId;
5380
+ }
5381
+ function inferRole(c, raw, maxX, driverAssigned) {
5382
+ if (raw.role) return raw.role;
5383
+ const kind = c.meta?.kind;
5384
+ if (kind === "bike") return "rider";
5385
+ if (kind === "tank") return "crew";
5386
+ if (Math.abs(raw.facing[2]) > 0.5) return "cargo";
5387
+ const isFrontRow = raw.hipPoint[0] >= maxX - ROW_EPSILON;
5388
+ if (kind === "plane" || kind === "heli") return isFrontRow ? "pilot" : "crew";
5389
+ if (isFrontRow) {
5390
+ if (!driverAssigned && raw.hipPoint[2] <= 0.05) return "driver";
5391
+ return "front_passenger";
5392
+ }
5393
+ return "rear";
5394
+ }
5395
+ function finalizeCabinSpaces(c) {
5396
+ c.root.updateMatrixWorld(true);
5397
+ const doorRecords = collectDoors(c);
5398
+ c.doors = doorRecords.map((r) => r.opening);
5399
+ const seats = [];
5400
+ const usedIds = /* @__PURE__ */ new Set();
5401
+ const pushSeat = (seat) => {
5402
+ let id = seat.id;
5403
+ if (usedIds.has(id)) {
5404
+ let suffix = 2;
5405
+ while (usedIds.has(`${id}_${suffix}`)) suffix++;
5406
+ id = `${id}_${suffix}`;
5407
+ }
5408
+ usedIds.add(id);
5409
+ seats.push(id === seat.id ? seat : { ...seat, id });
5410
+ };
5411
+ const explicit = c._explicitSeats || [];
5412
+ for (let i = 0; i < explicit.length; i++) {
5413
+ pushSeat(explicit[i]);
5414
+ }
5415
+ const invVehicle = new THREE.Matrix4().copy(c.vehicle.matrixWorld).invert();
5416
+ const tmpPoint = new V3();
5417
+ const rawSeats = (c._rawSeats || []).map((entry) => {
5418
+ if (!entry.parent || entry.parent === c.vehicle) return entry;
5419
+ entry.parent.updateMatrixWorld(true);
5420
+ tmpPoint.set(entry.hipPoint[0], entry.hipPoint[1], entry.hipPoint[2]).applyMatrix4(entry.parent.matrixWorld).applyMatrix4(invVehicle);
5421
+ return { ...entry, hipPoint: [tmpPoint.x, tmpPoint.y, tmpPoint.z] };
5422
+ });
5423
+ if (rawSeats.length === 0 && explicit.length === 0 && Array.isArray(c.seatTops) && c.seatTops.length > 0) {
5424
+ const isOpenBoat = c.meta?.kind === "boat";
5425
+ for (let i = 0; i < c.seatTops.length; i++) {
5426
+ const st = c.seatTops[i];
5427
+ rawSeats.push({
5428
+ hipPoint: [st.x, st.y, st.z],
5429
+ seatWidth: st.w,
5430
+ seatLen: st.l,
5431
+ facing: [1, 0, 0],
5432
+ isBench: false,
5433
+ benchIndex: 0,
5434
+ benchCount: 1,
5435
+ open: isOpenBoat
5436
+ });
5437
+ }
5438
+ }
5439
+ let maxX = Number.NEGATIVE_INFINITY;
5440
+ for (let i = 0; i < rawSeats.length; i++) {
5441
+ const x = rawSeats[i].hipPoint[0];
5442
+ if (x > maxX) maxX = x;
5443
+ }
5444
+ let driverAssigned = seats.some((s) => s.role === "driver");
5445
+ for (let i = 0; i < rawSeats.length; i++) {
5446
+ const raw = rawSeats[i];
5447
+ const role = inferRole(c, raw, maxX, driverAssigned);
5448
+ if (role === "driver") driverAssigned = true;
5449
+ const isOpen = raw.open === true;
5450
+ const headroomMetres = isOpen ? Number.POSITIVE_INFINITY : raw.headroomMetres != null ? round4(raw.headroomMetres) : measureHeadroom(c, raw.hipPoint);
5451
+ const legroomMetres = isOpen ? Number.POSITIVE_INFINITY : raw.legroomMetres != null ? round4(raw.legroomMetres) : measureLegroom(c, raw.hipPoint, raw.facing, raw.seatLen);
5452
+ const widthMetres = isOpen ? Number.POSITIVE_INFINITY : raw.widthMetres != null ? round4(raw.widthMetres) : measureShoulderWidth(c, raw, rawSeats, headroomMetres);
5453
+ const doorId = isOpen ? void 0 : raw.doorId !== void 0 ? raw.doorId : pickDoorId(raw.hipPoint, doorRecords);
5454
+ const sideTag = raw.hipPoint[2] < -0.05 ? "left" : raw.hipPoint[2] > 0.05 ? "right" : "center";
5455
+ const defaultId = role === "driver" ? "driver" : role === "front_passenger" ? `front_${sideTag}` : `${role}_${sideTag}`;
5456
+ const hipPoint = [round4(raw.hipPoint[0]), round4(raw.hipPoint[1]), round4(raw.hipPoint[2])];
5457
+ const seatSpace = doorId !== void 0 ? { id: raw.id ?? defaultId, role, hipPoint, headroomMetres, legroomMetres, widthMetres, doorId } : { id: raw.id ?? defaultId, role, hipPoint, headroomMetres, legroomMetres, widthMetres };
5458
+ pushSeat(seatSpace);
5459
+ }
5460
+ const kind = c.meta?.kind;
5461
+ if (seats.length === 0 && rawSeats.length === 0 && (kind === "bike" || kind === "quad")) {
5462
+ const zones = c.zones || [];
5463
+ const seatZone = zones.find((z) => z.id === "seat" && z.box);
5464
+ const hipPoint = seatZone?.box ? [
5465
+ round4((seatZone.box.x0 + seatZone.box.x1) / 2),
5466
+ round4(seatZone.box.y0 + (seatZone.box.y1 - seatZone.box.y0) * 0.75),
5467
+ round4((seatZone.box.z0 + seatZone.box.z1) / 2)
5468
+ ] : [round4(((c.meta?.rear ?? -1) + (c.meta?.front ?? 1)) * 0.25), round4((c.meta?.top ?? 1.1) * 0.75), 0];
5469
+ pushSeat({
5470
+ id: "rider",
5471
+ role: "rider",
5472
+ hipPoint,
5473
+ headroomMetres: Number.POSITIVE_INFINITY,
5474
+ legroomMetres: Number.POSITIVE_INFINITY,
5475
+ widthMetres: Number.POSITIVE_INFINITY
5476
+ });
5477
+ }
5478
+ c.seats = seats;
5479
+ }
5480
+ kit.finalizeCabinSpaces = finalizeCabinSpaces;
5481
+ kit._.finalizeCabinSpaces = finalizeCabinSpaces;
5482
+ return { finalizeCabinSpaces };
5483
+ }
5484
+
5090
5485
  // src/hood.ts
5091
5486
  var HOOD_LIFT = 8e-3;
5092
5487
  function installHood(kit) {
@@ -12883,6 +13278,7 @@ var GameVehicles = (() => {
12883
13278
  installGlass(kit);
12884
13279
  installLights(kit);
12885
13280
  installInterior(kit);
13281
+ installCabinSpace(kit);
12886
13282
  installHood(kit);
12887
13283
  installCar(kit);
12888
13284
  installTrucks(kit);
@@ -13192,6 +13588,102 @@ var GameVehicles = (() => {
13192
13588
  return found;
13193
13589
  }
13194
13590
 
13591
+ // src/destructible/door-shell.ts
13592
+ var DOOR_SHELL_DEPTH = 0.09;
13593
+ var DOOR_SHELL_MAX_DEPTH = 0.25;
13594
+ var WELD = 1e-5;
13595
+ var cellOf = (v) => Math.round(v / WELD);
13596
+ function weld(positions) {
13597
+ const ids = new Int32Array(positions.length / 3);
13598
+ const points = [];
13599
+ const cells = /* @__PURE__ */ new Map();
13600
+ const near = (x, y, z) => {
13601
+ const [cx, cy, cz] = [cellOf(x), cellOf(y), cellOf(z)];
13602
+ for (let i = -1; i <= 1; i++)
13603
+ for (let j = -1; j <= 1; j++)
13604
+ for (let k = -1; k <= 1; k++) {
13605
+ for (const id of cells.get(`${cx + i},${cy + j},${cz + k}`) ?? []) {
13606
+ if (Math.abs(points[id * 3] - x) <= WELD && Math.abs(points[id * 3 + 1] - y) <= WELD && Math.abs(points[id * 3 + 2] - z) <= WELD) return id;
13607
+ }
13608
+ }
13609
+ return void 0;
13610
+ };
13611
+ for (let i = 0; i < ids.length; i++) {
13612
+ const x = positions[i * 3];
13613
+ const y = positions[i * 3 + 1];
13614
+ const z = positions[i * 3 + 2];
13615
+ let id = near(x, y, z);
13616
+ if (id === void 0) {
13617
+ id = points.length / 3;
13618
+ points.push(x, y, z);
13619
+ const key = `${cellOf(x)},${cellOf(y)},${cellOf(z)}`;
13620
+ const cell = cells.get(key);
13621
+ if (cell) cell.push(id);
13622
+ else cells.set(key, [id]);
13623
+ }
13624
+ ids[i] = id;
13625
+ }
13626
+ return { ids, points };
13627
+ }
13628
+ function freeEdgesOf(ids) {
13629
+ const uses = /* @__PURE__ */ new Map();
13630
+ for (let t = 0; t < ids.length; t += 3) {
13631
+ for (let k = 0; k < 3; k++) {
13632
+ const a = ids[t + k];
13633
+ const b = ids[t + (k + 1) % 3];
13634
+ if (a === b) continue;
13635
+ const key = a < b ? `${a}:${b}` : `${b}:${a}`;
13636
+ const use = uses.get(key);
13637
+ if (use) use.count++;
13638
+ else uses.set(key, { count: 1, from: a, to: b });
13639
+ }
13640
+ }
13641
+ const free = [];
13642
+ uses.forEach((use) => {
13643
+ if (use.count === 1) free.push([use.from, use.to]);
13644
+ });
13645
+ return free;
13646
+ }
13647
+ function doorShell(params) {
13648
+ const depth = params.depth ?? DOOR_SHELL_DEPTH;
13649
+ const [ox, oy, oz] = params.outward ?? [0, 0, params.side < 0 ? -1 : 1];
13650
+ const { positions } = params;
13651
+ const along = (i) => positions[i] * ox + positions[i + 1] * oy + positions[i + 2] * oz;
13652
+ let outermost = -Infinity;
13653
+ for (let i = 0; i < positions.length; i += 3) outermost = Math.max(outermost, along(i));
13654
+ const floor = outermost - DOOR_SHELL_MAX_DEPTH;
13655
+ const sink = (x, y, z) => {
13656
+ const move = Math.max(0, Math.min(depth, x * ox + y * oy + z * oz - floor));
13657
+ return [x - ox * move, y - oy * move, z - oz * move];
13658
+ };
13659
+ const inner = new Float32Array(positions.length);
13660
+ for (let t = 0; t < positions.length; t += 9) {
13661
+ for (const [to, from] of [
13662
+ [0, 0],
13663
+ [1, 2],
13664
+ [2, 1]
13665
+ ]) {
13666
+ inner.set(sink(positions[t + from * 3], positions[t + from * 3 + 1], positions[t + from * 3 + 2]), t + to * 3);
13667
+ }
13668
+ }
13669
+ const { ids, points } = weld(positions);
13670
+ const free = freeEdgesOf(ids);
13671
+ const flange = new Float32Array(free.length * 18);
13672
+ const corner = (id, sunk) => {
13673
+ const [x, y, z] = [points[id * 3], points[id * 3 + 1], points[id * 3 + 2]];
13674
+ return sunk ? sink(x, y, z) : [x, y, z];
13675
+ };
13676
+ free.forEach(([a, b], i) => {
13677
+ const quad = [corner(b, false), corner(a, false), corner(a, true), corner(b, false), corner(a, true), corner(b, true)];
13678
+ quad.forEach((p, k) => flange.set(p, i * 18 + k * 3));
13679
+ });
13680
+ return { flange, inner, freeEdges: free.length };
13681
+ }
13682
+ function openEdgeCount(positions, minLength = 0) {
13683
+ const { ids, points } = weld(positions);
13684
+ return freeEdgesOf(ids).filter(([a, b]) => Math.hypot(points[a * 3] - points[b * 3], points[a * 3 + 1] - points[b * 3 + 1], points[a * 3 + 2] - points[b * 3 + 2]) > minLength).length;
13685
+ }
13686
+
13195
13687
  // src/destructible/armour.ts
13196
13688
  var ARMOUR_LEVELS = {
13197
13689
  IIIA: { glassStops: 1700, glassHp: 6e3, glassTakes: 0.25, steel: 8 },
@@ -14029,12 +14521,75 @@ var GameVehicles = (() => {
14029
14521
  if (centre.y < zone.y0 || centre.y > zone.y1) return false;
14030
14522
  return Math.abs(centre.x - zone.x0) < SEAM_AT_EDGE || Math.abs(centre.x - zone.x1) < SEAM_AT_EDGE;
14031
14523
  }
14524
+ function closeDoorSkin(three, meshes, params) {
14525
+ const THREE = three;
14526
+ const toVehicle = params.toVehicle;
14527
+ const positions = [];
14528
+ const at = new THREE.Vector3();
14529
+ for (const mesh2 of meshes) {
14530
+ const geometry = mesh2.geometry.index ? mesh2.geometry.toNonIndexed() : mesh2.geometry;
14531
+ const matrix = new THREE.Matrix4().multiplyMatrices(toVehicle, mesh2.matrixWorld);
14532
+ const position = geometry.getAttribute("position");
14533
+ for (let i = 0; i < position.count; i++) {
14534
+ at.fromBufferAttribute(position, i).applyMatrix4(matrix);
14535
+ positions.push(at.x, at.y, at.z);
14536
+ }
14537
+ if (geometry !== mesh2.geometry) geometry.dispose();
14538
+ }
14539
+ if (!positions.length) return [];
14540
+ const shell = doorShell({ positions, side: params.side, ...params.outward ? { outward: params.outward } : {} });
14541
+ const out = [];
14542
+ for (const [array, material] of [
14543
+ [shell.flange, params.paint],
14544
+ [shell.inner, params.liner]
14545
+ ]) {
14546
+ if (!array.length) continue;
14547
+ const geometry = new THREE.BufferGeometry();
14548
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(array, 3));
14549
+ geometry.computeVertexNormals();
14550
+ geometry.computeBoundingBox();
14551
+ geometry.computeBoundingSphere();
14552
+ out.push(new THREE.Mesh(geometry, material));
14553
+ }
14554
+ return out;
14555
+ }
14556
+
14557
+ // src/destructible/trunk-bay.ts
14558
+ var TRUNK_FLOOR_OVER_CLEARANCE = 0.12;
14559
+ var TRUNK_INSET = 0.05;
14560
+ var TRUNK_SEAL = 0.025;
14561
+ function buildTrunkBay(THREE, params) {
14562
+ const B = params.box;
14563
+ const floor = Math.max(B.y0, params.clearance + TRUNK_FLOOR_OVER_CLEARANCE);
14564
+ const top = B.y1 - TRUNK_INSET;
14565
+ const length = B.x1 - B.x0 - 2 * TRUNK_INSET;
14566
+ const width = B.z1 - B.z0 - 2 * TRUNK_INSET;
14567
+ if (length <= 0 || width <= 0 || top <= floor) return [];
14568
+ params.carpet.side = THREE.BackSide;
14569
+ const open = new THREE.MeshBasicMaterial({ visible: false });
14570
+ const tub = new THREE.Mesh(new THREE.BoxGeometry(length, top - floor, width), [params.carpet, params.carpet, open, params.carpet, params.carpet, params.carpet]);
14571
+ tub.position.set((B.x0 + B.x1) / 2, (floor + top) / 2, (B.z0 + B.z1) / 2);
14572
+ const seal = new THREE.Mesh(new THREE.BoxGeometry(TRUNK_SEAL, TRUNK_SEAL, width), params.seal);
14573
+ seal.position.set(B.x0 + TRUNK_INSET, top, (B.z0 + B.z1) / 2);
14574
+ for (const mesh2 of [tub, seal]) {
14575
+ mesh2.castShadow = false;
14576
+ mesh2.userData.noFollow = true;
14577
+ mesh2.userData.trunkBay = true;
14578
+ }
14579
+ return [tub, seal];
14580
+ }
14032
14581
 
14033
14582
  // src/destructible/visual.ts
14034
14583
  var HOLE_DECAL_SCALE = 2.4;
14035
14584
  var HOLE_BATCH_CAPACITY = 64;
14036
14585
  var DOOR_DEPTH = 0.07;
14037
14586
  var DOOR_SKIN_DEPTH = 0.09;
14587
+ var LID_OUTWARD = [-Math.SQRT1_2, Math.SQRT1_2, 0];
14588
+ var TRUNK_CARPET_COLOR = "#3a3c3f";
14589
+ var TRUNK_SEAL_COLOR = "#2a2b2d";
14590
+ var DOOR_TRIM_MARGIN = 0.03;
14591
+ var DOOR_TRIM_SIZE = 0.3;
14592
+ var LID_HINGE_INSET = 0.02;
14038
14593
  var DOOR_FLOOR_DEPTH = 0.2;
14039
14594
  var DOOR_EDGE_PIECES = 8;
14040
14595
  var DOOR_EDGE_REACH = 0.08;
@@ -14342,10 +14897,11 @@ var GameVehicles = (() => {
14342
14897
  const piv = new THREE.Group();
14343
14898
  piv.name = p.id;
14344
14899
  piv.userData.plateOf = p.id;
14345
- piv.position.set(sk - 0.016, B.y1 - 0.05, 0);
14900
+ const hinge = { x: B.x1 - LID_HINGE_INSET, y: B.y1 - LID_HINGE_INSET };
14901
+ piv.position.set(hinge.x, hinge.y, 0);
14346
14902
  piv.userData.rigid = true;
14347
14903
  this.c.vehicle.add(piv);
14348
- const panel = this.box(0.022, wy, wz, this.paint(), 0, -wy / 2, 0, piv);
14904
+ const panel = this.box(0.022, wy, wz, this.paint(), sk - 0.016 - hinge.x, B.y1 - 0.05 - hinge.y - wy / 2, 0, piv);
14349
14905
  this.plates.set(p.id, piv);
14350
14906
  this.extra.set(`recess_${p.id}`, [recess]);
14351
14907
  this.showWhenOpen(p.id, piv, panel, recess);
@@ -14424,12 +14980,16 @@ var GameVehicles = (() => {
14424
14980
  const seals = panes.map((g) => I.paneSeals.get(g)).filter((s) => !!s);
14425
14981
  const mirrors = this.mirrorsOn(z);
14426
14982
  const frames = this.framesAround(panes, inv);
14427
- const followers = I.followersIn(this.c, z, inv).filter((o) => !this.takeSeam(o, id, z, inv) && !this.inFloor(o, piv, z, inv));
14428
- objs = [...pcs, ...followers, ...panes, ...seals, ...mirrors, ...frames];
14983
+ const thin = I.followersIn(this.c, z, inv);
14984
+ const followers = [...thin, ...this.doorTrimIn(z, inv).filter((o) => !thin.includes(o))].filter((o) => !this.takeSeam(o, id, z, inv) && !this.inFloor(o, piv, z, inv));
14985
+ objs = [...pcs, ...this.shellOf(pcs, z, inv), ...followers, ...panes, ...seals, ...mirrors, ...frames];
14429
14986
  }
14430
14987
  } else {
14431
14988
  const pcs = this.cutZone(z);
14432
- if (pcs.length) objs = [...pcs, ...I.followersIn(this.c, z, inv)];
14989
+ if (pcs.length) {
14990
+ objs = [...pcs, ...this.shellOf(pcs, z, inv, LID_OUTWARD), ...I.followersIn(this.c, z, inv)];
14991
+ this.trunkBay(z);
14992
+ }
14433
14993
  }
14434
14994
  } catch {
14435
14995
  objs = [];
@@ -14445,7 +15005,7 @@ var GameVehicles = (() => {
14445
15005
  if (di >= 0) deform.splice(di, 1);
14446
15006
  }
14447
15007
  if (p.role === "door" && objs.length > 0) {
14448
- this.doorEdges(piv, z, this.doorTops.get(id) ?? B.y1 - 0.02);
15008
+ this.doorEdges(piv, z, this.doorTops.get(id) ?? B.y1 - 0.02, objs.some((o) => o.userData.doorShell));
14449
15009
  this.liftDoorTrim(objs, z);
14450
15010
  this.cutStripsAcross(piv, z, inv);
14451
15011
  }
@@ -14453,6 +15013,48 @@ var GameVehicles = (() => {
14453
15013
  this.c.root.updateMatrixWorld(true);
14454
15014
  return objs.length > 0;
14455
15015
  }
15016
+ /** The skin closed into a door with depth: the fold all round its real edge, in the paint, and the inner panel behind it, in the door card's grey. */
15017
+ shellOf(skin, z, inv, outward) {
15018
+ const paint = this.paint().clone();
15019
+ paint.side = this.THREE.DoubleSide;
15020
+ const liner = this.I.makeMaterial(DOOR_CARD_COLOR, { roughness: 0.85 }).clone();
15021
+ liner.side = this.THREE.DoubleSide;
15022
+ for (const piece of skin) piece.userData.doorSkin = true;
15023
+ const meshes = closeDoorSkin(this.THREE, skin, { toVehicle: inv, side: z.side < 0 ? -1 : 1, paint, liner, ...outward ? { outward } : {} });
15024
+ meshes.forEach((mesh2, i) => {
15025
+ mesh2.userData.doorShell = meshes.length === 2 && i === 0 ? "fold" : "inner";
15026
+ mesh2.castShadow = false;
15027
+ this.c.vehicle.add(mesh2);
15028
+ });
15029
+ return meshes;
15030
+ }
15031
+ /**
15032
+ * The trunk under a lid that opens: a tub lined in carpet (floor, sides, the front wall at the back seat) under the opening, and the rubber seal
15033
+ * along the sill, so the opening shows the luggage space and not the dark inside of the body.
15034
+ */
15035
+ trunkBay(z) {
15036
+ const carpet = this.I.makeMaterial(TRUNK_CARPET_COLOR, { roughness: 0.95 }).clone();
15037
+ const seal = this.I.makeMaterial(TRUNK_SEAL_COLOR, { roughness: 0.7 });
15038
+ for (const mesh2 of buildTrunkBay(this.THREE, { box: z.box, clearance: this.c.meta.clearance ?? 0.3, carpet, seal })) this.c.vehicle.add(mesh2);
15039
+ }
15040
+ /**
15041
+ * The small parts the model draws inside the door (the inner pull and its bezel, the lock knob, a speaker): they stand deeper than the thin
15042
+ * trim the followers take, but sit within the door, so they swing with it instead of staying in the air over the opening.
15043
+ */
15044
+ doorTrimIn(z, inv) {
15045
+ const B = z.box;
15046
+ const THREE = this.THREE;
15047
+ const deform = new Set(this.c.deform ?? []);
15048
+ return this.c.vehicle.children.filter((o) => {
15049
+ if (!o.isMesh || !o.visible || deform.has(o) || o.userData.decal || o.userData.glass || o.userData.noFollow || this.c.wheels.includes(o)) return false;
15050
+ const box2 = this.I.localBox(this.c, o, inv);
15051
+ if (box2.isEmpty()) return false;
15052
+ const centre = box2.getCenter(new THREE.Vector3());
15053
+ const size = box2.getSize(new THREE.Vector3());
15054
+ const inside = centre.x > B.x0 - DOOR_TRIM_MARGIN && centre.x < B.x1 + DOOR_TRIM_MARGIN && centre.y > B.y0 && centre.y < B.y1 && centre.z > B.z0 - DOOR_TRIM_MARGIN && centre.z < B.z1 + DOOR_TRIM_MARGIN;
15055
+ return inside && Math.max(size.x, size.y, size.z) <= DOOR_TRIM_SIZE;
15056
+ });
15057
+ }
14456
15058
  /** A thin part at the foot of the opening, well inside the skin (a step, a sill trim, a rail on the floor), is the floor's: it does not swing with the door. */
14457
15059
  inFloor(o, piv, z, inv) {
14458
15060
  const side2 = z.side < 0 ? -1 : 1;
@@ -14473,7 +15075,7 @@ var GameVehicles = (() => {
14473
15075
  return true;
14474
15076
  }
14475
15077
  /** A door has edges: a band that follows the skin all round closes it to its card and hides where the cut followed the triangles of the shell; the same band, in the same paint as on a real car, lines the opening. */
14476
- doorEdges(piv, z, y1) {
15078
+ doorEdges(piv, z, y1, closed) {
14477
15079
  const THREE = this.THREE;
14478
15080
  const B = z.box;
14479
15081
  const side2 = z.side < 0 ? -1 : 1;
@@ -14493,13 +15095,13 @@ var GameVehicles = (() => {
14493
15095
  const at = this.surface("z", side2, B, [[x, y]]);
14494
15096
  return at != null && Math.abs(at - flat) < DOOR_EDGE_REACH ? at : flat;
14495
15097
  });
14496
- const band = (lift, path, closed) => {
15098
+ const band = (lift, path, closed2) => {
14497
15099
  const position = [];
14498
15100
  const index = [];
14499
15101
  path.forEach((at, i) => {
14500
15102
  const [x, y] = loop[at];
14501
15103
  position.push(x, y, heights[at] + side2 * lift, x, y, heights[at] + side2 * (lift - DOOR_DEPTH));
14502
- if (!closed && i === path.length - 1) return;
15104
+ if (!closed2 && i === path.length - 1) return;
14503
15105
  const a = i * 2;
14504
15106
  const b = (i + 1) % path.length * 2;
14505
15107
  index.push(a, a + 1, b, b, a + 1, b + 1);
@@ -14525,21 +15127,18 @@ var GameVehicles = (() => {
14525
15127
  const cardMaterial = this.I.makeMaterial(DOOR_CARD_COLOR, { roughness: 0.85 }).clone();
14526
15128
  cardMaterial.side = THREE.DoubleSide;
14527
15129
  const card = new THREE.Mesh(cardGeometry, cardMaterial);
14528
- card.userData.noFollow = true;
14529
- card.castShadow = false;
14530
- this.c.vehicle.add(card);
14531
- piv.attach(card);
14532
15130
  const all = loop.map((_, i) => i);
14533
15131
  const top = 2 * DOOR_EDGE_PIECES;
14534
15132
  const sides = [...all.slice(3 * DOOR_EDGE_PIECES), ...all.slice(0, top + 1)];
14535
15133
  const edges = new THREE.Mesh(band(2e-3, all, true), paint);
14536
15134
  const lining = new THREE.Mesh(band(2e-3, sides, false), paint);
14537
- for (const m of [edges, lining]) {
15135
+ const onDoor = closed ? [] : [card, edges];
15136
+ for (const m of [...onDoor, lining]) {
14538
15137
  m.userData.noFollow = true;
14539
15138
  m.castShadow = false;
14540
15139
  this.c.vehicle.add(m);
14541
15140
  }
14542
- piv.attach(edges);
15141
+ for (const m of onDoor) piv.attach(m);
14543
15142
  }
14544
15143
  /** The frame the model draws round a door's window (a dark strip over the glass) goes with the door: left behind it hangs in the air over the opening. */
14545
15144
  framesAround(panes, inv) {
@@ -15552,6 +16151,7 @@ var GameVehicles = (() => {
15552
16151
  };
15553
16152
 
15554
16153
  // src/destructible/clips.ts
16154
+ var LID_OPEN = 1.31;
15555
16155
  var DURATION = 1.2;
15556
16156
  function createVehicleClips(model, vis, kit, c) {
15557
16157
  const zones = kit.zonesOf(c);
@@ -15564,7 +16164,7 @@ var GameVehicles = (() => {
15564
16164
  if (!z || vis && !vis.plates.has(p.id)) continue;
15565
16165
  const sgn = z.hinge === "rear" ? -1 : 1;
15566
16166
  doors[p.id] = { rotation: [0, (z.side < 0 ? -1 : 1) * sgn * 1.15, 0] };
15567
- } else if (p.role === "lid" && (!vis || vis.plates.has(p.id))) lid[p.id] = { rotation: [0, 0, -1.15] };
16167
+ } else if (p.role === "lid" && (!vis || vis.plates.has(p.id))) lid[p.id] = { rotation: [0, 0, -LID_OPEN] };
15568
16168
  else if (p.role === "hood" && (!vis || vis.hood?.id === p.id)) hood[p.id] = { rotation: [0, 0, (vis?.hood?.open ?? c.hood?.open ?? 1) * (vis?.hood?.sign ?? c.hood?.sign ?? 1)] };
15569
16169
  }
15570
16170
  const clips = [];
@@ -16929,6 +17529,132 @@ var GameVehicles = (() => {
16929
17529
  };
16930
17530
  }
16931
17531
 
17532
+ // src/destructible/rain-cover.ts
17533
+ var RAIN_OPENING_DIAMETER = 0.3;
17534
+ var RAIN_MOVE_STEP = 1;
17535
+ var RAIN_TURN_STEP = 0.08;
17536
+ var UPRIGHT = 0.7;
17537
+ var GONE2 = /* @__PURE__ */ new Set(["broken", "melted", "ashes"]);
17538
+ var COVERING_ROLES = /* @__PURE__ */ new Set(["roof"]);
17539
+ var COVERED_KINDS = /* @__PURE__ */ new Set(["car", "bus", "truck"]);
17540
+ var TALL_PANEL = 1.5;
17541
+ var NEAR_TOP = 0.85;
17542
+ var BODY_PANELS = 3;
17543
+ var OPENING_ROLES = /* @__PURE__ */ new Set(["roof", "glass"]);
17544
+ function bodyRoof(source, alive, kind) {
17545
+ const top = source.vehicle.meta.top;
17546
+ if (!COVERED_KINDS.has(kind) || top === void 0 || source.model.parts.some((def) => COVERING_ROLES.has(def.role))) return null;
17547
+ const panels = source.model.parts.filter((def) => def.role === "panel" && def.box.size[1] >= TALL_PANEL && def.box.center[1] + def.box.size[1] / 2 >= top * NEAR_TOP && alive(def.id));
17548
+ if (panels.length < BODY_PANELS) return null;
17549
+ const x0 = Math.min(...panels.map((def) => def.box.center[0] - def.box.size[0] / 2));
17550
+ const x1 = Math.max(...panels.map((def) => def.box.center[0] + def.box.size[0] / 2));
17551
+ const z1 = Math.max(...panels.map((def) => Math.abs(def.box.center[2]) + def.box.size[2] / 2));
17552
+ return { x: (x0 + x1) / 2, z: 0, halfX: (x1 - x0) / 2, halfZ: z1, top: Math.max(...panels.map((def) => def.box.center[1] + def.box.size[1] / 2)) };
17553
+ }
17554
+ var hasMoved = (elements, last) => {
17555
+ for (let index = 0; index < 16; index++) if (elements[index] !== last[index]) return true;
17556
+ return false;
17557
+ };
17558
+ var localOf = (box2, top = box2.center[1] + box2.size[1] / 2) => ({ x: box2.center[0], z: box2.center[2], halfX: box2.size[0] / 2, halfZ: box2.size[2] / 2, top });
17559
+ function createVehicleRainCover(source, options = {}) {
17560
+ const vehicle = source.vehicle;
17561
+ const node = vehicle.vehicle;
17562
+ const cabin = cabinBoxOf(vehicle);
17563
+ const cover = createFootprintRainCover();
17564
+ let roofs = [];
17565
+ let openings = [];
17566
+ let isShellChanged = true;
17567
+ let bumpedX = Infinity;
17568
+ let bumpedZ = Infinity;
17569
+ let bumpedYaw = 0;
17570
+ const placedAt = new Float64Array(16);
17571
+ const refreshShell = () => {
17572
+ if (!node?.localToWorld) return;
17573
+ const state = source.state();
17574
+ const byId = new Map(state.parts.map((part) => [part.id, part]));
17575
+ const mainGroup = state.groups[0] ? new Set(state.groups[0]) : null;
17576
+ const alive = (id) => {
17577
+ const part = byId.get(id);
17578
+ return part !== void 0 && !GONE2.has(part.status) && (mainGroup === null || mainGroup.has(id));
17579
+ };
17580
+ const nextRoofs = [];
17581
+ const nextOpenings = [];
17582
+ const roofParts = source.model.parts.filter((def) => COVERING_ROLES.has(def.role));
17583
+ const kind = String(vehicle.meta.kind);
17584
+ const hull = bodyRoof(source, alive, kind);
17585
+ const hasRoof = COVERED_KINDS.has(kind) && (roofParts.some((def) => alive(def.id)) || hull !== null);
17586
+ if (!state.destroyed && hasRoof) {
17587
+ if (roofParts.some((def) => alive(def.id))) {
17588
+ if (cabin) nextRoofs.push({ x: (cabin.x0 + cabin.x1) / 2, z: 0, halfX: (cabin.x1 - cabin.x0) / 2, halfZ: cabin.z, top: cabin.y0 + (cabin.y1 - cabin.y0) / 2 });
17589
+ for (const def of source.model.parts) {
17590
+ if (!alive(def.id) || !(COVERING_ROLES.has(def.role) || cabin && def.role === "glass")) continue;
17591
+ nextRoofs.push(localOf(def.box));
17592
+ }
17593
+ } else if (hull) {
17594
+ nextRoofs.push(hull);
17595
+ }
17596
+ for (const def of source.model.parts) {
17597
+ if (!OPENING_ROLES.has(def.role) || !(cabin || hull || COVERING_ROLES.has(def.role))) continue;
17598
+ if (!alive(def.id)) nextOpenings.push(localOf(def.box));
17599
+ }
17600
+ const frame = options.frame ?? vehicle.root;
17601
+ frame?.updateWorldMatrix?.(true, false);
17602
+ node.updateWorldMatrix?.(true, false);
17603
+ const inverse = node.matrixWorld.clone().invert();
17604
+ const V3 = node.position.constructor;
17605
+ for (const def of source.model.parts) {
17606
+ if (!OPENING_ROLES.has(def.role) || !alive(def.id)) continue;
17607
+ for (const hole of byId.get(def.id).holes) {
17608
+ if (!hole.through || hole.diameter < RAIN_OPENING_DIAMETER || !frame?.localToWorld) continue;
17609
+ const point = new V3(hole.point[0], hole.point[1], hole.point[2]);
17610
+ frame.localToWorld(point);
17611
+ point.applyMatrix4(inverse);
17612
+ nextOpenings.push({ x: point.x, z: point.z, halfX: hole.diameter / 2, halfZ: hole.diameter / 2, top: 0 });
17613
+ }
17614
+ }
17615
+ }
17616
+ roofs = nextRoofs;
17617
+ openings = nextOpenings;
17618
+ isShellChanged = true;
17619
+ };
17620
+ const place = () => {
17621
+ if (!node) return;
17622
+ node.updateWorldMatrix?.(true, false);
17623
+ const e = node.matrixWorld.elements;
17624
+ if (!isShellChanged && !hasMoved(e, placedAt)) return;
17625
+ placedAt.set(e);
17626
+ const scaleY = Math.hypot(e[4], e[5], e[6]);
17627
+ if (roofs.length === 0 || e[5] / (scaleY || 1) < UPRIGHT) {
17628
+ if (isShellChanged || bumpedX !== Infinity) cover.set([], [], true);
17629
+ bumpedX = Infinity;
17630
+ isShellChanged = false;
17631
+ return;
17632
+ }
17633
+ const scaleX = Math.hypot(e[0], e[1], e[2]);
17634
+ const scaleZ = Math.hypot(e[8], e[9], e[10]);
17635
+ const yaw = Math.atan2(e[2], e[0]);
17636
+ const toWorld = (f) => ({
17637
+ x: e[0] * f.x + e[4] * f.top + e[8] * f.z + e[12],
17638
+ z: e[2] * f.x + e[6] * f.top + e[10] * f.z + e[14],
17639
+ halfX: f.halfX * scaleX,
17640
+ halfZ: f.halfZ * scaleZ,
17641
+ yaw,
17642
+ top: e[1] * f.x + e[5] * f.top + e[9] * f.z + e[13]
17643
+ });
17644
+ const moved = Math.hypot(e[12] - bumpedX, e[14] - bumpedZ) >= RAIN_MOVE_STEP || Math.abs(yaw - bumpedYaw) >= RAIN_TURN_STEP;
17645
+ const isBump = isShellChanged || moved;
17646
+ cover.set(roofs.map(toWorld), openings.map(toWorld), isBump);
17647
+ isShellChanged = false;
17648
+ if (isBump) {
17649
+ bumpedX = e[12];
17650
+ bumpedZ = e[14];
17651
+ bumpedYaw = yaw;
17652
+ }
17653
+ };
17654
+ refreshShell();
17655
+ return { source: cover, refreshShell, place };
17656
+ }
17657
+
16932
17658
  // src/data/cabin.json
16933
17659
  var cabin_default = {
16934
17660
  source: "Spec 012 (R6, T0.2) \u2014 SAE J1100 interior packaging & ISO 7250-1 / NASA-STD-3000 adult anthropometry (1.80 m seated height = 0.936 m, buttock-knee = 0.612 m, shoulder = 0.468 m)",