@adatechnology/game-destruction-three 1.3.1 → 1.3.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 +294 -10
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +294 -10
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.global.js
CHANGED
|
@@ -11608,7 +11608,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11608
11608
|
z: p.z,
|
|
11609
11609
|
reachX: Math.abs(e[0]) * x + Math.abs(e[4]) * y + Math.abs(e[8]) * z,
|
|
11610
11610
|
reachZ: Math.abs(e[2]) * x + Math.abs(e[6]) * y + Math.abs(e[10]) * z,
|
|
11611
|
-
top: p.y + Math.abs(e[1]) * x + Math.abs(e[5]) * y + Math.abs(e[9]) * z
|
|
11611
|
+
top: p.y + Math.abs(e[1]) * x + Math.abs(e[5]) * y + Math.abs(e[9]) * z,
|
|
11612
|
+
bottom: p.y - Math.abs(e[1]) * x - Math.abs(e[5]) * y - Math.abs(e[9]) * z
|
|
11612
11613
|
};
|
|
11613
11614
|
}
|
|
11614
11615
|
var BUILDERS = {
|
|
@@ -11631,10 +11632,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11631
11632
|
var PILE_STEP = 0.01;
|
|
11632
11633
|
var TIP_SPEED = 0.6;
|
|
11633
11634
|
var TIP_TURN = 3;
|
|
11635
|
+
var RIDGE_TURN = Math.PI * (3 - Math.sqrt(5));
|
|
11636
|
+
var SIDE_BY_SIDE = 1e-4;
|
|
11634
11637
|
var POINT = [0, 0, 0, 0, 0, 0];
|
|
11635
11638
|
var SHARD_SHAPES = 6;
|
|
11636
11639
|
var SWEEP_MIN_SPEED = 1;
|
|
11637
11640
|
var WALL_RESTITUTION = 0.25;
|
|
11641
|
+
var ACROSS_MIN_STEP = 1e-4;
|
|
11638
11642
|
var WALL_GLIDE = 0.7;
|
|
11639
11643
|
var TUMBLE_REACH = 0.1;
|
|
11640
11644
|
var GROUND_RESTITUTION = 0.25;
|
|
@@ -11681,6 +11685,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11681
11685
|
__publicField(this, "rng", createRng(FRAGMENT_SEED));
|
|
11682
11686
|
/** The corners of the fragment being stepped (`writeCorners`), what of them it rests on, its halves at its fade, and its centre over that support: kept between calls. */
|
|
11683
11687
|
__publicField(this, "corners", new Float64Array(24));
|
|
11688
|
+
/** The corners of `corners` from the lowest (`ridgeUnder`). */
|
|
11689
|
+
__publicField(this, "lowCorners", [0, 0, 0, 0, 0, 0, 0, 0]);
|
|
11684
11690
|
__publicField(this, "support", createSupport());
|
|
11685
11691
|
__publicField(this, "halves", { x: 0, y: 0, z: 0 });
|
|
11686
11692
|
__publicField(this, "lever", { x: 0, y: 0, z: 0 });
|
|
@@ -11695,8 +11701,20 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11695
11701
|
__publicField(this, "supportTurn", 0);
|
|
11696
11702
|
/** The pose before the last update and after it, of the fragments that were awake (`interpolate`); null when the option is off. */
|
|
11697
11703
|
__publicField(this, "trail");
|
|
11704
|
+
/** Fragments crushed so far under a moving piece that came down on them with no room left (`meetMover`): they fade where they were. */
|
|
11705
|
+
__publicField(this, "crushed", 0);
|
|
11706
|
+
/** The pieces moving this update (`FragmentSystemOptions.movers`). */
|
|
11707
|
+
__publicField(this, "moving", []);
|
|
11708
|
+
/** Where a fragment was when its step began, and that point carried by a moving piece. */
|
|
11709
|
+
__publicField(this, "before");
|
|
11710
|
+
__publicField(this, "carried");
|
|
11711
|
+
/** The move of a piece since the last update, and its inverse. */
|
|
11712
|
+
__publicField(this, "shift");
|
|
11713
|
+
__publicField(this, "unshift");
|
|
11698
11714
|
__publicField(this, "markGeometry", null);
|
|
11699
11715
|
__publicField(this, "markMaterial", null);
|
|
11716
|
+
/** The floor under the fragment `pileUnder` is asked about (`floorUnder`, or the ground when that is all that was measured): what two pieces at one height must both stand on. */
|
|
11717
|
+
__publicField(this, "pileFloor", 0);
|
|
11700
11718
|
/** Set by `pileUnder`: the way off the edge when the fragment's centre is past what it lies on, else null. */
|
|
11701
11719
|
__publicField(this, "offEdge", null);
|
|
11702
11720
|
this.box = new THREE.BoxGeometry(1, 1, 1);
|
|
@@ -11705,6 +11723,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11705
11723
|
this.m = new THREE.Matrix4();
|
|
11706
11724
|
this.v = new THREE.Vector3();
|
|
11707
11725
|
this.w = new THREE.Vector3();
|
|
11726
|
+
this.before = new THREE.Vector3();
|
|
11727
|
+
this.carried = new THREE.Vector3();
|
|
11728
|
+
this.shift = new THREE.Matrix4();
|
|
11729
|
+
this.unshift = new THREE.Matrix4();
|
|
11708
11730
|
this.instances = new FragmentInstances(THREE, o.scene);
|
|
11709
11731
|
this.trail = o.interpolate ? new PoseTrail() : null;
|
|
11710
11732
|
}
|
|
@@ -11873,6 +11895,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11873
11895
|
const live = {
|
|
11874
11896
|
mesh: mesh2,
|
|
11875
11897
|
floor: null,
|
|
11898
|
+
ridgeTries: 0,
|
|
11899
|
+
ridgeWay: null,
|
|
11876
11900
|
home,
|
|
11877
11901
|
vel: new this.THREE.Vector3(f.velocity[0], f.velocity[1], f.velocity[2]),
|
|
11878
11902
|
ang: new this.THREE.Vector3(f.angularVelocity[0], f.angularVelocity[1], f.angularVelocity[2]),
|
|
@@ -12034,7 +12058,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12034
12058
|
update(dt) {
|
|
12035
12059
|
this.tick++;
|
|
12036
12060
|
this.clock += dt;
|
|
12061
|
+
this.moving = this.o.movers?.() ?? [];
|
|
12037
12062
|
this.wakeUnsupported();
|
|
12063
|
+
this.wakeMoved();
|
|
12038
12064
|
this.wakeRigid();
|
|
12039
12065
|
this.beginTick();
|
|
12040
12066
|
const g = this.o.gravity;
|
|
@@ -12068,6 +12094,23 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12068
12094
|
if (f.rigid) this.o.rigid?.remove(f.rigid);
|
|
12069
12095
|
f.rigid = null;
|
|
12070
12096
|
}
|
|
12097
|
+
/** A fragment asleep in the box of a piece that moves wakes in the same update: what it lay on, or what lies on it, is going. */
|
|
12098
|
+
wakeMoved() {
|
|
12099
|
+
if (this.moving.length === 0) return;
|
|
12100
|
+
for (const f of this.list) if (f.asleep && !f.dying && !f.rigid && this.nearAnyMover(f)) this.rouse(f);
|
|
12101
|
+
}
|
|
12102
|
+
/** Whether the fragment is in the box of the moving piece (or within its reach of it). */
|
|
12103
|
+
nearMover(f, mover) {
|
|
12104
|
+
const p = f.mesh.position;
|
|
12105
|
+
const reach2 = Math.max(f.half.x, f.half.y, f.half.z);
|
|
12106
|
+
const b = mover.box;
|
|
12107
|
+
return p.x >= b[0] - reach2 && p.x <= b[3] + reach2 && p.y >= b[1] - reach2 && p.y <= b[4] + reach2 && p.z >= b[2] - reach2 && p.z <= b[5] + reach2;
|
|
12108
|
+
}
|
|
12109
|
+
/** Whether the fragment is in the box of any piece moving this update. */
|
|
12110
|
+
nearAnyMover(f) {
|
|
12111
|
+
for (const mover of this.moving) if (this.nearMover(f, mover)) return true;
|
|
12112
|
+
return false;
|
|
12113
|
+
}
|
|
12071
12114
|
/** 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. */
|
|
12072
12115
|
wakeRigid() {
|
|
12073
12116
|
for (const f of this.list) if (f.rigid && f.asleep && !f.dying && !f.rigid.sleeping) this.rouse(f);
|
|
@@ -12149,29 +12192,77 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12149
12192
|
const ext = Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z;
|
|
12150
12193
|
f.floor = null;
|
|
12151
12194
|
const bottom = f.mesh.position.y - ext;
|
|
12152
|
-
const pile = this.pileUnder(f, bottom);
|
|
12153
|
-
const offEdge = this.offEdge;
|
|
12154
12195
|
const ground = this.o.groundAt(f.mesh.position.x, f.mesh.position.z);
|
|
12196
|
+
this.pileFloor = ground;
|
|
12197
|
+
let pile = this.pileUnder(f, bottom);
|
|
12155
12198
|
if (bottom <= ground + SUPPORT_GAP && pile <= ground) continue;
|
|
12156
12199
|
const floor2 = this.floorUnder(f);
|
|
12200
|
+
if (floor2 > ground) {
|
|
12201
|
+
this.pileFloor = floor2;
|
|
12202
|
+
pile = this.pileUnder(f, bottom);
|
|
12203
|
+
}
|
|
12204
|
+
const offEdge = this.offEdge;
|
|
12157
12205
|
if (bottom > Math.max(floor2, pile) + SUPPORT_GAP || pile > floor2 && offEdge) this.rouse(f);
|
|
12158
12206
|
}
|
|
12159
12207
|
}
|
|
12160
|
-
/** What a fragment lands on: measured where it is, and again only once it moved `FLOOR_REMEASURE` m off that spot (a ray down is not free). */
|
|
12208
|
+
/** What a fragment lands on: measured where it is, and again only once it moved half its size (at most `FLOOR_REMEASURE` m) off that spot (a ray down is not free). */
|
|
12161
12209
|
floorUnder(f) {
|
|
12162
12210
|
const p = f.mesh.position;
|
|
12163
12211
|
if (!this.o.surfaceAt) return this.o.groundAt(p.x, p.z);
|
|
12164
12212
|
const at3 = f.floor;
|
|
12165
|
-
|
|
12213
|
+
const away = Math.min(FLOOR_REMEASURE, Math.max(f.half.x, f.half.y, f.half.z));
|
|
12214
|
+
if (!at3 || Math.abs(at3.x - p.x) > away || Math.abs(at3.z - p.z) > away || p.y < at3.y - FLOOR_REMEASURE) {
|
|
12166
12215
|
f.floor = { x: p.x, z: p.z, y: this.o.surfaceAt(p.x, p.y, p.z) };
|
|
12167
12216
|
}
|
|
12168
12217
|
return f.floor.y;
|
|
12169
12218
|
}
|
|
12219
|
+
/**
|
|
12220
|
+
* Whether the fragment, come down on `floor` (what is built under its centre), lies only on its centre: none of its four lowest corners is over anything that high, so it
|
|
12221
|
+
* balances on an edge narrower than itself. Then the way it slides off (towards its lowest corner, or one more `RIDGE_TURN` round each time it lands so again, kept while it
|
|
12222
|
+
* slides), else null.
|
|
12223
|
+
* Asked once per measure of the floor (`floorUnder`), at the first contact.
|
|
12224
|
+
*/
|
|
12225
|
+
ridgeUnder(f, e, floor2) {
|
|
12226
|
+
const at3 = f.floor;
|
|
12227
|
+
const surfaceAt = this.o.surfaceAt;
|
|
12228
|
+
if (!at3 || !surfaceAt) return null;
|
|
12229
|
+
if (at3.ridge !== void 0) return at3.ridge;
|
|
12230
|
+
at3.ridge = null;
|
|
12231
|
+
const p = f.mesh.position;
|
|
12232
|
+
if (floor2 <= this.o.groundAt(p.x, p.z) + SUPPORT_GAP) return f.ridgeWay = null;
|
|
12233
|
+
const c = this.corners;
|
|
12234
|
+
writeCorners({ e, half: f.half, corners: c });
|
|
12235
|
+
const low = this.lowCorners;
|
|
12236
|
+
for (let i = 0; i < 8; i++) {
|
|
12237
|
+
let k = i;
|
|
12238
|
+
while (k > 0 && c[3 * low[k - 1] + 1] > c[3 * i + 1]) {
|
|
12239
|
+
low[k] = low[k - 1];
|
|
12240
|
+
k--;
|
|
12241
|
+
}
|
|
12242
|
+
low[k] = i;
|
|
12243
|
+
}
|
|
12244
|
+
for (let k = 0; k < 4; k++) {
|
|
12245
|
+
const i = low[k];
|
|
12246
|
+
if (surfaceAt(p.x + c[3 * i], p.y, p.z + c[3 * i + 2]) >= floor2 - SUPPORT_GAP) return f.ridgeWay = null;
|
|
12247
|
+
}
|
|
12248
|
+
if (f.ridgeWay) return at3.ridge = f.ridgeWay;
|
|
12249
|
+
const lowest = low[0];
|
|
12250
|
+
const lx = c[3 * lowest], lz = c[3 * lowest + 2];
|
|
12251
|
+
const tilt = c[3 * low[3] + 1] - c[3 * lowest + 1];
|
|
12252
|
+
const d = Math.hypot(lx, lz);
|
|
12253
|
+
f.ridgeTries++;
|
|
12254
|
+
const angle = f.seq * RIDGE_TURN + f.ridgeTries * RIDGE_TURN;
|
|
12255
|
+
f.ridgeWay = tilt > SUPPORT_GAP && d > 1e-6 && f.ridgeTries === 1 ? { x: lx / d, z: lz / d } : { x: Math.cos(angle), z: Math.sin(angle) };
|
|
12256
|
+
return at3.ridge = f.ridgeWay;
|
|
12257
|
+
}
|
|
12170
12258
|
step(f, dt, g) {
|
|
12171
12259
|
const mesh2 = f.mesh;
|
|
12172
12260
|
f.box = void 0;
|
|
12173
12261
|
f.vel.y -= g * dt;
|
|
12262
|
+
this.before.copy(mesh2.position);
|
|
12174
12263
|
if (!this.hitWall(f, dt)) mesh2.position.addScaledVector(f.vel, dt);
|
|
12264
|
+
const stirred = this.nearAnyMover(f);
|
|
12265
|
+
if (stirred) f.floor = null;
|
|
12175
12266
|
const w = f.ang.length();
|
|
12176
12267
|
if (w > 1e-5) {
|
|
12177
12268
|
this.dq.setFromAxisAngle(this.v.copy(f.ang).multiplyScalar(1 / w), w * dt);
|
|
@@ -12183,6 +12274,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12183
12274
|
const sc = f.dying ? f.fade : 1;
|
|
12184
12275
|
const ext = (Math.abs(e[1]) * h.x + Math.abs(e[5]) * h.y + Math.abs(e[9]) * h.z) * sc;
|
|
12185
12276
|
const floor2 = this.floorUnder(f);
|
|
12277
|
+
this.pileFloor = floor2;
|
|
12186
12278
|
const pile = this.pileUnder(f, mesh2.position.y - ext + Math.max(0, -f.vel.y) * dt);
|
|
12187
12279
|
const gy = Math.max(floor2, pile);
|
|
12188
12280
|
const tip = pile > floor2 ? this.offEdge : null;
|
|
@@ -12191,8 +12283,15 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12191
12283
|
if (mesh2.position.y - ext < gy) {
|
|
12192
12284
|
contact = true;
|
|
12193
12285
|
mesh2.position.y = gy + ext;
|
|
12286
|
+
const ridge = pile > floor2 ? null : this.ridgeUnder(f, e, floor2);
|
|
12194
12287
|
if (pile > floor2) {
|
|
12195
12288
|
turning = this.restOnDebris(f, { g, dt, gy, sc, tip });
|
|
12289
|
+
} else if (ridge) {
|
|
12290
|
+
f.vel.y = 0;
|
|
12291
|
+
f.vel.x += ridge.x * TIP_SPEED * dt * 10;
|
|
12292
|
+
f.vel.z += ridge.z * TIP_SPEED * dt * 10;
|
|
12293
|
+
f.floor = null;
|
|
12294
|
+
turning = true;
|
|
12196
12295
|
} else {
|
|
12197
12296
|
writeCorners({ e, half: this.scaledHalf(f, sc), corners: this.corners });
|
|
12198
12297
|
findSupport({ corners: this.corners, reach: Math.max(h.x, h.y, h.z) * sc, support: this.support });
|
|
@@ -12207,6 +12306,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12207
12306
|
f.ang.multiplyScalar(Math.exp(-0.15 * dt));
|
|
12208
12307
|
if (f.air > 0) this.flutter(f, dt);
|
|
12209
12308
|
}
|
|
12309
|
+
if (stirred) {
|
|
12310
|
+
for (const mover of this.moving) if (this.nearMover(f, mover)) this.meetMover(f, mover, dt);
|
|
12311
|
+
}
|
|
12210
12312
|
f.contact = contact;
|
|
12211
12313
|
if (contact && !turning && isSlow(f)) {
|
|
12212
12314
|
f.still += dt;
|
|
@@ -12222,11 +12324,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12222
12324
|
hitWall(f, dt) {
|
|
12223
12325
|
const sweep = this.o.sweep;
|
|
12224
12326
|
if (!sweep) return false;
|
|
12225
|
-
const
|
|
12226
|
-
|
|
12227
|
-
|
|
12327
|
+
const across = f.vel.length() < SWEEP_MIN_SPEED || f.contact && f.vel.y <= 0 && Math.hypot(f.vel.x, f.vel.z) < SWEEP_MIN_SPEED;
|
|
12328
|
+
const vy2 = across ? 0 : f.vel.y;
|
|
12329
|
+
const speed = Math.hypot(f.vel.x, vy2, f.vel.z);
|
|
12330
|
+
if (speed * dt < ACROSS_MIN_STEP) return false;
|
|
12228
12331
|
const p = f.mesh.position;
|
|
12229
|
-
const dir = [f.vel.x / speed,
|
|
12332
|
+
const dir = [f.vel.x / speed, vy2 / speed, f.vel.z / speed];
|
|
12230
12333
|
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
12231
12334
|
const reach2 = (x, y, z) => (Math.abs(e[0] * x + e[1] * y + e[2] * z) * f.half.x + Math.abs(e[4] * x + e[5] * y + e[6] * z) * f.half.y + Math.abs(e[8] * x + e[9] * y + e[10] * z) * f.half.z) * (f.dying ? f.fade : 1);
|
|
12232
12335
|
const ahead = reach2(dir[0], dir[1], dir[2]);
|
|
@@ -12243,6 +12346,68 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12243
12346
|
f.floor = null;
|
|
12244
12347
|
return true;
|
|
12245
12348
|
}
|
|
12349
|
+
/**
|
|
12350
|
+
* The fragment's way this step as the moving piece sees it: from where the piece carried the fragment's start to where the fragment got. A face of the piece on that way
|
|
12351
|
+
* stops it on the face, moving as the piece moves there, with what it had across the face kept as off a wall: a panel coming down on a sheet takes it along.
|
|
12352
|
+
*/
|
|
12353
|
+
meetMover(f, mover, dt) {
|
|
12354
|
+
const p = f.mesh.position;
|
|
12355
|
+
const shift = this.shift.fromArray(mover.delta);
|
|
12356
|
+
const from = this.carried.copy(this.before).applyMatrix4(shift);
|
|
12357
|
+
const rx = p.x - from.x, ry = p.y - from.y, rz = p.z - from.z;
|
|
12358
|
+
const span = Math.hypot(rx, ry, rz);
|
|
12359
|
+
if (span < 1e-6) return;
|
|
12360
|
+
const dir = [rx / span, ry / span, rz / span];
|
|
12361
|
+
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
12362
|
+
const reach2 = (x, y, z) => (Math.abs(e[0] * x + e[1] * y + e[2] * z) * f.half.x + Math.abs(e[4] * x + e[5] * y + e[6] * z) * f.half.y + Math.abs(e[8] * x + e[9] * y + e[10] * z) * f.half.z) * (f.dying ? f.fade : 1);
|
|
12363
|
+
const hit = mover.sweep([from.x, from.y, from.z], dir, span + reach2(dir[0], dir[1], dir[2]));
|
|
12364
|
+
if (!hit) return;
|
|
12365
|
+
const nx = hit.normal[0] ?? 0, ny = hit.normal[1] ?? 0, nz = hit.normal[2] ?? 0;
|
|
12366
|
+
if (rx * nx + ry * ny + rz * nz >= 0) return;
|
|
12367
|
+
const px = hit.point[0] ?? p.x, py = hit.point[1] ?? p.y, pz = hit.point[2] ?? p.z;
|
|
12368
|
+
const was = this.v.set(px, py, pz).applyMatrix4(this.unshift.copy(shift).invert());
|
|
12369
|
+
const cx = (px - was.x) / dt, cy = (py - was.y) / dt, cz = (pz - was.z) / dt;
|
|
12370
|
+
this.alongFace(f, nx, ny, nz);
|
|
12371
|
+
const off2 = Math.min(f.half.x, f.half.y, f.half.z) * (f.dying ? f.fade : 1) + 2e-3;
|
|
12372
|
+
const qx = px + nx * off2, qy = py + ny * off2, qz = pz + nz * off2;
|
|
12373
|
+
if (this.pinched(from, qx, qy, qz, off2)) {
|
|
12374
|
+
p.copy(from);
|
|
12375
|
+
f.vel.set(cx, cy, cz);
|
|
12376
|
+
this.crushed++;
|
|
12377
|
+
f.dying = true;
|
|
12378
|
+
this.activate(f);
|
|
12379
|
+
return;
|
|
12380
|
+
}
|
|
12381
|
+
p.set(qx, qy, qz);
|
|
12382
|
+
const ux = f.vel.x - cx, uy = f.vel.y - cy, uz = f.vel.z - cz;
|
|
12383
|
+
const inward = Math.min(0, ux * nx + uy * ny + uz * nz);
|
|
12384
|
+
const tx = ux - inward * nx, ty = uy - inward * ny, tz = uz - inward * nz;
|
|
12385
|
+
f.vel.set(cx + tx * WALL_GLIDE - inward * WALL_RESTITUTION * nx, cy + ty * WALL_GLIDE - inward * WALL_RESTITUTION * ny, cz + tz * WALL_GLIDE - inward * WALL_RESTITUTION * nz);
|
|
12386
|
+
f.ang.multiplyScalar(0.55);
|
|
12387
|
+
}
|
|
12388
|
+
/**
|
|
12389
|
+
* Whether a fragment the piece carried to `p` and pushed on to (x, y, z), `off` its reach from the face, gets there through something else or ends below what is under it there.
|
|
12390
|
+
*/
|
|
12391
|
+
pinched(p, x, y, z, off2) {
|
|
12392
|
+
const floor2 = this.o.surfaceAt ? this.o.surfaceAt(x, y, z) : this.o.groundAt(x, z);
|
|
12393
|
+
if (y - off2 < floor2) return true;
|
|
12394
|
+
const sweep = this.o.sweep;
|
|
12395
|
+
const dx = x - p.x, dy = y - p.y, dz = z - p.z;
|
|
12396
|
+
const length = Math.hypot(dx, dy, dz);
|
|
12397
|
+
if (!sweep || length < 1e-6) return false;
|
|
12398
|
+
return sweep([p.x, p.y, p.z], [dx / length, dy / length, dz / length], length) !== null;
|
|
12399
|
+
}
|
|
12400
|
+
/** Turns the fragment the least way that lays its thinnest side on the face of normal (nx, ny, nz). */
|
|
12401
|
+
alongFace(f, nx, ny, nz) {
|
|
12402
|
+
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
12403
|
+
const half = [f.half.x, f.half.y, f.half.z];
|
|
12404
|
+
let thin = 0;
|
|
12405
|
+
for (let i = 1; i < 3; i++) if (half[i] < half[thin]) thin = i;
|
|
12406
|
+
const side = e[thin * 4] * nx + e[thin * 4 + 1] * ny + e[thin * 4 + 2] * nz >= 0 ? 1 : -1;
|
|
12407
|
+
this.v.set(e[thin * 4] * side, e[thin * 4 + 1] * side, e[thin * 4 + 2] * side);
|
|
12408
|
+
this.dq.setFromUnitVectors(this.v, this.w.set(nx, ny, nz));
|
|
12409
|
+
f.mesh.quaternion.premultiply(this.dq).normalize();
|
|
12410
|
+
}
|
|
12246
12411
|
/**
|
|
12247
12412
|
* The top of the debris lying under a falling fragment: a piece lands on the pile, not through it, so two flat pieces never end up inside each other. Only pieces
|
|
12248
12413
|
* below it count (a resting one keeps its box), those whose top is at or below where the faller's bottom was a step ago plus a small step.
|
|
@@ -12253,6 +12418,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12253
12418
|
const reachX = Math.abs(e[0]) * f.half.x + Math.abs(e[4]) * f.half.y + Math.abs(e[8]) * f.half.z;
|
|
12254
12419
|
const reachZ = Math.abs(e[2]) * f.half.x + Math.abs(e[6]) * f.half.y + Math.abs(e[10]) * f.half.z;
|
|
12255
12420
|
const mine = shadowOf(e, f.half);
|
|
12421
|
+
const lowest = p.y - (Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z);
|
|
12256
12422
|
let top = Number.NEGATIVE_INFINITY;
|
|
12257
12423
|
const under = this.under;
|
|
12258
12424
|
under.length = 0;
|
|
@@ -12261,6 +12427,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12261
12427
|
const box = other.box ?? (other.box = restingBox(other));
|
|
12262
12428
|
const beneath = !other.asleep && other.mesh.position.y < bottom;
|
|
12263
12429
|
if (box.top > bottom + PILE_STEP && !beneath || box.top < top - PILE_STEP) continue;
|
|
12430
|
+
if (box.bottom >= lowest - SIDE_BY_SIDE && (other.seq > f.seq || box.bottom > this.pileFloor + SUPPORT_GAP)) continue;
|
|
12264
12431
|
if (Math.abs(box.x - p.x) >= box.reachX + reachX || Math.abs(box.z - p.z) >= box.reachZ + reachZ) continue;
|
|
12265
12432
|
if (!shadowsOverlap(mine, box.shadow, box.x - p.x, box.z - p.z)) continue;
|
|
12266
12433
|
if (box.top > top + PILE_STEP) under.length = 0;
|
|
@@ -29401,8 +29568,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29401
29568
|
var STATIC_REFRESH = 0.5;
|
|
29402
29569
|
var STATIC_REFRESH_PER_UPDATE = 8;
|
|
29403
29570
|
var SURFACE_RAYS = 4;
|
|
29404
|
-
var SURFACE_INSIDE =
|
|
29571
|
+
var SURFACE_INSIDE = 1e-3;
|
|
29405
29572
|
var SURFACE_STEP = 0.15;
|
|
29573
|
+
var MOVER_MIN_MOVE = 1e-3;
|
|
29574
|
+
var MOVER_RAYS = 4;
|
|
29406
29575
|
var STATIC_SPAN = 3;
|
|
29407
29576
|
var VERTICES_PER_UPDATE = 3e3;
|
|
29408
29577
|
var FEET_BAND = 0.03;
|
|
@@ -29813,6 +29982,15 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29813
29982
|
__publicField(this, "stopContactHits", null);
|
|
29814
29983
|
__publicField(this, "box");
|
|
29815
29984
|
__publicField(this, "tmpQ");
|
|
29985
|
+
/** The pieces that moved this update, as the fragments see them (`collectMovers`), and the record kept per piece. */
|
|
29986
|
+
__publicField(this, "moving", []);
|
|
29987
|
+
__publicField(this, "movers", /* @__PURE__ */ new WeakMap());
|
|
29988
|
+
__publicField(this, "moverFrom");
|
|
29989
|
+
__publicField(this, "moverTo");
|
|
29990
|
+
__publicField(this, "moverBox");
|
|
29991
|
+
__publicField(this, "moverBoxMoved");
|
|
29992
|
+
/** The box of a geometry's positions, made once (`drawnBoxOf`). */
|
|
29993
|
+
__publicField(this, "geometryBoxes", /* @__PURE__ */ new WeakMap());
|
|
29816
29994
|
__publicField(this, "v1");
|
|
29817
29995
|
__publicField(this, "v2");
|
|
29818
29996
|
__publicField(this, "v3");
|
|
@@ -29841,6 +30019,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29841
30019
|
this.workCosts = resolveWorkUnitCosts(o.workBudget?.costs);
|
|
29842
30020
|
this.box = new THREE.Box3();
|
|
29843
30021
|
this.tmpQ = new THREE.Quaternion();
|
|
30022
|
+
this.moverFrom = new THREE.Matrix4();
|
|
30023
|
+
this.moverTo = new THREE.Matrix4();
|
|
30024
|
+
this.moverBox = new THREE.Box3();
|
|
30025
|
+
this.moverBoxMoved = new THREE.Box3();
|
|
29844
30026
|
this.v1 = new THREE.Vector3();
|
|
29845
30027
|
this.v2 = new THREE.Vector3();
|
|
29846
30028
|
this.v3 = new THREE.Vector3();
|
|
@@ -29870,6 +30052,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29870
30052
|
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,
|
|
29871
30053
|
maxAwake: o.maxAwakeFragments ?? Infinity,
|
|
29872
30054
|
...o.interpolate ? { interpolate: true } : {},
|
|
30055
|
+
// the loose pieces that moved: the scraps on and in them go with them, and a part coming at a scrap meets it
|
|
30056
|
+
movers: () => this.moving,
|
|
29873
30057
|
rigid: {
|
|
29874
30058
|
add: (mesh2, half, mass, velocity, angular) => {
|
|
29875
30059
|
const body = this.pieceSys.create(`${DEBRIS_ID}${++this.debrisMade}`, mesh2, [half[0], half[1], half[2]], new THREE.Vector3(), mass, [velocity[0], velocity[1], velocity[2]], [angular[0], angular[1], angular[2]]);
|
|
@@ -30473,6 +30657,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30473
30657
|
this.pieceSys.update(dt);
|
|
30474
30658
|
this.measureCost();
|
|
30475
30659
|
this.updateFading(dt);
|
|
30660
|
+
this.collectMovers();
|
|
30661
|
+
this.syncTransforms();
|
|
30476
30662
|
this.fragments.update(dt);
|
|
30477
30663
|
this.updateActive(dt);
|
|
30478
30664
|
this.updateLeaks(dt);
|
|
@@ -31974,6 +32160,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31974
32160
|
}
|
|
31975
32161
|
}
|
|
31976
32162
|
this.bounds.set(newId, nb);
|
|
32163
|
+
nb.lastWorld = Float64Array.from(group.matrixWorld.elements);
|
|
31977
32164
|
for (const pv of nb.parts.values()) this.tagPart(pv, newId);
|
|
31978
32165
|
this.followSplit(from, nb);
|
|
31979
32166
|
const meshes = this.meshesOf(nb);
|
|
@@ -32275,6 +32462,103 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
32275
32462
|
}
|
|
32276
32463
|
return "";
|
|
32277
32464
|
}
|
|
32465
|
+
/**
|
|
32466
|
+
* The loose pieces that moved since the world was last told where they are (`FragmentSystemOptions.movers`), read before it is told: each with the box it took then and
|
|
32467
|
+
* takes now, its move, and a ray through its own parts.
|
|
32468
|
+
*/
|
|
32469
|
+
collectMovers() {
|
|
32470
|
+
const out = this.moving;
|
|
32471
|
+
out.length = 0;
|
|
32472
|
+
for (const b of this.bounds.values()) {
|
|
32473
|
+
const piece = b.piece;
|
|
32474
|
+
const was = b.lastWorld;
|
|
32475
|
+
if (!piece || piece.sleeping || !b.sync || !was || !this.world.has(b.id)) continue;
|
|
32476
|
+
b.root.updateWorldMatrix(true, false);
|
|
32477
|
+
const now = b.root.matrixWorld.elements;
|
|
32478
|
+
let same2 = true;
|
|
32479
|
+
for (let i = 0; i < 16 && same2; i++) same2 = now[i] === was[i];
|
|
32480
|
+
if (same2) continue;
|
|
32481
|
+
let solid = this.movers.get(b);
|
|
32482
|
+
if (!solid) {
|
|
32483
|
+
solid = this.moverOf(b.id);
|
|
32484
|
+
this.movers.set(b, solid);
|
|
32485
|
+
}
|
|
32486
|
+
const before = this.moverFrom.fromArray(was);
|
|
32487
|
+
this.moverTo.copy(b.root.matrixWorld).multiply(before.invert()).toArray(solid.delta);
|
|
32488
|
+
const box = solid.box;
|
|
32489
|
+
box.fill(Infinity, 0, 3);
|
|
32490
|
+
box.fill(-Infinity, 3, 6);
|
|
32491
|
+
this.drawnBoxOf(b.root, this.moverBox);
|
|
32492
|
+
const back = this.moverFrom.fromArray(solid.delta).invert();
|
|
32493
|
+
if (this.farthestCorner(back) < MOVER_MIN_MOVE) continue;
|
|
32494
|
+
this.growBox(box);
|
|
32495
|
+
this.growBox(box, back);
|
|
32496
|
+
out.push(solid);
|
|
32497
|
+
}
|
|
32498
|
+
}
|
|
32499
|
+
/**
|
|
32500
|
+
* The world box of what is drawn under `root`, from the box of each mesh's positions, kept per geometry here: never by `Box3.setFromObject`, which writes a bounding box
|
|
32501
|
+
* into each geometry it reads and so changes what the piece is made of for anyone who reads it whole.
|
|
32502
|
+
*/
|
|
32503
|
+
drawnBoxOf(root, out) {
|
|
32504
|
+
out.makeEmpty();
|
|
32505
|
+
root.updateWorldMatrix(true, true);
|
|
32506
|
+
root.traverseVisible((node) => {
|
|
32507
|
+
const mesh2 = node;
|
|
32508
|
+
const position = mesh2.isMesh ? mesh2.geometry?.getAttribute("position") : void 0;
|
|
32509
|
+
if (!position) return;
|
|
32510
|
+
let local2 = this.geometryBoxes.get(mesh2.geometry);
|
|
32511
|
+
if (!local2) {
|
|
32512
|
+
local2 = new this.THREE.Box3().setFromBufferAttribute(position);
|
|
32513
|
+
this.geometryBoxes.set(mesh2.geometry, local2);
|
|
32514
|
+
}
|
|
32515
|
+
out.union(this.moverBoxMoved.copy(local2).applyMatrix4(mesh2.matrixWorld));
|
|
32516
|
+
});
|
|
32517
|
+
}
|
|
32518
|
+
/** How far (m) the corner of `moverBox` that moves most goes under `matrix`. */
|
|
32519
|
+
farthestCorner(matrix) {
|
|
32520
|
+
if (this.moverBox.isEmpty()) return 0;
|
|
32521
|
+
const { min: min2, max: max2 } = this.moverBox;
|
|
32522
|
+
let most = 0;
|
|
32523
|
+
for (let i = 0; i < 8; i++) {
|
|
32524
|
+
const corner = this.v1.set(i & 1 ? max2.x : min2.x, i & 2 ? max2.y : min2.y, i & 4 ? max2.z : min2.z);
|
|
32525
|
+
const x = corner.x, y = corner.y, z = corner.z;
|
|
32526
|
+
corner.applyMatrix4(matrix);
|
|
32527
|
+
most = Math.max(most, Math.hypot(corner.x - x, corner.y - y, corner.z - z));
|
|
32528
|
+
}
|
|
32529
|
+
return most;
|
|
32530
|
+
}
|
|
32531
|
+
/** `box` grown by `moverBox`, under `matrix` when one is given. */
|
|
32532
|
+
growBox(box, matrix) {
|
|
32533
|
+
if (this.moverBox.isEmpty()) return;
|
|
32534
|
+
const at3 = matrix ? this.moverBoxMoved.copy(this.moverBox).applyMatrix4(matrix) : this.moverBox;
|
|
32535
|
+
box[0] = Math.min(box[0], at3.min.x);
|
|
32536
|
+
box[1] = Math.min(box[1], at3.min.y);
|
|
32537
|
+
box[2] = Math.min(box[2], at3.min.z);
|
|
32538
|
+
box[3] = Math.max(box[3], at3.max.x);
|
|
32539
|
+
box[4] = Math.max(box[4], at3.max.y);
|
|
32540
|
+
box[5] = Math.max(box[5], at3.max.z);
|
|
32541
|
+
}
|
|
32542
|
+
/** A moving piece as the fragments see it, made once per bound object: its sweep meets only its own parts, the first of them past whatever else is on the way. */
|
|
32543
|
+
moverOf(objectId) {
|
|
32544
|
+
return {
|
|
32545
|
+
box: [0, 0, 0, 0, 0, 0],
|
|
32546
|
+
delta: new Array(16).fill(0),
|
|
32547
|
+
sweep: (from, direction, distance) => {
|
|
32548
|
+
let start = [from[0], from[1], from[2]];
|
|
32549
|
+
let left = distance;
|
|
32550
|
+
for (let k = 0; k < MOVER_RAYS && left > 0; k++) {
|
|
32551
|
+
const hit = this.world.raycast(start, [direction[0], direction[1], direction[2]], left);
|
|
32552
|
+
if (!hit) return null;
|
|
32553
|
+
if (hit.object === objectId) return { point: [start[0] + direction[0] * hit.distance, start[1] + direction[1] * hit.distance, start[2] + direction[2] * hit.distance], normal: hit.normal };
|
|
32554
|
+
const past = hit.distance + SURFACE_INSIDE;
|
|
32555
|
+
start = [start[0] + direction[0] * past, start[1] + direction[1] * past, start[2] + direction[2] * past];
|
|
32556
|
+
left -= past;
|
|
32557
|
+
}
|
|
32558
|
+
return null;
|
|
32559
|
+
}
|
|
32560
|
+
};
|
|
32561
|
+
}
|
|
32278
32562
|
/** The top of the ground or of a standing part of the world under (x, z), below height y: a ray straight down through the destruction world. */
|
|
32279
32563
|
surfaceAt(x, y, z) {
|
|
32280
32564
|
const ground = this.groundAt(x, z);
|