@adatechnology/game-vehicles-three 0.9.1 → 0.9.3

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.d.ts CHANGED
@@ -4,7 +4,7 @@ import { EffectSink, Vec3, AudioSink, AnimationClipSpec } from '@adatechnology/g
4
4
  import { CabinSource, VehicleContext } from '@adatechnology/game-vehicles';
5
5
  import { LoopRecipe, Falloff, SampleAlias, SoundRecipe, SoundBank } from '@adatechnology/game-audio';
6
6
  import * as THREE_NS from 'three';
7
- import { Texture, Material, Color, Object3D, Matrix4, MeshStandardMaterial, MeshBasicMaterial, Mesh, CanvasTexture, CircleGeometry, Vector3, BufferGeometry, Side } from 'three';
7
+ import { Texture, Material, Color, Object3D, Matrix4, MeshStandardMaterial, MeshBasicMaterial, Mesh, Vector3, CanvasTexture, CircleGeometry, BufferGeometry, Side } from 'three';
8
8
  import '@adatechnology/game-vehicles-driving';
9
9
  import '@adatechnology/game-vehicles-proving';
10
10
 
@@ -361,6 +361,7 @@ interface VehicleLamps {
361
361
  }
362
362
  declare function createVehicleLamps(THREE: {
363
363
  Object3D: new () => Object3D;
364
+ Vector3: new () => Vector3;
364
365
  }, built: BuiltVehicle, options?: {
365
366
  lights?: unknown;
366
367
  owner?: string;
@@ -41659,6 +41659,8 @@ var GameVehiclesThree = (() => {
41659
41659
  var DOOR_STRIP_OVER = 0.05;
41660
41660
  var DOOR_TOP_OVER_PANE = 0.03;
41661
41661
  var HOLE_TEXTURE_SIZE = 64;
41662
+ var LAMP_BOX_MARGIN = 0.03;
41663
+ var GLOW_MIN_EMISSIVE = 0.05;
41662
41664
  var LAMINATED_HP = 1e3;
41663
41665
  var HOOD_SINK = 2e-3;
41664
41666
  var HOOD_GAP_CLOSED = 0.016;
@@ -42732,7 +42734,7 @@ var GameVehiclesThree = (() => {
42732
42734
  this.lightsOn = on;
42733
42735
  const dark = this.I.MATERIALS.bulbBroken;
42734
42736
  for (const L of this.c.lights) {
42735
- if (L.broken) continue;
42737
+ if (L.broken || L.dark) continue;
42736
42738
  for (const h of L.halo ?? []) h.visible = on;
42737
42739
  for (const m of L.inner ?? []) {
42738
42740
  if (on) {
@@ -42746,12 +42748,31 @@ var GameVehiclesThree = (() => {
42746
42748
  }
42747
42749
  /** The lens of a light is holed or cracked and stays; `pierced`: a round went through it to the bulb, and the lamp goes dark. */
42748
42750
  crackLight(p, pierced) {
42751
+ if (pierced) this.darkenGlowIn(p);
42749
42752
  const z = this.zone(p);
42750
42753
  if (!z) return;
42751
42754
  for (const L of z.lights) this.kit.crackLight(this.c, L, new this.THREE.Vector3(p.box.center[0] > 0 ? -1 : 1, 0, 0), pierced);
42752
42755
  }
42756
+ /** Everything of the lamp that glows goes dark: the fleet draws extra bulbs, reversing and amber strips in a lamp's place that the lamp's own list does not hold. */
42757
+ darkenGlowIn(p) {
42758
+ const dark = this.I.MATERIALS.bulbBroken;
42759
+ const [cx, cy, cz] = p.box.center;
42760
+ const [sx, sy, sz] = p.box.size;
42761
+ this.c.vehicle.updateMatrixWorld(true);
42762
+ this.c.vehicle.traverse((o) => {
42763
+ const mesh2 = o;
42764
+ if (!mesh2.isMesh || mesh2.userData.glass || mesh2.material === dark || Array.isArray(mesh2.material)) return;
42765
+ const { emissive, emissiveIntensity } = mesh2.material;
42766
+ if (!emissive || !(emissiveIntensity > 0) || emissive.r + emissive.g + emissive.b < GLOW_MIN_EMISSIVE) return;
42767
+ mesh2.geometry.computeBoundingBox();
42768
+ const mid = this.c.vehicle.worldToLocal(mesh2.localToWorld(mesh2.geometry.boundingBox.getCenter(new this.THREE.Vector3())));
42769
+ if (Math.abs(mid.x - cx) > sx / 2 + LAMP_BOX_MARGIN || Math.abs(mid.y - cy) > sy / 2 + LAMP_BOX_MARGIN || Math.abs(mid.z - cz) > sz / 2 + LAMP_BOX_MARGIN) return;
42770
+ mesh2.material = dark;
42771
+ });
42772
+ }
42753
42773
  /** The lens of a light breaks and its unit stays (damaged) or goes (destroyed). */
42754
42774
  breakLight(p, gone) {
42775
+ this.darkenGlowIn(p);
42755
42776
  const z = this.zone(p);
42756
42777
  if (!z) return;
42757
42778
  for (const L of z.lights) {
@@ -43392,9 +43413,10 @@ var GameVehiclesThree = (() => {
43392
43413
  if (p.lost || !(amount > 0)) return;
43393
43414
  const before = p.hp;
43394
43415
  const crumples = dtype === "blunt" && CRUMPLES.has(p.def.role) && (p.def.material === "steel" || p.def.material === "aluminium");
43395
- p.hp = Math.max(WELDED.has(p.def.role) || crumples ? 1 : 0, p.hp - amount);
43416
+ const punctures = dtype === "ballistic" && p.def.role === "tyre";
43417
+ p.hp = Math.max(WELDED.has(p.def.role) || crumples || punctures ? 1 : 0, p.hp - amount);
43396
43418
  out.push(ev({ type: "damage", part: p.def.id, amount: r2(before - p.hp), hp: r2(p.hp), damageType: dtype, ...source ? { source } : {} }));
43397
- wear(p, amount, out);
43419
+ if (!punctures) wear(p, amount, out);
43398
43420
  syncZone(p);
43399
43421
  if (p.hp <= 0) lose(p, "broken", out, cause);
43400
43422
  else if (p.def.role === "light") vis?.crackLight(p.def, dtype === "ballistic");
@@ -49758,11 +49780,12 @@ var GameVehiclesThree = (() => {
49758
49780
  reverse: { color: 16054015, intensity: 0.9, distance: 7, decay: 2 },
49759
49781
  interior: { color: 16769712, intensity: 0.5, distance: 2.4, decay: 2 }
49760
49782
  };
49783
+ var CENTRE_LAMP_X = 0.05;
49761
49784
  function createVehicleLamps(THREE, built2, options = {}) {
49762
49785
  const budget = isLightBudget(options.lights) ? options.lights : null;
49763
49786
  const owner = options.owner ?? "vehicle-lamps";
49764
49787
  const context = built2.context;
49765
- const lamps = (context?.lights ?? []).filter((l) => l && Array.isArray(l.inner)).map((l) => l.fog ? { ...l, kind: "fog" } : l);
49788
+ const lamps = (context?.lights ?? []).filter((l) => l && Array.isArray(l.inner)).map((l) => l.fog ? Object.create(l, { kind: { value: "fog" } }) : l);
49766
49789
  const bulbs = (context?.fogBulbs ?? []).filter((o) => o?.material);
49767
49790
  built2.group.traverse((o) => {
49768
49791
  if (o.userData?.lamp === "fog" && o.material && !bulbs.includes(o)) bulbs.push(o);
@@ -49811,7 +49834,12 @@ var GameVehiclesThree = (() => {
49811
49834
  const mat = m.material;
49812
49835
  if (mat && !Array.isArray(mat) && base.has(mat) && "emissiveIntensity" in mat) mat.emissiveIntensity = base.get(mat) * share;
49813
49836
  };
49837
+ const isOut = (l) => !!l.broken || !!l.dark;
49814
49838
  const glow = (l, share) => {
49839
+ if (isOut(l)) {
49840
+ for (const h of l.halo ?? []) h.visible = false;
49841
+ return;
49842
+ }
49815
49843
  for (const m of l.inner) {
49816
49844
  if (amber.has(m)) continue;
49817
49845
  glowMesh(m, share);
@@ -49839,8 +49867,13 @@ var GameVehiclesThree = (() => {
49839
49867
  const rear = anchor(0, Math.min(0.9, H * 0.45), -L / 2 - 0.3, 0, 0);
49840
49868
  const cabin = anchor(0, H * 0.85, 0, 0, 0);
49841
49869
  const sources = /* @__PURE__ */ new Map();
49842
- const beam = (id, on, make2) => {
49843
- const now = sources.get(id);
49870
+ const beam = (id, on, make2, count2) => {
49871
+ let now = sources.get(id);
49872
+ if (on && now && count2 !== void 0 && now.length !== count2) {
49873
+ for (const s of now) s.remove();
49874
+ sources.delete(id);
49875
+ now = void 0;
49876
+ }
49844
49877
  if (on && !now && budget) sources.set(id, make2());
49845
49878
  if (!on && now) {
49846
49879
  for (const s of now) s.remove();
@@ -49854,6 +49887,17 @@ var GameVehiclesThree = (() => {
49854
49887
  const point = (a, rule) => [
49855
49888
  budget.addSource({ owner, kind: "point", priority: LIGHT_PRIORITY.lamp, color: rule.color, intensity: rule.intensity, distance: rule.distance, decay: rule.decay, position: [0, 0, 0], follow: a })
49856
49889
  ];
49890
+ const working = (kind) => lamps.filter((l) => l.kind === kind && !isOut(l));
49891
+ const across = /* @__PURE__ */ new Map();
49892
+ built2.group.updateMatrixWorld(true);
49893
+ for (const l of lamps) {
49894
+ const anchorObject = l.group ?? l.inner[0];
49895
+ const at = anchorObject?.getWorldPosition?.(new THREE.Vector3());
49896
+ if (at) across.set(l, built2.group.worldToLocal(at).x);
49897
+ }
49898
+ const beamSide = (sign2) => !has.head || working("headlight").some((l) => (across.get(l) ?? 0) * sign2 > 0 || Math.abs(across.get(l) ?? 0) < CENTRE_LAMP_X);
49899
+ const health = () => lamps.map((l) => isOut(l) ? 1 : 0).join("");
49900
+ let healthSeen = health();
49857
49901
  const state = { mode: "off", fog: false, interior: false, brake: false, reverse: false, left: false, right: false };
49858
49902
  const apply = () => {
49859
49903
  const g = LAMP_RULES.glow;
@@ -49866,9 +49910,13 @@ var GameVehiclesThree = (() => {
49866
49910
  const lit = state.beacon ?? null;
49867
49911
  for (const b of beacons) glowMesh(b.mesh, lit === null ? g.beacon.off : lit === b.side ? g.beacon.lit : g.beacon.dark);
49868
49912
  const beamId = state.mode === "low" || state.mode === "high" ? state.mode : null;
49869
- for (const id of ["low", "high"]) beam(id, beamId === id, () => spots(front, LAMP_RULES[id]));
49870
- beam("fog", state.fog && has.fog, () => spots(fogAnchors, LAMP_RULES.fog));
49871
- beam("reverse", state.reverse, () => point(rear, LAMP_RULES.reverse));
49913
+ const sides = [-1, 1].map(beamSide);
49914
+ for (const id of ["low", "high"]) {
49915
+ const lit2 = beamId === id ? front.filter((_, i) => sides[i]) : [];
49916
+ beam(id, lit2.length > 0, () => spots(lit2, LAMP_RULES[id]), lit2.length);
49917
+ }
49918
+ beam("fog", state.fog && has.fog && working("fog").length > 0, () => spots(fogAnchors, LAMP_RULES.fog));
49919
+ beam("reverse", state.reverse && (!has.tail || working("taillight").length > 0), () => point(rear, LAMP_RULES.reverse));
49872
49920
  beam("interior", state.interior, () => point(cabin, LAMP_RULES.interior));
49873
49921
  };
49874
49922
  apply();
@@ -49878,7 +49926,9 @@ var GameVehiclesThree = (() => {
49878
49926
  return { ...state };
49879
49927
  },
49880
49928
  set(next) {
49881
- if (next.mode === state.mode && next.fog === state.fog && next.interior === state.interior && next.brake === state.brake && next.reverse === state.reverse && next.left === state.left && next.right === state.right && (next.beacon ?? null) === (state.beacon ?? null)) return;
49929
+ const seen = health();
49930
+ if (seen === healthSeen && next.mode === state.mode && next.fog === state.fog && next.interior === state.interior && next.brake === state.brake && next.reverse === state.reverse && next.left === state.left && next.right === state.right && (next.beacon ?? null) === (state.beacon ?? null)) return;
49931
+ healthSeen = seen;
49882
49932
  Object.assign(state, next);
49883
49933
  apply();
49884
49934
  },
@@ -49892,6 +49942,7 @@ var GameVehiclesThree = (() => {
49892
49942
  const original = originals.get(m);
49893
49943
  if (!original) return;
49894
49944
  originals.delete(m);
49945
+ if (!copies.has(copy)) return;
49895
49946
  m.material = original;
49896
49947
  if (copy && !Array.isArray(copy)) copy.dispose?.();
49897
49948
  };
@@ -50802,7 +50853,7 @@ var GameVehiclesThree = (() => {
50802
50853
  return { x: g.position.x, y: g.position.y, z: g.position.z, yaw: g.rotation.y, pitch: -g.rotation.x, roll: g.rotation.z, speed, ...size, eye: [ex, ey + adjust.seatHeight, ez + adjust.seatForward] };
50803
50854
  };
50804
50855
  const applyCamera = () => {
50805
- if (!host?.setViewCamera) return;
50856
+ if (!host?.setViewCamera || !open) return;
50806
50857
  host.setViewCamera(settings.camera === "room" ? null : rig.camera);
50807
50858
  if (settings.camera !== "room") rig.vehicle?.setMode(settings.camera);
50808
50859
  };