@adatechnology/game-weather-three 0.3.2 → 0.3.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
@@ -330,6 +330,7 @@ interface RigVehicles {
330
330
  }): {
331
331
  readonly group: THREE_NS.Object3D;
332
332
  readonly length: number;
333
+ readonly width?: number;
333
334
  dispose(): void;
334
335
  };
335
336
  }
@@ -2348,6 +2348,24 @@ var GameWeatherThree = (() => {
2348
2348
  };
2349
2349
  }
2350
2350
 
2351
+ // ../game-contracts/dist/index.js
2352
+ function footprintBlocker(object, footprint) {
2353
+ return (x, z, radius) => {
2354
+ const o = typeof object === "function" ? object() : object;
2355
+ const fp = typeof footprint === "function" ? footprint() : footprint;
2356
+ if (!o || !fp || !o.parent) return false;
2357
+ o.updateWorldMatrix?.(true, false);
2358
+ const e = o.matrixWorld.elements;
2359
+ const dx = x - e[12];
2360
+ const dz = z - e[14];
2361
+ const ax = e[0] ** 2 + e[1] ** 2 + e[2] ** 2;
2362
+ const az = e[8] ** 2 + e[9] ** 2 + e[10] ** 2;
2363
+ const lx = (dx * e[0] + dz * e[2]) / (ax || 1);
2364
+ const lz = (dx * e[8] + dz * e[10]) / (az || 1);
2365
+ return lx > fp.minX - radius && lx < fp.maxX + radius && lz > fp.minZ - radius && lz < fp.maxZ + radius;
2366
+ };
2367
+ }
2368
+
2351
2369
  // src/bench/text.ts
2352
2370
  var TEXTS = {
2353
2371
  en: { layers: { far_rain: "Rain curtain", near_rain: "Near rain and splashes", mist: "Mist and ash", sky: "Sky", lightning: "Lightning", headlights: "Headlights", haze: "Heat haze" } },
@@ -2367,8 +2385,10 @@ var GameWeatherThree = (() => {
2367
2385
  car.group.position.z = HEADLIGHTS.lamp[2] + 0.1 - car.length / 2;
2368
2386
  group.add(car.group);
2369
2387
  }
2388
+ const footprint = car ? footprintOf(car) : void 0;
2370
2389
  return {
2371
2390
  group,
2391
+ ...footprint ? { footprint } : {},
2372
2392
  dispose() {
2373
2393
  car?.dispose();
2374
2394
  }
@@ -2399,15 +2419,22 @@ var GameWeatherThree = (() => {
2399
2419
  }
2400
2420
  };
2401
2421
  }
2422
+ function footprintOf(car) {
2423
+ if (!car.width) return void 0;
2424
+ const z = car.group.position.z;
2425
+ return { minX: -car.width / 2, maxX: car.width / 2, minZ: z - car.length / 2, maxZ: z + car.length / 2 };
2426
+ }
2402
2427
  function attachRig(THREE, host, renderer, place, vehicles, key) {
2403
2428
  const scene = host.scene;
2404
2429
  const rig = place === false ? void 0 : buildRig(THREE, vehicles, key);
2405
2430
  let detach;
2431
+ let unblock;
2406
2432
  if (rig && place) {
2407
2433
  rig.group.position.set(place[0], 0, place[1]);
2408
2434
  rig.group.rotation.y = place[2];
2409
2435
  scene.add(rig.group);
2410
2436
  detach = renderer.headlights.attach(rig.group);
2437
+ if (rig.footprint) unblock = host.addBlocker?.(footprintBlocker(rig.group, rig.footprint));
2411
2438
  }
2412
2439
  return {
2413
2440
  update: (dt) => renderer.update(dt),
@@ -2416,6 +2443,7 @@ var GameWeatherThree = (() => {
2416
2443
  },
2417
2444
  dispose() {
2418
2445
  detach?.();
2446
+ unblock?.();
2419
2447
  if (rig) {
2420
2448
  scene.remove(rig.group);
2421
2449
  rig.dispose();