@adatechnology/game-vehicles 0.6.21 → 0.7.0

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
@@ -1890,6 +1890,12 @@ function installContext(kit) {
1890
1890
  this.particles = [];
1891
1891
  this.emitters = [];
1892
1892
  this.seatTops = [];
1893
+ this._seatsCache = null;
1894
+ this._doorsCache = null;
1895
+ this._rawSeats = [];
1896
+ this._explicitSeats = [];
1897
+ this._explicitDoors = [];
1898
+ this._noCabinRayObjs = /* @__PURE__ */ new Set();
1893
1899
  this.hood = null;
1894
1900
  this.rollState = null;
1895
1901
  this.flipped = false;
@@ -2091,6 +2097,32 @@ function installContext(kit) {
2091
2097
  dirToEffects(d) {
2092
2098
  return d.clone().applyQuaternion(this.vehicle.quaternion);
2093
2099
  }
2100
+ /** Measured seat spaces in vehicle local coordinates (computed lazily on first read). */
2101
+ get seats() {
2102
+ if (this._seatsCache === null) kit.finalizeCabinSpaces(this);
2103
+ return this._seatsCache;
2104
+ }
2105
+ set seats(value) {
2106
+ this._seatsCache = value;
2107
+ }
2108
+ /** Measured door and hatch openings in vehicle local coordinates (computed lazily on first read). */
2109
+ get doors() {
2110
+ if (this._doorsCache === null) kit.finalizeCabinSpaces(this);
2111
+ return this._doorsCache;
2112
+ }
2113
+ set doors(value) {
2114
+ this._doorsCache = value;
2115
+ }
2116
+ /** Declares an explicit seat space (e.g. open motorcycle/quad saddle) preserved verbatim by cabin space finalisation. */
2117
+ addSeat(seat) {
2118
+ this._explicitSeats.push(seat);
2119
+ return seat;
2120
+ }
2121
+ /** Declares an explicit door or hatch opening preserved verbatim by cabin space finalisation. */
2122
+ addDoor(door) {
2123
+ this._explicitDoors.push(door);
2124
+ return door;
2125
+ }
2094
2126
  /** Declares or refines a damage zone: `c.zone(id, label, box, parts, options)`. Pass `label === false` to remove an auto-derived zone. */
2095
2127
  zone(id, label, box, parts, o) {
2096
2128
  const d = Object.assign({ id }, o || {});
@@ -3022,7 +3054,8 @@ function installInterior(kit) {
3022
3054
  gp.userData.rigid = true;
3023
3055
  c.vehicle.add(gp);
3024
3056
  const n0 = c.seatTops.length;
3025
- kit.seat(c, 0, fl, 0, Object.assign({}, o, { face: null, parent: gp, dir: 1 }));
3057
+ const raw0 = c._rawSeats.length;
3058
+ kit.seat(c, 0, fl, 0, Object.assign({}, o, { face: void 0, parent: gp, dir: 1 }));
3026
3059
  const st = c.seatTops[n0];
3027
3060
  if (st) {
3028
3061
  st.x = x;
@@ -3031,6 +3064,17 @@ function installInterior(kit) {
3031
3064
  st.w = st.l;
3032
3065
  st.l = t;
3033
3066
  }
3067
+ const faceSign = o.face === "+z" ? 1 : -1;
3068
+ for (let idx = raw0; idx < c._rawSeats.length; idx++) {
3069
+ const entry = c._rawSeats[idx];
3070
+ const localZ = entry.hipPoint[2];
3071
+ c._rawSeats[idx] = {
3072
+ ...entry,
3073
+ hipPoint: [x - faceSign * localZ, entry.hipPoint[1], z],
3074
+ facing: [0, 0, faceSign],
3075
+ parent: null
3076
+ };
3077
+ }
3034
3078
  return gp;
3035
3079
  }
3036
3080
  const PR = o.parent;
@@ -3070,7 +3114,28 @@ function installInterior(kit) {
3070
3114
  });
3071
3115
  }
3072
3116
  }
3073
- c.seatTops.push({ x, y: fl + h + 0.01, z, w, l: cl });
3117
+ const hipY = fl + h + 0.01;
3118
+ c.seatTops.push({ x, y: hipY, z, w, l: cl });
3119
+ for (let j = 0; j < n; j++) {
3120
+ const zz = z + (j - (n - 1) / 2) * pw;
3121
+ c._rawSeats.push({
3122
+ id: o.id ? n > 1 ? `${o.id}_${j}` : o.id : void 0,
3123
+ role: o.role,
3124
+ hipPoint: [x, hipY, zz],
3125
+ seatWidth: pw,
3126
+ seatLen: cl,
3127
+ facing: [dir >= 0 ? 1 : -1, 0, 0],
3128
+ isBench: n > 1,
3129
+ benchIndex: j,
3130
+ benchCount: n,
3131
+ open: o.open,
3132
+ doorId: o.doorId,
3133
+ headroomMetres: o.headroomMetres,
3134
+ legroomMetres: o.legroomMetres,
3135
+ widthMetres: o.widthMetres,
3136
+ parent: PR ?? null
3137
+ });
3138
+ }
3074
3139
  };
3075
3140
  kit.steeringWheel = function(c, x, y, z, o) {
3076
3141
  o = o || {};
@@ -3093,6 +3158,9 @@ function installInterior(kit) {
3093
3158
  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 });
3094
3159
  });
3095
3160
  c.rod(new V3(0.03, 0, 0), new V3(o.col || 0.34, 0, 0), 0.032, mat, { parent: g, seg: 10 });
3161
+ g.traverse(function(node) {
3162
+ c._noCabinRayObjs.add(node);
3163
+ });
3096
3164
  return g;
3097
3165
  };
