@adatechnology/game-vehicles-three 0.9.10 → 0.9.12

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.
@@ -34491,6 +34491,49 @@ var GameVehiclesThree = (() => {
34491
34491
  Object.assign(I, shared2);
34492
34492
  return shared2;
34493
34493
  }
34494
+ var SmokeCause = { STEAM: "steam", OIL: "oil", FIRE: "fire" };
34495
+ var SMOKE_LOOKS = {
34496
+ [SmokeCause.STEAM]: { color: 14870248, alpha: 0.18 },
34497
+ [SmokeCause.OIL]: { color: 11120306, alpha: 0.2 },
34498
+ [SmokeCause.FIRE]: { color: 2302756, alpha: 0.3 }
34499
+ };
34500
+ var CAUSE_OF_EMITTER = { white: SmokeCause.STEAM, oil: SmokeCause.OIL, black: SmokeCause.FIRE };
34501
+ var smokeCauseOfEmitter = (kind) => CAUSE_OF_EMITTER[kind];
34502
+ var RATE_AT_NO_DAMAGE = 0.25;
34503
+ var RATE_AT_WRECK = 1;
34504
+ function smokeRate(baseRate, damage) {
34505
+ const level = Math.min(1, Math.max(0, damage));
34506
+ return baseRate * (RATE_AT_NO_DAMAGE + (RATE_AT_WRECK - RATE_AT_NO_DAMAGE) * level);
34507
+ }
34508
+ var PLUME_PUFFS = 3;
34509
+ var SMOKE_WIND = [-0.45, 0, 0.16];
34510
+ var LIFT = { [SmokeCause.STEAM]: 0.5, [SmokeCause.OIL]: 0.45, [SmokeCause.FIRE]: 0.6 };
34511
+ var DRAG = 0.4;
34512
+ var VENT_CLEARANCE = 0.08;
34513
+ var VENT_SPREAD = 0.18;
34514
+ var jitter = (random, span) => (random() - 0.5) * 2 * span;
34515
+ function smokePuff(params) {
34516
+ const { cause, scale, random } = params;
34517
+ const wind = params.wind ?? SMOKE_WIND;
34518
+ const look = SMOKE_LOOKS[cause];
34519
+ const isFire = cause === SmokeCause.FIRE;
34520
+ return {
34521
+ offset: [jitter(random, VENT_SPREAD * scale), random() * 0.05, jitter(random, VENT_SPREAD * scale)],
34522
+ velocity: [wind[0] + jitter(random, 0.22), 0.55 + random() * 0.5, wind[2] + jitter(random, 0.22)],
34523
+ size: (isFire ? 0.2 : 0.14) * scale * (0.8 + random() * 0.4),
34524
+ growth: (isFire ? 6 : 5) + random() * 2,
34525
+ life: (isFire ? 3.4 : 2.6) + random() * 1.2,
34526
+ color: look.color,
34527
+ alpha: look.alpha * (0.8 + random() * 0.4),
34528
+ lift: LIFT[cause],
34529
+ drag: DRAG
34530
+ };
34531
+ }
34532
+ function engineBayVent(box2) {
34533
+ const [cx, cy, cz] = box2.center;
34534
+ const [sx, sy] = box2.size;
34535
+ return [cx + sx * 0.15, cy + sy / 2 + VENT_CLEARANCE, cz];
34536
+ }
34494
34537
  var ROUTED_PARTICLE_TYPES = { smoke: "particle_puff", dust: "particle_puff", fire: "particle_glow" };
34495
34538
  var PUFF_LOOKS = {
34496
34539
  smokewhite: [10133927, 0.42],
@@ -34509,7 +34552,7 @@ var GameVehiclesThree = (() => {
34509
34552
  const life = input.life ?? LIFE[type] ?? 99;
34510
34553
  const size = (input.size ?? 1) * (input.grow ?? 1);
34511
34554
  const isFire = type === "fire";
34512
- const growth = isFire ? 1 : (SMOKE_START_SCALE + 1.5 * (1 - Math.exp(-life * 1.1)) + life * 0.12) / SMOKE_START_SCALE;
34555
+ const growth = input.growth ?? (isFire ? 1 : (SMOKE_START_SCALE + 1.5 * (1 - Math.exp(-life * 1.1)) + life * 0.12) / SMOKE_START_SCALE);
34513
34556
  return {
34514
34557
  effect: ROUTED_PARTICLE_TYPES[type],
34515
34558
  point: input.position,
@@ -34518,12 +34561,12 @@ var GameVehiclesThree = (() => {
34518
34561
  vy: input.velocity[1],
34519
34562
  vz: input.velocity[2],
34520
34563
  life,
34521
- size: isFire ? size * 0.85 : size * SMOKE_START_SCALE,
34564
+ size: input.growth !== void 0 ? size : isFire ? size * 0.85 : size * SMOKE_START_SCALE,
34522
34565
  grow: growth,
34523
34566
  color: input.color ?? (isFire ? FIRE_COLOR : look[0]),
34524
34567
  alpha: input.alpha ?? look[1],
34525
- gravity: isFire ? 0 : type === "dust" ? 0 : -0.08,
34526
- drag: type === "dust" ? 2.5 : isFire ? 1.5 : 0.9
34568
+ gravity: input.gravity ?? (isFire ? 0 : type === "dust" ? 0 : -0.08),
34569
+ drag: input.drag ?? (type === "dust" ? 2.5 : isFire ? 1.5 : 0.9)
34527
34570
  }
34528
34571
  };
34529
34572
  }
@@ -34674,7 +34717,10 @@ var GameVehiclesThree = (() => {
34674
34717
  ...o.op != null ? { alpha: o.op } : {},
34675
34718
  ...o.s ? { size: o.s } : {},
34676
34719
  ...o.life ? { life: o.life } : {},
34677
- ...o.grow ? { grow: o.grow } : {}
34720
+ ...o.grow ? { grow: o.grow } : {},
34721
+ ...o.growth ? { growth: o.growth } : {},
34722
+ ...o.lift != null ? { gravity: -o.lift } : {},
34723
+ ...o.drag != null ? { drag: o.drag } : {}
34678
34724
  })
34679
34725
  );
34680
34726
  return null;
@@ -34729,7 +34775,8 @@ var GameVehiclesThree = (() => {
34729
34775
  r: o.r || 0.01,
34730
34776
  spin: (c.rand() - 0.5) * 1.2,
34731
34777
  ph: c.rand() * 6.28,
34732
- grow: o.grow || 1
34778
+ grow: o.grow || 1,
34779
+ growth: o.growth || 0
34733
34780
  };
34734
34781
  c.particles.push(P);
34735
34782
  return P;
@@ -34770,7 +34817,7 @@ var GameVehiclesThree = (() => {
34770
34817
  m.position.addScaledVector(P.v, dt);
34771
34818
  m.position.x += Math.sin(P.age * 1.7 + P.ph) * 0.08 * dt;
34772
34819
  m.position.z += Math.cos(P.age * 1.3 + P.ph) * 0.08 * dt;
34773
- const gs = P.s0 * P.grow * (0.18 + 1.5 * (1 - Math.exp(-P.age * 1.1)) + P.age * 0.12);
34820
+ const gs = P.growth ? P.s0 * (1 + (P.growth - 1) * t) : P.s0 * P.grow * (0.18 + 1.5 * (1 - Math.exp(-P.age * 1.1)) + P.age * 0.12);
34774
34821
  m.scale.set(gs, gs, 1);
34775
34822
  m.material.rotation += P.spin * dt;
34776
34823
  m.material.opacity = P.op * Math.min(1, P.age / 0.3);
@@ -34846,7 +34893,8 @@ var GameVehiclesThree = (() => {
34846
34893
  acc: 0,
34847
34894
  s: o.s || 1,
34848
34895
  dir: o.dir || null,
34849
- gap: 0
34896
+ gap: 0,
34897
+ ...o.damage ? { damage: o.damage } : {}
34850
34898
  };
34851
34899
  c.emitters.push(e);
34852
34900
  return e;
@@ -34858,7 +34906,31 @@ var GameVehiclesThree = (() => {
34858
34906
  return ["#141414", 0.66];
34859
34907
  }
34860
34908
  kit.exhaustLook = exhaustLook;
34909
+ function spawnSmokePuff(c, cause, scale, vent) {
34910
+ for (let k = 0; k < PLUME_PUFFS; k++) {
34911
+ const puff = smokePuff({ cause, scale, random: c.rand });
34912
+ const at = vent.clone().add(c.dirToEffects(new V3(puff.offset[0], puff.offset[1], puff.offset[2])));
34913
+ kit.spawn(c, "smoke", at, new V3(puff.velocity[0], puff.velocity[1], puff.velocity[2]), {
34914
+ col: puff.color,
34915
+ op: puff.alpha,
34916
+ s: puff.size,
34917
+ life: puff.life,
34918
+ growth: puff.growth,
34919
+ lift: puff.lift,
34920
+ drag: puff.drag
34921
+ });
34922
+ }
34923
+ }
34924
+ function spawnOwnSmokePuff(c, e, p) {
34925
+ const black = e.kind === "black" || e.kind === "oil";
34926
+ kit.spawn(c, "smoke", p, new V3((c.rand() - 0.5) * 0.2, black ? 0.9 + c.rand() * 0.3 : 1.1 + c.rand() * 0.3, (c.rand() - 0.5) * 0.2), {
34927
+ variant: black ? "black" : "steam",
34928
+ s: (black ? 0.75 : 0.6) * e.s * (0.8 + c.rand() * 0.4),
34929
+ life: black ? 3.2 : 2
34930
+ });
34931
+ }
34861
34932
  function tickEmit(c, dt) {
34933
+ const plume = !!kit.effects?.();
34862
34934
  c.emitters.forEach(function(e) {
34863
34935
  if (e.kind === "exhaust") {
34864
34936
  const h = c.engineHealth == null ? 1 : c.engineHealth;
@@ -34869,7 +34941,7 @@ var GameVehiclesThree = (() => {
34869
34941
  if (e.gap > 0) return;
34870
34942
  }
34871
34943
  }
34872
- e.acc += e.rate * dt;
34944
+ e.acc += (plume && e.damage ? smokeRate(e.rate, e.damage()) : e.rate) * dt;
34873
34945
  while (e.acc >= 1) {
34874
34946
  e.acc -= 1;
34875
34947
  const p = e.world ? e.p.clone() : c.toEffects(e.p);
@@ -34882,8 +34954,10 @@ var GameVehiclesThree = (() => {
34882
34954
  s: (0.45 + c.rand() * 0.45) * e.s,
34883
34955
  life: 0.55 + c.rand() * 0.35
34884
34956
  });
34885
- if (c.rand() < 0.45)
34886
- kit.spawn(c, "smoke", p.clone().add(new V3(0, 0.7 * e.s, 0)), new V3(0, 1, 0), { variant: "black", s: 0.9 * e.s, life: 3.2 });
34957
+ if (c.rand() < 0.45) {
34958
+ if (plume) spawnSmokePuff(c, SmokeCause.FIRE, e.s, p.clone().add(new V3(0, 0.5 * e.s, 0)));
34959
+ else kit.spawn(c, "smoke", p.clone().add(new V3(0, 0.7 * e.s, 0)), new V3(0, 1, 0), { variant: "black", s: 0.9 * e.s, life: 3.2 });
34960
+ }
34887
34961
  if (c.rand() < 0.15)
34888
34962
  kit.spawn(
34889
34963
  c,
@@ -34902,14 +34976,9 @@ var GameVehiclesThree = (() => {
34902
34976
  life: 1.4 + c.rand() * 0.5
34903
34977
  });
34904
34978
  } else {
34905
- const preta = e.kind === "black";
34906
- kit.spawn(
34907
- c,
34908
- "smoke",
34909
- p,
34910
- new V3((c.rand() - 0.5) * 0.2, preta ? 0.9 + c.rand() * 0.3 : 1.1 + c.rand() * 0.3, (c.rand() - 0.5) * 0.2),
34911
- { variant: preta ? "black" : "steam", s: (preta ? 0.75 : 0.6) * e.s * (0.8 + c.rand() * 0.4), life: preta ? 3.2 : 2 }
34912
- );
34979
+ const cause = smokeCauseOfEmitter(e.kind);
34980
+ if (cause && plume) spawnSmokePuff(c, cause, e.s, p);
34981
+ else spawnOwnSmokePuff(c, e, p);
34913
34982
  }
34914
34983
  }
34915
34984
  });
@@ -35878,7 +35947,7 @@ var GameVehiclesThree = (() => {
35878
35947
  kit.addEmitter(c, pt.pos.clone().add(new V3(-0.1, 0.25, 0)), "white");
35879
35948
  hurtEngine(c, 0.6);
35880
35949
  } else if (k === "engine") {
35881
- kit.addEmitter(c, pt.pos.clone().add(new V3(0, 0.3, 0)), "black");
35950
+ kit.addEmitter(c, pt.pos.clone().add(new V3(0, 0.3, 0)), "oil", { rate: 6, damage: () => 1 - (c.engineHealth ?? 1) });
35882
35951
  hurtEngine(c, force > 1.1 ? 0.1 : 0.3);
35883
35952
  if (c.hood && force > 0.5 && !c.hood.noLatch) {
35884
35953
  c.hood.latch = Math.max(c.hood.latch, 0.15);
@@ -38974,7 +39043,7 @@ var GameVehiclesThree = (() => {
38974
39043
  }
38975
39044
  if (b >= 3) {
38976
39045
  I.hurtEngine(c, b === 4 ? 0.05 : 0.25);
38977
- kit.addEmitter(c, p.clone().add(new V3(0, 0.3, 0)), "black", { rate: b === 4 ? 6 : 4 });
39046
+ kit.addEmitter(c, p.clone().add(new V3(0, 0.3, 0)), "oil", { rate: b === 4 ? 6 : 4, damage: () => 1 - (c.engineHealth ?? 1) });
38978
39047
  if (land) I.puddle(c, "oil", p.clone().setY(Math.max(0.2, m.clearance || 0.3)), b === 4 ? 0.9 : 0.6);
38979
39048
  }
38980
39049
  if (b === 4) kit.addEmitter(c, p.clone().add(new V3(0, 0.15, 0)), "fire", { rate: 7, s: 0.7 });
@@ -42524,7 +42593,7 @@ var GameVehiclesThree = (() => {
42524
42593
  if (!z) return;
42525
42594
  const B = z.box;
42526
42595
  const THREE = this.THREE;
42527
- const mats = this.I.MATERIALS;
42596
+ const lining = this.I.makeMaterial(DOOR_CARD_COLOR, { roughness: 0.85 });
42528
42597
  const grid = (a0, a1, b0, b1) => {
42529
42598
  const out = [];
42530
42599
  for (const fa of [0.25, 0.5, 0.75]) for (const fb of [0.3, 0.7]) out.push([a0 + (a1 - a0) * fa, b0 + (b1 - b0) * fb]);
@@ -42539,7 +42608,7 @@ var GameVehiclesThree = (() => {
42539
42608
  const hingeFront = z.hinge !== "rear";
42540
42609
  const hx = hingeFront ? B.x1 - 0.03 : B.x0 + 0.03;
42541
42610
  const cy = (B.y0 + B.y1) / 2;
42542
- const recess = this.box(len - 0.04, hgt - 0.04, 0.01, mats.dark, (B.x0 + B.x1) / 2, cy, sk + s * 4e-3);
42611
+ const recess = this.box(len - 0.04, hgt - 0.04, 0.01, lining, (B.x0 + B.x1) / 2, cy, sk + s * 4e-3);
42543
42612
  recess.userData.noFollow = true;
42544
42613
  const piv = new THREE.Group();
42545
42614
  piv.name = p.id;
@@ -42556,7 +42625,7 @@ var GameVehiclesThree = (() => {
42556
42625
  if (sk == null) return;
42557
42626
  const wy = B.y1 - B.y0 - 0.1;
42558
42627
  const wz = B.z1 - B.z0 - 0.1;
42559
- const recess = this.box(0.01, wy - 0.04, wz - 0.04, mats.dark, sk + 4e-3, (B.y0 + B.y1) / 2, 0);
42628
+ const recess = this.box(0.01, wy - 0.04, wz - 0.04, lining, sk + 4e-3, (B.y0 + B.y1) / 2, 0);
42560
42629
  recess.userData.noFollow = true;
42561
42630
  const piv = new THREE.Group();
42562
42631
  piv.name = p.id;
@@ -42580,16 +42649,16 @@ var GameVehiclesThree = (() => {
42580
42649
  if (busy) return;
42581
42650
  const r = piv.rotation;
42582
42651
  const open = Math.abs(r.x) + Math.abs(r.y) + Math.abs(r.z) > 1e-3 || this.gone.has(id) || piv.parent !== this.c.vehicle;
42583
- if (open && !this.gone.has(id) && piv.parent === this.c.vehicle && !this.skins.has(id)) {
42652
+ if (open && piv.parent === this.c.vehicle && !this.skins.has(id)) {
42584
42653
  busy = true;
42585
42654
  try {
42586
- this.skins.set(id, this.takeSkin(id, piv));
42655
+ this.skins.set(id, this.takeSkin(id, piv, this.gone.has(id)));
42587
42656
  } finally {
42588
42657
  busy = false;
42589
42658
  }
42590
42659
  }
42591
42660
  panel.visible = open && !this.skins.get(id);
42592
- recess.visible = open && !this.skins.get(id);
42661
+ recess.visible = open && !this.skins.get(id) && !this.gone.has(id);
42593
42662
  if (open) this.openNow.add(id);
42594
42663
  else this.openNow.delete(id);
42595
42664
  this.seams.forEach((doors, seam) => {
@@ -42615,7 +42684,7 @@ var GameVehiclesThree = (() => {
42615
42684
  * Cuts the skin of a door or lid zone out of the body (as the damage's hanging door does) and hangs it, with the thin parts on it (trim, handle) and, for a door, the side
42616
42685
  * window over it, on the hinge. Done with the hinge closed, so every piece keeps its place; answers whether there was skin to take.
42617
42686
  */
42618
- takeSkin(id, piv) {
42687
+ takeSkin(id, piv, torn = false) {
42619
42688
  const p = this.byId.get(id);
42620
42689
  const z = p && this.zone(p);
42621
42690
  if (!p || !z) return false;
@@ -42635,7 +42704,8 @@ var GameVehiclesThree = (() => {
42635
42704
  this.doorTops.set(id, top);
42636
42705
  const rect = [B.x0 + 0.03, B.x1 - 0.03, B.y0 + Math.min(0.08, (B.y1 - B.y0) * 0.1), top];
42637
42706
  const pcs = I.cutPanel(this.c, z, rect, true, dirty, { anyN: true }).map((x) => x.mesh).filter((m) => !!m);
42638
- this.mend(dirty);
42707
+ if (torn) this.mendLater(dirty);
42708
+ else this.mend(dirty);
42639
42709
  if (pcs.length) {
42640
42710
  leaveDeepSkinOnBody(this.THREE, pcs, { toVehicle: inv, side: z.side < 0 ? -1 : 1, depth: DOOR_SKIN_DEPTH });
42641
42711
  const panes = I.windowsOver(this.c, z, inv);
@@ -43586,13 +43656,16 @@ var GameVehiclesThree = (() => {
43586
43656
  else this.I.panelBand(this.c, z, 4, dirty);
43587
43657
  } catch {
43588
43658
  }
43659
+ this.mendLater(dirty);
43660
+ this.gone.add(p.id);
43661
+ }
43662
+ mendLater(dirty) {
43589
43663
  dirty.forEach((msh) => {
43590
43664
  const g = msh.geometry;
43591
43665
  if (g.userData.crease || !g.index) this.smoothLater(msh);
43592
43666
  else g.computeVertexNormals();
43593
43667
  this.I.refreshBounds(g);
43594
43668
  });
43595
- this.gone.add(p.id);
43596
43669
  }
43597
43670
  // ---- parts coming off --------------------------------------------------------------------------------------------------------------------
43598
43671
  outward(p, away) {
@@ -43849,6 +43922,8 @@ var GameVehiclesThree = (() => {
43849
43922
  var TYRE_FLAT_AIR = 0.2;
43850
43923
  var BRAKE_FLUID_NEEDED = 0.6;
43851
43924
  var BRAKE_NO_FLUID = 0.15;
43925
+ var ENGINE_SMOKE_FROM = 0.85;
43926
+ var ENGINE_OIL_SMOKE_RATE = 4;
43852
43927
  var ENGINE_WORKING_C = 90;
43853
43928
  var ENGINE_SETTLE_S = 30;
43854
43929
  var ENGINE_HEATING = 0.5;
@@ -44092,6 +44167,7 @@ var GameVehiclesThree = (() => {
44092
44167
  out.push(ev({ type: "damage", part: p.def.id, amount: r2(before - p.hp), hp: r2(p.hp), damageType: dtype, ...source ? { source } : {} }));
44093
44168
  if (!punctures) wear(p, amount, out);
44094
44169
  syncZone(p);
44170
+ if (vis && p.def.role === "engine" && p.hp < p.def.hp * ENGINE_SMOKE_FROM) smokeFromBay(p, "oil", ENGINE_OIL_SMOKE_RATE);
44095
44171
  if (p.hp <= 0) lose(p, "broken", out, cause);
44096
44172
  else if (p.def.role === "light") vis?.crackLight(p.def, dtype === "ballistic");
44097
44173
  if (p.def.role === "tyre" && !p.flat && p.hp < p.def.hp * 0.6 && !p.lost) {
@@ -44176,6 +44252,10 @@ var GameVehiclesThree = (() => {
44176
44252
  const out3 = dirToWorld(new V3(dirLocal.x * 0.5, dirLocal.y * 0.5 - 0.6, dirLocal.z * 0.5));
44177
44253
  out.push(ev({ type: "leak", part: d.id, fluid, point: toWorld(holePoint), direction: r3(out3), rate: r2(rate), pressurized: !!d.contains.pressurized }));
44178
44254
  };
44255
+ const smokeFromBay = (p, kind, rate) => {
44256
+ const [x, y, z] = engineBayVent(p.def.box);
44257
+ kit.addEmitter(c, new V3(x, y, z), kind, { rate, damage: () => 1 - p.hp / p.def.hp });
44258
+ };
44179
44259
  const centreOf = (d) => new V3(d.box.center[0], d.box.center[1], d.box.center[2]);
44180
44260
  const ignite = (p, out) => {
44181
44261
  if (p.burning || p.lost) return;
@@ -44185,7 +44265,8 @@ var GameVehiclesThree = (() => {
44185
44265
  if (!vis) return;
44186
44266
  const cen = centreOf(d);
44187
44267
  kit.addEmitter(c, cen.clone().add(new V3(0, 0.1, 0)), "fire", { rate: d.role === "tyre" ? 7 : 10, s: d.role === "tyre" ? 0.6 : 0.9 });
44188
- kit.addEmitter(c, cen.clone().add(new V3(0, 0.6, 0)), "black", { rate: 4, s: 1.1 });
44268
+ if (d.role === "engine") smokeFromBay(p, "black", 5);
44269
+ else kit.addEmitter(c, cen.clone().add(new V3(0, 0.6, 0)), "black", { rate: 4, s: 1.1 });
44189
44270
  if (d.role === "fuel_tank" || d.role === "engine") {
44190
44271
  const l = leaks.get("fuel_tank");
44191
44272
  if (l?.pud && l.fluid === "fuel") I.igniteFuel(c, l.pud);
@@ -44916,7 +44997,7 @@ var GameVehiclesThree = (() => {
44916
44997
  if (oil < OIL_NEEDED) engine.hp = Math.max(0, engine.hp - engine.def.hp * OIL_WEAR * work * seconds * ((OIL_NEEDED - oil) / OIL_NEEDED));
44917
44998
  if (engineHeat >= ENGINE_STEAM_C && vis && !steaming) {
44918
44999
  steaming = true;
44919
- kit.addEmitter(c, new V3(engine.def.box.center[0], engine.def.box.center[1] + 0.4, 0), "white", { rate: 8, s: 1 });
45000
+ smokeFromBay(engine, "white", 8);
44920
45001
  }
44921
45002
  if (engineHeat >= ENGINE_SEIZE_C || engine.hp <= engine.def.hp * ENGINE_SEIZE_HP) {
44922
45003
  seized = true;