@adatechnology/game-destruction 0.11.0 → 0.12.0

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
@@ -1864,6 +1864,7 @@ var materials_default = [
1864
1864
  },
1865
1865
  hitDebris: "chips",
1866
1866
  breakDebris: "dust",
1867
+ visual: { innerColor: 10197652 },
1867
1868
  thermal: {
1868
1869
  conductivity: 0.15,
1869
1870
  heatCapacity: 2.5
@@ -1894,6 +1895,7 @@ var materials_default = [
1894
1895
  ],
1895
1896
  hitDebris: "chips",
1896
1897
  breakDebris: "dust",
1898
+ visual: { innerColor: 12085567 },
1897
1899
  thermal: {
1898
1900
  conductivity: 0.15,
1899
1901
  heatCapacity: 2.5
@@ -1924,6 +1926,7 @@ var materials_default = [
1924
1926
  ],
1925
1927
  hitDebris: "dust",
1926
1928
  breakDebris: "dust",
1929
+ visual: { innerColor: 14999507 },
1927
1930
  thermal: {
1928
1931
  conductivity: 0.1,
1929
1932
  heatCapacity: 1.5
@@ -1949,6 +1952,7 @@ var materials_default = [
1949
1952
  ],
1950
1953
  hitDebris: "chips",
1951
1954
  breakDebris: "dust",
1955
+ visual: { innerColor: 9407364 },
1952
1956
  thermal: {
1953
1957
  conductivity: 0.2,
1954
1958
  heatCapacity: 2.5
@@ -2718,6 +2722,7 @@ var BREACH_GRID_CAP = 4096;
2718
2722
  var CHIP_ENERGY = 200;
2719
2723
  var CHIP_SPLASH = 0.5;
2720
2724
  var BAR_BOW = 0.08;
2725
+ var BULLET_JOINT_SPAN = 0.3;
2721
2726
  var CUT_SLICE = 1;
2722
2727
  var cutFactorOf = (shape) => clamp2(Math.max(...shapeDims(shape)) / CUT_SLICE, 1, 50);
2723
2728
  var clamp2 = (v, a, b) => Math.max(a, Math.min(b, v));
@@ -3844,7 +3849,7 @@ var createDestruction = (options = {}) => {
3844
3849
  emit({ ...base(o, src), type: "crack", part: p.spec.id, crack, worldPoint: wp });
3845
3850
  setStage(o, p, 1, {}, src);
3846
3851
  };
3847
- const debris = (o, p, kind, point, normal, count, speed, src) => emit({ ...base(o, src), type: "debris", part: p.spec.id, kind, point, normal, count, speed });
3852
+ const debris = (o, p, kind, point, normal, count, speed, src, material) => emit({ ...base(o, src), type: "debris", part: p.spec.id, kind, point, normal, count, speed, ...material && material !== p.spec.material ? { material } : {} });
3848
3853
  const holeRate = (hole, pressurized) => (pressurized ? 0.5 : 0.1) * (hole.diameter / 9e-3);
3849
3854
  const detachEvents = (o, opened, by, src) => {
3850
3855
  for (const j of opened) emit({ ...base(o, src), type: "detach", joint: j.spec.id, parts: [j.spec.a, j.spec.b], by, groups: o.st.groups.map((g) => [...g]) });
@@ -3885,7 +3890,13 @@ var createDestruction = (options = {}) => {
3885
3890
  const small = pa.dims[0] * pa.dims[1] * pa.dims[2] <= pb.dims[0] * pb.dims[1] * pb.dims[2] ? pa : pb;
3886
3891
  return Math.max(0.06, 0.5 * Math.min(small.dims[0], small.dims[1], small.dims[2]));
3887
3892
  };
3888
- const wearJoints = (o, p, amount, near, radius = 0.06, src, split = false) => {
3893
+ const jointLength = (o, j) => {
3894
+ const A = partWorldAabb(o, o.parts[j.ia]), B = partWorldAabb(o, o.parts[j.ib]);
3895
+ let len = 0;
3896
+ for (let k = 0; k < 3; k++) len = Math.max(len, Math.min(A.max[k], B.max[k]) - Math.max(A.min[k], B.min[k]));
3897
+ return len;
3898
+ };
3899
+ const wearJoints = (o, p, amount, near, radius = 0.06, src, split = false, span) => {
3889
3900
  if (amount <= 0) return;
3890
3901
  const mine = (o.byPart.get(p.spec.id) ?? []).filter((j) => !j.st.open);
3891
3902
  if (split && mine.length) amount /= mine.length;
@@ -3893,7 +3904,7 @@ var createDestruction = (options = {}) => {
3893
3904
  if (j.st.open) continue;
3894
3905
  if (j.spec.kind === "rebar" && (isReinforced(o.parts[j.ia].spec) || isReinforced(o.parts[j.ib].spec))) continue;
3895
3906
  if (near && jointReach(o, j, near) > Math.max(radius, jointReachLimit(o, j))) continue;
3896
- j.st.hp -= amount;
3907
+ j.st.hp -= span === void 0 ? amount : amount * Math.min(1, span / Math.max(jointLength(o, j), 1e-6));
3897
3908
  if (j.st.hp <= 0) {
3898
3909
  j.st.hp = 0;
3899
3910
  j.st.open = true;
@@ -3922,7 +3933,7 @@ var createDestruction = (options = {}) => {
3922
3933
  if (spalls.length > MAX_SPALLS) spalls.shift();
3923
3934
  markDamaged(p);
3924
3935
  emit({ ...base(o, src), type: "spall", part: p.spec.id, layer: layer.index, point: wp, area: Math.PI * radius * radius });
3925
- debris(o, p, layer.mat.hitDebris, wp, normal, 5, 2, src);
3936
+ debris(o, p, layer.mat.hitDebris, wp, normal, 5, 2, src, layer.mat.id);
3926
3937
  setStage(o, p, 1, {}, src);
3927
3938
  };
3928
3939
  const crater = (o, p, wp, normal, radius, src) => {
@@ -4409,7 +4420,7 @@ var createDestruction = (options = {}) => {
4409
4420
  if (mat.fracture !== "shatter") addHole(o, p, entry, n, caliber / 1e3, false, void 0, src);
4410
4421
  } else addHole(o, p, entry, n, caliber / 1e3, false, void 0, src);
4411
4422
  debris(o, p, mat.hitDebris, entry, n, clamp2(Math.round(E / 60) + 2, 2, 14), clamp2(Math.sqrt(E) / 6, 1, 8), src);
4412
- wearJoints(o, p, (penetrated ? thr : E) * 0.02, void 0, 0, src, true);
4423
+ wearJoints(o, p, (penetrated ? thr : E) * 0.02, void 0, 0, src, true, BULLET_JOINT_SPAN);
4413
4424
  const absorbed = penetrated && mat.ductility >= 0.5 && mat.fracture !== "tear" ? Math.min(E, thr) : E;
4414
4425
  const dmg = applyDamage(o, p, absorbed * DMG_PER_J * scale, "ballistic", entry, d, absorbed * 0.1, 12, src);
4415
4426
  if (!isLost(p)) tearAt(o, p, "ballistic", entry, penetrated ? exitPoint : void 0, d, E, caliber / 1e3, src);