@adatechnology/game-vehicles-three 0.3.1 → 0.3.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.
package/dist/index.js CHANGED
@@ -728,6 +728,7 @@ var itemId = (key) => ITEM_OF[key] ?? key;
728
728
  var LANE = { z: 11, from: -12, wall: 13 };
729
729
  var MATERIAL_COLOURS = { metal: 13421772, glass: 4500223, rubber: 16750848, fuel: 16724736 };
730
730
  var ZONE_COLOURS = { door: 5627221, hood: 14540083, lid: 14522675, bumper: 14505437, glass: 4500223, light: 16777215, wheel: 16742195 };
731
+ var BODY_HEIGHT = 1.7;
731
732
  function createVehiclesTestModule(options = {}) {
732
733
  const locale = options.locale ?? "pt-BR";
733
734
  const text = TEXT[locale] ?? TEXT["pt-BR"];
@@ -859,6 +860,7 @@ function createVehiclesTestModule(options = {}) {
859
860
  entry.root.updateMatrixWorld(true);
860
861
  const inverse = new three.Matrix4().copy(entry.root.matrixWorld).invert();
861
862
  const bounds = new three.Box3();
863
+ const low = new three.Box3();
862
864
  const piece = new three.Box3();
863
865
  const matrix = new three.Matrix4();
864
866
  entry.root.traverse((mesh) => {
@@ -868,9 +870,11 @@ function createVehiclesTestModule(options = {}) {
868
870
  mesh.geometry.computeBoundingBox();
869
871
  piece.copy(mesh.geometry.boundingBox).applyMatrix4(matrix.multiplyMatrices(inverse, mesh.matrixWorld));
870
872
  bounds.union(piece);
873
+ if (piece.min.y < BODY_HEIGHT) low.union(piece);
871
874
  });
872
875
  const size = bounds.getSize(new three.Vector3());
873
876
  entry.size = { length: size.z, width: size.x, height: size.y };
877
+ if (!low.isEmpty()) entry.footprint = { minX: low.min.x, maxX: low.max.x, minZ: low.min.z, maxZ: low.max.z };
874
878
  return entry.size;
875
879
  };
876
880
  const clearHelpers = () => {
@@ -920,6 +924,23 @@ function createVehiclesTestModule(options = {}) {
920
924
  }
921
925
  helpersShown = boxKey();
922
926
  };
927
+ const local = { m: null, v: null };
928
+ const inside = (root, fp, x, z, radius) => {
929
+ if (!three) return false;
930
+ local.m ?? (local.m = new three.Matrix4());
931
+ local.v ?? (local.v = new three.Vector3());
932
+ root.updateWorldMatrix(true, false);
933
+ const p = local.v.set(x, 0, z).applyMatrix4(local.m.copy(root.matrixWorld).invert());
934
+ return p.x > fp.minX - radius && p.x < fp.maxX + radius && p.z > fp.minZ - radius && p.z < fp.maxZ + radius;
935
+ };
936
+ const blocked = (x, z, radius) => {
937
+ for (const entry of placed.values()) if (entry.root.parent && entry.footprint && inside(entry.root, entry.footprint, x, z, radius)) return true;
938
+ if (lane) {
939
+ const half = { l: lane.car.length / 2, w: lane.car.width / 2 };
940
+ if (inside(lane.group, { minX: -half.w, maxX: half.w, minZ: -half.l, maxZ: half.l }, x, z, radius)) return true;
941
+ }
942
+ return false;
943
+ };
923
944
  const clearLane = () => {
924
945
  stopEngine();
925
946
  if (!lane) return;
@@ -1140,10 +1161,12 @@ function createVehiclesTestModule(options = {}) {
1140
1161
  three = lent.THREE;
1141
1162
  const stopChange = lent.bench?.onChange(onChange);
1142
1163
  const stopFrame = lent.onFrame(frame);
1164
+ const stopBlocker = lent.addBlocker?.(blocked);
1143
1165
  lent.audio?.register?.(LIBRARY_BANK);
1144
1166
  return () => {
1145
1167
  stopChange?.();
1146
1168
  stopFrame();
1169
+ stopBlocker?.();
1147
1170
  clearHelpers();
1148
1171
  clearLane();
1149
1172
  host = null;