@adatechnology/game-destruction-three 0.22.0 → 0.22.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.global.js +28 -10
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +28 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1150,16 +1150,29 @@ var PieceSystem = class {
|
|
|
1150
1150
|
}
|
|
1151
1151
|
}
|
|
1152
1152
|
update(dt) {
|
|
1153
|
-
const steps = this.collisionSteps(dt);
|
|
1154
|
-
|
|
1153
|
+
const { steps, near } = this.collisionSteps(dt);
|
|
1154
|
+
if (steps === 1) {
|
|
1155
|
+
this.time += dt;
|
|
1156
|
+
this.step(dt);
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
const start = this.time;
|
|
1160
|
+
this.time = start + dt;
|
|
1161
|
+
const far = (b) => !near.has(b);
|
|
1162
|
+
this.step(dt, { moves: far, meets: (a, b) => far(a) && far(b) });
|
|
1163
|
+
for (let i = 0; i < steps; i++) {
|
|
1164
|
+
this.time = start + dt * (i + 1) / steps;
|
|
1165
|
+
this.step(dt / steps, { moves: (b) => near.has(b), meets: (a, b) => near.has(a) || near.has(b) });
|
|
1166
|
+
}
|
|
1155
1167
|
}
|
|
1156
1168
|
/**
|
|
1157
1169
|
* Steps of an update: one, or more while a round piece and a piece it could meet within the update close in fast enough to pass through each other between two (closing at
|
|
1158
1170
|
* their two speeds they cover at most the round one's radius per step: two cans at 3.6 m/s close 12 cm in a frame, a can is 7 cm across; a plank thrown at a can still counts).
|
|
1159
|
-
* A round piece with nothing in reach takes one step, so its sweep against the world (the costly part) runs once.
|
|
1171
|
+
* A round piece with nothing in reach takes one step, so its sweep against the world (the costly part) runs once; `near` holds the pieces of the pairs that need more.
|
|
1160
1172
|
*/
|
|
1161
1173
|
collisionSteps(dt) {
|
|
1162
1174
|
let need = 1;
|
|
1175
|
+
const near = /* @__PURE__ */ new Set();
|
|
1163
1176
|
const p = this.p;
|
|
1164
1177
|
const speedOf = (b) => b.held ? 0 : Math.hypot(b.velocity[0], b.velocity[1], b.velocity[2]);
|
|
1165
1178
|
for (const b of this.list) {
|
|
@@ -1176,13 +1189,17 @@ var PieceSystem = class {
|
|
|
1176
1189
|
const reach = closing * dt + rb + Math.hypot(o.halfExtents[0], o.halfExtents[1], o.halfExtents[2]);
|
|
1177
1190
|
const oc = this.centerOf(o, p);
|
|
1178
1191
|
if (Math.abs(oc.x - cx) > reach || Math.abs(oc.y - cy) > reach || Math.abs(oc.z - cz) > reach) continue;
|
|
1179
|
-
|
|
1192
|
+
const pair = Math.ceil(closing * dt / radius);
|
|
1193
|
+
if (pair < 2) continue;
|
|
1194
|
+
need = Math.max(need, pair);
|
|
1195
|
+
near.add(b);
|
|
1196
|
+
near.add(o);
|
|
1180
1197
|
}
|
|
1181
1198
|
}
|
|
1182
|
-
return Math.max(1, Math.min(MAX_COLLISION_STEPS, need));
|
|
1199
|
+
return { steps: Math.max(1, Math.min(MAX_COLLISION_STEPS, need)), near };
|
|
1183
1200
|
}
|
|
1184
|
-
step(
|
|
1185
|
-
|
|
1201
|
+
/** A step of `dt`: the pieces `only.moves` takes move (all when absent) and the pairs `only.meets` takes meet, so each pair meets in one of the steps of an update. */
|
|
1202
|
+
step(dt, only) {
|
|
1186
1203
|
this.solids = this.list.map((body) => {
|
|
1187
1204
|
const c = this.centerOf(body, new this.THREE.Vector3());
|
|
1188
1205
|
const h = body.halfExtents;
|
|
@@ -1243,14 +1260,14 @@ var PieceSystem = class {
|
|
|
1243
1260
|
b.calmAt = null;
|
|
1244
1261
|
continue;
|
|
1245
1262
|
}
|
|
1246
|
-
if (b.sleeping) continue;
|
|
1263
|
+
if (b.sleeping || only && !only.moves(b)) continue;
|
|
1247
1264
|
this.integrate(b, dt);
|
|
1248
1265
|
if (b.sleeping) continue;
|
|
1249
1266
|
const v = b.velocity;
|
|
1250
1267
|
const w = b.angularVelocity;
|
|
1251
1268
|
if (Math.hypot(v[0], v[1], v[2]) > WAKE_ABOVE_SPEED || Math.hypot(w[0], w[1], w[2]) > WAKE_ABOVE_SPIN) this.wakeAbove(b);
|
|
1252
1269
|
}
|
|
1253
|
-
this.collide(dt);
|
|
1270
|
+
this.collide(dt, only?.meets);
|
|
1254
1271
|
}
|
|
1255
1272
|
/** A few sleeping pieces each update (`SUPPORT_CHECKS`, in turn) look under them again: one whose table broke, or whose shelf fell over, falls. */
|
|
1256
1273
|
wakeUnsupported() {
|
|
@@ -1752,7 +1769,7 @@ var PieceSystem = class {
|
|
|
1752
1769
|
* Pieces against each other. Candidates by sweep and prune along x on their bounding spheres (sorted once per step: fifty cans cost a sort and a handful of pairs, not
|
|
1753
1770
|
* 1225); a pair with a round piece in it meets by its shapes (`shapeContact`) and exchanges an impulse, two boxes are only pushed apart (`separatePair`).
|
|
1754
1771
|
*/
|
|
1755
|
-
collide(dt) {
|
|
1772
|
+
collide(dt, meets) {
|
|
1756
1773
|
const n = this.list.length;
|
|
1757
1774
|
if (n < 2) return;
|
|
1758
1775
|
const centers = this.list.map((b) => {
|
|
@@ -1770,6 +1787,7 @@ var PieceSystem = class {
|
|
|
1770
1787
|
const a = this.list[i];
|
|
1771
1788
|
const b = this.list[j];
|
|
1772
1789
|
if ((a.held || a.sleeping) && (b.held || b.sleeping)) continue;
|
|
1790
|
+
if (meets && !meets(a, b)) continue;
|
|
1773
1791
|
const r = radii[i] + radii[j];
|
|
1774
1792
|
const ca = centers[i];
|
|
1775
1793
|
const cb = centers[j];
|