@adatechnology/game-destruction 0.8.1 → 0.9.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.d.ts CHANGED
@@ -62,6 +62,11 @@ interface MaterialDef {
62
62
  fracture: FractureStyle;
63
63
  /** Fragment size range in metres (default `[0.04, 0.2]`). */
64
64
  fragmentSize?: [number, number];
65
+ /**
66
+ * Thickness of one sheet, in metres, for a material that comes in sheets (paper). A `tear` part much thicker than a sheet is a stack of them (a book,
67
+ * a ream, a magazine) and comes apart as thin loose scraps (`Fragment.inner` for the pages) instead of slabs as thick as the part.
68
+ */
69
+ sheet?: number;
65
70
  /** Damage multipliers per damage type (default 1); `shelter` multiplies the resistance the material adds between a blast and a target (`blast.shelter`). */
66
71
  damageScale?: Partial<Record<DamageType | 'shelter', number>>;
67
72
  /** Debris emitted on a hit that does not break the part. */
@@ -79,6 +84,8 @@ interface MaterialDef {
79
84
  glows?: boolean;
80
85
  /** Transparent (glass): cracks are drawn as a star on the surface. */
81
86
  transparent?: boolean;
87
+ /** Colour of the inside, for the inner fragments and the hit debris (the pages of a book under its cover); default the colour of the part. */
88
+ innerColor?: number;
82
89
  };
83
90
  /** Free tags, e.g. `metal`, `organic`, `conductive`. */
84
91
  tags?: string[];
@@ -450,6 +450,23 @@ var GameDestruction = (() => {
450
450
  return angle === 0 ? q : quat.mul(q, quat.fromAxisAngle([0, 0, 1], angle));
451
451
  };
452
452
  var clamp = (v, a, b) => Math.max(a, Math.min(b, v));
453
+ var tearStack = (inp, root, t, u, v, n, sheet) => {
454
+ const { dims, rnd, maxFragments } = inp;
455
+ const layers = clamp(Math.ceil(dims[t] / STACK_LAYER), 2, 4);
456
+ const per = clamp(n, 3, Math.max(3, Math.floor(maxFragments / layers)));
457
+ const out = [];
458
+ for (let k = 0; k < layers; k++) {
459
+ const off = -dims[t] / 2 + (k + 0.5) * dims[t] / layers;
460
+ for (const b of bsp(root, per, [u, v], rnd)) {
461
+ if (out.length >= maxFragments) return out;
462
+ const c = [b.c[0], b.c[1], b.c[2]];
463
+ c[t] = off;
464
+ out.push({ center: c, size: [b.s[u], b.s[v], sheet], q: frame(u, v, t, (rnd() - 0.5) * 0.8), shape: "scrap", weight: b.s[u] * b.s[v], inner: out.length % 4 !== 0 });
465
+ }
466
+ }
467
+ return out;
468
+ };
469
+ var STACK_LAYER = 0.012;
453
470
  var planFragments = (inp) => {
454
471
  const { style, dims, rnd, maxFragments } = inp;
455
472
  const [fmin, fmax] = inp.fragmentSize;
@@ -492,6 +509,8 @@ var GameDestruction = (() => {
492
509
  }
493
510
  if (style === "tear") {
494
511
  const n2 = clamp(Math.round(dims[u] * dims[v] / (mean * mean)), 3, maxFragments);
512
+ const sheet = inp.sheet ?? 0;
513
+ if (sheet > 0 && dims[t] > sheet * 4) return tearStack(inp, root, t, u, v, n2, sheet);
495
514
  const th2 = Math.min(inp.thickness, dims[t]);
496
515
  for (const b of bsp(root, n2, [u, v], rnd)) {
497
516
  out.push({ center: [b.c[0], b.c[1], b.c[2]], size: [b.s[u], b.s[v], th2], q: frame(u, v, t), shape: "scrap", weight: b.s[u] * b.s[v] });
@@ -2137,6 +2156,7 @@ var GameDestruction = (() => {
2137
2156
  0.03,
2138
2157
  0.15
2139
2158
  ],
2159
+ sheet: 1e-3,
2140
2160
  damageScale: {
2141
2161
  slash: 3
2142
2162
  },
@@ -2152,7 +2172,8 @@ var GameDestruction = (() => {
2152
2172
  smoke: "grey"
2153
2173
  },
2154
2174
  visual: {
2155
- charColor: 1709072
2175
+ charColor: 1709072,
2176
+ innerColor: 15524048
2156
2177
  },
2157
2178
  tags: [
2158
2179
  "fabric",
@@ -4028,7 +4049,8 @@ var GameDestruction = (() => {
4028
4049
  hit: hitLocal,
4029
4050
  fragmentSize: p.mat.fragmentSize ?? [0.04, 0.2],
4030
4051
  maxFragments,
4031
- rnd
4052
+ rnd,
4053
+ sheet: p.mat.sheet
4032
4054
  });
4033
4055
  const holes = p.st.holes.length > 0 ? localHolesOf(p) : [];
4034
4056
  const mass = p.st.mass;
@@ -4052,7 +4074,8 @@ var GameDestruction = (() => {
4052
4074
  velocity: [dv[0] * k, dv[1] * k + 0.5 * rnd(), dv[2] * k],
4053
4075
  angularVelocity: [(rnd() - 0.5) * 12, (rnd() - 0.5) * 12, (rnd() - 0.5) * 12],
4054
4076
  mass: mass * f.weight / totW,
4055
- ...marks.length > 0 ? { marks } : {}
4077
+ ...marks.length > 0 ? { marks } : {},
4078
+ ...f.inner ? { inner: true } : {}
4056
4079
  };
4057
4080
  });
4058
4081
  const reinforcement = p.spec.reinforcement;