@adatechnology/game-destruction-three 1.1.2 → 1.3.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 +53 -2
- package/dist/index.global.js +431 -56
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +271 -27
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.global.js
CHANGED
|
@@ -57,6 +57,8 @@ var GameDestructionThree = (() => {
|
|
|
57
57
|
IMPACT_FAMILY_TAGS: () => IMPACT_FAMILY_TAGS,
|
|
58
58
|
IMPACT_SOUNDS: () => IMPACT_SOUNDS,
|
|
59
59
|
IMPACT_SOUND_KEYS: () => IMPACT_SOUND_KEYS,
|
|
60
|
+
KIT_ENERGY_RESOLUTION: () => KIT_ENERGY_RESOLUTION,
|
|
61
|
+
KIT_RULE: () => KIT_RULE,
|
|
60
62
|
MIN_PIECE_MASS_KG: () => MIN_PIECE_MASS_KG,
|
|
61
63
|
PhysicsOptionError: () => PhysicsOptionError,
|
|
62
64
|
ROCKET_MOTOR_LOOP: () => ROCKET_MOTOR_LOOP,
|
|
@@ -2379,6 +2381,7 @@ var GameDestructionThree = (() => {
|
|
|
2379
2381
|
var QUALITY = { $: "quality" };
|
|
2380
2382
|
var FRESH = { $: "fresh" };
|
|
2381
2383
|
var DIRECTION = { $: "direction" };
|
|
2384
|
+
var NORMAL = { $: "normal" };
|
|
2382
2385
|
var CAMERA_POSITION = { $: "cameraPosition" };
|
|
2383
2386
|
var burst = (system, count, spawn2) => ({ op: "burst", system, count, spawn: spawn2 });
|
|
2384
2387
|
var spawn = (system, options) => ({ op: "spawn", system, spawn: options });
|
|
@@ -2900,7 +2903,7 @@ var GameDestructionThree = (() => {
|
|
|
2900
2903
|
var TIP2 = [-0.8, 1.38, 3.4 - 0.78];
|
|
2901
2904
|
var PORT2 = [-0.76, 1.4, 3.32];
|
|
2902
2905
|
var FORWARD3 = [0, 0, -1];
|
|
2903
|
-
var
|
|
2906
|
+
var NORMAL2 = [0, 0, 1];
|
|
2904
2907
|
var WALL_Z2 = -4.45;
|
|
2905
2908
|
var SHOTS = [[0, 0.45, 0.9], [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6], [0], [0]];
|
|
2906
2909
|
var SHOT_TIME = pick(pick(SHOTS, PARAM), INDEX);
|
|
@@ -2925,8 +2928,8 @@ var GameDestructionThree = (() => {
|
|
|
2925
2928
|
set("target", [add(-0.8, rnd(-0.4, 0.4)), add(1.4, rnd(-0.3, 0.3)), WALL_Z2]),
|
|
2926
2929
|
when(
|
|
2927
2930
|
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"),
|
|
2931
|
+
[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))],
|
|
2932
|
+
[call2("impact", "concrete", variable("target"), NORMAL2, ite(eq(PARAM, BARRETT), 2, 1))]
|
|
2930
2933
|
),
|
|
2931
2934
|
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
2935
|
)
|
|
@@ -4321,7 +4324,16 @@ var GameDestructionThree = (() => {
|
|
|
4321
4324
|
};
|
|
4322
4325
|
var VIEWMODEL_EFFECTS = [MUZZLE_FLASH2, SMOKE_PUFF, BACKBLAST, FLAME_JET];
|
|
4323
4326
|
var aliasOf = (base, id, changes) => ({ ...base, id, pageId: `vehicle:${id}`, anchor: CAR_ORIGIN2, ...changes });
|
|
4327
|
+
var BODYWORK_IMPACT = {
|
|
4328
|
+
id: "impact_bodywork",
|
|
4329
|
+
pageId: "vehicle:impact_bodywork",
|
|
4330
|
+
team: "vehicles",
|
|
4331
|
+
budget: { particles: 80, debris: 20, lights: 1 },
|
|
4332
|
+
loop: 2,
|
|
4333
|
+
timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
|
|
4334
|
+
};
|
|
4324
4335
|
var VEHICLE_EFFECTS = [
|
|
4336
|
+
BODYWORK_IMPACT,
|
|
4325
4337
|
/** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
|
|
4326
4338
|
aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
|
|
4327
4339
|
/** 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 +5038,46 @@ var GameDestructionThree = (() => {
|
|
|
5026
5038
|
return evaluateCall(value.$, args.map((entry) => resolve(entry, context)));
|
|
5027
5039
|
}
|
|
5028
5040
|
}
|
|
5041
|
+
var PISTOL_BORE = 9e-3;
|
|
5042
|
+
var BARE_STEEL = 11778236;
|
|
5043
|
+
var DEFAULT_PAINT = 9147290;
|
|
5044
|
+
var DEFAULT_DIRECTION = [0, 0, -1];
|
|
5045
|
+
var MAX_SCALE = 3;
|
|
5046
|
+
var MIN_SCALE = 0.6;
|
|
5047
|
+
function reflected(direction, normal) {
|
|
5048
|
+
const along2 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
|
|
5049
|
+
const out = [direction[0] - 2 * along2 * normal[0], direction[1] - 2 * along2 * normal[1], direction[2] - 2 * along2 * normal[2]];
|
|
5050
|
+
const length = Math.hypot(out[0], out[1], out[2]);
|
|
5051
|
+
if (length < 1e-6 || Math.abs(along2) > 0.98) return normal;
|
|
5052
|
+
return [out[0] / length, out[1] / length, out[2] / length];
|
|
5053
|
+
}
|
|
5054
|
+
var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
|
|
5055
|
+
function bodyworkHitOf(values) {
|
|
5056
|
+
const raw = Array.isArray(values.direction) ? values.direction : [];
|
|
5057
|
+
const direction = raw.length === 3 && raw.every((entry) => typeof entry === "number" && Number.isFinite(entry)) ? [raw[0], raw[1], raw[2]] : DEFAULT_DIRECTION;
|
|
5058
|
+
return { direction, bore: numberOr(values.bore, PISTOL_BORE), paint: numberOr(values.paint, DEFAULT_PAINT), metal: numberOr(values.metal, BARE_STEEL) };
|
|
5059
|
+
}
|
|
5060
|
+
function bodyworkScale(bore) {
|
|
5061
|
+
return Math.min(MAX_SCALE, Math.max(MIN_SCALE, bore / PISTOL_BORE));
|
|
5062
|
+
}
|
|
5063
|
+
function bodyworkImpact(engine, point, normal, hit) {
|
|
5064
|
+
const scale = bodyworkScale(hit.bore);
|
|
5065
|
+
const off2 = reflected(hit.direction, normal);
|
|
5066
|
+
if (engine.quality < 2) {
|
|
5067
|
+
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 });
|
|
5068
|
+
engine.burst("add", 2, { p: plusScaled(point, normal, 0.01), size: [0.06 * scale, 0.12 * scale], life: 0.05, c0: 16770736, fi: 0 });
|
|
5069
|
+
engine.flash([plusScaled(point, normal, 0.15), 16760432, 1.6 * scale, 0.05, 4]);
|
|
5070
|
+
}
|
|
5071
|
+
const flakes = engine.scaled(Math.round(5 * scale));
|
|
5072
|
+
for (let index = 0; index < flakes; index++) {
|
|
5073
|
+
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 });
|
|
5074
|
+
}
|
|
5075
|
+
const slivers = engine.scaled(Math.round(2 * scale));
|
|
5076
|
+
for (let index = 0; index < slivers; index++) {
|
|
5077
|
+
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 });
|
|
5078
|
+
}
|
|
5079
|
+
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 });
|
|
5080
|
+
}
|
|
5029
5081
|
var UP12 = [0, 1, 0];
|
|
5030
5082
|
var ZERO = [0, 0, 0];
|
|
5031
5083
|
var FULL_TURN_DRAWN = 6.283;
|
|
@@ -5175,9 +5227,10 @@ var GameDestructionThree = (() => {
|
|
|
5175
5227
|
casing: ({ engine }, [port, type]) => casing(engine, port, type),
|
|
5176
5228
|
chips: ({ engine }, [point, direction, count, spread2]) => chips(engine, point, direction, count, spread2),
|
|
5177
5229
|
spark_at: ({ engine }, [point, direction, count, spread2]) => sparkAt(engine, point, direction, count, spread2),
|
|
5178
|
-
rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count)
|
|
5230
|
+
rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count),
|
|
5231
|
+
bodywork_impact: ({ engine }, [point, normal, direction, bore, paint2, metal]) => bodyworkImpact(engine, point, normal, bodyworkHitOf({ direction, bore, paint: paint2, metal }))
|
|
5179
5232
|
};
|
|
5180
|
-
var
|
|
5233
|
+
var DEFAULT_DIRECTION2 = [0, 0, -1];
|
|
5181
5234
|
var DEFAULT_NORMAL = [0, 1, 0];
|
|
5182
5235
|
var SCREEN_FIELDS = {
|
|
5183
5236
|
shake: "shake",
|
|
@@ -5244,7 +5297,7 @@ var GameDestructionThree = (() => {
|
|
|
5244
5297
|
return instance().fresh;
|
|
5245
5298
|
},
|
|
5246
5299
|
get direction() {
|
|
5247
|
-
return instance().setup.direction ??
|
|
5300
|
+
return instance().setup.direction ?? DEFAULT_DIRECTION2;
|
|
5248
5301
|
},
|
|
5249
5302
|
get normal() {
|
|
5250
5303
|
return instance().setup.normal ?? DEFAULT_NORMAL;
|
|
@@ -7002,6 +7055,69 @@ var GameDestructionThree = (() => {
|
|
|
7002
7055
|
addScaled(out, tangentB, sinTilt * Math.sin(phase));
|
|
7003
7056
|
return out;
|
|
7004
7057
|
}
|
|
7058
|
+
var CELL = 0.12;
|
|
7059
|
+
var OBSTACLE_BOUNCE = 0.3;
|
|
7060
|
+
var radiusOf = (piece) => Math.max(piece.sx, piece.sz) * 0.5;
|
|
7061
|
+
var thicknessOf = (piece) => Math.min(piece.sx, piece.sy, piece.sz);
|
|
7062
|
+
var cellKey = (i, k) => (i + 4096) * 8192 + (k + 4096);
|
|
7063
|
+
var RestingGrid = class {
|
|
7064
|
+
constructor() {
|
|
7065
|
+
__publicField2(this, "cells", /* @__PURE__ */ new Map());
|
|
7066
|
+
}
|
|
7067
|
+
clear() {
|
|
7068
|
+
for (const list of this.cells.values()) list.length = 0;
|
|
7069
|
+
}
|
|
7070
|
+
rebuild(pieces) {
|
|
7071
|
+
this.clear();
|
|
7072
|
+
for (const piece of pieces) {
|
|
7073
|
+
if (!piece.on || !piece.rest) continue;
|
|
7074
|
+
const key = cellKey(Math.floor(piece.x / CELL), Math.floor(piece.z / CELL));
|
|
7075
|
+
const list = this.cells.get(key);
|
|
7076
|
+
if (list) list.push(piece);
|
|
7077
|
+
else this.cells.set(key, [piece]);
|
|
7078
|
+
}
|
|
7079
|
+
}
|
|
7080
|
+
/** 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. */
|
|
7081
|
+
supportUnder(piece) {
|
|
7082
|
+
const i = Math.floor(piece.x / CELL);
|
|
7083
|
+
const k = Math.floor(piece.z / CELL);
|
|
7084
|
+
const reach2 = radiusOf(piece);
|
|
7085
|
+
let top = -Infinity;
|
|
7086
|
+
for (let di = -1; di <= 1; di++) {
|
|
7087
|
+
for (let dk = -1; dk <= 1; dk++) {
|
|
7088
|
+
for (const other of this.cells.get(cellKey(i + di, k + dk)) ?? []) {
|
|
7089
|
+
if (other === piece) continue;
|
|
7090
|
+
if (Math.hypot(other.x - piece.x, other.z - piece.z) > reach2 + radiusOf(other)) continue;
|
|
7091
|
+
const otherTop = other.y + thicknessOf(other) * 0.5;
|
|
7092
|
+
if (otherTop <= piece.y + thicknessOf(piece) * 0.5) top = Math.max(top, otherTop + thicknessOf(piece) * 0.5);
|
|
7093
|
+
}
|
|
7094
|
+
}
|
|
7095
|
+
}
|
|
7096
|
+
return top;
|
|
7097
|
+
}
|
|
7098
|
+
};
|
|
7099
|
+
function pushOutOfObstacles(piece, obstacles) {
|
|
7100
|
+
let moved = false;
|
|
7101
|
+
for (const body of obstacles) {
|
|
7102
|
+
if (piece.y < body.bottom || piece.y > body.top) continue;
|
|
7103
|
+
const dx = piece.x - body.x;
|
|
7104
|
+
const dz = piece.z - body.z;
|
|
7105
|
+
const distance = Math.hypot(dx, dz);
|
|
7106
|
+
const reach2 = body.radius + radiusOf(piece);
|
|
7107
|
+
if (distance >= reach2) continue;
|
|
7108
|
+
const nx = distance > 1e-6 ? dx / distance : 1;
|
|
7109
|
+
const nz = distance > 1e-6 ? dz / distance : 0;
|
|
7110
|
+
piece.x = body.x + nx * reach2;
|
|
7111
|
+
piece.z = body.z + nz * reach2;
|
|
7112
|
+
const into = piece.vx * nx + piece.vz * nz;
|
|
7113
|
+
if (into < 0) {
|
|
7114
|
+
piece.vx -= (1 + OBSTACLE_BOUNCE) * into * nx;
|
|
7115
|
+
piece.vz -= (1 + OBSTACLE_BOUNCE) * into * nz;
|
|
7116
|
+
}
|
|
7117
|
+
moved = true;
|
|
7118
|
+
}
|
|
7119
|
+
return moved;
|
|
7120
|
+
}
|
|
7005
7121
|
var CAPACITY = 500;
|
|
7006
7122
|
var GRAVITY2 = 9.8;
|
|
7007
7123
|
var QUARTER_TURN4 = 1.5708;
|
|
@@ -7022,6 +7138,7 @@ var GameDestructionThree = (() => {
|
|
|
7022
7138
|
__publicField2(this, "count", 0);
|
|
7023
7139
|
__publicField2(this, "next", 0);
|
|
7024
7140
|
__publicField2(this, "direction", { x: 0, y: 0, z: 0 });
|
|
7141
|
+
__publicField2(this, "resting", new RestingGrid());
|
|
7025
7142
|
}
|
|
7026
7143
|
spawn(options) {
|
|
7027
7144
|
const random = this.context.random;
|
|
@@ -7059,14 +7176,21 @@ var GameDestructionThree = (() => {
|
|
|
7059
7176
|
}
|
|
7060
7177
|
update(dt) {
|
|
7061
7178
|
this.count = 0;
|
|
7179
|
+
const contacts = this.context.debrisContacts;
|
|
7180
|
+
const obstacles = contacts?.obstacles() ?? [];
|
|
7181
|
+
let moving = false;
|
|
7062
7182
|
for (const piece of this.pieces) {
|
|
7063
7183
|
if (!piece.on) continue;
|
|
7064
|
-
this.count++;
|
|
7065
7184
|
piece.life -= dt;
|
|
7066
|
-
if (piece.life <= 0)
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7185
|
+
if (piece.life <= 0) piece.on = false;
|
|
7186
|
+
else if (!piece.rest) moving = true;
|
|
7187
|
+
}
|
|
7188
|
+
if (moving && contacts) this.resting.rebuild(this.pieces);
|
|
7189
|
+
else this.resting.clear();
|
|
7190
|
+
for (const piece of this.pieces) {
|
|
7191
|
+
if (!piece.on) continue;
|
|
7192
|
+
this.count++;
|
|
7193
|
+
if (obstacles.length > 0 && pushOutOfObstacles(piece, obstacles)) piece.rest = false;
|
|
7070
7194
|
if (!piece.rest) this.move(piece, dt);
|
|
7071
7195
|
}
|
|
7072
7196
|
}
|
|
@@ -7082,7 +7206,7 @@ var GameDestructionThree = (() => {
|
|
|
7082
7206
|
piece.rx += piece.ax * dt;
|
|
7083
7207
|
piece.ry += piece.ay * dt;
|
|
7084
7208
|
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;
|
|
7209
|
+
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
7210
|
if (piece.y >= groundHeight) return;
|
|
7087
7211
|
piece.y = groundHeight;
|
|
7088
7212
|
piece.vy *= -piece.bounce;
|
|
@@ -7742,6 +7866,14 @@ var GameDestructionThree = (() => {
|
|
|
7742
7866
|
this.decals = new DecalPool(this.context);
|
|
7743
7867
|
this.lights = new FlashLightPool(this.context);
|
|
7744
7868
|
}
|
|
7869
|
+
/**
|
|
7870
|
+
* 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
|
|
7871
|
+
* upright bodies `obstacles` answers (the player, asked once a frame while a piece moves) stop them and push them. `null` turns it off.
|
|
7872
|
+
*/
|
|
7873
|
+
setDebrisContacts(obstacles) {
|
|
7874
|
+
if (obstacles) this.context.debrisContacts = { obstacles };
|
|
7875
|
+
else delete this.context.debrisContacts;
|
|
7876
|
+
}
|
|
7745
7877
|
get random() {
|
|
7746
7878
|
return this.context.random;
|
|
7747
7879
|
}
|
|
@@ -10526,6 +10658,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10526
10658
|
const normals = new Float32Array(capacity * 3);
|
|
10527
10659
|
const impact3 = { body: 0, other: 0, impulse: 0, approach: 0, point: [0, 0, 0], normal: [0, 0, 0] };
|
|
10528
10660
|
const keep = (c, body, other, row, sign) => {
|
|
10661
|
+
if (options.ignores?.(other)) return;
|
|
10529
10662
|
let at3 = Math.imul(body, 2654435761) & mask;
|
|
10530
10663
|
while (tableStamp[at3] === stamp && tableKey[at3] !== body) at3 = at3 + 1 & mask;
|
|
10531
10664
|
let slot;
|
|
@@ -11594,6 +11727,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11594
11727
|
dying: false,
|
|
11595
11728
|
air: f.shape === "scrap" && sz[2] <= SHEET_MAX ? SHEET_AIR : 0,
|
|
11596
11729
|
body: null,
|
|
11730
|
+
rigid: null,
|
|
11597
11731
|
born: this.tick,
|
|
11598
11732
|
life: lasting ? 0 : Math.max(0, typeof this.o.life === "function" ? this.o.life(f, home) : this.o.life),
|
|
11599
11733
|
seq: this.nextSeq++,
|
|
@@ -11602,9 +11736,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11602
11736
|
isMortal: false
|
|
11603
11737
|
};
|
|
11604
11738
|
if (lasting || isBig(f.size)) {
|
|
11739
|
+
const rigid = this.o.rigid;
|
|
11740
|
+
if (rigid) live.rigid = rigid.add(mesh2, [sc.x / 2, sc.y / 2, sc.z / 2], f.mass, f.velocity, f.angularVelocity);
|
|
11605
11741
|
live.body = {
|
|
11606
11742
|
mass: f.mass,
|
|
11607
11743
|
push: (x, z) => {
|
|
11744
|
+
if (rigid && live.rigid) return rigid.push(live.rigid, x, z);
|
|
11608
11745
|
live.vel.x = x;
|
|
11609
11746
|
live.vel.z = z;
|
|
11610
11747
|
live.vel.y = Math.max(live.vel.y, 0.3);
|
|
@@ -11642,8 +11779,14 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11642
11779
|
const k = (1 - dist / radius) ** 2 * speed;
|
|
11643
11780
|
d.normalize().multiplyScalar(k);
|
|
11644
11781
|
d.y += k * 0.4;
|
|
11782
|
+
const spin = this.w.set(this.rng() - 0.5, this.rng() - 0.5, this.rng() - 0.5).multiplyScalar(k);
|
|
11783
|
+
if (f.rigid) {
|
|
11784
|
+
spin.multiplyScalar(Math.min(1, TUMBLE_REACH / Math.max(f.half.x, f.half.y, f.half.z)));
|
|
11785
|
+
this.o.rigid?.shove(f.rigid, [d.x, d.y, d.z], [spin.x, spin.y, spin.z]);
|
|
11786
|
+
continue;
|
|
11787
|
+
}
|
|
11645
11788
|
f.vel.add(d);
|
|
11646
|
-
f.ang.add(
|
|
11789
|
+
f.ang.add(spin);
|
|
11647
11790
|
this.rouse(f);
|
|
11648
11791
|
}
|
|
11649
11792
|
}
|
|
@@ -11697,7 +11840,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11697
11840
|
/** What lies inside the disc looks at the ground again: it was dug or heaped under it. */
|
|
11698
11841
|
wakeRegion(x, z, radius) {
|
|
11699
11842
|
for (const f of this.list) {
|
|
11700
|
-
if (!f.asleep || Math.hypot(f.mesh.position.x - x, f.mesh.position.z - z) > radius) continue;
|
|
11843
|
+
if (!f.asleep || f.rigid || Math.hypot(f.mesh.position.x - x, f.mesh.position.z - z) > radius) continue;
|
|
11701
11844
|
this.rouse(f);
|
|
11702
11845
|
}
|
|
11703
11846
|
}
|
|
@@ -11705,6 +11848,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11705
11848
|
this.tick++;
|
|
11706
11849
|
this.clock += dt;
|
|
11707
11850
|
this.wakeUnsupported();
|
|
11851
|
+
this.wakeRigid();
|
|
11708
11852
|
this.beginTick();
|
|
11709
11853
|
const g = this.o.gravity;
|
|
11710
11854
|
for (let i = this.active.length - 1; i >= 0; i--) {
|
|
@@ -11715,6 +11859,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11715
11859
|
if (f.fade <= 0) {
|
|
11716
11860
|
this.instances.remove(f.mesh);
|
|
11717
11861
|
this.o.scene.remove(f.mesh);
|
|
11862
|
+
this.release(f);
|
|
11718
11863
|
f.isActive = false;
|
|
11719
11864
|
this.active.splice(i, 1);
|
|
11720
11865
|
this.list.splice(this.list.indexOf(f), 1);
|
|
@@ -11723,19 +11868,34 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11723
11868
|
f.mesh.scale.copy(f.baseScale).multiplyScalar(f.fade);
|
|
11724
11869
|
}
|
|
11725
11870
|
if (f.asleep) continue;
|
|
11726
|
-
this.
|
|
11871
|
+
if (f.rigid) this.follow(f);
|
|
11872
|
+
else this.step(f, dt, g);
|
|
11727
11873
|
}
|
|
11728
11874
|
this.expireSleepers();
|
|
11729
11875
|
this.keepBudget();
|
|
11730
11876
|
this.trail?.commit();
|
|
11731
11877
|
this.drawInstanced();
|
|
11732
11878
|
}
|
|
11879
|
+
/** Its body goes with it. */
|
|
11880
|
+
release(f) {
|
|
11881
|
+
if (f.rigid) this.o.rigid?.remove(f.rigid);
|
|
11882
|
+
f.rigid = null;
|
|
11883
|
+
}
|
|
11884
|
+
/** 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. */
|
|
11885
|
+
wakeRigid() {
|
|
11886
|
+
for (const f of this.list) if (f.rigid && f.asleep && !f.dying && !f.rigid.sleeping) this.rouse(f);
|
|
11887
|
+
}
|
|
11888
|
+
/** A piece of debris moved by its rigid body: the body wrote its pose; it sleeps here when the body does. */
|
|
11889
|
+
follow(f) {
|
|
11890
|
+
f.box = void 0;
|
|
11891
|
+
if (f.rigid?.sleeping) this.sleep(f);
|
|
11892
|
+
}
|
|
11733
11893
|
/** The meshes go back to the step's pose and the ones awake are recorded as the previous one (`interpolate`). */
|
|
11734
11894
|
beginTick() {
|
|
11735
11895
|
const trail = this.trail;
|
|
11736
11896
|
if (!trail) return;
|
|
11737
11897
|
trail.begin();
|
|
11738
|
-
for (const f of this.active) if (!f.asleep) trail.record(f.mesh);
|
|
11898
|
+
for (const f of this.active) if (!f.asleep && !f.rigid) trail.record(f.mesh);
|
|
11739
11899
|
}
|
|
11740
11900
|
/** The meshes get the step pose back, before anything reads them. The instances take it at the next `update`. */
|
|
11741
11901
|
restoreStepPose() {
|
|
@@ -11750,7 +11910,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11750
11910
|
/** 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
11911
|
drawInstanced() {
|
|
11752
11912
|
for (const f of this.active) {
|
|
11753
|
-
if (f.asleep) this.instances.remove(f.mesh);
|
|
11913
|
+
if (f.asleep || f.rigid) this.instances.remove(f.mesh);
|
|
11754
11914
|
else this.instances.add(f.mesh);
|
|
11755
11915
|
}
|
|
11756
11916
|
this.instances.sync();
|
|
@@ -11760,12 +11920,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11760
11920
|
const most = this.o.maxAwake;
|
|
11761
11921
|
if (most === void 0 || !Number.isFinite(most)) return;
|
|
11762
11922
|
let awake = 0;
|
|
11763
|
-
for (const f of this.active) if (!f.asleep && !f.dying) awake++;
|
|
11923
|
+
for (const f of this.active) if (!f.asleep && !f.dying && !f.rigid) awake++;
|
|
11764
11924
|
if (awake <= most) return;
|
|
11765
11925
|
for (let i = 0; i < this.active.length; i++) {
|
|
11766
11926
|
const f = this.active[i];
|
|
11767
11927
|
if (awake <= most) return;
|
|
11768
|
-
if (f.asleep || f.dying || !f.contact || !isSlow(f)) continue;
|
|
11928
|
+
if (f.asleep || f.dying || f.rigid || !f.contact || !isSlow(f)) continue;
|
|
11769
11929
|
this.sleep(f);
|
|
11770
11930
|
i--;
|
|
11771
11931
|
awake--;
|
|
@@ -11797,7 +11957,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11797
11957
|
for (let k = 0; k < Math.min(SUPPORT_CHECKS, n); k++) {
|
|
11798
11958
|
this.supportTurn = (this.supportTurn + 1) % n;
|
|
11799
11959
|
const f = this.list[this.supportTurn];
|
|
11800
|
-
if (!f.asleep || f.dying) continue;
|
|
11960
|
+
if (!f.asleep || f.dying || f.rigid) continue;
|
|
11801
11961
|
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
11802
11962
|
const ext = Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z;
|
|
11803
11963
|
f.floor = null;
|
|
@@ -11983,6 +12143,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11983
12143
|
if (this.list[i].home === home) {
|
|
11984
12144
|
this.instances.remove(this.list[i].mesh);
|
|
11985
12145
|
this.o.scene.remove(this.list[i].mesh);
|
|
12146
|
+
this.release(this.list[i]);
|
|
11986
12147
|
this.deactivate(this.list[i]);
|
|
11987
12148
|
this.list[i].deadline = Infinity;
|
|
11988
12149
|
this.list.splice(i, 1);
|
|
@@ -11992,7 +12153,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11992
12153
|
clear() {
|
|
11993
12154
|
this.trail?.clear();
|
|
11994
12155
|
this.instances.clear();
|
|
11995
|
-
for (const f of this.list)
|
|
12156
|
+
for (const f of this.list) {
|
|
12157
|
+
this.o.scene.remove(f.mesh);
|
|
12158
|
+
this.release(f);
|
|
12159
|
+
}
|
|
11996
12160
|
this.list.length = 0;
|
|
11997
12161
|
this.active.length = 0;
|
|
11998
12162
|
this.mortal.length = 0;
|
|
@@ -14197,7 +14361,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14197
14361
|
var DEFAULT_HITS_MAX = 32;
|
|
14198
14362
|
var DEFAULT_MIN_APPROACH = 1.5;
|
|
14199
14363
|
var DEFAULT_CONTACT_RADIUS = 0.1;
|
|
14200
|
-
var createEngineImpacts = (loop, statics, destruction, options = {}) => {
|
|
14364
|
+
var createEngineImpacts = (loop, statics, destruction, options = {}, isDebris) => {
|
|
14201
14365
|
const hitsMax = options.hitsMax ?? DEFAULT_HITS_MAX;
|
|
14202
14366
|
const radius = options.contactRadius ?? DEFAULT_CONTACT_RADIUS;
|
|
14203
14367
|
const minApproach = options.minApproach ?? DEFAULT_MIN_APPROACH;
|
|
@@ -14205,8 +14369,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14205
14369
|
minImpulse: options.minImpulse ?? DEFAULT_MIN_IMPULSE,
|
|
14206
14370
|
bodiesMax: hitsMax,
|
|
14207
14371
|
accepts: (body) => statics.ownerOf.has(body),
|
|
14372
|
+
// what is left of a part that broke breaks nothing again when it lands: a blow of debris is no blow to the world
|
|
14373
|
+
...isDebris ? { ignores: isDebris } : {},
|
|
14208
14374
|
onImpact: (impact3) => {
|
|
14209
14375
|
if (impact3.approach < minApproach) return;
|
|
14376
|
+
if (options.harmless?.(impact3.other)) return;
|
|
14210
14377
|
const object = statics.ownerOf.get(impact3.body);
|
|
14211
14378
|
const part = statics.partOf.get(impact3.body);
|
|
14212
14379
|
if (object === void 0 || part === void 0 || destruction.part(object, part) === null) return;
|
|
@@ -14224,6 +14391,97 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14224
14391
|
});
|
|
14225
14392
|
};
|
|
14226
14393
|
|
|
14394
|
+
// src/kit-energy.ts
|
|
14395
|
+
var KIT_RULE = {
|
|
14396
|
+
/** A piece that lost a leg and is balanced on the line between the ones left is started down over it (`renderer.ts`). */
|
|
14397
|
+
GO_OVER_IF_BALANCED: "goOverIfBalanced",
|
|
14398
|
+
/** What stood on ground that went (a hole under a foot) is started down over the gap (`renderer.ts`). */
|
|
14399
|
+
CHECK_UNDERMINED: "checkUndermined",
|
|
14400
|
+
/** Furniture made a piece balanced on an edge of its feet is started over it (`EDGE_NUDGE`, `renderer.ts`). */
|
|
14401
|
+
LOOSEN_IF_FOOTLESS: "loosenIfFootless",
|
|
14402
|
+
/** A piece of the engine balanced on a narrow support is turned about its edge (`engine-pieces.ts`). */
|
|
14403
|
+
TOPPLE: "topple"
|
|
14404
|
+
};
|
|
14405
|
+
var RULES = Object.values(KIT_RULE);
|
|
14406
|
+
var GRAVITY3 = 9.81;
|
|
14407
|
+
var KIT_ENERGY_RESOLUTION = 1e-3;
|
|
14408
|
+
var REST_HEIGHT = KIT_ENERGY_RESOLUTION;
|
|
14409
|
+
var kineticEnergyOf = (body) => {
|
|
14410
|
+
const [vx2, vy2, vz2] = body.velocity;
|
|
14411
|
+
const [wx, wy, wz] = body.angularVelocity;
|
|
14412
|
+
const { x, y, z, w } = body.root.quaternion;
|
|
14413
|
+
const lx = (1 - 2 * (y * y + z * z)) * wx + 2 * (x * y + z * w) * wy + 2 * (x * z - y * w) * wz;
|
|
14414
|
+
const ly = 2 * (x * y - z * w) * wx + (1 - 2 * (x * x + z * z)) * wy + 2 * (y * z + x * w) * wz;
|
|
14415
|
+
const lz = 2 * (x * z + y * w) * wx + 2 * (y * z - x * w) * wy + (1 - 2 * (x * x + y * y)) * wz;
|
|
14416
|
+
const [hx, hy, hz2] = body.halfExtents;
|
|
14417
|
+
const m = body.mass;
|
|
14418
|
+
let ix = m * (hy * hy + hz2 * hz2) / 3;
|
|
14419
|
+
let iy = m * (hx * hx + hz2 * hz2) / 3;
|
|
14420
|
+
let iz = m * (hx * hx + hy * hy) / 3;
|
|
14421
|
+
const round2 = body.round;
|
|
14422
|
+
if (round2) {
|
|
14423
|
+
const about = round2.inertia * m * round2.radius * round2.radius;
|
|
14424
|
+
if (round2.kind === "sphere") ix = iy = iz = about;
|
|
14425
|
+
else if (round2.axis === 0) ix = about;
|
|
14426
|
+
else if (round2.axis === 1) iy = about;
|
|
14427
|
+
else iz = about;
|
|
14428
|
+
}
|
|
14429
|
+
return 0.5 * m * (vx2 * vx2 + vy2 * vy2 + vz2 * vz2) + 0.5 * (ix * lx * lx + iy * ly * ly + iz * lz * lz);
|
|
14430
|
+
};
|
|
14431
|
+
var fallEnergyOf = (body) => {
|
|
14432
|
+
const { x, y, z, w } = body.root.quaternion;
|
|
14433
|
+
const [hx, hy, hz2] = body.halfExtents;
|
|
14434
|
+
const [cx, cy, cz] = body.massCentre ?? [0, 0, 0];
|
|
14435
|
+
const rx = 2 * (x * y + z * w);
|
|
14436
|
+
const ry = 1 - 2 * (x * x + z * z);
|
|
14437
|
+
const rz = 2 * (y * z - x * w);
|
|
14438
|
+
const over2 = hx * Math.abs(rx) + hy * Math.abs(ry) + hz2 * Math.abs(rz) + rx * cx + ry * cy + rz * cz;
|
|
14439
|
+
const lowest = Math.min(hx - Math.abs(cx), hy - Math.abs(cy), hz2 - Math.abs(cz));
|
|
14440
|
+
return body.mass * GRAVITY3 * Math.max(0, over2 - lowest);
|
|
14441
|
+
};
|
|
14442
|
+
var KitEnergyLedger = class {
|
|
14443
|
+
constructor(onOver) {
|
|
14444
|
+
__publicField(this, "onOver", onOver);
|
|
14445
|
+
__publicField(this, "before", 0);
|
|
14446
|
+
__publicField(this, "tallies", new Map(RULES.map((rule) => [rule, { pushes: 0, overs: 0, worstShare: 0, worst: null }])));
|
|
14447
|
+
__publicField(this, "episodes", /* @__PURE__ */ new WeakMap());
|
|
14448
|
+
}
|
|
14449
|
+
begin(body) {
|
|
14450
|
+
this.before = kineticEnergyOf(body);
|
|
14451
|
+
if (this.before > body.mass * GRAVITY3 * REST_HEIGHT) return;
|
|
14452
|
+
const episode = this.episodes.get(body);
|
|
14453
|
+
if (!episode) {
|
|
14454
|
+
this.episodes.set(body, { given: new Float64Array(RULES.length), over: new Uint8Array(RULES.length), fall: fallEnergyOf(body) });
|
|
14455
|
+
return;
|
|
14456
|
+
}
|
|
14457
|
+
episode.given.fill(0);
|
|
14458
|
+
episode.over.fill(0);
|
|
14459
|
+
episode.fall = fallEnergyOf(body);
|
|
14460
|
+
}
|
|
14461
|
+
end(rule, body) {
|
|
14462
|
+
const tally = this.tallies.get(rule);
|
|
14463
|
+
tally.pushes++;
|
|
14464
|
+
const episode = this.episodes.get(body);
|
|
14465
|
+
const open = episode ?? { given: new Float64Array(RULES.length), over: new Uint8Array(RULES.length), fall: fallEnergyOf(body) };
|
|
14466
|
+
if (!episode) this.episodes.set(body, open);
|
|
14467
|
+
const index = RULES.indexOf(rule);
|
|
14468
|
+
const given = open.given[index] + kineticEnergyOf(body) - this.before;
|
|
14469
|
+
open.given[index] = given;
|
|
14470
|
+
const share = given <= 0 ? 0 : given / (open.fall + body.mass * GRAVITY3 * KIT_ENERGY_RESOLUTION);
|
|
14471
|
+
if (share > tally.worstShare) {
|
|
14472
|
+
tally.worstShare = share;
|
|
14473
|
+
tally.worst = { rule, objectId: body.objectId, given, fall: open.fall };
|
|
14474
|
+
}
|
|
14475
|
+
if (share <= 1 || open.over[index]) return;
|
|
14476
|
+
open.over[index] = 1;
|
|
14477
|
+
tally.overs++;
|
|
14478
|
+
this.onOver?.({ rule, objectId: body.objectId, given, fall: open.fall });
|
|
14479
|
+
}
|
|
14480
|
+
tally() {
|
|
14481
|
+
return RULES.map((rule) => ({ rule, ...this.tallies.get(rule) }));
|
|
14482
|
+
}
|
|
14483
|
+
};
|
|
14484
|
+
|
|
14227
14485
|
// src/engine-ground-heights.ts
|
|
14228
14486
|
var changedHeights = (before, after2, size) => {
|
|
14229
14487
|
let minX = size;
|
|
@@ -14660,6 +14918,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14660
14918
|
var NO_PROGRESS = 0.75;
|
|
14661
14919
|
var WAY_STEP_MIN = 0.02;
|
|
14662
14920
|
var WAY_STEP_MAX = 0.1;
|
|
14921
|
+
var BORN_INSIDE = { layers: ["static", "rubble"] };
|
|
14663
14922
|
var EnginePieces = class {
|
|
14664
14923
|
constructor(THREE, world, o) {
|
|
14665
14924
|
__publicField(this, "world", world);
|
|
@@ -14702,6 +14961,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14702
14961
|
__publicField(this, "blasts", []);
|
|
14703
14962
|
/** The host's fixed things (`staticSolids`) as static bodies. */
|
|
14704
14963
|
__publicField(this, "statics");
|
|
14964
|
+
/** The debris still passing through a fixed thing it was made inside (`throughStatics`). */
|
|
14965
|
+
__publicField(this, "passing", /* @__PURE__ */ new Set());
|
|
14966
|
+
/** A set of one fixed body, to ask how deep a piece is in that one. */
|
|
14967
|
+
__publicField(this, "oneStatic", /* @__PURE__ */ new Set());
|
|
14968
|
+
/** The bodies a piece of debris overlaps where it is made (`throughStatics`), kept between asks. */
|
|
14969
|
+
__publicField(this, "overlapped", []);
|
|
14705
14970
|
__publicField(this, "ignored", /* @__PURE__ */ new Set());
|
|
14706
14971
|
__publicField(this, "knocks", /* @__PURE__ */ new Map());
|
|
14707
14972
|
__publicField(this, "footprintOut", { corners: new Float64Array(16), normals: new Float64Array(6), minX: 0, maxX: 0, minZ: 0, maxZ: 0 });
|
|
@@ -14806,6 +15071,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14806
15071
|
this.byUser.delete(link.user);
|
|
14807
15072
|
this.byBody.delete(link.id);
|
|
14808
15073
|
this.bodyIds.delete(link.id);
|
|
15074
|
+
this.passing.delete(b);
|
|
14809
15075
|
this.active.delete(b);
|
|
14810
15076
|
if (this.byObject.get(b.objectId) === b) this.byObject.delete(b.objectId);
|
|
14811
15077
|
this.links.delete(b);
|
|
@@ -14946,6 +15212,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14946
15212
|
this.makeBodies(each);
|
|
14947
15213
|
each((b) => this.hang(b));
|
|
14948
15214
|
each((b) => this.sync(b, dt, h));
|
|
15215
|
+
this.meetStaticsAgain();
|
|
14949
15216
|
if (this.schedule) this.layGroundLater(each, dt);
|
|
14950
15217
|
else this.layGround(each, dt);
|
|
14951
15218
|
this.keepApart(apart2);
|
|
@@ -15219,7 +15486,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15219
15486
|
this.byBody.set(id, b);
|
|
15220
15487
|
this.bodyIds.add(id);
|
|
15221
15488
|
this.byObject.set(b.objectId, b);
|
|
15222
|
-
this.
|
|
15489
|
+
if (b.debris) this.throughStatics(b, link);
|
|
15490
|
+
else this.outOfStatics(b, link);
|
|
15223
15491
|
});
|
|
15224
15492
|
}
|
|
15225
15493
|
bodyDesc(b, user) {
|
|
@@ -15236,7 +15504,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15236
15504
|
centreAtOrigin: true,
|
|
15237
15505
|
keepPartContacts: shape.kind === "compound" && shape.children.length > 1,
|
|
15238
15506
|
material: this.material(b),
|
|
15239
|
-
layer: "debris",
|
|
15507
|
+
layer: b.debris ? "rubble" : "debris",
|
|
15240
15508
|
// no air drag: the kit's pieces never had any (a round piece's rolling resistance is the adapter's, `rolling`)
|
|
15241
15509
|
angularDamping: 0,
|
|
15242
15510
|
linearDamping: 0,
|
|
@@ -15300,6 +15568,52 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15300
15568
|
* 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
15569
|
* 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
15570
|
*/
|
|
15571
|
+
/**
|
|
15572
|
+
* 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,
|
|
15573
|
+
* 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
|
|
15574
|
+
* where the thing broke. It passes through what it was made inside until it is out of it, and only through that.
|
|
15575
|
+
*/
|
|
15576
|
+
throughStatics(b, link) {
|
|
15577
|
+
const q = b.root.quaternion;
|
|
15578
|
+
const c = this.centre(b);
|
|
15579
|
+
const found = this.overlapped;
|
|
15580
|
+
this.world.overlapShape(this.shapeOf(b), [c.x, c.y, c.z], [q.x, q.y, q.z, q.w], found, BORN_INSIDE);
|
|
15581
|
+
for (const id of found) {
|
|
15582
|
+
if (id === link.id || link.through?.includes(id) || !(this.statics.ids.has(id) || this.bodyIds.has(id))) continue;
|
|
15583
|
+
this.world.ignorePair(link.id, id, true);
|
|
15584
|
+
(link.through ?? (link.through = [])).push(id);
|
|
15585
|
+
}
|
|
15586
|
+
if (link.through?.length) this.passing.add(b);
|
|
15587
|
+
}
|
|
15588
|
+
/** 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. */
|
|
15589
|
+
meetStaticsAgain() {
|
|
15590
|
+
if (this.passing.size === 0 || !this.world.penetration) return;
|
|
15591
|
+
const one = this.oneStatic;
|
|
15592
|
+
for (const b of this.passing) {
|
|
15593
|
+
const link = this.links.get(b);
|
|
15594
|
+
const through = link?.through;
|
|
15595
|
+
if (!link || !through) {
|
|
15596
|
+
this.passing.delete(b);
|
|
15597
|
+
continue;
|
|
15598
|
+
}
|
|
15599
|
+
let remade = false;
|
|
15600
|
+
for (let i = through.length - 1; i >= 0; i--) {
|
|
15601
|
+
const id = through[i];
|
|
15602
|
+
if (!this.statics.ids.has(id) && !this.bodyIds.has(id)) {
|
|
15603
|
+
remade = true;
|
|
15604
|
+
through.splice(i, 1);
|
|
15605
|
+
continue;
|
|
15606
|
+
}
|
|
15607
|
+
one.clear();
|
|
15608
|
+
one.add(id);
|
|
15609
|
+
if (this.world.penetration(link.id, this.outAxis, one) > SINK) continue;
|
|
15610
|
+
this.world.ignorePair(link.id, id, false);
|
|
15611
|
+
through.splice(i, 1);
|
|
15612
|
+
}
|
|
15613
|
+
if (remade) this.throughStatics(b, link);
|
|
15614
|
+
if (through.length === 0) this.passing.delete(b);
|
|
15615
|
+
}
|
|
15616
|
+
}
|
|
15303
15617
|
outOfStatics(b, link) {
|
|
15304
15618
|
if (!this.world.penetration) return;
|
|
15305
15619
|
const axis2 = this.outAxis;
|
|
@@ -15491,20 +15805,25 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15491
15805
|
if (wx <= wz) {
|
|
15492
15806
|
const edge = dirX > 0 ? x1 : x0;
|
|
15493
15807
|
const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN, this.turningOf(b, 2)) * dt : 0;
|
|
15808
|
+
if (dw === 0) return;
|
|
15494
15809
|
const rx = -edge;
|
|
15495
15810
|
const ry = -low;
|
|
15811
|
+
this.o.kitEnergy?.begin(b);
|
|
15496
15812
|
w[2] += dw;
|
|
15497
15813
|
v[0] += -dw * ry;
|
|
15498
15814
|
v[1] += dw * rx;
|
|
15499
15815
|
} else {
|
|
15500
15816
|
const edge = dirZ > 0 ? z1 : z0;
|
|
15501
15817
|
const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN, this.turningOf(b, 0)) * dt : 0;
|
|
15818
|
+
if (dw === 0) return;
|
|
15502
15819
|
const rz = -edge;
|
|
15503
15820
|
const ry = -low;
|
|
15821
|
+
this.o.kitEnergy?.begin(b);
|
|
15504
15822
|
w[0] += dw;
|
|
15505
15823
|
v[1] += -dw * rz;
|
|
15506
15824
|
v[2] += dw * ry;
|
|
15507
15825
|
}
|
|
15826
|
+
this.o.kitEnergy?.end(KIT_RULE.TOPPLE, b);
|
|
15508
15827
|
}
|
|
15509
15828
|
/** Propped pieces lose most of their friction until they move or sleep (the push only presses them into the prop: an energy-free way to end a wedge). */
|
|
15510
15829
|
slip(b, link, isSlipping) {
|
|
@@ -16141,7 +16460,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16141
16460
|
var KEEP_EVERY = 0.5;
|
|
16142
16461
|
var SURFACE_CELL = 0.5;
|
|
16143
16462
|
var SURFACE_CELLS_ACROSS = 24;
|
|
16144
|
-
var
|
|
16463
|
+
var cellKey2 = (ix, iz) => (ix + 32768) * 65536 + (iz + 32768);
|
|
16145
16464
|
var KNOCK_FLAT = 0.5;
|
|
16146
16465
|
var SEPARATE_SPEED = 1.5;
|
|
16147
16466
|
var LIFT_DEPTH = STEP;
|
|
@@ -16255,6 +16574,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16255
16574
|
__publicField(this, "supportNormal", UP16);
|
|
16256
16575
|
__publicField(this, "supportFriction", null);
|
|
16257
16576
|
__publicField(this, "supportBody", null);
|
|
16577
|
+
/** What each rule of the kit gave the pieces it pushed (`ruleImpulse`, and the engine's own `topple`). */
|
|
16578
|
+
__publicField(this, "kitEnergy");
|
|
16258
16579
|
/** A piece is asleep on both sides (the engine's too): nothing of it changes until it wakes. */
|
|
16259
16580
|
__publicField(this, "isSettled", (body) => this.engine.isSettled(body));
|
|
16260
16581
|
__publicField(this, "measureAwake", (body) => {
|
|
@@ -16288,7 +16609,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16288
16609
|
this.loop = resolved.loop;
|
|
16289
16610
|
this.stepsItself = resolved.stepsItself;
|
|
16290
16611
|
this.trail = o.interpolate ? new PoseTrail() : null;
|
|
16612
|
+
this.kitEnergy = new KitEnergyLedger(o.onKitEnergy);
|
|
16291
16613
|
this.engine = new EnginePieces(THREE, resolved.loop.world, {
|
|
16614
|
+
kitEnergy: this.kitEnergy,
|
|
16292
16615
|
groundAt: o.terrainAt ?? o.groundAt,
|
|
16293
16616
|
...o.terrainRollingAt ? { groundRollingAt: o.terrainRollingAt } : {},
|
|
16294
16617
|
...o.terrainRollingDampingAt ? { groundRollingDampingAt: o.terrainRollingDampingAt } : {},
|
|
@@ -16313,7 +16636,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16313
16636
|
}
|
|
16314
16637
|
/** Contact blows on the fixed parts become `blunt` hits of `destruction` (`engine-impacts.ts`). Returns the way to stop it. */
|
|
16315
16638
|
contactHits(destruction, options) {
|
|
16316
|
-
return createEngineImpacts(this.loop, this.engine.statics, destruction, options);
|
|
16639
|
+
return createEngineImpacts(this.loop, this.engine.statics, destruction, options, (body) => this.engine.pieceOfBody(body)?.debris === true);
|
|
16317
16640
|
}
|
|
16318
16641
|
/**
|
|
16319
16642
|
* 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
|
|
@@ -16630,6 +16953,20 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16630
16953
|
b.still = 0;
|
|
16631
16954
|
b.calmAt = null;
|
|
16632
16955
|
}
|
|
16956
|
+
/** `impulse` given by a rule of the kit on its own, measured by its name (`kitEnergy`). */
|
|
16957
|
+
ruleImpulse(rule, b, impulse, point) {
|
|
16958
|
+
this.kitEnergy.begin(b);
|
|
16959
|
+
this.impulse(b, impulse, point);
|
|
16960
|
+
this.kitEnergy.end(rule, b);
|
|
16961
|
+
}
|
|
16962
|
+
/** Spin (rad/s, world axes x and z) added by a rule of the kit on its own, measured by its name (`kitEnergy`). */
|
|
16963
|
+
ruleSpin(rule, b, x, z) {
|
|
16964
|
+
this.kitEnergy.begin(b);
|
|
16965
|
+
b.angularVelocity[0] += x;
|
|
16966
|
+
b.angularVelocity[2] += z;
|
|
16967
|
+
b.sleeping = false;
|
|
16968
|
+
this.kitEnergy.end(rule, b);
|
|
16969
|
+
}
|
|
16633
16970
|
/** I^-1 * (x, y, z) in world space for a box with the body's half extents and mass (needs `this.m` to hold the body's rotation). */
|
|
16634
16971
|
mulInvInertia(b, x, y, z) {
|
|
16635
16972
|
this.m.makeRotationFromQuaternion(b.root.quaternion);
|
|
@@ -16834,7 +17171,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16834
17171
|
this.wideSurfaces.push(one);
|
|
16835
17172
|
continue;
|
|
16836
17173
|
}
|
|
16837
|
-
for (let ix = x0; ix <= x1; ix++) for (let iz = z0; iz <= z1; iz++) this.intoCell(
|
|
17174
|
+
for (let ix = x0; ix <= x1; ix++) for (let iz = z0; iz <= z1; iz++) this.intoCell(cellKey2(ix, iz), one);
|
|
16838
17175
|
}
|
|
16839
17176
|
for (const one of this.wideSurfaces) for (const key of this.surfaceGrid.keys()) this.intoCell(key, one);
|
|
16840
17177
|
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 +17226,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16889
17226
|
}
|
|
16890
17227
|
/** The surfaces whose cell holds `(x, z)`, the wide ones (`wideSurfaces`) among them. */
|
|
16891
17228
|
surfacesAt(x, z) {
|
|
16892
|
-
return this.surfaceGrid.get(
|
|
17229
|
+
return this.surfaceGrid.get(cellKey2(Math.floor(x / SURFACE_CELL), Math.floor(z / SURFACE_CELL))) ?? this.wideSurfaces;
|
|
16893
17230
|
}
|
|
16894
17231
|
/** 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
17232
|
topAt(x, z, y, step, self) {
|
|
@@ -16982,13 +17319,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16982
17319
|
if (most === void 0 || !Number.isFinite(most)) return;
|
|
16983
17320
|
let awake = 0;
|
|
16984
17321
|
for (const b of this.list) {
|
|
16985
|
-
if (b.sleeping || b.held) continue;
|
|
17322
|
+
if (b.sleeping || b.held || b.debris) continue;
|
|
16986
17323
|
if (this.hasComeToRest(b) && (b.balancing || b.still >= SLEEP_AFTER && !b.hinge && !this.onSteepSupport(b))) this.sleepByBudget(b);
|
|
16987
17324
|
else awake++;
|
|
16988
17325
|
}
|
|
16989
17326
|
for (const b of this.list) {
|
|
16990
17327
|
if (awake <= most) return;
|
|
16991
|
-
if (b.sleeping || b.held || !this.hasComeToRest(b)) continue;
|
|
17328
|
+
if (b.sleeping || b.held || b.debris || !this.hasComeToRest(b)) continue;
|
|
16992
17329
|
this.sleepByBudget(b);
|
|
16993
17330
|
awake--;
|
|
16994
17331
|
}
|
|
@@ -17007,12 +17344,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
17007
17344
|
const c = this.centerOf(b, this.p);
|
|
17008
17345
|
return Math.hypot(c.x - focus[0], c.y - focus[1], c.z - focus[2]) > keep.far.distance;
|
|
17009
17346
|
};
|
|
17010
|
-
const
|
|
17347
|
+
const pieces = this.list.filter((b) => !b.debris);
|
|
17348
|
+
const atRest = pieces.filter((b) => !b.held && this.hasComeToRest(b));
|
|
17011
17349
|
if (keep.far.action === "sleep") {
|
|
17012
17350
|
for (const b of atRest) if (!b.sleeping && isFarAndOld(b)) this.sleepByBudget(b);
|
|
17013
17351
|
}
|
|
17014
17352
|
const fades = keep.far.action === "fade";
|
|
17015
|
-
let over2 =
|
|
17353
|
+
let over2 = pieces.length - keep.maxLive;
|
|
17016
17354
|
const far2 = new Set(atRest.filter(isFarAndOld));
|
|
17017
17355
|
for (const b of [...atRest].sort((a, c) => Number(far2.has(c)) - Number(far2.has(a)))) {
|
|
17018
17356
|
if (!(over2 > 0 || fades && far2.has(b))) return;
|
|
@@ -18414,7 +18752,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
18414
18752
|
for (const [a, b] of bars) length += Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]) + Math.abs(a[2] - b[2]);
|
|
18415
18753
|
return Math.PI * (diameter / 2) * (diameter / 2) * length * density;
|
|
18416
18754
|
};
|
|
18417
|
-
var
|
|
18755
|
+
var GRAVITY4 = 9.81;
|
|
18418
18756
|
var MPA = 1e6;
|
|
18419
18757
|
var FLEXURE_DEFAULTS = {
|
|
18420
18758
|
enabled: true,
|
|
@@ -18517,7 +18855,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
18517
18855
|
var sectionWidth = (g, axis2) => g.member ? g.dims[g.depthAxes.find((a) => a !== axis2) ?? axis2] : 1;
|
|
18518
18856
|
var lineLoad = (g, load) => {
|
|
18519
18857
|
const area = g.member ? g.dims[g.spanAxes[0]] : g.dims[g.spanAxes[0]] * g.dims[g.spanAxes[1]];
|
|
18520
|
-
return load *
|
|
18858
|
+
return load * GRAVITY4 / Math.max(area, 1e-6);
|
|
18521
18859
|
};
|
|
18522
18860
|
var spanOf = (g, contacts, samples = 9) => {
|
|
18523
18861
|
if (contacts.length === 0) return 0;
|
|
@@ -19157,7 +19495,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
19157
19495
|
let anyFoundation = false;
|
|
19158
19496
|
for (let i = 0; i < parts.length; i++) {
|
|
19159
19497
|
const p = parts[i];
|
|
19160
|
-
weight += p.mass *
|
|
19498
|
+
weight += p.mass * GRAVITY4;
|
|
19161
19499
|
wu += p.mass * g[i].u;
|
|
19162
19500
|
if (p.kind === "foundation") {
|
|
19163
19501
|
anyFoundation = true;
|
|
@@ -19176,7 +19514,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
19176
19514
|
if (!anyFoundation) {
|
|
19177
19515
|
for (let i = 0; i < parts.length; i++) if (parts[i].min[1] - ground < 0.1) footEnd = Math.max(footEnd, g[i].u + g[i].du / 2);
|
|
19178
19516
|
}
|
|
19179
|
-
const totalMass = weight /
|
|
19517
|
+
const totalMass = weight / GRAVITY4;
|
|
19180
19518
|
const uCg = totalMass > 0 ? wu / totalMass : 0;
|
|
19181
19519
|
const width = vmax.map((hi, j) => hi > vmin[j] ? hi - vmin[j] : 0);
|
|
19182
19520
|
const widest = Math.max(...width);
|
|
@@ -20808,7 +21146,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
20808
21146
|
const steel = bars * Math.PI * (part.reinforcement.diameter / 2) ** 2;
|
|
20809
21147
|
newtons = m.concreteFactor * fc * section + steel * resolveFlexure(options.flexure).rebarYieldMPa * 1e6;
|
|
20810
21148
|
}
|
|
20811
|
-
return Math.max(1, newtons /
|
|
21149
|
+
return Math.max(1, newtons / GRAVITY4 * foundation);
|
|
20812
21150
|
};
|
|
20813
21151
|
var fragility = (ductility, thickness) => {
|
|
20814
21152
|
if (ductility >= 0.3) return 1;
|
|
@@ -21719,7 +22057,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
21719
22057
|
const width = sectionWidth(g, axis2);
|
|
21720
22058
|
const impulse = sum / offsets.length * cos2 * reach2 * width * L;
|
|
21721
22059
|
const weight = axis2 === g.gravity ? p.bendLoad : p.st.mass;
|
|
21722
|
-
const kinetic = impulseEnergy(impulse, lineLoad(g, weight) /
|
|
22060
|
+
const kinetic = impulseEnergy(impulse, lineLoad(g, weight) / GRAVITY4 * L, flexure);
|
|
21723
22061
|
const sec = sectionOf(p, axis2);
|
|
21724
22062
|
const EI = s.elasticGPa * 1e9 * sec.section.b * sec.section.h ** 3 / 12;
|
|
21725
22063
|
const along2 = axis2 === g.gravity ? -Math.sign(away[axis2] * g.up[axis2]) : 0;
|
|
@@ -21974,8 +22312,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
21974
22312
|
const dead = p.st.load ?? p.st.mass;
|
|
21975
22313
|
const force = N * cfg.loadFactor;
|
|
21976
22314
|
let stress = 0;
|
|
21977
|
-
if (force >= 0) stress = (dead * structureSafety + force /
|
|
21978
|
-
else if (dead + force /
|
|
22315
|
+
if (force >= 0) stress = (dead * structureSafety + force / GRAVITY4) / (p.cap * capacityScale(p));
|
|
22316
|
+
else if (dead + force / GRAVITY4 < 0) {
|
|
21979
22317
|
let cap = w.tension.get(i);
|
|
21980
22318
|
if (cap === void 0) {
|
|
21981
22319
|
const r = p.spec.reinforcement;
|
|
@@ -21988,7 +22326,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
21988
22326
|
});
|
|
21989
22327
|
w.tension.set(i, cap);
|
|
21990
22328
|
}
|
|
21991
|
-
stress = Math.min(10, -(dead + force /
|
|
22329
|
+
stress = Math.min(10, -(dead + force / GRAVITY4) * GRAVITY4 / Math.max(cap * capacityScale(p), 1));
|
|
21992
22330
|
}
|
|
21993
22331
|
if (stress > (p.st.stress ?? 0)) p.st.stress = stress;
|
|
21994
22332
|
if ((p.st.stress ?? 0) > o.maxStress) o.maxStress = p.st.stress ?? 0;
|
|
@@ -22130,7 +22468,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
22130
22468
|
m += p.st.mass;
|
|
22131
22469
|
for (let k = 0; k < 3; k++) c[k] += p.st.mass * p.pos[k];
|
|
22132
22470
|
}
|
|
22133
|
-
return { w: m *
|
|
22471
|
+
return { w: m * GRAVITY4, c: m > 0 ? [c[0] / m, c[1] / m, c[2] / m] : c };
|
|
22134
22472
|
};
|
|
22135
22473
|
const initSoil = (o, profile, carried, carrySets) => {
|
|
22136
22474
|
const so = { profile, s: 0, a: 0, b: 0, imp: [0, 0], pivot: [0, 0, 0], dirty: true, sets: /* @__PURE__ */ new Map(), emitted: { t: -Infinity, s: 0, tilt: 0, status: "stable" } };
|
|
@@ -22295,7 +22633,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
22295
22633
|
if (flat < 0.5) return pieces;
|
|
22296
22634
|
const side = hashOf(p.spec.id) & 1 ? -1 : 1;
|
|
22297
22635
|
const nx = side * across[0] / flat, nz = side * across[2] / flat;
|
|
22298
|
-
const spin = Math.sqrt(3 *
|
|
22636
|
+
const spin = Math.sqrt(3 * GRAVITY4 / height);
|
|
22299
22637
|
const foot = box.min[1];
|
|
22300
22638
|
return pieces.map((f) => {
|
|
22301
22639
|
const up = Math.max(0, f.center[1] - foot);
|
|
@@ -22523,7 +22861,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
22523
22861
|
loadFactor: structureSafety,
|
|
22524
22862
|
points: over2.map(({ q }) => {
|
|
22525
22863
|
const c = aabbOf(q.spec.shape, q.pos, q.q);
|
|
22526
|
-
return { weight: (q.st.load ?? q.st.mass) *
|
|
22864
|
+
return { weight: (q.st.load ?? q.st.mass) * GRAVITY4, side: Math.min(c.max[0] - c.min[0], c.max[2] - c.min[2]) };
|
|
22527
22865
|
})
|
|
22528
22866
|
});
|
|
22529
22867
|
if (fp.share > 1 - 1 / soilCfg.safety) return { status: "unsupported", failed: [], cracks: [] };
|
|
@@ -24135,9 +24473,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
24135
24473
|
at3[p.thin] = Math.sign(lp[p.thin]) * p.dims[p.thin] / 2;
|
|
24136
24474
|
const r = vec.distance(toWorld(p.pos, p.q, at3), centre);
|
|
24137
24475
|
const side = sideOnOverpressure(tnt, r);
|
|
24138
|
-
const
|
|
24476
|
+
const reflected2 = 2 * side + 6 * side * side / (side + 7 * 101325);
|
|
24139
24477
|
const impulse = bodyImpulse(tnt, r);
|
|
24140
|
-
if (
|
|
24478
|
+
if (reflected2 > PANEL_PRESSURE && impulse > PANEL_IMPULSE && (reflected2 - PANEL_PRESSURE) * (impulse - PANEL_IMPULSE) >= PANEL_PI) loaded++;
|
|
24141
24479
|
}
|
|
24142
24480
|
if (loaded < PANEL_POINTS_LOADED) return false;
|
|
24143
24481
|
const grid = gridOf(p);
|
|
@@ -28829,6 +29167,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28829
29167
|
var UNDERMINED_KEEP = 0.6;
|
|
28830
29168
|
var SOLIDS_MAX = 64;
|
|
28831
29169
|
var UNDERMINED_PUSH = 0.6;
|
|
29170
|
+
var DEBRIS_ID = "debris#";
|
|
28832
29171
|
var UNDERMINED_STILL = 0.05;
|
|
28833
29172
|
var SOLID_WELD = 1e-4;
|
|
28834
29173
|
var UNCHECKED_KINDS = /* @__PURE__ */ new Set(["structure", "room", "ground"]);
|
|
@@ -29062,6 +29401,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29062
29401
|
/** The parts the ground went down under, drawn going down (`subside`). */
|
|
29063
29402
|
__publicField(this, "settlement");
|
|
29064
29403
|
__publicField(this, "fragments");
|
|
29404
|
+
/** Count of the bodies made for big debris: each gets an id of its own. */
|
|
29405
|
+
__publicField(this, "debrisMade", 0);
|
|
29065
29406
|
__publicField(this, "ground");
|
|
29066
29407
|
__publicField(this, "pieceSys");
|
|
29067
29408
|
__publicField(this, "cages");
|
|
@@ -29148,7 +29489,34 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29148
29489
|
// and it meets the walls, ceilings and furniture on its way: it stops on their face instead of flying into them
|
|
29149
29490
|
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
29491
|
maxAwake: o.maxAwakeFragments ?? Infinity,
|
|
29151
|
-
...o.interpolate ? { interpolate: true } : {}
|
|
29492
|
+
...o.interpolate ? { interpolate: true } : {},
|
|
29493
|
+
rigid: {
|
|
29494
|
+
add: (mesh2, half, mass, velocity, angular) => {
|
|
29495
|
+
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]]);
|
|
29496
|
+
body.debris = true;
|
|
29497
|
+
return body;
|
|
29498
|
+
},
|
|
29499
|
+
remove: (handle) => this.pieceSys.remove(handle.objectId),
|
|
29500
|
+
push: (handle, x, z) => {
|
|
29501
|
+
const body = handle;
|
|
29502
|
+
body.velocity[0] = x;
|
|
29503
|
+
body.velocity[2] = z;
|
|
29504
|
+
body.velocity[1] = Math.max(body.velocity[1], 0.3);
|
|
29505
|
+
body.sleeping = false;
|
|
29506
|
+
body.still = 0;
|
|
29507
|
+
body.calmAt = null;
|
|
29508
|
+
},
|
|
29509
|
+
shove: (handle, velocity, spin) => {
|
|
29510
|
+
const body = handle;
|
|
29511
|
+
for (let i = 0; i < 3; i++) {
|
|
29512
|
+
body.velocity[i] = body.velocity[i] + velocity[i];
|
|
29513
|
+
body.angularVelocity[i] = body.angularVelocity[i] + spin[i];
|
|
29514
|
+
}
|
|
29515
|
+
body.sleeping = false;
|
|
29516
|
+
body.still = 0;
|
|
29517
|
+
body.calmAt = null;
|
|
29518
|
+
}
|
|
29519
|
+
}
|
|
29152
29520
|
});
|
|
29153
29521
|
this.cages = new RebarCages(THREE, o.scene);
|
|
29154
29522
|
this.settledBatches = new SettledBatches(THREE, o.scene, o.settledBatches ?? { enabled: false });
|
|
@@ -29175,6 +29543,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29175
29543
|
...o.groundWorkerFrames !== void 0 ? { groundWorkerFrames: o.groundWorkerFrames } : {},
|
|
29176
29544
|
...this.blastDebris ? { keep: { maxLive: this.blastDebris.maxLivePieces, far: this.blastDebris.far, ...o.focus ? { focus: o.focus } : {}, onFade: (b) => this.fadePiece(b) } } : {},
|
|
29177
29545
|
onHardLanding: (p, point, speed) => this.hardLanding(p, point, speed),
|
|
29546
|
+
...o.onKitEnergy ? { onKitEnergy: o.onKitEnergy } : {},
|
|
29178
29547
|
sweep: (p, from, to) => this.sweepPiece(p, from, to),
|
|
29179
29548
|
onSlam: (p, hit, speed) => this.slam(p, hit, speed),
|
|
29180
29549
|
// two pieces knocked together: each sounds as its material does (a can on a can, a bottle on a table's leg)
|
|
@@ -29620,10 +29989,15 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29620
29989
|
return shape === 0 ? 1 : drawn / shape;
|
|
29621
29990
|
}
|
|
29622
29991
|
pieces() {
|
|
29623
|
-
return
|
|
29992
|
+
return this.pieceSys.list.filter((piece) => !piece.debris);
|
|
29624
29993
|
}
|
|
29625
29994
|
piece(objectId) {
|
|
29626
|
-
|
|
29995
|
+
const piece = this.pieceSys.get(objectId);
|
|
29996
|
+
return piece && !piece.debris ? piece : null;
|
|
29997
|
+
}
|
|
29998
|
+
/** What each rule of the kit that moves a piece by itself (`KIT_RULE`) gave the pieces it pushed, against their own fall (see `RendererOptions.onKitEnergy`). */
|
|
29999
|
+
kitEnergy() {
|
|
30000
|
+
return this.pieceSys.kitEnergy.tally();
|
|
29627
30001
|
}
|
|
29628
30002
|
impulse(objectId, impulse, point) {
|
|
29629
30003
|
const p = this.pieceSys.get(objectId);
|
|
@@ -29651,6 +30025,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29651
30025
|
}
|
|
29652
30026
|
/** 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
30027
|
slam(p, hit, speed) {
|
|
30028
|
+
if (p.debris) return;
|
|
29654
30029
|
const energy = 0.5 * p.mass * speed * speed;
|
|
29655
30030
|
const direction = [-hit.normal[0], -hit.normal[1], -hit.normal[2]];
|
|
29656
30031
|
this.landingSound(hit.object, hit.point, clamp6(speed / 10, 0.2, 1));
|
|
@@ -29662,6 +30037,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29662
30037
|
}
|
|
29663
30038
|
}
|
|
29664
30039
|
hardLanding(p, point, speed) {
|
|
30040
|
+
if (p.debris) return;
|
|
29665
30041
|
this.landingSound(p.objectId, point, clamp6(speed / 10, 0.2, 1));
|
|
29666
30042
|
this.syncBound(p.objectId);
|
|
29667
30043
|
try {
|
|
@@ -30270,7 +30646,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30270
30646
|
for (const [id, a] of this.staticNow()) scan(a, id, null, 6);
|
|
30271
30647
|
const c = this.v1;
|
|
30272
30648
|
for (const pc of this.pieceSys.list) {
|
|
30273
|
-
if (pc.held) continue;
|
|
30649
|
+
if (pc.held || pc.debris) continue;
|
|
30274
30650
|
this.pieceSys.centerOf(pc, c);
|
|
30275
30651
|
const reach2 = Math.hypot(pc.halfExtents[0], pc.halfExtents[1], pc.halfExtents[2]) + radius;
|
|
30276
30652
|
if (Math.abs(c.x - x) > reach2 || Math.abs(c.z - z) > reach2) continue;
|
|
@@ -31300,9 +31676,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31300
31676
|
this.setContacts(b, b.piece ?? piece, left);
|
|
31301
31677
|
const loose = b.piece;
|
|
31302
31678
|
if (away && loose) {
|
|
31303
|
-
|
|
31304
|
-
loose.angularVelocity[2] -= away.x * EDGE_NUDGE;
|
|
31305
|
-
loose.sleeping = false;
|
|
31679
|
+
this.pieceSys.ruleSpin(KIT_RULE.LOOSEN_IF_FOOTLESS, loose, away.z * EDGE_NUDGE, -away.x * EDGE_NUDGE);
|
|
31306
31680
|
} else this.tipIfTopHeavy(b);
|
|
31307
31681
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
31308
31682
|
}
|
|
@@ -31398,7 +31772,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31398
31772
|
body.sleeping = false;
|
|
31399
31773
|
body.still = 0;
|
|
31400
31774
|
body.calmAt = null;
|
|
31401
|
-
if (held.length > 0 && length > 1e-6) this.pieceSys.
|
|
31775
|
+
if (held.length > 0 && length > 1e-6) this.pieceSys.ruleImpulse(KIT_RULE.CHECK_UNDERMINED, body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + gx, floor2, centre[2] + gz]);
|
|
31402
31776
|
if (!was) this.o.onLoosened?.(b.id, body, "ground");
|
|
31403
31777
|
}
|
|
31404
31778
|
}
|
|
@@ -31415,7 +31789,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31415
31789
|
if (this.standsWith(held, null, centre, feet.floor)) return;
|
|
31416
31790
|
const inside = insideBy(convexHull2(held), [centre[0], centre[2]]);
|
|
31417
31791
|
const reach2 = this.reachAlong(body, inside.out.x, inside.out.z);
|
|
31418
|
-
this.pieceSys.
|
|
31792
|
+
this.pieceSys.ruleImpulse(KIT_RULE.GO_OVER_IF_BALANCED, body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + inside.out.x * reach2, feet.floor, centre[2] + inside.out.z * reach2]);
|
|
31419
31793
|
}
|
|
31420
31794
|
/** How far (m) the box of a piece reaches from its middle along the level direction (x, z), turned as it is: the support of its box that way. */
|
|
31421
31795
|
reachAlong(body, x, z) {
|
|
@@ -31839,7 +32213,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31839
32213
|
reach2(distance, { objectId: pc.objectId, generation: pc.generation, impulse, point }, [c.x, c.y, c.z]);
|
|
31840
32214
|
};
|
|
31841
32215
|
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);
|
|
32216
|
+
for (const pc of reached) if (!pc.debris) shove(pc);
|
|
31843
32217
|
if (this.o.shoveable) this.loosen(p, ev.radius, energy, reachOf2, policy, reach2);
|
|
31844
32218
|
this.advanceWakes(0);
|
|
31845
32219
|
this.fragments.blast(p, ev.radius, Math.min(20, Math.sqrt(energy) * 0.08));
|
|
@@ -31907,6 +32281,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31907
32281
|
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
32282
|
};
|
|
31909
32283
|
for (const pc of this.pieceSys.list) {
|
|
32284
|
+
if (pc.debris) continue;
|
|
31910
32285
|
this.pieceSys.centerOf(pc, centre);
|
|
31911
32286
|
read(pc.objectId);
|
|
31912
32287
|
}
|