@adatechnology/game-vehicles 0.6.16 → 0.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -895,7 +895,7 @@ function boxTriangle(geo, ti, t) {
895
895
  ti.boxes[j + 3 + k] = Math.max(P[a + k], P[b + k], P[c + k]);
896
896
  }
897
897
  }
898
- function advance(geo, ti, deadline) {
898
+ function advance(geo, ti, deadline, clock) {
899
899
  const total = blockCount(ti.triangles);
900
900
  while (ti.builtBlocks < total) {
901
901
  const block = ti.builtBlocks;
@@ -903,7 +903,7 @@ function advance(geo, ti, deadline) {
903
903
  for (let t = block * TRI_BLOCK; t < t1; t++) boxTriangle(geo, ti, t);
904
904
  boxBlock(ti, block);
905
905
  ti.builtBlocks++;
906
- if (deadline !== Infinity && performance.now() >= deadline) break;
906
+ if (deadline !== Infinity && clock() >= deadline) break;
907
907
  }
908
908
  return ti.builtBlocks === total;
909
909
  }
@@ -927,14 +927,14 @@ function triIndexOf(geo) {
927
927
  if (!supports(geo)) return void 0;
928
928
  let ti = cache.get(geo);
929
929
  if (!ti || !isCurrent(geo, ti)) ti = start(geo);
930
- advance(geo, ti, Infinity);
930
+ advance(geo, ti, Infinity, performance.now.bind(performance));
931
931
  return ti;
932
932
  }
933
- function warmTriIndex(geo, deadline) {
933
+ function warmTriIndex(geo, deadline, clock = performance.now.bind(performance)) {
934
934
  if (!supports(geo)) return true;
935
935
  let ti = cache.get(geo);
936
936
  if (!ti || !isCurrent(geo, ti)) ti = start(geo);
937
- return advance(geo, ti, deadline);
937
+ return advance(geo, ti, deadline, clock);
938
938
  }
939
939
  function storeTriIndex(geo, boxes) {
940
940
  const ti = start(geo);
@@ -978,7 +978,7 @@ function rayIndexOf(geo) {
978
978
  if (shared && isCurrent(geo, shared) && shared.builtBlocks === blockCount(shared.triangles)) return shared;
979
979
  let ti = rayCache.get(geo);
980
980
  if (!ti || !isCurrent(geo, ti)) ti = start(geo, rayCache);
981
- advance(geo, ti, Infinity);
981
+ advance(geo, ti, Infinity, performance.now.bind(performance));
982
982
  return ti;
983
983
  }
984
984
  var BLOCK_SLACK = 1e-6;
@@ -1271,9 +1271,9 @@ function installGeometry(kit) {
1271
1271
  const cs = Math.cos(deg * PI / 180);
1272
1272
  let phase = 0;
1273
1273
  let at = 0;
1274
- function hashSlice(deadline) {
1274
+ function hashSlice(deadline, clock) {
1275
1275
  for (; at < n; at++) {
1276
- if ((at & 1023) === 0 && performance.now() > deadline) return false;
1276
+ if ((at & 1023) === 0 && clock() > deadline) return false;
1277
1277
  const x = Math.round(P[3 * at] * 2e3) | 0;
1278
1278
  const y = Math.round(P[3 * at + 1] * 2e3) | 0;
1279
1279
  const z = Math.round(P[3 * at + 2] * 2e3) | 0;
@@ -1302,9 +1302,9 @@ function installGeometry(kit) {
1302
1302
  members = new Int32Array(n);
1303
1303
  for (let i = 0; i < n; i++) members[fill[groupOf[i]]++] = i / 3 | 0;
1304
1304
  }
1305
- function smoothSlice(deadline) {
1305
+ function smoothSlice(deadline, clock) {
1306
1306
  for (; at < n; at++) {
1307
- if ((at & 1023) === 0 && performance.now() > deadline) return false;
1307
+ if ((at & 1023) === 0 && clock() > deadline) return false;
1308
1308
  const fi = (at / 3 | 0) * 3;
1309
1309
  const g = groupOf[at];
1310
1310
  let sx = 0;
@@ -1330,16 +1330,16 @@ function installGeometry(kit) {
1330
1330
  }
1331
1331
  return true;
1332
1332
  }
1333
- function step(deadline) {
1333
+ function step(deadline, clock = performance.now.bind(performance)) {
1334
1334
  if (latestCrease.get(geo) !== token) return true;
1335
1335
  if (phase === 0) {
1336
- if (!hashSlice(deadline)) return false;
1336
+ if (!hashSlice(deadline, clock)) return false;
1337
1337
  gather();
1338
1338
  phase = 1;
1339
1339
  at = 0;
1340
1340
  }
1341
1341
  if (phase === 1) {
1342
- const done = smoothSlice(deadline);
1342
+ const done = smoothSlice(deadline, clock);
1343
1343
  if (deadline !== Infinity) normal.needsUpdate = true;
1344
1344
  if (!done) return false;
1345
1345
  phase = 2;
@@ -6140,15 +6140,32 @@ function installExplosion(kit) {
6140
6140
  const m = c.meta;
6141
6141
  return new V3(m.front - 0.6, (m.clearance || 0.3) + 0.3, 0);
6142
6142
  }
6143
+ function worldPointOf(c, local) {
6144
+ c.vehicle.updateWorldMatrix(true, false);
6145
+ const wp = local.clone().applyMatrix4(c.vehicle.matrixWorld);
6146
+ return [wp.x, wp.y, wp.z];
6147
+ }
6148
+ function startVehicleFire(c, local, radius, life) {
6149
+ const effects = kit.effects?.();
6150
+ if (!effects) return false;
6151
+ const handle = effects.play({ effect: "volumetric_fire", point: worldPointOf(c, local), values: { radius, life } });
6152
+ if (handle != null) {
6153
+ c.vfxHandles = c.vfxHandles || [];
6154
+ c.vfxHandles.push(handle);
6155
+ }
6156
+ return true;
6157
+ }
6143
6158
  kit.explode = function(c, o) {
6144
6159
  o = o || {};
6145
6160
  if (c.blast || c.exploded) return false;
6146
6161
  const fuse = o.now ? 0 : o.delay != null ? o.delay : 3 + c.rand() * 5;
6147
- c.blast = { phase: "fire", t: 0, T: fuse };
6162
+ c.blast = { phase: "fire", t: 0, T: fuse, skipBlastEffect: !!o.skipBlastEffect };
6148
6163
  if (fuse > 0) {
6149
6164
  const ep = enginePos(c);
6150
- kit.addEmitter(c, ep.clone().add(new V3(0, 0.25, 0)), "fire", { rate: 10, s: 0.9 });
6151
- kit.addEmitter(c, ep.clone().add(new V3(0, 0.6, 0)), "black", { rate: 6, s: 1.2 });
6165
+ if (!startVehicleFire(c, ep.clone().add(new V3(0, 0.25, 0)), 0.55, fuse + 2)) {
6166
+ kit.addEmitter(c, ep.clone().add(new V3(0, 0.25, 0)), "fire", { rate: 10, s: 0.9 });
6167
+ kit.addEmitter(c, ep.clone().add(new V3(0, 0.6, 0)), "black", { rate: 6, s: 1.2 });
6168
+ }
6152
6169
  I.hurtEngine(c, 0.1);
6153
6170
  }
6154
6171
  if (c.hood) c.hood.target = 0;
@@ -6166,8 +6183,10 @@ function installExplosion(kit) {
6166
6183
  return p.kind === "fuel_tank";
6167
6184
  });
6168
6185
  const tp = tk ? tk.pos.clone() : enginePos(c);
6169
- kit.addEmitter(c, tp.clone().setY(Math.max(0.15, tp.y)), "fire", { rate: 12, s: 1.1 });
6170
- kit.addEmitter(c, tp.clone().setY(tp.y + 0.8), "black", { rate: 5, s: 1.4 });
6186
+ if (!startVehicleFire(c, tp.clone().setY(Math.max(0.15, tp.y)), 0.65, 25)) {
6187
+ kit.addEmitter(c, tp.clone().setY(Math.max(0.15, tp.y)), "fire", { rate: 12, s: 1.1 });
6188
+ kit.addEmitter(c, tp.clone().setY(tp.y + 0.8), "black", { rate: 5, s: 1.4 });
6189
+ }
6171
6190
  return "fire";
6172
6191
  }
6173
6192
  return null;
@@ -6274,42 +6293,51 @@ function installExplosion(kit) {
6274
6293
  c.emitters = c.emitters.filter(function(e) {
6275
6294
  return e.kind !== "exhaust";
6276
6295
  });
6277
- const fl = new THREE.Sprite(
6278
- new THREE.SpriteMaterial({
6279
- map: I.glowTexture(),
6280
- color: 16767392,
6281
- blending: THREE.AdditiveBlending,
6282
- transparent: true,
6283
- depthWrite: false,
6284
- fog: false
6285
- })
6286
- );
6287
- fl.raycast = function() {
6288
- };
6289
- fl.position.copy(cen);
6290
- fl.scale.setScalar(0.1);
6291
- c.effects.add(fl);
6292
- B.flash = fl;
6293
- const sw = new THREE.Mesh(new THREE.RingGeometry(0.8, 1, 64), boomMat("#ffcf8a", 0.6, true));
6294
- sw.rotation.x = -PI / 2;
6295
- sw.position.set(cen.x, 0.07, cen.z);
6296
- c.effects.add(sw);
6297
- B.shock = sw;
6298
- const k = big ? 1.8 : 1;
6299
- for (let i = 0; i < (big ? 70 : 46); i++) {
6300
- const d = new V3(c.rand() - 0.5, c.rand() * 0.9, c.rand() - 0.5).normalize();
6301
- kit.spawn(c, "fire", cen.clone().addScaledVector(d, 0.3), d.multiplyScalar((2.5 + c.rand() * 4) * k), {
6302
- s: (1 + c.rand() * 1.4) * k,
6303
- life: 0.8 + c.rand() * 0.7
6304
- });
6305
- }
6306
- for (let j = 0; j < (big ? 30 : 18); j++) {
6307
- const d2 = new V3(c.rand() - 0.5, 0.4 + c.rand(), c.rand() - 0.5).normalize();
6308
- kit.spawn(c, "smoke", cen.clone().addScaledVector(d2, 0.6), d2.multiplyScalar(1.5 + c.rand() * 2), {
6309
- variant: "black",
6310
- s: (1.4 + c.rand()) * k,
6311
- life: 4 + c.rand() * 2
6312
- });
6296
+ const effects = kit.effects?.();
6297
+ if (effects) {
6298
+ if (!B.skipBlastEffect) {
6299
+ c.effects.updateWorldMatrix(true, false);
6300
+ const worldCen = cen.clone().applyMatrix4(c.effects.matrixWorld);
6301
+ effects.play({ effect: big ? "fuel_station_tank" : "car_fuel_tank", point: [worldCen.x, worldCen.y, worldCen.z], values: {} });
6302
+ }
6303
+ } else {
6304
+ const fl = new THREE.Sprite(
6305
+ new THREE.SpriteMaterial({
6306
+ map: I.glowTexture(),
6307
+ color: 16767392,
6308
+ blending: THREE.AdditiveBlending,
6309
+ transparent: true,
6310
+ depthWrite: false,
6311
+ fog: false
6312
+ })
6313
+ );
6314
+ fl.raycast = function() {
6315
+ };
6316
+ fl.position.copy(cen);
6317
+ fl.scale.setScalar(0.1);
6318
+ c.effects.add(fl);
6319
+ B.flash = fl;
6320
+ const sw = new THREE.Mesh(new THREE.RingGeometry(0.8, 1, 64), boomMat("#ffcf8a", 0.6, true));
6321
+ sw.rotation.x = -PI / 2;
6322
+ sw.position.set(cen.x, 0.07, cen.z);
6323
+ c.effects.add(sw);
6324
+ B.shock = sw;
6325
+ const k = big ? 1.8 : 1;
6326
+ for (let i = 0; i < (big ? 70 : 46); i++) {
6327
+ const d = new V3(c.rand() - 0.5, c.rand() * 0.9, c.rand() - 0.5).normalize();
6328
+ kit.spawn(c, "fire", cen.clone().addScaledVector(d, 0.3), d.multiplyScalar((2.5 + c.rand() * 4) * k), {
6329
+ s: (1 + c.rand() * 1.4) * k,
6330
+ life: 0.8 + c.rand() * 0.7
6331
+ });
6332
+ }
6333
+ for (let j = 0; j < (big ? 30 : 18); j++) {
6334
+ const d2 = new V3(c.rand() - 0.5, 0.4 + c.rand(), c.rand() - 0.5).normalize();
6335
+ kit.spawn(c, "smoke", cen.clone().addScaledVector(d2, 0.6), d2.multiplyScalar(1.5 + c.rand() * 2), {
6336
+ variant: "black",
6337
+ s: (1.4 + c.rand()) * k,
6338
+ life: 4 + c.rand() * 2
6339
+ });
6340
+ }
6313
6341
  }
6314
6342
  I.burst(c, "spark", cen, 40, { speed: 7, spread: 1.6 });
6315
6343
  I.burst(c, "scrap", cen, 14, {
@@ -6322,7 +6350,7 @@ function installExplosion(kit) {
6322
6350
  const G = gm2.userData.glass;
6323
6351
  if (!G || G.broken || !gm2.visible || !gm2.parent) return;
6324
6352
  if (G.type === "laminated") {
6325
- for (let k2 = 0; k2 < 3; k2++) I.crackGlass(c, gm2, I.glassPt ? I.glassPt(c, gm2, c.rand) : gm2.position.clone(), 1.2);
6353
+ for (let k = 0; k < 3; k++) I.crackGlass(c, gm2, I.glassPt ? I.glassPt(c, gm2, c.rand) : gm2.position.clone(), 1.2);
6326
6354
  return;
6327
6355
  }
6328
6356
  I.shatterGlass(c, gm2, 1.4, new V3(0, 1, 0));
@@ -6348,14 +6376,19 @@ function installExplosion(kit) {
6348
6376
  c.emitters.forEach(function(e) {
6349
6377
  if (e.kind === "fire") e.rate = Math.min(e.rate, 7);
6350
6378
  });
6351
- kit.addEmitter(c, ep.clone().add(new V3(0, 0.15, 0)), "fire", { rate: 8, s: 0.8 });
6352
- 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 });
6353
- kit.addEmitter(c, ep.clone().add(new V3(0, 0.9, 0)), "black", { rate: 4, s: 1.4 });
6379
+ if (effects) {
6380
+ startVehicleFire(c, ep.clone().add(new V3(0, 0.15, 0)), 0.55, 30);
6381
+ startVehicleFire(c, new V3(((m.front || 1) + (m.rear || -1)) / 2, (m.clearance || 0.3) + 0.35, 0), 0.45, 25);
6382
+ } else {
6383
+ kit.addEmitter(c, ep.clone().add(new V3(0, 0.15, 0)), "fire", { rate: 8, s: 0.8 });
6384
+ 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 });
6385
+ kit.addEmitter(c, ep.clone().add(new V3(0, 0.9, 0)), "black", { rate: 4, s: 1.4 });
6386
+ }
6354
6387
  c.parts.forEach(function(p) {
6355
6388
  if (p.kind === "glass" || p.kind === "headlight" || p.kind === "taillight" || p.kind === "hood") p.done = true;
6356
6389
  });
6357
6390
  c.log.push({ kind: "explosion", label: kit.t(big ? "blast.tank_explosion" : "blast.explosion") });
6358
- if (big) bigBoomFx(c);
6391
+ if (big && !effects) bigBoomFx(c);
6359
6392
  }
6360
6393
  function tickBoom(c, dt) {
6361
6394
  const B = c.blast;
@@ -11150,6 +11183,11 @@ function createVehicleKit(options) {
11150
11183
  return c;
11151
11184
  }
11152
11185
  kit.dispose = function(c) {
11186
+ if (Array.isArray(c.vfxHandles) && c.vfxHandles.length > 0) {
11187
+ const effects = kit.effects?.();
11188
+ for (const handle of c.vfxHandles) effects?.stop?.(handle);
11189
+ c.vfxHandles = [];
11190
+ }
11153
11191
  const shared = Object.values(I.PARTICLE_GEOMETRIES);
11154
11192
  c.root.traverse(function(o) {
11155
11193
  if (o.isSprite) {
@@ -11271,7 +11309,7 @@ function armourLevelOf(meta, option) {
11271
11309
  }
11272
11310
 
11273
11311
  // src/destructible/impl.ts
11274
- import { ignitionChance, resolveIgnitionRules, sparkTargetFactor } from "@adatechnology/game-contracts";
11312
+ import { chargeFireball, DEFAULT_BLAST_IMPULSE, fireballDose, waveWork, ignitionChance, ignitionDose, resolveIgnitionRules, sparkTargetFactor } from "@adatechnology/game-contracts";
11275
11313
 
11276
11314
  // src/destructible/model.ts
11277
11315
  var JOINT_RULES = {
@@ -11888,6 +11926,9 @@ function buildVehicleModel(kit, c, options = {}) {
11888
11926
  return { parts, joints, hub: hubId, hitch };
11889
11927
  }
11890
11928
 
11929
+ // src/destructible/visual.ts
11930
+ import { DEFERRED_QUEUE_ID, drainDetached } from "@adatechnology/game-contracts";
11931
+
11891
11932
  // src/destructible/subdivide-near.ts
11892
11933
  var SUBDIVIDE_DEPTH = 12;
11893
11934
  function subdivideNear(THREE, params) {
@@ -12102,6 +12143,7 @@ function isDoorSeam(three, params) {
12102
12143
 
12103
12144
  // src/destructible/visual.ts
12104
12145
  var HOLE_DECAL_SCALE = 2.4;
12146
+ var HOLE_BATCH_CAPACITY = 64;
12105
12147
  var DOOR_DEPTH = 0.07;
12106
12148
  var DOOR_SKIN_DEPTH = 0.09;
12107
12149
  var DOOR_FLOOR_DEPTH = 0.2;
@@ -12253,7 +12295,25 @@ var VehicleVisuals = class {
12253
12295
  __publicField(this, "holdFrame", -1);
12254
12296
  /** Normal smoothing still running, by mesh: a mesh cut again gets a new task and the old one is dropped. */
12255
12297
  __publicField(this, "smoothing", /* @__PURE__ */ new Map());
12298
+ /** The bullet holes of one carrier and material, drawn as one instanced batch each (a door full of holes still draws as one). */
12299
+ __publicField(this, "holes", /* @__PURE__ */ new Map());
12256
12300
  __publicField(this, "hood");
12301
+ /** What `pump` drains when no shared queue owns the smoothing: the same steps, timed by `drainDetached`. */
12302
+ __publicField(this, "pumpQueue", {
12303
+ id: DEFERRED_QUEUE_ID.VEHICLE_CREASE,
12304
+ pending: () => this.smoothing.size + (this.warming ? 1 : 0),
12305
+ run: (deadline, clock) => {
12306
+ let ran = 0;
12307
+ for (const [msh, task] of this.smoothing) {
12308
+ if (msh.geometry !== task.geo || task.step(deadline, clock)) this.smoothing.delete(msh);
12309
+ ran++;
12310
+ if (clock() >= deadline) return ran;
12311
+ }
12312
+ this.warmIndexes(deadline, clock);
12313
+ return ran + 1;
12314
+ },
12315
+ flush: () => this.finishAll()
12316
+ });
12257
12317
  ;
12258
12318
  c.smoothLater = (mesh) => this.smoothLater(mesh);
12259
12319
  this.kit = kit;
@@ -13182,19 +13242,44 @@ var VehicleVisuals = class {
13182
13242
  const pane = part?.role === "glass" ? this.panesOf(part).find((g) => g.visible) : void 0;
13183
13243
  if (part?.role === "glass" && (!pane || pane.userData.glass?.broken)) return;
13184
13244
  const radius = Math.max(6e-3, diameter / 2) * HOLE_DECAL_SCALE;
13185
- const m = new THREE.Mesh(holeDiscGeometry(THREE), holeMaterial(this.kit, part?.material ?? "steel"));
13186
- m.scale.set(radius, radius, 1);
13187
13245
  const n = new THREE.Vector3(...normal);
13188
- m.position.set(...point).addScaledVector(n, 3e-3);
13189
- this.c.vehicle.add(m);
13190
- m.lookAt(this.c.vehicle.localToWorld(m.position.clone().add(n)));
13191
- m.userData.decal = true;
13192
- m.userData.noFollow = true;
13193
- m.renderOrder = 3;
13194
- m.raycast = () => {
13195
- };
13196
13246
  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);
13197
- if (carrier) carrier.attach(m);
13247
+ const parent = carrier ?? this.c.vehicle;
13248
+ const material = holeMaterial(this.kit, part?.material ?? "steel");
13249
+ const key = `${parent.uuid}|${material.uuid}`;
13250
+ let batches = this.holes.get(key);
13251
+ let batch = batches?.[batches.length - 1];
13252
+ if (!batch || batch.count >= HOLE_BATCH_CAPACITY) {
13253
+ batch = new THREE.InstancedMesh(holeDiscGeometry(THREE), material, HOLE_BATCH_CAPACITY);
13254
+ batch.count = 0;
13255
+ batch.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
13256
+ batch.castShadow = false;
13257
+ batch.receiveShadow = false;
13258
+ batch.userData.decal = true;
13259
+ batch.userData.noFollow = true;
13260
+ batch.renderOrder = 3;
13261
+ batch.raycast = () => {
13262
+ };
13263
+ batch.frustumCulled = false;
13264
+ parent.add(batch);
13265
+ if (!batches) {
13266
+ batches = [];
13267
+ this.holes.set(key, batches);
13268
+ }
13269
+ batches.push(batch);
13270
+ }
13271
+ const at = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 3e-3));
13272
+ const toward = this.c.vehicle.localToWorld(new THREE.Vector3(...point).addScaledVector(n, 1.003));
13273
+ const pose = new THREE.Object3D();
13274
+ pose.position.copy(at);
13275
+ pose.scale.set(radius, radius, 1);
13276
+ pose.lookAt(toward);
13277
+ pose.updateMatrix();
13278
+ parent.updateWorldMatrix(true, false);
13279
+ const instance = new THREE.Matrix4().copy(parent.matrixWorld).invert().multiply(pose.matrix);
13280
+ batch.setMatrixAt(batch.count, instance);
13281
+ batch.count += 1;
13282
+ batch.instanceMatrix.needsUpdate = true;
13198
13283
  }
13199
13284
  /** The door or lid a hinge group stands for. */
13200
13285
  /** 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. */
@@ -13347,12 +13432,7 @@ var VehicleVisuals = class {
13347
13432
  }
13348
13433
  if (this.queued) return;
13349
13434
  if (!this.smoothing.size && !this.warming) return;
13350
- const deadline = performance.now() + budgetMs;
13351
- for (const [msh, task] of this.smoothing) {
13352
- if (msh.geometry !== task.geo || task.step(deadline)) this.smoothing.delete(msh);
13353
- if (performance.now() >= deadline) return;
13354
- }
13355
- this.warmIndexes(deadline);
13435
+ drainDetached(this.pumpQueue, budgetMs);
13356
13436
  }
13357
13437
  setQueued(isQueued) {
13358
13438
  this.queued = isQueued;
@@ -13368,24 +13448,24 @@ var VehicleVisuals = class {
13368
13448
  return this.smoothing.size + (this.warming ? 1 : 0);
13369
13449
  }
13370
13450
  /** One slice of the pending work, for the shared queue. */
13371
- runStep(deadline) {
13451
+ runStep(deadline, clock) {
13372
13452
  const next = this.smoothing.entries().next();
13373
13453
  if (!next.done) {
13374
13454
  const [msh, task] = next.value;
13375
- if (msh.geometry !== task.geo || task.step(deadline)) this.smoothing.delete(msh);
13455
+ if (msh.geometry !== task.geo || task.step(deadline, clock)) this.smoothing.delete(msh);
13376
13456
  return true;
13377
13457
  }
13378
13458
  if (!this.warming) return false;
13379
- this.warmIndexes(deadline);
13459
+ this.warmIndexes(deadline, clock);
13380
13460
  return true;
13381
13461
  }
13382
13462
  finishAll() {
13383
13463
  while (this.runStep(Infinity)) ;
13384
13464
  }
13385
13465
  /** Measures the triangles of the heavy body meshes once, a slice per frame, so the first panel torn off finds them ready (see `triIndexOf`). */
13386
- warmIndexes(deadline) {
13466
+ warmIndexes(deadline, clock) {
13387
13467
  if (!this.warming) return;
13388
- this.warming = this.warming.filter((msh) => !warmTriIndex(msh.geometry, deadline));
13468
+ this.warming = this.warming.filter((msh) => !warmTriIndex(msh.geometry, deadline, clock));
13389
13469
  if (!this.warming.length) this.warming = null;
13390
13470
  }
13391
13471
  /** Moves the panel of a lost zone out of the body (the kit's torn-off look). */
@@ -13637,9 +13717,12 @@ var ROLE_RESIST = {
13637
13717
  rim: 4
13638
13718
  };
13639
13719
  var BLUNT = { steel: 0.8, aluminium: 1, glass: 1.5, plastic: 1.2, rubber: 0.3 };
13720
+ var SHIELDED_REACH = 0.25;
13721
+ var DENSITY = { steel: 7850, aluminium: 2700, glass: 2500, plastic: 1100, rubber: 1100, wood_hard: 750, fabric: 400 };
13640
13722
  var SHIELDED = /* @__PURE__ */ new Set(["engine", "gearbox", "frame", "radiator", "fuel_tank", "oil_pan", "battery", "alternator", "brakes", "steering", "shocks"]);
13641
13723
  var AMBIENT = 20;
13642
13724
  var FLAME = 700;
13725
+ var FIREBALL_NOTICE = 0.05;
13643
13726
  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 };
13644
13727
  var ARMOUR_STEEL_MM = { IIIA: 4, III: 7 };
13645
13728
  var SOFT_LEAD = 0.8;
@@ -13895,8 +13978,9 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
13895
13978
  for (const j of js) if (!j.open && (j.def.a === d.id || j.def.b === d.id)) openJoint(j, "part_lost", out);
13896
13979
  recomputeGroups();
13897
13980
  };
13898
- const damage = (p, amount, dtype, source, out, cause) => {
13899
- if (p.lost || !(amount > 0)) return;
13981
+ const damage = (p, hitAmount, dtype, source, out, cause, pieces = 1) => {
13982
+ if (p.lost || !(hitAmount > 0)) return;
13983
+ const amount = pieces > 1 ? Math.min(hitAmount * pieces, Math.max(hitAmount, p.hp)) : hitAmount;
13900
13984
  const before = p.hp;
13901
13985
  const crumples = dtype === "blunt" && CRUMPLES.has(p.def.role) && (p.def.material === "steel" || p.def.material === "aluminium");
13902
13986
  const punctures = dtype === "ballistic" && p.def.role === "tyre";
@@ -14003,16 +14087,30 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14003
14087
  if (l?.pud && l.fluid === "fuel") I.igniteFuel(c, l.pud);
14004
14088
  }
14005
14089
  };
14006
- const burningBlast = (centreLocal, radius, energy, source, out) => {
14090
+ const burningBlast = (centreLocal, radius, energy, source, out, tnt = energy * DEFAULT_BLAST_IMPULSE.tntPerJoule) => {
14091
+ let tank = 0;
14007
14092
  for (const d of model.parts) {
14008
14093
  const p = ps.get(d.id);
14009
14094
  if (p.lost) continue;
14010
14095
  const dist = distToBox(d, centreLocal);
14011
14096
  if (dist > radius) continue;
14012
- const base = energy / (1 + dist * dist * 4);
14013
- const shield = SHIELDED.has(d.role) ? 0.25 : 1;
14014
- damage(p, base * (BLUNT[d.material] ?? 1) * shield * 0.04, "explosive", source, out);
14015
- }
14097
+ const work = waveOn(d, centreLocal, dist, tnt);
14098
+ if (d.role === "fuel_tank") tank = work;
14099
+ damage(p, work * (BLUNT[d.material] ?? 1), "explosive", source, out);
14100
+ }
14101
+ return tank;
14102
+ };
14103
+ const waveOn = (d, centreLocal, dist, tnt) => {
14104
+ const [sx, sy, sz] = d.box.size;
14105
+ const toward = new V3(centreLocal.x - d.box.center[0], centreLocal.y - d.box.center[1], centreLocal.z - d.box.center[2]);
14106
+ const length = toward.length();
14107
+ if (length > 1e-6) toward.multiplyScalar(1 / length);
14108
+ else toward.set(0, 1, 0);
14109
+ const area = Math.abs(toward.x) * sy * sz + Math.abs(toward.y) * sx * sz + Math.abs(toward.z) * sx * sy;
14110
+ const face = Math.max(sx * sy, sx * sz, sy * sz, 1e-6);
14111
+ const thickness = Math.min(Math.min(sx, sy, sz), d.mass / ((DENSITY[d.material] ?? 1e3) * face));
14112
+ const wave = waveWork({ tnt, distance: dist, reach: SHIELDED.has(d.role) ? SHIELDED_REACH : 1, area, mass: Math.max(d.mass, 0.05), thickness });
14113
+ return wave.energy + wave.shock;
14016
14114
  };
14017
14115
  const explode = (tank, source, out) => {
14018
14116
  if (exploded) return;
@@ -14022,7 +14120,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14022
14120
  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 } : {} }));
14023
14121
  tank.liters = 0;
14024
14122
  leaks.delete(d.id);
14025
- if (vis) kit.explode(c, { delay: 0.6 });
14123
+ if (vis) kit.explode(c, { delay: 0.6, skipBlastEffect: true });
14026
14124
  else c.blast = c.blast ?? { phase: "fire", t: 0, T: 0.6 };
14027
14125
  lose(tank, "broken", out);
14028
14126
  burningBlast(centreOf(d), spec.radius, spec.energy, source, out);
@@ -14116,6 +14214,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14116
14214
  const d = p.def;
14117
14215
  const E = h.energy ?? 0;
14118
14216
  const cal = h.caliber ?? 9;
14217
+ const pieces = h.pieces ?? 1;
14119
14218
  const dir = dirToLocal(h.direction ?? [0, 0, -1]).normalize();
14120
14219
  const n = h.normal ? dirToLocal(h.normal).normalize() : normalOf(d, v);
14121
14220
  const res = resist(d, p);
@@ -14126,7 +14225,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14126
14225
  if (metal && !through && cosInc < 0.3 && E > 40) {
14127
14226
  const refl = dir.clone().addScaledVector(n, -2 * dir.dot(n));
14128
14227
  out.push(ev({ type: "ricochet", part: d.id, point: worldPoint, direction: r3(dirToWorld(refl)), energy: r2(E * 0.4) }));
14129
- damage(p, E * 0.05, "ballistic", h.source, out, worldPoint);
14228
+ damage(p, E * 0.05, "ballistic", h.source, out, worldPoint, pieces);
14130
14229
  vis?.spark([v.x, v.y, v.z], [refl.x, refl.y, refl.z], 6);
14131
14230
  return;
14132
14231
  }
@@ -14157,13 +14256,13 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14157
14256
  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) };
14158
14257
  p.cracks.push(crack);
14159
14258
  out.push(ev({ type: "crack", part: d.id, crack, worldPoint }));
14160
- damage(p, E * (armourLevel && !through ? armourLevel.glassTakes : 0.5), "ballistic", h.source, out, worldPoint);
14161
- } else damage(p, laminated ? E * 0.5 : p.hp, "ballistic", h.source, out, worldPoint);
14259
+ damage(p, E * (armourLevel && !through ? armourLevel.glassTakes : 0.5), "ballistic", h.source, out, worldPoint, pieces);
14260
+ } else damage(p, laminated ? E * 0.5 : p.hp, "ballistic", h.source, out, worldPoint, laminated ? pieces : 1);
14162
14261
  break;
14163
14262
  }
14164
14263
  case "rubber": {
14165
14264
  push(through);
14166
- damage(p, E * 0.4, "ballistic", h.source, out, worldPoint);
14265
+ damage(p, E * 0.4, "ballistic", h.source, out, worldPoint, pieces);
14167
14266
  if (through && !p.lost && !p.flat) {
14168
14267
  if (E >= TYRE_BURST_JOULES || cal >= TYRE_BURST_CALIBER) deflate(p, 1);
14169
14268
  else p.airLoss += TYRE_LEAK_PER_MM2 * Math.PI * (cal / 2) ** 2;
@@ -14180,7 +14279,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14180
14279
  vis?.spark([v.x, v.y, v.z], [dir.x, dir.y, dir.z], through ? 4 : 8);
14181
14280
  let amount = through ? E * 0.6 : E * 0.25;
14182
14281
  if (through && (d.role === "battery" || d.role === "alternator")) amount = Math.max(amount, p.hp * 0.65);
14183
- damage(p, amount, "ballistic", h.source, out, worldPoint);
14282
+ damage(p, amount, "ballistic", h.source, out, worldPoint, pieces);
14184
14283
  if (through && d.role === "fuel_tank") rollIgnition(p, h, metal, out);
14185
14284
  }
14186
14285
  }
@@ -14251,12 +14350,12 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14251
14350
  const nearest = Math.min(...model.parts.map((d) => distToBox(d, v)));
14252
14351
  if (nearest > radius) return;
14253
14352
  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 });
14254
- burningBlast(v, radius, E, h.source, out);
14353
+ const tankWork = burningBlast(v, radius, E, h.source, out, h.tnt);
14255
14354
  const tank = [...ps.values()].find((q) => q.def.role === "fuel_tank" && !q.lost);
14256
14355
  if (tank && !exploded) {
14257
14356
  const dist = distToBox(tank.def, v);
14258
14357
  if (dist <= radius) {
14259
- const verdict = kit.blastDamage(c, E / (1 + dist * dist * 4) / 50);
14358
+ const verdict = kit.blastDamage(c, tankWork);
14260
14359
  if (verdict === "explosion") explode(tank, h.source, out);
14261
14360
  else if (verdict === "fire") {
14262
14361
  light(tank, out);
@@ -14264,7 +14363,14 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14264
14363
  }
14265
14364
  }
14266
14365
  }
14267
- heat(v, radius * 0.5, 450, 1, out);
14366
+ const fireball = h.fireball ?? chargeFireball(E * DEFAULT_BLAST_IMPULSE.tntPerJoule);
14367
+ for (const d of model.parts) {
14368
+ const p = ps.get(d.id);
14369
+ if (p.lost || !d.ignitionC) continue;
14370
+ const needed = ignitionDose(d.ignitionC, AMBIENT);
14371
+ const share = Math.min(1, fireballDose(fireball, distToBox(d, v)) / needed);
14372
+ if (share >= FIREBALL_NOTICE) p.temp = Math.max(p.temp, AMBIENT + (d.ignitionC + 1 - AMBIENT) * share);
14373
+ }
14268
14374
  };
14269
14375
  const fireHit = (h, out) => {
14270
14376
  sync();
@@ -14660,6 +14766,7 @@ function createVehicleDestructible(kit, vehicleCtx, options = {}) {
14660
14766
  joints: js.map((j) => [j.def.id, j.hp, j.progress, j.open, j.by ?? null])
14661
14767
  }),
14662
14768
  partName: (pid) => ps.get(pid)?.def.name ?? pid,
14769
+ objectsOf: (pid) => vis?.objectsOf(pid) ?? [],
14663
14770
  status: computeStatus,
14664
14771
  animations: () => createVehicleClips(model, vis, kit, c),
14665
14772
  crumple: (point, direction, depth) => {
@@ -14755,14 +14862,14 @@ function buildVehicleItem(kit, key, options = {}) {
14755
14862
  }
14756
14863
 
14757
14864
  // src/destructible/crease-queue.ts
14758
- import { DEFERRED_QUEUE_ID } from "@adatechnology/game-contracts";
14865
+ import { DEFERRED_QUEUE_ID as DEFERRED_QUEUE_ID2 } from "@adatechnology/game-contracts";
14759
14866
  function createCreaseQueue() {
14760
14867
  const tracked = [];
14761
14868
  let cursor = 0;
14762
14869
  let lastFrame;
14763
14870
  let attached = false;
14764
14871
  const deferred = {
14765
- id: DEFERRED_QUEUE_ID.VEHICLE_CREASE,
14872
+ id: DEFERRED_QUEUE_ID2.VEHICLE_CREASE,
14766
14873
  pending(frame) {
14767
14874
  lastFrame = frame;
14768
14875
  let units = 0;
@@ -14776,7 +14883,7 @@ function createCreaseQueue() {
14776
14883
  if (ran > 0 && clock() >= deadline) break;
14777
14884
  const work = tracked[cursor % tracked.length];
14778
14885
  cursor = (cursor + 1) % tracked.length;
14779
- if (work.pendingUnits(lastFrame) > 0 && work.runStep(deadline)) {
14886
+ if (work.pendingUnits(lastFrame) > 0 && work.runStep(deadline, clock)) {
14780
14887
  ran++;
14781
14888
  skipped = 0;
14782
14889
  } else skipped++;
@@ -14921,10 +15028,139 @@ function cabinEnclosure(source, options = {}) {
14921
15028
  leak
14922
15029
  };
14923
15030
  }
15031
+
15032
+ // src/data/cabin.json
15033
+ var cabin_default = {
15034
+ 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)",
15035
+ entryDuckFactor: 0.44,
15036
+ categories: {
15037
+ passenger_car: {
15038
+ frontHeadroomMetres: 0.95,
15039
+ rearHeadroomMetres: 0.9,
15040
+ frontLegroomMetres: 0.62,
15041
+ widthMetres: 0.52,
15042
+ door: { widthMetres: 0.65, heightMetres: 0.8 }
15043
+ },
15044
+ suv_pickup: {
15045
+ frontHeadroomMetres: 0.98,
15046
+ rearHeadroomMetres: 0.93,
15047
+ frontLegroomMetres: 0.64,
15048
+ widthMetres: 0.54,
15049
+ door: { widthMetres: 0.7, heightMetres: 0.82 }
15050
+ },
15051
+ van: {
15052
+ frontHeadroomMetres: 1.05,
15053
+ rearHeadroomMetres: 1.05,
15054
+ frontLegroomMetres: 0.65,
15055
+ widthMetres: 0.54,
15056
+ door: { widthMetres: 0.75, heightMetres: 0.95 }
15057
+ },
15058
+ truck: {
15059
+ frontHeadroomMetres: 1,
15060
+ rearHeadroomMetres: 1,
15061
+ frontLegroomMetres: 0.62,
15062
+ widthMetres: 0.52,
15063
+ door: { widthMetres: 0.65, heightMetres: 0.85 }
15064
+ },
15065
+ bus: {
15066
+ frontHeadroomMetres: 1.2,
15067
+ rearHeadroomMetres: 1.2,
15068
+ frontLegroomMetres: 0.62,
15069
+ widthMetres: 0.5,
15070
+ door: { widthMetres: 0.7, heightMetres: 1.75 }
15071
+ },
15072
+ agricultural: {
15073
+ frontHeadroomMetres: 1.05,
15074
+ rearHeadroomMetres: null,
15075
+ frontLegroomMetres: 0.62,
15076
+ widthMetres: 0.52,
15077
+ door: { widthMetres: 0.65, heightMetres: 0.9 }
15078
+ },
15079
+ military_light: {
15080
+ frontHeadroomMetres: 0.95,
15081
+ rearHeadroomMetres: 0.92,
15082
+ frontLegroomMetres: 0.62,
15083
+ widthMetres: 0.5,
15084
+ door: { widthMetres: 0.6, heightMetres: 0.8 }
15085
+ },
15086
+ military_armored: {
15087
+ frontHeadroomMetres: 0.88,
15088
+ rearHeadroomMetres: 0.88,
15089
+ frontLegroomMetres: 0.58,
15090
+ widthMetres: 0.46,
15091
+ door: { widthMetres: 0.5, heightMetres: 0.55 }
15092
+ },
15093
+ open_vehicle: {
15094
+ frontHeadroomMetres: null,
15095
+ rearHeadroomMetres: null,
15096
+ frontLegroomMetres: null,
15097
+ widthMetres: null,
15098
+ door: null
15099
+ },
15100
+ boat_cabin: {
15101
+ frontHeadroomMetres: 1.05,
15102
+ rearHeadroomMetres: 1.05,
15103
+ frontLegroomMetres: 0.62,
15104
+ widthMetres: 0.52,
15105
+ door: { widthMetres: 0.6, heightMetres: 0.9 }
15106
+ },
15107
+ aircraft_enclosed: {
15108
+ frontHeadroomMetres: 0.95,
15109
+ rearHeadroomMetres: 0.92,
15110
+ frontLegroomMetres: 0.62,
15111
+ widthMetres: 0.48,
15112
+ door: { widthMetres: 0.55, heightMetres: 0.8 }
15113
+ }
15114
+ }
15115
+ };
15116
+
15117
+ // src/cabin.ts
15118
+ var CABIN_CATEGORIES = [
15119
+ "passenger_car",
15120
+ "suv_pickup",
15121
+ "van",
15122
+ "truck",
15123
+ "bus",
15124
+ "agricultural",
15125
+ "military_light",
15126
+ "military_armored",
15127
+ "open_vehicle",
15128
+ "boat_cabin",
15129
+ "aircraft_enclosed"
15130
+ ];
15131
+ var toClearance = (value) => value === null ? Number.POSITIVE_INFINITY : value;
15132
+ var toCabinMinimum = (category, raw) => {
15133
+ if (category === "open_vehicle") {
15134
+ return {
15135
+ frontHeadroomMetres: Number.POSITIVE_INFINITY,
15136
+ rearHeadroomMetres: Number.POSITIVE_INFINITY,
15137
+ frontLegroomMetres: Number.POSITIVE_INFINITY,
15138
+ widthMetres: Number.POSITIVE_INFINITY,
15139
+ door: void 0
15140
+ };
15141
+ }
15142
+ return {
15143
+ frontHeadroomMetres: toClearance(raw.frontHeadroomMetres),
15144
+ rearHeadroomMetres: raw.rearHeadroomMetres === null ? void 0 : raw.rearHeadroomMetres,
15145
+ frontLegroomMetres: toClearance(raw.frontLegroomMetres),
15146
+ widthMetres: toClearance(raw.widthMetres),
15147
+ door: raw.door === null ? void 0 : { widthMetres: raw.door.widthMetres, heightMetres: raw.door.heightMetres }
15148
+ };
15149
+ };
15150
+ var CABIN_SOURCE = cabin_default.source;
15151
+ var ENTRY_DUCK_FACTOR = cabin_default.entryDuckFactor;
15152
+ var CABIN_MINIMUMS = Object.fromEntries(
15153
+ CABIN_CATEGORIES.map((category) => [category, toCabinMinimum(category, cabin_default.categories[category])])
15154
+ );
15155
+ var cabinMinimumOf = (category) => CABIN_MINIMUMS[category];
14924
15156
  export {
14925
15157
  ARMOUR_LEVELS,
15158
+ CABIN_CATEGORIES,
14926
15159
  CABIN_LEAK,
15160
+ CABIN_MINIMUMS,
15161
+ CABIN_SOURCE,
14927
15162
  CRASH_RULES,
15163
+ ENTRY_DUCK_FACTOR,
14928
15164
  JOINT_RULES,
14929
15165
  LEGACY_STATES,
14930
15166
  LEGACY_ZONE_IDS,
@@ -14934,6 +15170,7 @@ export {
14934
15170
  buildVehicleModel,
14935
15171
  cabinBoxOf,
14936
15172
  cabinEnclosure,
15173
+ cabinMinimumOf,
14937
15174
  clamp,
14938
15175
  crackedGlassMaterial,
14939
15176
  crashDeltaV,