3098
3166
  kit.yoke = function(c, x, y, z, o) {
@@ -3159,8 +3227,8 @@ function installInterior(kit) {
3159
3227
  x: x0 - 0.07,
3160
3228
  y: belt + 0.04,
3161
3229
  w: zi * 2,
3162
- d: 0.5,
3163
- h: Math.min(0.42, belt + 0.04 - fl - 0.1),
3230
+ d: o.dashD ?? 0.5,
3231
+ h: o.dashH ?? Math.min(0.42, belt + 0.04 - fl - 0.1),
3164
3232
  drv: drv * zs,
3165
3233
  mat: trim,
3166
3234
  top: fab
@@ -3188,22 +3256,32 @@ function installInterior(kit) {
3188
3256
  if (r === 0) {
3189
3257
  if (o.front === "bench") {
3190
3258
  const wb = zi * 2 - 0.62;
3191
- kit.seat(c, x, fl, drv * zs, { w: 0.5, mat: fab, back, lean, h: seatH });
3192
- kit.seat(c, x, fl, -drv * (zi - wb / 2 - 0.03), { w: wb, n: 2, mat: fab, back, lean, h: seatH });
3259
+ kit.seat(c, x, fl, drv * zs, { w: 0.5, mat: fab, back, lean, h: seatH, id: "driver", role: "driver" });
3260
+ kit.seat(c, x, fl, -drv * (zi - wb / 2 - 0.03), { w: wb, n: 2, mat: fab, back, lean, h: seatH, role: "front_passenger" });
3193
3261
  } else {
3194
3262
  ;
3195
3263
  [-1, 1].forEach(function(s) {
3196
- kit.seat(c, x, fl, s * zs, { w: Math.min(0.52, zi - zs + 0.22), mat: fab, back, lean, h: seatH });
3264
+ const isDriver = s === drv;
3265
+ kit.seat(c, x, fl, s * zs, {
3266
+ w: Math.min(0.52, zi - zs + 0.22),
3267
+ mat: fab,
3268
+ back,
3269
+ lean,
3270
+ h: seatH,
3271
+ id: isDriver ? "driver" : void 0,
3272
+ role: isDriver ? "driver" : "front_passenger"
3273
+ });
3197
3274
  });
3198
3275
  if (!o.noConsole) consoleBox(c, x + 0.16, fl, Math.min(0.26, seatH), trim);
3199
3276
  }
3200
- } 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 });
3277
+ } 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" });
3278
+ const trimLen = Math.min(0.8, (o.rowPitch ?? 0.88) - 0.06);
3201
3279
  [-1, 1].forEach(function(s) {
3202
- 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));
3280
+ c.roundBox(trimLen, belt - fl - 0.08, 0.035, 0.015, trim, x + 0.12, (belt + fl) / 2 + 0.02, s * (zi + 0.02));
3203
3281
  c.roundBox(0.3, 0.05, 0.07, 0.02, fab, x + 0.16, fl + seatH + 0.16, s * (zi - 0.015));
3204
3282
  c.roundBox(0.08, 0.025, 0.02, 8e-3, MATERIALS.chrome, x + 0.36, belt - 0.11, s * (zi - 5e-3));
3205
3283
  });
3206
- x -= r === 0 ? 0.88 : 0.8;
3284
+ x -= r === 0 ? o.rowPitch ?? 0.88 : 0.8;
3207
3285
  }
3208
3286
  if (o.ft != null) {
3209
3287
  const hx1 = o.ft - 0.04;
@@ -3213,7 +3291,11 @@ function installInterior(kit) {
3213
3291
  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 });
3214
3292
  c.roundBox(0.03, 0.06, 0.22, 0.02, MATERIALS.plastic, o.ft - 0.12, roof - 0.11, 0);
3215
3293
  [-1, 1].forEach(function(s) {
3216
- 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] });
3294
+ if (o.visorUp) {
3295
+ 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] });
3296
+ } else {
3297
+ 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] });
3298
+ }
3217
3299
  });
3218
3300
  }
3219
3301
  };
@@ -3260,6 +3342,267 @@ function installInterior(kit) {
3260
3342
  return shared;
3261
3343
  }
3262
3344
 
