@adatechnology/game-vehicles-three 0.3.0 → 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
@@ -1,4 +1,5 @@
1
1
  // src/build.ts
2
+ import { markKitOrigin } from "@adatechnology/game-contracts";
2
3
  import { colorFromSeed, fleetDims, paintPalettes, paletteOf } from "@adatechnology/game-vehicles-fleet";
3
4
 
4
5
  // src/lite.ts
@@ -230,6 +231,7 @@ function createVehiclesThree(THREE, options) {
230
231
  const pivotMatrix = new THREE.Matrix4().makeTranslation(-cx, -bounds.min.y, -cz).multiply(rotation);
231
232
  const group = new THREE.Group();
232
233
  group.name = `vehicle:${key}`;
234
+ markKitOrigin(group, { owner: "game-vehicles-three", kind: "vehicle", id: key });
233
235
  const damageables = kit.damageables(c, pivotMatrix);
234
236
  let pruned = 0;
235
237
  if (quality === "high") {
@@ -726,6 +728,7 @@ var itemId = (key) => ITEM_OF[key] ?? key;
726
728
  var LANE = { z: 11, from: -12, wall: 13 };
727
729
  var MATERIAL_COLOURS = { metal: 13421772, glass: 4500223, rubber: 16750848, fuel: 16724736 };
728
730
  var ZONE_COLOURS = { door: 5627221, hood: 14540083, lid: 14522675, bumper: 14505437, glass: 4500223, light: 16777215, wheel: 16742195 };
731
+ var BODY_HEIGHT = 1.7;
729
732
  function createVehiclesTestModule(options = {}) {
730
733
  const locale = options.locale ?? "pt-BR";
731
734
  const text = TEXT[locale] ?? TEXT["pt-BR"];
@@ -857,6 +860,7 @@ function createVehiclesTestModule(options = {}) {
857
860
  entry.root.updateMatrixWorld(true);
858
861
  const inverse = new three.Matrix4().copy(entry.root.matrixWorld).invert();
859
862
  const bounds = new three.Box3();
863
+ const low = new three.Box3();
860
864
  const piece = new three.Box3();
861
865
  const matrix = new three.Matrix4();
862
866
  entry.root.traverse((mesh) => {
@@ -866,9 +870,11 @@ function createVehiclesTestModule(options = {}) {
866
870
  mesh.geometry.computeBoundingBox();
867
871
  piece.copy(mesh.geometry.boundingBox).applyMatrix4(matrix.multiplyMatrices(inverse, mesh.matrixWorld));
868
872
  bounds.union(piece);
873
+ if (piece.min.y < BODY_HEIGHT) low.union(piece);
869
874
  });
870
875
  const size = bounds.getSize(new three.Vector3());
871
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 };
872
878
  return entry.size;
873
879
  };
874
880
  const clearHelpers = () => {
@@ -918,6 +924,23 @@ function createVehiclesTestModule(options = {}) {
918
924
  }
919
925
  helpersShown = boxKey();
920
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
+ };
921
944
  const clearLane = () => {
922
945
  stopEngine();
923
946
  if (!lane) return;
@@ -1138,10 +1161,12 @@ function createVehiclesTestModule(options = {}) {
1138
1161
  three = lent.THREE;
1139
1162
  const stopChange = lent.bench?.onChange(onChange);
1140
1163
  const stopFrame = lent.onFrame(frame);
1164
+ const stopBlocker = lent.addBlocker?.(blocked);
1141
1165
  lent.audio?.register?.(LIBRARY_BANK);
1142
1166
  return () => {
1143
1167
  stopChange?.();
1144
1168
  stopFrame();
1169
+ stopBlocker?.();
1145
1170
  clearHelpers();
1146
1171
  clearLane();
1147
1172
  host = null;