@adatechnology/game-destruction-three 1.1.1 → 1.2.0
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.d.ts +3 -1
- package/dist/index.global.js +309 -44
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +161 -27
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
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;
|
|
@@ -1071,6 +1073,7 @@ var FragmentSystem = class {
|
|
|
1071
1073
|
dying: false,
|
|
1072
1074
|
air: f.shape === "scrap" && sz[2] <= SHEET_MAX ? SHEET_AIR : 0,
|
|
1073
1075
|
body: null,
|
|
1076
|
+
rigid: null,
|
|
1074
1077
|
born: this.tick,
|
|
1075
1078
|
life: lasting ? 0 : Math.max(0, typeof this.o.life === "function" ? this.o.life(f, home) : this.o.life),
|
|
1076
1079
|
seq: this.nextSeq++,
|
|
@@ -1079,9 +1082,12 @@ var FragmentSystem = class {
|
|
|
1079
1082
|
isMortal: false
|
|
1080
1083
|
};
|
|
1081
1084
|
if (lasting || isBig(f.size)) {
|
|
1085
|
+
const rigid = this.o.rigid;
|
|
1086
|
+
if (rigid) live.rigid = rigid.add(mesh, [sc.x / 2, sc.y / 2, sc.z / 2], f.mass, f.velocity, f.angularVelocity);
|
|
1082
1087
|
live.body = {
|
|
1083
1088
|
mass: f.mass,
|
|
1084
1089
|
push: (x, z) => {
|
|
1090
|
+
if (rigid && live.rigid) return rigid.push(live.rigid, x, z);
|
|
1085
1091
|
live.vel.x = x;
|
|
1086
1092
|
live.vel.z = z;
|
|
1087
1093
|
live.vel.y = Math.max(live.vel.y, 0.3);
|
|
@@ -1119,8 +1125,14 @@ var FragmentSystem = class {
|
|
|
1119
1125
|
const k = (1 - dist / radius) ** 2 * speed;
|
|
1120
1126
|
d.normalize().multiplyScalar(k);
|
|
1121
1127
|
d.y += k * 0.4;
|
|
1128
|
+
const spin = this.w.set(this.rng() - 0.5, this.rng() - 0.5, this.rng() - 0.5).multiplyScalar(k);
|
|
1129
|
+
if (f.rigid) {
|
|
1130
|
+
spin.multiplyScalar(Math.min(1, TUMBLE_REACH / Math.max(f.half.x, f.half.y, f.half.z)));
|
|
1131
|
+
this.o.rigid?.shove(f.rigid, [d.x, d.y, d.z], [spin.x, spin.y, spin.z]);
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1122
1134
|
f.vel.add(d);
|
|
1123
|
-
f.ang.add(
|
|
1135
|
+
f.ang.add(spin);
|
|
1124
1136
|
this.rouse(f);
|
|
1125
1137
|
}
|
|
1126
1138
|
}
|
|
@@ -1174,7 +1186,7 @@ var FragmentSystem = class {
|
|
|
1174
1186
|
/** What lies inside the disc looks at the ground again: it was dug or heaped under it. */
|
|
1175
1187
|
wakeRegion(x, z, radius) {
|
|
1176
1188
|
for (const f of this.list) {
|
|
1177
|
-
if (!f.asleep || Math.hypot(f.mesh.position.x - x, f.mesh.position.z - z) > radius) continue;
|
|
1189
|
+
if (!f.asleep || f.rigid || Math.hypot(f.mesh.position.x - x, f.mesh.position.z - z) > radius) continue;
|
|
1178
1190
|
this.rouse(f);
|
|
1179
1191
|
}
|
|
1180
1192
|
}
|
|
@@ -1182,6 +1194,7 @@ var FragmentSystem = class {
|
|
|
1182
1194
|
this.tick++;
|
|
1183
1195
|
this.clock += dt;
|
|
1184
1196
|
this.wakeUnsupported();
|
|
1197
|
+
this.wakeRigid();
|
|
1185
1198
|
this.beginTick();
|
|
1186
1199
|
const g = this.o.gravity;
|
|
1187
1200
|
for (let i = this.active.length - 1; i >= 0; i--) {
|
|
@@ -1192,6 +1205,7 @@ var FragmentSystem = class {
|
|
|
1192
1205
|
if (f.fade <= 0) {
|
|
1193
1206
|
this.instances.remove(f.mesh);
|
|
1194
1207
|
this.o.scene.remove(f.mesh);
|
|
1208
|
+
this.release(f);
|
|
1195
1209
|
f.isActive = false;
|
|
1196
1210
|
this.active.splice(i, 1);
|
|
1197
1211
|
this.list.splice(this.list.indexOf(f), 1);
|
|
@@ -1200,19 +1214,34 @@ var FragmentSystem = class {
|
|
|
1200
1214
|
f.mesh.scale.copy(f.baseScale).multiplyScalar(f.fade);
|
|
1201
1215
|
}
|
|
1202
1216
|
if (f.asleep) continue;
|
|
1203
|
-
this.
|
|
1217
|
+
if (f.rigid) this.follow(f);
|
|
1218
|
+
else this.step(f, dt, g);
|
|
1204
1219
|
}
|
|
1205
1220
|
this.expireSleepers();
|
|
1206
1221
|
this.keepBudget();
|
|
1207
1222
|
this.trail?.commit();
|
|
1208
1223
|
this.drawInstanced();
|
|
1209
1224
|
}
|
|
1225
|
+
/** Its body goes with it. */
|
|
1226
|
+
release(f) {
|
|
1227
|
+
if (f.rigid) this.o.rigid?.remove(f.rigid);
|
|
1228
|
+
f.rigid = null;
|
|
1229
|
+
}
|
|
1230
|
+
/** The debris moved by a rigid body that the body's world woke (something fell on it, a blast, its ground dug): it is awake here too. */
|
|
1231
|
+
wakeRigid() {
|
|
1232
|
+
for (const f of this.list) if (f.rigid && f.asleep && !f.dying && !f.rigid.sleeping) this.rouse(f);
|
|
1233
|
+
}
|
|
1234
|
+
/** A piece of debris moved by its rigid body: the body wrote its pose; it sleeps here when the body does. */
|
|
1235
|
+
follow(f) {
|
|
1236
|
+
f.box = void 0;
|
|
1237
|
+
if (f.rigid?.sleeping) this.sleep(f);
|
|
1238
|
+
}
|
|
1210
1239
|
/** The meshes go back to the step's pose and the ones awake are recorded as the previous one (`interpolate`). */
|
|
1211
1240
|
beginTick() {
|
|
1212
1241
|
const trail = this.trail;
|
|
1213
1242
|
if (!trail) return;
|
|
1214
1243
|
trail.begin();
|
|
1215
|
-
for (const f of this.active) if (!f.asleep) trail.record(f.mesh);
|
|
1244
|
+
for (const f of this.active) if (!f.asleep && !f.rigid) trail.record(f.mesh);
|
|
1216
1245
|
}
|
|
1217
1246
|
/** The meshes get the step pose back, before anything reads them. The instances take it at the next `update`. */
|
|
1218
1247
|
restoreStepPose() {
|
|
@@ -1227,7 +1256,7 @@ var FragmentSystem = class {
|
|
|
1227
1256
|
/** The fragments in flight are drawn by the instances, those at rest on their own (the settled batches take them): then the instances take the transforms of this update. */
|
|
1228
1257
|
drawInstanced() {
|
|
1229
1258
|
for (const f of this.active) {
|
|
1230
|
-
if (f.asleep) this.instances.remove(f.mesh);
|
|
1259
|
+
if (f.asleep || f.rigid) this.instances.remove(f.mesh);
|
|
1231
1260
|
else this.instances.add(f.mesh);
|
|
1232
1261
|
}
|
|
1233
1262
|
this.instances.sync();
|
|
@@ -1237,12 +1266,12 @@ var FragmentSystem = class {
|
|
|
1237
1266
|
const most = this.o.maxAwake;
|
|
1238
1267
|
if (most === void 0 || !Number.isFinite(most)) return;
|
|
1239
1268
|
let awake = 0;
|
|
1240
|
-
for (const f of this.active) if (!f.asleep && !f.dying) awake++;
|
|
1269
|
+
for (const f of this.active) if (!f.asleep && !f.dying && !f.rigid) awake++;
|
|
1241
1270
|
if (awake <= most) return;
|
|
1242
1271
|
for (let i = 0; i < this.active.length; i++) {
|
|
1243
1272
|
const f = this.active[i];
|
|
1244
1273
|
if (awake <= most) return;
|
|
1245
|
-
if (f.asleep || f.dying || !f.contact || !isSlow(f)) continue;
|
|
1274
|
+
if (f.asleep || f.dying || f.rigid || !f.contact || !isSlow(f)) continue;
|
|
1246
1275
|
this.sleep(f);
|
|
1247
1276
|
i--;
|
|
1248
1277
|
awake--;
|
|
@@ -1274,7 +1303,7 @@ var FragmentSystem = class {
|
|
|
1274
1303
|
for (let k = 0; k < Math.min(SUPPORT_CHECKS, n); k++) {
|
|
1275
1304
|
this.supportTurn = (this.supportTurn + 1) % n;
|
|
1276
1305
|
const f = this.list[this.supportTurn];
|
|
1277
|
-
if (!f.asleep || f.dying) continue;
|
|
1306
|
+
if (!f.asleep || f.dying || f.rigid) continue;
|
|
1278
1307
|
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
1279
1308
|
const ext = Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z;
|
|
1280
1309
|
f.floor = null;
|
|
@@ -1317,6 +1346,7 @@ var FragmentSystem = class {
|
|
|
1317
1346
|
const gy = Math.max(floor, pile);
|
|
1318
1347
|
const tip = pile > floor ? this.offEdge : null;
|
|
1319
1348
|
let contact = false;
|
|
1349
|
+
let turning = false;
|
|
1320
1350
|
if (mesh.position.y - ext < gy) {
|
|
1321
1351
|
contact = true;
|
|
1322
1352
|
mesh.position.y = gy + ext;
|
|
@@ -1325,8 +1355,9 @@ var FragmentSystem = class {
|
|
|
1325
1355
|
f.vel.x *= 0.7;
|
|
1326
1356
|
f.vel.z *= 0.7;
|
|
1327
1357
|
f.ang.multiplyScalar(0.55);
|
|
1328
|
-
|
|
1329
|
-
f.ang.
|
|
1358
|
+
const tumble = Math.min(1, TUMBLE_REACH / Math.max(h.x, h.y, h.z));
|
|
1359
|
+
f.ang.x += (this.rng() - 0.5) * 2 * tumble;
|
|
1360
|
+
f.ang.z += (this.rng() - 0.5) * 2 * tumble;
|
|
1330
1361
|
} else {
|
|
1331
1362
|
f.vel.y = 0;
|
|
1332
1363
|
const sliding = Math.hypot(f.vel.x, f.vel.z);
|
|
@@ -1344,9 +1375,13 @@ var FragmentSystem = class {
|
|
|
1344
1375
|
f.vel.z += tip.z * TIP_SPEED * dt * 10;
|
|
1345
1376
|
f.ang.x += tip.z * TIP_TURN * dt * 10;
|
|
1346
1377
|
f.ang.z -= tip.x * TIP_TURN * dt * 10;
|
|
1347
|
-
} else if (contact && f.vel.lengthSq() < 4)
|
|
1378
|
+
} else if (contact && f.vel.lengthSq() < 4) {
|
|
1379
|
+
turning = this.settle(f, dt);
|
|
1380
|
+
this.m.makeRotationFromQuaternion(mesh.quaternion);
|
|
1381
|
+
mesh.position.y = gy + (Math.abs(e[1]) * h.x + Math.abs(e[5]) * h.y + Math.abs(e[9]) * h.z) * sc;
|
|
1382
|
+
}
|
|
1348
1383
|
f.contact = contact;
|
|
1349
|
-
if (contact && isSlow(f)) {
|
|
1384
|
+
if (contact && !turning && isSlow(f)) {
|
|
1350
1385
|
f.still += dt;
|
|
1351
1386
|
if (f.still > SETTLE_SECONDS) this.sleep(f);
|
|
1352
1387
|
} else {
|
|
@@ -1424,7 +1459,7 @@ var FragmentSystem = class {
|
|
|
1424
1459
|
f.ang.x += (this.rng() - 0.5) * SHEET_SWAY * 4 * dt;
|
|
1425
1460
|
f.ang.z += (this.rng() - 0.5) * SHEET_SWAY * 4 * dt;
|
|
1426
1461
|
}
|
|
1427
|
-
/** Tip the fragment towards lying on its flattest face. */
|
|
1462
|
+
/** Tip the fragment towards lying on its flattest face. True while its end is still more than `LAID_GAP` from lying. */
|
|
1428
1463
|
settle(f, dt) {
|
|
1429
1464
|
const mesh = f.mesh;
|
|
1430
1465
|
this.m.makeRotationFromQuaternion(mesh.quaternion);
|
|
@@ -1446,6 +1481,7 @@ var FragmentSystem = class {
|
|
|
1446
1481
|
this.dq.setFromUnitVectors(this.v, this.w);
|
|
1447
1482
|
this.q.copy(this.dq).multiply(mesh.quaternion);
|
|
1448
1483
|
mesh.quaternion.slerp(this.q, clamp(dt * 7, 0, 1));
|
|
1484
|
+
return Math.sqrt(Math.max(0, 1 - this.v.y * this.v.y)) * Math.max(half[0], half[1], half[2]) > LAID_GAP;
|
|
1449
1485
|
}
|
|
1450
1486
|
/** Remove the fragments of one object (after `restore`). */
|
|
1451
1487
|
removeHome(home) {
|
|
@@ -1453,6 +1489,7 @@ var FragmentSystem = class {
|
|
|
1453
1489
|
if (this.list[i].home === home) {
|
|
1454
1490
|
this.instances.remove(this.list[i].mesh);
|
|
1455
1491
|
this.o.scene.remove(this.list[i].mesh);
|
|
1492
|
+
this.release(this.list[i]);
|
|
1456
1493
|
this.deactivate(this.list[i]);
|
|
1457
1494
|
this.list[i].deadline = Infinity;
|
|
1458
1495
|
this.list.splice(i, 1);
|
|
@@ -1462,7 +1499,10 @@ var FragmentSystem = class {
|
|
|
1462
1499
|
clear() {
|
|
1463
1500
|
this.trail?.clear();
|
|
1464
1501
|
this.instances.clear();
|
|
1465
|
-
for (const f of this.list)
|
|
1502
|
+
for (const f of this.list) {
|
|
1503
|
+
this.o.scene.remove(f.mesh);
|
|
1504
|
+
this.release(f);
|
|
1505
|
+
}
|
|
1466
1506
|
this.list.length = 0;
|
|
1467
1507
|
this.active.length = 0;
|
|
1468
1508
|
this.mortal.length = 0;
|
|
@@ -3379,7 +3419,7 @@ var DEFAULT_MIN_IMPULSE = 30;
|
|
|
3379
3419
|
var DEFAULT_HITS_MAX = 32;
|
|
3380
3420
|
var DEFAULT_MIN_APPROACH = 1.5;
|
|
3381
3421
|
var DEFAULT_CONTACT_RADIUS = 0.1;
|
|
3382
|
-
var createEngineImpacts = (loop, statics, destruction, options = {}) => {
|
|
3422
|
+
var createEngineImpacts = (loop, statics, destruction, options = {}, isDebris) => {
|
|
3383
3423
|
const hitsMax = options.hitsMax ?? DEFAULT_HITS_MAX;
|
|
3384
3424
|
const radius = options.contactRadius ?? DEFAULT_CONTACT_RADIUS;
|
|
3385
3425
|
const minApproach = options.minApproach ?? DEFAULT_MIN_APPROACH;
|
|
@@ -3387,8 +3427,11 @@ var createEngineImpacts = (loop, statics, destruction, options = {}) => {
|
|
|
3387
3427
|
minImpulse: options.minImpulse ?? DEFAULT_MIN_IMPULSE,
|
|
3388
3428
|
bodiesMax: hitsMax,
|
|
3389
3429
|
accepts: (body) => statics.ownerOf.has(body),
|
|
3430
|
+
// what is left of a part that broke breaks nothing again when it lands: a blow of debris is no blow to the world
|
|
3431
|
+
...isDebris ? { ignores: isDebris } : {},
|
|
3390
3432
|
onImpact: (impact2) => {
|
|
3391
3433
|
if (impact2.approach < minApproach) return;
|
|
3434
|
+
if (options.harmless?.(impact2.other)) return;
|
|
3392
3435
|
const object = statics.ownerOf.get(impact2.body);
|
|
3393
3436
|
const part = statics.partOf.get(impact2.body);
|
|
3394
3437
|
if (object === void 0 || part === void 0 || destruction.part(object, part) === null) return;
|
|
@@ -3846,6 +3889,7 @@ var WAKE_MARGIN2 = 0.1;
|
|
|
3846
3889
|
var NO_PROGRESS = 0.75;
|
|
3847
3890
|
var WAY_STEP_MIN = 0.02;
|
|
3848
3891
|
var WAY_STEP_MAX = 0.1;
|
|
3892
|
+
var BORN_INSIDE = { layers: ["static", "rubble"] };
|
|
3849
3893
|
var EnginePieces = class {
|
|
3850
3894
|
constructor(THREE, world, o) {
|
|
3851
3895
|
__publicField(this, "world", world);
|
|
@@ -3888,6 +3932,12 @@ var EnginePieces = class {
|
|
|
3888
3932
|
__publicField(this, "blasts", []);
|
|
3889
3933
|
/** The host's fixed things (`staticSolids`) as static bodies. */
|
|
3890
3934
|
__publicField(this, "statics");
|
|
3935
|
+
/** The debris still passing through a fixed thing it was made inside (`throughStatics`). */
|
|
3936
|
+
__publicField(this, "passing", /* @__PURE__ */ new Set());
|
|
3937
|
+
/** A set of one fixed body, to ask how deep a piece is in that one. */
|
|
3938
|
+
__publicField(this, "oneStatic", /* @__PURE__ */ new Set());
|
|
3939
|
+
/** The bodies a piece of debris overlaps where it is made (`throughStatics`), kept between asks. */
|
|
3940
|
+
__publicField(this, "overlapped", []);
|
|
3891
3941
|
__publicField(this, "ignored", /* @__PURE__ */ new Set());
|
|
3892
3942
|
__publicField(this, "knocks", /* @__PURE__ */ new Map());
|
|
3893
3943
|
__publicField(this, "footprintOut", { corners: new Float64Array(16), normals: new Float64Array(6), minX: 0, maxX: 0, minZ: 0, maxZ: 0 });
|
|
@@ -3992,6 +4042,7 @@ var EnginePieces = class {
|
|
|
3992
4042
|
this.byUser.delete(link.user);
|
|
3993
4043
|
this.byBody.delete(link.id);
|
|
3994
4044
|
this.bodyIds.delete(link.id);
|
|
4045
|
+
this.passing.delete(b);
|
|
3995
4046
|
this.active.delete(b);
|
|
3996
4047
|
if (this.byObject.get(b.objectId) === b) this.byObject.delete(b.objectId);
|
|
3997
4048
|
this.links.delete(b);
|
|
@@ -4132,6 +4183,7 @@ var EnginePieces = class {
|
|
|
4132
4183
|
this.makeBodies(each);
|
|
4133
4184
|
each((b) => this.hang(b));
|
|
4134
4185
|
each((b) => this.sync(b, dt, h));
|
|
4186
|
+
this.meetStaticsAgain();
|
|
4135
4187
|
if (this.schedule) this.layGroundLater(each, dt);
|
|
4136
4188
|
else this.layGround(each, dt);
|
|
4137
4189
|
this.keepApart(apart2);
|
|
@@ -4405,7 +4457,8 @@ var EnginePieces = class {
|
|
|
4405
4457
|
this.byBody.set(id, b);
|
|
4406
4458
|
this.bodyIds.add(id);
|
|
4407
4459
|
this.byObject.set(b.objectId, b);
|
|
4408
|
-
this.
|
|
4460
|
+
if (b.debris) this.throughStatics(b, link);
|
|
4461
|
+
else this.outOfStatics(b, link);
|
|
4409
4462
|
});
|
|
4410
4463
|
}
|
|
4411
4464
|
bodyDesc(b, user) {
|
|
@@ -4422,7 +4475,7 @@ var EnginePieces = class {
|
|
|
4422
4475
|
centreAtOrigin: true,
|
|
4423
4476
|
keepPartContacts: shape.kind === "compound" && shape.children.length > 1,
|
|
4424
4477
|
material: this.material(b),
|
|
4425
|
-
layer: "debris",
|
|
4478
|
+
layer: b.debris ? "rubble" : "debris",
|
|
4426
4479
|
// no air drag: the kit's pieces never had any (a round piece's rolling resistance is the adapter's, `rolling`)
|
|
4427
4480
|
angularDamping: 0,
|
|
4428
4481
|
linearDamping: 0,
|
|
@@ -4486,6 +4539,52 @@ var EnginePieces = class {
|
|
|
4486
4539
|
* lifted (`underGround`). Left to the engine it is pushed out a little each step (`maxPushOut`), which reads as the piece rising by itself: a roof sheet made 1 m
|
|
4487
4540
|
* into a shelf rose 0.83-0.94 m over the room's 11 s. Only past a contact's sink (`SINK`): resting on a shelf it is not moved.
|
|
4488
4541
|
*/
|
|
4542
|
+
/**
|
|
4543
|
+
* A piece of debris made inside something (the bars of a cage that gave way, inside the wall that still stands; a chunk overlapping the part next to the one that broke,
|
|
4544
|
+
* or the chunk cut beside it) is not moved out of it as a piece is (`outOfStatics`), and the engine does not push the two apart: debris is born
|
|
4545
|
+
* where the thing broke. It passes through what it was made inside until it is out of it, and only through that.
|
|
4546
|
+
*/
|
|
4547
|
+
throughStatics(b, link) {
|
|
4548
|
+
const q = b.root.quaternion;
|
|
4549
|
+
const c = this.centre(b);
|
|
4550
|
+
const found = this.overlapped;
|
|
4551
|
+
this.world.overlapShape(this.shapeOf(b), [c.x, c.y, c.z], [q.x, q.y, q.z, q.w], found, BORN_INSIDE);
|
|
4552
|
+
for (const id of found) {
|
|
4553
|
+
if (id === link.id || link.through?.includes(id) || !(this.statics.ids.has(id) || this.bodyIds.has(id))) continue;
|
|
4554
|
+
this.world.ignorePair(link.id, id, true);
|
|
4555
|
+
(link.through ?? (link.through = [])).push(id);
|
|
4556
|
+
}
|
|
4557
|
+
if (link.through?.length) this.passing.add(b);
|
|
4558
|
+
}
|
|
4559
|
+
/** The debris passing through what it was made inside meets it again once it is out of it; what was made again meanwhile (a fixed thing's body is a new one) is looked at afresh. */
|
|
4560
|
+
meetStaticsAgain() {
|
|
4561
|
+
if (this.passing.size === 0 || !this.world.penetration) return;
|
|
4562
|
+
const one = this.oneStatic;
|
|
4563
|
+
for (const b of this.passing) {
|
|
4564
|
+
const link = this.links.get(b);
|
|
4565
|
+
const through = link?.through;
|
|
4566
|
+
if (!link || !through) {
|
|
4567
|
+
this.passing.delete(b);
|
|
4568
|
+
continue;
|
|
4569
|
+
}
|
|
4570
|
+
let remade = false;
|
|
4571
|
+
for (let i = through.length - 1; i >= 0; i--) {
|
|
4572
|
+
const id = through[i];
|
|
4573
|
+
if (!this.statics.ids.has(id) && !this.bodyIds.has(id)) {
|
|
4574
|
+
remade = true;
|
|
4575
|
+
through.splice(i, 1);
|
|
4576
|
+
continue;
|
|
4577
|
+
}
|
|
4578
|
+
one.clear();
|
|
4579
|
+
one.add(id);
|
|
4580
|
+
if (this.world.penetration(link.id, this.outAxis, one) > SINK) continue;
|
|
4581
|
+
this.world.ignorePair(link.id, id, false);
|
|
4582
|
+
through.splice(i, 1);
|
|
4583
|
+
}
|
|
4584
|
+
if (remade) this.throughStatics(b, link);
|
|
4585
|
+
if (through.length === 0) this.passing.delete(b);
|
|
4586
|
+
}
|
|
4587
|
+
}
|
|
4489
4588
|
outOfStatics(b, link) {
|
|
4490
4589
|
if (!this.world.penetration) return;
|
|
4491
4590
|
const axis = this.outAxis;
|
|
@@ -5500,7 +5599,7 @@ var PieceSystem = class {
|
|
|
5500
5599
|
}
|
|
5501
5600
|
/** Contact blows on the fixed parts become `blunt` hits of `destruction` (`engine-impacts.ts`). Returns the way to stop it. */
|
|
5502
5601
|
contactHits(destruction, options) {
|
|
5503
|
-
return createEngineImpacts(this.loop, this.engine.statics, destruction, options);
|
|
5602
|
+
return createEngineImpacts(this.loop, this.engine.statics, destruction, options, (body) => this.engine.pieceOfBody(body)?.debris === true);
|
|
5504
5603
|
}
|
|
5505
5604
|
/**
|
|
5506
5605
|
* The pieces a blast at `point` can reach: the bodies the engine's `blastQuery` finds within `radius` (the pieces among them), in the order of `list`, and the pieces that have no
|
|
@@ -6169,13 +6268,13 @@ var PieceSystem = class {
|
|
|
6169
6268
|
if (most === void 0 || !Number.isFinite(most)) return;
|
|
6170
6269
|
let awake = 0;
|
|
6171
6270
|
for (const b of this.list) {
|
|
6172
|
-
if (b.sleeping || b.held) continue;
|
|
6271
|
+
if (b.sleeping || b.held || b.debris) continue;
|
|
6173
6272
|
if (this.hasComeToRest(b) && (b.balancing || b.still >= SLEEP_AFTER && !b.hinge && !this.onSteepSupport(b))) this.sleepByBudget(b);
|
|
6174
6273
|
else awake++;
|
|
6175
6274
|
}
|
|
6176
6275
|
for (const b of this.list) {
|
|
6177
6276
|
if (awake <= most) return;
|
|
6178
|
-
if (b.sleeping || b.held || !this.hasComeToRest(b)) continue;
|
|
6277
|
+
if (b.sleeping || b.held || b.debris || !this.hasComeToRest(b)) continue;
|
|
6179
6278
|
this.sleepByBudget(b);
|
|
6180
6279
|
awake--;
|
|
6181
6280
|
}
|
|
@@ -6194,12 +6293,13 @@ var PieceSystem = class {
|
|
|
6194
6293
|
const c = this.centerOf(b, this.p);
|
|
6195
6294
|
return Math.hypot(c.x - focus[0], c.y - focus[1], c.z - focus[2]) > keep.far.distance;
|
|
6196
6295
|
};
|
|
6197
|
-
const
|
|
6296
|
+
const pieces = this.list.filter((b) => !b.debris);
|
|
6297
|
+
const atRest = pieces.filter((b) => !b.held && this.hasComeToRest(b));
|
|
6198
6298
|
if (keep.far.action === "sleep") {
|
|
6199
6299
|
for (const b of atRest) if (!b.sleeping && isFarAndOld(b)) this.sleepByBudget(b);
|
|
6200
6300
|
}
|
|
6201
6301
|
const fades = keep.far.action === "fade";
|
|
6202
|
-
let over2 =
|
|
6302
|
+
let over2 = pieces.length - keep.maxLive;
|
|
6203
6303
|
const far2 = new Set(atRest.filter(isFarAndOld));
|
|
6204
6304
|
for (const b of [...atRest].sort((a, c) => Number(far2.has(c)) - Number(far2.has(a)))) {
|
|
6205
6305
|
if (!(over2 > 0 || fades && far2.has(b))) return;
|
|
@@ -8736,6 +8836,7 @@ var UNDERMINED_STAND = 0.4;
|
|
|
8736
8836
|
var UNDERMINED_KEEP = 0.6;
|
|
8737
8837
|
var SOLIDS_MAX = 64;
|
|
8738
8838
|
var UNDERMINED_PUSH = 0.6;
|
|
8839
|
+
var DEBRIS_ID = "debris#";
|
|
8739
8840
|
var UNDERMINED_STILL = 0.05;
|
|
8740
8841
|
var SOLID_WELD = 1e-4;
|
|
8741
8842
|
var UNCHECKED_KINDS = /* @__PURE__ */ new Set(["structure", "room", "ground"]);
|
|
@@ -8969,6 +9070,8 @@ var Renderer = class {
|
|
|
8969
9070
|
/** The parts the ground went down under, drawn going down (`subside`). */
|
|
8970
9071
|
__publicField(this, "settlement");
|
|
8971
9072
|
__publicField(this, "fragments");
|
|
9073
|
+
/** Count of the bodies made for big debris: each gets an id of its own. */
|
|
9074
|
+
__publicField(this, "debrisMade", 0);
|
|
8972
9075
|
__publicField(this, "ground");
|
|
8973
9076
|
__publicField(this, "pieceSys");
|
|
8974
9077
|
__publicField(this, "cages");
|
|
@@ -9055,7 +9158,34 @@ var Renderer = class {
|
|
|
9055
9158
|
// and it meets the walls, ceilings and furniture on its way: it stops on their face instead of flying into them
|
|
9056
9159
|
sweep: (from, direction, distance) => typeof this.world.raycast === "function" ? this.world.raycast([from[0], from[1], from[2]], [direction[0], direction[1], direction[2]], distance) : null,
|
|
9057
9160
|
maxAwake: o.maxAwakeFragments ?? Infinity,
|
|
9058
|
-
...o.interpolate ? { interpolate: true } : {}
|
|
9161
|
+
...o.interpolate ? { interpolate: true } : {},
|
|
9162
|
+
rigid: {
|
|
9163
|
+
add: (mesh, half, mass, velocity, angular) => {
|
|
9164
|
+
const body = this.pieceSys.create(`${DEBRIS_ID}${++this.debrisMade}`, mesh, [half[0], half[1], half[2]], new THREE.Vector3(), mass, [velocity[0], velocity[1], velocity[2]], [angular[0], angular[1], angular[2]]);
|
|
9165
|
+
body.debris = true;
|
|
9166
|
+
return body;
|
|
9167
|
+
},
|
|
9168
|
+
remove: (handle) => this.pieceSys.remove(handle.objectId),
|
|
9169
|
+
push: (handle, x, z) => {
|
|
9170
|
+
const body = handle;
|
|
9171
|
+
body.velocity[0] = x;
|
|
9172
|
+
body.velocity[2] = z;
|
|
9173
|
+
body.velocity[1] = Math.max(body.velocity[1], 0.3);
|
|
9174
|
+
body.sleeping = false;
|
|
9175
|
+
body.still = 0;
|
|
9176
|
+
body.calmAt = null;
|
|
9177
|
+
},
|
|
9178
|
+
shove: (handle, velocity, spin) => {
|
|
9179
|
+
const body = handle;
|
|
9180
|
+
for (let i = 0; i < 3; i++) {
|
|
9181
|
+
body.velocity[i] = body.velocity[i] + velocity[i];
|
|
9182
|
+
body.angularVelocity[i] = body.angularVelocity[i] + spin[i];
|
|
9183
|
+
}
|
|
9184
|
+
body.sleeping = false;
|
|
9185
|
+
body.still = 0;
|
|
9186
|
+
body.calmAt = null;
|
|
9187
|
+
}
|
|
9188
|
+
}
|
|
9059
9189
|
});
|
|
9060
9190
|
this.cages = new RebarCages(THREE, o.scene);
|
|
9061
9191
|
this.settledBatches = new SettledBatches(THREE, o.scene, o.settledBatches ?? { enabled: false });
|
|
@@ -9527,10 +9657,11 @@ var Renderer = class {
|
|
|
9527
9657
|
return shape === 0 ? 1 : drawn / shape;
|
|
9528
9658
|
}
|
|
9529
9659
|
pieces() {
|
|
9530
|
-
return
|
|
9660
|
+
return this.pieceSys.list.filter((piece) => !piece.debris);
|
|
9531
9661
|
}
|
|
9532
9662
|
piece(objectId) {
|
|
9533
|
-
|
|
9663
|
+
const piece = this.pieceSys.get(objectId);
|
|
9664
|
+
return piece && !piece.debris ? piece : null;
|
|
9534
9665
|
}
|
|
9535
9666
|
impulse(objectId, impulse, point) {
|
|
9536
9667
|
const p = this.pieceSys.get(objectId);
|
|
@@ -9558,6 +9689,7 @@ var Renderer = class {
|
|
|
9558
9689
|
}
|
|
9559
9690
|
/** A piece thrown into a wall: the wall takes the blow of its weight where it met it, the piece takes it too, and each sounds as its material does. */
|
|
9560
9691
|
slam(p, hit, speed) {
|
|
9692
|
+
if (p.debris) return;
|
|
9561
9693
|
const energy = 0.5 * p.mass * speed * speed;
|
|
9562
9694
|
const direction = [-hit.normal[0], -hit.normal[1], -hit.normal[2]];
|
|
9563
9695
|
this.landingSound(hit.object, hit.point, clamp(speed / 10, 0.2, 1));
|
|
@@ -9569,6 +9701,7 @@ var Renderer = class {
|
|
|
9569
9701
|
}
|
|
9570
9702
|
}
|
|
9571
9703
|
hardLanding(p, point, speed) {
|
|
9704
|
+
if (p.debris) return;
|
|
9572
9705
|
this.landingSound(p.objectId, point, clamp(speed / 10, 0.2, 1));
|
|
9573
9706
|
this.syncBound(p.objectId);
|
|
9574
9707
|
try {
|
|
@@ -10177,7 +10310,7 @@ var Renderer = class {
|
|
|
10177
10310
|
for (const [id, a] of this.staticNow()) scan(a, id, null, 6);
|
|
10178
10311
|
const c = this.v1;
|
|
10179
10312
|
for (const pc of this.pieceSys.list) {
|
|
10180
|
-
if (pc.held) continue;
|
|
10313
|
+
if (pc.held || pc.debris) continue;
|
|
10181
10314
|
this.pieceSys.centerOf(pc, c);
|
|
10182
10315
|
const reach = Math.hypot(pc.halfExtents[0], pc.halfExtents[1], pc.halfExtents[2]) + radius;
|
|
10183
10316
|
if (Math.abs(c.x - x) > reach || Math.abs(c.z - z) > reach) continue;
|
|
@@ -11746,7 +11879,7 @@ var Renderer = class {
|
|
|
11746
11879
|
reach(distance, { objectId: pc.objectId, generation: pc.generation, impulse, point }, [c.x, c.y, c.z]);
|
|
11747
11880
|
};
|
|
11748
11881
|
const reached = this.o.blastQuery ? this.pieceSys.piecesInBlast(this.o.blastQuery, p, ev.radius) : [...this.pieceSys.list];
|
|
11749
|
-
for (const pc of reached) shove(pc);
|
|
11882
|
+
for (const pc of reached) if (!pc.debris) shove(pc);
|
|
11750
11883
|
if (this.o.shoveable) this.loosen(p, ev.radius, energy, reachOf2, policy, reach);
|
|
11751
11884
|
this.advanceWakes(0);
|
|
11752
11885
|
this.fragments.blast(p, ev.radius, Math.min(20, Math.sqrt(energy) * 0.08));
|
|
@@ -11814,6 +11947,7 @@ var Renderer = class {
|
|
|
11814
11947
|
if (centre.distanceTo(point) <= ev.radius) cover.set(objectId, reach.call(this.world, ev.point, [centre.x, centre.y, centre.z], { ignore: [ev.object, objectId] }));
|
|
11815
11948
|
};
|
|
11816
11949
|
for (const pc of this.pieceSys.list) {
|
|
11950
|
+
if (pc.debris) continue;
|
|
11817
11951
|
this.pieceSys.centerOf(pc, centre);
|
|
11818
11952
|
read(pc.objectId);
|
|
11819
11953
|
}
|