@adatechnology/game-destruction-three 1.1.0 → 1.1.1

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
@@ -3822,6 +3822,13 @@ var TAPER_MIN = 2e-3;
3822
3822
  var RING_SEGMENTS = 16;
3823
3823
  var TOPPLE = 3;
3824
3824
  var HOLD_MARGIN = 4;
3825
+ var HOLD_MARGIN_REAL = 6;
3826
+ var holdPush = (params) => {
3827
+ const e = Math.abs(params.edge);
3828
+ const arm = params.height * params.height + e * e;
3829
+ if (arm <= 0) return 0;
3830
+ return Math.min(HOLD_MARGIN * params.gravity * e / arm, HOLD_MARGIN_REAL * params.gravity * e / (params.turning + arm));
3831
+ };
3825
3832
  var SIDE_DEAD = 0.01;
3826
3833
  var BOX_FOOT = 0.02;
3827
3834
  var PUSH_SPIN = 0.3;
@@ -4584,11 +4591,24 @@ var EnginePieces = class {
4584
4591
  /**
4585
4592
  * The push (rad/s2) that turns a piece about the edge of its support at `edge` (m from its centre, `height` m above it): the kit's `TOPPLE`, and on a support narrow both ways (a leg, a pole: a plate on its
4586
4593
  * edge is narrow one way only) at least what beats gravity's hold (at most `g |edge| / (height^2 + edge^2)` for any shape: a 5 cm leg 74 cm tall held against `TOPPLE` alone and stood for ever). Not where only
4587
- * the contacts of one instant sit off its centre: a box rocking on a table's edge reads like that, and stays.
4594
+ * the contacts of one instant sit off its centre: a box rocking on a table's edge reads like that, and stays. `turning` is the piece's own inertia about that edge's
4595
+ * axis (`turningOf`): the strong push is bounded by it (`holdPush`).
4588
4596
  */
4589
- topplePush(edge, height, isNarrow) {
4597
+ topplePush(edge, height, isNarrow, turning) {
4590
4598
  const push = TOPPLE * Math.min(height, 1);
4591
- return isNarrow ? Math.max(push, HOLD_MARGIN * this.o.gravity * Math.abs(edge) / (height * height + edge * edge)) : push;
4599
+ return isNarrow ? Math.max(push, holdPush({ edge, height, gravity: this.o.gravity, turning })) : push;
4600
+ }
4601
+ /**
4602
+ * The moment of inertia of the piece per kilogram (m²) about the world axis `axis` (0 x, 2 z) through its centre of mass, as the box it is: what resists its turning
4603
+ * about the edge it would go over (`holdPush`).
4604
+ */
4605
+ turningOf(b, axis) {
4606
+ const [hx, hy, hz] = b.halfExtents;
4607
+ const { x, y, z, w } = b.root.quaternion;
4608
+ const ax = axis === 0 ? 1 - 2 * (y * y + z * z) : 2 * (x * z - y * w);
4609
+ const ay = axis === 0 ? 2 * (x * y - z * w) : 2 * (y * z + x * w);
4610
+ const az = axis === 0 ? 2 * (x * z + y * w) : 1 - 2 * (x * x + y * y);
4611
+ return ((hy * hy + hz * hz) * ax * ax + (hx * hx + hz * hz) * ay * ay + (hx * hx + hy * hy) * az * az) / 3;
4592
4612
  }
4593
4613
  topple(b, dt) {
4594
4614
  const link = this.links.get(b);
@@ -4656,7 +4676,7 @@ var EnginePieces = class {
4656
4676
  const v = b.velocity;
4657
4677
  if (wx <= wz) {
4658
4678
  const edge = dirX > 0 ? x1 : x0;
4659
- const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN) * dt : 0;
4679
+ const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN, this.turningOf(b, 2)) * dt : 0;
4660
4680
  const rx = -edge;
4661
4681
  const ry = -low;
4662
4682
  w[2] += dw;
@@ -4664,7 +4684,7 @@ var EnginePieces = class {
4664
4684
  v[1] += dw * rx;
4665
4685
  } else {
4666
4686
  const edge = dirZ > 0 ? z1 : z0;
4667
- const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN) * dt : 0;
4687
+ const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN, this.turningOf(b, 0)) * dt : 0;
4668
4688
  const rz = -edge;
4669
4689
  const ry = -low;
4670
4690
  w[0] += dw;
@@ -11301,9 +11321,15 @@ var Renderer = class {
11301
11321
  const centre = centreOfBoxes(meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty()));
11302
11322
  if (this.standsWith(held, null, centre, feet.floor)) return;
11303
11323
  const inside = insideBy(convexHull(held), [centre[0], centre[2]]);
11304
- const reach = Math.max(body.halfExtents[0], body.halfExtents[2]);
11324
+ const reach = this.reachAlong(body, inside.out.x, inside.out.z);
11305
11325
  this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + inside.out.x * reach, feet.floor, centre[2] + inside.out.z * reach]);
11306
11326
  }
11327
+ /** How far (m) the box of a piece reaches from its middle along the level direction (x, z), turned as it is: the support of its box that way. */
11328
+ reachAlong(body, x, z) {
11329
+ const e = new this.THREE.Matrix4().makeRotationFromQuaternion(body.root.quaternion).elements;
11330
+ const [hx, hy, hz] = body.halfExtents;
11331
+ return hx * Math.abs(e[0] * x + e[2] * z) + hy * Math.abs(e[4] * x + e[6] * z) + hz * Math.abs(e[8] * x + e[10] * z);
11332
+ }
11307
11333
  /**
11308
11334
  * Whether what stands on the points `held` of its feet (`all` of them whole) stays up with its centre at `centre`: the centre is inside what holds by `UNDERMINED_STAND` per metre of its height above `floor`, or it keeps
11309
11335
  * most of the hold it had (`UNDERMINED_KEEP` of how far inside its whole feet `all` the centre was; null when those are gone with a leg).