3345
+ // src/cabin-space.ts
3346
+ var HEADROOM_RAY_OFFSETS = [
3347
+ [0, 0],
3348
+ [0.06, 0],
3349
+ [-0.06, 0],
3350
+ [0, -0.06],
3351
+ [0, 0.06]
3352
+ ];
3353
+ var HEADROOM_START_OFFSET = 0.02;
3354
+ var HEADROOM_MIN_HIT = 0.2;
3355
+ var LEGROOM_KNEE_OFFSET = 0.12;
3356
+ var LEGROOM_START_PAD = 0.02;
3357
+ var LEGROOM_MIN_HIT = 0.02;
3358
+ var SHOULDER_HEIGHT_OFFSET = 0.38;
3359
+ var SHOULDER_MIN_HIT = 0.14;
3360
+ var ROW_EPSILON = 0.25;
3361
+ var NEIGHBOR_ROW_TOLERANCE = 0.35;
3362
+ var DOOR_ROOF_TRIM = 0.05;
3363
+ var round4 = (value) => Number.isFinite(value) ? Math.round(value * 1e4) / 1e4 : value;
3364
+ function installCabinSpace(kit) {
3365
+ const THREE = kit.THREE;
3366
+ const V3 = THREE.Vector3;
3367
+ const raycaster = new THREE.Raycaster();
3368
+ const originVec = new V3();
3369
+ const dirVec = new V3();
3370
+ function castFirst(c, ox, oy, oz, dx, dy, dz, minDist) {
3371
+ originVec.set(ox, oy, oz);
3372
+ dirVec.set(dx, dy, dz);
3373
+ raycaster.set(originVec, dirVec);
3374
+ const hits = raycaster.intersectObject(c.vehicle, true);
3375
+ const ignored = c._noCabinRayObjs;
3376
+ for (let i = 0; i < hits.length; i++) {
3377
+ const h = hits[i];
3378
+ if (!h) continue;
3379
+ if (h.object.visible === false || h.object.userData?.noCabinRay === true || ignored?.has(h.object)) continue;
3380
+ if (h.distance >= minDist) return h.distance;
3381
+ }
3382
+ return Number.POSITIVE_INFINITY;
3383
+ }
3384
+ function measureHeadroom(c, hip) {
3385
+ let minClearance = Number.POSITIVE_INFINITY;
3386
+ for (let i = 0; i < HEADROOM_RAY_OFFSETS.length; i++) {
3387
+ const offset = HEADROOM_RAY_OFFSETS[i];
3388
+ const dist = castFirst(c, hip[0] + offset[0], hip[1] + HEADROOM_START_OFFSET, hip[2] + offset[1], 0, 1, 0, HEADROOM_MIN_HIT);
3389
+ const clear = Number.isFinite(dist) ? dist + HEADROOM_START_OFFSET : Number.POSITIVE_INFINITY;
3390
+ if (clear < minClearance) minClearance = clear;
3391
+ }
3392
+ return round4(minClearance);
3393
+ }
3394
+ function measureLegroom(c, hip, facing, seatLen) {
3395
+ const startOffset = seatLen / 2 + LEGROOM_START_PAD;
3396
+ const dist = castFirst(
3397
+ c,
3398
+ hip[0] + facing[0] * startOffset,
3399
+ hip[1] + LEGROOM_KNEE_OFFSET,
3400
+ hip[2] + facing[2] * startOffset,
3401
+ facing[0],
3402
+ 0,
3403
+ facing[2],
3404
+ LEGROOM_MIN_HIT
3405
+ );
3406
+ return Number.isFinite(dist) ? round4(startOffset + dist) : Number.POSITIVE_INFINITY;
3407
+ }
3408
+ function measureShoulderWidth(c, raw, allRaw, headroom) {
3409
+ const hip = raw.hipPoint;
3410
+ const fx = raw.facing[0];
3411
+ const fz = raw.facing[2];
3412
+ const lx = -fz;
3413
+ const lz = fx;
3414
+ const sy = hip[1] + SHOULDER_HEIGHT_OFFSET;
3415
+ const wallPos = castFirst(c, hip[0], sy, hip[2], lx, 0, lz, SHOULDER_MIN_HIT);
3416
+ const wallNeg = castFirst(c, hip[0], sy, hip[2], -lx, 0, -lz, SHOULDER_MIN_HIT);
3417
+ let neighborPos = Number.POSITIVE_INFINITY;
3418
+ let neighborNeg = Number.POSITIVE_INFINITY;
3419
+ for (let i = 0; i < allRaw.length; i++) {
3420
+ const other = allRaw[i];
3421
+ if (!other || other === raw) continue;
3422
+ const dx = other.hipPoint[0] - hip[0];
3423
+ const dy = Math.abs(other.hipPoint[1] - hip[1]);
3424
+ const dz = other.hipPoint[2] - hip[2];
3425
+ if (dy > NEIGHBOR_ROW_TOLERANCE) continue;
3426
+ const alongFacing = Math.abs(dx * fx + dz * fz);
3427
+ if (alongFacing > NEIGHBOR_ROW_TOLERANCE) continue;
3428
+ const alongLat = dx * lx + dz * lz;
3429
+ if (alongLat > 0.05 && alongLat / 2 < neighborPos) neighborPos = alongLat / 2;
3430
+ else if (alongLat < -0.05 && -alongLat / 2 < neighborNeg) neighborNeg = -alongLat / 2;
3431
+ }
3432
+ const halfFallback = Number.isFinite(headroom) ? raw.seatWidth / 2 : Number.POSITIVE_INFINITY;
3433
+ const posSpace = Math.min(wallPos, neighborPos);
3434
+ const negSpace = Math.min(wallNeg, neighborNeg);
3435
+ const leftAvail = Number.isFinite(posSpace) ? posSpace : halfFallback;
3436
+ const rightAvail = Number.isFinite(negSpace) ? negSpace : halfFallback;
3437
+ const total = leftAvail + rightAvail;
3438
+ return round4(total);
3439
+ }
3440
+ function collectDoors(c) {
3441
+ const records = [];
3442
+ const seen = /* @__PURE__ */ new Set();
3443
+ const explicit = c._explicitDoors || [];
3444
+ for (let i = 0; i < explicit.length; i++) {
3445
+ const d = explicit[i];
3446
+ if (seen.has(d.id)) continue;
3447
+ seen.add(d.id);
3448
+ const side2 = d.id.includes("left") ? -1 : d.id.includes("right") ? 1 : 0;
3449
+ records.push({ opening: d, center: [0, 0, side2], side: side2 });
3450
+ }
3451
+ const zones = c.zones || [];
3452
+ const cabin = c.meta?.cabin;
3453
+ const ghRoof = c.meta?.glasshouse?.roof;
3454
+ for (let i = 0; i < zones.length; i++) {
3455
+ const z = zones[i];
3456
+ if (!z || z.type !== "door" || !z.box || seen.has(z.id)) continue;
3457
+ seen.add(z.id);
3458
+ const b = z.box;
3459
+ const dx = Math.abs(b.x1 - b.x0);
3460
+ const dz = Math.abs(b.z1 - b.z0);
3461
+ const dy = Math.abs(b.y1 - b.y0);
3462
+ const isSideDoor = dx >= dz;
3463
+ const widthMetres = isSideDoor ? dx : dz;
3464
+ let heightMetres = dy;
3465
+ if (isSideDoor && ghRoof != null) {
3466
+ const floorY = cabin?.y0 != null ? cabin.y0 + 0.05 : b.y0;
3467
+ const roofY = ghRoof - DOOR_ROOF_TRIM;
3468
+ if (roofY - floorY > heightMetres) heightMetres = roofY - floorY;
3469
+ }
3470
+ const center = [(b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, (b.z0 + b.z1) / 2];
3471
+ const side2 = typeof z.side === "number" ? z.side : center[2] < -0.1 ? -1 : center[2] > 0.1 ? 1 : 0;
3472
+ records.push({
3473
+ opening: {
3474
+ id: z.id,
3475
+ widthMetres: round4(widthMetres),
3476
+ heightMetres: round4(heightMetres)
3477
+ },
3478
+ center,
3479
+ side: side2
3480
+ });
3481
+ }
3482
+ return records;
3483
+ }
3484
+ function pickDoorId(hip, doors) {
3485
+ if (doors.length === 0) return void 0;
3486
+ const seatSide = hip[2] < -0.05 ? -1 : hip[2] > 0.05 ? 1 : 0;
3487
+ let bestId;
3488
+ let bestScore = Number.POSITIVE_INFINITY;
3489
+ for (let i = 0; i < doors.length; i++) {
3490
+ const d = doors[i];
3491
+ const dx = d.center[0] - hip[0];
3492
+ const dz = d.center[2] - hip[2];
3493
+ const sidePenalty = seatSide !== 0 && d.side !== 0 && seatSide !== d.side ? 10 : 0;
3494
+ const score = dx * dx + dz * dz + sidePenalty;
3495
+ if (score < bestScore) {
3496
+ bestScore = score;
3497
+ bestId = d.opening.id;
3498
+ }
3499
+ }
3500
+ return bestId;
3501
+ }
3502
+ function inferRole(c, raw, maxX, driverAssigned) {
3503
+ if (raw.role) return raw.role;
3504
+ const kind = c.meta?.kind;
3505
+ if (kind === "bike") return "rider";
3506
+ if (kind === "tank") return "crew";
3507
+ if (Math.abs(raw.facing[2]) > 0.5) return "cargo";
3508
+ const isFrontRow = raw.hipPoint[0] >= maxX - ROW_EPSILON;
3509
+ if (kind === "plane" || kind === "heli") return isFrontRow ? "pilot" : "crew";
3510
+ if (isFrontRow) {
3511
+ if (!driverAssigned && raw.hipPoint[2] <= 0.05) return "driver";
3512
+ return "front_passenger";
3513
+ }
3514
+ return "rear";
3515
+ }
3516
+ function finalizeCabinSpaces(c) {
3517
+ c.root.updateMatrixWorld(true);
3518
+ const doorRecords = collectDoors(c);
3519
+ c.doors = doorRecords.map((r) => r.opening);
3520
+ const seats = [];
3521
+ const usedIds = /* @__PURE__ */ new Set();
3522
+ const pushSeat = (seat) => {
3523
+ let id = seat.id;
3524
+ if (usedIds.has(id)) {
3525
+ let suffix = 2;
3526
+ while (usedIds.has(`${id}_${suffix}`)) suffix++;
3527
+ id = `${id}_${suffix}`;
3528
+ }
3529
+ usedIds.add(id);
3530
+ seats.push(id === seat.id ? seat : { ...seat, id });
3531
+ };
3532
+ const explicit = c._explicitSeats || [];
3533
+ for (let i = 0; i < explicit.length; i++) {
3534
+ pushSeat(explicit[i]);
3535
+ }
3536
+ const invVehicle = new THREE.Matrix4().copy(c.vehicle.matrixWorld).invert();
3537
+ const tmpPoint = new V3();
3538
+ const rawSeats = (c._rawSeats || []).map((entry) => {
3539
+ if (!entry.parent || entry.parent === c.vehicle) return entry;
3540
+ entry.parent.updateMatrixWorld(true);
3541
+ tmpPoint.set(entry.hipPoint[0], entry.hipPoint[1], entry.hipPoint[2]).applyMatrix4(entry.parent.matrixWorld).applyMatrix4(invVehicle);
3542
+ return { ...entry, hipPoint: [tmpPoint.x, tmpPoint.y, tmpPoint.z] };
3543
+ });
3544
+ if (rawSeats.length === 0 && explicit.length === 0 && Array.isArray(c.seatTops) && c.seatTops.length > 0) {
3545
+ const isOpenBoat = c.meta?.kind === "boat";
3546
+ for (let i = 0; i < c.seatTops.length; i++) {
3547
+ const st = c.seatTops[i];
3548
+ rawSeats.push({
3549
+ hipPoint: [st.x, st.y, st.z],
3550
+ seatWidth: st.w,
3551
+ seatLen: st.l,
3552
+ facing: [1, 0, 0],
3553
+ isBench: false,
3554
+ benchIndex: 0,
3555
+ benchCount: 1,
3556
+ open: isOpenBoat
3557
+ });
3558
+ }
3559
+ }
3560
+ let maxX = Number.NEGATIVE_INFINITY;
3561
+ for (let i = 0; i < rawSeats.length; i++) {
3562
+ const x = rawSeats[i].hipPoint[0];
3563
+ if (x > maxX) maxX = x;
3564
+ }
3565
+ let driverAssigned = seats.some((s) => s.role === "driver");
3566
+ for (let i = 0; i < rawSeats.length; i++) {
3567
+ const raw = rawSeats[i];
3568
+ const role = inferRole(c, raw, maxX, driverAssigned);
3569
+ if (role === "driver") driverAssigned = true;
3570
+ const isOpen = raw.open === true;
3571
+ const headroomMetres = isOpen ? Number.POSITIVE_INFINITY : raw.headroomMetres != null ? round4(raw.headroomMetres) : measureHeadroom(c, raw.hipPoint);
3572
+ const legroomMetres = isOpen ? Number.POSITIVE_INFINITY : raw.legroomMetres != null ? round4(raw.legroomMetres) : measureLegroom(c, raw.hipPoint, raw.facing, raw.seatLen);
3573
+ const widthMetres = isOpen ? Number.POSITIVE_INFINITY : raw.widthMetres != null ? round4(raw.widthMetres) : measureShoulderWidth(c, raw, rawSeats, headroomMetres);
3574
+ const doorId = isOpen ? void 0 : raw.doorId !== void 0 ? raw.doorId : pickDoorId(raw.hipPoint, doorRecords);
3575
+ const sideTag = raw.hipPoint[2] < -0.05 ? "left" : raw.hipPoint[2] > 0.05 ? "right" : "center";
3576
+ const defaultId = role === "driver" ? "driver" : role === "front_passenger" ? `front_${sideTag}` : `${role}_${sideTag}`;
3577
+ const hipPoint = [round4(raw.hipPoint[0]), round4(raw.hipPoint[1]), round4(raw.hipPoint[2])];
3578
+ const seatSpace = doorId !== void 0 ? { id: raw.id ?? defaultId, role, hipPoint, headroomMetres, legroomMetres, widthMetres, doorId } : { id: raw.id ?? defaultId, role, hipPoint, headroomMetres, legroomMetres, widthMetres };
3579
+ pushSeat(seatSpace);
3580
+ }
3581
+ const kind = c.meta?.kind;
3582
+ if (seats.length === 0 && rawSeats.length === 0 && (kind === "bike" || kind === "quad")) {
3583
+ const zones = c.zones || [];
3584
+ const seatZone = zones.find((z) => z.id === "seat" && z.box);
3585
+ const hipPoint = seatZone?.box ? [
3586
+ round4((seatZone.box.x0 + seatZone.box.x1) / 2),
3587
+ round4(seatZone.box.y0 + (seatZone.box.y1 - seatZone.box.y0) * 0.75),
3588
+ round4((seatZone.box.z0 + seatZone.box.z1) / 2)
3589
+ ] : [round4(((c.meta?.rear ?? -1) + (c.meta?.front ?? 1)) * 0.25), round4((c.meta?.top ?? 1.1) * 0.75), 0];
3590
+ pushSeat({
3591
+ id: "rider",
3592
+ role: "rider",
3593
+ hipPoint,
3594
+ headroomMetres: Number.POSITIVE_INFINITY,
3595
+ legroomMetres: Number.POSITIVE_INFINITY,
3596
+ widthMetres: Number.POSITIVE_INFINITY
3597
+ });
3598
+ }
3599
+ c.seats = seats;
3600
+ }
3601
+ kit.finalizeCabinSpaces = finalizeCabinSpaces;
3602
+ kit._.finalizeCabinSpaces = finalizeCabinSpaces;
3603
+ return { finalizeCabinSpaces };
3604
+ }
3605
+
3263
3606
  // src/hood.ts
3264
3607
  var HOOD_LIFT = 8e-3;
3265
3608
  function installHood(kit) {
@@ -11059,6 +11402,7 @@ function createVehicleKit(options) {
11059
11402
  installGlass(kit);
11060
11403
  installLights(kit);
11061
11404
  installInterior(kit);
11405
+ installCabinSpace(kit);
11062
11406
  installHood(kit);
11063
11407
  installCar(kit);
11064
11408
  installTrucks(kit);
@@ -11368,6 +11712,102 @@ function findStrayLamps(c, THREE) {
11368
11712
  return found;
11369
11713
  }
11370
11714
 
11715
+ // src/destructible/door-shell.ts
11716
+ var DOOR_SHELL_DEPTH = 0.09;
11717
+ var DOOR_SHELL_MAX_DEPTH = 0.25;
11718
+ var WELD = 1e-5;
11719
+ var cellOf = (v) => Math.round(v / WELD);
11720
+ function weld(positions) {
11721
+ const ids = new Int32Array(positions.length / 3);
11722
+ const points = [];
11723
+ const cells = /* @__PURE__ */ new Map();
11724
+ const near = (x, y, z) => {
11725
+ const [cx, cy, cz] = [cellOf(x), cellOf(y), cellOf(z)];
11726
+ for (let i = -1; i <= 1; i++)
11727
+ for (let j = -1; j <= 1; j++)
11728
+ for (let k = -1; k <= 1; k++) {
11729
+ for (const id of cells.get(`${cx + i},${cy + j},${cz + k}`) ?? []) {
11730
+ 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;
11731
+ }
11732
+ }
11733
+ return void 0;
11734
+ };
11735
+ for (let i = 0; i < ids.length; i++) {
11736
+ const x = positions[i * 3];
11737
+ const y = positions[i * 3 + 1];
11738
+ const z = positions[i * 3 + 2];
11739
+ let id = near(x, y, z);
11740
+ if (id === void 0) {
11741
+ id = points.length / 3;
11742
+ points.push(x, y, z);
11743
+ const key = `${cellOf(x)},${cellOf(y)},${cellOf(z)}`;
11744
+ const cell = cells.get(key);
11745
+ if (cell) cell.push(id);
11746
+ else cells.set(key, [id]);
11747
+ }
11748
+ ids[i] = id;
11749
+ }
11750
+ return { ids, points };
11751
+ }
11752
+ function freeEdgesOf(ids) {
11753
+ const uses = /* @__PURE__ */ new Map();
11754
+ for (let t = 0; t < ids.length; t += 3) {
11755
+ for (let k = 0; k < 3; k++) {
11756
+ const a = ids[t + k];
11757
+ const b = ids[t + (k + 1) % 3];
11758
+ if (a === b) continue;
11759
+ const key = a < b ? `${a}:${b}` : `${b}:${a}`;
11760
+ const use = uses.get(key);
11761
+ if (use) use.count++;
11762
+ else uses.set(key, { count: 1, from: a, to: b });
11763
+ }
11764
+ }
11765
+ const free = [];
11766
+ uses.forEach((use) => {
11767
+ if (use.count === 1) free.push([use.from, use.to]);
11768
+ });
11769
+ return free;
11770
+ }
11771
+ function doorShell(params) {
11772
+ const depth = params.depth ?? DOOR_SHELL_DEPTH;
11773
+ const [ox, oy, oz] = params.outward ?? [0, 0, params.side < 0 ? -1 : 1];
11774
+ const { positions } = params;
11775
+ const along = (i) => positions[i] * ox + positions[i + 1] * oy + positions[i + 2] * oz;
11776
+ let outermost = -Infinity;
11777
+ for (let i = 0; i < positions.length; i += 3) outermost = Math.max(outermost, along(i));
11778
+ const floor = outermost - DOOR_SHELL_MAX_DEPTH;
11779
+ const sink = (x, y, z) => {
11780
+ const move = Math.max(0, Math.min(depth, x * ox + y * oy + z * oz - floor));
11781
+ return [x - ox * move, y - oy * move, z - oz * move];
11782
+ };
11783
+ const inner = new Float32Array(positions.length);
11784
+ for (let t = 0; t < positions.length; t += 9) {
11785
+ for (const [to, from] of [
11786
+ [0, 0],
11787
+ [1, 2],
11788
+ [2, 1]
11789
+ ]) {
11790
+ inner.set(sink(positions[t + from * 3], positions[t + from * 3 + 1], positions[t + from * 3 + 2]), t + to * 3);
11791
+ }
11792
+ }
11793
+ const { ids, points } = weld(positions);
11794
+ const free = freeEdgesOf(ids);
11795
+ const flange = new Float32Array(free.length * 18);
11796
+ const corner = (id, sunk) => {
11797
+ const [x, y, z] = [points[id * 3], points[id * 3 + 1], points[id * 3 + 2]];
11798
+ return sunk ? sink(x, y, z) : [x, y, z];
11799
+ };
11800
+ free.forEach(([a, b], i) => {
11801
+ const quad = [corner(b, false), corner(a, false), corner(a, true), corner(b, false), corner(a, true), corner(b, true)];
11802
+ quad.forEach((p, k) => flange.set(p, i * 18 + k * 3));
11803
+ });
11804
+ return { flange, inner, freeEdges: free.length };
11805
+ }
11806
+ function openEdgeCount(positions, minLength = 0) {
11807
+ const { ids, points } = weld(positions);
11808
+ 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;
11809
+ }
11810
+
11371
11811
  // src/destructible/armour.ts
11372
11812
  var ARMOUR_LEVELS = {
11373
11813
  IIIA: { glassStops: 1700, glassHp: 6e3, glassTakes: 0.25, steel: 8 },
@@ -12211,12 +12651,75 @@ function isDoorSeam(three, params) {
12211
12651
  if (centre.y < zone.y0 || centre.y > zone.y1) return false;
12212
12652
  return Math.abs(centre.x - zone.x0) < SEAM_AT_EDGE || Math.abs(centre.x - zone.x1) < SEAM_AT_EDGE;
12213
12653
  }
12654
+ function closeDoorSkin(three, meshes, params) {
12655
+ const THREE = three;
12656
+ const toVehicle = params.toVehicle;
12657
+ const positions = [];
12658
+ const at = new THREE.Vector3();
12659
+ for (const mesh of meshes) {
12660
+ const geometry = mesh.geometry.index ? mesh.geometry.toNonIndexed() : mesh.geometry;
12661
+ const matrix = new THREE.Matrix4().multiplyMatrices(toVehicle, mesh.matrixWorld);
12662
+ const position = geometry.getAttribute("position");
12663
+ for (let i = 0; i < position.count; i++) {
12664
+ at.fromBufferAttribute(position, i).applyMatrix4(matrix);
12665
+ positions.push(at.x, at.y, at.z);
12666
+ }
12667
+ if (geometry !== mesh.geometry) geometry.dispose();
12668
+ }
12669
+ if (!positions.length) return [];
12670
+ const shell = doorShell({ positions, side: params.side, ...params.outward ? { outward: params.outward } : {} });
12671
+ const out = [];
12672
+ for (const [array, material] of [
12673
+ [shell.flange, params.paint],
12674
+ [shell.inner, params.liner]
12675
+ ]) {
12676
+ if (!array.length) continue;
12677
+ const geometry = new THREE.BufferGeometry();
12678
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(array, 3));
12679
+ geometry.computeVertexNormals();
12680
+ geometry.computeBoundingBox();
12681
+ geometry.computeBoundingSphere();
12682
+ out.push(new THREE.Mesh(geometry, material));
12683
+ }
12684
+ return out;
12685
+ }
12686
+
12687
+ // src/destructible/trunk-bay.ts
12688
+ var TRUNK_FLOOR_OVER_CLEARANCE = 0.12;
12689
+ var TRUNK_INSET = 0.05;
12690
+ var TRUNK_SEAL = 0.025;
12691
+ function buildTrunkBay(THREE, params) {
12692
+ const B = params.box;
12693
+ const floor = Math.max(B.y0, params.clearance + TRUNK_FLOOR_OVER_CLEARANCE);
12694
+ const top = B.y1 - TRUNK_INSET;
12695
+ const length = B.x1 - B.x0 - 2 * TRUNK_INSET;
12696
+ const width = B.z1 - B.z0 - 2 * TRUNK_INSET;
12697
+ if (length <= 0 || width <= 0 || top <= floor) return [];
12698
+ params.carpet.side = THREE.BackSide;
12699
+ const open = new THREE.MeshBasicMaterial({ visible: false });
12700
+ const tub = new THREE.Mesh(new THREE.BoxGeometry(length, top - floor, width), [params.carpet, params.carpet, open, params.carpet, params.carpet, params.carpet]);
12701
+ tub.position.set((B.x0 + B.x1) / 2, (floor + top) / 2, (B.z0 + B.z1) / 2);
12702
+ const seal = new THREE.Mesh(new THREE.BoxGeometry(TRUNK_SEAL, TRUNK_SEAL, width), params.seal);
12703
+ seal.position.set(B.x0 + TRUNK_INSET, top, (B.z0 + B.z1) / 2);
12704
+ for (const mesh of [tub, seal]) {
12705
+ mesh.castShadow = false;
12706
+ mesh.userData.noFollow = true;
12707
+ mesh.userData.trunkBay = true;
12708
+ }
12709
+ return [tub, seal];
12710
+ }
12214
12711
 
12215
12712
  // src/destructible/visual.ts
12216
12713
  var HOLE_DECAL_SCALE = 2.4;
12217
12714
  var HOLE_BATCH_CAPACITY = 64;
12218
12715
  var DOOR_DEPTH = 0.07;
12219
12716
  var DOOR_SKIN_DEPTH = 0.09;
12717
+ var LID_OUTWARD = [-Math.SQRT1_2, Math.SQRT1_2, 0];
12718
+ var TRUNK_CARPET_COLOR = "#3a3c3f";
12719
+ var TRUNK_SEAL_COLOR = "#2a2b2d";
12720
+ var DOOR_TRIM_MARGIN = 0.03;
12721
+ var DOOR_TRIM_SIZE = 0.3;
12722
+ var LID_HINGE_INSET = 0.02;
12220
12723
  var DOOR_FLOOR_DEPTH = 0.2;
12221
12724
  var DOOR_EDGE_PIECES = 8;
12222
12725
  var DOOR_EDGE_REACH = 0.08;
@@ -12524,10 +13027,11 @@ var VehicleVisuals = class {
12524
13027
  const piv = new THREE.Group();
12525
13028
  piv.name = p.id;
12526
13029
  piv.userData.plateOf = p.id;
12527
- piv.position.set(sk - 0.016, B.y1 - 0.05, 0);
13030
+ const hinge = { x: B.x1 - LID_HINGE_INSET, y: B.y1 - LID_HINGE_INSET };
13031
+ piv.position.set(hinge.x, hinge.y, 0);
12528
13032
  piv.userData.rigid = true;
12529
13033
  this.c.vehicle.add(piv);
12530
- const panel = this.box(0.022, wy, wz, this.paint(), 0, -wy / 2, 0, piv);
13034
+ 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);
12531
13035
  this.plates.set(p.id, piv);
12532
13036
  this.extra.set(`recess_${p.id}`, [recess]);
12533
13037
  this.showWhenOpen(p.id, piv, panel, recess);
@@ -12606,12 +13110,16 @@ var VehicleVisuals = class {
12606
13110
  const seals = panes.map((g) => I.paneSeals.get(g)).filter((s) => !!s);
12607
13111
  const mirrors = this.mirrorsOn(z);
12608
13112
  const frames = this.framesAround(panes, inv);
12609
- const followers = I.followersIn(this.c, z, inv).filter((o) => !this.takeSeam(o, id, z, inv) && !this.inFloor(o, piv, z, inv));
12610
- objs = [...pcs, ...followers, ...panes, ...seals, ...mirrors, ...frames];
13113
+ const thin = I.followersIn(this.c, z, inv);
13114
+ 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));
13115
+ objs = [...pcs, ...this.shellOf(pcs, z, inv), ...followers, ...panes, ...seals, ...mirrors, ...frames];
12611
13116
  }
12612
13117
  } else {
12613
13118
  const pcs = this.cutZone(z);
12614
- if (pcs.length) objs = [...pcs, ...I.followersIn(this.c, z, inv)];
13119
+ if (pcs.length) {
13120
+ objs = [...pcs, ...this.shellOf(pcs, z, inv, LID_OUTWARD), ...I.followersIn(this.c, z, inv)];
13121
+ this.trunkBay(z);
13122
+ }
12615
13123
  }
