@adatechnology/game-vehicles-three 0.9.1 → 0.9.2

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.
@@ -2308,11 +2308,12 @@ var LAMP_RULES = {
2308
2308
  reverse: { color: 16054015, intensity: 0.9, distance: 7, decay: 2 },
2309
2309
  interior: { color: 16769712, intensity: 0.5, distance: 2.4, decay: 2 }
2310
2310
  };
2311
+ var CENTRE_LAMP_X = 0.05;
2311
2312
  function createVehicleLamps(THREE, built, options = {}) {
2312
2313
  const budget = isLightBudget(options.lights) ? options.lights : null;
2313
2314
  const owner = options.owner ?? "vehicle-lamps";
2314
2315
  const context = built.context;
2315
- const lamps = (context?.lights ?? []).filter((l) => l && Array.isArray(l.inner)).map((l) => l.fog ? { ...l, kind: "fog" } : l);
2316
+ const lamps = (context?.lights ?? []).filter((l) => l && Array.isArray(l.inner)).map((l) => l.fog ? Object.create(l, { kind: { value: "fog" } }) : l);
2316
2317
  const bulbs = (context?.fogBulbs ?? []).filter((o) => o?.material);
2317
2318
  built.group.traverse((o) => {
2318
2319
  if (o.userData?.lamp === "fog" && o.material && !bulbs.includes(o)) bulbs.push(o);
@@ -2361,7 +2362,12 @@ function createVehicleLamps(THREE, built, options = {}) {
2361
2362
  const mat = m.material;
2362
2363
  if (mat && !Array.isArray(mat) && base.has(mat) && "emissiveIntensity" in mat) mat.emissiveIntensity = base.get(mat) * share;
2363
2364
  };
2365
+ const isOut = (l) => !!l.broken || !!l.dark;
2364
2366
  const glow = (l, share) => {
2367
+ if (isOut(l)) {
2368
+ for (const h of l.halo ?? []) h.visible = false;
2369
+ return;
2370
+ }
2365
2371
  for (const m of l.inner) {
2366
2372
  if (amber.has(m)) continue;
2367
2373
  glowMesh(m, share);
@@ -2389,8 +2395,13 @@ function createVehicleLamps(THREE, built, options = {}) {
2389
2395
  const rear = anchor(0, Math.min(0.9, H * 0.45), -L / 2 - 0.3, 0, 0);
2390
2396
  const cabin = anchor(0, H * 0.85, 0, 0, 0);
2391
2397
  const sources = /* @__PURE__ */ new Map();
2392
- const beam = (id, on, make) => {
2393
- const now = sources.get(id);
2398
+ const beam = (id, on, make, count2) => {
2399
+ let now = sources.get(id);
2400
+ if (on && now && count2 !== void 0 && now.length !== count2) {
2401
+ for (const s of now) s.remove();
2402
+ sources.delete(id);
2403
+ now = void 0;
2404
+ }
2394
2405
  if (on && !now && budget) sources.set(id, make());
2395
2406
  if (!on && now) {
2396
2407
  for (const s of now) s.remove();
@@ -2404,6 +2415,17 @@ function createVehicleLamps(THREE, built, options = {}) {
2404
2415
  const point = (a, rule) => [
2405
2416
  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 })
2406
2417
  ];
2418
+ const working = (kind) => lamps.filter((l) => l.kind === kind && !isOut(l));
2419
+ const across = /* @__PURE__ */ new Map();
2420
+ built.group.updateMatrixWorld(true);
2421
+ for (const l of lamps) {
2422
+ const anchorObject = l.group ?? l.inner[0];
2423
+ const at = anchorObject?.getWorldPosition?.(new THREE.Vector3());
2424
+ if (at) across.set(l, built.group.worldToLocal(at).x);
2425
+ }
2426
+ const beamSide = (sign) => !has.head || working("headlight").some((l) => (across.get(l) ?? 0) * sign > 0 || Math.abs(across.get(l) ?? 0) < CENTRE_LAMP_X);
2427
+ const health = () => lamps.map((l) => isOut(l) ? 1 : 0).join("");
2428
+ let healthSeen = health();
2407
2429
  const state = { mode: "off", fog: false, interior: false, brake: false, reverse: false, left: false, right: false };
2408
2430
  const apply = () => {
2409
2431
  const g = LAMP_RULES.glow;
@@ -2416,9 +2438,13 @@ function createVehicleLamps(THREE, built, options = {}) {
2416
2438
  const lit = state.beacon ?? null;
2417
2439
  for (const b of beacons) glowMesh(b.mesh, lit === null ? g.beacon.off : lit === b.side ? g.beacon.lit : g.beacon.dark);
2418
2440
  const beamId = state.mode === "low" || state.mode === "high" ? state.mode : null;
2419
- for (const id of ["low", "high"]) beam(id, beamId === id, () => spots(front, LAMP_RULES[id]));
2420
- beam("fog", state.fog && has.fog, () => spots(fogAnchors, LAMP_RULES.fog));
2421
- beam("reverse", state.reverse, () => point(rear, LAMP_RULES.reverse));
2441
+ const sides = [-1, 1].map(beamSide);
2442
+ for (const id of ["low", "high"]) {
2443
+ const lit2 = beamId === id ? front.filter((_, i) => sides[i]) : [];
2444
+ beam(id, lit2.length > 0, () => spots(lit2, LAMP_RULES[id]), lit2.length);
2445
+ }
2446
+ beam("fog", state.fog && has.fog && working("fog").length > 0, () => spots(fogAnchors, LAMP_RULES.fog));
2447
+ beam("reverse", state.reverse && (!has.tail || working("taillight").length > 0), () => point(rear, LAMP_RULES.reverse));
2422
2448
  beam("interior", state.interior, () => point(cabin, LAMP_RULES.interior));
2423
2449
  };
2424
2450
  apply();
@@ -2428,7 +2454,9 @@ function createVehicleLamps(THREE, built, options = {}) {
2428
2454
  return { ...state };
2429
2455
  },
2430
2456
  set(next) {
2431
- 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;
2457
+ const seen = health();
2458
+ 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;
2459
+ healthSeen = seen;
2432
2460
  Object.assign(state, next);
2433
2461
  apply();
2434
2462
  },
@@ -2442,6 +2470,7 @@ function createVehicleLamps(THREE, built, options = {}) {
2442
2470
  const original = originals.get(m);
2443
2471
  if (!original) return;
2444
2472
  originals.delete(m);
2473
+ if (!copies.has(copy)) return;
2445
2474
  m.material = original;
2446
2475
  if (copy && !Array.isArray(copy)) copy.dispose?.();
2447
2476
  };
@@ -3381,7 +3410,7 @@ function createProvingModule(options) {
3381
3410
  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] };
3382
3411
  };
3383
3412
  const applyCamera = () => {
3384
- if (!host?.setViewCamera) return;
3413
+ if (!host?.setViewCamera || !open) return;
3385
3414
  host.setViewCamera(settings.camera === "room" ? null : rig.camera);
3386
3415
  if (settings.camera !== "room") rig.vehicle?.setMode(settings.camera);
3387
3416
  };
@@ -4000,4 +4029,4 @@ export {
4000
4029
  createProvingModule,
4001
4030
  loadProvingModule
4002
4031
  };
4003
- //# sourceMappingURL=chunk-NVMORI7X.js.map
4032
+ //# sourceMappingURL=chunk-IHMZYKUW.js.map