@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.global.js
CHANGED
|
@@ -11358,6 +11358,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11358
11358
|
var SWEEP_MIN_SPEED = 1;
|
|
11359
11359
|
var WALL_RESTITUTION = 0.25;
|
|
11360
11360
|
var WALL_GLIDE = 0.7;
|
|
11361
|
+
var TUMBLE_REACH = 0.1;
|
|
11362
|
+
var LAID_GAP = 5e-3;
|
|
11361
11363
|
var STAND_RATIO = 0.6;
|
|
11362
11364
|
var SETTLE_SECONDS = 0.4;
|
|
11363
11365
|
var isSlow = (f) => f.vel.lengthSq() < 0.012 && f.ang.lengthSq() < 0.2;
|
|
@@ -11838,6 +11840,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11838
11840
|
const gy = Math.max(floor2, pile);
|
|
11839
11841
|
const tip = pile > floor2 ? this.offEdge : null;
|
|
11840
11842
|
let contact = false;
|
|
11843
|
+
let turning = false;
|
|
11841
11844
|
if (mesh2.position.y - ext < gy) {
|
|
11842
11845
|
contact = true;
|
|
11843
11846
|
mesh2.position.y = gy + ext;
|
|
@@ -11846,8 +11849,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11846
11849
|
f.vel.x *= 0.7;
|
|
11847
11850
|
f.vel.z *= 0.7;
|
|
11848
11851
|
f.ang.multiplyScalar(0.55);
|
|
11849
|
-
|
|
11850
|
-
f.ang.
|
|
11852
|
+
const tumble = Math.min(1, TUMBLE_REACH / Math.max(h.x, h.y, h.z));
|
|
11853
|
+
f.ang.x += (this.rng() - 0.5) * 2 * tumble;
|
|
11854
|
+
f.ang.z += (this.rng() - 0.5) * 2 * tumble;
|
|
11851
11855
|
} else {
|
|
11852
11856
|
f.vel.y = 0;
|
|
11853
11857
|
const sliding = Math.hypot(f.vel.x, f.vel.z);
|
|
@@ -11865,9 +11869,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11865
11869
|
f.vel.z += tip.z * TIP_SPEED * dt * 10;
|
|
11866
11870
|
f.ang.x += tip.z * TIP_TURN * dt * 10;
|
|
11867
11871
|
f.ang.z -= tip.x * TIP_TURN * dt * 10;
|
|
11868
|
-
} else if (contact && f.vel.lengthSq() < 4)
|
|
11872
|
+
} else if (contact && f.vel.lengthSq() < 4) {
|
|
11873
|
+
turning = this.settle(f, dt);
|
|
11874
|
+
this.m.makeRotationFromQuaternion(mesh2.quaternion);
|
|
11875
|
+
mesh2.position.y = gy + (Math.abs(e[1]) * h.x + Math.abs(e[5]) * h.y + Math.abs(e[9]) * h.z) * sc;
|
|
11876
|
+
}
|
|
11869
11877
|
f.contact = contact;
|
|
11870
|
-
if (contact && isSlow(f)) {
|
|
11878
|
+
if (contact && !turning && isSlow(f)) {
|
|
11871
11879
|
f.still += dt;
|
|
11872
11880
|
if (f.still > SETTLE_SECONDS) this.sleep(f);
|
|
11873
11881
|
} else {
|
|
@@ -11945,7 +11953,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11945
11953
|
f.ang.x += (this.rng() - 0.5) * SHEET_SWAY * 4 * dt;
|
|
11946
11954
|
f.ang.z += (this.rng() - 0.5) * SHEET_SWAY * 4 * dt;
|
|
11947
11955
|
}
|
|
11948
|
-
/** Tip the fragment towards lying on its flattest face. */
|
|
11956
|
+
/** Tip the fragment towards lying on its flattest face. True while its end is still more than `LAID_GAP` from lying. */
|
|
11949
11957
|
settle(f, dt) {
|
|
11950
11958
|
const mesh2 = f.mesh;
|
|
11951
11959
|
this.m.makeRotationFromQuaternion(mesh2.quaternion);
|
|
@@ -11967,6 +11975,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11967
11975
|
this.dq.setFromUnitVectors(this.v, this.w);
|
|
11968
11976
|
this.q.copy(this.dq).multiply(mesh2.quaternion);
|
|
11969
11977
|
mesh2.quaternion.slerp(this.q, clamp6(dt * 7, 0, 1));
|
|
11978
|
+
return Math.sqrt(Math.max(0, 1 - this.v.y * this.v.y)) * Math.max(half[0], half[1], half[2]) > LAID_GAP;
|
|
11970
11979
|
}
|
|
11971
11980
|
/** Remove the fragments of one object (after `restore`). */
|
|
11972
11981
|
removeHome(home) {
|
|
@@ -14627,6 +14636,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14627
14636
|
var RING_SEGMENTS = 16;
|
|
14628
14637
|
var TOPPLE = 3;
|
|
14629
14638
|
var HOLD_MARGIN = 4;
|
|
14639
|
+
var HOLD_MARGIN_REAL = 6;
|
|
14640
|
+
var holdPush = (params) => {
|
|
14641
|
+
const e = Math.abs(params.edge);
|
|
14642
|
+
const arm = params.height * params.height + e * e;
|
|
14643
|
+
if (arm <= 0) return 0;
|
|
14644
|
+
return Math.min(HOLD_MARGIN * params.gravity * e / arm, HOLD_MARGIN_REAL * params.gravity * e / (params.turning + arm));
|
|
14645
|
+
};
|
|
14630
14646
|
var SIDE_DEAD = 0.01;
|
|
14631
14647
|
var BOX_FOOT = 0.02;
|
|
14632
14648
|
var PUSH_SPIN = 0.3;
|
|
@@ -15389,11 +15405,24 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15389
15405
|
/**
|
|
15390
15406
|
* 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
15407
|
* 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.
|
|
15408
|
+
* 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
|
|
15409
|
+
* axis (`turningOf`): the strong push is bounded by it (`holdPush`).
|
|
15393
15410
|
*/
|
|
15394
|
-
topplePush(edge, height, isNarrow) {
|
|
15411
|
+
topplePush(edge, height, isNarrow, turning) {
|
|
15395
15412
|
const push = TOPPLE * Math.min(height, 1);
|
|
15396
|
-
return isNarrow ? Math.max(push,
|
|
15413
|
+
return isNarrow ? Math.max(push, holdPush({ edge, height, gravity: this.o.gravity, turning })) : push;
|
|
15414
|
+
}
|
|
15415
|
+
/**
|
|
15416
|
+
* 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
|
|
15417
|
+
* about the edge it would go over (`holdPush`).
|
|
15418
|
+
*/
|
|
15419
|
+
turningOf(b, axis2) {
|
|
15420
|
+
const [hx, hy, hz2] = b.halfExtents;
|
|
15421
|
+
const { x, y, z, w } = b.root.quaternion;
|
|
15422
|
+
const ax = axis2 === 0 ? 1 - 2 * (y * y + z * z) : 2 * (x * z - y * w);
|
|
15423
|
+
const ay = axis2 === 0 ? 2 * (x * y - z * w) : 2 * (y * z + x * w);
|
|
15424
|
+
const az = axis2 === 0 ? 2 * (x * z + y * w) : 1 - 2 * (x * x + y * y);
|
|
15425
|
+
return ((hy * hy + hz2 * hz2) * ax * ax + (hx * hx + hz2 * hz2) * ay * ay + (hx * hx + hy * hy) * az * az) / 3;
|
|
15397
15426
|
}
|
|
15398
15427
|
topple(b, dt) {
|
|
15399
15428
|
const link = this.links.get(b);
|
|
@@ -15461,7 +15490,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15461
15490
|
const v = b.velocity;
|
|
15462
15491
|
if (wx <= wz) {
|
|
15463
15492
|
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;
|
|
15493
|
+
const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN, this.turningOf(b, 2)) * dt : 0;
|
|
15465
15494
|
const rx = -edge;
|
|
15466
15495
|
const ry = -low;
|
|
15467
15496
|
w[2] += dw;
|
|
@@ -15469,7 +15498,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15469
15498
|
v[1] += dw * rx;
|
|
15470
15499
|
} else {
|
|
15471
15500
|
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;
|
|
15501
|
+
const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN, this.turningOf(b, 0)) * dt : 0;
|
|
15473
15502
|
const rz = -edge;
|
|
15474
15503
|
const ry = -low;
|
|
15475
15504
|
w[0] += dw;
|
|
@@ -31385,9 +31414,15 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31385
31414
|
const centre = centreOfBoxes(meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty()));
|
|
31386
31415
|
if (this.standsWith(held, null, centre, feet.floor)) return;
|
|
31387
31416
|
const inside = insideBy(convexHull2(held), [centre[0], centre[2]]);
|
|
31388
|
-
const reach2 =
|
|
31417
|
+
const reach2 = this.reachAlong(body, inside.out.x, inside.out.z);
|
|
31389
31418
|
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
31419
|
}
|
|
31420
|
+
/** 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. */
|
|
31421
|
+
reachAlong(body, x, z) {
|
|
31422
|
+
const e = new this.THREE.Matrix4().makeRotationFromQuaternion(body.root.quaternion).elements;
|
|
31423
|
+
const [hx, hy, hz2] = body.halfExtents;
|
|
31424
|
+
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);
|
|
31425
|
+
}
|
|
31391
31426
|
/**
|
|
31392
31427
|
* 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
31428
|
* 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).
|