@adatechnology/game-vehicles-three 0.9.9 → 0.9.10

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.
@@ -56,9 +56,11 @@ var GameVehiclesThree = (() => {
56
56
  createGearGuess: () => createGearGuess,
57
57
  createProvingModule: () => createProvingModule,
58
58
  createVehicleBody: () => createVehicleBody,
59
+ createVehicleColliders: () => createVehicleColliders,
59
60
  createVehicleDashboard: () => createVehicleDashboard,
60
61
  createVehicleLamps: () => createVehicleLamps,
61
62
  createVehicleLod: () => createVehicleLod,
63
+ createVehicleLodQueue: () => createVehicleLodQueue,
62
64
  createVehicleSound: () => createVehicleSound,
63
65
  createVehiclesTestModule: () => createVehiclesTestModule,
64
66
  createVehiclesThree: () => createVehiclesThree,
@@ -77,11 +79,82 @@ var GameVehiclesThree = (() => {
77
79
  loadProvingModule: () => loadProvingModule,
78
80
  loadVehiclesTestModule: () => loadVehiclesTestModule,
79
81
  rpmShare: () => rpmShare,
80
- slideOfGrip: () => slideOfGrip
82
+ slideOfGrip: () => slideOfGrip,
83
+ vehicleColliders: () => vehicleColliders
81
84
  });
82
85
 
83
86
  // ../game-contracts/dist/index.js
84
87
  var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
88
+ var NEAREST = 0.3;
89
+ function sideOnImpulse(tnt, distance, nearest = NEAREST) {
90
+ if (!(tnt > 0)) return 0;
91
+ const w3 = Math.cbrt(tnt);
92
+ const z = Math.max(distance, nearest) / w3;
93
+ const near = z / 0.23 * (z / 0.23);
94
+ const far = z / 1.55;
95
+ const scaled = 0.067 * Math.sqrt(1 + near * near) / (z * z * Math.cbrt(1 + far * far * far));
96
+ return scaled * w3 * 100;
97
+ }
98
+ var ATMOSPHERE = 101325;
99
+ function sideOnOverpressure(tnt, distance, nearest = NEAREST) {
100
+ if (!(tnt > 0)) return 0;
101
+ const z = Math.max(distance, nearest) / Math.cbrt(tnt);
102
+ const ratio = 808 * (1 + (z / 4.5) ** 2) / (Math.sqrt(1 + (z / 0.048) ** 2) * Math.sqrt(1 + (z / 0.32) ** 2) * Math.sqrt(1 + (z / 1.35) ** 2));
103
+ return ratio * ATMOSPHERE;
104
+ }
105
+ var CHARGE_RADIUS = 1.3;
106
+ var CHARGE_SECONDS = 0.01;
107
+ var CHARGE_FLUX = 15e5;
108
+ var DOSE_PER_DEGREE = 300;
109
+ function chargeFireball(tnt) {
110
+ const cube = Math.cbrt(Math.max(0, tnt));
111
+ return { radius: CHARGE_RADIUS * cube, seconds: CHARGE_SECONDS * cube, flux: CHARGE_FLUX };
112
+ }
113
+ function fireballDose(fireball, distance) {
114
+ const share = distance <= fireball.radius ? 1 : (fireball.radius / distance) ** 2;
115
+ return fireball.flux * fireball.seconds * share;
116
+ }
117
+ function ignitionDose(ignitionC, ambientC = 20) {
118
+ return DOSE_PER_DEGREE * Math.max(1, ignitionC - ambientC);
119
+ }
120
+ var ATMOSPHERE2 = 101325;
121
+ var NEAREST_SCALED = 0.2;
122
+ var LOADED_MARGIN = 0.15;
123
+ var TNT_JOULES = 4184e3;
124
+ var SHOCK_COUPLING = 0.04;
125
+ var SHOCK_SCALED = 0.6;
126
+ function reflectedLoad(tnt, distance) {
127
+ if (!(tnt > 0)) return { pressure: 0, impulse: 0 };
128
+ const cube = Math.cbrt(tnt);
129
+ const nearest = NEAREST_SCALED * cube;
130
+ const side2 = sideOnOverpressure(tnt, distance, nearest);
131
+ const z = Math.max(distance, nearest) / cube;
132
+ const pressure = 2 * side2 * (7 * ATMOSPHERE2 + 4 * side2) / (7 * ATMOSPHERE2 + side2);
133
+ const impulse = sideOnImpulse(tnt, distance, nearest) * (2 + 4 / (1 + z * z));
134
+ return { pressure, impulse };
135
+ }
136
+ function waveWork(input) {
137
+ const load = reflectedLoad(input.tnt, input.distance);
138
+ const reach = Math.min(1, Math.max(0, input.reach));
139
+ const pressure = load.pressure * reach;
140
+ if (!(input.area > 0) || !(input.mass > 0) || pressure <= 0) return { energy: 0, shock: 0, pressure, loaded: 0 };
141
+ const loaded = Math.min(input.area, Math.PI * (input.distance + LOADED_MARGIN) ** 2);
142
+ const mass = input.mass * (loaded / input.area);
143
+ const impulse = load.impulse * reach * loaded;
144
+ const impulsive = impulse * impulse / (2 * mass);
145
+ const quasiStatic = pressure * loaded * Math.max(input.thickness, 1e-4);
146
+ return { energy: Math.min(impulsive, quasiStatic), shock: shockWork(input), pressure, loaded };
147
+ }
148
+ function shockWork(input) {
149
+ const cube = Math.cbrt(input.tnt);
150
+ if (!(cube > 0) || !(input.area > 0)) return 0;
151
+ const z = Math.max(input.distance, 0) / cube;
152
+ const radius = Math.cbrt(3 * input.tnt / (4 * Math.PI * 1600));
153
+ const share = Math.min(0.5, input.area / (4 * Math.PI * (input.distance + radius) ** 2));
154
+ const falloff = 1 + z / SHOCK_SCALED * (z / SHOCK_SCALED);
155
+ const reach = Math.min(1, Math.max(0, input.reach));
156
+ return SHOCK_COUPLING * input.tnt * TNT_JOULES * share * reach * reach / (falloff * falloff);
157
+ }
85
158
  var LAUNCHED = "launched";
86
159
  function launchBody(root, velocity) {
87
160
  root.userData[LAUNCHED] = [velocity[0], velocity[1], velocity[2]];
@@ -130,18 +203,44 @@ var GameVehiclesThree = (() => {
130
203
  const flame = flameBase * (1 - rules.flameFillInfluence * (1 - k));
131
204
  return 1 - (1 - Math.min(1, Math.max(0, spark))) * (1 - Math.min(1, Math.max(0, flame)));
132
205
  };
206
+ var FRAME_PHASES = ["input", "fixedSimulate", "lateSimulate", "present", "render", "idle"];
133
207
  var DEFERRED_QUEUE_ID = {
134
208
  DESTRUCTION_EVENTS: "destruction.events",
135
209
  BREACH_PAINT: "floorplan.breach-paint",
210
+ BREACH_CUT: "floorplan.breach-cut",
136
211
  AUDIO_VOICES: "audio.voices",
137
- VEHICLE_CREASE: "vehicles.crease"
212
+ VEHICLE_CREASE: "vehicles.crease",
213
+ AUDIO_OCCLUSION: "audio.occlusion",
214
+ FLUID_FILM: "fluids.film",
215
+ VEHICLE_LOD_BATCH: "vehicles.lod-batch",
216
+ SETTLED_BATCH: "destruction.settled-batch",
217
+ STATIC_BATCH: "render.static-batch",
218
+ ANIMALS_STATIC_BATCH: "animals.static-batch",
219
+ CHARACTERS_STATIC_BATCH: "characters.static-batch",
220
+ HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
221
+ DESTRUCTION_PREFIT: "destruction.prefit"
138
222
  };
139
223
  var DEFERRED_PRIORITY = {
140
224
  [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
141
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
225
+ // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
226
+ [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
227
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
142
228
  [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
143
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
229
+ [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
230
+ [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
231
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
232
+ [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
233
+ [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
234
+ [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
235
+ [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
236
+ [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
237
+ [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
238
+ [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
144
239
  };
240
+ var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
241
+ function drainDetached(queue, budgetMs, clock = () => performance.now()) {
242
+ return queue.run(clock() + budgetMs, clock);
243
+ }
145
244
  var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
146
245
  var warnedKeys = () => {
147
246
  const holder = globalThis;
@@ -251,6 +350,22 @@ var GameVehiclesThree = (() => {
251
350
  var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing2) => `land_${surface}_${landing2}`));
252
351
  var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
253
352
  var SWING_LEAD_SECONDS = { punch: 0.07, kick: 0.09, shove: 0, blade: 0.05, blunt: 0.1, chop: 0.11 };
353
+ var WORKER_KIND_ID = {
354
+ GROUND_TILES: "destruction.ground-tiles",
355
+ CROWD_PHYSICS: "crowd.physics",
356
+ PIECE_BOXES: "destruction.piece-boxes",
357
+ STATIC_COLLIDERS: "destruction.static-colliders",
358
+ SHAPES_GENERATE: "shapes.generate",
359
+ WORLD_REGION: "world.region"
360
+ };
361
+ var WORKER_KIND_DEFAULTS = {
362
+ [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
363
+ [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
364
+ [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
365
+ [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
366
+ [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
367
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
368
+ };
254
369
 
255
370
  // ../game-vehicles-fleet/dist/index.js
256
371
  var military = [
@@ -3859,6 +3974,32 @@ var GameVehiclesThree = (() => {
3859
3974
  }
3860
3975
  ];
3861
3976
  }
3977
+ var THICKNESS_STEP = 0.0625;
3978
+ var THINNEST = 0.15;
3979
+ var CLEARANCE = 15e-4;
3980
+ var SPOKE_HALF_THICKNESS = 0.02;
3981
+ var DISH_HALF_THICKNESS = 0.025;
3982
+ function sharesPlaneWithDish(reach, scale) {
3983
+ const dishReach = reach * 0.9;
3984
+ const outer = Math.abs(reach + SPOKE_HALF_THICKNESS * scale - (dishReach + DISH_HALF_THICKNESS));
3985
+ const inner = Math.abs(reach - SPOKE_HALF_THICKNESS * scale - (dishReach - DISH_HALF_THICKNESS));
3986
+ return outer < CLEARANCE || inner < CLEARANCE;
3987
+ }
3988
+ function separateSpokes(context) {
3989
+ for (const wheel of context.wheels) {
3990
+ let previous = 1 + THICKNESS_STEP;
3991
+ for (const child of wheel.children) {
3992
+ const mesh2 = child;
3993
+ const type = mesh2.geometry?.type;
3994
+ if (!mesh2.isMesh || type !== "BufferGeometry" && type !== "BoxGeometry" || mesh2.position.z === 0) continue;
3995
+ const reach = Math.abs(mesh2.position.z);
3996
+ let scale = previous - THICKNESS_STEP;
3997
+ while (sharesPlaneWithDish(reach, scale) && scale > THINNEST) scale -= THICKNESS_STEP / 2;
3998
+ mesh2.scale.z = Math.max(scale, THINNEST);
3999
+ previous = scale;
4000
+ }
4001
+ }
4002
+ }
3862
4003
  function installBoatsExtra(fx) {
3863
4004
  const kit = fx.kit;
3864
4005
  const THREE = kit.THREE;
@@ -4292,12 +4433,12 @@ var GameVehiclesThree = (() => {
4292
4433
  cs.castShadow = false;
4293
4434
  [1, -1].forEach(function(s) {
4294
4435
  c.roundBox(2.6, 0.06, 0.42, 0.02, teak, -2.45, 0.86, s * 0.82);
4295
- c.roundBox(2.6, 0.38, 0.06, 0.02, white, -2.45, 0.67, s * 0.6);
4436
+ c.roundBox(2.6, 0.376, 0.06, 0.02, white, -2.45, 0.671, s * 0.6);
4296
4437
  c.roundBox(2.8, 0.22, 0.05, 0.02, white, -2.4, 1.02, s * (H.sheerAt(-2.4).z - 0.32));
4297
4438
  c.cylinder(0.06, 0.07, 0.11, MT.chrome, -1.6, 1.15, s * 1.06);
4298
4439
  c.cylinder(0.035, 0.035, 0.02, MT.chrome, -1.6, 1.21, s * 1.06);
4299
4440
  });
4300
- c.roundBox(0.3, 0.38, 1.2, 0.03, white, -3.75, 0.67, 0);
4441
+ c.roundBox(0.3, 0.376, 1.2, 0.03, white, -3.75, 0.671, 0);
4301
4442
  c.seatTops.push({ x: -2.6, y: 0.9, z: 0.82, w: 0.42, l: 2.4 }, { x: -2.6, y: 0.9, z: -0.82, w: 0.42, l: 2.4 });
4302
4443
  const trST = [
4303
4444
  [-1.1, 0.8, 1.56, 2, 6],
@@ -4706,9 +4847,9 @@ var GameVehiclesThree = (() => {
4706
4847
  });
4707
4848
  c.roundBox(1.6, 0.03, 0.1, 0.01, MT.wood, 0.3, 0.05, 0.38, { rot: [0.2, 0, 0] });
4708
4849
  c.roundBox(1.6, 0.03, 0.1, 0.01, MT.wood, 0.3, 0.06, 0.28, { rot: [0.2, 0, 0] });
4709
- c.roundBox(0.36, 0.24, 0.26, 0.03, CM("#ffffff", { roughness: 0.5 }), 1.25, 0.14, 0.15);
4850
+ c.roundBox(0.36, 0.24, 0.26, 0.03, CM("#ffffff", { roughness: 0.5 }), 1.25, 0.142, 0.15);
4710
4851
  c.roundBox(0.1, 0.03, 0.02, 5e-3, CM("#d01c1c"), 1.25, 0.2, 0.282);
4711
- c.roundBox(0.03, 0.1, 0.02, 5e-3, CM("#d01c1c"), 1.25, 0.2, 0.282);
4852
+ c.roundBox(0.03, 0.1, 0.02, 5e-3, CM("#d01c1c"), 1.25, 0.2, 0.284);
4712
4853
  const buoy = c.add(new THREE.TorusGeometry(0.24, 0.06, 10, 24), CM("#f0f0ea", { roughness: 0.6 }), 1.1, 0.1, -0.2);
4713
4854
  buoy.rotation.x = PI / 2;
4714
4855
  const motor = EA.outboard(c, -1.99, 0.55, 0, { k: 1, tiller: true, label: "40", col: "#1d1f22" });
@@ -4844,7 +4985,7 @@ var GameVehiclesThree = (() => {
4844
4985
  return Math.min(0.06 - y, x - x0 - 0.04);
4845
4986
  }),
4846
4987
  CM("#1d2023", { roughness: 0.6 }),
4847
- { sz: 1.004, dy: 3e-3 }
4988
+ { sz: 1.004, dy: 3e-3, ends: false }
4848
4989
  );
4849
4990
  EA.sheerTube(c, H, x0 + 0.02, 6.2, 0.07, blk, { dy: -0.1, dz: 0.02 });
4850
4991
  const deck = c.add(EA.deckGeo(H, x0 + 0.02, 6.32, { n: 40, m: 10, crown: 0.05 }), deckC);
@@ -7935,7 +8076,7 @@ var GameVehiclesThree = (() => {
7935
8076
  [0.62, 0.48, -0.48, -0.62].forEach(function(z) {
7936
8077
  const s = dg.at(dg.uz(z), 0.25);
7937
8078
  c2.cylinder(0.045, 0.045, 0.1, EXH, s.p.x - 0.02, 0.25, z, "x");
7938
- c2.cylinder(0.036, 0.036, 0.102, MT.dark, s.p.x - 0.02, 0.25, z, "x");
8079
+ c2.cylinder(0.036, 0.036, 0.106, MT.dark, s.p.x - 0.02, 0.25, z, "x");
7939
8080
  });
7940
8081
  const lip = K.grid(-1, 0, { z1: 0.7, y0: 0.88, y1: 0.97, du: 0.03, dv: 0.02 });
7941
8082
  K.skin(lip, GLOSS, { u0: 0.05, u1: 0.95, yb: 0.925, yt: 0.955, off: 0.016, thick: 0.02, nv: 2 });
@@ -8348,7 +8489,7 @@ var GameVehiclesThree = (() => {
8348
8489
  side: s,
8349
8490
  noPart: true
8350
8491
  });
8351
- c.roundBox(0.03, 0.12, 0.42, 0.02, MT.dark, bx + 0.125, by - bh * 0.3, s * 0.35);
8492
+ c.roundBox(0.03, 0.12, 0.42, 0.02, MT.dark, bx + 0.119, by - bh * 0.3, s * 0.35);
8352
8493
  });
8353
8494
  }
8354
8495
  c.roundBox(0.06, 0.06, 0.12, 0.02, MT.steel, bx + 0.13, by - bh * 0.35, 0);
@@ -8451,7 +8592,7 @@ var GameVehiclesThree = (() => {
8451
8592
  -(W - 0.2) / 2 + (k + 0.5) * (W - 0.2) / 8
8452
8593
  );
8453
8594
  [1, -1].forEach(function(s) {
8454
- c.roundBox(0.06, 0.32, 0.06, 0.01, MT.trim, rear + 0.12, ry - 0.2, s * 0.43);
8595
+ c.roundBox(0.06, 0.32, 0.06, 0.01, MT.trim, rear + 0.118, ry - 0.2, s * 0.43);
8455
8596
  });
8456
8597
  m.rearBumper = bar;
8457
8598
  c.part("bumper", trl("labels.rear_bumper"), bar, new V3(rear, 0.52, 0), 1);
@@ -9513,7 +9654,7 @@ var GameVehiclesThree = (() => {
9513
9654
  });
9514
9655
  const vg = c.roundBox(0.32, 0.2, 0.03, 0.03, MT.armorGlass, 1.3, 2.45, zs);
9515
9656
  kit.asGlass(c, vg, s > 0 ? lbl("right_armored_viewport") : lbl("left_armored_viewport"), "laminated");
9516
- c.roundBox(0.4, 0.28, 0.02, 0.03, plate, 1.3, 2.45, zs - s * 4e-3);
9657
+ c.roundBox(0.4, 0.28, 0.02, 0.03, plate, 1.3, 2.45, zs - s * 8e-3);
9517
9658
  for (let x = rear + 0.2; x < bx0; x += 0.3) {
9518
9659
  c.sphere(0.018, MT.steel, x, 1.2, zs);
9519
9660
  c.sphere(0.018, MT.steel, x, 2.98, zs);
@@ -9622,7 +9763,7 @@ var GameVehiclesThree = (() => {
9622
9763
  const hx0 = 0.02, hx1 = 1.84 + FX, hy = 1.48;
9623
9764
  [1, -1].forEach(function(s) {
9624
9765
  c.roundBox(hx1 - hx0, 0.38, 0.035, 0.02, paint, (hx0 + hx1) / 2, 1.22, s * 0.36, { def: true });
9625
- for (let j = 0; j < 5; j++) c.roundBox(0.22, 0.025, 0.012, 8e-3, MT.dark, 0.75 + j * 0.16, 1.24, s * 0.38);
9766
+ for (let j = 0; j < 5; j++) c.roundBox(0.22, 0.025, 0.012, 8e-3, MT.dark, 0.75 + j * 0.16, 1.24, s * (0.38 + j % 2 * 3e-3));
9626
9767
  c.roundBox(1, 0.03, 0.02, 0.01, CM("#e9e6dd"), 0.55, 1.36, s * 0.38);
9627
9768
  c.text("275", 0.3, 0.14, 0.32, 1.2, s * 0.384, s > 0 ? "+z" : "-z", { fg: "#f2efe6" });
9628
9769
  });
@@ -10096,7 +10237,7 @@ var GameVehiclesThree = (() => {
10096
10237
  const hs = c.add(
10097
10238
  EA.foilGeo(
10098
10239
  [
10099
- { p: [-3.9, 1.44, 0], c: 0.3, t: 0.1 },
10240
+ { p: [-3.9, 1.44, s * 2e-3], c: 0.3, t: 0.1 },
10100
10241
  { p: [-3.95, 1.44, s * 0.42], c: 0.22, t: 0.09 }
10101
10242
  ],
10102
10243
  { up: "y", n: 8 }
@@ -10335,7 +10476,7 @@ var GameVehiclesThree = (() => {
10335
10476
  },
10336
10477
  lbl("chin_windows"),
10337
10478
  "tempered",
10338
- { pos: new V3(2.3, 0.88, 0) }
10479
+ { pos: new V3(2.3, 0.88, 0), k: 0.988 }
10339
10480
  );
10340
10481
  [1, -1].forEach(function(s) {
10341
10482
  EA.fuseGlass(
@@ -10435,7 +10576,7 @@ var GameVehiclesThree = (() => {
10435
10576
  tipCol: "#e6e4dd",
10436
10577
  phase: 0.25
10437
10578
  });
10438
- c.roundBox(0.5, 0.12, 0.16, 0.05, MT.steel, 0, 2.8, 0);
10579
+ c.roundBox(0.5, 0.12, 0.16, 0.05, MT.steel, 0, 2.797, 0);
10439
10580
  const bm = boom(
10440
10581
  c,
10441
10582
  EA,
@@ -10469,7 +10610,7 @@ var GameVehiclesThree = (() => {
10469
10610
  const hs = c.add(
10470
10611
  EA.foilGeo(
10471
10612
  [
10472
- { p: [-4.05, 1.68, 0], c: 0.42, t: 0.12, cam: -0.04 },
10613
+ { p: [-4.05, 1.68, s * 2e-3], c: 0.42, t: 0.12, cam: -0.04 },
10473
10614
  { p: [-4.1, 1.68, s * 0.99], c: 0.38, t: 0.11, cam: -0.04 }
10474
10615
  ],
10475
10616
  { up: "y", n: 8 }
@@ -10718,7 +10859,7 @@ var GameVehiclesThree = (() => {
10718
10859
  },
10719
10860
  lbl("chin_windows"),
10720
10861
  "tempered",
10721
- { pos: new V3(3.05, 0.95, 0) }
10862
+ { pos: new V3(3.05, 0.95, 0), k: 0.988 }
10722
10863
  );
10723
10864
  [1, -1].forEach(function(s) {
10724
10865
  EA.fuseGlass(c, ST, EA.sideKeepP(fdP, 0.6, s), s > 0 ? lbl("co_pilot_door_window") : lbl("pilot_door_window"), "tempered", {
@@ -10883,7 +11024,7 @@ var GameVehiclesThree = (() => {
10883
11024
  const hs = c.add(
10884
11025
  EA.foilGeo(
10885
11026
  [
10886
- { p: [-5.75, 2.1, 0], c: 0.62, t: 0.12, cam: -0.03 },
11027
+ { p: [-5.75, 2.1, s * 2e-3], c: 0.62, t: 0.12, cam: -0.03 },
10887
11028
  { p: [-5.85, 2.1, s * 1.05], c: 0.52, t: 0.11, cam: -0.03 }
10888
11029
  ],
10889
11030
  { up: "y", n: 8 }
@@ -11296,7 +11437,7 @@ var GameVehiclesThree = (() => {
11296
11437
  EA.colorize(
11297
11438
  EA.foilGeo(
11298
11439
  [
11299
- { p: [-8.3, 2.75, 0], c: 1, t: 0.1 },
11440
+ { p: [-8.3, 2.75, s * 2e-3], c: 1, t: 0.1 },
11300
11441
  { p: [-8.5, 2.75, s * 1.85], c: 0.7, t: 0.09 }
11301
11442
  ],
11302
11443
  { up: "y", n: 8 }
@@ -12366,7 +12507,7 @@ var GameVehiclesThree = (() => {
12366
12507
  const floor = c.roundBox(L, 0.1, W, 0.02, wood, cx, y0, 0, { def: true });
12367
12508
  c.roundBox(L - 0.1, 0.14, 0.2, 0.02, MT.trim, cx, y0 - 0.12, 0.45);
12368
12509
  c.roundBox(L - 0.1, 0.14, 0.2, 0.02, MT.trim, cx, y0 - 0.12, -0.45);
12369
- for (let xs = x1 + 0.2; xs < x0; xs += 0.55) c.roundBox(0.08, 0.1, W - 0.05, 0.02, MT.trim, xs, y0 - 0.1, 0);
12510
+ for (let xs = x1 + 0.2; xs < x0; xs += 0.55) c.roundBox(0.08, 0.1, W - 0.05, 0.02, MT.trim, xs, y0 - 0.102, 0);
12370
12511
  const sides = [];
12371
12512
  [1, -1].forEach(function(s) {
12372
12513
  const sd = c.roundBox(L, sideH, 0.06, 0.02, wood, cx, y0 + sideH / 2 + 0.05, s * (W / 2 - 0.03), { def: true });
@@ -12377,7 +12518,7 @@ var GameVehiclesThree = (() => {
12377
12518
  c.roundBox(L, 0.03, 0.015, 6e-3, CM("#3a3c2e", { roughness: 0.9 }), cx, y0 + 0.05 + sideH * t * 2, s * (W / 2 + 2e-3));
12378
12519
  });
12379
12520
  });
12380
- c.roundBox(0.06, sideH, W, 0.02, wood, x0 - 0.03, y0 + sideH / 2 + 0.05, 0, { def: true });
12521
+ c.roundBox(0.06, sideH, W, 0.02, wood, x0 - 0.028, y0 + sideH / 2 + 0.05, 0, { def: true });
12381
12522
  const tg = c.roundBox(0.06, sideH * 0.7, W - 0.1, 0.02, wood, x1 - 0.02, y0 - sideH * 0.3, 0);
12382
12523
  tg.rotation.z = 0.08;
12383
12524
  const top = y0 + sideH + bowH, yb = y0 + sideH + 0.05, nseg = 20, pos = [], idx = [];
@@ -12771,7 +12912,7 @@ var GameVehiclesThree = (() => {
12771
12912
  top: roofY + 0.03,
12772
12913
  k: 0.28,
12773
12914
  holes,
12774
- archInner: W / 2 - ww - 0.1,
12915
+ archInner: W / 2 - ww - 0.098,
12775
12916
  sub: 0.18,
12776
12917
  bev: 0.025
12777
12918
  });
@@ -13104,8 +13245,7 @@ var GameVehiclesThree = (() => {
13104
13245
  [1.3, roofY, 0.1],
13105
13246
  [F - 0.04, 1.02, 0.06],
13106
13247
  [F, 0.9, 0.05],
13107
- [2.05, 0.46, 0.06],
13108
- [-1.4, 0.44, 0.04]
13248
+ [2.05, 0.46, 0.06]
13109
13249
  ];
13110
13250
  const arches = axles.map(function(x) {
13111
13251
  return [x, wr, wr + 0.09];
@@ -13183,8 +13323,8 @@ var GameVehiclesThree = (() => {
13183
13323
  [1, -1].forEach(function(s) {
13184
13324
  c.roundBox(1.6, 0.16, 0.12, 0.04, OLIVE_STEEL, (axles[1] + axles[2]) / 2, wr, s * (W / 2 - ww - 0.1));
13185
13325
  c.cylinder(0.12, 0.12, 0.2, OLIVE_STEEL, (axles[1] + axles[2]) / 2, wr, s * (W / 2 - ww - 0.1), "z");
13186
- c.roundBox(1, 0.05, 0.32, 0.02, paintMat(c, col), axles[0], 1.12, s * (W / 2 - 0.16), { def: true });
13187
- c.roundBox(2.35, 0.05, 0.32, 0.02, paintMat(c, col), (axles[1] + axles[2]) / 2, 1.12, s * (W / 2 - 0.16), { def: true });
13326
+ c.roundBox(1, 0.05, 0.32, 0.02, paintMat(c, col), axles[0], 1.12, s * (W / 2 - 0.158), { def: true });
13327
+ c.roundBox(2.35, 0.05, 0.32, 0.02, paintMat(c, col), (axles[1] + axles[2]) / 2, 1.12, s * (W / 2 - 0.158), { def: true });
13188
13328
  c.roundBox(1.2, 0.26, 0.28, 0.03, paintMat(c, OLIVE2), -1.45, 1.28, s * (W / 2 - 0.17));
13189
13329
  [-0.95, -1.95].forEach(function(x) {
13190
13330
  c.roundBox(0.3, 0.2, 0.02, 0.01, MT.dark, x, 1.28, s * (W / 2 - 0.025));
@@ -13341,7 +13481,7 @@ var GameVehiclesThree = (() => {
13341
13481
  m.kind = "car";
13342
13482
  m.bullet = true;
13343
13483
  const low = c.roundBox(6.6, 0.62, 2, 0.08, paintMat(c, col), -0.1, 0.78, 0, { def: true, sub: 0.3 });
13344
- c.roundBox(0.55, 0.62, 2, 0.06, paintMat(c, col), 3.1, 0.8, 0, { def: true, rot: [0, 0, -0.95] });
13484
+ c.roundBox(0.55, 0.62, 2.004, 0.06, paintMat(c, col), 3.1, 0.8, 0, { def: true, rot: [0, 0, -0.95] });
13345
13485
  const items = [
13346
13486
  [R, 1.05, 0.04],
13347
13487
  [R - 0.02, deckY - 0.04, 0.05],
@@ -13384,7 +13524,7 @@ var GameVehiclesThree = (() => {
13384
13524
  (ex0 + ex1) / 2
13385
13525
  );
13386
13526
  scale(c, nB, bcen, 1.45);
13387
- c.roundBox(ex1 - ex0 - 0.1, 0.02, 2.1, 0.01, BAY_LIGHT, bcen.x, 0.95, 0);
13527
+ c.roundBox(ex1 - ex0 - 0.1, 0.012, 2.1, 0.01, BAY_LIGHT, bcen.x, 0.957, 0);
13388
13528
  [1, -1].forEach(function(sd) {
13389
13529
  c.roundBox(ex1 - ex0 - 0.1, 0.55, 0.02, 0.01, BAY_LIGHT, bcen.x, 1.25, sd * 1.08);
13390
13530
  });
@@ -13410,12 +13550,12 @@ var GameVehiclesThree = (() => {
13410
13550
  c.roundBox(0.55, 0.42, 0.03, 0.01, MT.rubber, 2.95, 0.86, s * (W / 2 + 0.05));
13411
13551
  c.part("armor", s > 0 ? trl("labels.right_skirt") : trl("labels.left_skirt"), sk, new V3(-0.2, 0.86, s * W / 2), 1.2);
13412
13552
  c.roundBox(0.5, 0.03, 0.6, 0.01, paintMat(c, col), F - 0.25, 1.08, s * tz, { rot: [0, 0, -0.35] });
13413
- c.roundBox(0.03, 0.5, 0.55, 0.01, MT.rubber, R + 0.02, 0.85, s * tz);
13553
+ c.roundBox(0.03, 0.5, 0.55, 0.01, MT.rubber, R + 0.015, 0.85, s * tz);
13414
13554
  star(c, 0.6, 1.3, s * (H.half(1.3) + 0.01), 0.17, s > 0 ? "+z" : "-z", { ring: true });
13415
13555
  c.text(trl("texts.army"), 1, 0.16, -1.5, 1.3, s * (H.half(1.3) + 0.01), s > 0 ? "+z" : "-z", { fg: "#dcdace", size: 0.7 });
13416
13556
  guardedHeadlight(c, 2.95, gl(2.95) + 0.16, s * 1.3, s, { style: "round" });
13417
13557
  c.roundBox(0.1, 0.16, 0.08, 0.02, OLIVE_STEEL, 2.9, gl(2.9) + 0.04, s * 1.3);
13418
- c.roundBox(0.1, 0.18, 0.3, 0.03, OLIVE_STEEL, R - 0.04, 1.35, s * 1.25);
13558
+ c.roundBox(0.1, 0.18, 0.3, 0.03, OLIVE_STEEL, R - 0.037, 1.35, s * 1.25);
13419
13559
  kit.taillight(c, { style: "round2", x: R - 0.08, y: 1.35, z: s * 1.25, w: 0.2, h: 0.09, d: 0.05, side: s });
13420
13560
  c.tube(
13421
13561
  [
@@ -13457,7 +13597,7 @@ var GameVehiclesThree = (() => {
13457
13597
  { rot: [0, 0, -0.18] }
13458
13598
  );
13459
13599
  hatch(c, 2.05, roofY - 0.1, -0.78, 0.28, 0, OLIVE_STEEL, { yaw: 0 });
13460
- kit.seat(c, 1.95, 0.62, -0.78, { w: 0.44, h: 0.34, back: 0.5, lean: 0.5, mat: CM("#2f3226", { roughness: 0.9 }) });
13600
+ kit.seat(c, 1.95, 0.62, -0.76, { w: 0.44, h: 0.34, back: 0.5, lean: 0.5, mat: CM("#2f3226", { roughness: 0.9 }) });
13461
13601
  [-0.95, -0.78, -0.61].forEach(function(z, i) {
13462
13602
  periscope(c, 2.3, roofY - 0.08, z, 0.14, i === 1 ? lbl("driver_periscope") : null);
13463
13603
  });
@@ -13579,14 +13719,14 @@ var GameVehiclesThree = (() => {
13579
13719
  const g = new THREE.Group();
13580
13720
  g.position.set(x, y, z);
13581
13721
  c.vehicle.add(g);
13582
- const wmsh = new THREE.Mesh(new THREE.CylinderGeometry(rad, rad, w * 0.8, 24), wm);
13722
+ const wmsh = new THREE.Mesh(new THREE.CylinderGeometry(rad, rad, w * (opt.width ?? 0.8), 24), wm);
13583
13723
  wmsh.rotation.x = PI / 2;
13584
13724
  wmsh.castShadow = true;
13585
13725
  g.add(wmsh);
13586
13726
  if (opt.tires)
13587
13727
  [-1, 1].forEach(function(q) {
13588
13728
  const t = new THREE.Mesh(new THREE.TorusGeometry(rad - 0.035, 0.035, 6, 24), MT.rubber);
13589
- t.position.z = q * w * 0.22;
13729
+ t.position.z = q * w * (opt.tireAt ?? 0.22);
13590
13730
  g.add(t);
13591
13731
  });
13592
13732
  const hb = new THREE.Mesh(new THREE.CylinderGeometry(rad * 0.32, rad * 0.32, w * 0.86, 10), MT.steel);
@@ -13603,21 +13743,21 @@ var GameVehiclesThree = (() => {
13603
13743
  for (let k = 0; k < 6; k++) {
13604
13744
  const b = new THREE.Mesh(G2.roundedBox(rad * 1.5, 0.05, 0.04, 0.01), wm);
13605
13745
  b.rotation.z = k / 6 * PI;
13606
- b.position.z = (z > 0 ? 1 : -1) * w * 0.42;
13746
+ b.position.z = (z > 0 ? 1 : -1) * (w * 0.42 + k * 3e-3);
13607
13747
  g.add(b);
13608
13748
  }
13609
13749
  c.spin.push({ o: g, axis: "z", v: 0, track: true });
13610
13750
  return g;
13611
13751
  }
13612
13752
  for (let i = 0; i < n; i++) wheel(xs + i * sp, r + th, r, { tires: true });
13613
- wheel(x0, yS, rS, { teeth: true });
13614
- wheel(x1, yI, rI, { spokes: true, tires: true });
13753
+ wheel(x0, yS, rS, { teeth: true, width: 0.76 });
13754
+ wheel(x1, yI, rI, { spokes: true, tires: true, width: 0.76, tireAt: 0.2 });
13615
13755
  const topY = function(x) {
13616
13756
  return yS + rS + th / 2 + (yI + rI - yS - rS) * (x - x0) / (x1 - x0);
13617
13757
  };
13618
13758
  for (let q = 0; q < 4; q++) {
13619
13759
  const xr = x0 + (x1 - x0) * (0.2 + q * 0.2);
13620
- wheel(xr, topY(xr) - rr - th / 2 - 0.01, rr, {});
13760
+ wheel(xr, topY(xr) - rr - th / 2 - 0.01, rr, { width: 0.7 });
13621
13761
  }
13622
13762
  const path = [], segs = 12;
13623
13763
  function arc(cx, cy, rad, a0, a1) {
@@ -13641,7 +13781,7 @@ var GameVehiclesThree = (() => {
13641
13781
  const curve = new THREE.SplineCurve(pts.concat([pts[0]])), lenT = curve.getLength(), nl = Math.round(lenT / 0.15), links = [];
13642
13782
  for (let l = 0; l < nl; l++) {
13643
13783
  const t = l / nl, p = curve.getPointAt(t), tg = curve.getTangentAt(t), ang = Math.atan2(tg.y, tg.x);
13644
- const lg = G2.roundedBox(0.13, th, w, 0.015);
13784
+ const lg = G2.roundedBox(0.13, th, w - l % 2 * 4e-3, 0.015);
13645
13785
  lg.applyMatrix4(new THREE.Matrix4().makeRotationZ(ang).setPosition(p.x, p.y, 0));
13646
13786
  links.push(lg);
13647
13787
  const gh2 = G2.roundedBox(0.05, 0.05, 0.05, 0.01);
@@ -17345,9 +17485,9 @@ var GameVehiclesThree = (() => {
17345
17485
  ],
17346
17486
  col
17347
17487
  );
17348
- lamp(c, { style: "rect", x: 0.57, y: 0.91, z: 0, w: 0.2, h: 0.11, d: 0.08, side: 1, label: trl("labels.headlight") });
17488
+ lamp(c, { style: "rect", x: 0.575, y: 0.91, z: 0, w: 0.2, h: 0.11, d: 0.08, side: 1, label: trl("labels.headlight") });
17349
17489
  c.roundBox(0.1, 0.07, 0.18, 0.02, blk, 0.36, 1.04, 0, { rot: [0, 0, 0.4] });
17350
- c.roundBox(0.02, 0.05, 0.15, 0.01, MT.gauge, 0.39, 1.06, 0, { rot: [0, 0, 0.4] });
17490
+ c.roundBox(0.02, 0.05, 0.15, 0.01, MT.gauge, 0.39, 1.064, 0, { rot: [0, 0, 0.4] });
17351
17491
  handlebar(c, 0.36, 1.03, 0.37, { rise: 0.04, back: 0.06, mat: MT.chrome, stalk: 0.19 });
17352
17492
  [1, -1].forEach(function(s) {
17353
17493
  blinker(c, 0.48, 0.9, s * 0.17, true);
@@ -17549,7 +17689,7 @@ var GameVehiclesThree = (() => {
17549
17689
  body(
17550
17690
  c,
17551
17691
  [
17552
- [0.44, 1.13, 0.85, 0.24, 2.6],
17692
+ [0.435, 1.13, 0.85, 0.24, 2.6],
17553
17693
  [0.55, 1.11, 0.87, 0.24, 2.6],
17554
17694
  [0.6, 1.05, 0.91, 0.16, 2.4]
17555
17695
  ],
@@ -17716,7 +17856,7 @@ var GameVehiclesThree = (() => {
17716
17856
  body(
17717
17857
  c,
17718
17858
  [
17719
- [0.62, 1.32, 0.98, 0.3, 2.6],
17859
+ [0.615, 1.32, 0.98, 0.3, 2.6],
17720
17860
  [0.72, 1.28, 1, 0.3, 2.6],
17721
17861
  [0.78, 1.2, 1.02, 0.22, 2.4]
17722
17862
  ],
@@ -18220,17 +18360,17 @@ var GameVehiclesThree = (() => {
18220
18360
  return Math.max(0.94 - x, x - 1.69, Math.abs(z) - (0.44 - 0.16 * t * t));
18221
18361
  }
18222
18362
  });
18223
- const cut = kit.cutMesh(shellM, holes, 50);
18363
+ const cut2 = kit.cutMesh(shellM, holes, 50);
18224
18364
  c.deform.push(shellM);
18225
18365
  function glassFrom(geo, label, type) {
18226
18366
  if (!geo || !geo.attributes.position.count) return null;
18227
18367
  return kit.addGlass(c, geo, label, type, { mat: MT.glass });
18228
18368
  }
18229
- glassFrom(cut.windshield, lbl("windshield"), "laminated");
18230
- glassFrom(cut.rear_window, lbl("rear_window"), "laminated");
18369
+ glassFrom(cut2.windshield, lbl("windshield"), "laminated");
18370
+ glassFrom(cut2.rear_window, lbl("rear_window"), "laminated");
18231
18371
  [1, -1].forEach(function(sd) {
18232
- glassFrom(cut["front_window" + sd], sd > 0 ? lbl("front_window_right") : lbl("front_window_left"), "tempered");
18233
- glassFrom(cut["quarter_window" + sd], sd > 0 ? lbl("rear_quarter_glass_right") : lbl("rear_quarter_glass_left"), "tempered");
18372
+ glassFrom(cut2["front_window" + sd], sd > 0 ? lbl("front_window_right") : lbl("front_window_left"), "tempered");
18373
+ glassFrom(cut2["quarter_window" + sd], sd > 0 ? lbl("rear_quarter_glass_right") : lbl("rear_quarter_glass_left"), "tempered");
18234
18374
  });
18235
18375
  [1, -1].forEach(function(sd) {
18236
18376
  ;
@@ -18325,7 +18465,7 @@ var GameVehiclesThree = (() => {
18325
18465
  c.plate(1.845, 0.55, 0, "+x");
18326
18466
  c.plate(-1.98, 0.62, 0, "-x");
18327
18467
  c.roundBox(0.06, 0.03, 0.14, 0.01, MT.chrome, -1.96, 0.71, 0);
18328
- const hood = kit.makeHood(c, cut.hood, {
18468
+ const hood = kit.makeHood(c, cut2.hood, {
18329
18469
  x0: 0.95,
18330
18470
  col: hex,
18331
18471
  open: 1.15,
@@ -18647,8 +18787,8 @@ var GameVehiclesThree = (() => {
18647
18787
  return b;
18648
18788
  }
18649
18789
  function plateMoto(c, x, y, txt) {
18650
- c.roundBox(0.02, 0.15, 0.2, 8e-3, MT.trim, x + 0.012, y, 0);
18651
- c.text(txt || kit.config.plate.slice(0, 5), 0.2, 0.135, x, y, 0, "-x", {
18790
+ c.roundBox(0.02, 0.15, 0.2, 8e-3, MT.trim, x + 9e-3, y, 0);
18791
+ c.text(txt || kit.config.plate.slice(0, 5), 0.2, 0.135, x - 3e-3, y, 0, "-x", {
18652
18792
  w: 300,
18653
18793
  h: 220,
18654
18794
  bg: "#f2f2ee",
@@ -18763,7 +18903,7 @@ var GameVehiclesThree = (() => {
18763
18903
  g.add(d);
18764
18904
  for (let q = 0; q < 12; q++) {
18765
18905
  const a2 = q / 12 * PI * 2, sl = new THREE.Mesh(G2.roundedBox(rimR * 0.42, 0.016, 6e-3, 5e-3), o.slot || CM("#1c1e21", { metalness: 0.5, roughness: 0.4 }));
18766
- sl.position.set(Math.cos(a2) * rimR * 0.62, Math.sin(a2) * rimR * 0.62, s * (hw * 0.72 + 6e-3));
18906
+ sl.position.set(Math.cos(a2) * rimR * 0.62, Math.sin(a2) * rimR * 0.62, s * (hw * 0.72 + 0.0105));
18767
18907
  sl.rotation.z = a2;
18768
18908
  g.add(sl);
18769
18909
  }
@@ -18861,7 +19001,7 @@ var GameVehiclesThree = (() => {
18861
19001
  body(
18862
19002
  c,
18863
19003
  [
18864
- [0.34, 0.36, 0.29, 0.28, 2.6],
19004
+ [0.335, 0.36, 0.29, 0.28, 2.6],
18865
19005
  [0.46, 0.38, 0.31, 0.46, 3],
18866
19006
  [0.6, 0.41, 0.34, 0.5, 3],
18867
19007
  [0.74, 0.43, 0.37, 0.46, 2.8],
@@ -19269,7 +19409,7 @@ var GameVehiclesThree = (() => {
19269
19409
  body(
19270
19410
  c,
19271
19411
  [
19272
- [0.42, 1.05, 0.82, 0.26, 2.6],
19412
+ [0.415, 1.05, 0.82, 0.26, 2.6],
19273
19413
  [0.52, 1.03, 0.83, 0.28, 2.6],
19274
19414
  [0.59, 0.99, 0.85, 0.22, 2.4],
19275
19415
  [0.62, 0.95, 0.87, 0.1, 2.2]
@@ -19290,7 +19430,7 @@ var GameVehiclesThree = (() => {
19290
19430
  });
19291
19431
  c.roundBox(0.015, 0.1, 0.2, 0.02, SMOKEG, 0.55, 1.035, 0, { rot: [0, 0, 0.55] });
19292
19432
  c.roundBox(0.07, 0.03, 0.16, 0.01, CM("#121518", { roughness: 0.25, metalness: 0.3 }), 0.44, 1.07, 0, { rot: [0, 0, 0.5] });
19293
- c.roundBox(0.04, 0.032, 0.1, 6e-3, MT.gauge, 0.45, 1.075, 0, { rot: [0, 0, 0.5] });
19433
+ c.roundBox(0.04, 0.032, 0.1, 6e-3, MT.gauge, 0.45, 1.078, 0, { rot: [0, 0, 0.5] });
19294
19434
  [1, -1].forEach(function(s) {
19295
19435
  blinker(c, 0.5, 0.92, s * 0.16, true);
19296
19436
  });
@@ -19707,7 +19847,7 @@ var GameVehiclesThree = (() => {
19707
19847
  });
19708
19848
  c.cylinder(0.12, 0.12, 0.07, CH, 0.2, 0.56, 0.17, "z");
19709
19849
  c.cylinder(0.1, 0.1, 0.012, CM("#9ea3a7", { metalness: 0.55, roughness: 0.35 }), 0.2, 0.56, 0.21, "z");
19710
- c.text("114", 0.1, 0.04, 0.2, 0.56, 0.217, "+z", { fg: "#1b1c1f", size: 0.85 });
19850
+ c.text("114", 0.1, 0.04, 0.2, 0.56, 0.219, "+z", { fg: "#1b1c1f", size: 0.85 });
19711
19851
  c.sphere(0.17, CH, -0.06, 0.32, -0.17, 1.35, 0.85, 0.28);
19712
19852
  c.cylinder(0.07, 0.07, 0.02, CH, -0.02, 0.3, -0.215, "z");
19713
19853
  c.roundBox(0.86, 0.035, 0.02, 0.015, CM("#1a1a1a", { roughness: 0.8 }), -0.43, 0.32, 0.15, { rot: [0, 0, 0] });
@@ -20102,12 +20242,12 @@ var GameVehiclesThree = (() => {
20102
20242
  col
20103
20243
  );
20104
20244
  c.roundBox(0.1, 0.07, 0.18, 0.02, blk, 0.36, 1.04, 0, { rot: [0, 0, 0.4] });
20105
- c.roundBox(0.02, 0.05, 0.15, 0.01, MT.gauge, 0.39, 1.06, 0, { rot: [0, 0, 0.4] });
20245
+ c.roundBox(0.02, 0.05, 0.15, 0.01, MT.gauge, 0.39, 1.064, 0, { rot: [0, 0, 0.4] });
20106
20246
  [1, -1].forEach(function(s) {
20107
20247
  blinker(c, 0.48, 0.9, s * 0.17, true);
20108
20248
  });
20109
20249
  Z.fairing = grab(c, n0);
20110
- lamp(c, { style: "rect", x: 0.57, y: 0.91, z: 0, w: 0.2, h: 0.11, d: 0.08, side: 1, label: trl("labels.headlight") });
20250
+ lamp(c, { style: "rect", x: 0.575, y: 0.91, z: 0, w: 0.2, h: 0.11, d: 0.08, side: 1, label: trl("labels.headlight") });
20111
20251
  n0 = c.vehicle.children.length;
20112
20252
  handlebar(c, 0.36, 1.02, 0.36, { rise: 0.03, back: 0.06, mat: MT.chrome, stalk: 0.19 });
20113
20253
  Z.handlebar = grab(c, n0);
@@ -20231,9 +20371,19 @@ var GameVehiclesThree = (() => {
20231
20371
  return [s[0], cy - hh, cy + hh, s[3] * k, s[4], s[5]];
20232
20372
  });
20233
20373
  }
20374
+ function stretchSt(st) {
20375
+ const out = st.map(function(q) {
20376
+ return q.slice();
20377
+ });
20378
+ const last = out.length - 1;
20379
+ const dir = out[last][0] >= out[0][0] ? 1 : -1;
20380
+ out[0][0] = out[0][0] + dir * 3e-3;
20381
+ out[last][0] = out[last][0] - dir * 3e-3;
20382
+ return out;
20383
+ }
20234
20384
  function fSkin(c, EA, st, keep, mat, o) {
20235
20385
  o = o || {};
20236
- const m = c.add(EA.fuseGeo(scaleSt(st, o.k || 1.004), { smooth: o.smooth || 48, seg: o.seg || 30 }), mat, 0, 0, 0, o.parent);
20386
+ const m = c.add(EA.fuseGeo(stretchSt(scaleSt(st, o.k || EA.nextSkinScale(c))), { smooth: o.smooth || 48, seg: o.seg || 30 }), mat, 0, 0, 0, o.parent);
20237
20387
  m.castShadow = false;
20238
20388
  cutSub(m, [keep], o.sub || 0.06, o.pre);
20239
20389
  c.deform.push(m);
@@ -20241,7 +20391,7 @@ var GameVehiclesThree = (() => {
20241
20391
  }
20242
20392
  function fGlass(c, EA, st, keep, label, type, o) {
20243
20393
  o = o || {};
20244
- const m = new THREE.Mesh(EA.fuseGeo(scaleSt(st, o.k || 0.988), { smooth: o.smooth || 48, seg: o.seg || 30 }), o.mat || MT.glass);
20394
+ const m = new THREE.Mesh(EA.fuseGeo(scaleSt(st, o.k || EA.nextPaneScale(c)), { smooth: o.smooth || 48, seg: o.seg || 30 }), o.mat || MT.glass);
20245
20395
  (o.parent || c.vehicle).add(m);
20246
20396
  cutSub(m, [keep], o.sub || 0.07, o.pre);
20247
20397
  return kit.asGlass(c, m, label, type || "tempered", o.pos ? { pos: o.pos } : {});
@@ -20403,7 +20553,7 @@ var GameVehiclesThree = (() => {
20403
20553
  return Math.min(boltW(x) - Math.abs(y - bolt(x)), x + 3.2, 2.93 - x, Math.abs(z) - 0.12);
20404
20554
  }),
20405
20555
  black,
20406
- { parent: grp, sub: 0.05, pre: EA.keepT([-3.3, 3, -0.35, 0.2, 0.1]) }
20556
+ { parent: grp, sub: 0.05, k: 1.013, pre: EA.keepT([-3.3, 3, -0.35, 0.2, 0.1]) }
20407
20557
  );
20408
20558
  const doorR = EA.polySdf([
20409
20559
  [1.38, -0.4],
@@ -20468,7 +20618,7 @@ var GameVehiclesThree = (() => {
20468
20618
  };
20469
20619
  const g = EA.foilGeo(
20470
20620
  [
20471
- { p: [1.46, dh(0), 0], c: 1.6, t: 0.12, cam: 0.025, noCap: true },
20621
+ { p: [1.46, dh(0), s * 2e-3], c: 1.6, t: 0.12, cam: 0.025, noCap: true },
20472
20622
  { p: [1.46, dh(2.6), s * 2.6], c: 1.6, t: 0.12, cam: 0.025 },
20473
20623
  { p: [1.46, dh(4.9), s * 4.9], c: 1.6, t: 0.12, cam: 0.025 },
20474
20624
  { p: [1.43, dh(5.18), s * 5.18], c: 1.5, t: 0.11, cam: 0.02 },
@@ -20525,7 +20675,7 @@ var GameVehiclesThree = (() => {
20525
20675
  const hs = c.add(
20526
20676
  EA.foilGeo(
20527
20677
  [
20528
- { p: [-2.78, 0.1, 0], c: 0.78, t: 0.07 },
20678
+ { p: [-2.78, 0.1, s * 2e-3], c: 0.78, t: 0.07 },
20529
20679
  { p: [-2.85, 0.1, s * 1.1], c: 0.74, t: 0.07 },
20530
20680
  { p: [-2.95, 0.1, s * 1.36], c: 0.6, t: 0.06 },
20531
20681
  { p: [-3.1, 0.1, s * 1.46], c: 0.32, t: 0.05 }
@@ -20776,7 +20926,7 @@ var GameVehiclesThree = (() => {
20776
20926
  EA.sideKeepP(ckP, 0.5, s),
20777
20927
  s > 0 ? lbl("right_flight_deck_window") : lbl("left_flight_deck_window"),
20778
20928
  "tempered",
20779
- { pos: new V3(5.4, 2.25, s * 0.8) }
20929
+ { pos: new V3(5.4, 2.25, s * 0.8), k: 1.0085 }
20780
20930
  );
20781
20931
  fGlass(
20782
20932
  c,
@@ -20830,7 +20980,7 @@ var GameVehiclesThree = (() => {
20830
20980
  const w = c.add(
20831
20981
  EA.foilGeo(
20832
20982
  [
20833
- { p: [1.52, dh(0), 0], c: 2.38, t: 0.15, cam: 0.02 },
20983
+ { p: [1.52, dh(0), s * 2e-3], c: 2.38, t: 0.15, cam: 0.02 },
20834
20984
  { p: [1.52, dh(0.86), s * 0.86], c: 2.38, t: 0.15, cam: 0.02 },
20835
20985
  { p: [1.42, dh(2.47), s * 2.47], c: 2.25, t: 0.145, cam: 0.02 },
20836
20986
  { p: [0.98, dh(7.42), s * 7.42], c: 1.4, t: 0.12, cam: 0.02 },
@@ -20965,7 +21115,7 @@ var GameVehiclesThree = (() => {
20965
21115
  const hs = c.add(
20966
21116
  EA.foilGeo(
20967
21117
  [
20968
- { p: [-5.95, 2.3, 0], c: 1.55, t: 0.1 },
21118
+ { p: [-5.95, 2.3, s * 2e-3], c: 1.55, t: 0.1 },
20969
21119
  { p: [-6.62, 2.3 + 3.2 * 0.176, s * 3.2], c: 0.86, t: 0.09 }
20970
21120
  ],
20971
21121
  { up: "y", n: 10 }
@@ -21228,7 +21378,7 @@ var GameVehiclesThree = (() => {
21228
21378
  const w = c.add(
21229
21379
  EA.foilGeo(
21230
21380
  [
21231
- { p: [1.56, dh(0), 0], c: 1.98, t: 0.15, cam: 0.025, noCap: true },
21381
+ { p: [1.56, dh(0), s * 2e-3], c: 1.98, t: 0.15, cam: 0.025, noCap: true },
21232
21382
  { p: [1.56, dh(3.6), s * 3.6], c: 1.98, t: 0.15, cam: 0.025 },
21233
21383
  { p: [1.38, dh(7.7), s * 7.7], c: 1.3, t: 0.12, cam: 0.02 },
21234
21384
  { p: [1.32, dh(7.94), s * 7.94], c: 1.1, t: 0.06, cam: 0.01 }
@@ -21370,7 +21520,7 @@ var GameVehiclesThree = (() => {
21370
21520
  const hs = c.add(
21371
21521
  EA.foilGeo(
21372
21522
  [
21373
- { p: [-4.8, 3.08, 0], c: 1.55, t: 0.1 },
21523
+ { p: [-4.8, 3.08, s * 2e-3], c: 1.55, t: 0.1 },
21374
21524
  { p: [-5.15, 3.08, s * 3.1], c: 1, t: 0.09 }
21375
21525
  ],
21376
21526
  { up: "y", n: 10 }
@@ -21573,7 +21723,7 @@ var GameVehiclesThree = (() => {
21573
21723
  EA.sideKeepP(ckP, 0.5, s),
21574
21724
  s > 0 ? lbl("right_flight_deck_side_window") : lbl("left_flight_deck_side_window"),
21575
21725
  "tempered",
21576
- { pos: new V3(3.6, 2, s * 0.78) }
21726
+ { pos: new V3(3.6, 2, s * 0.78), k: 1.0085 }
21577
21727
  );
21578
21728
  fGlass(
21579
21729
  c,
@@ -21601,7 +21751,7 @@ var GameVehiclesThree = (() => {
21601
21751
  return Math.min(8e-3 - Math.abs(EA.polySdf(rrect(2.62, 3.25, 0.72, 2.22, 0.12))(x, y)), -z - 0.5);
21602
21752
  }),
21603
21753
  MT.dark,
21604
- { k: 1.003 }
21754
+ { k: 1.0065 }
21605
21755
  );
21606
21756
  void dF;
21607
21757
  EA.fuseSkin(
@@ -21611,7 +21761,7 @@ var GameVehiclesThree = (() => {
21611
21761
  return Math.min(0.035 - Math.abs(x - 3.88 - (y - 1.75) * 0.5), y - 1.7, 2.42 - y);
21612
21762
  }),
21613
21763
  blk,
21614
- { k: 1.004 }
21764
+ { k: 1.0065 }
21615
21765
  );
21616
21766
  c.rod(new V3(5, 1.74, 0), new V3(4.05, 2.4, 0), 0.02, blk);
21617
21767
  const fl = 0.8, fab = CM("#c9bda6", { roughness: 0.75 });
@@ -21650,7 +21800,7 @@ var GameVehiclesThree = (() => {
21650
21800
  const w = c.add(
21651
21801
  EA.foilGeo(
21652
21802
  [
21653
- { p: [1, dh(0), 0], c: 2.45, t: 0.14, cam: 0.02 },
21803
+ { p: [1, dh(0), s * 2e-3], c: 2.45, t: 0.14, cam: 0.02 },
21654
21804
  { p: [0.95, dh(0.85), s * 0.85], c: 2.42, t: 0.14, cam: 0.02 },
21655
21805
  { p: [0.55, dh(2.4), s * 2.4], c: 1.9, t: 0.13, cam: 0.02 },
21656
21806
  { p: [-0.32, dh(5.75), s * 5.75], c: 1.08, t: 0.11, cam: 0.02 },
@@ -21732,7 +21882,7 @@ var GameVehiclesThree = (() => {
21732
21882
  const finB = c.add(
21733
21883
  EA.foilGeo(
21734
21884
  [
21735
- { p: [-3.89, 2.25, 0], c: 2.22, t: 0.115 },
21885
+ { p: [-3.89, 2.253, 0], c: 2.22, t: 0.115 },
21736
21886
  { p: [-5.34, 4.185, 0], c: 1.17, t: 0.105 }
21737
21887
  ],
21738
21888
  { up: "z", n: 10 }
@@ -21755,7 +21905,7 @@ var GameVehiclesThree = (() => {
21755
21905
  const hs = c.add(
21756
21906
  EA.foilGeo(
21757
21907
  [
21758
- { p: [-5.3, 4.2, 0], c: 1.18, t: 0.1 },
21908
+ { p: [-5.3, 4.2, s * 2e-3], c: 1.18, t: 0.1 },
21759
21909
  { p: [-5.9, 4.24, s * 2.55], c: 0.62, t: 0.09 }
21760
21910
  ],
21761
21911
  { up: "y", n: 10 }
@@ -22017,7 +22167,7 @@ var GameVehiclesThree = (() => {
22017
22167
  [1, -1].forEach(function(s) {
22018
22168
  const g = EA.foilGeo(
22019
22169
  [
22020
- { p: [1.52, dh(0), 0], c: 2.35, t: 0.15, cam: 0.02 },
22170
+ { p: [1.52, dh(0), s * 2e-3], c: 2.35, t: 0.15, cam: 0.02 },
22021
22171
  { p: [1.5, dh(0.48), s * 0.48], c: 2.32, t: 0.15, cam: 0.02 },
22022
22172
  { p: [0.78, dh(5.4), s * 5.4], c: 1.2, t: 0.12, cam: 0.02 },
22023
22173
  { p: [0.74, dh(5.57), s * 5.57], c: 1.1, t: 0.07, cam: 0.01 }
@@ -22122,7 +22272,7 @@ var GameVehiclesThree = (() => {
22122
22272
  [1, -1].forEach(function(s) {
22123
22273
  const g = EA.foilGeo(
22124
22274
  [
22125
- { p: [-4.3, 1.72, 0], c: 1.3, t: 0.1 },
22275
+ { p: [-4.3, 1.72, s * 2e-3], c: 1.3, t: 0.1 },
22126
22276
  { p: [-4.72, 1.76, s * 2.2], c: 0.75, t: 0.09 }
22127
22277
  ],
22128
22278
  { up: "y", n: 10 }
@@ -22383,7 +22533,7 @@ var GameVehiclesThree = (() => {
22383
22533
  const fl = c.roundBox(L, 0.035, 2 * hw, 0.01, LINER, cx, o.floor, 0);
22384
22534
  for (let k = 0; k < 7; k++) c.roundBox(L - 0.04, 0.018, 0.04, 8e-3, LINER, cx, o.floor + 0.025, -hw * 0.8 + k * hw * 1.6 / 6);
22385
22535
  [1, -1].forEach(function(s) {
22386
- c.roundBox(L, h, 0.025, 0.01, LINER, cx, o.floor + h / 2, s * (hw + 0.012));
22536
+ c.roundBox(L - 8e-3, h, 0.025, 0.01, LINER, cx, o.floor + h / 2, s * (hw + 0.012));
22387
22537
  });
22388
22538
  c.roundBox(0.025, h, 2 * hw, 0.01, LINER, o.x0 + 0.012, o.floor + h / 2, 0);
22389
22539
  c.roundBox(0.03, h + 0.05, 2 * hw + 0.02, 0.01, c.paint(c.meta.color), o.x1 - 0.015, o.floor + (h + 0.05) / 2, 0);
@@ -23279,10 +23429,10 @@ var GameVehiclesThree = (() => {
23279
23429
  pre: function(c2, _m) {
23280
23430
  const gx = fX(s, 0.82) - 0.012, gy = 0.82, gh = 0.46, gw = 1.08, tz = 0.8;
23281
23431
  c2.roundBox(0.05, gh, gw, 0.04, MT.chrome, gx, gy, 0, { taper: { sz: tz } });
23282
- c2.roundBox(0.056, gh - 0.1, gw - 0.16, 0.02, GLOSS, gx + 2e-3, gy, 0, { taper: { sz: tz - 0.02 } });
23432
+ c2.roundBox(0.058, gh - 0.1, gw - 0.16, 0.02, GLOSS, gx + 2e-3, gy, 0, { taper: { sz: tz - 0.02 } });
23283
23433
  [0.13, 0.045, -0.04, -0.125].forEach(function(dy) {
23284
23434
  const k = (dy + gh / 2 - 0.05) / (gh - 0.1);
23285
- c2.roundBox(0.06, 0.022, (gw - 0.2) * (1 + (tz - 1) * k), 8e-3, MT.chrome, gx + 4e-3, gy + dy, 0);
23435
+ c2.roundBox(0.066, 0.022, (gw - 0.2) * (1 + (tz - 1) * k), 8e-3, MT.chrome, gx + 4e-3, gy + dy, 0);
23286
23436
  });
23287
23437
  c2.roundBox(0.04, 0.04, 1.32, 0.015, MT.chrome, fX(s, 1.04) - 0.03, 1.04, 0);
23288
23438
  kit.emblem(c2, fX(s, 0.9) + 0.03, 0.9, 0, 0.06);
@@ -23618,9 +23768,9 @@ var GameVehiclesThree = (() => {
23618
23768
  pre: function(c2, _m) {
23619
23769
  const gx = fX(s, 0.8) - 0.012, gy = 0.8, gw = 1.14, gh = 0.52;
23620
23770
  c2.roundBox(0.05, gh, gw, 0.04, MT.chrome, gx, gy, 0, { taper: { sz: 0.84 } });
23621
- c2.roundBox(0.056, gh - 0.12, gw - 0.16, 0.02, GLOSS, gx + 2e-3, gy - 0.01, 0, { taper: { sz: 0.82 } });
23771
+ c2.roundBox(0.058, gh - 0.12, gw - 0.16, 0.02, GLOSS, gx + 2e-3, gy - 0.01, 0, { taper: { sz: 0.82 } });
23622
23772
  [0.12, -0.02, -0.14].forEach(function(dy) {
23623
- c2.roundBox(0.06, 0.03, (gw - 0.22) * (1 - (dy + 0.2) * 0.4), 0.01, MT.housing, gx + 4e-3, gy + dy, 0);
23773
+ c2.roundBox(0.066, 0.03, (gw - 0.22) * (1 - (dy + 0.2) * 0.4), 0.01, MT.housing, gx + 4e-3, gy + dy, 0);
23624
23774
  });
23625
23775
  c2.roundBox(0.04, 0.05, 1.3, 0.02, MT.chrome, fX(s, 1.04) - 0.03, 1.04, 0);
23626
23776
  kit.emblem(c2, gx + 0.035, gy + 0.06, 0, 0.06);
@@ -23786,7 +23936,7 @@ var GameVehiclesThree = (() => {
23786
23936
  wg.add(bolt);
23787
23937
  }
23788
23938
  for (let sk = 0; sk < 6; sk++) {
23789
- const sa = sk / 6 * PI * 2, hole = new THREE.Mesh(new THREE.CylinderGeometry(rr * 0.13, rr * 0.13, 0.034, 14), MT.hole);
23939
+ const sa = sk / 6 * PI * 2, hole = new THREE.Mesh(new THREE.CylinderGeometry(rr * 0.13, rr * 0.13, 0.03, 14), MT.hole);
23790
23940
  hole.rotation.x = PI / 2;
23791
23941
  hole.position.set(Math.cos(sa) * rr * 0.58, Math.sin(sa) * rr * 0.58, fz + zs * 2e-3);
23792
23942
  wg.add(hole);
@@ -23815,7 +23965,7 @@ var GameVehiclesThree = (() => {
23815
23965
  c.rod(new V3(0.6, 2.8, sd * 0.78), new V3(-0.25, 2.8, sd * 0.78), 0.035, red);
23816
23966
  });
23817
23967
  c.rod(new V3(0.6, 2.8, -0.78), new V3(0.6, 2.8, 0.78), 0.035, red);
23818
- c.rod(new V3(-0.25, 2.8, -0.78), new V3(-0.25, 2.8, 0.78), 0.035, red);
23968
+ c.rod(new V3(-0.25, 2.8, -0.78), new V3(-0.25, 2.8, 0.78), 0.032, red);
23819
23969
  c.rod(new V3(-0.25, 2.3, -0.8), new V3(-0.25, 2.8, 0.78), 0.03, red);
23820
23970
  const roofItems = [c.roundBox(0.16, 0.05, 1.3, 0.02, MT.trim, 0.42, m.top + 0.08, 0)];
23821
23971
  [-0.48, -0.16, 0.16, 0.48].forEach(function(z) {
@@ -24396,8 +24546,8 @@ var GameVehiclesThree = (() => {
24396
24546
  );
24397
24547
  const zz = sd * (kit.halfAt(W, m.tumble, 1.75) + 0.012), zt = sd * (kit.halfAt(W, m.tumble, 2.22) + 0.012);
24398
24548
  c2.text("RESGATE", 1.2, 0.3, sd > 0 ? -1.5 : -0.85, 2.22, zt, sd > 0 ? "+z" : "-z", { fg: red });
24399
- [0, PI / 3, -PI / 3].forEach(function(a) {
24400
- c2.roundBox(0.09, 0.36, 0.01, 0.01, blu, -2.25, 1.75, zz, { rot: [0, 0, a] });
24549
+ [0, PI / 3, -PI / 3].forEach(function(a, i) {
24550
+ c2.roundBox(0.09, 0.36, 0.01, 0.01, blu, -2.25, 1.75, zz + sd * i * 25e-4, { rot: [0, 0, a] });
24401
24551
  });
24402
24552
  });
24403
24553
  if (c2.hood) {
@@ -24747,9 +24897,31 @@ var GameVehiclesThree = (() => {
24747
24897
  if (o.col) colorize(g, o.col);
24748
24898
  return g;
24749
24899
  }
24900
+ function stretchEnds(st, by) {
24901
+ const out = st.map(function(q) {
24902
+ return q.slice();
24903
+ });
24904
+ const last = out.length - 1;
24905
+ const dir = out[last][0] >= out[0][0] ? 1 : -1;
24906
+ out[0][0] = out[0][0] - dir * by;
24907
+ out[last][0] = out[last][0] + dir * by;
24908
+ return out;
24909
+ }
24910
+ const paneCount = /* @__PURE__ */ new WeakMap();
24911
+ function nextPaneScale(c) {
24912
+ const n = paneCount.get(c) ?? 0;
24913
+ paneCount.set(c, n + 1);
24914
+ return 0.988 - 35e-4 * (n % 4);
24915
+ }
24916
+ const skinCount = /* @__PURE__ */ new WeakMap();
24917
+ function nextSkinScale(c) {
24918
+ const n = skinCount.get(c) ?? 0;
24919
+ skinCount.set(c, n + 1);
24920
+ return 1.004 + 25e-4 * (n % 3);
24921
+ }
24750
24922
  function fuseGlass(c, st, keep, label, type, o) {
24751
24923
  o = o || {};
24752
- const k = o.k || 0.988;
24924
+ const k = o.k || nextPaneScale(c);
24753
24925
  const st2 = st.map(function(s) {
24754
24926
  const cy = (s[1] + s[2]) / 2, hh = (s[2] - s[1]) / 2 * k;
24755
24927
  return [s[0], cy - hh, cy + hh, s[3] * k, s[4], s[5]];
@@ -24762,12 +24934,12 @@ var GameVehiclesThree = (() => {
24762
24934
  }
24763
24935
  function fuseSkin(c, st, keep, mat, o) {
24764
24936
  o = o || {};
24765
- const k = o.k || 1.004;
24937
+ const k = o.k || nextSkinScale(c);
24766
24938
  const st2 = st.map(function(s) {
24767
24939
  const cy = (s[1] + s[2]) / 2, hh = (s[2] - s[1]) / 2 * k;
24768
24940
  return [s[0], cy - hh, cy + hh, s[3] * k, s[4], s[5]];
24769
24941
  });
24770
- const m = c.add(fuseGeo(st2, { smooth: o.smooth || 48, seg: o.seg || 30 }), mat, 0, 0, 0, o.parent);
24942
+ const m = c.add(fuseGeo(stretchEnds(st2, -3e-3), { smooth: o.smooth || 48, seg: o.seg || 30 }), mat, 0, 0, 0, o.parent);
24771
24943
  m.castShadow = false;
24772
24944
  kit.cutMesh(m, [keep], 40);
24773
24945
  c.deform.push(m);
@@ -25038,7 +25210,7 @@ var GameVehiclesThree = (() => {
25038
25210
  }
25039
25211
  ;
25040
25212
  (o.screens || []).forEach(function(s) {
25041
- const sc = c.roundBox(0.012, s[2], s[3], 8e-3, MT.screen, x - 0.085, y + s[0], s[1]);
25213
+ const sc = c.roundBox(0.012, s[2], s[3], 8e-3, MT.screen, x - 0.091, y + s[0], s[1]);
25042
25214
  sc.castShadow = false;
25043
25215
  });
25044
25216
  }
@@ -25078,7 +25250,7 @@ var GameVehiclesThree = (() => {
25078
25250
  );
25079
25251
  c.roundBox(0.42 * k, 0.07 * k, 0.33 * k, 0.03 * k, CM(o.band || "#2a2c30", { roughness: 0.5 }), -0.2 * k - 0.05, -0.02 * k, 0, P);
25080
25252
  c.roundBox(0.17 * k, shaft, 0.11 * k, 0.04 * k, low, -0.16 * k, -shaft / 2 - 0.02, 0, P);
25081
- c.roundBox(0.36 * k, 0.018, 0.2 * k, 8e-3, low, -0.17 * k, -shaft - 0.01, 0, P);
25253
+ c.roundBox(0.36 * k, 0.018, 0.2 * k, 8e-3, low, -0.17 * k, -shaft - 6e-3, 0, P);
25082
25254
  c.cylinder(0.055 * k, 0.05 * k, 0.32 * k, low, -0.2 * k, -shaft - 0.09 * k, 0, "x", P);
25083
25255
  c.roundBox(0.16 * k, 0.12 * k, 0.025, 0.01, low, -0.18 * k, -shaft - 0.17 * k, 0, P);
25084
25256
  const pr = propeller(c, -0.38 * k, -shaft - 0.09 * k, 0, {
@@ -25110,7 +25282,11 @@ var GameVehiclesThree = (() => {
25110
25282
  function skinOf2(c, mesh2, keep, mat, o) {
25111
25283
  o = o || {};
25112
25284
  const g = mesh2.geometry.clone(), p = g.attributes.position, sz = o.sz || 1.006, dy = o.dy || 0;
25285
+ let reach = 0;
25286
+ for (let i = 0; i < p.count; i++) reach = Math.max(reach, Math.abs(p.getX(i)));
25287
+ const sx = o.ends === false ? 1 : 1 - 3e-3 / (reach || 1);
25113
25288
  for (let i = 0; i < p.count; i++) {
25289
+ p.setX(i, p.getX(i) * sx);
25114
25290
  p.setZ(i, p.getZ(i) * sz);
25115
25291
  p.setY(i, p.getY(i) + dy * Math.sign(p.getY(i)));
25116
25292
  }
@@ -25224,6 +25400,8 @@ var GameVehiclesThree = (() => {
25224
25400
  foilGeo,
25225
25401
  fuseGeo,
25226
25402
  fuseGlass,
25403
+ nextPaneScale,
25404
+ nextSkinScale,
25227
25405
  fuseSkin,
25228
25406
  bandT,
25229
25407
  cutT,
@@ -25372,7 +25550,7 @@ var GameVehiclesThree = (() => {
25372
25550
  const tank = c.roundBox(0.48, 0.24, 0.3, 0.06, CM("#a3241c", { roughness: 0.5 }), -2.05, 0.06, -0.38);
25373
25551
  c.rod(new V3(-2, 0.18, -0.38), new V3(-2.3, 0.4, -0.1), 0.01, CM("#1b1b1b"));
25374
25552
  c.roundBox(1.8, 0.03, 0.1, 0.01, MT.wood, -0.6, 0, 0.5, { rot: [0.3, 0, 0] });
25375
- c.roundBox(0.35, 0.03, 0.14, 0.02, MT.wood, 0.45, 0, 0.5, { rot: [0.3, 0, 0] });
25553
+ c.roundBox(0.35, 0.03, 0.14, 0.02, MT.wood, 0.45, 4e-3, 0.5, { rot: [0.3, 0, 0] });
25376
25554
  c.rod(new V3(-2.35, 0.42, 0.6), new V3(-2.35, 1.1, 0.6), 0.012, MT.chrome);
25377
25555
  EA.navLight(c, -2.35, 1.13, 0.6, "white", trl("labels.stern_light_mast"), { r: 0.035 });
25378
25556
  EA.navLight(c, 2.3, 0.53, 0.06, "green", trl("labels.starboard_bow_light_green"), { r: 0.03 });
@@ -25549,7 +25727,7 @@ var GameVehiclesThree = (() => {
25549
25727
  c.roundBox(2.3, 0.22, 0.5, 0.07, vinyl, -2.3, 0.45, s * 0.75);
25550
25728
  c.roundBox(2.3, 0.4, 0.12, 0.05, vinyl, -2.3, 0.72, s * (H.half(-2.3, 0.7) - 0.08));
25551
25729
  });
25552
- c.roundBox(0.5, 0.22, 1.5, 0.07, vinyl, -3.35, 0.45, 0);
25730
+ c.roundBox(0.5, 0.22, 1.5, 0.07, vinyl, -3.35, 0.453, 0);
25553
25731
  c.roundBox(0.12, 0.42, 2.1, 0.05, vinyl, -3.52, 0.74, 0);
25554
25732
  c.seatTops.push(
25555
25733
  { x: -2.3, y: 0.57, z: 0.75, w: 0.5, l: 2.2 },
@@ -25557,8 +25735,8 @@ var GameVehiclesThree = (() => {
25557
25735
  { x: 2, y: 0.57, z: 0, w: 1.2, l: 0.9 }
25558
25736
  );
25559
25737
  const cy = 0.22;
25560
- c.roundBox(0.85, 0.72, 0.78, 0.12, white, 0.75, cy + 0.36, 0.72);
25561
- c.roundBox(0.85, 0.72, 0.72, 0.12, white, 0.75, cy + 0.36, -0.74);
25738
+ c.roundBox(0.85, 0.72, 0.78, 0.12, white, 0.75, cy + 0.362, 0.72);
25739
+ c.roundBox(0.85, 0.72, 0.72, 0.12, white, 0.75, cy + 0.362, -0.74);
25562
25740
  c.roundBox(0.42, 0.04, 0.7, 0.015, CM("#18191b", { roughness: 0.7 }), 0.95, cy + 0.74, 0.72, { rot: [0, 0, -0.35] });
25563
25741
  [0.55, 0.72, 0.89].forEach(function(z, i) {
25564
25742
  c.cylinder(0.045, 0.045, 0.012, MT.gauge, 0.93 + (i === 1 ? 0.05 : 0), cy + 0.79, z, null, { seg: 16 }).rotation.set(0, 0, 1.22);
@@ -25569,8 +25747,8 @@ var GameVehiclesThree = (() => {
25569
25747
  c.rod(new V3(0.62, cy + 0.72, 0.62), new V3(0.55, cy + 0.82, 0.62), 0.02, MT.chrome);
25570
25748
  c.rod(new V3(0.55, cy + 0.7, 0.98), new V3(0.42, cy + 0.88, 1), 0.015, MT.chrome);
25571
25749
  c.sphere(0.035, MT.plastic, 0.42, cy + 0.9, 1);
25572
- kit.seat(c, -0.1, cy, 0.72, { w: 0.55, h: 0.42, back: 0.48, lean: 0.12, mat: vinyl, headrest: false });
25573
- kit.seat(c, -0.1, cy, -0.74, { w: 0.55, h: 0.42, back: 0.48, lean: 0.12, mat: vinyl, headrest: false });
25750
+ kit.seat(c, -0.1, cy + 2e-3, 0.72, { w: 0.55, h: 0.42, back: 0.48, lean: 0.12, mat: vinyl, headrest: false });
25751
+ kit.seat(c, -0.1, cy + 2e-3, -0.74, { w: 0.55, h: 0.42, back: 0.48, lean: 0.12, mat: vinyl, headrest: false });
25574
25752
  [1, -1].forEach(function(s) {
25575
25753
  const pts = [];
25576
25754
  for (let i = 0; i <= 8; i++) {
@@ -25792,7 +25970,7 @@ var GameVehiclesThree = (() => {
25792
25970
  [1.6, -0.55],
25793
25971
  [1.95, -1]
25794
25972
  ].forEach(function(q) {
25795
- c.roundBox(0.42, 0.24, 0.32, 0.03, CM("#3f6fa0", { roughness: 0.6 }), q[0], dk(q[0]) + 0.12, q[1]);
25973
+ c.roundBox(0.42, 0.24, 0.32, 0.03, CM("#3f6fa0", { roughness: 0.6 }), q[0], dk(q[0]) + 0.128 + (q[0] > 1.9 ? 4e-3 : 0), q[1]);
25796
25974
  });
25797
25975
  const hx = -2.7, hy0 = dk(hx), hh = 1.9, hw2 = 1.1, cas = c.roundBox(2, hh, hw2 * 2, 0.08, wht, hx, hy0 + hh / 2, 0, { def: true });
25798
25976
  const cutF = {
@@ -25881,11 +26059,11 @@ var GameVehiclesThree = (() => {
25881
26059
  c.rod(new V3(0, 0, 0), new V3(0, Math.cos(a8) * 0.36, Math.sin(a8) * 0.36), 0.014, MT.wood, { parent: whl });
25882
26060
  }
25883
26061
  c.cylinder(0.05, 0.05, 0.14, MT.wood, 0.06, 0, 0, "x", { parent: whl });
25884
- kit.seat(c, hx - 0.05, hy0, 0, { w: 0.5, h: 0.55, back: 0.45, mat: inner, headrest: false });
26062
+ kit.seat(c, hx - 0.05, hy0 + 2e-3, 0, { w: 0.5, h: 0.55, back: 0.45, mat: inner, headrest: false });
25885
26063
  c.roundBox(1.8, 0.12, 0.65, 0.04, CM("#7c5a3b"), hx - 0.2, hy0 + 0.5, -0.72);
25886
26064
  c.roundBox(1.7, 0.08, 0.55, 0.04, CM("#6b7c8f", { roughness: 1 }), hx - 0.2, hy0 + 0.6, -0.72);
25887
26065
  c.roundBox(1.9, 0.02, 2.1, 0.01, inner, hx, hy0 + hh - 0.06, 0).castShadow = false;
25888
- c.cylinder(0.1, 0.1, 1.2, MT.trim, hx - 0.75, hy0 + hh + 0.6, 0.65);
26066
+ c.cylinder(0.1, 0.1, 1.2, MT.trim, hx - 0.75, hy0 + hh + 0.596, 0.65);
25889
26067
  c.cylinder(0.13, 0.1, 0.1, MT.trim, hx - 0.75, hy0 + hh + 1.22, 0.65);
25890
26068
  c.rod(new V3(hx + 0.4, hy0 + hh + 0.1, 0), new V3(hx + 0.4, hy0 + hh + 1.6, 0), 0.04, wood);
25891
26069
  EA.navLight(c, hx + 0.4, hy0 + hh + 1.65, 0, "white", trl("labels.masthead_light"), { r: 0.05 });
@@ -25986,7 +26164,7 @@ var GameVehiclesThree = (() => {
25986
26164
  const EA = shared2.EA, white = "#ecebe6";
25987
26165
  const paintW = c.paint(white);
25988
26166
  const ST = [
25989
- [2.3, 0.98, 1.46, 0.7, 2.4],
26167
+ [2.297, 0.98, 1.46, 0.7, 2.4],
25990
26168
  [2.15, 0.88, 1.55, 0.92, 2.6],
25991
26169
  [1.85, 0.8, 1.61, 1.02, 2.8],
25992
26170
  [1.45, 0.72, 1.65, 1.08, 3],
@@ -26115,7 +26293,7 @@ var GameVehiclesThree = (() => {
26115
26293
  };
26116
26294
  const g = EA.foilGeo(
26117
26295
  [
26118
- { p: [0.66, dh(0), 0], c: 1.63, t: 0.12, cam: 0.02 },
26296
+ { p: [0.66, dh(0), s * 2e-3], c: 1.63, t: 0.12, cam: 0.02 },
26119
26297
  { p: [0.66, dh(2.6), s * 2.6], c: 1.63, t: 0.12, cam: 0.02 },
26120
26298
  { p: [0.62, dh(5.2), s * 5.2], c: 1.14, t: 0.11, cam: 0.02 },
26121
26299
  { p: [0.58, dh(5.5) + 0.02, s * 5.5], c: 0.98, t: 0.06, cam: 0.01 }
@@ -26154,7 +26332,7 @@ var GameVehiclesThree = (() => {
26154
26332
  const hs = c.add(
26155
26333
  EA.foilGeo(
26156
26334
  [
26157
- { p: [-4.6, 1.42, 0], c: 1.2, t: 0.09 },
26335
+ { p: [-4.6, 1.42, s * 2e-3], c: 1.2, t: 0.09 },
26158
26336
  { p: [-4.95, 1.42, s * 1.72], c: 0.86, t: 0.08 }
26159
26337
  ],
26160
26338
  { up: "y", n: 10 }
@@ -26405,7 +26583,7 @@ var GameVehiclesThree = (() => {
26405
26583
  const w = c.add(
26406
26584
  EA.foilGeo(
26407
26585
  [
26408
- { p: [1.18, dh(0), 0], c: 1.71, t: 0.15, cam: 0.02 },
26586
+ { p: [1.18, dh(0), s * 2e-3], c: 1.71, t: 0.15, cam: 0.02 },
26409
26587
  { p: [1.18, dh(5.6), s * 5.6], c: 1.71, t: 0.14, cam: 0.02 },
26410
26588
  { p: [1.12, dh(5.84) + 0.02, s * 5.84], c: 1.55, t: 0.07, cam: 0.01 }
26411
26589
  ],
@@ -26439,7 +26617,7 @@ var GameVehiclesThree = (() => {
26439
26617
  const hs = c.add(
26440
26618
  EA.foilGeo(
26441
26619
  [
26442
- { p: [-2.95, 0.36, 0], c: 0.95, t: 0.09 },
26620
+ { p: [-2.95, 0.36, s * 2e-3], c: 0.95, t: 0.09 },
26443
26621
  { p: [-3.05, 0.36, s * 1.8], c: 0.8, t: 0.08 }
26444
26622
  ],
26445
26623
  { up: "y", n: 10 }
@@ -26471,8 +26649,8 @@ var GameVehiclesThree = (() => {
26471
26649
  const finB = c.add(
26472
26650
  EA.foilGeo(
26473
26651
  [
26474
- { p: [-2.64, 0.42, 0], c: 1.27, t: 0.11 },
26475
- { p: [-3.24, 1.85, 0], c: 0.74, t: 0.1 }
26652
+ { p: [-2.64, 0.424, 0], c: 1.27, t: 0.11 },
26653
+ { p: [-3.24, 1.853, 0], c: 0.74, t: 0.1 }
26476
26654
  ],
26477
26655
  { up: "z", n: 10 }
26478
26656
  ),
@@ -26742,10 +26920,11 @@ var GameVehiclesThree = (() => {
26742
26920
  EA.sideKeepP(fdP, 0.35, s),
26743
26921
  s > 0 ? lbl("front_right_door_window") : lbl("front_left_door_window"),
26744
26922
  "tempered",
26745
- { pos: new V3(0.4, 1.5, s * 0.64) }
26923
+ { pos: new V3(0.4, 1.5, s * 0.64), k: 0.988 }
26746
26924
  );
26747
26925
  EA.fuseGlass(c, ST, EA.sideKeepP(rdP, 0.35, s), s > 0 ? lbl("rear_right_door_window") : lbl("rear_left_door_window"), "tempered", {
26748
- pos: new V3(-0.5, 1.5, s * 0.63)
26926
+ pos: new V3(-0.5, 1.5, s * 0.63),
26927
+ k: 0.988
26749
26928
  });
26750
26929
  const df = EA.polySdf([
26751
26930
  [0.78, 0.72],
@@ -26841,7 +27020,7 @@ var GameVehiclesThree = (() => {
26841
27020
  const hs = c.add(
26842
27021
  EA.foilGeo(
26843
27022
  [
26844
- { p: [-5.25, 1.76, 0], c: 0.45, t: 0.1 },
27023
+ { p: [-5.25, 1.76, s * 2e-3], c: 0.45, t: 0.1 },
26845
27024
  { p: [-5.32, 1.76, s * 0.62], c: 0.34, t: 0.09 }
26846
27025
  ],
26847
27026
  { up: "y", n: 8 }
@@ -27169,7 +27348,7 @@ var GameVehiclesThree = (() => {
27169
27348
  const hs = c.add(
27170
27349
  EA.foilGeo(
27171
27350
  [
27172
- { p: [-5.3, 1.98, 0], c: 0.6, t: 0.11 },
27351
+ { p: [-5.3, 1.98, s * 2e-3], c: 0.6, t: 0.11 },
27173
27352
  { p: [-5.38, 1.98, s * 1], c: 0.52, t: 0.1 }
27174
27353
  ],
27175
27354
  { up: "y", n: 8 }
@@ -27367,7 +27546,10 @@ var GameVehiclesThree = (() => {
27367
27546
  hasSunroof: (key) => !!options.sunroofs?.includes(key),
27368
27547
  register(spec, build) {
27369
27548
  if (!groups.has(spec.group) || only && !only.has(spec.key) || skip.has(spec.key)) return;
27370
- kit.register({ ...spec, seedKey: legacyVehicleSeeds[spec.key] }, build);
27549
+ kit.register({ ...spec, seedKey: legacyVehicleSeeds[spec.key] }, (context, vehicleKit) => {
27550
+ build(context, vehicleKit);
27551
+ separateSpokes(context);
27552
+ });
27371
27553
  }
27372
27554
  };
27373
27555
  }
@@ -28195,7 +28377,7 @@ var GameVehiclesThree = (() => {
28195
28377
  }
28196
28378
  }
28197
28379
 
28198
- // ../game-shapes/dist/chunk-FZQTELDQ.js
28380
+ // ../game-shapes/dist/chunk-E3X7UDDV.js
28199
28381
  function canonicalJson(value) {
28200
28382
  if (value === null) return "null";
28201
28383
  if (typeof value === "number") return Object.is(value, -0) ? "-0" : Number.isFinite(value) ? String(value) : JSON.stringify(String(value));
@@ -29585,6 +29767,253 @@ var GameVehiclesThree = (() => {
29585
29767
  custom: { fields: { generator: str, params: () => null }, required: ["generator"] }
29586
29768
  };
29587
29769
 
29770
+ // ../game-shapes/dist/index.js
29771
+ var MIN_HALF = 0.01;
29772
+ var MAX_DEPTH = 3;
29773
+ var SPLIT_GAIN = 0.7;
29774
+ var MIN_POINTS = 8;
29775
+ var THICK = 0.03;
29776
+ var FAT = 0.15;
29777
+ var eigenvectors = (a) => {
29778
+ const m = a.slice();
29779
+ const v = [1, 0, 0, 0, 1, 0, 0, 0, 1];
29780
+ for (let sweep = 0; sweep < 24; sweep++) {
29781
+ const off = Math.abs(m[1]) + Math.abs(m[2]) + Math.abs(m[5]);
29782
+ if (off < 1e-12) break;
29783
+ for (const [p, q] of [[0, 1], [0, 2], [1, 2]]) {
29784
+ const apq = m[p * 3 + q];
29785
+ if (Math.abs(apq) < 1e-15) continue;
29786
+ const theta = (m[q * 3 + q] - m[p * 3 + p]) / (2 * apq);
29787
+ const t = Math.sign(theta || 1) / (Math.abs(theta) + Math.sqrt(theta * theta + 1));
29788
+ const c = 1 / Math.sqrt(t * t + 1);
29789
+ const s = t * c;
29790
+ for (let k = 0; k < 3; k++) {
29791
+ const mkp = m[k * 3 + p], mkq = m[k * 3 + q];
29792
+ m[k * 3 + p] = c * mkp - s * mkq;
29793
+ m[k * 3 + q] = s * mkp + c * mkq;
29794
+ }
29795
+ for (let k = 0; k < 3; k++) {
29796
+ const mpk = m[p * 3 + k], mqk = m[q * 3 + k];
29797
+ m[p * 3 + k] = c * mpk - s * mqk;
29798
+ m[q * 3 + k] = s * mpk + c * mqk;
29799
+ }
29800
+ for (let k = 0; k < 3; k++) {
29801
+ const vkp = v[k * 3 + p], vkq = v[k * 3 + q];
29802
+ v[k * 3 + p] = c * vkp - s * vkq;
29803
+ v[k * 3 + q] = s * vkp + c * vkq;
29804
+ }
29805
+ }
29806
+ }
29807
+ return v;
29808
+ };
29809
+ var quatOfAxes = (v) => {
29810
+ v[2] = v[3] * v[7] - v[6] * v[4];
29811
+ v[5] = v[6] * v[1] - v[0] * v[7];
29812
+ v[8] = v[0] * v[4] - v[3] * v[1];
29813
+ const [m00, m01, m02, m10, m11, m12, m20, m21, m22] = v;
29814
+ const trace = m00 + m11 + m22;
29815
+ let x, y, z, w;
29816
+ if (trace > 0) {
29817
+ const s = 0.5 / Math.sqrt(trace + 1);
29818
+ w = 0.25 / s;
29819
+ x = (m21 - m12) * s;
29820
+ y = (m02 - m20) * s;
29821
+ z = (m10 - m01) * s;
29822
+ } else if (m00 > m11 && m00 > m22) {
29823
+ const s = 2 * Math.sqrt(1 + m00 - m11 - m22);
29824
+ w = (m21 - m12) / s;
29825
+ x = 0.25 * s;
29826
+ y = (m01 + m10) / s;
29827
+ z = (m02 + m20) / s;
29828
+ } else if (m11 > m22) {
29829
+ const s = 2 * Math.sqrt(1 + m11 - m00 - m22);
29830
+ w = (m02 - m20) / s;
29831
+ x = (m01 + m10) / s;
29832
+ y = 0.25 * s;
29833
+ z = (m12 + m21) / s;
29834
+ } else {
29835
+ const s = 2 * Math.sqrt(1 + m22 - m00 - m11);
29836
+ w = (m10 - m01) / s;
29837
+ x = (m02 + m20) / s;
29838
+ y = (m12 + m21) / s;
29839
+ z = 0.25 * s;
29840
+ }
29841
+ const l = Math.hypot(x, y, z, w);
29842
+ return [x / l, y / l, z / l, w / l];
29843
+ };
29844
+ var fitOne = (points) => {
29845
+ const n = points.length / 3;
29846
+ let mx = 0, my = 0, mz = 0;
29847
+ for (let i = 0; i < points.length; i += 3) {
29848
+ mx += points[i];
29849
+ my += points[i + 1];
29850
+ mz += points[i + 2];
29851
+ }
29852
+ mx /= n;
29853
+ my /= n;
29854
+ mz /= n;
29855
+ const c = [0, 0, 0, 0, 0, 0, 0, 0, 0];
29856
+ for (let i = 0; i < points.length; i += 3) {
29857
+ const d = [points[i] - mx, points[i + 1] - my, points[i + 2] - mz];
29858
+ for (let r = 0; r < 3; r++) for (let k = 0; k < 3; k++) c[r * 3 + k] += d[r] * d[k];
29859
+ }
29860
+ const axes = eigenvectors(c);
29861
+ const rotation = quatOfAxes(axes);
29862
+ const lo = [Infinity, Infinity, Infinity];
29863
+ const hi = [-Infinity, -Infinity, -Infinity];
29864
+ for (let i = 0; i < points.length; i += 3) {
29865
+ for (let k = 0; k < 3; k++) {
29866
+ const t = points[i] * axes[k] + points[i + 1] * axes[3 + k] + points[i + 2] * axes[6 + k];
29867
+ lo[k] = Math.min(lo[k], t);
29868
+ hi[k] = Math.max(hi[k], t);
29869
+ }
29870
+ }
29871
+ const mid = [0, 1, 2].map((k) => (lo[k] + hi[k]) / 2);
29872
+ const center = [0, 1, 2].map((r) => axes[r * 3] * mid[0] + axes[r * 3 + 1] * mid[1] + axes[r * 3 + 2] * mid[2]);
29873
+ const half = [0, 1, 2].map((k) => Math.max(MIN_HALF, (hi[k] - lo[k]) / 2));
29874
+ return { box: { center, half, rotation }, axes, volume: 8 * half[0] * half[1] * half[2] };
29875
+ };
29876
+ var MIDDLE = [0.5];
29877
+ var ALONG = [0.15, 0.3, 0.5, 0.7, 0.85];
29878
+ var cut = (points, fit, k, along) => {
29879
+ const a = fit.axes;
29880
+ const middle = fit.box.center[0] * a[k] + fit.box.center[1] * a[3 + k] + fit.box.center[2] * a[6 + k];
29881
+ const mid = middle + (along - 0.5) * 2 * fit.box.half[k];
29882
+ const low = [];
29883
+ const high = [];
29884
+ for (let i = 0; i < points.length; i += 3) {
29885
+ const t = points[i] * a[k] + points[i + 1] * a[3 + k] + points[i + 2] * a[6 + k];
29886
+ (t < mid ? low : high).push(points[i], points[i + 1], points[i + 2]);
29887
+ }
29888
+ return [low, high];
29889
+ };
29890
+ var fitInto = (points, depth, out, isSurface = false) => {
29891
+ const fit = fitOne(points);
29892
+ const [thin, middle] = [...fit.box.half].sort((a, b) => a - b);
29893
+ if (depth >= MAX_DEPTH || points.length / 3 < MIN_POINTS || !isSurface && thin <= Math.max(THICK, FAT * middle)) {
29894
+ out.push(fit.box);
29895
+ return;
29896
+ }
29897
+ let best = null;
29898
+ let bestVolume = fit.volume * SPLIT_GAIN;
29899
+ for (let k = 0; k < 3; k++) {
29900
+ for (const along of isSurface ? ALONG : MIDDLE) {
29901
+ const [low, high] = cut(points, fit, k, along);
29902
+ if (low.length < 9 || high.length < 9) continue;
29903
+ const v = fitOne(low).volume + fitOne(high).volume;
29904
+ if (v < bestVolume) {
29905
+ bestVolume = v;
29906
+ best = [low, high];
29907
+ }
29908
+ }
29909
+ }
29910
+ if (!best) {
29911
+ out.push(fit.box);
29912
+ return;
29913
+ }
29914
+ fitInto(best[0], depth + 1, out, isSurface);
29915
+ fitInto(best[1], depth + 1, out, isSurface);
29916
+ };
29917
+ var EDGE = 0.2;
29918
+ var MAX_SAMPLES = 64;
29919
+ var MAX_SOLIDS = 16;
29920
+ var sampled = (points, triangles) => {
29921
+ const out = points.slice();
29922
+ for (let t = 0; t + 2 < triangles.length; t += 3) {
29923
+ for (let e = 0; e < 3; e++) {
29924
+ const a = triangles[t + e] * 3;
29925
+ const b = triangles[t + (e + 1) % 3] * 3;
29926
+ const length = Math.hypot(points[b] - points[a], points[b + 1] - points[a + 1], points[b + 2] - points[a + 2]);
29927
+ const count2 = Math.min(MAX_SAMPLES, Math.ceil(length / EDGE) - 1);
29928
+ for (let i = 1; i <= count2; i++) {
29929
+ const f = i / (count2 + 1);
29930
+ out.push(points[a] + (points[b] - points[a]) * f, points[a + 1] + (points[b + 1] - points[a + 1]) * f, points[a + 2] + (points[b + 2] - points[a + 2]) * f);
29931
+ }
29932
+ }
29933
+ }
29934
+ return out;
29935
+ };
29936
+ var WELD = 1e-4;
29937
+ var solidsOf = (points, triangles) => {
29938
+ const parent = Array.from({ length: points.length / 3 }, (_, v) => v);
29939
+ const at = /* @__PURE__ */ new Map();
29940
+ for (let v = 0; v < parent.length; v++) {
29941
+ const key = `${Math.round(points[v * 3] / WELD)},${Math.round(points[v * 3 + 1] / WELD)},${Math.round(points[v * 3 + 2] / WELD)}`;
29942
+ const first = at.get(key);
29943
+ if (first === void 0) at.set(key, v);
29944
+ else parent[v] = first;
29945
+ }
29946
+ const find = (v) => {
29947
+ let root = v;
29948
+ while (parent[root] !== root) root = parent[root];
29949
+ while (parent[v] !== root) [parent[v], v] = [root, parent[v]];
29950
+ return root;
29951
+ };
29952
+ for (let t = 0; t + 2 < triangles.length; t += 3) {
29953
+ parent[find(triangles[t + 1])] = find(triangles[t]);
29954
+ parent[find(triangles[t + 2])] = find(triangles[t]);
29955
+ }
29956
+ const groups = /* @__PURE__ */ new Map();
29957
+ for (let t = 0; t + 2 < triangles.length; t += 3) {
29958
+ const root = find(triangles[t]);
29959
+ const group = groups.get(root);
29960
+ if (group) group.push(triangles[t], triangles[t + 1], triangles[t + 2]);
29961
+ else groups.set(root, [triangles[t], triangles[t + 1], triangles[t + 2]]);
29962
+ }
29963
+ return [...groups.values()];
29964
+ };
29965
+ var fitOrientedBoxes = (points, triangles) => {
29966
+ if (points.length < 9) return [];
29967
+ const out = [];
29968
+ if (!triangles || triangles.length < 3) {
29969
+ fitInto(points, 0, out);
29970
+ return out;
29971
+ }
29972
+ const solids = solidsOf(points, triangles);
29973
+ const parts = solids.length > MAX_SOLIDS ? [triangles] : solids;
29974
+ for (const part of parts) {
29975
+ const own = [];
29976
+ const renumber = /* @__PURE__ */ new Map();
29977
+ const local = part.map((v) => {
29978
+ if (!renumber.has(v)) {
29979
+ renumber.set(v, own.length / 3);
29980
+ own.push(points[v * 3], points[v * 3 + 1], points[v * 3 + 2]);
29981
+ }
29982
+ return renumber.get(v);
29983
+ });
29984
+ if (own.length >= 9) fitInto(sampled(own, local), 0, out, true);
29985
+ }
29986
+ return out;
29987
+ };
29988
+ var fitOrientedBox = (points) => points.length < 9 ? null : fitOne(points).box;
29989
+ var hugs = (points, box2) => {
29990
+ const found = new Uint8Array(8);
29991
+ const a = box2.axes;
29992
+ let flat = 0;
29993
+ for (let k = 0; k < 3; k++) if (box2.half[k] <= box2.tolerance[k]) flat |= 1 << k;
29994
+ for (let i = 0; i < points.length; i += 3) {
29995
+ const dx = points[i] - box2.center[0], dy = points[i + 1] - box2.center[1], dz = points[i + 2] - box2.center[2];
29996
+ let corner = 0;
29997
+ let near = true;
29998
+ for (let k = 0; k < 3 && near; k++) {
29999
+ const t = dx * a[k * 3] + dy * a[k * 3 + 1] + dz * a[k * 3 + 2];
30000
+ if (Math.abs(Math.abs(t) - box2.half[k]) > box2.tolerance[k]) near = false;
30001
+ else if (t >= 0) corner |= 1 << k;
30002
+ }
30003
+ if (!near) continue;
30004
+ corner &= ~flat;
30005
+ for (let s = flat; ; s = s - 1 & flat) {
30006
+ found[corner | s] = 1;
30007
+ if (s === 0) break;
30008
+ }
30009
+ }
30010
+ for (let c = 0; c < 8; c++) if (!found[c]) return false;
30011
+ return true;
30012
+ };
30013
+ var SAME_COLOUR = 1 / 512;
30014
+ var SAME_FACING = 1 - 1e-6;
30015
+ var PARALLEL = Math.cos(2 * Math.PI / 180);
30016
+
29588
30017
  // ../game-shapes-three/dist/index.js
29589
30018
  var UV_BEFORE_NORMAL = /* @__PURE__ */ new Set(["LatheGeometry", "ExtrudeGeometry"]);
29590
30019
  var INDEX_FIRST = /* @__PURE__ */ new Set(["BoxGeometry", "CylinderGeometry", "ConeGeometry", "SphereGeometry", "PlaneGeometry", "CircleGeometry", "RingGeometry", "LatheGeometry", "TorusGeometry"]);
@@ -30676,7 +31105,7 @@ var GameVehiclesThree = (() => {
30676
31105
  ti.boxes[j + 3 + k] = Math.max(P[a + k], P[b + k], P[c + k]);
30677
31106
  }
30678
31107
  }
30679
- function advance(geo, ti, deadline) {
31108
+ function advance(geo, ti, deadline, clock) {
30680
31109
  const total = blockCount(ti.triangles);
30681
31110
  while (ti.builtBlocks < total) {
30682
31111
  const block = ti.builtBlocks;
@@ -30684,7 +31113,7 @@ var GameVehiclesThree = (() => {
30684
31113
  for (let t = block * TRI_BLOCK; t < t1; t++) boxTriangle(geo, ti, t);
30685
31114
  boxBlock(ti, block);
30686
31115
  ti.builtBlocks++;
30687
- if (deadline !== Infinity && performance.now() >= deadline) break;
31116
+ if (deadline !== Infinity && clock() >= deadline) break;
30688
31117
  }
30689
31118
  return ti.builtBlocks === total;
30690
31119
  }
@@ -30708,14 +31137,14 @@ var GameVehiclesThree = (() => {
30708
31137
  if (!supports(geo)) return void 0;
30709
31138
  let ti = cache.get(geo);
30710
31139
  if (!ti || !isCurrent(geo, ti)) ti = start(geo);
30711
- advance(geo, ti, Infinity);
31140
+ advance(geo, ti, Infinity, performance.now.bind(performance));
30712
31141
  return ti;
30713
31142
  }
30714
- function warmTriIndex(geo, deadline) {
31143
+ function warmTriIndex(geo, deadline, clock = performance.now.bind(performance)) {
30715
31144
  if (!supports(geo)) return true;
30716
31145
  let ti = cache.get(geo);
30717
31146
  if (!ti || !isCurrent(geo, ti)) ti = start(geo);
30718
- return advance(geo, ti, deadline);
31147
+ return advance(geo, ti, deadline, clock);
30719
31148
  }
30720
31149
  function storeTriIndex(geo, boxes) {
30721
31150
  const ti = start(geo);
@@ -30759,7 +31188,7 @@ var GameVehiclesThree = (() => {
30759
31188
  if (shared2 && isCurrent(geo, shared2) && shared2.builtBlocks === blockCount(shared2.triangles)) return shared2;
30760
31189
  let ti = rayCache.get(geo);
30761
31190
  if (!ti || !isCurrent(geo, ti)) ti = start(geo, rayCache);
30762
- advance(geo, ti, Infinity);
31191
+ advance(geo, ti, Infinity, performance.now.bind(performance));
30763
31192
  return ti;
30764
31193
  }
30765
31194
  var BLOCK_SLACK = 1e-6;
@@ -31050,9 +31479,9 @@ var GameVehiclesThree = (() => {
31050
31479
  const cs = Math.cos(deg * PI / 180);
31051
31480
  let phase = 0;
31052
31481
  let at = 0;
31053
- function hashSlice(deadline) {
31482
+ function hashSlice(deadline, clock) {
31054
31483
  for (; at < n; at++) {
31055
- if ((at & 1023) === 0 && performance.now() > deadline) return false;
31484
+ if ((at & 1023) === 0 && clock() > deadline) return false;
31056
31485
  const x = Math.round(P[3 * at] * 2e3) | 0;
31057
31486
  const y = Math.round(P[3 * at + 1] * 2e3) | 0;
31058
31487
  const z = Math.round(P[3 * at + 2] * 2e3) | 0;
@@ -31081,9 +31510,9 @@ var GameVehiclesThree = (() => {
31081
31510
  members = new Int32Array(n);
31082
31511
  for (let i = 0; i < n; i++) members[fill2[groupOf[i]]++] = i / 3 | 0;
31083
31512
  }
31084
- function smoothSlice(deadline) {
31513
+ function smoothSlice(deadline, clock) {
31085
31514
  for (; at < n; at++) {
31086
- if ((at & 1023) === 0 && performance.now() > deadline) return false;
31515
+ if ((at & 1023) === 0 && clock() > deadline) return false;
31087
31516
  const fi = (at / 3 | 0) * 3;
31088
31517
  const g = groupOf[at];
31089
31518
  let sx = 0;
@@ -31109,16 +31538,16 @@ var GameVehiclesThree = (() => {
31109
31538
  }
31110
31539
  return true;
31111
31540
  }
31112
- function step(deadline) {
31541
+ function step(deadline, clock = performance.now.bind(performance)) {
31113
31542
  if (latestCrease.get(geo) !== token) return true;
31114
31543
  if (phase === 0) {
31115
- if (!hashSlice(deadline)) return false;
31544
+ if (!hashSlice(deadline, clock)) return false;
31116
31545
  gather();
31117
31546
  phase = 1;
31118
31547
  at = 0;
31119
31548
  }
31120
31549
  if (phase === 1) {
31121
- const done = smoothSlice(deadline);
31550
+ const done = smoothSlice(deadline, clock);
31122
31551
  if (deadline !== Infinity) normal.needsUpdate = true;
31123
31552
  if (!done) return false;
31124
31553
  phase = 2;
@@ -31299,7 +31728,7 @@ var GameVehiclesThree = (() => {
31299
31728
  }
31300
31729
  return t;
31301
31730
  }
31302
- const cut = {};
31731
+ const cut2 = {};
31303
31732
  const n = new V3();
31304
31733
  const e1 = new V3();
31305
31734
  const e2 = new V3();
@@ -31358,7 +31787,7 @@ var GameVehiclesThree = (() => {
31358
31787
  const T = tests[0];
31359
31788
  const lo = T.bounds.lo;
31360
31789
  const hi = T.bounds.hi;
31361
- const rem = T.tag ? cut[T.tag] = cut[T.tag] || [] : null;
31790
+ const rem = T.tag ? cut2[T.tag] = cut2[T.tag] || [] : null;
31362
31791
  const boxes = ti.boxes;
31363
31792
  const blocks = ti.blocks;
31364
31793
  let runFrom = -1;
@@ -31396,7 +31825,7 @@ var GameVehiclesThree = (() => {
31396
31825
  for (let f = 0; f < nv; f += 3) tris.push(readTri(f));
31397
31826
  tests.forEach(function(T) {
31398
31827
  const next = [];
31399
- const rem = T.tag ? cut[T.tag] = cut[T.tag] || [] : null;
31828
+ const rem = T.tag ? cut2[T.tag] = cut2[T.tag] || [] : null;
31400
31829
  tris.forEach(function(t) {
31401
31830
  testTri(T, t, next, rem);
31402
31831
  });
@@ -31457,8 +31886,8 @@ var GameVehiclesThree = (() => {
31457
31886
  const boxesOut = ti ? new Float64Array(total * 6) : void 0;
31458
31887
  const out = { geo: fill2(segments, total, boxesOut), cut: {}, tasks: {} };
31459
31888
  if (boxesOut) storeTriIndex(out.geo, boxesOut);
31460
- Object.keys(cut).forEach(function(k) {
31461
- const piece = fill2([cut[k]], cut[k].length);
31889
+ Object.keys(cut2).forEach(function(k) {
31890
+ const piece = fill2([cut2[k]], cut2[k].length);
31462
31891
  const mode = tests.find(function(T) {
31463
31892
  return T.tag === k;
31464
31893
  }).pieces;
@@ -32111,7 +32540,7 @@ var GameVehiclesThree = (() => {
32111
32540
  geo = subdivide(geo, o.sub || 0.2);
32112
32541
  tumble(geo, o.T);
32113
32542
  const tests = (o.holes || []).slice();
32114
- let cut = {};
32543
+ let cut2 = {};
32115
32544
  if (o.arches && o.archInner != null)
32116
32545
  o.arches.forEach(function(a) {
32117
32546
  const zk = o.archInner;
@@ -32130,12 +32559,12 @@ var GameVehiclesThree = (() => {
32130
32559
  if (tests.length) {
32131
32560
  const r = cutGeometry(geo, tests);
32132
32561
  geo = r.geo;
32133
- cut = r.cut;
32562
+ cut2 = r.cut;
32134
32563
  }
32135
32564
  crease(geo, 42);
32136
32565
  const m = c.add(geo, o.mat || c.paint(o.col));
32137
32566
  c.deform.push(m);
32138
- m.userData.cut = cut;
32567
+ m.userData.cut = cut2;
32139
32568
  if (o.arches)
32140
32569
  o.arches.forEach(function(a) {
32141
32570
  const a0 = Math.asin(clamp((o.bottomY - a[1]) / a[2], -1, 1));
@@ -35883,15 +36312,32 @@ var GameVehiclesThree = (() => {
35883
36312
  const m = c.meta;
35884
36313
  return new V3(m.front - 0.6, (m.clearance || 0.3) + 0.3, 0);
35885
36314
  }
36315
+ function worldPointOf(c, local) {
36316
+ c.vehicle.updateWorldMatrix(true, false);
36317
+ const wp = local.clone().applyMatrix4(c.vehicle.matrixWorld);
36318
+ return [wp.x, wp.y, wp.z];
36319
+ }
36320
+ function startVehicleFire(c, local, radius, life) {
36321
+ const effects = kit.effects?.();
36322
+ if (!effects) return false;
36323
+ const handle = effects.play({ effect: "volumetric_fire", point: worldPointOf(c, local), values: { radius, life } });
36324
+ if (handle != null) {
36325
+ c.vfxHandles = c.vfxHandles || [];
36326
+ c.vfxHandles.push(handle);
36327
+ }
36328
+ return true;
36329
+ }
35886
36330
  kit.explode = function(c, o) {
35887
36331
  o = o || {};
35888
36332
  if (c.blast || c.exploded) return false;
35889
36333
  const fuse2 = o.now ? 0 : o.delay != null ? o.delay : 3 + c.rand() * 5;
35890
- c.blast = { phase: "fire", t: 0, T: fuse2 };
36334
+ c.blast = { phase: "fire", t: 0, T: fuse2, skipBlastEffect: !!o.skipBlastEffect };
35891
36335
  if (fuse2 > 0) {
35892
36336
  const ep = enginePos(c);
35893
- kit.addEmitter(c, ep.clone().add(new V3(0, 0.25, 0)), "fire", { rate: 10, s: 0.9 });
35894
- kit.addEmitter(c, ep.clone().add(new V3(0, 0.6, 0)), "black", { rate: 6, s: 1.2 });
36337
+ if (!startVehicleFire(c, ep.clone().add(new V3(0, 0.25, 0)), 0.55, fuse2 + 2)) {
36338
+ kit.addEmitter(c, ep.clone().add(new V3(0, 0.25, 0)), "fire", { rate: 10, s: 0.9 });
36339
+ kit.addEmitter(c, ep.clone().add(new V3(0, 0.6, 0)), "black", { rate: 6, s: 1.2 });
36340
+ }
35895
36341
  I.hurtEngine(c, 0.1);
35896
36342
  }
35897
36343
  if (c.hood) c.hood.target = 0;
@@ -35909,8 +36355,10 @@ var GameVehiclesThree = (() => {
35909
36355
  return p.kind === "fuel_tank";
35910
36356
  });
35911
36357
  const tp = tk ? tk.pos.clone() : enginePos(c);
35912
- kit.addEmitter(c, tp.clone().setY(Math.max(0.15, tp.y)), "fire", { rate: 12, s: 1.1 });
35913
- kit.addEmitter(c, tp.clone().setY(tp.y + 0.8), "black", { rate: 5, s: 1.4 });
36358
+ if (!startVehicleFire(c, tp.clone().setY(Math.max(0.15, tp.y)), 0.65, 25)) {
36359
+ kit.addEmitter(c, tp.clone().setY(Math.max(0.15, tp.y)), "fire", { rate: 12, s: 1.1 });
36360
+ kit.addEmitter(c, tp.clone().setY(tp.y + 0.8), "black", { rate: 5, s: 1.4 });
36361
+ }
35914
36362
  return "fire";
35915
36363
  }
35916
36364
  return null;
@@ -36017,42 +36465,51 @@ var GameVehiclesThree = (() => {
36017
36465
  c.emitters = c.emitters.filter(function(e) {
36018
36466
  return e.kind !== "exhaust";
36019
36467
  });
36020
- const fl = new THREE.Sprite(
36021
- new THREE.SpriteMaterial({
36022
- map: I.glowTexture(),
36023
- color: 16767392,
36024
- blending: THREE.AdditiveBlending,
36025
- transparent: true,
36026
- depthWrite: false,
36027
- fog: false
36028
- })
36029
- );
36030
- fl.raycast = function() {
36031
- };
36032
- fl.position.copy(cen);
36033
- fl.scale.setScalar(0.1);
36034
- c.effects.add(fl);
36035
- B.flash = fl;
36036
- const sw = new THREE.Mesh(new THREE.RingGeometry(0.8, 1, 64), boomMat("#ffcf8a", 0.6, true));
36037
- sw.rotation.x = -PI / 2;
36038
- sw.position.set(cen.x, 0.07, cen.z);
36039
- c.effects.add(sw);
36040
- B.shock = sw;
36041
- const k = big ? 1.8 : 1;
36042
- for (let i = 0; i < (big ? 70 : 46); i++) {
36043
- const d = new V3(c.rand() - 0.5, c.rand() * 0.9, c.rand() - 0.5).normalize();
36044
- kit.spawn(c, "fire", cen.clone().addScaledVector(d, 0.3), d.multiplyScalar((2.5 + c.rand() * 4) * k), {
36045
- s: (1 + c.rand() * 1.4) * k,
36046
- life: 0.8 + c.rand() * 0.7
36047
- });
36048
- }
36049
- for (let j = 0; j < (big ? 30 : 18); j++) {
36050
- const d2 = new V3(c.rand() - 0.5, 0.4 + c.rand(), c.rand() - 0.5).normalize();
36051
- kit.spawn(c, "smoke", cen.clone().addScaledVector(d2, 0.6), d2.multiplyScalar(1.5 + c.rand() * 2), {
36052
- variant: "black",
36053
- s: (1.4 + c.rand()) * k,
36054
- life: 4 + c.rand() * 2
36055
- });
36468
+ const effects = kit.effects?.();
36469
+ if (effects) {
36470
+ if (!B.skipBlastEffect) {
36471
+ c.effects.updateWorldMatrix(true, false);
36472
+ const worldCen = cen.clone().applyMatrix4(c.effects.matrixWorld);
36473
+ effects.play({ effect: big ? "fuel_station_tank" : "car_fuel_tank", point: [worldCen.x, worldCen.y, worldCen.z], values: {} });
36474
+ }
36475
+ } else {
36476
+ const fl = new THREE.Sprite(
36477
+ new THREE.SpriteMaterial({
36478
+ map: I.glowTexture(),
36479
+ color: 16767392,
36480
+ blending: THREE.AdditiveBlending,
36481
+ transparent: true,
36482
+ depthWrite: false,
36483
+ fog: false
36484
+ })
36485
+ );
36486
+ fl.raycast = function() {
36487
+ };
36488
+ fl.position.copy(cen);
36489
+ fl.scale.setScalar(0.1);
36490
+ c.effects.add(fl);
36491
+ B.flash = fl;
36492
+ const sw = new THREE.Mesh(new THREE.RingGeometry(0.8, 1, 64), boomMat("#ffcf8a", 0.6, true));
36493
+ sw.rotation.x = -PI / 2;
36494
+ sw.position.set(cen.x, 0.07, cen.z);
36495
+ c.effects.add(sw);
36496
+ B.shock = sw;
36497
+ const k = big ? 1.8 : 1;
36498
+ for (let i = 0; i < (big ? 70 : 46); i++) {
36499
+ const d = new V3(c.rand() - 0.5, c.rand() * 0.9, c.rand() - 0.5).normalize();
36500
+ kit.spawn(c, "fire", cen.clone().addScaledVector(d, 0.3), d.multiplyScalar((2.5 + c.rand() * 4) * k), {
36501
+ s: (1 + c.rand() * 1.4) * k,
36502
+ life: 0.8 + c.rand() * 0.7
36503
+ });
36504
+ }
36505
+ for (let j = 0; j < (big ? 30 : 18); j++) {
36506
+ const d2 = new V3(c.rand() - 0.5, 0.4 + c.rand(), c.rand() - 0.5).normalize();
36507
+ kit.spawn(c, "smoke", cen.clone().addScaledVector(d2, 0.6), d2.multiplyScalar(1.5 + c.rand() * 2), {
36508
+ variant: "black",
36509
+ s: (1.4 + c.rand()) * k,
36510
+ life: 4 + c.rand() * 2
36511
+ });
36512
+ }
36056
36513
  }
36057
36514
  I.burst(c, "spark", cen, 40, { speed: 7, spread: 1.6 });
36058
36515
  I.burst(c, "scrap", cen, 14, {
@@ -36065,7 +36522,7 @@ var GameVehiclesThree = (() => {
36065
36522
  const G2 = gm2.userData.glass;
36066
36523
  if (!G2 || G2.broken || !gm2.visible || !gm2.parent) return;
36067
36524
  if (G2.type === "laminated") {
36068
- for (let k2 = 0; k2 < 3; k2++) I.crackGlass(c, gm2, I.glassPt ? I.glassPt(c, gm2, c.rand) : gm2.position.clone(), 1.2);
36525
+ for (let k = 0; k < 3; k++) I.crackGlass(c, gm2, I.glassPt ? I.glassPt(c, gm2, c.rand) : gm2.position.clone(), 1.2);
36069
36526
  return;
36070
36527
  }
36071
36528
  I.shatterGlass(c, gm2, 1.4, new V3(0, 1, 0));
@@ -36091,14 +36548,19 @@ var GameVehiclesThree = (() => {
36091
36548
  c.emitters.forEach(function(e) {
36092
36549
  if (e.kind === "fire") e.rate = Math.min(e.rate, 7);
36093
36550
  });
36094
- kit.addEmitter(c, ep.clone().add(new V3(0, 0.15, 0)), "fire", { rate: 8, s: 0.8 });
36095
- kit.addEmitter(c, new V3(((m.front || 1) + (m.rear || -1)) / 2, (m.clearance || 0.3) + 0.35, 0), "fire", { rate: 6, s: 0.7 });
36096
- kit.addEmitter(c, ep.clone().add(new V3(0, 0.9, 0)), "black", { rate: 4, s: 1.4 });
36551
+ if (effects) {
36552
+ startVehicleFire(c, ep.clone().add(new V3(0, 0.15, 0)), 0.55, 30);
36553
+ startVehicleFire(c, new V3(((m.front || 1) + (m.rear || -1)) / 2, (m.clearance || 0.3) + 0.35, 0), 0.45, 25);
36554
+ } else {
36555
+ kit.addEmitter(c, ep.clone().add(new V3(0, 0.15, 0)), "fire", { rate: 8, s: 0.8 });
36556
+ kit.addEmitter(c, new V3(((m.front || 1) + (m.rear || -1)) / 2, (m.clearance || 0.3) + 0.35, 0), "fire", { rate: 6, s: 0.7 });
36557
+ kit.addEmitter(c, ep.clone().add(new V3(0, 0.9, 0)), "black", { rate: 4, s: 1.4 });
36558
+ }
36097
36559
  c.parts.forEach(function(p) {
36098
36560
  if (p.kind === "glass" || p.kind === "headlight" || p.kind === "taillight" || p.kind === "hood") p.done = true;
36099
36561
  });
36100
36562
  c.log.push({ kind: "explosion", label: kit.t(big ? "blast.tank_explosion" : "blast.explosion") });
36101
- if (big) bigBoomFx(c);
36563
+ if (big && !effects) bigBoomFx(c);
36102
36564
  }
36103
36565
  function tickBoom(c, dt) {
36104
36566
  const B = c.blast;
@@ -40861,6 +41323,11 @@ var GameVehiclesThree = (() => {
40861
41323
  return c;
40862
41324
  }
40863
41325
  kit.dispose = function(c) {
41326
+ if (Array.isArray(c.vfxHandles) && c.vfxHandles.length > 0) {
41327
+ const effects = kit.effects?.();
41328
+ for (const handle of c.vfxHandles) effects?.stop?.(handle);
41329
+ c.vfxHandles = [];
41330
+ }
40864
41331
  const shared2 = Object.values(I.PARTICLE_GEOMETRIES);
40865
41332
  c.root.traverse(function(o) {
40866
41333
  if (o.isSprite) {
@@ -41798,6 +42265,7 @@ var GameVehiclesThree = (() => {
41798
42265
  return Math.abs(centre.x - zone.x0) < SEAM_AT_EDGE || Math.abs(centre.x - zone.x1) < SEAM_AT_EDGE;
41799
42266
  }
41800
42267
  var HOLE_DECAL_SCALE = 2.4;
42268
+ var HOLE_BATCH_CAPACITY = 64;
41801
42269
  var DOOR_DEPTH = 0.07;
41802
42270
  var DOOR_SKIN_DEPTH = 0.09;
41803
42271
  var DOOR_FLOOR_DEPTH = 0.2;
@@ -41937,7 +42405,23 @@ var GameVehiclesThree = (() => {
41937
42405
  __publicField(this, "holdArmed", false);
41938
42406
  __publicField(this, "holdFrame", -1);
41939
42407
  __publicField(this, "smoothing", /* @__PURE__ */ new Map());
42408
+ __publicField(this, "holes", /* @__PURE__ */ new Map());
41940
42409
  __publicField(this, "hood");
42410
+ __publicField(this, "pumpQueue", {
42411
+ id: DEFERRED_QUEUE_ID.VEHICLE_CREASE,
42412
+ pending: () => this.smoothing.size + (this.warming ? 1 : 0),
42413
+ run: (deadline, clock) => {
42414
+ let ran = 0;
42415
+ for (const [msh, task] of this.smoothing) {
42416
+ if (msh.geometry !== task.geo || task.step(deadline, clock)) this.smoothing.delete(msh);
42417
+ ran++;
42418
+ if (clock() >= deadline) return ran;
42419
+ }
42420
+ this.warmIndexes(deadline, clock);
42421
+ return ran + 1;
42422
+ },
42423
+ flush: () => this.finishAll()
42424
+ });
41941
42425
  ;
41942
42426
  c.smoothLater = (mesh2) => this.smoothLater(mesh2);
41943
42427
  this.kit = kit;
@@ -42866,19 +43350,44 @@ var GameVehiclesThree = (() => {
42866
43350
  const pane = part?.role === "glass" ? this.panesOf(part).find((g) => g.visible) : void 0;
42867
43351
  if (part?.role === "glass" && (!pane || pane.userData.glass?.broken)) return;
42868
43352
  const radius = Math.max(6e-3, diameter / 2) * HOLE_DECAL_SCALE;
42869
- const m = new THREE.Mesh(holeDiscGeometry(THREE), holeMaterial(this.kit, part?.material ?? "steel"));
42870
- m.scale.set(radius, radius, 1);
42871
43353
  const n = new THREE.Vector3(...normal);
42872
- m.position.set(...point).addScaledVector(n, 3e-3);
42873
- this.c.vehicle.add(m);
42874
- m.lookAt(this.c.vehicle.localToWorld(m.position.clone().add(n)));
42875
- m.userData.decal = true;
42876
- m.userData.noFollow = true;
42877
- m.renderOrder = 3;
42878
- m.raycast = () => {
42879
- };
42880
43354
  const carrier = (part && (this.plates.get(part.id) ?? (part.id === this.hood?.id ? this.c.hood?.piv : void 0))) ?? (pane && pane.parent !== this.c.vehicle ? pane.parent : null);
42881
- if (carrier) carrier.attach(m);
43355
+ const parent = carrier ?? this.c.vehicle;
43356
+ const material = holeMaterial(this.kit, part?.material ?? "steel");
43357
+ const key = `${parent.uuid}|${material.uuid}`;
43358
+ let batches = this.holes.get(key);
43359
+ let batch = batches?.[batches.length - 1];
43360
+ if (!batch || batch.count >= HOLE_BATCH_CAPACITY) {
43361
+ batch = new THREE.InstancedMesh(holeDiscGeometry(THREE), material, HOLE_BATCH_CAPACITY);
43362
+ batch.count = 0;
43363
+ batch.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
43364
+ batch.castShadow = false;
43365
+ batch.receiveShadow = false;
43366
+ batch.userData.decal = true;
43367
+ batch.userData.noFollow = true;
43368
+ batch.renderOrder = 3;
43369
+ batch.raycast = () => {
43370
+ };
43371
+ batch.frustumCulled = false;
43372
+ parent.add(batch);
43373
+ if (!batches) {
43374
+ batches = [];
43375
+ this.holes.set(key, batches);
43376
+ }
43377
+ batches.push(batch);
43378
+ }
43379
+ const at = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 3e-3));
43380
+ const toward = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 1.003));
43381
+ const pose = new THREE.Object3D();
43382
+ pose.position.copy(at);
43383
+ pose.scale.set(radius, radius, 1);
43384
+ pose.lookAt(toward);
43385
+ pose.updateMatrix();
43386
+ parent.updateWorldMatrix(true, false);
43387
+ const instance = new THREE.Matrix4().copy(parent.matrixWorld).invert().multiply(pose.matrix);
43388
+ batch.setMatrixAt(batch.count, instance);
43389
+ batch.count += 1;
43390
+ batch.instanceMatrix.needsUpdate = true;
42882
43391
  }
42883
43392
  /** The door or lid a hinge group stands for. */
42884
43393
  /** The part a separately drawn piece stands for (a mirror on the door, a battery under the hood), so a shot at it lands on that part. */
@@ -43031,12 +43540,7 @@ var GameVehiclesThree = (() => {
43031
43540
  }
43032
43541
  if (this.queued) return;
43033
43542
  if (!this.smoothing.size && !this.warming) return;
43034
- const deadline = performance.now() + budgetMs;
43035
- for (const [msh, task] of this.smoothing) {
43036
- if (msh.geometry !== task.geo || task.step(deadline)) this.smoothing.delete(msh);
43037
- if (performance.now() >= deadline) return;
43038
- }
43039
- this.warmIndexes(deadline);
43543
+ drainDetached(this.pumpQueue, budgetMs);
43040
43544
  }
43041
43545
  setQueued(isQueued) {
43042
43546
  this.queued = isQueued;
@@ -43052,24 +43556,24 @@ var GameVehiclesThree = (() => {
43052
43556
  return this.smoothing.size + (this.warming ? 1 : 0);
43053
43557
  }
43054
43558
  /** One slice of the pending work, for the shared queue. */
43055
- runStep(deadline) {
43559
+ runStep(deadline, clock) {
43056
43560
  const next = this.smoothing.entries().next();
43057
43561
  if (!next.done) {
43058
43562
  const [msh, task] = next.value;
43059
- if (msh.geometry !== task.geo || task.step(deadline)) this.smoothing.delete(msh);
43563
+ if (msh.geometry !== task.geo || task.step(deadline, clock)) this.smoothing.delete(msh);
43060
43564
  return true;
43061
43565
  }
43062
43566
  if (!this.warming) return false;
43063
- this.warmIndexes(deadline);
43567
+ this.warmIndexes(deadline, clock);
43064
43568
  return true;
43065
43569
  }
43066
43570
  finishAll() {
43067
43571
  while (this.runStep(Infinity)) ;
43068
43572
  }
43069
43573
  /** Measures the triangles of the heavy body meshes once, a slice per frame, so the first panel torn off finds them ready (see `triIndexOf`). */
43070
- warmIndexes(deadline) {
43574
+ warmIndexes(deadline, clock) {
43071
43575
  if (!this.warming) return;
43072
- this.warming = this.warming.filter((msh) => !warmTriIndex(msh.geometry, deadline));
43576
+ this.warming = this.warming.filter((msh) => !warmTriIndex(msh.geometry, deadline, clock));
43073
43577
  if (!this.warming.length) this.warming = null;
43074
43578
  }
43075
43579
  /** Moves the panel of a lost zone out of the body (the kit's torn-off look). */
@@ -43317,9 +43821,12 @@ var GameVehiclesThree = (() => {
43317
43821
  rim: 4
43318
43822
  };
43319
43823
  var BLUNT = { steel: 0.8, aluminium: 1, glass: 1.5, plastic: 1.2, rubber: 0.3 };
43824
+ var SHIELDED_REACH = 0.25;
43825
+ var DENSITY = { steel: 7850, aluminium: 2700, glass: 2500, plastic: 1100, rubber: 1100, wood_hard: 750, fabric: 400 };
43320
43826
  var SHIELDED = /* @__PURE__ */ new Set(["engine", "gearbox", "frame", "radiator", "fuel_tank", "oil_pan", "battery", "alternator", "brakes", "steering", "shocks"]);
43321
43827
  var AMBIENT = 20;
43322
43828
  var FLAME = 700;
43829
+ var FIREBALL_NOTICE = 0.05;
43323
43830
  var STEEL_MM = { panel: 0.8, door: 1.6, hood: 0.8, lid: 0.8, roof: 0.8, fender: 0.8, pillar: 2, frame: 4, rim: 3, engine: 40, gearbox: 25, fuel_tank: 1, radiator: 1, battery: 2, brakes: 10, steering: 8, shocks: 6, oil_pan: 2, alternator: 4, hitch: 8, other: 2 };
43324
43831
  var ARMOUR_STEEL_MM = { IIIA: 4, III: 7 };
43325
43832
  var SOFT_LEAD = 0.8;
@@ -43575,8 +44082,9 @@ var GameVehiclesThree = (() => {
43575
44082
  for (const j of js) if (!j.open && (j.def.a === d.id || j.def.b === d.id)) openJoint(j, "part_lost", out);
43576
44083
  recomputeGroups();
43577
44084
  };
43578
- const damage = (p, amount, dtype, source, out, cause) => {
43579
- if (p.lost || !(amount > 0)) return;
44085
+ const damage = (p, hitAmount, dtype, source, out, cause, pieces = 1) => {
44086
+ if (p.lost || !(hitAmount > 0)) return;
44087
+ const amount = pieces > 1 ? Math.min(hitAmount * pieces, Math.max(hitAmount, p.hp)) : hitAmount;
43580
44088
  const before = p.hp;
43581
44089
  const crumples = dtype === "blunt" && CRUMPLES.has(p.def.role) && (p.def.material === "steel" || p.def.material === "aluminium");
43582
44090
  const punctures = dtype === "ballistic" && p.def.role === "tyre";
@@ -43683,16 +44191,30 @@ var GameVehiclesThree = (() => {
43683
44191
  if (l?.pud && l.fluid === "fuel") I.igniteFuel(c, l.pud);
43684
44192
  }
43685
44193
  };
43686
- const burningBlast = (centreLocal, radius, energy, source, out) => {
44194
+ const burningBlast = (centreLocal, radius, energy, source, out, tnt = energy * DEFAULT_BLAST_IMPULSE.tntPerJoule) => {
44195
+ let tank = 0;
43687
44196
  for (const d of model.parts) {
43688
44197
  const p = ps.get(d.id);
43689
44198
  if (p.lost) continue;
43690
44199
  const dist = distToBox(d, centreLocal);
43691
44200
  if (dist > radius) continue;
43692
- const base = energy / (1 + dist * dist * 4);
43693
- const shield = SHIELDED.has(d.role) ? 0.25 : 1;
43694
- damage(p, base * (BLUNT[d.material] ?? 1) * shield * 0.04, "explosive", source, out);
43695
- }
44201
+ const work = waveOn(d, centreLocal, dist, tnt);
44202
+ if (d.role === "fuel_tank") tank = work;
44203
+ damage(p, work * (BLUNT[d.material] ?? 1), "explosive", source, out);
44204
+ }
44205
+ return tank;
44206
+ };
44207
+ const waveOn = (d, centreLocal, dist, tnt) => {
44208
+ const [sx, sy, sz] = d.box.size;
44209
+ const toward = new V3(centreLocal.x - d.box.center[0], centreLocal.y - d.box.center[1], centreLocal.z - d.box.center[2]);
44210
+ const length = toward.length();
44211
+ if (length > 1e-6) toward.multiplyScalar(1 / length);
44212
+ else toward.set(0, 1, 0);
44213
+ const area3 = Math.abs(toward.x) * sy * sz + Math.abs(toward.y) * sx * sz + Math.abs(toward.z) * sx * sy;
44214
+ const face = Math.max(sx * sy, sx * sz, sy * sz, 1e-6);
44215
+ const thickness = Math.min(Math.min(sx, sy, sz), d.mass / ((DENSITY[d.material] ?? 1e3) * face));
44216
+ const wave = waveWork({ tnt, distance: dist, reach: SHIELDED.has(d.role) ? SHIELDED_REACH : 1, area: area3, mass: Math.max(d.mass, 0.05), thickness });
44217
+ return wave.energy + wave.shock;
43696
44218
  };
43697
44219
  const explode = (tank, source, out) => {
43698
44220
  if (exploded) return;
@@ -43702,7 +44224,7 @@ var GameVehiclesThree = (() => {
43702
44224
  out.push(ev({ type: "explode", part: d.id, point: toWorld(d.box.center), energy: spec.energy, radius: spec.radius, ..."effect" in spec && spec.effect !== void 0 ? { effect: spec.effect } : {} }));
43703
44225
  tank.liters = 0;
43704
44226
  leaks.delete(d.id);
43705
- if (vis) kit.explode(c, { delay: 0.6 });
44227
+ if (vis) kit.explode(c, { delay: 0.6, skipBlastEffect: true });
43706
44228
  else c.blast = c.blast ?? { phase: "fire", t: 0, T: 0.6 };
43707
44229
  lose(tank, "broken", out);
43708
44230
  burningBlast(centreOf(d), spec.radius, spec.energy, source, out);
@@ -43796,6 +44318,7 @@ var GameVehiclesThree = (() => {
43796
44318
  const d = p.def;
43797
44319
  const E = h.energy ?? 0;
43798
44320
  const cal = h.caliber ?? 9;
44321
+ const pieces = h.pieces ?? 1;
43799
44322
  const dir = dirToLocal(h.direction ?? [0, 0, -1]).normalize();
43800
44323
  const n = h.normal ? dirToLocal(h.normal).normalize() : normalOf(d, v);
43801
44324
  const res = resist(d, p);
@@ -43806,7 +44329,7 @@ var GameVehiclesThree = (() => {
43806
44329
  if (metal && !through && cosInc < 0.3 && E > 40) {
43807
44330
  const refl = dir.clone().addScaledVector(n, -2 * dir.dot(n));
43808
44331
  out.push(ev({ type: "ricochet", part: d.id, point: worldPoint, direction: r3(dirToWorld(refl)), energy: r2(E * 0.4) }));
43809
- damage(p, E * 0.05, "ballistic", h.source, out, worldPoint);
44332
+ damage(p, E * 0.05, "ballistic", h.source, out, worldPoint, pieces);
43810
44333
  vis?.spark([v.x, v.y, v.z], [refl.x, refl.y, refl.z], 6);
43811
44334
  return;
43812
44335
  }
@@ -43837,13 +44360,13 @@ var GameVehiclesThree = (() => {
43837
44360
  const crack = { point: r3(fromVehicle(v, M)), normal: r3(fromVehicle(n, new THREE.Matrix4().extractRotation(M))), length: r2(0.15 + force * 0.35), rays: 6 + Math.round(force * 6) };
43838
44361
  p.cracks.push(crack);
43839
44362
  out.push(ev({ type: "crack", part: d.id, crack, worldPoint }));
43840
- damage(p, E * (armourLevel && !through ? armourLevel.glassTakes : 0.5), "ballistic", h.source, out, worldPoint);
43841
- } else damage(p, laminated ? E * 0.5 : p.hp, "ballistic", h.source, out, worldPoint);
44363
+ damage(p, E * (armourLevel && !through ? armourLevel.glassTakes : 0.5), "ballistic", h.source, out, worldPoint, pieces);
44364
+ } else damage(p, laminated ? E * 0.5 : p.hp, "ballistic", h.source, out, worldPoint, laminated ? pieces : 1);
43842
44365
  break;
43843
44366
  }
43844
44367
  case "rubber": {
43845
44368
  push(through);
43846
- damage(p, E * 0.4, "ballistic", h.source, out, worldPoint);
44369
+ damage(p, E * 0.4, "ballistic", h.source, out, worldPoint, pieces);
43847
44370
  if (through && !p.lost && !p.flat) {
43848
44371
  if (E >= TYRE_BURST_JOULES || cal >= TYRE_BURST_CALIBER) deflate(p, 1);
43849
44372
  else p.airLoss += TYRE_LEAK_PER_MM2 * Math.PI * (cal / 2) ** 2;
@@ -43860,7 +44383,7 @@ var GameVehiclesThree = (() => {
43860
44383
  vis?.spark([v.x, v.y, v.z], [dir.x, dir.y, dir.z], through ? 4 : 8);
43861
44384
  let amount = through ? E * 0.6 : E * 0.25;
43862
44385
  if (through && (d.role === "battery" || d.role === "alternator")) amount = Math.max(amount, p.hp * 0.65);
43863
- damage(p, amount, "ballistic", h.source, out, worldPoint);
44386
+ damage(p, amount, "ballistic", h.source, out, worldPoint, pieces);
43864
44387
  if (through && d.role === "fuel_tank") rollIgnition(p, h, metal, out);
43865
44388
  }
43866
44389
  }
@@ -43931,12 +44454,12 @@ var GameVehiclesThree = (() => {
43931
44454
  const nearest = Math.min(...model.parts.map((d) => distToBox(d, v)));
43932
44455
  if (nearest > radius) return;
43933
44456
  if (vis && E >= 3e3) kit.impact(c, v.clone().addScaledVector(dir, -0.1).setY(clamp(v.y, 0.3, 1.2)), dir, clamp(0.4 + E / 6e4, 0.4, 1.4), { noStain: true });
43934
- burningBlast(v, radius, E, h.source, out);
44457
+ const tankWork = burningBlast(v, radius, E, h.source, out, h.tnt);
43935
44458
  const tank = [...ps.values()].find((q) => q.def.role === "fuel_tank" && !q.lost);
43936
44459
  if (tank && !exploded) {
43937
44460
  const dist = distToBox(tank.def, v);
43938
44461
  if (dist <= radius) {
43939
- const verdict = kit.blastDamage(c, E / (1 + dist * dist * 4) / 50);
44462
+ const verdict = kit.blastDamage(c, tankWork);
43940
44463
  if (verdict === "explosion") explode(tank, h.source, out);
43941
44464
  else if (verdict === "fire") {
43942
44465
  light(tank, out);
@@ -43944,7 +44467,14 @@ var GameVehiclesThree = (() => {
43944
44467
  }
43945
44468
  }
43946
44469
  }
43947
- heat(v, radius * 0.5, 450, 1, out);
44470
+ const fireball = h.fireball ?? chargeFireball(E * DEFAULT_BLAST_IMPULSE.tntPerJoule);
44471
+ for (const d of model.parts) {
44472
+ const p = ps.get(d.id);
44473
+ if (p.lost || !d.ignitionC) continue;
44474
+ const needed = ignitionDose(d.ignitionC, AMBIENT);
44475
+ const share = Math.min(1, fireballDose(fireball, distToBox(d, v)) / needed);
44476
+ if (share >= FIREBALL_NOTICE) p.temp = Math.max(p.temp, AMBIENT + (d.ignitionC + 1 - AMBIENT) * share);
44477
+ }
43948
44478
  };
43949
44479
  const fireHit = (h, out) => {
43950
44480
  sync();
@@ -44340,6 +44870,7 @@ var GameVehiclesThree = (() => {
44340
44870
  joints: js.map((j) => [j.def.id, j.hp, j.progress, j.open, j.by ?? null])
44341
44871
  }),
44342
44872
  partName: (pid) => ps.get(pid)?.def.name ?? pid,
44873
+ objectsOf: (pid) => vis?.objectsOf(pid) ?? [],
44343
44874
  status: computeStatus,
44344
44875
  animations: () => createVehicleClips(model, vis, kit, c),
44345
44876
  crumple: (point, direction, depth) => {
@@ -44451,7 +44982,7 @@ var GameVehiclesThree = (() => {
44451
44982
  if (ran > 0 && clock() >= deadline) break;
44452
44983
  const work = tracked[cursor % tracked.length];
44453
44984
  cursor = (cursor + 1) % tracked.length;
44454
- if (work.pendingUnits(lastFrame) > 0 && work.runStep(deadline)) {
44985
+ if (work.pendingUnits(lastFrame) > 0 && work.runStep(deadline, clock)) {
44455
44986
  ran++;
44456
44987
  skipped = 0;
44457
44988
  } else skipped++;
@@ -44592,6 +45123,126 @@ var GameVehiclesThree = (() => {
44592
45123
  leak
44593
45124
  };
44594
45125
  }
45126
+ var cabin_default = {
45127
+ 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)",
45128
+ entryDuckFactor: 0.44,
45129
+ categories: {
45130
+ passenger_car: {
45131
+ frontHeadroomMetres: 0.95,
45132
+ rearHeadroomMetres: 0.9,
45133
+ frontLegroomMetres: 0.62,
45134
+ widthMetres: 0.52,
45135
+ door: { widthMetres: 0.65, heightMetres: 0.8 }
45136
+ },
45137
+ suv_pickup: {
45138
+ frontHeadroomMetres: 0.98,
45139
+ rearHeadroomMetres: 0.93,
45140
+ frontLegroomMetres: 0.64,
45141
+ widthMetres: 0.54,
45142
+ door: { widthMetres: 0.7, heightMetres: 0.82 }
45143
+ },
45144
+ van: {
45145
+ frontHeadroomMetres: 1.05,
45146
+ rearHeadroomMetres: 1.05,
45147
+ frontLegroomMetres: 0.65,
45148
+ widthMetres: 0.54,
45149
+ door: { widthMetres: 0.75, heightMetres: 0.95 }
45150
+ },
45151
+ truck: {
45152
+ frontHeadroomMetres: 1,
45153
+ rearHeadroomMetres: 1,
45154
+ frontLegroomMetres: 0.62,
45155
+ widthMetres: 0.52,
45156
+ door: { widthMetres: 0.65, heightMetres: 0.85 }
45157
+ },
45158
+ bus: {
45159
+ frontHeadroomMetres: 1.2,
45160
+ rearHeadroomMetres: 1.2,
45161
+ frontLegroomMetres: 0.62,
45162
+ widthMetres: 0.5,
45163
+ door: { widthMetres: 0.7, heightMetres: 1.75 }
45164
+ },
45165
+ agricultural: {
45166
+ frontHeadroomMetres: 1.05,
45167
+ rearHeadroomMetres: null,
45168
+ frontLegroomMetres: 0.62,
45169
+ widthMetres: 0.52,
45170
+ door: { widthMetres: 0.65, heightMetres: 0.9 }
45171
+ },
45172
+ military_light: {
45173
+ frontHeadroomMetres: 0.95,
45174
+ rearHeadroomMetres: 0.92,
45175
+ frontLegroomMetres: 0.62,
45176
+ widthMetres: 0.5,
45177
+ door: { widthMetres: 0.6, heightMetres: 0.8 }
45178
+ },
45179
+ military_armored: {
45180
+ frontHeadroomMetres: 0.88,
45181
+ rearHeadroomMetres: 0.88,
45182
+ frontLegroomMetres: 0.58,
45183
+ widthMetres: 0.46,
45184
+ door: { widthMetres: 0.5, heightMetres: 0.55 }
45185
+ },
45186
+ open_vehicle: {
45187
+ frontHeadroomMetres: null,
45188
+ rearHeadroomMetres: null,
45189
+ frontLegroomMetres: null,
45190
+ widthMetres: null,
45191
+ door: null
45192
+ },
45193
+ boat_cabin: {
45194
+ frontHeadroomMetres: 1.05,
45195
+ rearHeadroomMetres: 1.05,
45196
+ frontLegroomMetres: 0.62,
45197
+ widthMetres: 0.52,
45198
+ door: { widthMetres: 0.6, heightMetres: 0.9 }
45199
+ },
45200
+ aircraft_enclosed: {
45201
+ frontHeadroomMetres: 0.95,
45202
+ rearHeadroomMetres: 0.92,
45203
+ frontLegroomMetres: 0.62,
45204
+ widthMetres: 0.48,
45205
+ door: { widthMetres: 0.55, heightMetres: 0.8 }
45206
+ }
45207
+ }
45208
+ };
45209
+ var CABIN_CATEGORIES = [
45210
+ "passenger_car",
45211
+ "suv_pickup",
45212
+ "van",
45213
+ "truck",
45214
+ "bus",
45215
+ "agricultural",
45216
+ "military_light",
45217
+ "military_armored",
45218
+ "open_vehicle",
45219
+ "boat_cabin",
45220
+ "aircraft_enclosed"
45221
+ ];
45222
+ var toClearance = (value) => value === null ? Number.POSITIVE_INFINITY : value;
45223
+ var toCabinMinimum = (category, raw) => {
45224
+ if (category === "open_vehicle") {
45225
+ return {
45226
+ frontHeadroomMetres: Number.POSITIVE_INFINITY,
45227
+ rearHeadroomMetres: Number.POSITIVE_INFINITY,
45228
+ frontLegroomMetres: Number.POSITIVE_INFINITY,
45229
+ widthMetres: Number.POSITIVE_INFINITY,
45230
+ door: void 0
45231
+ };
45232
+ }
45233
+ return {
45234
+ frontHeadroomMetres: toClearance(raw.frontHeadroomMetres),
45235
+ rearHeadroomMetres: raw.rearHeadroomMetres === null ? void 0 : raw.rearHeadroomMetres,
45236
+ frontLegroomMetres: toClearance(raw.frontLegroomMetres),
45237
+ widthMetres: toClearance(raw.widthMetres),
45238
+ door: raw.door === null ? void 0 : { widthMetres: raw.door.widthMetres, heightMetres: raw.door.heightMetres }
45239
+ };
45240
+ };
45241
+ var CABIN_SOURCE = cabin_default.source;
45242
+ var ENTRY_DUCK_FACTOR = cabin_default.entryDuckFactor;
45243
+ var CABIN_MINIMUMS = Object.fromEntries(
45244
+ CABIN_CATEGORIES.map((category) => [category, toCabinMinimum(category, cabin_default.categories[category])])
45245
+ );
44595
45246
 
44596
45247
  // src/cabin-smoke.ts
44597
45248
  function createCabinSmoke() {
@@ -44628,7 +45279,7 @@ var GameVehiclesThree = (() => {
44628
45279
  };
44629
45280
  }
44630
45281
 
44631
- // ../game-audio/dist/chunk-ZFNHDQRV.js
45282
+ // ../game-audio/dist/chunk-ZE4VVIU3.js
44632
45283
  var DISTANCE_CURVES = {
44633
45284
  /** The game's `sfx`: `vol / (1 + d² × 0.004)`, cutoff `/ (1 + d × 0.01)`, silent below 0.01 (jogo L62091–62092, L62101). */
44634
45285
  game_sfx: { model: "inverse_square", k: 4e-3, cutoffK: 0.01, minGain: 0.01 },
@@ -46756,6 +47407,54 @@ var GameVehiclesThree = (() => {
46756
47407
  }
46757
47408
  var BATCHED_LAYER = 30;
46758
47409
  var MATRIX_EPSILON = 1e-6;
47410
+ function createStaticBatchQueue({ id = DEFERRED_QUEUE_ID.STATIC_BATCH } = {}) {
47411
+ const members = [];
47412
+ let cursor = 0;
47413
+ let attached = false;
47414
+ const deferred = {
47415
+ id,
47416
+ pending() {
47417
+ let units = 0;
47418
+ for (const work of members) units += work.pendingUnits();
47419
+ return units;
47420
+ },
47421
+ run(deadline, clock) {
47422
+ let ran = 0;
47423
+ let skipped = 0;
47424
+ while (members.length > 0 && skipped < members.length) {
47425
+ if (ran > 0 && clock() >= deadline) break;
47426
+ const work = members[cursor % members.length];
47427
+ cursor = (cursor + 1) % members.length;
47428
+ if (work.pendingUnits() > 0) {
47429
+ work.runUnit();
47430
+ ran++;
47431
+ skipped = 0;
47432
+ } else skipped++;
47433
+ }
47434
+ return ran;
47435
+ },
47436
+ flush() {
47437
+ for (const work of [...members]) work.finishAll();
47438
+ },
47439
+ attach() {
47440
+ attached = true;
47441
+ },
47442
+ detach() {
47443
+ attached = false;
47444
+ }
47445
+ };
47446
+ return {
47447
+ deferredQueue: () => deferred,
47448
+ isAttached: () => attached,
47449
+ join(work) {
47450
+ members.push(work);
47451
+ return () => {
47452
+ const at = members.indexOf(work);
47453
+ if (at >= 0) members.splice(at, 1);
47454
+ };
47455
+ }
47456
+ };
47457
+ }
46759
47458
  var ATTRIBUTES = ["position", "normal", "uv", "color"];
46760
47459
  var isShown = (object2, root) => {
46761
47460
  for (let node = object2; node; node = node.parent) {
@@ -46770,43 +47469,91 @@ var GameVehiclesThree = (() => {
46770
47469
  const geometry = mesh2.geometry;
46771
47470
  return geometry.attributes.position !== void 0 && Object.keys(geometry.morphAttributes).length === 0;
46772
47471
  };
46773
- var signatureOf = (mesh2, materialKey2) => {
47472
+ var signatureOf = (mesh2, materialKey2, shadowOnly) => {
47473
+ if (shadowOnly) return shadowSideKey(mesh2.material);
46774
47474
  const { attributes } = mesh2.geometry;
46775
47475
  const present = ATTRIBUTES.filter((name) => attributes[name] !== void 0).map((name) => `${name}${attributes[name].itemSize}`);
46776
47476
  return `${materialKey2(mesh2.material)}|${present.join(",")}|${mesh2.castShadow ? 1 : 0}${mesh2.receiveShadow ? 1 : 0}`;
46777
47477
  };
46778
47478
  var uuidOf = (material) => material.uuid;
46779
- var sameMatrix = (a, b) => a.elements.every((value, index) => Math.abs(value - b.elements[index]) < MATRIX_EPSILON);
47479
+ var castsPlainShadow = (mesh2) => {
47480
+ const material = mesh2.material;
47481
+ const custom = mesh2;
47482
+ if (!mesh2.castShadow || !material.visible || custom.customDepthMaterial || custom.customDistanceMaterial) return false;
47483
+ if (material.wireframe === true || (material.clippingPlanes?.length ?? 0) > 0) return false;
47484
+ if (material.displacementMap && material.displacementScale !== 0) return false;
47485
+ return !(material.alphaTest > 0 && (material.map || material.alphaMap));
47486
+ };
47487
+ var shadowSideKey = (material) => `${material.side}|${material.shadowSide ?? ""}`;
47488
+ var sameMatrix = (a, b) => {
47489
+ const left = a.elements;
47490
+ const right = b.elements;
47491
+ for (let at = 0; at < 16; at++) if (Math.abs(left[at] - right[at]) >= MATRIX_EPSILON) return false;
47492
+ return true;
47493
+ };
46780
47494
  function createStaticBatcher(THREE, root, options = {}) {
46781
47495
  const include = options.include ?? (() => true);
46782
- const follow = options.followMeshes === true;
47496
+ const shadowOnly = options.shadowOnly === true;
47497
+ const follow = options.followMeshes === true && !shadowOnly;
46783
47498
  root.updateMatrixWorld(true);
46784
47499
  const inverse = new THREE.Matrix4().copy(root.matrixWorld).invert();
47500
+ const materialKey2 = options.materialKey ?? uuidOf;
46785
47501
  const groups = /* @__PURE__ */ new Map();
46786
47502
  root.traverse((object2) => {
46787
47503
  const mesh2 = object2;
46788
- if (!mesh2.isMesh || !isShown(mesh2, root) || !isBatchable(mesh2) || !include(mesh2)) return;
46789
- const key = signatureOf(mesh2, options.materialKey ?? uuidOf);
46790
- groups.set(key, [...groups.get(key) ?? [], mesh2]);
47504
+ if (!mesh2.isMesh || !isShown(mesh2, root) || !isBatchable(mesh2) || shadowOnly && !castsPlainShadow(mesh2) || !include(mesh2)) return;
47505
+ const key = signatureOf(mesh2, materialKey2, shadowOnly);
47506
+ const waiting = groups.get(key);
47507
+ if (waiting) waiting.push(mesh2);
47508
+ else groups.set(key, [mesh2]);
46791
47509
  });
46792
47510
  const group = new THREE.Group();
46793
47511
  group.name = "static-batches";
46794
47512
  const sources = [];
46795
- const pending = [...groups.values()].filter((meshes) => meshes.length >= 2);
46796
- const mergeSome = (deadline) => {
46797
- while (pending.length > 0) {
46798
- const meshes = pending.shift();
46799
- if (meshes.every((mesh2) => isShown(mesh2, root))) sources.push(...mergeGroup(THREE, { meshes, inverse: new THREE.Matrix4().copy(root.matrixWorld).invert(), group, follow, onBatch: options.onBatch }));
46800
- if (performance.now() >= deadline) return;
47513
+ const maxVertices = options.maxVertices ?? (shadowOnly ? 65535 : Number.POSITIVE_INFINITY);
47514
+ const chunks = (meshes) => {
47515
+ const out = [[]];
47516
+ let vertices = 0;
47517
+ for (const mesh2 of meshes) {
47518
+ const count2 = mesh2.geometry.attributes.position.count;
47519
+ if (vertices + count2 > maxVertices && out[out.length - 1].length > 0) {
47520
+ out.push([]);
47521
+ vertices = 0;
47522
+ }
47523
+ ;
47524
+ out[out.length - 1].push(mesh2);
47525
+ vertices += count2;
46801
47526
  }
47527
+ return out;
46802
47528
  };
46803
- if (options.budgetMs === void 0) mergeSome(Number.POSITIVE_INFINITY);
47529
+ const pending = [...groups.entries()].flatMap(([key, meshes]) => chunks(meshes).map((chunk) => [key, chunk])).filter(([, meshes]) => meshes.length >= 2);
47530
+ const groupedMasks = /* @__PURE__ */ new Map();
47531
+ for (const [, meshes] of pending) for (const mesh2 of meshes) groupedMasks.set(mesh2, mesh2.layers.mask);
47532
+ const isUnchanged = (mesh2, key) => isShown(mesh2, root) && include(mesh2) && isBatchable(mesh2) && (!shadowOnly || castsPlainShadow(mesh2)) && mesh2.layers.mask === groupedMasks.get(mesh2) && signatureOf(mesh2, materialKey2, shadowOnly) === key;
47533
+ const mergeNext = () => {
47534
+ const [key, meshes] = pending.shift();
47535
+ const still = meshes.filter((mesh2) => isUnchanged(mesh2, key));
47536
+ for (const mesh2 of meshes) groupedMasks.delete(mesh2);
47537
+ if (still.length < 2) return;
47538
+ inverse.copy(root.matrixWorld).invert();
47539
+ for (const source of mergeGroup(THREE, { meshes: still, inverse, group, follow, shadowOnly, onBatch: options.onBatch })) sources.push(source);
47540
+ };
47541
+ const queue = options.queue ?? createStaticBatchQueue();
47542
+ const leaveQueue = queue.join({
47543
+ pendingUnits: () => pending.length,
47544
+ runUnit: mergeNext,
47545
+ finishAll() {
47546
+ while (pending.length > 0) mergeNext();
47547
+ }
47548
+ });
47549
+ if (options.budgetMs === void 0 && options.queue === void 0) while (pending.length > 0) mergeNext();
46804
47550
  root.add(group);
46805
47551
  const scratch2 = new THREE.Matrix4();
46806
47552
  let released = 0;
46807
47553
  const release = (source) => {
46808
47554
  source.released = true;
46809
- source.mesh.layers.mask = source.mask;
47555
+ if (shadowOnly) source.mesh.castShadow = source.castShadow;
47556
+ else source.mesh.layers.mask = source.mask;
46810
47557
  const { index } = source.batch;
46811
47558
  const first = index.array[source.start];
46812
47559
  for (let at = source.start; at < source.start + source.count; at++) index.array[at] = first;
@@ -46826,7 +47573,7 @@ var GameVehiclesThree = (() => {
46826
47573
  return {
46827
47574
  group,
46828
47575
  update() {
46829
- if (pending.length > 0) mergeSome(performance.now() + (options.budgetMs ?? Number.POSITIVE_INFINITY));
47576
+ if (pending.length > 0 && !queue.isAttached()) drainDetached(queue.deferredQueue(), options.budgetMs ?? Number.POSITIVE_INFINITY);
46830
47577
  const before = released;
46831
47578
  inverse.copy(root.matrixWorld).invert();
46832
47579
  for (const source of sources) if (!source.released && hasChanged(source)) release(source);
@@ -46834,31 +47581,41 @@ var GameVehiclesThree = (() => {
46834
47581
  },
46835
47582
  stats: () => ({ batches: group.children.length, batched: sources.filter((source) => !source.released).length, released }),
46836
47583
  dispose() {
46837
- for (const source of sources) if (!source.released) source.mesh.layers.mask = source.mask;
47584
+ for (const source of sources) {
47585
+ if (source.released) continue;
47586
+ if (shadowOnly) source.mesh.castShadow = source.castShadow;
47587
+ else source.mesh.layers.mask = source.mask;
47588
+ }
47589
+ leaveQueue();
47590
+ pending.length = 0;
47591
+ groupedMasks.clear();
46838
47592
  group.removeFromParent();
46839
47593
  for (const child of group.children) {
46840
47594
  ;
46841
47595
  child.geometry.dispose();
47596
+ if (shadowOnly) child.material.dispose();
46842
47597
  child.skeleton?.dispose();
46843
47598
  }
46844
47599
  }
46845
47600
  };
46846
47601
  }
46847
- function copyAttribute(name, attribute, target, offset, matrix, normalMatrix2) {
47602
+ var isPlain = (attribute) => !attribute.isInterleavedBufferAttribute && !attribute.normalized;
47603
+ function copyAttribute(name, attribute, target, offset, matrix) {
46848
47604
  const size = attribute.itemSize;
47605
+ const count2 = attribute.count;
46849
47606
  const source = attribute.array;
46850
- const flat = !attribute.isInterleavedBufferAttribute && source.length === attribute.count * size;
47607
+ const plain = isPlain(attribute);
46851
47608
  if (name !== "position" && name !== "normal") {
46852
- if (flat) target.set(source, offset * size);
46853
- else for (let at = 0; at < attribute.count; at++) for (let k = 0; k < size; k++) target[(offset + at) * size + k] = attribute.getComponent(at, k);
47609
+ if (!attribute.isInterleavedBufferAttribute && source.length === count2 * size) target.set(source, offset * size);
47610
+ else for (let at = 0; at < count2; at++) for (let k = 0; k < size; k++) target[(offset + at) * size + k] = attribute.getComponent(at, k);
46854
47611
  return;
46855
47612
  }
46856
- const e = (name === "position" ? matrix : normalMatrix2).elements;
47613
+ const e = matrix.elements;
46857
47614
  const isNormal = name === "normal";
46858
- for (let at = 0; at < attribute.count; at++) {
46859
- const x = attribute.getX(at);
46860
- const y = attribute.getY(at);
46861
- const z = attribute.getZ(at);
47615
+ for (let at = 0; at < count2; at++) {
47616
+ const x = plain ? source[at * size] : attribute.getX(at);
47617
+ const y = plain ? source[at * size + 1] : attribute.getY(at);
47618
+ const z = plain ? source[at * size + 2] : attribute.getZ(at);
46862
47619
  const out = (offset + at) * 3;
46863
47620
  if (isNormal) {
46864
47621
  const nx = e[0] * x + e[3] * y + e[6] * z;
@@ -46894,11 +47651,23 @@ var GameVehiclesThree = (() => {
46894
47651
  mesh2.frustumCulled = false;
46895
47652
  return mesh2;
46896
47653
  }
46897
- function mergeGroup(THREE, { meshes, inverse: rootInverse, group, follow, onBatch }) {
47654
+ function shadowBatch(THREE, merged, like) {
47655
+ const material = new THREE.MeshBasicMaterial({ colorWrite: false, depthWrite: false, side: like.side });
47656
+ material.shadowSide = like.shadowSide;
47657
+ material.name = "shadow-batch";
47658
+ const mesh2 = new THREE.Mesh(merged, material);
47659
+ merged.setDrawRange(0, -1);
47660
+ mesh2.onBeforeShadow = () => merged.setDrawRange(0, Number.POSITIVE_INFINITY);
47661
+ mesh2.onAfterShadow = () => merged.setDrawRange(0, -1);
47662
+ mesh2.castShadow = true;
47663
+ mesh2.receiveShadow = false;
47664
+ return mesh2;
47665
+ }
47666
+ function mergeGroup(THREE, { meshes, inverse: rootInverse, group, follow, shadowOnly, onBatch }) {
46898
47667
  const identity = new THREE.Matrix4();
46899
47668
  const inverse = follow ? identity : rootInverse;
46900
47669
  const first = meshes[0];
46901
- const names = ATTRIBUTES.filter((name) => first.geometry.attributes[name] !== void 0);
47670
+ const names = shadowOnly ? ["position"] : ATTRIBUTES.filter((name) => first.geometry.attributes[name] !== void 0);
46902
47671
  const pieces = meshes.map((mesh22) => {
46903
47672
  const local = new THREE.Matrix4().multiplyMatrices(inverse, mesh22.matrixWorld);
46904
47673
  const vertices = mesh22.geometry.attributes.position.count;
@@ -46908,14 +47677,14 @@ var GameVehiclesThree = (() => {
46908
47677
  const totalVertices = pieces.reduce((sum, piece) => sum + piece.vertices, 0);
46909
47678
  const totalIndices = pieces.reduce((sum, piece) => sum + piece.indexCount, 0);
46910
47679
  const merged = new THREE.BufferGeometry();
46911
- const normalMatrix2 = new THREE.Matrix3();
47680
+ const normalMatrices = names.includes("normal") ? pieces.map((piece) => new THREE.Matrix3().getNormalMatrix(follow ? identity : piece.local)) : [];
46912
47681
  for (const name of names) {
46913
47682
  const size = first.geometry.attributes[name].itemSize;
46914
47683
  const array = new Float32Array(totalVertices * size);
46915
47684
  let offset = 0;
46916
- for (const piece of pieces) {
46917
- const matrix = follow ? identity : piece.local;
46918
- copyAttribute(name, piece.mesh.geometry.attributes[name], array, offset, matrix, normalMatrix2.getNormalMatrix(matrix));
47685
+ for (const [at, piece] of pieces.entries()) {
47686
+ const matrix = name === "normal" ? normalMatrices[at] : follow ? identity : piece.local;
47687
+ copyAttribute(name, piece.mesh.geometry.attributes[name], array, offset, matrix);
46919
47688
  offset += piece.vertices;
46920
47689
  }
46921
47690
  merged.setAttribute(name, new THREE.BufferAttribute(array, size));
@@ -46923,10 +47692,12 @@ var GameVehiclesThree = (() => {
46923
47692
  const indexArray2 = totalVertices > 65535 ? new Uint32Array(totalIndices) : new Uint16Array(totalIndices);
46924
47693
  const indexAttribute = new THREE.BufferAttribute(indexArray2, 1);
46925
47694
  merged.setIndex(indexAttribute);
46926
- const mesh2 = follow ? skinnedBatch(THREE, merged, first.material, meshes) : new THREE.Mesh(merged, first.material);
46927
- mesh2.name = `batch:${first.material.name || first.material.type}`;
46928
- mesh2.castShadow = first.castShadow;
46929
- mesh2.receiveShadow = first.receiveShadow;
47695
+ const mesh2 = shadowOnly ? shadowBatch(THREE, merged, first.material) : follow ? skinnedBatch(THREE, merged, first.material, meshes) : new THREE.Mesh(merged, first.material);
47696
+ mesh2.name = shadowOnly ? `shadow-batch:${shadowSideKey(first.material)}` : `batch:${first.material.name || first.material.type}`;
47697
+ if (!shadowOnly) {
47698
+ mesh2.castShadow = first.castShadow;
47699
+ mesh2.receiveShadow = first.receiveShadow;
47700
+ }
46930
47701
  mesh2.raycast = () => void 0;
46931
47702
  merged.computeBoundingBox();
46932
47703
  merged.computeBoundingSphere();
@@ -46938,8 +47709,10 @@ var GameVehiclesThree = (() => {
46938
47709
  let indexOffset = 0;
46939
47710
  for (const piece of pieces) {
46940
47711
  const index = piece.mesh.geometry.index;
46941
- if (index) for (let at = 0; at < piece.indexCount; at++) indexArray2[indexOffset + at] = index.getX(at) + vertexOffset;
46942
- else for (let at = 0; at < piece.indexCount; at++) indexArray2[indexOffset + at] = at + vertexOffset;
47712
+ if (index) {
47713
+ const indices = index.array;
47714
+ for (let at = 0; at < piece.indexCount; at++) indexArray2[indexOffset + at] = indices[at] + vertexOffset;
47715
+ } else for (let at = 0; at < piece.indexCount; at++) indexArray2[indexOffset + at] = at + vertexOffset;
46943
47716
  sources.push({
46944
47717
  mesh: piece.mesh,
46945
47718
  geometry: piece.mesh.geometry,
@@ -46948,12 +47721,14 @@ var GameVehiclesThree = (() => {
46948
47721
  local: piece.local,
46949
47722
  world: piece.mesh.matrixWorld.clone(),
46950
47723
  mask: piece.mesh.layers.mask,
47724
+ castShadow: piece.mesh.castShadow,
46951
47725
  batch,
46952
47726
  start: indexOffset,
46953
47727
  count: piece.indexCount,
46954
47728
  released: false
46955
47729
  });
46956
- piece.mesh.layers.set(BATCHED_LAYER);
47730
+ if (shadowOnly) piece.mesh.castShadow = false;
47731
+ else piece.mesh.layers.set(BATCHED_LAYER);
46957
47732
  vertexOffset += piece.vertices;
46958
47733
  indexOffset += piece.indexCount;
46959
47734
  }
@@ -47999,10 +48774,357 @@ var GameVehiclesThree = (() => {
47999
48774
  };
48000
48775
  }
48001
48776
 
48777
+ // src/collider-fit.ts
48778
+ var FIT = 0.01;
48779
+ var MIN_HALF2 = 5e-3;
48780
+ var COARSEN_ABOVE = 60;
48781
+ var COARSE_CELL = 8e-3;
48782
+ var COARSE_MIN_TRIANGLES = 12;
48783
+ var IDENTITY_AXES = [1, 0, 0, 0, 1, 0, 0, 0, 1];
48784
+ var CELL_BIAS = 4096;
48785
+ var CELL_SPAN = 8192;
48786
+ var soupOf = () => ({ vertices: [], indices: [], placed: /* @__PURE__ */ new Map() });
48787
+ var addTriangle = (soup, source, positions, corners, matrix) => {
48788
+ let placed = soup.placed.get(source);
48789
+ if (!placed) soup.placed.set(source, placed = /* @__PURE__ */ new Map());
48790
+ for (const corner of corners) {
48791
+ let at = placed.get(corner);
48792
+ if (at === void 0) {
48793
+ const x = positions[corner * 3], y = positions[corner * 3 + 1], z = positions[corner * 3 + 2];
48794
+ at = soup.vertices.length / 3;
48795
+ placed.set(corner, at);
48796
+ soup.vertices.push(
48797
+ matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12],
48798
+ matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13],
48799
+ matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14]
48800
+ );
48801
+ }
48802
+ soup.indices.push(at);
48803
+ }
48804
+ };
48805
+ var cellKey = (x, y, z, cell) => ((Math.floor(x / cell) + CELL_BIAS) * CELL_SPAN + (Math.floor(y / cell) + CELL_BIAS)) * CELL_SPAN + (Math.floor(z / cell) + CELL_BIAS);
48806
+ var coarsen = (soup) => {
48807
+ const count2 = soup.vertices.length / 3;
48808
+ const cells = /* @__PURE__ */ new Map();
48809
+ const sums = [];
48810
+ const counts = [];
48811
+ const to = new Uint32Array(count2);
48812
+ for (let i = 0; i < count2; i++) {
48813
+ const x = soup.vertices[i * 3], y = soup.vertices[i * 3 + 1], z = soup.vertices[i * 3 + 2];
48814
+ const key = cellKey(x, y, z, COARSE_CELL);
48815
+ let at = cells.get(key);
48816
+ if (at === void 0) {
48817
+ at = counts.length;
48818
+ cells.set(key, at);
48819
+ counts.push(0);
48820
+ sums.push(0, 0, 0);
48821
+ }
48822
+ to[i] = at;
48823
+ counts[at] = counts[at] + 1;
48824
+ sums[at * 3] = sums[at * 3] + x;
48825
+ sums[at * 3 + 1] = sums[at * 3 + 1] + y;
48826
+ sums[at * 3 + 2] = sums[at * 3 + 2] + z;
48827
+ }
48828
+ const best = new Float64Array(counts.length).fill(Infinity);
48829
+ const vertices = new Array(counts.length * 3).fill(0);
48830
+ for (let i = 0; i < count2; i++) {
48831
+ const at = to[i];
48832
+ const n = counts[at];
48833
+ const x = soup.vertices[i * 3], y = soup.vertices[i * 3 + 1], z = soup.vertices[i * 3 + 2];
48834
+ const d = (x - sums[at * 3] / n) ** 2 + (y - sums[at * 3 + 1] / n) ** 2 + (z - sums[at * 3 + 2] / n) ** 2;
48835
+ if (d >= best[at]) continue;
48836
+ best[at] = d;
48837
+ vertices[at * 3] = x;
48838
+ vertices[at * 3 + 1] = y;
48839
+ vertices[at * 3 + 2] = z;
48840
+ }
48841
+ const indices = [];
48842
+ const seen = /* @__PURE__ */ new Set();
48843
+ const stride = counts.length;
48844
+ for (let i = 0; i + 2 < soup.indices.length; i += 3) {
48845
+ const a = to[soup.indices[i]], b = to[soup.indices[i + 1]], c = to[soup.indices[i + 2]];
48846
+ if (a === b || b === c || a === c) continue;
48847
+ const lo = Math.min(a, b, c), hi = Math.max(a, b, c);
48848
+ const key = (lo * stride + (a + b + c - lo - hi)) * stride + hi;
48849
+ if (seen.has(key)) continue;
48850
+ seen.add(key);
48851
+ indices.push(a, b, c);
48852
+ }
48853
+ return { vertices, indices, placed: /* @__PURE__ */ new Map() };
48854
+ };
48855
+ var axesOf = ([x, y, z, w]) => [
48856
+ 1 - 2 * (y * y + z * z),
48857
+ 2 * (x * y + z * w),
48858
+ 2 * (x * z - y * w),
48859
+ 2 * (x * y - z * w),
48860
+ 1 - 2 * (x * x + z * z),
48861
+ 2 * (y * z + x * w),
48862
+ 2 * (x * z + y * w),
48863
+ 2 * (y * z - x * w),
48864
+ 1 - 2 * (x * x + y * y)
48865
+ ];
48866
+ var tightened = (points, box2) => {
48867
+ const axes = axesOf(box2.rotation);
48868
+ const low = [Infinity, Infinity, Infinity];
48869
+ const high = [-Infinity, -Infinity, -Infinity];
48870
+ for (let i = 0; i < points.length; i += 3) {
48871
+ for (let k = 0; k < 3; k++) {
48872
+ const t = points[i] * axes[k * 3] + points[i + 1] * axes[k * 3 + 1] + points[i + 2] * axes[k * 3 + 2];
48873
+ if (t < low[k]) low[k] = t;
48874
+ if (t > high[k]) high[k] = t;
48875
+ }
48876
+ }
48877
+ const mid = [0, 1, 2].map((k) => (low[k] + high[k]) / 2);
48878
+ const center = [0, 1, 2].map((k) => mid[0] * axes[k] + mid[1] * axes[3 + k] + mid[2] * axes[6 + k]);
48879
+ const half = [0, 1, 2].map((k) => Math.max(MIN_HALF2, (high[k] - low[k]) / 2));
48880
+ return { center, half, rotation: box2.rotation };
48881
+ };
48882
+ var isOneBox = (soup) => fitOrientedBoxes(soup.vertices, soup.indices).length <= 1;
48883
+ var colliderOf = (id, key, soup) => {
48884
+ const points = soup.vertices;
48885
+ if (points.length < 9) return null;
48886
+ const low = [Infinity, Infinity, Infinity];
48887
+ const high = [-Infinity, -Infinity, -Infinity];
48888
+ for (let i = 0; i < points.length; i += 3) {
48889
+ for (let k = 0; k < 3; k++) {
48890
+ const v = points[i + k];
48891
+ if (v < low[k]) low[k] = v;
48892
+ if (v > high[k]) high[k] = v;
48893
+ }
48894
+ }
48895
+ const center = [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2];
48896
+ const half = [(high[0] - low[0]) / 2, (high[1] - low[1]) / 2, (high[2] - low[2]) / 2];
48897
+ const held = half.map((h) => Math.max(MIN_HALF2, h));
48898
+ let oneBox;
48899
+ const isHeldByOneBox = () => oneBox ?? (oneBox = isOneBox(soup));
48900
+ if (hugs(points, { center, half, axes: IDENTITY_AXES, tolerance: [FIT, FIT, FIT] }) && isHeldByOneBox()) return { id, key, center, half: held, rotation: [0, 0, 0, 1] };
48901
+ const turned = fitOrientedBox(points);
48902
+ if (turned && hugs(points, { center: turned.center, half: turned.half, axes: axesOf(turned.rotation), tolerance: [FIT, FIT, FIT] }) && isHeldByOneBox()) return { id, key, ...tightened(points, turned) };
48903
+ const coarse = soup.indices.length / 3 > COARSEN_ABOVE ? coarsen(soup) : soup;
48904
+ const kept = coarse.indices.length >= COARSE_MIN_TRIANGLES * 3 ? coarse : soup;
48905
+ return { id, key, center, half: held, rotation: [0, 0, 0, 1], mesh: { vertices: new Float32Array(kept.vertices), indices: new Uint32Array(kept.indices) } };
48906
+ };
48907
+
48908
+ // src/colliders.ts
48909
+ var SHELL_ROLES2 = /* @__PURE__ */ new Set(["panel", "fender", "roof", "frame", "glass", "pillar", "door", "lid", "hood", "bumper"]);
48910
+ var GONE2 = /* @__PURE__ */ new Set(["broken", "melted", "ashes"]);
48911
+ var MIN_AREA = 1e-9;
48912
+ var CHUNK = 0.8;
48913
+ var CELL_BIAS2 = 512;
48914
+ var CELL_SPAN2 = 1024;
48915
+ var PART_SPAN = 2 ** 30;
48916
+ var DEFAULT_BUDGET = Infinity;
48917
+ var isDrawn = (mesh2, stop) => {
48918
+ if (!mesh2.isMesh || !mesh2.geometry || mesh2.userData.ghost || mesh2.userData.helper) return false;
48919
+ if (!mesh2.geometry.getAttribute("position")) return false;
48920
+ for (let node = mesh2; node; node = node.parent) {
48921
+ if (node.visible === false || node.userData.noSurfaceRay) return false;
48922
+ if (node === stop) break;
48923
+ }
48924
+ return true;
48925
+ };
48926
+ var shellPartAt = (shell, hub, x, y, z) => {
48927
+ let best = hub;
48928
+ let bestVolume = Infinity;
48929
+ for (const part of shell) {
48930
+ const { center, size } = part.box;
48931
+ if (Math.abs(x - center[0]) > size[0] / 2 || Math.abs(y - center[1]) > size[1] / 2 || Math.abs(z - center[2]) > size[2] / 2) continue;
48932
+ const volume = size[0] * size[1] * size[2];
48933
+ if (volume < bestVolume) [best, bestVolume] = [part.id, volume];
48934
+ }
48935
+ return best;
48936
+ };
48937
+ var isNotDrawn = (positions, [a, b, c]) => {
48938
+ const ux = positions[b * 3] - positions[a * 3], uy = positions[b * 3 + 1] - positions[a * 3 + 1], uz = positions[b * 3 + 2] - positions[a * 3 + 2];
48939
+ const wx = positions[c * 3] - positions[a * 3], wy = positions[c * 3 + 1] - positions[a * 3 + 1], wz = positions[c * 3 + 2] - positions[a * 3 + 2];
48940
+ const area3 = Math.hypot(uy * wz - uz * wy, uz * wx - ux * wz, ux * wy - uy * wx);
48941
+ return !(area3 > MIN_AREA);
48942
+ };
48943
+ var sameMatrix2 = (a, b) => {
48944
+ for (let i = 0; i < 16; i++) if (a[i] !== b[i]) return false;
48945
+ return true;
48946
+ };
48947
+ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
48948
+ const entries2 = /* @__PURE__ */ new Map();
48949
+ const pieces = /* @__PURE__ */ new Map();
48950
+ const partIndex = new Map(vehicle.model.parts.map((part, index) => [part.id, index]));
48951
+ const isShown3 = new Map(vehicle.model.parts.map((part) => [part.id, part.visual]));
48952
+ const shell = vehicle.model.parts.filter((part) => SHELL_ROLES2.has(part.role));
48953
+ const toFrame = new THREE.Matrix4();
48954
+ const toVehicle = new THREE.Matrix4();
48955
+ const toShell = new THREE.Matrix4();
48956
+ const placed = new THREE.Vector3();
48957
+ const matrix = new THREE.Matrix4();
48958
+ let pending = false;
48959
+ const release = (entry) => {
48960
+ for (const key of entry.chunks.keys()) {
48961
+ const piece = pieces.get(key);
48962
+ if (!piece) continue;
48963
+ piece.entries.delete(entry);
48964
+ piece.dirty = true;
48965
+ }
48966
+ };
48967
+ const touch = (entry, only) => {
48968
+ for (const key of entry.chunks.keys()) if (!only || only.has(key)) {
48969
+ const piece = pieces.get(key);
48970
+ if (piece) piece.dirty = true;
48971
+ }
48972
+ };
48973
+ const assign = (mesh2, entry, budget) => {
48974
+ toShell.multiplyMatrices(toVehicle, mesh2.matrixWorld);
48975
+ const positions = entry.positions;
48976
+ const index = entry.indexArray;
48977
+ const owner = entry.owner;
48978
+ const e = toShell.elements;
48979
+ for (; entry.assigned < entry.triangles && budget.left > 0; entry.assigned++, budget.left--) {
48980
+ const t = entry.assigned * 3;
48981
+ const a = index ? index[t] : t, b = index ? index[t + 1] : t + 1, c = index ? index[t + 2] : t + 2;
48982
+ placed.set(
48983
+ (positions[a * 3] + positions[b * 3] + positions[c * 3]) / 3,
48984
+ (positions[a * 3 + 1] + positions[b * 3 + 1] + positions[c * 3 + 1]) / 3,
48985
+ (positions[a * 3 + 2] + positions[b * 3 + 2] + positions[c * 3 + 2]) / 3
48986
+ );
48987
+ const x = e[0] * placed.x + e[4] * placed.y + e[8] * placed.z + e[12];
48988
+ const y = e[1] * placed.x + e[5] * placed.y + e[9] * placed.z + e[13];
48989
+ const z = e[2] * placed.x + e[6] * placed.y + e[10] * placed.z + e[14];
48990
+ const part = owner ?? shellPartAt(shell, vehicle.model.hub, x, y, z);
48991
+ const cell = ((Math.floor(x / CHUNK) + CELL_BIAS2) * CELL_SPAN2 + (Math.floor(y / CHUNK) + CELL_BIAS2)) * CELL_SPAN2 + (Math.floor(z / CHUNK) + CELL_BIAS2);
48992
+ entry.pieceOf[entry.assigned] = (partIndex.get(part) ?? 0) * PART_SPAN + cell;
48993
+ }
48994
+ if (entry.assigned < entry.triangles) return false;
48995
+ for (let t = 0; t < entry.triangles; t++) {
48996
+ const key = entry.pieceOf[t];
48997
+ let list2 = entry.chunks.get(key);
48998
+ if (!list2) entry.chunks.set(key, list2 = []);
48999
+ list2.push(t);
49000
+ }
49001
+ for (const key of entry.chunks.keys()) {
49002
+ let piece = pieces.get(key);
49003
+ if (!piece) {
49004
+ const part = vehicle.model.parts[Math.floor(key / PART_SPAN)].id;
49005
+ pieces.set(key, piece = { key, part, entries: /* @__PURE__ */ new Set(), dirty: true, collider: null });
49006
+ }
49007
+ piece.entries.add(entry);
49008
+ piece.dirty = true;
49009
+ }
49010
+ entry.snapshot = new Float32Array(positions);
49011
+ return true;
49012
+ };
49013
+ const follow = (entry, position) => {
49014
+ const array = entry.positions;
49015
+ const moved = /* @__PURE__ */ new Set();
49016
+ const changed = new Uint8Array(array.length / 3);
49017
+ for (let i = 0; i < array.length; i++) {
49018
+ if (array[i] === entry.snapshot[i]) continue;
49019
+ changed[Math.floor(i / 3)] = 1;
49020
+ entry.snapshot[i] = array[i];
49021
+ }
49022
+ const index = entry.indexArray;
49023
+ for (let t = 0; t < entry.triangles; t++) {
49024
+ const a = index ? index[t * 3] : t * 3, b = index ? index[t * 3 + 1] : t * 3 + 1, c = index ? index[t * 3 + 2] : t * 3 + 2;
49025
+ if (changed[a] || changed[b] || changed[c]) moved.add(entry.pieceOf[t]);
49026
+ }
49027
+ entry.version = position.version;
49028
+ touch(entry, moved);
49029
+ };
49030
+ const read = (mesh2, owner, budget) => {
49031
+ const geometry = mesh2.geometry;
49032
+ const position = geometry.getAttribute("position");
49033
+ const indexAttribute = geometry.getIndex();
49034
+ const triangles = Math.floor((indexAttribute ? indexAttribute.count : position.count) / 3);
49035
+ matrix.multiplyMatrices(toFrame, mesh2.matrixWorld);
49036
+ let entry = entries2.get(mesh2);
49037
+ if (entry && (entry.geometry !== geometry || entry.owner !== owner || entry.positions !== position.array || entry.indexArray !== indexAttribute?.array || entry.triangles !== triangles)) {
49038
+ release(entry);
49039
+ entries2.delete(mesh2);
49040
+ entry = void 0;
49041
+ }
49042
+ if (!entry) {
49043
+ entry = { geometry, owner, positions: position.array, indexArray: indexAttribute?.array, triangles, matrix: [...matrix.elements], version: position.version, snapshot: new Float32Array(0), pieceOf: new Float64Array(triangles), assigned: 0, chunks: /* @__PURE__ */ new Map() };
49044
+ entries2.set(mesh2, entry);
49045
+ }
49046
+ if (entry.assigned < entry.triangles) {
49047
+ if (!assign(mesh2, entry, budget)) pending = true;
49048
+ return;
49049
+ }
49050
+ if (!sameMatrix2(entry.matrix, matrix.elements)) {
49051
+ entry.matrix = [...matrix.elements];
49052
+ touch(entry);
49053
+ }
49054
+ if (position.version !== entry.version) follow(entry, position);
49055
+ };
49056
+ const rebuild = (piece, budget) => {
49057
+ const soup = soupOf();
49058
+ for (const entry of piece.entries) {
49059
+ for (const t of entry.chunks.get(piece.key) ?? []) {
49060
+ const index = entry.indexArray;
49061
+ budget.left--;
49062
+ const corners = index ? [index[t * 3], index[t * 3 + 1], index[t * 3 + 2]] : [t * 3, t * 3 + 1, t * 3 + 2];
49063
+ if (isNotDrawn(entry.positions, corners)) continue;
49064
+ addTriangle(soup, entry, entry.positions, corners, entry.matrix);
49065
+ }
49066
+ }
49067
+ piece.collider = colliderOf(piece.part, `${piece.part}#${piece.key % PART_SPAN}`, soup);
49068
+ piece.dirty = false;
49069
+ };
49070
+ const make2 = () => {
49071
+ const root = vehicle.vehicle.vehicle;
49072
+ frame.updateWorldMatrix(true, true);
49073
+ root.updateWorldMatrix(true, true);
49074
+ toFrame.copy(frame.matrixWorld).invert();
49075
+ toVehicle.copy(root.matrixWorld).invert();
49076
+ const state = new Map(vehicle.state().parts.map((part) => [part.id, part]));
49077
+ const isGone = (id) => {
49078
+ const part = state.get(id);
49079
+ return part !== void 0 && (GONE2.has(part.status) || part.group !== 0);
49080
+ };
49081
+ const budget = { left: options.budget ?? DEFAULT_BUDGET };
49082
+ pending = false;
49083
+ const live = /* @__PURE__ */ new Map();
49084
+ const claimed = /* @__PURE__ */ new Set();
49085
+ for (const part of vehicle.model.parts) {
49086
+ for (const object2 of vehicle.objectsOf(part.id)) {
49087
+ object2.traverse((node) => {
49088
+ const mesh2 = node;
49089
+ if (claimed.has(mesh2)) return;
49090
+ claimed.add(mesh2);
49091
+ if (!isGone(part.id) && isDrawn(mesh2, root)) live.set(mesh2, part.id);
49092
+ });
49093
+ }
49094
+ }
49095
+ root.traverse((node) => {
49096
+ const mesh2 = node;
49097
+ if (!claimed.has(mesh2) && isDrawn(mesh2, root)) live.set(mesh2, null);
49098
+ });
49099
+ for (const [mesh2, entry] of entries2) {
49100
+ if (live.has(mesh2)) continue;
49101
+ release(entry);
49102
+ entries2.delete(mesh2);
49103
+ }
49104
+ for (const [mesh2, owner] of live) read(mesh2, owner, budget);
49105
+ const out = [];
49106
+ for (const [key, piece] of pieces) {
49107
+ if (piece.entries.size === 0) {
49108
+ pieces.delete(key);
49109
+ continue;
49110
+ }
49111
+ if (piece.dirty) {
49112
+ if (budget.left <= 0) pending = true;
49113
+ else rebuild(piece, budget);
49114
+ }
49115
+ if (piece.collider && !(isGone(piece.part) && isShown3.get(piece.part))) out.push(piece.collider);
49116
+ }
49117
+ return out;
49118
+ };
49119
+ return { pieces: make2, isPending: () => pending };
49120
+ };
49121
+ var vehicleColliders = (THREE, vehicle, frame) => createVehicleColliders(THREE, vehicle, frame).pieces();
49122
+
48002
49123
  // src/vehicle-lod.ts
48003
49124
  var VEHICLE_LOD_DISTANCE = 14;
48004
- var BATCH_BUDGET_MS = 2;
49125
+ var HIT_BATCH_VERTICES = 16384;
48005
49126
  var VEHICLE_REBATCH_AFTER_MS = 1500;
49127
+ var createVehicleLodQueue = () => createStaticBatchQueue({ id: DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH });
48006
49128
  var isShown2 = (object2, top) => {
48007
49129
  for (let node = object2; node && node !== top; node = node.parent) if (node.visible === false) return false;
48008
49130
  return true;
@@ -48010,7 +49132,9 @@ var GameVehiclesThree = (() => {
48010
49132
  function createVehicleLod(kit, context, root, full, options = {}) {
48011
49133
  const THREE = kit.THREE;
48012
49134
  const now = options.now ?? (() => performance.now());
49135
+ const queue = options.queue ?? createVehicleLodQueue();
48013
49136
  let changedAt = Number.NEGATIVE_INFINITY;
49137
+ let isRestless = false;
48014
49138
  let isUploaded = false;
48015
49139
  let modelKey = "";
48016
49140
  const culled = /* @__PURE__ */ new Map();
@@ -48043,6 +49167,9 @@ var GameVehiclesThree = (() => {
48043
49167
  let isFused = false;
48044
49168
  let isLocked = false;
48045
49169
  let batcher = null;
49170
+ const rejoined = [];
49171
+ let givenBack = 0;
49172
+ let offered = 0;
48046
49173
  let shadow = null;
48047
49174
  const castsShadow = /* @__PURE__ */ new Set();
48048
49175
  const shadowProxyOf = (fused) => {
@@ -48072,15 +49199,27 @@ var GameVehiclesThree = (() => {
48072
49199
  root.add(proxy);
48073
49200
  return proxy;
48074
49201
  };
49202
+ const lockedBatcher = (include) => {
49203
+ const made = createStaticBatcher(THREE, full, { queue, budgetMs: 2, maxVertices: HIT_BATCH_VERTICES, ...include ? { include } : {} });
49204
+ made.group.traverse((object2) => object2.userData.skipLite = true);
49205
+ made.group.userData.noSurfaceRay = true;
49206
+ markKitOrigin(made.group, { owner: "game-vehicles-three", kind: "vehicle", id: root.name });
49207
+ return made;
49208
+ };
48075
49209
  const batchLocked = () => {
48076
- batcher = createStaticBatcher(THREE, full, { budgetMs: BATCH_BUDGET_MS });
48077
- batcher.group.traverse((object2) => object2.userData.skipLite = true);
48078
- batcher.group.userData.noSurfaceRay = true;
48079
- markKitOrigin(batcher.group, { owner: "game-vehicles-three", kind: "vehicle", id: root.name });
49210
+ batcher = lockedBatcher();
49211
+ };
49212
+ const isOnItsOwn = (mesh2) => mesh2.layers.mask !== 1 << BATCHED_LAYER && mesh2.parent?.name !== "static-batches";
49213
+ const disposeRejoined = () => {
49214
+ for (const made of rejoined) made.dispose();
49215
+ rejoined.length = 0;
48080
49216
  };
48081
49217
  const drawFull = () => {
48082
49218
  if (!batcher && isLocked) {
48083
- if (now() - changedAt >= VEHICLE_REBATCH_AFTER_MS) batchLocked();
49219
+ if (!isRestless || now() - changedAt >= VEHICLE_REBATCH_AFTER_MS) {
49220
+ isRestless = false;
49221
+ batchLocked();
49222
+ }
48084
49223
  return;
48085
49224
  }
48086
49225
  if (!batcher) {
@@ -48094,17 +49233,28 @@ var GameVehiclesThree = (() => {
48094
49233
  castsShadow.add(object2);
48095
49234
  object2.castShadow = false;
48096
49235
  });
48097
- batcher = createStaticBatcher(THREE, full, { budgetMs: BATCH_BUDGET_MS });
49236
+ batcher = createStaticBatcher(THREE, full, { queue, budgetMs: 2 });
48098
49237
  batcher.group.traverse((object2) => object2.userData.skipLite = true);
48099
49238
  batcher.group.userData.noSurfaceRay = true;
48100
49239
  markKitOrigin(batcher.group, { owner: "game-vehicles-three", kind: "vehicle", id: root.name });
48101
49240
  return;
48102
49241
  }
48103
49242
  if (!batcher) return;
48104
- if (batcher.update() > 0) changedAt = now();
48105
- if (batcher.stats().batched === 0 && batcher.stats().released > 0) {
49243
+ let changed = batcher.update();
49244
+ for (const made of rejoined) changed += made.update();
49245
+ givenBack += changed;
49246
+ if (changed > 0) changedAt = now();
49247
+ const { batched, released } = batcher.stats();
49248
+ const rejoinedBatched = rejoined.reduce((sum, made) => sum + made.stats().batched, 0);
49249
+ if (batched === 0 && released > 0 && rejoinedBatched === 0) {
48106
49250
  batcher.dispose();
48107
49251
  batcher = null;
49252
+ disposeRejoined();
49253
+ givenBack = offered = 0;
49254
+ isRestless = true;
49255
+ } else if (isLocked && givenBack - offered >= 2 && now() - changedAt >= VEHICLE_REBATCH_AFTER_MS) {
49256
+ offered = givenBack;
49257
+ rejoined.push(lockedBatcher(isOnItsOwn));
48108
49258
  }
48109
49259
  };
48110
49260
  const build = () => {
@@ -48148,6 +49298,7 @@ var GameVehiclesThree = (() => {
48148
49298
  isLocked || (isLocked = touched);
48149
49299
  if (keyOf() !== modelKey) {
48150
49300
  changedAt = now();
49301
+ isRestless = true;
48151
49302
  api.dispose();
48152
49303
  armUpload();
48153
49304
  }
@@ -48168,6 +49319,8 @@ var GameVehiclesThree = (() => {
48168
49319
  show(false);
48169
49320
  batcher?.dispose();
48170
49321
  batcher = null;
49322
+ disposeRejoined();
49323
+ givenBack = offered = 0;
48171
49324
  for (const mesh2 of castsShadow) mesh2.castShadow = true;
48172
49325
  castsShadow.clear();
48173
49326
  shadow?.removeFromParent();
@@ -48621,7 +49774,7 @@ var GameVehiclesThree = (() => {
48621
49774
 
48622
49775
  // src/test-area/types.ts
48623
49776
  var defaultEffectIds = {
48624
- ignite: "vehicle_fire",
49777
+ ignite: "volumetric_fire",
48625
49778
  explode: "car_fuel_tank",
48626
49779
  glass: "glass_burst",
48627
49780
  sparks: "impact_metal",
@@ -48640,7 +49793,9 @@ var GameVehiclesThree = (() => {
48640
49793
  var DEFAULT_TEST_VEHICLES = ["compact_hatch", "midsize_sedan", "midsize_pickup", "sport_bike", "box_truck", "city_bus", "battle_tank", "attack_helicopter"];
48641
49794
  var ITEM_OF = { compact_hatch: "hatch", midsize_sedan: "sedan", midsize_pickup: "pickup", sport_bike: "sport_bike", box_truck: "box_truck", city_bus: "city_bus", battle_tank: "battle_tank", attack_helicopter: "attack_helicopter" };
48642
49795
  var itemId = (key) => ITEM_OF[key] ?? key;
49796
+ var COLLIDER_BUDGET = 25e3;
48643
49797
  var LANE = { z: 11, from: -12, wall: 13 };
49798
+ var CRASH_WALL = { length: 6, height: 2, thickness: 0.15 };
48644
49799
  var SPARK_EVERY_S = 0.08;
48645
49800
  var TYRE_DAMAGE = /* @__PURE__ */ new Set(["flat_tyre", "torn_tyre", "run_flat"]);
48646
49801
  var LEAF_REST_RADIANS = 0.02;
@@ -48732,6 +49887,9 @@ var GameVehiclesThree = (() => {
48732
49887
  const kit = r.userData.kit;
48733
49888
  const d = createVehicleDestructible(kit, r.userData.vehicle, { id, frame: root, name: text.items[itemKey] ?? key, creaseQueue });
48734
49889
  tapEffects(d);
49890
+ const colliders = createVehicleColliders(kit.THREE, d, root, { budget: COLLIDER_BUDGET });
49891
+ d.colliders = colliders.pieces;
49892
+ d.collidersPending = colliders.isPending;
48735
49893
  const setPartPose = d.setPartPose?.bind(d);
48736
49894
  {
48737
49895
  const rests = new Map(d.describe().parts.map((part) => [part.id, part.rotation ?? [0, 0, 0]]));
@@ -48887,7 +50045,10 @@ var GameVehiclesThree = (() => {
48887
50045
  stopEngine();
48888
50046
  if (!lane) return;
48889
50047
  lane.group.parent?.remove(lane.group);
48890
- lane.wall.parent?.remove(lane.wall);
50048
+ if (lane.wall) {
50049
+ lane.wall.parent?.remove(lane.wall);
50050
+ discardObject3D(lane.wall);
50051
+ }
48891
50052
  lane = null;
48892
50053
  };
48893
50054
  const startLane = () => {
@@ -48896,10 +50057,14 @@ var GameVehiclesThree = (() => {
48896
50057
  const kit = kitFor(three);
48897
50058
  const vehicles = createVehiclesThree(three, { kit, fleet });
48898
50059
  const built2 = vehicles.build("compact_hatch", { quality: settings.damage === "none" ? "lite" : "high", seed: settings.seed });
48899
- const wall = new three.Mesh(new three.BoxGeometry(0.6, 2, 6), new three.MeshStandardMaterial({ color: 7829367 }));
48900
- wall.position.set(LANE.wall + 0.3, 1, LANE.z);
50060
+ const wall = options.wall ? options.wall(three, CRASH_WALL) : null;
48901
50061
  const scene = host.scene;
48902
- scene.add(built2.group, wall);
50062
+ scene.add(built2.group);
50063
+ if (wall) {
50064
+ wall.rotation.y = Math.PI / 2;
50065
+ wall.position.set(LANE.wall + CRASH_WALL.thickness / 2, 0, LANE.z);
50066
+ scene.add(wall);
50067
+ }
48903
50068
  const mode = settings.driving === "semi" || settings.damage !== "none" ? "semi" : "arcade";
48904
50069
  const damage = settings.damage === "none" || !built2.context ? null : createLaneDamage({ kit, context: built2.context, frame: built2.group, damage: settings.damage });
48905
50070
  const surfaces = createSurfaces();
@@ -49035,9 +50200,10 @@ var GameVehiclesThree = (() => {
49035
50200
  }
49036
50201
  };
49037
50202
  const creaseQueue = createCreaseQueue();
50203
+ const lodQueue = createVehicleLodQueue();
49038
50204
  const updateLod = (entry) => {
49039
50205
  if (!host || settings.quality === "lite") return;
49040
- entry.lod ?? (entry.lod = createVehicleLod(entry.root.userData.kit, entry.item.vehicle, entry.root, entry.root.children[0]));
50206
+ entry.lod ?? (entry.lod = createVehicleLod(entry.root.userData.kit, entry.item.vehicle, entry.root, entry.root.children[0], { queue: lodQueue }));
49041
50207
  const at = host.player().position;
49042
50208
  const distance = Math.hypot(at[0] - entry.root.position.x, at[2] - entry.root.position.z);
49043
50209
  const c = entry.item.vehicle;
@@ -49047,6 +50213,7 @@ var GameVehiclesThree = (() => {
49047
50213
  const frame = (dt) => {
49048
50214
  for (const [id, entry] of placed) {
49049
50215
  if (!entry.root.parent) {
50216
+ entry.lod?.dispose();
49050
50217
  placed.delete(id);
49051
50218
  continue;
49052
50219
  }
@@ -49154,6 +50321,7 @@ var GameVehiclesThree = (() => {
49154
50321
  const stopFrame = lent.onFrame(frame);
49155
50322
  const stopBlocker = lent.addBlocker?.(blocked);
49156
50323
  const stopCrease = lent.defer?.(creaseQueue.deferredQueue(), DEFERRED_PRIORITY[DEFERRED_QUEUE_ID.VEHICLE_CREASE]);
50324
+ const stopLodBatch = lent.defer?.(lodQueue.deferredQueue(), DEFERRED_PRIORITY[DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]);
49157
50325
  if (isRenderPools(lent.pools)) lent.pools.materials.register("vehicles.cracked-glass", () => crackedGlassMaterial(three, new three.DataTexture(new Uint8Array(4), 1, 1)));
49158
50326
  lent.audio?.register?.(LIBRARY_BANK);
49159
50327
  lent.audio?.register?.(VEHICLE_SOUND_BANK);
@@ -49163,6 +50331,7 @@ var GameVehiclesThree = (() => {
49163
50331
  stopFrame();
49164
50332
  stopBlocker?.();
49165
50333
  stopCrease?.();
50334
+ stopLodBatch?.();
49166
50335
  cabins.clear(effects());
49167
50336
  clearHelpers();
49168
50337
  clearLane();
@@ -49291,6 +50460,589 @@ var GameVehiclesThree = (() => {
49291
50460
  };
49292
50461
  }
49293
50462
 
50463
+ // ../game-runtime/dist/index.js
50464
+ var DEFAULT_MIN_EVERY_FRAMES = 4;
50465
+ function createQueueEntry(queue, options) {
50466
+ return {
50467
+ queue,
50468
+ phase: options.phase ?? "idle",
50469
+ priority: options.priority,
50470
+ minEveryFrames: options.minEveryFrames ?? DEFAULT_MIN_EVERY_FRAMES,
50471
+ reserveMs: options.reserveMs ?? 0,
50472
+ mustDrain: options.mustDrain === true,
50473
+ reserveLeft: 0,
50474
+ waitingFrames: 0,
50475
+ maxWaitingFrames: 0,
50476
+ ranUnits: 0,
50477
+ spentMs: 0,
50478
+ lastSpentMs: 0,
50479
+ forced: 0,
50480
+ lastPending: 0
50481
+ };
50482
+ }
50483
+ function insertByPriority(entries2, entry) {
50484
+ let index = entries2.length;
50485
+ while (index > 0 && entries2[index - 1].priority < entry.priority) index--;
50486
+ entries2.splice(index, 0, entry);
50487
+ }
50488
+ function queueStats(entry) {
50489
+ return {
50490
+ id: entry.queue.id,
50491
+ pending: entry.lastPending,
50492
+ ranUnits: entry.ranUnits,
50493
+ spentMs: entry.spentMs,
50494
+ lastSpentMs: entry.lastSpentMs,
50495
+ mustDrain: entry.mustDrain,
50496
+ framesWaiting: entry.waitingFrames,
50497
+ maxFramesWaiting: entry.maxWaitingFrames,
50498
+ forced: entry.forced
50499
+ };
50500
+ }
50501
+ var MICROS_PER_SECOND = 1e6;
50502
+ var toMicros = (seconds) => Math.round(seconds * MICROS_PER_SECOND);
50503
+ function defaultClock() {
50504
+ if (typeof performance !== "undefined" && typeof performance.now === "function") return () => performance.now();
50505
+ return () => Date.now();
50506
+ }
50507
+ var RENDER_ESTIMATE_WEIGHT = 0.125;
50508
+ function createRenderEstimate() {
50509
+ let value = 0;
50510
+ let seeded = false;
50511
+ return {
50512
+ get value() {
50513
+ return value;
50514
+ },
50515
+ add(sample) {
50516
+ value = seeded ? value + (sample - value) * RENDER_ESTIMATE_WEIGHT : sample;
50517
+ seeded = true;
50518
+ }
50519
+ };
50520
+ }
50521
+ var DEFAULT_MS = 4;
50522
+ var DEFAULT_MIN_MS = 1;
50523
+ var MAX_RESERVE_SHARE = 0.5;
50524
+ function createFrameBudget(options = {}) {
50525
+ const clock = options.clock ?? defaultClock();
50526
+ const entries2 = [];
50527
+ const reportedQueues = /* @__PURE__ */ new Set();
50528
+ let frame = 0;
50529
+ let frameOpen = false;
50530
+ let debt = 0;
50531
+ let common = 0;
50532
+ let spentThisFrame = 0;
50533
+ let mustDrainSpent = 0;
50534
+ let unbounded = false;
50535
+ let mode = "quota";
50536
+ let allowance = 0;
50537
+ let isAllowanceReady = false;
50538
+ let frameStart = 0;
50539
+ let frameTarget = 0;
50540
+ let isRenderSkipped = false;
50541
+ const forcedMs = [];
50542
+ const minMs = options.minMs ?? DEFAULT_MIN_MS;
50543
+ const mustDrainIds = options.mustDrainIds ?? MUST_DRAIN_QUEUE_IDS;
50544
+ const renderEstimate = createRenderEstimate();
50545
+ const reservedTotal = () => entries2.reduce((sum, entry) => sum + entry.reserveMs, 0);
50546
+ const carveReserves = (pool) => {
50547
+ for (const entry of entries2) {
50548
+ entry.reserveLeft = 0;
50549
+ if (entry.reserveMs <= 0 || entry.mustDrain || entry.queue.pending(frame) <= 0) continue;
50550
+ entry.reserveLeft = Math.min(entry.reserveMs, pool);
50551
+ pool -= entry.reserveLeft;
50552
+ }
50553
+ return pool;
50554
+ };
50555
+ const beginFrame = (frameStartMs) => {
50556
+ frame++;
50557
+ frameOpen = true;
50558
+ spentThisFrame = 0;
50559
+ mustDrainSpent = 0;
50560
+ forcedMs.length = 0;
50561
+ isRenderSkipped = false;
50562
+ for (const entry of entries2) entry.lastSpentMs = 0;
50563
+ const target = budget.targetMs;
50564
+ if (target !== void 0 && frameStartMs !== void 0 && !unbounded) {
50565
+ const now = clock();
50566
+ const lag = now - frameStartMs;
50567
+ mode = "deadline";
50568
+ frameTarget = target;
50569
+ frameStart = lag >= 0 && lag <= target ? frameStartMs : now;
50570
+ isAllowanceReady = false;
50571
+ allowance = 0;
50572
+ common = 0;
50573
+ debt = 0;
50574
+ return;
50575
+ }
50576
+ mode = "quota";
50577
+ allowance = Math.max(0, budget.ms - debt);
50578
+ common = Math.max(0, carveReserves(budget.ms) - debt);
50579
+ debt = 0;
50580
+ };
50581
+ const ensureAllowance = () => {
50582
+ if (isAllowanceReady) return;
50583
+ isAllowanceReady = true;
50584
+ const left = frameStart + frameTarget - renderEstimate.value - clock();
50585
+ allowance = Math.max(minMs, Math.min(budget.ms, left));
50586
+ common = carveReserves(allowance);
50587
+ };
50588
+ const refreshForIdle = () => {
50589
+ for (const entry of entries2) if (entry.phase === "present") entry.reserveLeft = 0;
50590
+ const realLeft = frameStart + frameTarget - clock();
50591
+ const total = Math.max(Math.min(allowance - spentThisFrame, realLeft), minMs - spentThisFrame);
50592
+ common = Math.max(0, total - entries2.reduce((sum, entry) => sum + entry.reserveLeft, 0));
50593
+ };
50594
+ const reportError = (error, entry) => {
50595
+ if (options.onError) return options.onError(error, { id: entry.queue.id, phase: entry.phase });
50596
+ if (reportedQueues.has(entry.queue.id)) return;
50597
+ reportedQueues.add(entry.queue.id);
50598
+ console.error(`game-runtime: queue ${entry.queue.id} threw`, error);
50599
+ };
50600
+ const runQueue = (entry, deadline) => {
50601
+ try {
50602
+ return entry.queue.run(deadline, clock);
50603
+ } catch (error) {
50604
+ reportError(error, entry);
50605
+ return 0;
50606
+ }
50607
+ };
50608
+ const runEntry = (entry, deadline) => {
50609
+ const started = clock();
50610
+ const ran = runQueue(entry, deadline);
50611
+ const spent = Math.max(0, clock() - started);
50612
+ entry.ranUnits += ran;
50613
+ entry.spentMs += spent;
50614
+ entry.lastSpentMs += spent;
50615
+ entry.waitingFrames = 0;
50616
+ if (entry.mustDrain) {
50617
+ mustDrainSpent += spent;
50618
+ return spent;
50619
+ }
50620
+ spentThisFrame += spent;
50621
+ if (unbounded) return spent;
50622
+ const fromReserve = Math.min(entry.reserveLeft, spent);
50623
+ entry.reserveLeft -= fromReserve;
50624
+ common -= spent - fromReserve;
50625
+ if (common < 0) {
50626
+ if (mode === "quota") debt = Math.min(budget.ms, debt - common);
50627
+ common = 0;
50628
+ }
50629
+ return spent;
50630
+ };
50631
+ const drainMustDrain = (entry) => {
50632
+ entry.lastPending = entry.queue.pending(frame);
50633
+ if (entry.lastPending <= 0) {
50634
+ entry.waitingFrames = 0;
50635
+ return;
50636
+ }
50637
+ runEntry(entry, Infinity);
50638
+ };
50639
+ const drainEntry = (entry) => {
50640
+ entry.lastPending = entry.queue.pending(frame);
50641
+ if (entry.lastPending <= 0) {
50642
+ entry.waitingFrames = 0;
50643
+ return;
50644
+ }
50645
+ if (unbounded) {
50646
+ runEntry(entry, Infinity);
50647
+ return;
50648
+ }
50649
+ const share = entry.reserveLeft + common;
50650
+ if (share > 0) {
50651
+ runEntry(entry, clock() + share);
50652
+ return;
50653
+ }
50654
+ entry.waitingFrames++;
50655
+ entry.maxWaitingFrames = Math.max(entry.maxWaitingFrames, entry.waitingFrames);
50656
+ if (entry.waitingFrames < entry.minEveryFrames) return;
50657
+ entry.forced++;
50658
+ forcedMs.push(runEntry(entry, clock()));
50659
+ };
50660
+ const budget = {
50661
+ ms: options.ms ?? DEFAULT_MS,
50662
+ register(queue, queueOptions) {
50663
+ if (entries2.some((candidate) => candidate.queue === queue)) throw new Error(`budget.register(${queue.id}): this queue is already registered`);
50664
+ if (queueOptions.mustDrain === true && !mustDrainIds.has(queue.id)) {
50665
+ throw new Error(`budget.register(${queue.id}): mustDrain is only for ${[...mustDrainIds].join(", ")} (CLAUDE.md \xA715: a new queue does not enter the mustDrain class without the owner's decision; a host passes its own list as the budget's mustDrainIds)`);
50666
+ }
50667
+ const reserveMs = queueOptions.reserveMs ?? 0;
50668
+ if (reservedTotal() + reserveMs > budget.ms * MAX_RESERVE_SHARE) {
50669
+ throw new Error(`budget.register(${queue.id}): the reserves would pass half of the ${budget.ms} ms budget`);
50670
+ }
50671
+ if (budget.targetMs !== void 0 && reservedTotal() + reserveMs > minMs) {
50672
+ throw new Error(`budget.register(${queue.id}): with a deadline the reserves come out of the ${minMs} ms floor and would pass it`);
50673
+ }
50674
+ const entry = createQueueEntry(queue, queueOptions);
50675
+ insertByPriority(entries2, entry);
50676
+ queue.attach?.();
50677
+ return () => {
50678
+ const at = entries2.indexOf(entry);
50679
+ if (at < 0) return;
50680
+ entries2.splice(at, 1);
50681
+ queue.detach?.();
50682
+ };
50683
+ },
50684
+ targetMs: options.targetMs,
50685
+ get mode() {
50686
+ return mode;
50687
+ },
50688
+ beginFrame,
50689
+ recordRender(ms) {
50690
+ if (budget.targetMs === void 0 || isRenderSkipped || !Number.isFinite(ms)) return;
50691
+ renderEstimate.add(Math.min(Math.max(ms, 0), budget.targetMs));
50692
+ },
50693
+ skipRenderSample() {
50694
+ isRenderSkipped = true;
50695
+ },
50696
+ drain(phase) {
50697
+ if (phase === "present" && !frameOpen) beginFrame();
50698
+ for (const entry of [...entries2]) if (entry.mustDrain && entry.phase === phase) drainMustDrain(entry);
50699
+ if (mode === "deadline" && !unbounded) {
50700
+ ensureAllowance();
50701
+ if (phase === "idle") refreshForIdle();
50702
+ }
50703
+ for (const entry of [...entries2]) if (!entry.mustDrain && entry.phase === phase) drainEntry(entry);
50704
+ if (phase === "idle") frameOpen = false;
50705
+ },
50706
+ flushAll() {
50707
+ for (const entry of entries2) entry.queue.flush();
50708
+ },
50709
+ get unbounded() {
50710
+ return unbounded;
50711
+ },
50712
+ set unbounded(value) {
50713
+ unbounded = value;
50714
+ },
50715
+ stats() {
50716
+ return {
50717
+ mode,
50718
+ ms: budget.ms,
50719
+ targetMs: mode === "deadline" ? frameTarget : void 0,
50720
+ allowanceMs: allowance,
50721
+ renderEstimateMs: renderEstimate.value,
50722
+ spentMs: spentThisFrame,
50723
+ mustDrainSpentMs: mustDrainSpent,
50724
+ overMs: Math.max(0, spentThisFrame - Math.max(allowance, minMs)),
50725
+ forcedThisFrame: forcedMs.length,
50726
+ forcedMs: [...forcedMs],
50727
+ debtMs: debt,
50728
+ queues: entries2.map(queueStats)
50729
+ };
50730
+ },
50731
+ dispose() {
50732
+ for (const entry of entries2.splice(0)) entry.queue.detach?.();
50733
+ }
50734
+ };
50735
+ return budget;
50736
+ }
50737
+ var NONE = [];
50738
+ function createCommandBuffer(nextTick) {
50739
+ let pending = [];
50740
+ return {
50741
+ push(kind, payload, tick) {
50742
+ pending.push({ kind, payload, tick: tick ?? nextTick() });
50743
+ },
50744
+ take(tick) {
50745
+ if (pending.length === 0) return NONE;
50746
+ const due = [];
50747
+ const later = [];
50748
+ for (const command of pending) (command.tick <= tick ? due : later).push(command);
50749
+ pending = later;
50750
+ return due;
50751
+ },
50752
+ clear() {
50753
+ pending = [];
50754
+ }
50755
+ };
50756
+ }
50757
+ var sanitizeSeconds = (seconds) => Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
50758
+ var sanitizeTimeScale = (scale) => Number.isFinite(scale) ? Math.max(0, scale) : 1;
50759
+ function resolveFrameTime(realSeconds, exact, residual, config) {
50760
+ const given = sanitizeSeconds(realSeconds);
50761
+ if (exact) return { seconds: given, micros: toMicros(given), residual };
50762
+ const clamped = Math.min(given, config.maxFrameSeconds);
50763
+ const micros = toMicros(clamped) + residual;
50764
+ const wholeSteps = Math.round(micros / config.fixedMicros);
50765
+ const drift = micros - wholeSteps * config.fixedMicros;
50766
+ if (config.snapMicros > 0 && wholeSteps >= 1 && Math.abs(drift) <= config.snapMicros) {
50767
+ return { seconds: wholeSteps * config.fixedDt, micros: wholeSteps * config.fixedMicros, residual: drift };
50768
+ }
50769
+ return { seconds: clamped, micros, residual: 0 };
50770
+ }
50771
+ function createPhaseRunner(deps) {
50772
+ const { clock, ctx, lists, reportError, fixedDt, probe } = deps;
50773
+ const phaseMs = Object.fromEntries(FRAME_PHASES.map((phase) => [phase, 0]));
50774
+ let tick = 0;
50775
+ const runEntries = (phase) => {
50776
+ for (const entry of lists[phase].entries) {
50777
+ if (entry.dead) continue;
50778
+ const watcher = probe();
50779
+ watcher?.enter(entry.id);
50780
+ try {
50781
+ entry.fn(ctx);
50782
+ } catch (error) {
50783
+ reportError(error, { id: entry.id, phase });
50784
+ } finally {
50785
+ watcher?.leave(entry.id);
50786
+ }
50787
+ }
50788
+ };
50789
+ return {
50790
+ runPhase(phase, dt) {
50791
+ const started = clock();
50792
+ ctx.dt = dt;
50793
+ runEntries(phase);
50794
+ phaseMs[phase] = clock() - started;
50795
+ },
50796
+ runFixed(steps, isHeld) {
50797
+ const started = clock();
50798
+ ctx.dt = fixedDt;
50799
+ let ran = 0;
50800
+ for (let substep = 0; substep < steps; substep++) {
50801
+ if (isHeld?.()) break;
50802
+ ran++;
50803
+ ctx.substep = substep;
50804
+ ctx.tick = tick;
50805
+ runEntries("fixedSimulate");
50806
+ tick++;
50807
+ }
50808
+ ctx.substep = 0;
50809
+ ctx.tick = tick;
50810
+ phaseMs.fixedSimulate = clock() - started;
50811
+ return ran;
50812
+ },
50813
+ get tick() {
50814
+ return tick;
50815
+ },
50816
+ phaseMs
50817
+ };
50818
+ }
50819
+ function createSystemList(isRunning) {
50820
+ let entries2 = [];
50821
+ const waiting = [];
50822
+ const insert = (entry) => {
50823
+ let index = entries2.length;
50824
+ while (index > 0 && entries2[index - 1].order > entry.order) index--;
50825
+ entries2.splice(index, 0, entry);
50826
+ };
50827
+ return {
50828
+ add(entry) {
50829
+ if (isRunning()) waiting.push(entry);
50830
+ else insert(entry);
50831
+ },
50832
+ remove(entry) {
50833
+ entry.dead = true;
50834
+ if (!isRunning()) entries2 = entries2.filter((candidate) => candidate !== entry);
50835
+ },
50836
+ get entries() {
50837
+ return entries2;
50838
+ },
50839
+ settle() {
50840
+ if (entries2.some((entry) => entry.dead)) entries2 = entries2.filter((entry) => !entry.dead);
50841
+ for (const entry of waiting.splice(0)) if (!entry.dead) insert(entry);
50842
+ },
50843
+ clear() {
50844
+ for (const entry of entries2) entry.dead = true;
50845
+ for (const entry of waiting.splice(0)) entry.dead = true;
50846
+ entries2 = isRunning() ? entries2 : [];
50847
+ }
50848
+ };
50849
+ }
50850
+ function createScheduler(options = {}) {
50851
+ const fixedDt = options.fixedDt ?? 1 / 60;
50852
+ const fixedMicros = toMicros(fixedDt);
50853
+ const maxSubsteps = options.maxSubsteps ?? 4;
50854
+ const timeConfig = { fixedMicros, fixedDt, maxFrameSeconds: options.maxFrameSeconds ?? 0.25, snapMicros: Math.round((options.snapMs ?? 0.25) * 1e3) };
50855
+ const clock = options.clock ?? defaultClock();
50856
+ let accumulator = 0;
50857
+ let residual = 0;
50858
+ let droppedMicros = 0;
50859
+ let heldMicros = 0;
50860
+ let substepsLastFrame = 0;
50861
+ let running = false;
50862
+ let disposed = false;
50863
+ let paused = false;
50864
+ let scripted = false;
50865
+ let timeScale = 1;
50866
+ let systemProbe;
50867
+ let nextSystem = 0;
50868
+ const reportedErrors = /* @__PURE__ */ new Set();
50869
+ const lists = Object.fromEntries(FRAME_PHASES.map((phase) => [phase, createSystemList(() => running)]));
50870
+ const ctx = { dt: 0, realDt: 0, fixedDt, alpha: 0, frame: 0, tick: 0, substep: 0, simTime: 0, paused: false, scripted: false, simulated: true, fixedFrozen: false };
50871
+ const reportError = options.onError ?? ((error, system) => {
50872
+ if (reportedErrors.has(system.id)) return;
50873
+ reportedErrors.add(system.id);
50874
+ console.error(`game-runtime: system ${system.id} (${system.phase}) threw`, error);
50875
+ });
50876
+ const budget = createFrameBudget({ ms: options.budgetMs ?? 4, targetMs: options.targetMs, minMs: options.minBudgetMs, mustDrainIds: options.mustDrainIds, clock, onError: (error, queue) => reportError(error, { id: `queue:${queue.id}`, phase: queue.phase }) });
50877
+ const runner = createPhaseRunner({ clock, ctx, lists, reportError, fixedDt, probe: () => systemProbe });
50878
+ const { runPhase, runFixed } = runner;
50879
+ const settleAll = () => {
50880
+ for (const phase of FRAME_PHASES) lists[phase].settle();
50881
+ };
50882
+ const begin = (frameStartMs) => {
50883
+ running = true;
50884
+ budget.beginFrame(frameStartMs);
50885
+ ctx.frame++;
50886
+ ctx.paused = paused;
50887
+ ctx.scripted = scripted;
50888
+ ctx.tick = runner.tick;
50889
+ };
50890
+ const end = () => {
50891
+ running = false;
50892
+ settleAll();
50893
+ };
50894
+ const simulate = (seconds, micros, exact) => {
50895
+ runPhase("input", seconds);
50896
+ if (paused) return;
50897
+ if (ctx.fixedFrozen) {
50898
+ heldMicros += Math.round(micros * timeScale);
50899
+ ctx.simTime += seconds * timeScale;
50900
+ runPhase("lateSimulate", seconds * timeScale);
50901
+ return;
50902
+ }
50903
+ accumulator += Math.round(micros * timeScale);
50904
+ let steps = Math.floor(accumulator / fixedMicros);
50905
+ if (!exact && steps > maxSubsteps) {
50906
+ droppedMicros += accumulator - maxSubsteps * fixedMicros;
50907
+ steps = maxSubsteps;
50908
+ accumulator = maxSubsteps * fixedMicros;
50909
+ }
50910
+ accumulator -= steps * fixedMicros;
50911
+ substepsLastFrame = runFixed(steps, options.holdFixed);
50912
+ if (substepsLastFrame < steps) {
50913
+ heldMicros += (steps - substepsLastFrame) * fixedMicros;
50914
+ ctx.fixedFrozen = true;
50915
+ }
50916
+ ctx.alpha = accumulator / fixedMicros;
50917
+ ctx.simTime += seconds * timeScale;
50918
+ runPhase("lateSimulate", seconds * timeScale);
50919
+ };
50920
+ const frame = (realSeconds, run = {}) => {
50921
+ if (running) throw new Error("scheduler.frame: re-entrant call");
50922
+ if (disposed) throw new Error("scheduler.frame: the scheduler was disposed");
50923
+ const time = resolveFrameTime(realSeconds, run.exact === true, residual, timeConfig);
50924
+ residual = time.residual;
50925
+ const seconds = time.seconds;
50926
+ begin(run.frameStartMs);
50927
+ try {
50928
+ ctx.simulated = run.simulate !== false;
50929
+ ctx.fixedFrozen = ctx.simulated && (run.freezeFixed === true || options.holdFixed?.() === true);
50930
+ ctx.realDt = seconds;
50931
+ ctx.alpha = accumulator / fixedMicros;
50932
+ substepsLastFrame = 0;
50933
+ if (ctx.simulated) simulate(seconds, time.micros, run.exact === true);
50934
+ ctx.alpha = accumulator / fixedMicros;
50935
+ runPhase("present", paused ? 0 : seconds * timeScale);
50936
+ budget.drain("present");
50937
+ if (run.render !== false) {
50938
+ runPhase("render", seconds);
50939
+ budget.recordRender(runner.phaseMs.render);
50940
+ }
50941
+ runPhase("idle", seconds);
50942
+ budget.drain("idle");
50943
+ } finally {
50944
+ ctx.simulated = true;
50945
+ ctx.fixedFrozen = false;
50946
+ end();
50947
+ }
50948
+ };
50949
+ const advanceStep = (dt, steps) => {
50950
+ begin();
50951
+ try {
50952
+ ctx.simulated = true;
50953
+ ctx.realDt = dt;
50954
+ ctx.alpha = 0;
50955
+ runPhase("input", dt);
50956
+ if (!paused) {
50957
+ runFixed(steps);
50958
+ ctx.simTime += dt;
50959
+ runPhase("lateSimulate", dt);
50960
+ }
50961
+ runPhase("present", paused ? 0 : dt);
50962
+ budget.drain("present");
50963
+ runPhase("idle", dt);
50964
+ budget.drain("idle");
50965
+ } finally {
50966
+ end();
50967
+ }
50968
+ };
50969
+ const advance2 = (seconds, advanceOptions = {}) => {
50970
+ if (running) throw new Error("scheduler.advance: re-entrant call");
50971
+ if (disposed) throw new Error("scheduler.advance: the scheduler was disposed");
50972
+ const dt = sanitizeSeconds(advanceOptions.dt ?? fixedDt) || fixedDt;
50973
+ const iterations = Math.max(1, Math.round(sanitizeSeconds(seconds) / dt));
50974
+ const steps = Math.max(1, Math.round(dt / fixedDt));
50975
+ const wasUnbounded = budget.unbounded;
50976
+ budget.unbounded = true;
50977
+ scripted = true;
50978
+ accumulator = 0;
50979
+ residual = 0;
50980
+ scheduler.commands.clear();
50981
+ try {
50982
+ for (let i = 0; i < iterations; i++) advanceStep(dt, steps);
50983
+ } finally {
50984
+ scripted = false;
50985
+ ctx.scripted = false;
50986
+ budget.unbounded = wasUnbounded;
50987
+ accumulator = 0;
50988
+ ctx.alpha = 0;
50989
+ }
50990
+ };
50991
+ const scheduler = {
50992
+ add(system, systemOptions) {
50993
+ if (disposed) return () => void 0;
50994
+ const entry = {
50995
+ id: systemOptions.id ?? `${systemOptions.phase}#${nextSystem++}`,
50996
+ phase: systemOptions.phase,
50997
+ fn: system,
50998
+ order: systemOptions.order ?? 0,
50999
+ dead: false
51000
+ };
51001
+ lists[entry.phase].add(entry);
51002
+ return () => lists[entry.phase].remove(entry);
51003
+ },
51004
+ frame,
51005
+ advance: advance2,
51006
+ pause() {
51007
+ paused = true;
51008
+ },
51009
+ resume() {
51010
+ paused = false;
51011
+ },
51012
+ get paused() {
51013
+ return paused;
51014
+ },
51015
+ get timeScale() {
51016
+ return timeScale;
51017
+ },
51018
+ set timeScale(value) {
51019
+ timeScale = sanitizeTimeScale(value);
51020
+ },
51021
+ resetClock() {
51022
+ accumulator = 0;
51023
+ residual = 0;
51024
+ },
51025
+ get systemProbe() {
51026
+ return systemProbe;
51027
+ },
51028
+ set systemProbe(value) {
51029
+ systemProbe = value;
51030
+ },
51031
+ budget,
51032
+ commands: createCommandBuffer(() => runner.tick),
51033
+ stats() {
51034
+ return { frame: ctx.frame, tick: runner.tick, substepsLastFrame, droppedSeconds: droppedMicros / MICROS_PER_SECOND, heldSeconds: heldMicros / MICROS_PER_SECOND, phaseMs: { ...runner.phaseMs }, budget: budget.stats() };
51035
+ },
51036
+ dispose() {
51037
+ disposed = true;
51038
+ budget.dispose();
51039
+ for (const phase of FRAME_PHASES) lists[phase].clear();
51040
+ settleAll();
51041
+ }
51042
+ };
51043
+ return scheduler;
51044
+ }
51045
+
49294
51046
  // ../game-vehicles-proving/dist/index.js
49295
51047
  var lerpTable = (table2, x) => {
49296
51048
  if (x <= table2[0][0]) return table2[0][1];
@@ -49346,6 +51098,7 @@ var GameVehiclesThree = (() => {
49346
51098
  return Math.round(x * k) / k;
49347
51099
  };
49348
51100
  var subjectSpec = (subject) => ({ ...semiSpecFromStats(subject.stats, subject.body), ...subject.spec });
51101
+ var STEPS_PER_TICK = 2;
49349
51102
  function startRun(test, subject, options = {}) {
49350
51103
  const procedure = test.procedure;
49351
51104
  if (test.kind !== "measured" || !procedure) throw new Error(`startRun: ${test.id} is not a measured test`);
@@ -49361,7 +51114,7 @@ var GameVehiclesThree = (() => {
49361
51114
  let time = 0;
49362
51115
  let done = false;
49363
51116
  let nextSample = 0;
49364
- let carry = 0;
51117
+ let scheduler;
49365
51118
  let last = { throttle: 0, brake: 0, steer: 0, handbrake: false };
49366
51119
  const tick = (h) => {
49367
51120
  const input = procedure.input(driver.state, time, memo);
@@ -49392,12 +51145,16 @@ var GameVehiclesThree = (() => {
49392
51145
  get input() {
49393
51146
  return last;
49394
51147
  },
49395
- step(dt) {
49396
- carry += dt;
49397
- while (!done && carry >= fixed) {
49398
- carry -= fixed;
49399
- tick(fixed);
51148
+ fixedStep: fixed,
51149
+ stepFixed(steps) {
51150
+ for (let i = 0; i < steps && !done; i++) tick(fixed);
51151
+ },
51152
+ advance(seconds) {
51153
+ if (!scheduler) {
51154
+ scheduler = createScheduler({ fixedDt: fixed * STEPS_PER_TICK });
51155
+ scheduler.add(() => this.stepFixed(STEPS_PER_TICK), { phase: "fixedSimulate", id: "proving.run" });
49400
51156
  }
51157
+ scheduler.frame(seconds, { exact: true, render: false });
49401
51158
  },
49402
51159
  result() {
49403
51160
  const range2 = test.range?.(subject) ?? {};
@@ -49413,8 +51170,7 @@ var GameVehiclesThree = (() => {
49413
51170
  }
49414
51171
  function runTest(test, subject, options = {}) {
49415
51172
  const run = startRun(test, subject, options);
49416
- const fixed = options.fixedStep ?? 1 / 120;
49417
- while (!run.done) run.step(fixed * 60);
51173
+ while (!run.done) run.stepFixed(STEPS_PER_TICK);
49418
51174
  return run.result();
49419
51175
  }
49420
51176
  var KMH = 3.6;
@@ -49965,6 +51721,7 @@ var GameVehiclesThree = (() => {
49965
51721
  const has = { head: lamps.some((l) => l.kind === "headlight"), tail: lamps.some((l) => l.kind === "taillight"), fog: lamps.some((l) => l.kind === "fog"), indicators: false, beacon: beacons.length > 0 };
49966
51722
  const originals = /* @__PURE__ */ new Map();
49967
51723
  const copies = /* @__PURE__ */ new Map();
51724
+ const copyOf = /* @__PURE__ */ new Map();
49968
51725
  const base = /* @__PURE__ */ new Map();
49969
51726
  const own = (mesh2) => {
49970
51727
  const mat = mesh2.material;
@@ -49973,6 +51730,7 @@ var GameVehiclesThree = (() => {
49973
51730
  const copy = mat.clone();
49974
51731
  originals.set(mesh2, mat);
49975
51732
  copies.set(copy, mat);
51733
+ copyOf.set(mesh2, copy);
49976
51734
  base.set(copy, mat.emissiveIntensity ?? 1);
49977
51735
  mesh2.material = copy;
49978
51736
  return copy;
@@ -50108,13 +51866,12 @@ var GameVehiclesThree = (() => {
50108
51866
  for (const a of anchors) a.removeFromParent();
50109
51867
  anchors.length = 0;
50110
51868
  const giveBack = (m) => {
50111
- const copy = m.material;
50112
51869
  const original = originals.get(m);
50113
51870
  if (!original) return;
50114
51871
  originals.delete(m);
50115
- if (!copies.has(copy)) return;
50116
- m.material = original;
50117
- if (copy && !Array.isArray(copy)) copy.dispose?.();
51872
+ if (copies.has(m.material)) m.material = original;
51873
+ copyOf.get(m)?.dispose?.();
51874
+ copyOf.delete(m);
50118
51875
  };
50119
51876
  for (const b of beacons) giveBack(b.mesh);
50120
51877
  for (const l of lamps) {
@@ -50127,6 +51884,7 @@ var GameVehiclesThree = (() => {
50127
51884
  }
50128
51885
  originals.clear();
50129
51886
  copies.clear();
51887
+ copyOf.clear();
50130
51888
  base.clear();
50131
51889
  }
50132
51890
  };
@@ -50785,6 +52543,7 @@ var GameVehiclesThree = (() => {
50785
52543
  let misted = false;
50786
52544
  let lastGear = null;
50787
52545
  let driveClock = 0;
52546
+ let boardHalfSecond = 0;
50788
52547
  let queue = [];
50789
52548
  let open = false;
50790
52549
  let lastWrap = 0;
@@ -51054,6 +52813,7 @@ var GameVehiclesThree = (() => {
51054
52813
  if (!car) return;
51055
52814
  parking = null;
51056
52815
  run = startRun(test, car.subject);
52816
+ boardHalfSecond = 0;
51057
52817
  setSurface(run.surface);
51058
52818
  if (id === "turn_circle") run.driver.place(0, TRACK.start, 0);
51059
52819
  rig.vehicle?.reset();
@@ -51397,7 +53157,7 @@ var GameVehiclesThree = (() => {
51397
53157
  adjust[ADJUST_KEYS[change.id]] = Number(change.value);
51398
53158
  break;
51399
53159
  case "time_scale":
51400
- settings.timeScale = Number(change.value);
53160
+ settings.timeScale = Math.max(1, Math.round(Number(change.value)));
51401
53161
  break;
51402
53162
  case "gearbox":
51403
53163
  gearbox = change.value === "manual" ? "manual" : "automatic";
@@ -51420,7 +53180,6 @@ var GameVehiclesThree = (() => {
51420
53180
  let speed = 0;
51421
53181
  let steer = 0;
51422
53182
  if (run) {
51423
- run.step(dt * settings.timeScale);
51424
53183
  const s = run.driver.state;
51425
53184
  pose(s, s.steerAngle);
51426
53185
  speed = s.u;
@@ -51476,7 +53235,8 @@ var GameVehiclesThree = (() => {
51476
53235
  lastGear = geared.gear;
51477
53236
  drawBoard();
51478
53237
  } else if (!geared) lastGear = null;
51479
- if (run && Math.floor(run.time * 2) !== Math.floor((run.time - dt * settings.timeScale) * 2) || driving && Math.floor(driveClock * 2) !== Math.floor((driveClock - dt) * 2)) drawBoard();
53238
+ if (run && Math.floor(run.time * 2) !== boardHalfSecond || driving && Math.floor(driveClock * 2) !== Math.floor((driveClock - dt) * 2)) drawBoard();
53239
+ if (run) boardHalfSecond = Math.floor(run.time * 2);
51480
53240
  if (driving) driveClock += dt;
51481
53241
  };
51482
53242
  const speedNow = () => Math.abs(run?.driver.state.u ?? driving?.driver.state.u ?? parking?.driver.state.u ?? 0) * 3.6;
@@ -51563,6 +53323,7 @@ var GameVehiclesThree = (() => {
51563
53323
  lent.audio?.preload?.(VEHICLE_PRELOAD_SOUNDS);
51564
53324
  const stopChange = lent.bench?.onChange(onChange);
51565
53325
  const stopFrame = lent.onFrame(frame);
53326
+ const stopRunTick = lent.onFrame(() => run?.stepFixed(STEPS_PER_TICK * settings.timeScale), { phase: "fixedSimulate" });
51566
53327
  const stopClear = lent.onClear?.(() => {
51567
53328
  open = false;
51568
53329
  teardown();
@@ -51571,6 +53332,7 @@ var GameVehiclesThree = (() => {
51571
53332
  return () => {
51572
53333
  stopChange?.();
51573
53334
  stopFrame();
53335
+ stopRunTick();
51574
53336
  stopClear?.();
51575
53337
  teardown();
51576
53338
  lent.setViewCamera?.(null);