@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.
@@ -14627,6 +14627,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14627
14627
  var RING_SEGMENTS = 16;
14628
14628
  var TOPPLE = 3;
14629
14629
  var HOLD_MARGIN = 4;
14630
+ var HOLD_MARGIN_REAL = 6;
14631
+ var holdPush = (params) => {
14632
+ const e = Math.abs(params.edge);
14633
+ const arm = params.height * params.height + e * e;
14634
+ if (arm <= 0) return 0;
14635
+ return Math.min(HOLD_MARGIN * params.gravity * e / arm, HOLD_MARGIN_REAL * params.gravity * e / (params.turning + arm));
14636
+ };
14630
14637
  var SIDE_DEAD = 0.01;
14631
14638
  var BOX_FOOT = 0.02;
14632
14639
  var PUSH_SPIN = 0.3;
@@ -15389,11 +15396,24 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15389
15396
  /**
15390
15397
  * 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
15391
15398
  * 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
15392
- * the contacts of one instant sit off its centre: a box rocking on a table's edge reads like that, and stays.
15399
+ * 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
15400
+ * axis (`turningOf`): the strong push is bounded by it (`holdPush`).
15393
15401
  */
15394
- topplePush(edge, height, isNarrow) {
15402
+ topplePush(edge, height, isNarrow, turning) {
15395
15403
  const push = TOPPLE * Math.min(height, 1);
15396
- return isNarrow ? Math.max(push, HOLD_MARGIN * this.o.gravity * Math.abs(edge) / (height * height + edge * edge)) : push;
15404
+ return isNarrow ? Math.max(push, holdPush({ edge, height, gravity: this.o.gravity, turning })) : push;
15405
+ }
15406
+ /**
15407
+ * 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
15408
+ * about the edge it would go over (`holdPush`).
15409
+ */
15410
+ turningOf(b, axis2) {
15411
+ const [hx, hy, hz2] = b.halfExtents;
15412
+ const { x, y, z, w } = b.root.quaternion;
15413
+ const ax = axis2 === 0 ? 1 - 2 * (y * y + z * z) : 2 * (x * z - y * w);
15414
+ const ay = axis2 === 0 ? 2 * (x * y - z * w) : 2 * (y * z + x * w);
15415
+ const az = axis2 === 0 ? 2 * (x * z + y * w) : 1 - 2 * (x * x + y * y);
15416
+ return ((hy * hy + hz2 * hz2) * ax * ax + (hx * hx + hz2 * hz2) * ay * ay + (hx * hx + hy * hy) * az * az) / 3;
15397
15417
  }
15398
15418
  topple(b, dt) {
15399
15419
  const link = this.links.get(b);
@@ -15461,7 +15481,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15461
15481
  const v = b.velocity;
15462
15482
  if (wx <= wz) {
15463
15483
  const edge = dirX > 0 ? x1 : x0;
15464
- const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN) * dt : 0;
15484
+ const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN, this.turningOf(b, 2)) * dt : 0;
15465
15485
  const rx = -edge;
15466
15486
  const ry = -low;
15467
15487
  w[2] += dw;
@@ -15469,7 +15489,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15469
15489
  v[1] += dw * rx;
15470
15490
  } else {
15471
15491
  const edge = dirZ > 0 ? z1 : z0;
15472
- const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN) * dt : 0;
15492
+ const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN, this.turningOf(b, 0)) * dt : 0;
15473
15493
  const rz = -edge;
15474
15494
  const ry = -low;
15475
15495
  w[0] += dw;
@@ -31385,9 +31405,15 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
31385
31405
  const centre = centreOfBoxes(meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty()));
31386
31406
  if (this.standsWith(held, null, centre, feet.floor)) return;
31387
31407
  const inside = insideBy(convexHull2(held), [centre[0], centre[2]]);
31388
- const reach2 = Math.max(body.halfExtents[0], body.halfExtents[2]);
31408
+ const reach2 = this.reachAlong(body, inside.out.x, inside.out.z);
31389
31409
  this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + inside.out.x * reach2, feet.floor, centre[2] + inside.out.z * reach2]);
31390
31410
  }
31411
+ /** 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. */
31412
+ reachAlong(body, x, z) {
31413
+ const e = new this.THREE.Matrix4().makeRotationFromQuaternion(body.root.quaternion).elements;
31414
+ const [hx, hy, hz2] = body.halfExtents;
31415
+ return hx * Math.abs(e[0] * x + e[2] * z) + hy * Math.abs(e[4] * x + e[6] * z) + hz2 * Math.abs(e[8] * x + e[10] * z);
31416
+ }
31391
31417
  /**
31392
31418
  * 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
31393
31419
  * 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).