@adatechnology/game-destruction-three 1.1.2 → 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 +295 -39
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +147 -22
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -2379,6 +2379,7 @@ var GameDestructionThree = (() => {
|
|
|
2379
2379
|
var QUALITY = { $: "quality" };
|
|
2380
2380
|
var FRESH = { $: "fresh" };
|
|
2381
2381
|
var DIRECTION = { $: "direction" };
|
|
2382
|
+
var NORMAL = { $: "normal" };
|
|
2382
2383
|
var CAMERA_POSITION = { $: "cameraPosition" };
|
|
2383
2384
|
var burst = (system, count, spawn2) => ({ op: "burst", system, count, spawn: spawn2 });
|
|
2384
2385
|
var spawn = (system, options) => ({ op: "spawn", system, spawn: options });
|
|
@@ -2900,7 +2901,7 @@ var GameDestructionThree = (() => {
|
|
|
2900
2901
|
var TIP2 = [-0.8, 1.38, 3.4 - 0.78];
|
|
2901
2902
|
var PORT2 = [-0.76, 1.4, 3.32];
|
|
2902
2903
|
var FORWARD3 = [0, 0, -1];
|
|
2903
|
-
var
|
|
2904
|
+
var NORMAL2 = [0, 0, 1];
|
|
2904
2905
|
var WALL_Z2 = -4.45;
|
|
2905
2906
|
var SHOTS = [[0, 0.45, 0.9], [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6], [0], [0]];
|
|
2906
2907
|
var SHOT_TIME = pick(pick(SHOTS, PARAM), INDEX);
|
|
@@ -2925,8 +2926,8 @@ var GameDestructionThree = (() => {
|
|
|
2925
2926
|
set("target", [add(-0.8, rnd(-0.4, 0.4)), add(1.4, rnd(-0.3, 0.3)), WALL_Z2]),
|
|
2926
2927
|
when(
|
|
2927
2928
|
eq(PARAM, SHOTGUN),
|
|
2928
|
-
[repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2],
|
|
2929
|
-
[call2("impact", "concrete", variable("target"),
|
|
2929
|
+
[repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2], NORMAL2, 0.35))],
|
|
2930
|
+
[call2("impact", "concrete", variable("target"), NORMAL2, ite(eq(PARAM, BARRETT), 2, 1))]
|
|
2930
2931
|
),
|
|
2931
2932
|
when(and(eq(PARAM, AK), eq(mod(round(mul(SHOT_TIME, 10)), 3), 0)), [spawn("streak", { p: TIP2, dir: FORWARD3, cone: 0, sp: 90, life: 0.09, len: 0.025, c0: 16752704, a: 1 })])
|
|
2932
2933
|
)
|
|
@@ -4321,7 +4322,16 @@ var GameDestructionThree = (() => {
|
|
|
4321
4322
|
};
|
|
4322
4323
|
var VIEWMODEL_EFFECTS = [MUZZLE_FLASH2, SMOKE_PUFF, BACKBLAST, FLAME_JET];
|
|
4323
4324
|
var aliasOf = (base, id, changes) => ({ ...base, id, pageId: `vehicle:${id}`, anchor: CAR_ORIGIN2, ...changes });
|
|
4325
|
+
var BODYWORK_IMPACT = {
|
|
4326
|
+
id: "impact_bodywork",
|
|
4327
|
+
pageId: "vehicle:impact_bodywork",
|
|
4328
|
+
team: "vehicles",
|
|
4329
|
+
budget: { particles: 80, debris: 20, lights: 1 },
|
|
4330
|
+
loop: 2,
|
|
4331
|
+
timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
|
|
4332
|
+
};
|
|
4324
4333
|
var VEHICLE_EFFECTS = [
|
|
4334
|
+
BODYWORK_IMPACT,
|
|
4325
4335
|
/** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
|
|
4326
4336
|
aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
|
|
4327
4337
|
/** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
|
|
@@ -5026,6 +5036,46 @@ var GameDestructionThree = (() => {
|
|
|
5026
5036
|
return evaluateCall(value.$, args.map((entry) => resolve(entry, context)));
|
|
5027
5037
|
}
|
|
5028
5038
|
}
|
|
5039
|
+
var PISTOL_BORE = 9e-3;
|
|
5040
|
+
var BARE_STEEL = 11778236;
|
|
5041
|
+
var DEFAULT_PAINT = 9147290;
|
|
5042
|
+
var DEFAULT_DIRECTION = [0, 0, -1];
|
|
5043
|
+
var MAX_SCALE = 3;
|
|
5044
|
+
var MIN_SCALE = 0.6;
|
|
5045
|
+
function reflected(direction, normal) {
|
|
5046
|
+
const along2 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
|
|
5047
|
+
const out = [direction[0] - 2 * along2 * normal[0], direction[1] - 2 * along2 * normal[1], direction[2] - 2 * along2 * normal[2]];
|
|
5048
|
+
const length = Math.hypot(out[0], out[1], out[2]);
|
|
5049
|
+
if (length < 1e-6 || Math.abs(along2) > 0.98) return normal;
|
|
5050
|
+
return [out[0] / length, out[1] / length, out[2] / length];
|
|
5051
|
+
}
|
|
5052
|
+
var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
|
|
5053
|
+
function bodyworkHitOf(values) {
|
|
5054
|
+
const raw = Array.isArray(values.direction) ? values.direction : [];
|
|
5055
|
+
const direction = raw.length === 3 && raw.every((entry) => typeof entry === "number" && Number.isFinite(entry)) ? [raw[0], raw[1], raw[2]] : DEFAULT_DIRECTION;
|
|
5056
|
+
return { direction, bore: numberOr(values.bore, PISTOL_BORE), paint: numberOr(values.paint, DEFAULT_PAINT), metal: numberOr(values.metal, BARE_STEEL) };
|
|
5057
|
+
}
|
|
5058
|
+
function bodyworkScale(bore) {
|
|
5059
|
+
return Math.min(MAX_SCALE, Math.max(MIN_SCALE, bore / PISTOL_BORE));
|
|
5060
|
+
}
|
|
5061
|
+
function bodyworkImpact(engine, point, normal, hit) {
|
|
5062
|
+
const scale = bodyworkScale(hit.bore);
|
|
5063
|
+
const off2 = reflected(hit.direction, normal);
|
|
5064
|
+
if (engine.quality < 2) {
|
|
5065
|
+
engine.burst("streak", Math.round(14 * scale), { p: point, dir: off2, cone: 0.75, sp: [4, 12], life: [0.08, 0.3], len: 0.03, c0: 16774352, c1: 16738840, g: 9.8, gnd: 2 });
|
|
5066
|
+
engine.burst("add", 2, { p: plusScaled(point, normal, 0.01), size: [0.06 * scale, 0.12 * scale], life: 0.05, c0: 16770736, fi: 0 });
|
|
5067
|
+
engine.flash([plusScaled(point, normal, 0.15), 16760432, 1.6 * scale, 0.05, 4]);
|
|
5068
|
+
}
|
|
5069
|
+
const flakes = engine.scaled(Math.round(5 * scale));
|
|
5070
|
+
for (let index = 0; index < flakes; index++) {
|
|
5071
|
+
engine.debrisPiece({ p: point, dir: normal, cone: 0.9, sp: [1.2, 3.5], size: [8e-3 * scale, 12e-4, 6e-3 * scale], k: [0.5, 1.4], c: hit.paint, life: 6, bounce: 0.2 });
|
|
5072
|
+
}
|
|
5073
|
+
const slivers = engine.scaled(Math.round(2 * scale));
|
|
5074
|
+
for (let index = 0; index < slivers; index++) {
|
|
5075
|
+
engine.debrisPiece({ p: point, dir: off2, cone: 0.6, sp: [2.5, 6], size: [25e-4, 15e-4, 0.01 * scale], k: [0.6, 1.3], c: hit.metal, life: 6, bounce: 0.35 });
|
|
5076
|
+
}
|
|
5077
|
+
engine.burst("normal", Math.round(6 * scale), { p: point, dir: normal, cone: 0.7, sp: [0.4, 1.4], drag: 2.5, life: [0.4, 0.9], size: [0.03, 0.07], grow: 3, c0: hit.paint, a: 0.45, g: -0.05 });
|
|
5078
|
+
}
|
|
5029
5079
|
var UP12 = [0, 1, 0];
|
|
5030
5080
|
var ZERO = [0, 0, 0];
|
|
5031
5081
|
var FULL_TURN_DRAWN = 6.283;
|
|
@@ -5175,9 +5225,10 @@ var GameDestructionThree = (() => {
|
|
|
5175
5225
|
casing: ({ engine }, [port, type]) => casing(engine, port, type),
|
|
5176
5226
|
chips: ({ engine }, [point, direction, count, spread2]) => chips(engine, point, direction, count, spread2),
|
|
5177
5227
|
spark_at: ({ engine }, [point, direction, count, spread2]) => sparkAt(engine, point, direction, count, spread2),
|
|
5178
|
-
rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count)
|
|
5228
|
+
rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count),
|
|
5229
|
+
bodywork_impact: ({ engine }, [point, normal, direction, bore, paint2, metal]) => bodyworkImpact(engine, point, normal, bodyworkHitOf({ direction, bore, paint: paint2, metal }))
|
|
5179
5230
|
};
|
|
5180
|
-
var
|
|
5231
|
+
var DEFAULT_DIRECTION2 = [0, 0, -1];
|
|
5181
5232
|
var DEFAULT_NORMAL = [0, 1, 0];
|
|
5182
5233
|
var SCREEN_FIELDS = {
|
|
5183
5234
|
shake: "shake",
|
|
@@ -5244,7 +5295,7 @@ var GameDestructionThree = (() => {
|
|
|
5244
5295
|
return instance().fresh;
|
|
5245
5296
|
},
|
|
5246
5297
|
get direction() {
|
|
5247
|
-
return instance().setup.direction ??
|
|
5298
|
+
return instance().setup.direction ?? DEFAULT_DIRECTION2;
|
|
5248
5299
|
},
|
|
5249
5300
|
get normal() {
|
|
5250
5301
|
return instance().setup.normal ?? DEFAULT_NORMAL;
|
|
@@ -7002,6 +7053,69 @@ var GameDestructionThree = (() => {
|
|
|
7002
7053
|
addScaled(out, tangentB, sinTilt * Math.sin(phase));
|
|
7003
7054
|
return out;
|
|
7004
7055
|
}
|
|
7056
|
+
var CELL = 0.12;
|
|
7057
|
+
var OBSTACLE_BOUNCE = 0.3;
|
|
7058
|
+
var radiusOf = (piece) => Math.max(piece.sx, piece.sz) * 0.5;
|
|
7059
|
+
var thicknessOf = (piece) => Math.min(piece.sx, piece.sy, piece.sz);
|
|
7060
|
+
var cellKey = (i, k) => (i + 4096) * 8192 + (k + 4096);
|
|
7061
|
+
var RestingGrid = class {
|
|
7062
|
+
constructor() {
|
|
7063
|
+
__publicField2(this, "cells", /* @__PURE__ */ new Map());
|
|
7064
|
+
}
|
|
7065
|
+
clear() {
|
|
7066
|
+
for (const list of this.cells.values()) list.length = 0;
|
|
7067
|
+
}
|
|
7068
|
+
rebuild(pieces) {
|
|
7069
|
+
this.clear();
|
|
7070
|
+
for (const piece of pieces) {
|
|
7071
|
+
if (!piece.on || !piece.rest) continue;
|
|
7072
|
+
const key = cellKey(Math.floor(piece.x / CELL), Math.floor(piece.z / CELL));
|
|
7073
|
+
const list = this.cells.get(key);
|
|
7074
|
+
if (list) list.push(piece);
|
|
7075
|
+
else this.cells.set(key, [piece]);
|
|
7076
|
+
}
|
|
7077
|
+
}
|
|
7078
|
+
/** The height a piece at `piece`'s place lands at on the pieces under it (the top of the highest one it overlaps), or `-Infinity` over none. */
|
|
7079
|
+
supportUnder(piece) {
|
|
7080
|
+
const i = Math.floor(piece.x / CELL);
|
|
7081
|
+
const k = Math.floor(piece.z / CELL);
|
|
7082
|
+
const reach2 = radiusOf(piece);
|
|
7083
|
+
let top = -Infinity;
|
|
7084
|
+
for (let di = -1; di <= 1; di++) {
|
|
7085
|
+
for (let dk = -1; dk <= 1; dk++) {
|
|
7086
|
+
for (const other of this.cells.get(cellKey(i + di, k + dk)) ?? []) {
|
|
7087
|
+
if (other === piece) continue;
|
|
7088
|
+
if (Math.hypot(other.x - piece.x, other.z - piece.z) > reach2 + radiusOf(other)) continue;
|
|
7089
|
+
const otherTop = other.y + thicknessOf(other) * 0.5;
|
|
7090
|
+
if (otherTop <= piece.y + thicknessOf(piece) * 0.5) top = Math.max(top, otherTop + thicknessOf(piece) * 0.5);
|
|
7091
|
+
}
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
return top;
|
|
7095
|
+
}
|
|
7096
|
+
};
|
|
7097
|
+
function pushOutOfObstacles(piece, obstacles) {
|
|
7098
|
+
let moved = false;
|
|
7099
|
+
for (const body of obstacles) {
|
|
7100
|
+
if (piece.y < body.bottom || piece.y > body.top) continue;
|
|
7101
|
+
const dx = piece.x - body.x;
|
|
7102
|
+
const dz = piece.z - body.z;
|
|
7103
|
+
const distance = Math.hypot(dx, dz);
|
|
7104
|
+
const reach2 = body.radius + radiusOf(piece);
|
|
7105
|
+
if (distance >= reach2) continue;
|
|
7106
|
+
const nx = distance > 1e-6 ? dx / distance : 1;
|
|
7107
|
+
const nz = distance > 1e-6 ? dz / distance : 0;
|
|
7108
|
+
piece.x = body.x + nx * reach2;
|
|
7109
|
+
piece.z = body.z + nz * reach2;
|
|
7110
|
+
const into = piece.vx * nx + piece.vz * nz;
|
|
7111
|
+
if (into < 0) {
|
|
7112
|
+
piece.vx -= (1 + OBSTACLE_BOUNCE) * into * nx;
|
|
7113
|
+
piece.vz -= (1 + OBSTACLE_BOUNCE) * into * nz;
|
|
7114
|
+
}
|
|
7115
|
+
moved = true;
|
|
7116
|
+
}
|
|
7117
|
+
return moved;
|
|
7118
|
+
}
|
|
7005
7119
|
var CAPACITY = 500;
|
|
7006
7120
|
var GRAVITY2 = 9.8;
|
|
7007
7121
|
var QUARTER_TURN4 = 1.5708;
|
|
@@ -7022,6 +7136,7 @@ var GameDestructionThree = (() => {
|
|
|
7022
7136
|
__publicField2(this, "count", 0);
|
|
7023
7137
|
__publicField2(this, "next", 0);
|
|
7024
7138
|
__publicField2(this, "direction", { x: 0, y: 0, z: 0 });
|
|
7139
|
+
__publicField2(this, "resting", new RestingGrid());
|
|
7025
7140
|
}
|
|
7026
7141
|
spawn(options) {
|
|
7027
7142
|
const random = this.context.random;
|
|
@@ -7059,14 +7174,21 @@ var GameDestructionThree = (() => {
|
|
|
7059
7174
|
}
|
|
7060
7175
|
update(dt) {
|
|
7061
7176
|
this.count = 0;
|
|
7177
|
+
const contacts = this.context.debrisContacts;
|
|
7178
|
+
const obstacles = contacts?.obstacles() ?? [];
|
|
7179
|
+
let moving = false;
|
|
7062
7180
|
for (const piece of this.pieces) {
|
|
7063
7181
|
if (!piece.on) continue;
|
|
7064
|
-
this.count++;
|
|
7065
7182
|
piece.life -= dt;
|
|
7066
|
-
if (piece.life <= 0)
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7183
|
+
if (piece.life <= 0) piece.on = false;
|
|
7184
|
+
else if (!piece.rest) moving = true;
|
|
7185
|
+
}
|
|
7186
|
+
if (moving && contacts) this.resting.rebuild(this.pieces);
|
|
7187
|
+
else this.resting.clear();
|
|
7188
|
+
for (const piece of this.pieces) {
|
|
7189
|
+
if (!piece.on) continue;
|
|
7190
|
+
this.count++;
|
|
7191
|
+
if (obstacles.length > 0 && pushOutOfObstacles(piece, obstacles)) piece.rest = false;
|
|
7070
7192
|
if (!piece.rest) this.move(piece, dt);
|
|
7071
7193
|
}
|
|
7072
7194
|
}
|
|
@@ -7082,7 +7204,7 @@ var GameDestructionThree = (() => {
|
|
|
7082
7204
|
piece.rx += piece.ax * dt;
|
|
7083
7205
|
piece.ry += piece.ay * dt;
|
|
7084
7206
|
piece.rz += piece.az * dt;
|
|
7085
|
-
const groundHeight = this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5;
|
|
7207
|
+
const groundHeight = Math.max(this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5, this.resting.supportUnder(piece));
|
|
7086
7208
|
if (piece.y >= groundHeight) return;
|
|
7087
7209
|
piece.y = groundHeight;
|
|
7088
7210
|
piece.vy *= -piece.bounce;
|
|
@@ -7742,6 +7864,14 @@ var GameDestructionThree = (() => {
|
|
|
7742
7864
|
this.decals = new DecalPool(this.context);
|
|
7743
7865
|
this.lights = new FlashLightPool(this.context);
|
|
7744
7866
|
}
|
|
7867
|
+
/**
|
|
7868
|
+
* Turns on the touch of the debris pieces (a game's world; the Workshop page's recording has none): they pile on the pieces at rest under them, and the
|
|
7869
|
+
* upright bodies `obstacles` answers (the player, asked once a frame while a piece moves) stop them and push them. `null` turns it off.
|
|
7870
|
+
*/
|
|
7871
|
+
setDebrisContacts(obstacles) {
|
|
7872
|
+
if (obstacles) this.context.debrisContacts = { obstacles };
|
|
7873
|
+
else delete this.context.debrisContacts;
|
|
7874
|
+
}
|
|
7745
7875
|
get random() {
|
|
7746
7876
|
return this.context.random;
|
|
7747
7877
|
}
|
|
@@ -10526,6 +10656,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10526
10656
|
const normals = new Float32Array(capacity * 3);
|
|
10527
10657
|
const impact3 = { body: 0, other: 0, impulse: 0, approach: 0, point: [0, 0, 0], normal: [0, 0, 0] };
|
|
10528
10658
|
const keep = (c, body, other, row, sign) => {
|
|
10659
|
+
if (options.ignores?.(other)) return;
|
|
10529
10660
|
let at3 = Math.imul(body, 2654435761) & mask;
|
|
10530
10661
|
while (tableStamp[at3] === stamp && tableKey[at3] !== body) at3 = at3 + 1 & mask;
|
|
10531
10662
|
let slot;
|
|
@@ -11594,6 +11725,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11594
11725
|
dying: false,
|
|
11595
11726
|
air: f.shape === "scrap" && sz[2] <= SHEET_MAX ? SHEET_AIR : 0,
|
|
11596
11727
|
body: null,
|
|
11728
|
+
rigid: null,
|
|
11597
11729
|
born: this.tick,
|
|
11598
11730
|
life: lasting ? 0 : Math.max(0, typeof this.o.life === "function" ? this.o.life(f, home) : this.o.life),
|
|
11599
11731
|
seq: this.nextSeq++,
|
|
@@ -11602,9 +11734,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11602
11734
|
isMortal: false
|
|
11603
11735
|
};
|
|
11604
11736
|
if (lasting || isBig(f.size)) {
|
|
11737
|
+
const rigid = this.o.rigid;
|
|
11738
|
+
if (rigid) live.rigid = rigid.add(mesh2, [sc.x / 2, sc.y / 2, sc.z / 2], f.mass, f.velocity, f.angularVelocity);
|
|
11605
11739
|
live.body = {
|
|
11606
11740
|
mass: f.mass,
|
|
11607
11741
|
push: (x, z) => {
|
|
11742
|
+
if (rigid && live.rigid) return rigid.push(live.rigid, x, z);
|
|
11608
11743
|
live.vel.x = x;
|
|
11609
11744
|
live.vel.z = z;
|
|
11610
11745
|
live.vel.y = Math.max(live.vel.y, 0.3);
|
|
@@ -11642,8 +11777,14 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11642
11777
|
const k = (1 - dist / radius) ** 2 * speed;
|
|
11643
11778
|
d.normalize().multiplyScalar(k);
|
|
11644
11779
|
d.y += k * 0.4;
|
|
11780
|
+
const spin = this.w.set(this.rng() - 0.5, this.rng() - 0.5, this.rng() - 0.5).multiplyScalar(k);
|
|
11781
|
+
if (f.rigid) {
|
|
11782
|
+
spin.multiplyScalar(Math.min(1, TUMBLE_REACH / Math.max(f.half.x, f.half.y, f.half.z)));
|
|
11783
|
+
this.o.rigid?.shove(f.rigid, [d.x, d.y, d.z], [spin.x, spin.y, spin.z]);
|
|
11784
|
+
continue;
|
|
11785
|
+
}
|
|
11645
11786
|
f.vel.add(d);
|
|
11646
|
-
f.ang.add(
|
|
11787
|
+
f.ang.add(spin);
|
|
11647
11788
|
this.rouse(f);
|
|
11648
11789
|
}
|
|
11649
11790
|
}
|
|
@@ -11697,7 +11838,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11697
11838
|
/** What lies inside the disc looks at the ground again: it was dug or heaped under it. */
|
|
11698
11839
|
wakeRegion(x, z, radius) {
|
|
11699
11840
|
for (const f of this.list) {
|
|
11700
|
-
if (!f.asleep || Math.hypot(f.mesh.position.x - x, f.mesh.position.z - z) > radius) continue;
|
|
11841
|
+
if (!f.asleep || f.rigid || Math.hypot(f.mesh.position.x - x, f.mesh.position.z - z) > radius) continue;
|
|
11701
11842
|
this.rouse(f);
|
|
11702
11843
|
}
|
|
11703
11844
|
}
|
|
@@ -11705,6 +11846,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11705
11846
|
this.tick++;
|
|
11706
11847
|
this.clock += dt;
|
|
11707
11848
|
this.wakeUnsupported();
|
|
11849
|
+
this.wakeRigid();
|
|
11708
11850
|
this.beginTick();
|
|
11709
11851
|
const g = this.o.gravity;
|
|
11710
11852
|
for (let i = this.active.length - 1; i >= 0; i--) {
|
|
@@ -11715,6 +11857,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11715
11857
|
if (f.fade <= 0) {
|
|
11716
11858
|
this.instances.remove(f.mesh);
|
|
11717
11859
|
this.o.scene.remove(f.mesh);
|
|
11860
|
+
this.release(f);
|
|
11718
11861
|
f.isActive = false;
|
|
11719
11862
|
this.active.splice(i, 1);
|
|
11720
11863
|
this.list.splice(this.list.indexOf(f), 1);
|
|
@@ -11723,19 +11866,34 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11723
11866
|
f.mesh.scale.copy(f.baseScale).multiplyScalar(f.fade);
|
|
11724
11867
|
}
|
|
11725
11868
|
if (f.asleep) continue;
|
|
11726
|
-
this.
|
|
11869
|
+
if (f.rigid) this.follow(f);
|
|
11870
|
+
else this.step(f, dt, g);
|
|
11727
11871
|
}
|
|
11728
11872
|
this.expireSleepers();
|
|
11729
11873
|
this.keepBudget();
|
|
11730
11874
|
this.trail?.commit();
|
|
11731
11875
|
this.drawInstanced();
|
|
11732
11876
|
}
|
|
11877
|
+
/** Its body goes with it. */
|
|
11878
|
+
release(f) {
|
|
11879
|
+
if (f.rigid) this.o.rigid?.remove(f.rigid);
|
|
11880
|
+
f.rigid = null;
|
|
11881
|
+
}
|
|
11882
|
+
/** 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. */
|
|
11883
|
+
wakeRigid() {
|
|
11884
|
+
for (const f of this.list) if (f.rigid && f.asleep && !f.dying && !f.rigid.sleeping) this.rouse(f);
|
|
11885
|
+
}
|
|
11886
|
+
/** A piece of debris moved by its rigid body: the body wrote its pose; it sleeps here when the body does. */
|
|
11887
|
+
follow(f) {
|
|
11888
|
+
f.box = void 0;
|
|
11889
|
+
if (f.rigid?.sleeping) this.sleep(f);
|
|
11890
|
+
}
|
|
11733
11891
|
/** The meshes go back to the step's pose and the ones awake are recorded as the previous one (`interpolate`). */
|
|
11734
11892
|
beginTick() {
|
|
11735
11893
|
const trail = this.trail;
|
|
11736
11894
|
if (!trail) return;
|
|
11737
11895
|
trail.begin();
|
|
11738
|
-
for (const f of this.active) if (!f.asleep) trail.record(f.mesh);
|
|
11896
|
+
for (const f of this.active) if (!f.asleep && !f.rigid) trail.record(f.mesh);
|
|
11739
11897
|
}
|
|
11740
11898
|
/** The meshes get the step pose back, before anything reads them. The instances take it at the next `update`. */
|
|
11741
11899
|
restoreStepPose() {
|
|
@@ -11750,7 +11908,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11750
11908
|
/** 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. */
|
|
11751
11909
|
drawInstanced() {
|
|
11752
11910
|
for (const f of this.active) {
|
|
11753
|
-
if (f.asleep) this.instances.remove(f.mesh);
|
|
11911
|
+
if (f.asleep || f.rigid) this.instances.remove(f.mesh);
|
|
11754
11912
|
else this.instances.add(f.mesh);
|
|
11755
11913
|
}
|
|
11756
11914
|
this.instances.sync();
|
|
@@ -11760,12 +11918,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11760
11918
|
const most = this.o.maxAwake;
|
|
11761
11919
|
if (most === void 0 || !Number.isFinite(most)) return;
|
|
11762
11920
|
let awake = 0;
|
|
11763
|
-
for (const f of this.active) if (!f.asleep && !f.dying) awake++;
|
|
11921
|
+
for (const f of this.active) if (!f.asleep && !f.dying && !f.rigid) awake++;
|
|
11764
11922
|
if (awake <= most) return;
|
|
11765
11923
|
for (let i = 0; i < this.active.length; i++) {
|
|
11766
11924
|
const f = this.active[i];
|
|
11767
11925
|
if (awake <= most) return;
|
|
11768
|
-
if (f.asleep || f.dying || !f.contact || !isSlow(f)) continue;
|
|
11926
|
+
if (f.asleep || f.dying || f.rigid || !f.contact || !isSlow(f)) continue;
|
|
11769
11927
|
this.sleep(f);
|
|
11770
11928
|
i--;
|
|
11771
11929
|
awake--;
|
|
@@ -11797,7 +11955,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11797
11955
|
for (let k = 0; k < Math.min(SUPPORT_CHECKS, n); k++) {
|
|
11798
11956
|
this.supportTurn = (this.supportTurn + 1) % n;
|
|
11799
11957
|
const f = this.list[this.supportTurn];
|
|
11800
|
-
if (!f.asleep || f.dying) continue;
|
|
11958
|
+
if (!f.asleep || f.dying || f.rigid) continue;
|
|
11801
11959
|
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
11802
11960
|
const ext = Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z;
|
|
11803
11961
|
f.floor = null;
|
|
@@ -11983,6 +12141,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11983
12141
|
if (this.list[i].home === home) {
|
|
11984
12142
|
this.instances.remove(this.list[i].mesh);
|
|
11985
12143
|
this.o.scene.remove(this.list[i].mesh);
|
|
12144
|
+
this.release(this.list[i]);
|
|
11986
12145
|
this.deactivate(this.list[i]);
|
|
11987
12146
|
this.list[i].deadline = Infinity;
|
|
11988
12147
|
this.list.splice(i, 1);
|
|
@@ -11992,7 +12151,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11992
12151
|
clear() {
|
|
11993
12152
|
this.trail?.clear();
|
|
11994
12153
|
this.instances.clear();
|
|
11995
|
-
for (const f of this.list)
|
|
12154
|
+
for (const f of this.list) {
|
|
12155
|
+
this.o.scene.remove(f.mesh);
|
|
12156
|
+
this.release(f);
|
|
12157
|
+
}
|
|
11996
12158
|
this.list.length = 0;
|
|
11997
12159
|
this.active.length = 0;
|
|
11998
12160
|
this.mortal.length = 0;
|
|
@@ -14197,7 +14359,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14197
14359
|
var DEFAULT_HITS_MAX = 32;
|
|
14198
14360
|
var DEFAULT_MIN_APPROACH = 1.5;
|
|
14199
14361
|
var DEFAULT_CONTACT_RADIUS = 0.1;
|
|
14200
|
-
var createEngineImpacts = (loop, statics, destruction, options = {}) => {
|
|
14362
|
+
var createEngineImpacts = (loop, statics, destruction, options = {}, isDebris) => {
|
|
14201
14363
|
const hitsMax = options.hitsMax ?? DEFAULT_HITS_MAX;
|
|
14202
14364
|
const radius = options.contactRadius ?? DEFAULT_CONTACT_RADIUS;
|
|
14203
14365
|
const minApproach = options.minApproach ?? DEFAULT_MIN_APPROACH;
|
|
@@ -14205,8 +14367,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14205
14367
|
minImpulse: options.minImpulse ?? DEFAULT_MIN_IMPULSE,
|
|
14206
14368
|
bodiesMax: hitsMax,
|
|
14207
14369
|
accepts: (body) => statics.ownerOf.has(body),
|
|
14370
|
+
// what is left of a part that broke breaks nothing again when it lands: a blow of debris is no blow to the world
|
|
14371
|
+
...isDebris ? { ignores: isDebris } : {},
|
|
14208
14372
|
onImpact: (impact3) => {
|
|
14209
14373
|
if (impact3.approach < minApproach) return;
|
|
14374
|
+
if (options.harmless?.(impact3.other)) return;
|
|
14210
14375
|
const object = statics.ownerOf.get(impact3.body);
|
|
14211
14376
|
const part = statics.partOf.get(impact3.body);
|
|
14212
14377
|
if (object === void 0 || part === void 0 || destruction.part(object, part) === null) return;
|
|
@@ -14660,6 +14825,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14660
14825
|
var NO_PROGRESS = 0.75;
|
|
14661
14826
|
var WAY_STEP_MIN = 0.02;
|
|
14662
14827
|
var WAY_STEP_MAX = 0.1;
|
|
14828
|
+
var BORN_INSIDE = { layers: ["static", "rubble"] };
|
|
14663
14829
|
var EnginePieces = class {
|
|
14664
14830
|
constructor(THREE, world, o) {
|
|
14665
14831
|
__publicField(this, "world", world);
|
|
@@ -14702,6 +14868,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14702
14868
|
__publicField(this, "blasts", []);
|
|
14703
14869
|
/** The host's fixed things (`staticSolids`) as static bodies. */
|
|
14704
14870
|
__publicField(this, "statics");
|
|
14871
|
+
/** The debris still passing through a fixed thing it was made inside (`throughStatics`). */
|
|
14872
|
+
__publicField(this, "passing", /* @__PURE__ */ new Set());
|
|
14873
|
+
/** A set of one fixed body, to ask how deep a piece is in that one. */
|
|
14874
|
+
__publicField(this, "oneStatic", /* @__PURE__ */ new Set());
|
|
14875
|
+
/** The bodies a piece of debris overlaps where it is made (`throughStatics`), kept between asks. */
|
|
14876
|
+
__publicField(this, "overlapped", []);
|
|
14705
14877
|
__publicField(this, "ignored", /* @__PURE__ */ new Set());
|
|
14706
14878
|
__publicField(this, "knocks", /* @__PURE__ */ new Map());
|
|
14707
14879
|
__publicField(this, "footprintOut", { corners: new Float64Array(16), normals: new Float64Array(6), minX: 0, maxX: 0, minZ: 0, maxZ: 0 });
|
|
@@ -14806,6 +14978,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14806
14978
|
this.byUser.delete(link.user);
|
|
14807
14979
|
this.byBody.delete(link.id);
|
|
14808
14980
|
this.bodyIds.delete(link.id);
|
|
14981
|
+
this.passing.delete(b);
|
|
14809
14982
|
this.active.delete(b);
|
|
14810
14983
|
if (this.byObject.get(b.objectId) === b) this.byObject.delete(b.objectId);
|
|
14811
14984
|
this.links.delete(b);
|
|
@@ -14946,6 +15119,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14946
15119
|
this.makeBodies(each);
|
|
14947
15120
|
each((b) => this.hang(b));
|
|
14948
15121
|
each((b) => this.sync(b, dt, h));
|
|
15122
|
+
this.meetStaticsAgain();
|
|
14949
15123
|
if (this.schedule) this.layGroundLater(each, dt);
|
|
14950
15124
|
else this.layGround(each, dt);
|
|
14951
15125
|
this.keepApart(apart2);
|
|
@@ -15219,7 +15393,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15219
15393
|
this.byBody.set(id, b);
|
|
15220
15394
|
this.bodyIds.add(id);
|
|
15221
15395
|
this.byObject.set(b.objectId, b);
|
|
15222
|
-
this.
|
|
15396
|
+
if (b.debris) this.throughStatics(b, link);
|
|
15397
|
+
else this.outOfStatics(b, link);
|
|
15223
15398
|
});
|
|
15224
15399
|
}
|
|
15225
15400
|
bodyDesc(b, user) {
|
|
@@ -15236,7 +15411,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15236
15411
|
centreAtOrigin: true,
|
|
15237
15412
|
keepPartContacts: shape.kind === "compound" && shape.children.length > 1,
|
|
15238
15413
|
material: this.material(b),
|
|
15239
|
-
layer: "debris",
|
|
15414
|
+
layer: b.debris ? "rubble" : "debris",
|
|
15240
15415
|
// no air drag: the kit's pieces never had any (a round piece's rolling resistance is the adapter's, `rolling`)
|
|
15241
15416
|
angularDamping: 0,
|
|
15242
15417
|
linearDamping: 0,
|
|
@@ -15300,6 +15475,52 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15300
15475
|
* 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
|
|
15301
15476
|
* 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.
|
|
15302
15477
|
*/
|
|
15478
|
+
/**
|
|
15479
|
+
* 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,
|
|
15480
|
+
* 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
|
|
15481
|
+
* where the thing broke. It passes through what it was made inside until it is out of it, and only through that.
|
|
15482
|
+
*/
|
|
15483
|
+
throughStatics(b, link) {
|
|
15484
|
+
const q = b.root.quaternion;
|
|
15485
|
+
const c = this.centre(b);
|
|
15486
|
+
const found = this.overlapped;
|
|
15487
|
+
this.world.overlapShape(this.shapeOf(b), [c.x, c.y, c.z], [q.x, q.y, q.z, q.w], found, BORN_INSIDE);
|
|
15488
|
+
for (const id of found) {
|
|
15489
|
+
if (id === link.id || link.through?.includes(id) || !(this.statics.ids.has(id) || this.bodyIds.has(id))) continue;
|
|
15490
|
+
this.world.ignorePair(link.id, id, true);
|
|
15491
|
+
(link.through ?? (link.through = [])).push(id);
|
|
15492
|
+
}
|
|
15493
|
+
if (link.through?.length) this.passing.add(b);
|
|
15494
|
+
}
|
|
15495
|
+
/** 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. */
|
|
15496
|
+
meetStaticsAgain() {
|
|
15497
|
+
if (this.passing.size === 0 || !this.world.penetration) return;
|
|
15498
|
+
const one = this.oneStatic;
|
|
15499
|
+
for (const b of this.passing) {
|
|
15500
|
+
const link = this.links.get(b);
|
|
15501
|
+
const through = link?.through;
|
|
15502
|
+
if (!link || !through) {
|
|
15503
|
+
this.passing.delete(b);
|
|
15504
|
+
continue;
|
|
15505
|
+
}
|
|
15506
|
+
let remade = false;
|
|
15507
|
+
for (let i = through.length - 1; i >= 0; i--) {
|
|
15508
|
+
const id = through[i];
|
|
15509
|
+
if (!this.statics.ids.has(id) && !this.bodyIds.has(id)) {
|
|
15510
|
+
remade = true;
|
|
15511
|
+
through.splice(i, 1);
|
|
15512
|
+
continue;
|
|
15513
|
+
}
|
|
15514
|
+
one.clear();
|
|
15515
|
+
one.add(id);
|
|
15516
|
+
if (this.world.penetration(link.id, this.outAxis, one) > SINK) continue;
|
|
15517
|
+
this.world.ignorePair(link.id, id, false);
|
|
15518
|
+
through.splice(i, 1);
|
|
15519
|
+
}
|
|
15520
|
+
if (remade) this.throughStatics(b, link);
|
|
15521
|
+
if (through.length === 0) this.passing.delete(b);
|
|
15522
|
+
}
|
|
15523
|
+
}
|
|
15303
15524
|
outOfStatics(b, link) {
|
|
15304
15525
|
if (!this.world.penetration) return;
|
|
15305
15526
|
const axis2 = this.outAxis;
|
|
@@ -16141,7 +16362,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16141
16362
|
var KEEP_EVERY = 0.5;
|
|
16142
16363
|
var SURFACE_CELL = 0.5;
|
|
16143
16364
|
var SURFACE_CELLS_ACROSS = 24;
|
|
16144
|
-
var
|
|
16365
|
+
var cellKey2 = (ix, iz) => (ix + 32768) * 65536 + (iz + 32768);
|
|
16145
16366
|
var KNOCK_FLAT = 0.5;
|
|
16146
16367
|
var SEPARATE_SPEED = 1.5;
|
|
16147
16368
|
var LIFT_DEPTH = STEP;
|
|
@@ -16313,7 +16534,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16313
16534
|
}
|
|
16314
16535
|
/** Contact blows on the fixed parts become `blunt` hits of `destruction` (`engine-impacts.ts`). Returns the way to stop it. */
|
|
16315
16536
|
contactHits(destruction, options) {
|
|
16316
|
-
return createEngineImpacts(this.loop, this.engine.statics, destruction, options);
|
|
16537
|
+
return createEngineImpacts(this.loop, this.engine.statics, destruction, options, (body) => this.engine.pieceOfBody(body)?.debris === true);
|
|
16317
16538
|
}
|
|
16318
16539
|
/**
|
|
16319
16540
|
* 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
|
|
@@ -16834,7 +17055,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16834
17055
|
this.wideSurfaces.push(one);
|
|
16835
17056
|
continue;
|
|
16836
17057
|
}
|
|
16837
|
-
for (let ix = x0; ix <= x1; ix++) for (let iz = z0; iz <= z1; iz++) this.intoCell(
|
|
17058
|
+
for (let ix = x0; ix <= x1; ix++) for (let iz = z0; iz <= z1; iz++) this.intoCell(cellKey2(ix, iz), one);
|
|
16838
17059
|
}
|
|
16839
17060
|
for (const one of this.wideSurfaces) for (const key of this.surfaceGrid.keys()) this.intoCell(key, one);
|
|
16840
17061
|
for (let i = 0; i < this.cellLists.length; i++) if (this.cellLists[i].length !== this.cellCounts[i]) this.cellLists[i].length = this.cellCounts[i];
|
|
@@ -16889,7 +17110,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16889
17110
|
}
|
|
16890
17111
|
/** The surfaces whose cell holds `(x, z)`, the wide ones (`wideSurfaces`) among them. */
|
|
16891
17112
|
surfacesAt(x, z) {
|
|
16892
|
-
return this.surfaceGrid.get(
|
|
17113
|
+
return this.surfaceGrid.get(cellKey2(Math.floor(x / SURFACE_CELL), Math.floor(z / SURFACE_CELL))) ?? this.wideSurfaces;
|
|
16893
17114
|
}
|
|
16894
17115
|
/** The highest top of a piece (other than `self`) under `(x, z)` that a point at height `y` stands on (at most `step` above it), -Infinity when none; the boxes of the last update. */
|
|
16895
17116
|
topAt(x, z, y, step, self) {
|
|
@@ -16982,13 +17203,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16982
17203
|
if (most === void 0 || !Number.isFinite(most)) return;
|
|
16983
17204
|
let awake = 0;
|
|
16984
17205
|
for (const b of this.list) {
|
|
16985
|
-
if (b.sleeping || b.held) continue;
|
|
17206
|
+
if (b.sleeping || b.held || b.debris) continue;
|
|
16986
17207
|
if (this.hasComeToRest(b) && (b.balancing || b.still >= SLEEP_AFTER && !b.hinge && !this.onSteepSupport(b))) this.sleepByBudget(b);
|
|
16987
17208
|
else awake++;
|
|
16988
17209
|
}
|
|
16989
17210
|
for (const b of this.list) {
|
|
16990
17211
|
if (awake <= most) return;
|
|
16991
|
-
if (b.sleeping || b.held || !this.hasComeToRest(b)) continue;
|
|
17212
|
+
if (b.sleeping || b.held || b.debris || !this.hasComeToRest(b)) continue;
|
|
16992
17213
|
this.sleepByBudget(b);
|
|
16993
17214
|
awake--;
|
|
16994
17215
|
}
|
|
@@ -17007,12 +17228,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
17007
17228
|
const c = this.centerOf(b, this.p);
|
|
17008
17229
|
return Math.hypot(c.x - focus[0], c.y - focus[1], c.z - focus[2]) > keep.far.distance;
|
|
17009
17230
|
};
|
|
17010
|
-
const
|
|
17231
|
+
const pieces = this.list.filter((b) => !b.debris);
|
|
17232
|
+
const atRest = pieces.filter((b) => !b.held && this.hasComeToRest(b));
|
|
17011
17233
|
if (keep.far.action === "sleep") {
|
|
17012
17234
|
for (const b of atRest) if (!b.sleeping && isFarAndOld(b)) this.sleepByBudget(b);
|
|
17013
17235
|
}
|
|
17014
17236
|
const fades = keep.far.action === "fade";
|
|
17015
|
-
let over2 =
|
|
17237
|
+
let over2 = pieces.length - keep.maxLive;
|
|
17016
17238
|
const far2 = new Set(atRest.filter(isFarAndOld));
|
|
17017
17239
|
for (const b of [...atRest].sort((a, c) => Number(far2.has(c)) - Number(far2.has(a)))) {
|
|
17018
17240
|
if (!(over2 > 0 || fades && far2.has(b))) return;
|
|
@@ -24135,9 +24357,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
24135
24357
|
at3[p.thin] = Math.sign(lp[p.thin]) * p.dims[p.thin] / 2;
|
|
24136
24358
|
const r = vec.distance(toWorld(p.pos, p.q, at3), centre);
|
|
24137
24359
|
const side = sideOnOverpressure(tnt, r);
|
|
24138
|
-
const
|
|
24360
|
+
const reflected2 = 2 * side + 6 * side * side / (side + 7 * 101325);
|
|
24139
24361
|
const impulse = bodyImpulse(tnt, r);
|
|
24140
|
-
if (
|
|
24362
|
+
if (reflected2 > PANEL_PRESSURE && impulse > PANEL_IMPULSE && (reflected2 - PANEL_PRESSURE) * (impulse - PANEL_IMPULSE) >= PANEL_PI) loaded++;
|
|
24141
24363
|
}
|
|
24142
24364
|
if (loaded < PANEL_POINTS_LOADED) return false;
|
|
24143
24365
|
const grid = gridOf(p);
|
|
@@ -28829,6 +29051,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28829
29051
|
var UNDERMINED_KEEP = 0.6;
|
|
28830
29052
|
var SOLIDS_MAX = 64;
|
|
28831
29053
|
var UNDERMINED_PUSH = 0.6;
|
|
29054
|
+
var DEBRIS_ID = "debris#";
|
|
28832
29055
|
var UNDERMINED_STILL = 0.05;
|
|
28833
29056
|
var SOLID_WELD = 1e-4;
|
|
28834
29057
|
var UNCHECKED_KINDS = /* @__PURE__ */ new Set(["structure", "room", "ground"]);
|
|
@@ -29062,6 +29285,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29062
29285
|
/** The parts the ground went down under, drawn going down (`subside`). */
|
|
29063
29286
|
__publicField(this, "settlement");
|
|
29064
29287
|
__publicField(this, "fragments");
|
|
29288
|
+
/** Count of the bodies made for big debris: each gets an id of its own. */
|
|
29289
|
+
__publicField(this, "debrisMade", 0);
|
|
29065
29290
|
__publicField(this, "ground");
|
|
29066
29291
|
__publicField(this, "pieceSys");
|
|
29067
29292
|
__publicField(this, "cages");
|
|
@@ -29148,7 +29373,34 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29148
29373
|
// and it meets the walls, ceilings and furniture on its way: it stops on their face instead of flying into them
|
|
29149
29374
|
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,
|
|
29150
29375
|
maxAwake: o.maxAwakeFragments ?? Infinity,
|
|
29151
|
-
...o.interpolate ? { interpolate: true } : {}
|
|
29376
|
+
...o.interpolate ? { interpolate: true } : {},
|
|
29377
|
+
rigid: {
|
|
29378
|
+
add: (mesh2, half, mass, velocity, angular) => {
|
|
29379
|
+
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]]);
|
|
29380
|
+
body.debris = true;
|
|
29381
|
+
return body;
|
|
29382
|
+
},
|
|
29383
|
+
remove: (handle) => this.pieceSys.remove(handle.objectId),
|
|
29384
|
+
push: (handle, x, z) => {
|
|
29385
|
+
const body = handle;
|
|
29386
|
+
body.velocity[0] = x;
|
|
29387
|
+
body.velocity[2] = z;
|
|
29388
|
+
body.velocity[1] = Math.max(body.velocity[1], 0.3);
|
|
29389
|
+
body.sleeping = false;
|
|
29390
|
+
body.still = 0;
|
|
29391
|
+
body.calmAt = null;
|
|
29392
|
+
},
|
|
29393
|
+
shove: (handle, velocity, spin) => {
|
|
29394
|
+
const body = handle;
|
|
29395
|
+
for (let i = 0; i < 3; i++) {
|
|
29396
|
+
body.velocity[i] = body.velocity[i] + velocity[i];
|
|
29397
|
+
body.angularVelocity[i] = body.angularVelocity[i] + spin[i];
|
|
29398
|
+
}
|
|
29399
|
+
body.sleeping = false;
|
|
29400
|
+
body.still = 0;
|
|
29401
|
+
body.calmAt = null;
|
|
29402
|
+
}
|
|
29403
|
+
}
|
|
29152
29404
|
});
|
|
29153
29405
|
this.cages = new RebarCages(THREE, o.scene);
|
|
29154
29406
|
this.settledBatches = new SettledBatches(THREE, o.scene, o.settledBatches ?? { enabled: false });
|
|
@@ -29620,10 +29872,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29620
29872
|
return shape === 0 ? 1 : drawn / shape;
|
|
29621
29873
|
}
|
|
29622
29874
|
pieces() {
|
|
29623
|
-
return
|
|
29875
|
+
return this.pieceSys.list.filter((piece) => !piece.debris);
|
|
29624
29876
|
}
|
|
29625
29877
|
piece(objectId) {
|
|
29626
|
-
|
|
29878
|
+
const piece = this.pieceSys.get(objectId);
|
|
29879
|
+
return piece && !piece.debris ? piece : null;
|
|
29627
29880
|
}
|
|
29628
29881
|
impulse(objectId, impulse, point) {
|
|
29629
29882
|
const p = this.pieceSys.get(objectId);
|
|
@@ -29651,6 +29904,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29651
29904
|
}
|
|
29652
29905
|
/** 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. */
|
|
29653
29906
|
slam(p, hit, speed) {
|
|
29907
|
+
if (p.debris) return;
|
|
29654
29908
|
const energy = 0.5 * p.mass * speed * speed;
|
|
29655
29909
|
const direction = [-hit.normal[0], -hit.normal[1], -hit.normal[2]];
|
|
29656
29910
|
this.landingSound(hit.object, hit.point, clamp6(speed / 10, 0.2, 1));
|
|
@@ -29662,6 +29916,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29662
29916
|
}
|
|
29663
29917
|
}
|
|
29664
29918
|
hardLanding(p, point, speed) {
|
|
29919
|
+
if (p.debris) return;
|
|
29665
29920
|
this.landingSound(p.objectId, point, clamp6(speed / 10, 0.2, 1));
|
|
29666
29921
|
this.syncBound(p.objectId);
|
|
29667
29922
|
try {
|
|
@@ -30270,7 +30525,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30270
30525
|
for (const [id, a] of this.staticNow()) scan(a, id, null, 6);
|
|
30271
30526
|
const c = this.v1;
|
|
30272
30527
|
for (const pc of this.pieceSys.list) {
|
|
30273
|
-
if (pc.held) continue;
|
|
30528
|
+
if (pc.held || pc.debris) continue;
|
|
30274
30529
|
this.pieceSys.centerOf(pc, c);
|
|
30275
30530
|
const reach2 = Math.hypot(pc.halfExtents[0], pc.halfExtents[1], pc.halfExtents[2]) + radius;
|
|
30276
30531
|
if (Math.abs(c.x - x) > reach2 || Math.abs(c.z - z) > reach2) continue;
|
|
@@ -31839,7 +32094,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31839
32094
|
reach2(distance, { objectId: pc.objectId, generation: pc.generation, impulse, point }, [c.x, c.y, c.z]);
|
|
31840
32095
|
};
|
|
31841
32096
|
const reached = this.o.blastQuery ? this.pieceSys.piecesInBlast(this.o.blastQuery, p, ev.radius) : [...this.pieceSys.list];
|
|
31842
|
-
for (const pc of reached) shove(pc);
|
|
32097
|
+
for (const pc of reached) if (!pc.debris) shove(pc);
|
|
31843
32098
|
if (this.o.shoveable) this.loosen(p, ev.radius, energy, reachOf2, policy, reach2);
|
|
31844
32099
|
this.advanceWakes(0);
|
|
31845
32100
|
this.fragments.blast(p, ev.radius, Math.min(20, Math.sqrt(energy) * 0.08));
|
|
@@ -31907,6 +32162,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31907
32162
|
if (centre.distanceTo(point) <= ev.radius) cover.set(objectId, reach2.call(this.world, ev.point, [centre.x, centre.y, centre.z], { ignore: [ev.object, objectId] }));
|
|
31908
32163
|
};
|
|
31909
32164
|
for (const pc of this.pieceSys.list) {
|
|
32165
|
+
if (pc.debris) continue;
|
|
31910
32166
|
this.pieceSys.centerOf(pc, centre);
|
|
31911
32167
|
read(pc.objectId);
|
|
31912
32168
|
}
|