@adatechnology/game-destruction-three 1.1.0 → 1.1.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.
- package/dist/index.global.js +46 -11
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -11
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -837,6 +837,8 @@ var SHARD_SHAPES = 6;
|
|
|
837
837
|
var SWEEP_MIN_SPEED = 1;
|
|
838
838
|
var WALL_RESTITUTION = 0.25;
|
|
839
839
|
var WALL_GLIDE = 0.7;
|
|
840
|
+
var TUMBLE_REACH = 0.1;
|
|
841
|
+
var LAID_GAP = 5e-3;
|
|
840
842
|
var STAND_RATIO = 0.6;
|
|
841
843
|
var SETTLE_SECONDS = 0.4;
|
|
842
844
|
var isSlow = (f) => f.vel.lengthSq() < 0.012 && f.ang.lengthSq() < 0.2;
|
|
@@ -1317,6 +1319,7 @@ var FragmentSystem = class {
|
|
|
1317
1319
|
const gy = Math.max(floor, pile);
|
|
1318
1320
|
const tip = pile > floor ? this.offEdge : null;
|
|
1319
1321
|
let contact = false;
|
|
1322
|
+
let turning = false;
|
|
1320
1323
|
if (mesh.position.y - ext < gy) {
|
|
1321
1324
|
contact = true;
|
|
1322
1325
|
mesh.position.y = gy + ext;
|
|
@@ -1325,8 +1328,9 @@ var FragmentSystem = class {
|
|
|
1325
1328
|
f.vel.x *= 0.7;
|
|
1326
1329
|
f.vel.z *= 0.7;
|
|
1327
1330
|
f.ang.multiplyScalar(0.55);
|
|
1328
|
-
|
|
1329
|
-
f.ang.
|
|
1331
|
+
const tumble = Math.min(1, TUMBLE_REACH / Math.max(h.x, h.y, h.z));
|
|
1332
|
+
f.ang.x += (this.rng() - 0.5) * 2 * tumble;
|
|
1333
|
+
f.ang.z += (this.rng() - 0.5) * 2 * tumble;
|
|
1330
1334
|
} else {
|
|
1331
1335
|
f.vel.y = 0;
|
|
1332
1336
|
const sliding = Math.hypot(f.vel.x, f.vel.z);
|
|
@@ -1344,9 +1348,13 @@ var FragmentSystem = class {
|
|
|
1344
1348
|
f.vel.z += tip.z * TIP_SPEED * dt * 10;
|
|
1345
1349
|
f.ang.x += tip.z * TIP_TURN * dt * 10;
|
|
1346
1350
|
f.ang.z -= tip.x * TIP_TURN * dt * 10;
|
|
1347
|
-
} else if (contact && f.vel.lengthSq() < 4)
|
|
1351
|
+
} else if (contact && f.vel.lengthSq() < 4) {
|
|
1352
|
+
turning = this.settle(f, dt);
|
|
1353
|
+
this.m.makeRotationFromQuaternion(mesh.quaternion);
|
|
1354
|
+
mesh.position.y = gy + (Math.abs(e[1]) * h.x + Math.abs(e[5]) * h.y + Math.abs(e[9]) * h.z) * sc;
|
|
1355
|
+
}
|
|
1348
1356
|
f.contact = contact;
|
|
1349
|
-
if (contact && isSlow(f)) {
|
|
1357
|
+
if (contact && !turning && isSlow(f)) {
|
|
1350
1358
|
f.still += dt;
|
|
1351
1359
|
if (f.still > SETTLE_SECONDS) this.sleep(f);
|
|
1352
1360
|
} else {
|
|
@@ -1424,7 +1432,7 @@ var FragmentSystem = class {
|
|
|
1424
1432
|
f.ang.x += (this.rng() - 0.5) * SHEET_SWAY * 4 * dt;
|
|
1425
1433
|
f.ang.z += (this.rng() - 0.5) * SHEET_SWAY * 4 * dt;
|
|
1426
1434
|
}
|
|
1427
|
-
/** Tip the fragment towards lying on its flattest face. */
|
|
1435
|
+
/** Tip the fragment towards lying on its flattest face. True while its end is still more than `LAID_GAP` from lying. */
|
|
1428
1436
|
settle(f, dt) {
|
|
1429
1437
|
const mesh = f.mesh;
|
|
1430
1438
|
this.m.makeRotationFromQuaternion(mesh.quaternion);
|
|
@@ -1446,6 +1454,7 @@ var FragmentSystem = class {
|
|
|
1446
1454
|
this.dq.setFromUnitVectors(this.v, this.w);
|
|
1447
1455
|
this.q.copy(this.dq).multiply(mesh.quaternion);
|
|
1448
1456
|
mesh.quaternion.slerp(this.q, clamp(dt * 7, 0, 1));
|
|
1457
|
+
return Math.sqrt(Math.max(0, 1 - this.v.y * this.v.y)) * Math.max(half[0], half[1], half[2]) > LAID_GAP;
|
|
1449
1458
|
}
|
|
1450
1459
|
/** Remove the fragments of one object (after `restore`). */
|
|
1451
1460
|
removeHome(home) {
|
|
@@ -3822,6 +3831,13 @@ var TAPER_MIN = 2e-3;
|
|
|
3822
3831
|
var RING_SEGMENTS = 16;
|
|
3823
3832
|
var TOPPLE = 3;
|
|
3824
3833
|
var HOLD_MARGIN = 4;
|
|
3834
|
+
var HOLD_MARGIN_REAL = 6;
|
|
3835
|
+
var holdPush = (params) => {
|
|
3836
|
+
const e = Math.abs(params.edge);
|
|
3837
|
+
const arm = params.height * params.height + e * e;
|
|
3838
|
+
if (arm <= 0) return 0;
|
|
3839
|
+
return Math.min(HOLD_MARGIN * params.gravity * e / arm, HOLD_MARGIN_REAL * params.gravity * e / (params.turning + arm));
|
|
3840
|
+
};
|
|
3825
3841
|
var SIDE_DEAD = 0.01;
|
|
3826
3842
|
var BOX_FOOT = 0.02;
|
|
3827
3843
|
var PUSH_SPIN = 0.3;
|
|
@@ -4584,11 +4600,24 @@ var EnginePieces = class {
|
|
|
4584
4600
|
/**
|
|
4585
4601
|
* 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
4602
|
* 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.
|
|
4603
|
+
* 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
|
|
4604
|
+
* axis (`turningOf`): the strong push is bounded by it (`holdPush`).
|
|
4588
4605
|
*/
|
|
4589
|
-
topplePush(edge, height, isNarrow) {
|
|
4606
|
+
topplePush(edge, height, isNarrow, turning) {
|
|
4590
4607
|
const push = TOPPLE * Math.min(height, 1);
|
|
4591
|
-
return isNarrow ? Math.max(push,
|
|
4608
|
+
return isNarrow ? Math.max(push, holdPush({ edge, height, gravity: this.o.gravity, turning })) : push;
|
|
4609
|
+
}
|
|
4610
|
+
/**
|
|
4611
|
+
* 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
|
|
4612
|
+
* about the edge it would go over (`holdPush`).
|
|
4613
|
+
*/
|
|
4614
|
+
turningOf(b, axis) {
|
|
4615
|
+
const [hx, hy, hz] = b.halfExtents;
|
|
4616
|
+
const { x, y, z, w } = b.root.quaternion;
|
|
4617
|
+
const ax = axis === 0 ? 1 - 2 * (y * y + z * z) : 2 * (x * z - y * w);
|
|
4618
|
+
const ay = axis === 0 ? 2 * (x * y - z * w) : 2 * (y * z + x * w);
|
|
4619
|
+
const az = axis === 0 ? 2 * (x * z + y * w) : 1 - 2 * (x * x + y * y);
|
|
4620
|
+
return ((hy * hy + hz * hz) * ax * ax + (hx * hx + hz * hz) * ay * ay + (hx * hx + hy * hy) * az * az) / 3;
|
|
4592
4621
|
}
|
|
4593
4622
|
topple(b, dt) {
|
|
4594
4623
|
const link = this.links.get(b);
|
|
@@ -4656,7 +4685,7 @@ var EnginePieces = class {
|
|
|
4656
4685
|
const v = b.velocity;
|
|
4657
4686
|
if (wx <= wz) {
|
|
4658
4687
|
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;
|
|
4688
|
+
const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN, this.turningOf(b, 2)) * dt : 0;
|
|
4660
4689
|
const rx = -edge;
|
|
4661
4690
|
const ry = -low;
|
|
4662
4691
|
w[2] += dw;
|
|
@@ -4664,7 +4693,7 @@ var EnginePieces = class {
|
|
|
4664
4693
|
v[1] += dw * rx;
|
|
4665
4694
|
} else {
|
|
4666
4695
|
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;
|
|
4696
|
+
const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN, this.turningOf(b, 0)) * dt : 0;
|
|
4668
4697
|
const rz = -edge;
|
|
4669
4698
|
const ry = -low;
|
|
4670
4699
|
w[0] += dw;
|
|
@@ -11301,9 +11330,15 @@ var Renderer = class {
|
|
|
11301
11330
|
const centre = centreOfBoxes(meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty()));
|
|
11302
11331
|
if (this.standsWith(held, null, centre, feet.floor)) return;
|
|
11303
11332
|
const inside = insideBy(convexHull(held), [centre[0], centre[2]]);
|
|
11304
|
-
const reach =
|
|
11333
|
+
const reach = this.reachAlong(body, inside.out.x, inside.out.z);
|
|
11305
11334
|
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
11335
|
}
|
|
11336
|
+
/** 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. */
|
|
11337
|
+
reachAlong(body, x, z) {
|
|
11338
|
+
const e = new this.THREE.Matrix4().makeRotationFromQuaternion(body.root.quaternion).elements;
|
|
11339
|
+
const [hx, hy, hz] = body.halfExtents;
|
|
11340
|
+
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);
|
|
11341
|
+
}
|
|
11307
11342
|
/**
|
|
11308
11343
|
* 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
11344
|
* 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).
|