12616
13124
  } catch {
12617
13125
  objs = [];
@@ -12627,7 +13135,7 @@ var VehicleVisuals = class {
12627
13135
  if (di >= 0) deform.splice(di, 1);
12628
13136
  }
12629
13137
  if (p.role === "door" && objs.length > 0) {
12630
- this.doorEdges(piv, z, this.doorTops.get(id) ?? B.y1 - 0.02);
13138
+ this.doorEdges(piv, z, this.doorTops.get(id) ?? B.y1 - 0.02, objs.some((o) => o.userData.doorShell));
12631
13139
  this.liftDoorTrim(objs, z);
12632
13140
  this.cutStripsAcross(piv, z, inv);
12633
13141
  }
@@ -12635,6 +13143,48 @@ var VehicleVisuals = class {
12635
13143
  this.c.root.updateMatrixWorld(true);
12636
13144
  return objs.length > 0;
12637
13145
  }
13146
+ /** 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. */
13147
+ shellOf(skin, z, inv, outward) {
13148
+ const paint = this.paint().clone();
13149
+ paint.side = this.THREE.DoubleSide;
13150
+ const liner = this.I.makeMaterial(DOOR_CARD_COLOR, { roughness: 0.85 }).clone();
13151
+ liner.side = this.THREE.DoubleSide;
13152
+ for (const piece of skin) piece.userData.doorSkin = true;
13153
+ const meshes = closeDoorSkin(this.THREE, skin, { toVehicle: inv, side: z.side < 0 ? -1 : 1, paint, liner, ...outward ? { outward } : {} });
13154
+ meshes.forEach((mesh, i) => {
13155
+ mesh.userData.doorShell = meshes.length === 2 && i === 0 ? "fold" : "inner";
13156
+ mesh.castShadow = false;
13157
+ this.c.vehicle.add(mesh);
13158
+ });
13159
+ return meshes;
13160
+ }
13161
+ /**
13162
+ * 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
13163
+ * along the sill, so the opening shows the luggage space and not the dark inside of the body.
13164
+ */
13165
+ trunkBay(z) {
13166
+ const carpet = this.I.makeMaterial(TRUNK_CARPET_COLOR, { roughness: 0.95 }).clone();
13167
+ const seal = this.I.makeMaterial(TRUNK_SEAL_COLOR, { roughness: 0.7 });
13168
+ for (const mesh of buildTrunkBay(this.THREE, { box: z.box, clearance: this.c.meta.clearance ?? 0.3, carpet, seal })) this.c.vehicle.add(mesh);
13169
+ }
13170
+ /**
13171
+ * 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
13172
+ * trim the followers take, but sit within the door, so they swing with it instead of staying in the air over the opening.
13173
+ */
13174
+ doorTrimIn(z, inv) {
13175
+ const B = z.box;
13176
+ const THREE = this.THREE;
13177
+ const deform = new Set(this.c.deform ?? []);
13178
+ return this.c.vehicle.children.filter((o) => {
13179
+ if (!o.isMesh || !o.visible || deform.has(o) || o.userData.decal || o.userData.glass || o.userData.noFollow || this.c.wheels.includes(o)) return false;
13180
+ const box = this.I.localBox(this.c, o, inv);
13181
+ if (box.isEmpty()) return false;
13182
+ const centre = box.getCenter(new THREE.Vector3());
13183
+ const size = box.getSize(new THREE.Vector3());
13184
+ 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;
13185
+ return inside && Math.max(size.x, size.y, size.z) <= DOOR_TRIM_SIZE;
13186
+ });
13187
+ }
12638
13188
  /** 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. */
12639
13189
  inFloor(o, piv, z, inv) {
12640
13190
  const side2 = z.side < 0 ? -1 : 1;
@@ -12655,7 +13205,7 @@ var VehicleVisuals = class {
12655
13205
  return true;
12656
13206
  }
12657
13207
  /** 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. */
12658
- doorEdges(piv, z, y1) {
13208
+ doorEdges(piv, z, y1, closed) {
12659
13209
  const THREE = this.THREE;
12660
13210
  const B = z.box;
12661
13211
  const side2 = z.side < 0 ? -1 : 1;
@@ -12675,13 +13225,13 @@ var VehicleVisuals = class {
12675
13225
  const at = this.surface("z", side2, B, [[x, y]]);
12676
13226
  return at != null && Math.abs(at - flat) < DOOR_EDGE_REACH ? at : flat;
12677
13227
  });
12678
- const band = (lift, path, closed) => {
13228
+ const band = (lift, path, closed2) => {
12679
13229
  const position = [];
12680
13230
  const index = [];
12681
13231
  path.forEach((at, i) => {
12682
13232
  const [x, y] = loop[at];
12683
13233
  position.push(x, y, heights[at] + side2 * lift, x, y, heights[at] + side2 * (lift - DOOR_DEPTH));
12684
- if (!closed && i === path.length - 1) return;
13234
+ if (!closed2 && i === path.length - 1) return;
12685
13235
  const a = i * 2;
12686
13236
  const b = (i + 1) % path.length * 2;
12687
13237
  index.push(a, a + 1, b, b, a + 1, b + 1);
@@ -12707,21 +13257,18 @@ var VehicleVisuals = class {
12707
13257
  const cardMaterial = this.I.makeMaterial(DOOR_CARD_COLOR, { roughness: 0.85 }).clone();
12708
13258
  cardMaterial.side = THREE.DoubleSide;
12709
13259
  const card = new THREE.Mesh(cardGeometry, cardMaterial);
12710
- card.userData.noFollow = true;
12711
- card.castShadow = false;
12712
- this.c.vehicle.add(card);
12713
- piv.attach(card);
12714
13260
  const all = loop.map((_, i) => i);
12715
13261
  const top = 2 * DOOR_EDGE_PIECES;
12716
13262
  const sides = [...all.slice(3 * DOOR_EDGE_PIECES), ...all.slice(0, top + 1)];
12717
13263
  const edges = new THREE.Mesh(band(2e-3, all, true), paint);
12718
13264
  const lining = new THREE.Mesh(band(2e-3, sides, false), paint);
12719
- for (const m of [edges, lining]) {
13265
+ const onDoor = closed ? [] : [card, edges];
13266
+ for (const m of [...onDoor, lining]) {
12720
13267
  m.userData.noFollow = true;
12721
13268
  m.castShadow = false;
12722
13269
  this.c.vehicle.add(m);
12723
13270
  }
12724
- piv.attach(edges);
13271
+ for (const m of onDoor) piv.attach(m);
12725
13272
  }
12726
13273
  /** 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. */
12727
13274
  framesAround(panes, inv) {
@@ -13734,6 +14281,7 @@ var VehicleVisuals = class {
13734
14281
  };
13735
14282
 
13736
14283
  // src/destructible/clips.ts
14284
+ var LID_OPEN = 1.31;
13737
14285
  var DURATION = 1.2;
13738
14286
  function createVehicleClips(model, vis, kit, c) {
13739
14287
  const zones = kit.zonesOf(c);
@@ -13746,7 +14294,7 @@ function createVehicleClips(model, vis, kit, c) {
13746
14294
  if (!z || vis && !vis.plates.has(p.id)) continue;
13747
14295
  const sgn = z.hinge === "rear" ? -1 : 1;
13748
14296
  doors[p.id] = { rotation: [0, (z.side < 0 ? -1 : 1) * sgn * 1.15, 0] };
13749
- } else if (p.role === "lid" && (!vis || vis.plates.has(p.id))) lid[p.id] = { rotation: [0, 0, -1.15] };
14297
+ } else if (p.role === "lid" && (!vis || vis.plates.has(p.id))) lid[p.id] = { rotation: [0, 0, -LID_OPEN] };
13750
14298
  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)] };
13751
14299
  }
13752
14300
  const clips = [];
@@ -15112,6 +15660,133 @@ function cabinEnclosure(source, options = {}) {
15112
15660
  };
15113
15661
  }
15114
15662
 
15663
+ // src/destructible/rain-cover.ts
15664
+ import { createFootprintRainCover } from "@adatechnology/game-contracts";
15665
+ var RAIN_OPENING_DIAMETER = 0.3;
15666
+ var RAIN_MOVE_STEP = 1;
15667
+ var RAIN_TURN_STEP = 0.08;
15668
+ var UPRIGHT = 0.7;
15669
+ var GONE2 = /* @__PURE__ */ new Set(["broken", "melted", "ashes"]);
15670
+ var COVERING_ROLES = /* @__PURE__ */ new Set(["roof"]);
15671
+ var COVERED_KINDS = /* @__PURE__ */ new Set(["car", "bus", "truck"]);
15672
+ var TALL_PANEL = 1.5;
15673
+ var NEAR_TOP = 0.85;
15674
+ var BODY_PANELS = 3;
15675
+ var OPENING_ROLES = /* @__PURE__ */ new Set(["roof", "glass"]);
15676
+ function bodyRoof(source, alive, kind) {
15677
+ const top = source.vehicle.meta.top;
15678
+ if (!COVERED_KINDS.has(kind) || top === void 0 || source.model.parts.some((def) => COVERING_ROLES.has(def.role))) return null;
15679
+ 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));
15680
+ if (panels.length < BODY_PANELS) return null;
15681
+ const x0 = Math.min(...panels.map((def) => def.box.center[0] - def.box.size[0] / 2));
15682
+ const x1 = Math.max(...panels.map((def) => def.box.center[0] + def.box.size[0] / 2));
15683
+ const z1 = Math.max(...panels.map((def) => Math.abs(def.box.center[2]) + def.box.size[2] / 2));
15684
+ 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)) };
15685
+ }
15686
+ var hasMoved = (elements, last) => {
15687
+ for (let index = 0; index < 16; index++) if (elements[index] !== last[index]) return true;
15688
+ return false;
15689
+ };
15690
+ var localOf = (box, top = box.center[1] + box.size[1] / 2) => ({ x: box.center[0], z: box.center[2], halfX: box.size[0] / 2, halfZ: box.size[2] / 2, top });
15691
+ function createVehicleRainCover(source, options = {}) {
15692
+ const vehicle = source.vehicle;
15693
+ const node = vehicle.vehicle;
15694
+ const cabin = cabinBoxOf(vehicle);
15695
+ const cover = createFootprintRainCover();
15696
+ let roofs = [];
15697
+ let openings = [];
15698
+ let isShellChanged = true;
15699
+ let bumpedX = Infinity;
15700
+ let bumpedZ = Infinity;
15701
+ let bumpedYaw = 0;
15702
+ const placedAt = new Float64Array(16);
15703
+ const refreshShell = () => {
15704
+ if (!node?.localToWorld) return;
15705
+ const state = source.state();
15706
+ const byId = new Map(state.parts.map((part) => [part.id, part]));
15707
+ const mainGroup = state.groups[0] ? new Set(state.groups[0]) : null;
15708
+ const alive = (id) => {
15709
+ const part = byId.get(id);
15710
+ return part !== void 0 && !GONE2.has(part.status) && (mainGroup === null || mainGroup.has(id));
15711
+ };
15712
+ const nextRoofs = [];
15713
+ const nextOpenings = [];
15714
+ const roofParts = source.model.parts.filter((def) => COVERING_ROLES.has(def.role));
15715
+ const kind = String(vehicle.meta.kind);
15716
+ const hull = bodyRoof(source, alive, kind);
15717
+ const hasRoof = COVERED_KINDS.has(kind) && (roofParts.some((def) => alive(def.id)) || hull !== null);
15718
+ if (!state.destroyed && hasRoof) {
15719
+ if (roofParts.some((def) => alive(def.id))) {
15720
+ 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 });
15721
+ for (const def of source.model.parts) {
15722
+ if (!alive(def.id) || !(COVERING_ROLES.has(def.role) || cabin && def.role === "glass")) continue;
15723
+ nextRoofs.push(localOf(def.box));
15724
+ }
15725
+ } else if (hull) {
15726
+ nextRoofs.push(hull);
15727
+ }
15728
+ for (const def of source.model.parts) {
15729
+ if (!OPENING_ROLES.has(def.role) || !(cabin || hull || COVERING_ROLES.has(def.role))) continue;
15730
+ if (!alive(def.id)) nextOpenings.push(localOf(def.box));
15731
+ }
15732
+ const frame = options.frame ?? vehicle.root;
15733
+ frame?.updateWorldMatrix?.(true, false);
15734
+ node.updateWorldMatrix?.(true, false);
15735
+ const inverse = node.matrixWorld.clone().invert();
15736
+ const V3 = node.position.constructor;
15737
+ for (const def of source.model.parts) {
15738
+ if (!OPENING_ROLES.has(def.role) || !alive(def.id)) continue;
15739
+ for (const hole of byId.get(def.id).holes) {
15740
+ if (!hole.through || hole.diameter < RAIN_OPENING_DIAMETER || !frame?.localToWorld) continue;
15741
+ const point = new V3(hole.point[0], hole.point[1], hole.point[2]);
15742
+ frame.localToWorld(point);
15743
+ point.applyMatrix4(inverse);
15744
+ nextOpenings.push({ x: point.x, z: point.z, halfX: hole.diameter / 2, halfZ: hole.diameter / 2, top: 0 });
15745
+ }
15746
+ }
15747
+ }
15748
+ roofs = nextRoofs;
15749
+ openings = nextOpenings;
15750
+ isShellChanged = true;
15751
+ };
15752
+ const place = () => {
15753
+ if (!node) return;
15754
+ node.updateWorldMatrix?.(true, false);
15755
+ const e = node.matrixWorld.elements;
15756
+ if (!isShellChanged && !hasMoved(e, placedAt)) return;
15757
+ placedAt.set(e);
15758
+ const scaleY = Math.hypot(e[4], e[5], e[6]);
15759
+ if (roofs.length === 0 || e[5] / (scaleY || 1) < UPRIGHT) {
15760
+ if (isShellChanged || bumpedX !== Infinity) cover.set([], [], true);
15761
+ bumpedX = Infinity;
15762
+ isShellChanged = false;
15763
+ return;
15764
+ }
15765
+ const scaleX = Math.hypot(e[0], e[1], e[2]);
15766
+ const scaleZ = Math.hypot(e[8], e[9], e[10]);
15767
+ const yaw = Math.atan2(e[2], e[0]);
15768
+ const toWorld = (f) => ({
15769
+ x: e[0] * f.x + e[4] * f.top + e[8] * f.z + e[12],
15770
+ z: e[2] * f.x + e[6] * f.top + e[10] * f.z + e[14],
15771
+ halfX: f.halfX * scaleX,
15772
+ halfZ: f.halfZ * scaleZ,
15773
+ yaw,
15774
+ top: e[1] * f.x + e[5] * f.top + e[9] * f.z + e[13]
15775
+ });
15776
+ const moved = Math.hypot(e[12] - bumpedX, e[14] - bumpedZ) >= RAIN_MOVE_STEP || Math.abs(yaw - bumpedYaw) >= RAIN_TURN_STEP;
15777
+ const isBump = isShellChanged || moved;
15778
+ cover.set(roofs.map(toWorld), openings.map(toWorld), isBump);
15779
+ isShellChanged = false;
15780
+ if (isBump) {
15781
+ bumpedX = e[12];
15782
+ bumpedZ = e[14];
15783
+ bumpedYaw = yaw;
15784
+ }
15785
+ };
15786
+ refreshShell();
15787
+ return { source: cover, refreshShell, place };
15788
+ }
15789
+
15115
15790
  // src/data/cabin.json
