@adatechnology/game-floorplan-three 0.8.0 → 0.8.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.
@@ -13540,6 +13540,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
13540
13540
  var CHIP_ENERGY = 200;
13541
13541
  var CHIP_SPLASH = 0.5;
13542
13542
  var CRATER_SPENT = 0.6;
13543
+ var EDGE_REACH = 1.5;
13543
13544
  var BAR_BOW = 0.08;
13544
13545
  var BULLET_JOINT_SPAN = 0.3;
13545
13546
  var CUT_SLICE = 1;
@@ -14913,6 +14914,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14913
14914
  const lo = cell.center[a] - cell.size[a] / 2 + w / 2, hi = cell.center[a] + cell.size[a] / 2 - w / 2;
14914
14915
  size[a] = w;
14915
14916
  center[a] = clamp2(lp[a], lo, hi);
14917
+ const [from, to] = tornToEdge({ p, cell, a, b: a === u ? v : u, at: lp[a], crater: [center[a] - w / 2, center[a] + w / 2], reach: w * EDGE_REACH, gone: (k) => worn[k] === -1 });
14918
+ size[a] = to - from;
14919
+ center[a] = (from + to) / 2;
14916
14920
  }
14917
14921
  const taken2 = (cut[i] ?? 0) + size[u] * size[v];
14918
14922
  if (taken2 >= cell.size[u] * cell.size[v] * CRATER_SPENT) {
@@ -14950,6 +14954,19 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
14950
14954
  collapseCheck(o, src);
14951
14955
  }
14952
14956
  };
14957
+ const tornToEdge = (o) => {
14958
+ const { p, cell, a, b, at, crater: crater2, reach, gone } = o;
14959
+ const half = p.dims[a] / 2;
14960
+ const lo = cell.center[a] - cell.size[a] / 2, hi = cell.center[a] + cell.size[a] / 2;
14961
+ const free = (side, sign2) => {
14962
+ if (sign2 > 0 ? side >= half - 1e-6 : side <= -half + 1e-6) return sign2 > 0 || a !== planeAxes(p.thin)[1];
14963
+ const probe = side + sign2 * 1e-3;
14964
+ return gridOf(p).some((c, k) => gone(k) && Math.abs(probe - c.center[a]) <= c.size[a] / 2 && Math.abs(cell.center[b] - c.center[b]) <= c.size[b] / 2);
14965
+ };
14966
+ if (at - lo <= reach && free(lo, -1)) return [lo, Math.max(crater2[1], lo)];
14967
+ if (hi - at <= reach && free(hi, 1)) return [Math.min(crater2[0], hi), hi];
14968
+ return crater2;
14969
+ };
14953
14970
  const craterAcross = (energy) => clamp2(0.03 + 12e-4 * Math.sqrt(Math.max(0, energy)), 0.03, 0.14);
