@adatechnology/game-destruction-three 0.26.3 → 0.26.4
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 +50 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +50 -4
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -4755,6 +4755,8 @@ var NARROW2 = 0.3;
|
|
|
4755
4755
|
var SUPPORT_MARGIN = 0.05;
|
|
4756
4756
|
var TOPPLE2 = 3;
|
|
4757
4757
|
var TIP_ACCELERATION = 30;
|
|
4758
|
+
var TIP_RISING = 0.02;
|
|
4759
|
+
var TIP_RISE_AFTER = 0.5;
|
|
4758
4760
|
var TIP_LYING = 0.25;
|
|
4759
4761
|
var TIP_SECONDS = 3;
|
|
4760
4762
|
var STEP = 0.03;
|
|
@@ -4773,6 +4775,9 @@ var edgeFractions = (half, thin) => {
|
|
|
4773
4775
|
};
|
|
4774
4776
|
var SUPPORT_CHECKS2 = 16;
|
|
4775
4777
|
var SUPPORT_GAP2 = 0.02;
|
|
4778
|
+
var STEEP_MARGIN = 1.1;
|
|
4779
|
+
var SLOPE_MIN_NORMAL = 0.5;
|
|
4780
|
+
var LIES_FLAT = 0.985;
|
|
4776
4781
|
var KEEP_EVERY = 0.5;
|
|
4777
4782
|
var WAKE_ABOVE_SPEED = 0.05;
|
|
4778
4783
|
var WAKE_ABOVE_SPIN = 0.1;
|
|
@@ -4903,6 +4908,7 @@ var PieceSystem = class {
|
|
|
4903
4908
|
/** The surface normal and the friction of what the last `supportAt` found under the point (the ground and fixed tops are level: up, and no piece). */
|
|
4904
4909
|
__publicField(this, "supportNormal", UP);
|
|
4905
4910
|
__publicField(this, "supportFriction", null);
|
|
4911
|
+
__publicField(this, "supportBody", null);
|
|
4906
4912
|
/** The terrain's surfaces by rolling resistance and damping (`terrainSurface`), one object each. */
|
|
4907
4913
|
__publicField(this, "terrainSurfaces", /* @__PURE__ */ new Map());
|
|
4908
4914
|
/** The terrain's surface by ground tile (`groundTileKey`) this update, null for the default: read once per tile, not per contact per substep. */
|
|
@@ -5091,6 +5097,10 @@ var PieceSystem = class {
|
|
|
5091
5097
|
get(objectId) {
|
|
5092
5098
|
return this.list.find((b) => b.objectId === objectId) ?? null;
|
|
5093
5099
|
}
|
|
5100
|
+
/** Whether `upper` lies flat on a top of `lower` that is steeper than its friction holds: what it slides on, not a wall in its way. */
|
|
5101
|
+
slidesOn(upper, lower) {
|
|
5102
|
+
return this.restsOn(upper, lower, false) && this.onSteepSupport(upper);
|
|
5103
|
+
}
|
|
5094
5104
|
/** Sets a piece falling over, about the world axes x and z (a unit axis): its feet are thinner than the box that stands for it, so the box alone would hold it up. */
|
|
5095
5105
|
tip(body, x, z) {
|
|
5096
5106
|
body.tipping = { x, z, seconds: TIP_SECONDS };
|
|
@@ -5560,9 +5570,11 @@ var PieceSystem = class {
|
|
|
5560
5570
|
for (let k = 0; k < Math.min(SUPPORT_CHECKS2, n); k++) {
|
|
5561
5571
|
this.supportTurn = (this.supportTurn + 1) % n;
|
|
5562
5572
|
const b = this.list[this.supportTurn];
|
|
5563
|
-
if (!b.sleeping || b.held
|
|
5573
|
+
if (!b.sleeping || b.held) continue;
|
|
5564
5574
|
const rest = b.restPoints;
|
|
5565
|
-
|
|
5575
|
+
const budgeted = !!rest && rest.length > 0;
|
|
5576
|
+
const held = onlyBudget && !budgeted ? true : budgeted ? rest.every((point) => this.supportsPoint(b, point)) : this.supported(b, false) || this.supported(b, true);
|
|
5577
|
+
if (held && !this.onSteepSupport(b)) continue;
|
|
5566
5578
|
b.sleeping = false;
|
|
5567
5579
|
b.still = 0;
|
|
5568
5580
|
b.calmAt = null;
|
|
@@ -5685,6 +5697,7 @@ var PieceSystem = class {
|
|
|
5685
5697
|
if (fixed >= top) on = null;
|
|
5686
5698
|
this.supportNormal = on ? faceNormal(on, face) : UP;
|
|
5687
5699
|
this.supportFriction = on?.body.friction ?? null;
|
|
5700
|
+
this.supportBody = on?.body ?? null;
|
|
5688
5701
|
return Math.max(top, fixed);
|
|
5689
5702
|
}
|
|
5690
5703
|
/** Stops a piece that ran into something on its way from `start` to `pos` (`sweep`): moves it back to where it met it and takes the speed into it. */
|
|
@@ -6019,7 +6032,8 @@ var PieceSystem = class {
|
|
|
6019
6032
|
b.tipping.seconds -= h;
|
|
6020
6033
|
const [hx, hy, hz] = b.halfExtents;
|
|
6021
6034
|
const upHalf = Math.abs(e[1]) * hx + Math.abs(e[5]) * hy + Math.abs(e[9]) * hz;
|
|
6022
|
-
|
|
6035
|
+
const rising = TIP_SECONDS - b.tipping.seconds > TIP_RISE_AFTER && v[1] > TIP_RISING;
|
|
6036
|
+
if (upHalf < TIP_LYING || b.tipping.seconds <= 0 || rising) b.tipping = null;
|
|
6023
6037
|
else {
|
|
6024
6038
|
w[0] += b.tipping.x * TIP_ACCELERATION * h;
|
|
6025
6039
|
w[2] += b.tipping.z * TIP_ACCELERATION * h;
|
|
@@ -6069,7 +6083,31 @@ var PieceSystem = class {
|
|
|
6069
6083
|
b.balancing = unstable;
|
|
6070
6084
|
this.keepsTilt(b, q, dt);
|
|
6071
6085
|
const held = (touched || propped !== void 0) && !b.tipping;
|
|
6072
|
-
if (!b.hinge && (b.still >= SLEEP_AFTER || this.staysInPlace(b, held, pos, q, dt))) this.sleep(b);
|
|
6086
|
+
if (!b.hinge && (b.still >= SLEEP_AFTER || this.staysInPlace(b, held, pos, q, dt)) && !this.onSteepSupport(b)) this.sleep(b);
|
|
6087
|
+
}
|
|
6088
|
+
/**
|
|
6089
|
+
* Whether `b` lies flat on a settled top (asleep) tilted past what the friction of the two holds (a laptop on a table top gone over at 42 degrees, held by 0.49 up to 26),
|
|
6090
|
+
* with every corner that touches on it: it slides, it does not sleep there, and one asleep there wakes. Held by anything else (the floor, a flat top, a side it leans on, a
|
|
6091
|
+
* pile still moving) it is not this case: the contacts hold or move it.
|
|
6092
|
+
*/
|
|
6093
|
+
onSteepSupport(b) {
|
|
6094
|
+
const c = this.centerOf(b, this.p);
|
|
6095
|
+
const e = this.m.makeRotationFromQuaternion(b.root.quaternion).elements;
|
|
6096
|
+
let touching = false;
|
|
6097
|
+
for (const [sx, sy, sz] of this.samples(b, false)) {
|
|
6098
|
+
const y = c.y + e[1] * sx + e[5] * sy + e[9] * sz;
|
|
6099
|
+
if (this.supportAt(b, c.x + e[0] * sx + e[4] * sy + e[8] * sz, y, c.z + e[2] * sx + e[6] * sy + e[10] * sz, STEP) < y - SUPPORT_GAP2) continue;
|
|
6100
|
+
if (this.supportBody && !this.supportBody.sleeping) return false;
|
|
6101
|
+
const n = this.supportNormal;
|
|
6102
|
+
const ny = n[1];
|
|
6103
|
+
const holds = pairFriction(b.friction, this.supportFriction).static;
|
|
6104
|
+
if (ny >= 1 - 1e-6 || ny < SLOPE_MIN_NORMAL || Math.sqrt(Math.max(0, 1 - ny * ny)) / ny <= holds * STEEP_MARGIN) return false;
|
|
6105
|
+
let flat = 0;
|
|
6106
|
+
for (let axis = 0; axis < 12; axis += 4) flat = Math.max(flat, Math.abs(e[axis] * n[0] + e[axis + 1] * n[1] + e[axis + 2] * n[2]));
|
|
6107
|
+
if (flat < LIES_FLAT) return false;
|
|
6108
|
+
touching = true;
|
|
6109
|
+
}
|
|
6110
|
+
return touching;
|
|
6073
6111
|
}
|
|
6074
6112
|
/** The piece sleeps where it lies: its speeds are dropped, nothing moves it. */
|
|
6075
6113
|
sleep(b) {
|
|
@@ -6510,6 +6548,12 @@ var PieceSystem = class {
|
|
|
6510
6548
|
if (resting) return;
|
|
6511
6549
|
const [upper, c, up] = n[1] > 0 ? [a, ca, n] : [b, cb, [-n[0], -n[1], -n[2]]];
|
|
6512
6550
|
if (upper.held || upper.sleeping) return;
|
|
6551
|
+
const otherCentre = upper === a ? cb : ca;
|
|
6552
|
+
if (c[1] < otherCentre[1] - SLOP) {
|
|
6553
|
+
const level = boxesApartAlongGround(sa, sb);
|
|
6554
|
+
if (level) this.slideApart(a, b, ima, imb, level);
|
|
6555
|
+
return;
|
|
6556
|
+
}
|
|
6513
6557
|
upper.propped = up;
|
|
6514
6558
|
const e = this.m.makeRotationFromQuaternion(upper.root.quaternion).elements;
|
|
6515
6559
|
const r = [hit.point[0] - c[0], hit.point[1] - c[1], hit.point[2] - c[2]];
|
|
@@ -8699,6 +8743,7 @@ var SettledBatches = class {
|
|
|
8699
8743
|
this.batcher?.update();
|
|
8700
8744
|
this.sinceMade += dt;
|
|
8701
8745
|
if (!this.options.enabled || this.sinceMade < this.options.intervalSeconds) return;
|
|
8746
|
+
if (this.queue.pending() > 0) return;
|
|
8702
8747
|
const meshes = atRest().filter((mesh) => isBatchableDebris(mesh, this.options.maxVertices) || this.batched(mesh));
|
|
8703
8748
|
const outside = meshes.length - (this.batcher?.stats().batched ?? 0);
|
|
8704
8749
|
if (outside < this.options.minMeshes) return;
|
|
@@ -9648,6 +9693,7 @@ var Renderer = class {
|
|
|
9648
9693
|
if (!hit) return null;
|
|
9649
9694
|
const other = this.pieceSys.get(hit.object);
|
|
9650
9695
|
if (other && (p.round || other.round)) return null;
|
|
9696
|
+
if (other && this.pieceSys.slidesOn(p, other)) return null;
|
|
9651
9697
|
const material = this.world.part(hit.object, hit.part)?.material;
|
|
9652
9698
|
const restitution = material === void 0 ? void 0 : surfaceOf(material, this.world.materials.get(material))?.restitution;
|
|
9653
9699
|
return { object: hit.object, part: hit.part, distance: hit.distance, point: hit.point, normal: hit.normal, ...restitution === void 0 ? {} : { restitution } };
|