15116
15791
  var cabin_default = {
15117
15792
  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)",
@@ -15243,11 +15918,16 @@ export {
15243
15918
  CABIN_MINIMUMS,
15244
15919
  CABIN_SOURCE,
15245
15920
  CRASH_RULES,
15921
+ DOOR_SHELL_DEPTH,
15922
+ DOOR_SHELL_MAX_DEPTH,
15246
15923
  ENTRY_DUCK_FACTOR,
15247
15924
  JOINT_RULES,
15248
15925
  LEGACY_STATES,
15249
15926
  LEGACY_ZONE_IDS,
15250
15927
  PLUME_PUFFS,
15928
+ RAIN_MOVE_STEP,
15929
+ RAIN_OPENING_DIAMETER,
15930
+ RAIN_TURN_STEP,
15251
15931
  SEED_SALTS,
15252
15932
  SMOKE_LOOKS,
15253
15933
  SMOKE_WIND,
@@ -15267,8 +15947,10 @@ export {
15267
15947
  createTranslate,
15268
15948
  createVehicleDestructible,
15269
15949
  createVehicleKit,
15950
+ createVehicleRainCover,
15270
15951
  defaultDamageableKinds,
15271
15952
  defaultLodSettings,
15953
+ doorShell,
15272
15954
  engineBayVent,
15273
15955
  format,
15274
15956
  hash,
@@ -15276,6 +15958,7 @@ export {
15276
15958
  legacyLightId,
15277
15959
  legacyZoneId,
15278
15960
  listLocales,
15961
+ openEdgeCount,
15279
15962
  registerLegacySeeds,
15280
15963
  registerLocale,
15281
15964
  resolveStrings,