14954
14971
  const craterFragments = (o, p, cell, dir, speed, mass, tag) => {
14955
14972
  const { c, q } = partXf(o, p);
@@ -19749,6 +19766,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19749
19766
  var SPALL_RAGGED = 0.045;
19750
19767
  var COVER2 = 0.015;
19751
19768
  var MAX_FLAKES = 64;
19769
+ function clipToBox(unit, box3) {
19770
+ const lo = [Math.max(unit.x - unit.sx / 2, box3[0]), Math.max(unit.y - unit.sy / 2, box3[1]), Math.max(unit.z - unit.sz / 2, box3[2])];
19771
+ const hi = [Math.min(unit.x + unit.sx / 2, box3[3]), Math.min(unit.y + unit.sy / 2, box3[4]), Math.min(unit.z + unit.sz / 2, box3[5])];
19772
+ if (hi[0] - lo[0] <= 1e-4 || hi[1] - lo[1] <= 1e-4 || hi[2] - lo[2] <= 1e-4) return null;
19773
+ return { x: (lo[0] + hi[0]) / 2, y: (lo[1] + hi[1]) / 2, z: (lo[2] + hi[2]) / 2, sx: hi[0] - lo[0], sy: hi[1] - lo[1], sz: hi[2] - lo[2], colour: unit.colour };
19774
+ }
19752
19775
  function installDestructionBreach(K, _shared) {
19753
19776
  const { THREE, fragmentMaterial, invalidate, invalidateShadow } = K;
19754
19777
  function createBreachView(opts) {
@@ -19859,6 +19882,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19859
19882
  material.userData.breachCore = core;
19860
19883
  return material;
19861
19884
  }
19885
+ function drawnBounds(items) {
19886
+ house.updateMatrixWorld(true);
19887
+ const box3 = new THREE.Box3(), toHouse = new THREE.Matrix4().copy(house.matrixWorld).invert();
19888
+ for (const it of items) {
19889
+ const a = it.mesh.userData._p0 || it.mesh.geometry.attributes.position.array;
19890
+ tmp.m.multiplyMatrices(toHouse, it.mesh.matrixWorld);
19891
+ for (let k = it.v0; k < it.v1; k++) box3.expandByPoint(tmp.p.set(a[k * 3], a[k * 3 + 1], a[k * 3 + 2]).applyMatrix4(tmp.m));
19892
+ }
19893
+ return [box3.min.x, box3.min.y, box3.min.z, box3.max.x, box3.max.y, box3.max.z];
19894
+ }
19862
19895
  function maskOf(hostId, parts) {
19863
19896
  const host = structure.byId.get(hostId);
19864
19897
  const [u0, v0, u1, v1] = host.aabb;
@@ -19946,7 +19979,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
19946
19979
  for (const { c, part, units: units2, thick, mid } of shown) {
19947
19980
  if (!near(c)) continue;
19948
19981
  const centre = mask.start + (c.a + c.b) / 2, y = (c.y0 + c.y1) / 2, len = c.b - c.a, h = c.y1 - c.y0;
19949
- const at = (s, dy, d, colour) => list2.push({ x: mask.alongU ? centre : mid, y, z: mask.alongU ? mid : centre, sx: mask.alongU ? s : d, sy: dy, sz: mask.alongU ? d : s, colour });
19982
+ const at = (s, dy, d, colour) => {
19983
+ const unit = clipToBox({ x: mask.alongU ? centre : mid, y, z: mask.alongU ? mid : centre, sx: mask.alongU ? s : d, sy: dy, sz: mask.alongU ? d : s, colour }, view.bounds);
19984
+ if (unit) list2.push(unit);
19985
+ };
19950
19986
  const base = fragmentMaterial(part.material).color.getHex();
19951
19987
  const n = noise2(centre * 3.1, y * 2.7, 0.07);
19952
19988
  if (units2.mortar === "concrete") {
@@ -20013,6 +20049,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
20013
20049
  units: null,
20014
20050
  gone: 0,
20015
20051
  pits: 0,
20052
+ bounds: drawnBounds(items),
20016
20053
  chips: new Map(parts.map((id) => [id, []])),
20017
20054
  spalls: new Map(parts.map((id) => [id, []])),
20018
20055
  openings: /* @__PURE__ */ new Map(),
@@ -21702,11 +21739,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21702
21739
  return { oid: so.objectId, parts, centre };
21703
21740
  };
21704
21741
  const role = (p) => p.structure && p.structure.role;
21742
+ const listening = [];
21705
21743
  const events = (room) => {
21706
21744
  const list2 = [];
21707
- room.world.on("*", (e) => list2.push(e));
21745
+ listening.push(room.world.on("*", (e) => list2.push(e)));
21708
21746
  return list2;
21709
21747
  };
21748
+ const stopListening = () => {
21749
+ for (const off of listening.splice(0)) off?.();
21750
+ };
21710
21751
  const collapsed = (list2) => list2.filter((e) => e.type === "collapse").flatMap((e) => e.parts.map((p) => p.id || p));
21711
21752
  const whole = (room, oid, pid) => {
21712
21753
  const p = room.world.part(oid, pid);
@@ -21720,7 +21761,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21720
21761
  const bullet = (room, oid, pid, point, energy) => {
21721
21762
  room.world.hitPart(oid, pid, { type: "ballistic", point, direction: [0, 0, -1], energy, caliber: 9 });
21722
21763
  };
21723
- return [
21764
+ const scenarios = [
21724
21765
  {
21725
21766
  id: "house_one_pillar",
21726
21767
  name: text.scenarios.house_one_pillar,
@@ -21814,6 +21855,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
21814
21855
  }
21815
21856
  }
21816
21857
  ];
21858
+ return scenarios.map((scenario) => ({
21859
+ ...scenario,
21860
+ run(context) {
21861
+ try {
21862
+ return scenario.run(context);
21863
+ } finally {
21864
+ stopListening();
21865
+ }
21866
+ }
21867
+ }));
21817
21868
  }
21818
21869
 
21819
21870
  // src/test-area/specimens.ts