@adatechnology/game-destruction-three 0.22.0 → 0.23.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 +352 -29
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +338 -29
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.global.js
CHANGED
|
@@ -40,6 +40,7 @@ var GameDestructionThree = (() => {
|
|
|
40
40
|
DESTRUCTION_SOUND_KEYS: () => DESTRUCTION_SOUND_KEYS,
|
|
41
41
|
DRAG_SOUNDS: () => DRAG_SOUNDS,
|
|
42
42
|
EXPLOSION_BOOM: () => EXPLOSION_BOOM,
|
|
43
|
+
FIRE_FADE_SECONDS: () => FIRE_FADE_SECONDS,
|
|
43
44
|
FIRE_FALLOFF: () => FIRE_FALLOFF,
|
|
44
45
|
FIRE_LOOP: () => FIRE_LOOP,
|
|
45
46
|
FIRE_SOUNDS: () => FIRE_SOUNDS,
|
|
@@ -9471,13 +9472,35 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9471
9472
|
}
|
|
9472
9473
|
return faceted(THREE, positions);
|
|
9473
9474
|
}
|
|
9475
|
+
function buildRubbleGeometry(THREE, seed) {
|
|
9476
|
+
const rnd2 = createRng(9e3 + seed);
|
|
9477
|
+
const base = new THREE.BoxGeometry(1, 1, 1, 2, 2, 2).toNonIndexed();
|
|
9478
|
+
const source = base.getAttribute("position");
|
|
9479
|
+
const moved = /* @__PURE__ */ new Map();
|
|
9480
|
+
const positions = [];
|
|
9481
|
+
for (let i = 0; i < source.count; i++) {
|
|
9482
|
+
const p = [source.getX(i), source.getY(i), source.getZ(i)];
|
|
9483
|
+
const key = p.map((x) => x.toFixed(3)).join(",");
|
|
9484
|
+
let out = moved.get(key);
|
|
9485
|
+
if (!out) {
|
|
9486
|
+
const outer = p.filter((x) => Math.abs(x) > 0.49).length;
|
|
9487
|
+
const bite = outer === 3 ? 0.08 + 0.3 * rnd2() : outer === 2 ? 0.1 * rnd2() : 0;
|
|
9488
|
+
out = p.map((x) => Math.abs(x) > 0.49 ? x - Math.sign(x) * bite * (0.4 + 0.6 * rnd2()) : x);
|
|
9489
|
+
moved.set(key, out);
|
|
9490
|
+
}
|
|
9491
|
+
positions.push(out[0], out[1], out[2]);
|
|
9492
|
+
}
|
|
9493
|
+
base.dispose();
|
|
9494
|
+
return faceted(THREE, positions);
|
|
9495
|
+
}
|
|
9474
9496
|
|
|
9475
9497
|
// src/fragments.ts
|
|
9476
9498
|
var BUILDERS = {
|
|
9477
9499
|
sliver: buildSliverGeometry,
|
|
9478
9500
|
lump: buildLumpGeometry,
|
|
9479
9501
|
veneer: buildVeneerGeometry,
|
|
9480
|
-
board: buildBrokenBoardGeometry
|
|
9502
|
+
board: buildBrokenBoardGeometry,
|
|
9503
|
+
rubble: buildRubbleGeometry
|
|
9481
9504
|
};
|
|
9482
9505
|
var SHEET_MAX = 4e-3;
|
|
9483
9506
|
var SHEET_AIR = 2.5;
|
|
@@ -9586,6 +9609,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9586
9609
|
if (f.shape === "chunk" && form === "granules") return this.sharedGeometry("lump", seed);
|
|
9587
9610
|
if (f.shape === "scrap" && form === "plies") return this.sharedGeometry("veneer", seed);
|
|
9588
9611
|
if (f.shape === "slab" && (form === "slivers" || form === "plies")) return this.sharedGeometry("board", seed);
|
|
9612
|
+
if (f.shape === "chunk" && this.o.crumbles?.(f.material)) return this.sharedGeometry("rubble", seed);
|
|
9589
9613
|
return this.box;
|
|
9590
9614
|
}
|
|
9591
9615
|
markParts() {
|
|
@@ -9594,18 +9618,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9594
9618
|
return { geometry: this.markGeometry, material: this.markMaterial };
|
|
9595
9619
|
}
|
|
9596
9620
|
/**
|
|
9597
|
-
* Meshes, never put in a scene by this class, that draw every shared piece of a fragment once: the box, the six shards, the wood splinters, MDF lumps
|
|
9621
|
+
* Meshes, never put in a scene by this class, that draw every shared piece of a fragment once: the box, the six shards, the wood splinters, MDF lumps, plywood veneer, broken masonry, the bullet-hole disc, and the opaque and
|
|
9598
9622
|
* glass materials. A host draws them at load so the first blast does not upload these buffers in the middle of a frame.
|
|
9599
9623
|
*/
|
|
9600
9624
|
warmMeshes() {
|
|
9601
9625
|
const opaque = this.materialFor("warm", 8421504, false);
|
|
9602
9626
|
const glass2 = this.materialFor("warm", 8421504, true);
|
|
9603
9627
|
const geometries = [this.box, ...Array.from({ length: SHARD_SHAPES }, (_, index) => this.shardGeometry(index))];
|
|
9604
|
-
const
|
|
9628
|
+
const shaped = ["sliver", "lump", "veneer", "board", "rubble"].flatMap((shape) => Array.from({ length: FRAGMENT_SHAPE_VARIANTS }, (_, index) => this.sharedGeometry(shape, index)));
|
|
9605
9629
|
const { geometry, material } = this.markParts();
|
|
9606
9630
|
return [
|
|
9607
9631
|
...geometries.flatMap((shared) => [new this.THREE.Mesh(shared, opaque), new this.THREE.Mesh(shared, glass2)]),
|
|
9608
|
-
...
|
|
9632
|
+
...shaped.map((shared) => new this.THREE.Mesh(shared, opaque)),
|
|
9609
9633
|
new this.THREE.Mesh(geometry, material)
|
|
9610
9634
|
];
|
|
9611
9635
|
}
|
|
@@ -10367,16 +10391,29 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
10367
10391
|
}
|
|
10368
10392
|
}
|
|
10369
10393
|
update(dt) {
|
|
10370
|
-
const steps = this.collisionSteps(dt);
|
|
10371
|
-
|
|
10394
|
+
const { steps, near } = this.collisionSteps(dt);
|
|
10395
|
+
if (steps === 1) {
|
|
10396
|
+
this.time += dt;
|
|
10397
|
+
this.step(dt);
|
|
10398
|
+
return;
|
|
10399
|
+
}
|
|
10400
|
+
const start = this.time;
|
|
10401
|
+
this.time = start + dt;
|
|
10402
|
+
const far = (b) => !near.has(b);
|
|
10403
|
+
this.step(dt, { moves: far, meets: (a, b) => far(a) && far(b) });
|
|
10404
|
+
for (let i = 0; i < steps; i++) {
|
|
10405
|
+
this.time = start + dt * (i + 1) / steps;
|
|
10406
|
+
this.step(dt / steps, { moves: (b) => near.has(b), meets: (a, b) => near.has(a) || near.has(b) });
|
|
10407
|
+
}
|
|
10372
10408
|
}
|
|
10373
10409
|
/**
|
|
10374
10410
|
* Steps of an update: one, or more while a round piece and a piece it could meet within the update close in fast enough to pass through each other between two (closing at
|
|
10375
10411
|
* their two speeds they cover at most the round one's radius per step: two cans at 3.6 m/s close 12 cm in a frame, a can is 7 cm across; a plank thrown at a can still counts).
|
|
10376
|
-
* A round piece with nothing in reach takes one step, so its sweep against the world (the costly part) runs once.
|
|
10412
|
+
* A round piece with nothing in reach takes one step, so its sweep against the world (the costly part) runs once; `near` holds the pieces of the pairs that need more.
|
|
10377
10413
|
*/
|
|
10378
10414
|
collisionSteps(dt) {
|
|
10379
10415
|
let need = 1;
|
|
10416
|
+
const near = /* @__PURE__ */ new Set();
|
|
10380
10417
|
const p = this.p;
|
|
10381
10418
|
const speedOf = (b) => b.held ? 0 : Math.hypot(b.velocity[0], b.velocity[1], b.velocity[2]);
|
|
10382
10419
|
for (const b of this.list) {
|
|
@@ -10393,13 +10430,17 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
10393
10430
|
const reach = closing * dt + rb + Math.hypot(o.halfExtents[0], o.halfExtents[1], o.halfExtents[2]);
|
|
10394
10431
|
const oc = this.centerOf(o, p);
|
|
10395
10432
|
if (Math.abs(oc.x - cx) > reach || Math.abs(oc.y - cy) > reach || Math.abs(oc.z - cz) > reach) continue;
|
|
10396
|
-
|
|
10433
|
+
const pair = Math.ceil(closing * dt / radius);
|
|
10434
|
+
if (pair < 2) continue;
|
|
10435
|
+
need = Math.max(need, pair);
|
|
10436
|
+
near.add(b);
|
|
10437
|
+
near.add(o);
|
|
10397
10438
|
}
|
|
10398
10439
|
}
|
|
10399
|
-
return Math.max(1, Math.min(MAX_COLLISION_STEPS, need));
|
|
10440
|
+
return { steps: Math.max(1, Math.min(MAX_COLLISION_STEPS, need)), near };
|
|
10400
10441
|
}
|
|
10401
|
-
step(
|
|
10402
|
-
|
|
10442
|
+
/** A step of `dt`: the pieces `only.moves` takes move (all when absent) and the pairs `only.meets` takes meet, so each pair meets in one of the steps of an update. */
|
|
10443
|
+
step(dt, only) {
|
|
10403
10444
|
this.solids = this.list.map((body) => {
|
|
10404
10445
|
const c = this.centerOf(body, new this.THREE.Vector3());
|
|
10405
10446
|
const h = body.halfExtents;
|
|
@@ -10460,14 +10501,14 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
10460
10501
|
b.calmAt = null;
|
|
10461
10502
|
continue;
|
|
10462
10503
|
}
|
|
10463
|
-
if (b.sleeping) continue;
|
|
10504
|
+
if (b.sleeping || only && !only.moves(b)) continue;
|
|
10464
10505
|
this.integrate(b, dt);
|
|
10465
10506
|
if (b.sleeping) continue;
|
|
10466
10507
|
const v = b.velocity;
|
|
10467
10508
|
const w = b.angularVelocity;
|
|
10468
10509
|
if (Math.hypot(v[0], v[1], v[2]) > WAKE_ABOVE_SPEED || Math.hypot(w[0], w[1], w[2]) > WAKE_ABOVE_SPIN) this.wakeAbove(b);
|
|
10469
10510
|
}
|
|
10470
|
-
this.collide(dt);
|
|
10511
|
+
this.collide(dt, only?.meets);
|
|
10471
10512
|
}
|
|
10472
10513
|
/** A few sleeping pieces each update (`SUPPORT_CHECKS`, in turn) look under them again: one whose table broke, or whose shelf fell over, falls. */
|
|
10473
10514
|
wakeUnsupported() {
|
|
@@ -10969,7 +11010,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
10969
11010
|
* Pieces against each other. Candidates by sweep and prune along x on their bounding spheres (sorted once per step: fifty cans cost a sort and a handful of pairs, not
|
|
10970
11011
|
* 1225); a pair with a round piece in it meets by its shapes (`shapeContact`) and exchanges an impulse, two boxes are only pushed apart (`separatePair`).
|
|
10971
11012
|
*/
|
|
10972
|
-
collide(dt) {
|
|
11013
|
+
collide(dt, meets) {
|
|
10973
11014
|
const n = this.list.length;
|
|
10974
11015
|
if (n < 2) return;
|
|
10975
11016
|
const centers = this.list.map((b) => {
|
|
@@ -10987,6 +11028,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
10987
11028
|
const a = this.list[i];
|
|
10988
11029
|
const b = this.list[j];
|
|
10989
11030
|
if ((a.held || a.sleeping) && (b.held || b.sleeping)) continue;
|
|
11031
|
+
if (meets && !meets(a, b)) continue;
|
|
10990
11032
|
const r = radii[i] + radii[j];
|
|
10991
11033
|
const ca = centers[i];
|
|
10992
11034
|
const cb = centers[j];
|
|
@@ -11371,10 +11413,24 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
11371
11413
|
maxSettlement: 0.05,
|
|
11372
11414
|
crackDistortion: 1 / 300,
|
|
11373
11415
|
damageDistortion: 1 / 150,
|
|
11416
|
+
bearingCrackDistortion: 1 / 500,
|
|
11417
|
+
bearingDamageDistortion: 1 / 300,
|
|
11374
11418
|
distortionDamage: 0.3,
|
|
11375
11419
|
bridgeSpanDepth: 10,
|
|
11376
11420
|
beamRebarRatio: 4e-3
|
|
11377
11421
|
};
|
|
11422
|
+
var clampNumber = (v, a, b) => Math.max(a, Math.min(b, v));
|
|
11423
|
+
var settlementAt = (settlement, point) => {
|
|
11424
|
+
const d = [settlement.to[0] - settlement.from[0], settlement.to[1] - settlement.from[1], settlement.to[2] - settlement.from[2]];
|
|
11425
|
+
const length2 = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
|
|
11426
|
+
const t = length2 > 0 ? clampNumber(((point[0] - settlement.from[0]) * d[0] + (point[1] - settlement.from[1]) * d[1] + (point[2] - settlement.from[2]) * d[2]) / length2, 0, 1) : 0;
|
|
11427
|
+
const drops = settlement.drop;
|
|
11428
|
+
if (drops.length === 0) return 0;
|
|
11429
|
+
const at3 = t * (drops.length - 1);
|
|
11430
|
+
const i = Math.floor(at3);
|
|
11431
|
+
const j = Math.min(drops.length - 1, i + 1);
|
|
11432
|
+
return drops[i] + (drops[j] - drops[i]) * (at3 - i);
|
|
11433
|
+
};
|
|
11378
11434
|
var WIND_DEFAULTS = {
|
|
11379
11435
|
speed: 40,
|
|
11380
11436
|
direction: [1, 0, 0],
|
|
@@ -12725,6 +12781,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
12725
12781
|
};
|
|
12726
12782
|
var RESTING_HOLD_COS = Math.cos(Math.PI / 6);
|
|
12727
12783
|
var BLAST_REFERENCE_RESISTANCE = 200 * 1900 * 0.13;
|
|
12784
|
+
var ARCH_ANGLE = Math.PI / 3;
|
|
12728
12785
|
var assemblies_default = [
|
|
12729
12786
|
{
|
|
12730
12787
|
id: "brick_wall_plastered",
|
|
@@ -13062,6 +13119,47 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13062
13119
|
return Math.sqrt(nearest) * nearestScale;
|
|
13063
13120
|
}
|
|
13064
13121
|
|
|
13122
|
+
// src/stair-crack.ts
|
|
13123
|
+
function stairCrackPath(spec) {
|
|
13124
|
+
const rnd2 = createRng(spec.seed);
|
|
13125
|
+
const run = Math.max(0.02, spec.step[0] / 2);
|
|
13126
|
+
const rise = Math.max(0.02, spec.step[1]);
|
|
13127
|
+
const points = [[0, 0]];
|
|
13128
|
+
let h = 0;
|
|
13129
|
+
let u = 0;
|
|
13130
|
+
let walked = 0;
|
|
13131
|
+
while (walked < spec.length) {
|
|
13132
|
+
const along2 = run * (rnd2() < 0.2 ? 2 : 1);
|
|
13133
|
+
h += along2;
|
|
13134
|
+
points.push([h, u]);
|
|
13135
|
+
u += rise;
|
|
13136
|
+
points.push([h, u]);
|
|
13137
|
+
walked += along2 + rise;
|
|
13138
|
+
}
|
|
13139
|
+
return points;
|
|
13140
|
+
}
|
|
13141
|
+
function stairCrackStrip(points, width, taper) {
|
|
13142
|
+
const out = [];
|
|
13143
|
+
const n = points.length - 1;
|
|
13144
|
+
for (let k = 0; k < n; k++) {
|
|
13145
|
+
const [h0, u0] = points[k];
|
|
13146
|
+
const [h1, u1] = points[k + 1];
|
|
13147
|
+
const length = Math.hypot(h1 - h0, u1 - u0) || 1;
|
|
13148
|
+
const half0 = width * (1 - (1 - taper) * k / n) / 2;
|
|
13149
|
+
const half1 = width * (1 - (1 - taper) * (k + 1) / n) / 2;
|
|
13150
|
+
const sh = -(u1 - u0) / length;
|
|
13151
|
+
const su = (h1 - h0) / length;
|
|
13152
|
+
const eh = (h1 - h0) / length * half0;
|
|
13153
|
+
const eu = (u1 - u0) / length * half0;
|
|
13154
|
+
const a = [h0 - eh - sh * half0, u0 - eu - su * half0];
|
|
13155
|
+
const b = [h1 + eh - sh * half1, u1 + eu - su * half1];
|
|
13156
|
+
const c = [h1 + eh + sh * half1, u1 + eu + su * half1];
|
|
13157
|
+
const d = [h0 - eh + sh * half0, u0 - eu + su * half0];
|
|
13158
|
+
out.push(...a, ...b, ...c, ...a, ...c, ...d);
|
|
13159
|
+
}
|
|
13160
|
+
return out;
|
|
13161
|
+
}
|
|
13162
|
+
|
|
13065
13163
|
// src/visual.ts
|
|
13066
13164
|
var POS_ATTR = "position";
|
|
13067
13165
|
function positionAttr(geo) {
|
|
@@ -13166,6 +13264,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13166
13264
|
}
|
|
13167
13265
|
};
|
|
13168
13266
|
var DECAL_SNAP = 0.03;
|
|
13267
|
+
var STAIR_CRACK_LIFT = 2e-3;
|
|
13268
|
+
var STAIR_CRACK_TAPER = 0.35;
|
|
13169
13269
|
var Visuals = class {
|
|
13170
13270
|
constructor(THREE, lowQuality, decalCap) {
|
|
13171
13271
|
__publicField(this, "THREE", THREE);
|
|
@@ -13659,6 +13759,71 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13659
13759
|
lines.renderOrder = 2;
|
|
13660
13760
|
this.addDecal(mv, { obj: lines, geometry: geo });
|
|
13661
13761
|
}
|
|
13762
|
+
/**
|
|
13763
|
+
* A stair-step crack through the joints of a wall (settlement): from `worldPoint` on the face whose outward normal is `worldNormal`, climbing toward
|
|
13764
|
+
* `worldToward` (the side that went down) one unit at a time, `width` metres wide at its start. A strip of triangles in the mesh's space, owned by the
|
|
13765
|
+
* part's marks: it goes with them (cleared, restored, disposed).
|
|
13766
|
+
*/
|
|
13767
|
+
addStairCrack(mv, worldPoint, worldNormal, worldToward, spec) {
|
|
13768
|
+
const mesh2 = mv.mesh;
|
|
13769
|
+
mesh2.updateWorldMatrix(true, false);
|
|
13770
|
+
const n = worldNormal.clone().normalize();
|
|
13771
|
+
const up = new this.THREE.Vector3(0, 1, 0).addScaledVector(n, -n.y).normalize();
|
|
13772
|
+
const side = worldToward.clone().addScaledVector(n, -worldToward.dot(n)).addScaledVector(up, -worldToward.dot(up));
|
|
13773
|
+
if (side.lengthSq() < 1e-8) side.crossVectors(up, n);
|
|
13774
|
+
side.normalize();
|
|
13775
|
+
const start = this.onFace(mesh2, worldPoint, n).clone().addScaledVector(n, STAIR_CRACK_LIFT);
|
|
13776
|
+
const flat = stairCrackStrip(stairCrackPath({ length: spec.length, step: spec.step, seed: spec.seed }), spec.width, STAIR_CRACK_TAPER);
|
|
13777
|
+
const flip = new this.THREE.Vector3().crossVectors(side, up).dot(n) < 0;
|
|
13778
|
+
const verts = [];
|
|
13779
|
+
const point = this.a;
|
|
13780
|
+
for (let i = 0; i < flat.length; i += 6) {
|
|
13781
|
+
const order = flip ? [0, 2, 1] : [0, 1, 2];
|
|
13782
|
+
for (const k of order) {
|
|
13783
|
+
point.copy(start).addScaledVector(side, flat[i + k * 2]).addScaledVector(up, flat[i + k * 2 + 1]);
|
|
13784
|
+
mesh2.worldToLocal(point);
|
|
13785
|
+
verts.push(point.x, point.y, point.z);
|
|
13786
|
+
}
|
|
13787
|
+
}
|
|
13788
|
+
const geo = new this.THREE.BufferGeometry();
|
|
13789
|
+
geo.setAttribute("position", new this.THREE.Float32BufferAttribute(verts, 3));
|
|
13790
|
+
const strip = new this.THREE.Mesh(geo, this.kit.patchMaterial(spec.color));
|
|
13791
|
+
strip.renderOrder = 2;
|
|
13792
|
+
this.addDecal(mv, { obj: strip, geometry: geo });
|
|
13793
|
+
}
|
|
13794
|
+
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
13795
|
+
// Settlement
|
|
13796
|
+
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
13797
|
+
/**
|
|
13798
|
+
* Moves the part's vertices and its marks down by `dropAt(world point)` metres (negative: up), where each of them is: a part that settled more at
|
|
13799
|
+
* one end tilts. Writes the geometry unless `write` is false (several parts of one merged mesh are then written once by `commit`).
|
|
13800
|
+
*/
|
|
13801
|
+
sink(mv, dropAt, write = true) {
|
|
13802
|
+
if (!this.ownGeometry(mv)) return false;
|
|
13803
|
+
const mesh2 = mv.mesh;
|
|
13804
|
+
mesh2.updateWorldMatrix(true, false);
|
|
13805
|
+
const scale = mesh2.matrixWorld.getMaxScaleOnAxis() || 1;
|
|
13806
|
+
const down = this.b.set(0, -1, 0).transformDirection(this.m4.copy(mesh2.matrixWorld).invert());
|
|
13807
|
+
const work = mv.host ? mv.host.work : mv.work;
|
|
13808
|
+
const from = mv.range ? mv.range[0] * 3 : 0;
|
|
13809
|
+
const to = mv.range ? mv.range[1] * 3 : work.length;
|
|
13810
|
+
const point = this.a;
|
|
13811
|
+
for (let i = from; i < to; i += 3) {
|
|
13812
|
+
const d = dropAt(point.set(work[i], work[i + 1], work[i + 2]).applyMatrix4(mesh2.matrixWorld)) / scale;
|
|
13813
|
+
work[i] += down.x * d;
|
|
13814
|
+
work[i + 1] += down.y * d;
|
|
13815
|
+
work[i + 2] += down.z * d;
|
|
13816
|
+
}
|
|
13817
|
+
for (const decal2 of mv.decals) decal2.obj.position.addScaledVector(down, dropAt(decal2.obj.getWorldPosition(point)) / scale);
|
|
13818
|
+
mv.touched = true;
|
|
13819
|
+
if (write) this.commit(mv);
|
|
13820
|
+
return true;
|
|
13821
|
+
}
|
|
13822
|
+
/** Writes what `sink` moved into the geometry. */
|
|
13823
|
+
commit(mv) {
|
|
13824
|
+
const pos = positionAttr(mv.mesh.geometry);
|
|
13825
|
+
if (pos) this.writePositions(mv, pos);
|
|
13826
|
+
}
|
|
13662
13827
|
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
13663
13828
|
// Char and heat glow
|
|
13664
13829
|
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
@@ -14054,6 +14219,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14054
14219
|
}
|
|
14055
14220
|
restorePart(pv) {
|
|
14056
14221
|
for (const mv of pv.meshes) this.restoreMesh(mv);
|
|
14222
|
+
delete pv.settled;
|
|
14057
14223
|
pv.charApplied = 0;
|
|
14058
14224
|
pv.glowApplied = 0;
|
|
14059
14225
|
pv.meltApplied = 0;
|
|
@@ -14064,6 +14230,77 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14064
14230
|
}
|
|
14065
14231
|
};
|
|
14066
14232
|
|
|
14233
|
+
// src/settlement.ts
|
|
14234
|
+
var SETTLE_SECONDS = 1.2;
|
|
14235
|
+
var SETTLE_REDRAW = 0.1;
|
|
14236
|
+
var dropOf = (line, point) => line ? settlementAt(line, point) : 0;
|
|
14237
|
+
var sameLine = (a, b) => !!a && a.drop.length === b.drop.length && a.drop.every((v, k) => v === b.drop[k]) && a.from.every((v, k) => v === b.from[k]) && a.to.every((v, k) => v === b.to[k]);
|
|
14238
|
+
var SettlementView = class {
|
|
14239
|
+
constructor(THREE, visuals) {
|
|
14240
|
+
__publicField(this, "visuals", visuals);
|
|
14241
|
+
__publicField(this, "moving", /* @__PURE__ */ new Map());
|
|
14242
|
+
__publicField(this, "local");
|
|
14243
|
+
__publicField(this, "inverse");
|
|
14244
|
+
this.local = new THREE.Vector3();
|
|
14245
|
+
this.inverse = new THREE.Matrix4();
|
|
14246
|
+
}
|
|
14247
|
+
/** The parts of an object (`root` draws it in object space) and their settlement now: those that changed start going to it. */
|
|
14248
|
+
follow(root, parts) {
|
|
14249
|
+
for (const [pv, target] of parts) {
|
|
14250
|
+
if (!target || pv.gone !== "none" || sameLine(this.moving.get(pv)?.target ?? pv.settled, target)) continue;
|
|
14251
|
+
this.finish(pv);
|
|
14252
|
+
this.moving.set(pv, { pv, root, start: pv.settled, target, shown: 0, elapsed: 0, lastDrawn: -SETTLE_REDRAW });
|
|
14253
|
+
}
|
|
14254
|
+
}
|
|
14255
|
+
get count() {
|
|
14256
|
+
return this.moving.size;
|
|
14257
|
+
}
|
|
14258
|
+
update(dt) {
|
|
14259
|
+
for (const s of this.moving.values()) {
|
|
14260
|
+
s.elapsed += dt;
|
|
14261
|
+
const done = s.elapsed >= SETTLE_SECONDS;
|
|
14262
|
+
if (!done && s.elapsed - s.lastDrawn < SETTLE_REDRAW) continue;
|
|
14263
|
+
s.lastDrawn = s.elapsed;
|
|
14264
|
+
const t = Math.min(1, s.elapsed / SETTLE_SECONDS);
|
|
14265
|
+
this.draw(s, t * t * (3 - 2 * t));
|
|
14266
|
+
if (done) {
|
|
14267
|
+
s.pv.settled = s.target;
|
|
14268
|
+
this.moving.delete(s.pv);
|
|
14269
|
+
}
|
|
14270
|
+
}
|
|
14271
|
+
}
|
|
14272
|
+
/** Draws the rest of a part's settlement at once (it is about to be split off or put back). */
|
|
14273
|
+
finish(pv) {
|
|
14274
|
+
const s = this.moving.get(pv);
|
|
14275
|
+
if (!s) return;
|
|
14276
|
+
this.draw(s, 1);
|
|
14277
|
+
pv.settled = s.target;
|
|
14278
|
+
this.moving.delete(pv);
|
|
14279
|
+
}
|
|
14280
|
+
/** Forget a part without drawing (it was put back as it was). */
|
|
14281
|
+
forget(pv) {
|
|
14282
|
+
this.moving.delete(pv);
|
|
14283
|
+
}
|
|
14284
|
+
clear() {
|
|
14285
|
+
this.moving.clear();
|
|
14286
|
+
}
|
|
14287
|
+
draw(s, shown) {
|
|
14288
|
+
const share = shown - s.shown;
|
|
14289
|
+
if (share <= 0) return;
|
|
14290
|
+
s.shown = shown;
|
|
14291
|
+
s.root.updateWorldMatrix(true, false);
|
|
14292
|
+
this.inverse.copy(s.root.matrixWorld).invert();
|
|
14293
|
+
const dropAt = (world) => {
|
|
14294
|
+
const p = this.local.copy(world).applyMatrix4(this.inverse);
|
|
14295
|
+
const at3 = [p.x, p.y, p.z];
|
|
14296
|
+
return (dropOf(s.target, at3) - dropOf(s.start, at3)) * share;
|
|
14297
|
+
};
|
|
14298
|
+
const writes = /* @__PURE__ */ new Map();
|
|
14299
|
+
for (const mv of s.pv.meshes) if (this.visuals.sink(mv, dropAt, false)) writes.set(mv.host ?? mv, mv);
|
|
14300
|
+
for (const mv of writes.values()) this.visuals.commit(mv);
|
|
14301
|
+
}
|
|
14302
|
+
};
|
|
14303
|
+
|
|
14067
14304
|
// src/renderer.ts
|
|
14068
14305
|
var rendererCount = 0;
|
|
14069
14306
|
var COLLAPSE_CLOUD_KG = 1e3;
|
|
@@ -14073,6 +14310,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14073
14310
|
var WOOD_RIM = 1.5;
|
|
14074
14311
|
var IMPACT_TAGS = ["metal", "glass", "wood"];
|
|
14075
14312
|
var GLOW_FROM_C = 430;
|
|
14313
|
+
var MIN_DRAWN_CRACK_WIDTH = 4e-3;
|
|
14314
|
+
var SETTLEMENT_CRACK_COLOR = 2827296;
|
|
14076
14315
|
var QUEUE_CAP = 4e3;
|
|
14077
14316
|
var TRICKLE_SECONDS = [2, 5];
|
|
14078
14317
|
var TRICKLE_EVERY = 0.25;
|
|
@@ -14292,6 +14531,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14292
14531
|
});
|
|
14293
14532
|
__publicField(this, "unsubscribe");
|
|
14294
14533
|
__publicField(this, "visuals");
|
|
14534
|
+
/** The parts the ground went down under, drawn going down (`subside`). */
|
|
14535
|
+
__publicField(this, "settlement");
|
|
14295
14536
|
__publicField(this, "fragments");
|
|
14296
14537
|
__publicField(this, "ground");
|
|
14297
14538
|
__publicField(this, "pieceSys");
|
|
@@ -14300,6 +14541,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14300
14541
|
__publicField(this, "fires", /* @__PURE__ */ new Map());
|
|
14301
14542
|
/** Primed parts burning in the effects world until they go off: their burn loop ends when they are put out. */
|
|
14302
14543
|
__publicField(this, "primedBurning", /* @__PURE__ */ new Set());
|
|
14544
|
+
/** The burn loops asked of the host and not yet ended, by part: whatever stops a part's fire ends its loop, once, with what it started with. */
|
|
14545
|
+
__publicField(this, "burnSounds", /* @__PURE__ */ new Map());
|
|
14303
14546
|
__publicField(this, "leaks", []);
|
|
14304
14547
|
__publicField(this, "homeTags", []);
|
|
14305
14548
|
__publicField(this, "throttles", /* @__PURE__ */ new Map());
|
|
@@ -14334,6 +14577,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14334
14577
|
this.v2 = new THREE.Vector3();
|
|
14335
14578
|
const maxParticles = Math.max(8, Math.floor((o.maxParticles ?? 2500) * (this.low ? 0.5 : 1)));
|
|
14336
14579
|
this.visuals = new Visuals(THREE, this.low, 600);
|
|
14580
|
+
this.settlement = new SettlementView(THREE, this.visuals);
|
|
14337
14581
|
this.ground = new GroundSpots(THREE, o.scene, this.groundAt, 48);
|
|
14338
14582
|
if (!o.vfx) warnOnce("game-destruction-three.own-effects-world", "game-destruction-three made an effects world of its own because the host lent none (options.vfx); pass the host effects so the effects share one budget");
|
|
14339
14583
|
this.vfx = o.vfx ?? createVfx({ profile: this.quality, gravity: this.gravity, groundAt: this.groundAt, sprites: { capacity: maxParticles, density: this.low ? 0.6 : 1 } });
|
|
@@ -14348,7 +14592,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14348
14592
|
gravity: this.gravity,
|
|
14349
14593
|
max: this.maxFragments,
|
|
14350
14594
|
life: o.fragmentLife ?? 12,
|
|
14351
|
-
formOf: (id) => this.world.materials.get(id)?.splitForm
|
|
14595
|
+
formOf: (id) => this.world.materials.get(id)?.splitForm,
|
|
14596
|
+
crumbles: (id) => this.world.materials.get(id)?.fracture === "crumble"
|
|
14352
14597
|
});
|
|
14353
14598
|
this.cages = new RebarCages(THREE, o.scene);
|
|
14354
14599
|
this.pieceSys = new PieceSystem(THREE, {
|
|
@@ -14743,6 +14988,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14743
14988
|
this.checkBroken();
|
|
14744
14989
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
14745
14990
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
14991
|
+
this.settlement.update(dt);
|
|
14746
14992
|
this.updateActive(dt);
|
|
14747
14993
|
this.updateLeaks(dt);
|
|
14748
14994
|
this.updateTrickles(dt);
|
|
@@ -14818,6 +15064,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14818
15064
|
node.quaternion.set(q[0], q[1], q[2], q[3]);
|
|
14819
15065
|
node.updateMatrixWorld(true);
|
|
14820
15066
|
}
|
|
15067
|
+
/** The ground went down under some parts of an object: each part with a settlement (`PartState.settlement`) starts going down to it. */
|
|
15068
|
+
onSubside(objectId) {
|
|
15069
|
+
const b = this.bounds.get(objectId);
|
|
15070
|
+
const state = this.world.state(objectId);
|
|
15071
|
+
if (!b || !state) return;
|
|
15072
|
+
const parts = [];
|
|
15073
|
+
for (const ps of state.parts) {
|
|
15074
|
+
const pv = b.parts.get(ps.id);
|
|
15075
|
+
if (pv && ps.settlement) parts.push([pv, ps.settlement]);
|
|
15076
|
+
}
|
|
15077
|
+
this.settlement.follow(b.soilNode ?? b.root, parts);
|
|
15078
|
+
}
|
|
14821
15079
|
syncTransforms() {
|
|
14822
15080
|
for (const b of this.bounds.values()) this.syncOne(b);
|
|
14823
15081
|
}
|
|
@@ -14968,9 +15226,15 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14968
15226
|
case "debris":
|
|
14969
15227
|
this.vfx.burst(ev.kind, ev.point, ev.normal, ev.count, ev.speed > 0 ? ev.speed : DEFAULT_SPEED[ev.kind] ?? 1, this.debrisOptions(ev.kind, ev.object, ev.part, ev.material));
|
|
14970
15228
|
break;
|
|
14971
|
-
case "fracture":
|
|
15229
|
+
case "fracture": {
|
|
15230
|
+
const pv = this.partVis(ev.object, ev.part);
|
|
15231
|
+
if (pv) this.settlement.forget(pv);
|
|
14972
15232
|
this.onFracture(ev);
|
|
14973
15233
|
break;
|
|
15234
|
+
}
|
|
15235
|
+
case "subside":
|
|
15236
|
+
this.onSubside(ev.object);
|
|
15237
|
+
break;
|
|
14974
15238
|
case "detach":
|
|
14975
15239
|
this.onDetach(ev);
|
|
14976
15240
|
break;
|
|
@@ -14980,6 +15244,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14980
15244
|
case "collapse": {
|
|
14981
15245
|
const root = this.bounds.get(ev.object)?.root;
|
|
14982
15246
|
const furniture = !!root && kitOriginOf(root)?.kind === "furniture";
|
|
15247
|
+
for (const part of ev.parts) {
|
|
15248
|
+
const pv = this.partVis(ev.object, part);
|
|
15249
|
+
if (pv) this.settlement.finish(pv);
|
|
15250
|
+
}
|
|
14983
15251
|
this.splitLoose(ev.object);
|
|
14984
15252
|
if (!furniture || ev.mass >= COLLAPSE_CLOUD_KG) this.playEvent({ kind: "collapse" }, this.rootPoint(ev.object));
|
|
14985
15253
|
else this.vfx.burst("dust", this.rootPoint(ev.object), [0, 1, 0], clamp6(Math.round(ev.mass / 4), 4, 24), 0.8);
|
|
@@ -14997,7 +15265,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14997
15265
|
this.startFire(ev);
|
|
14998
15266
|
this.activate(ev.object, ev.part);
|
|
14999
15267
|
this.sound("ignite", ev.point, 0.7);
|
|
15000
|
-
this.
|
|
15268
|
+
this.startBurnSound(ev.object, ev.part, ev.point, this.burning(ev.object, ev.part));
|
|
15001
15269
|
break;
|
|
15002
15270
|
case "primed":
|
|
15003
15271
|
if (ev.trigger !== "explosion") {
|
|
@@ -15005,7 +15273,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15005
15273
|
this.primedBurning.add(`${ev.object}|${ev.part}`);
|
|
15006
15274
|
this.activate(ev.object, ev.part);
|
|
15007
15275
|
this.sound("primed", ev.point, 0.7, { seconds: ev.delay });
|
|
15008
|
-
this.
|
|
15276
|
+
if (!this.burnSounds.has(`${ev.object}|${ev.part}`)) this.startBurnSound(ev.object, ev.part, ev.point, { fuel: "gas" });
|
|
15009
15277
|
}
|
|
15010
15278
|
break;
|
|
15011
15279
|
case "spall":
|
|
@@ -15027,20 +15295,20 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15027
15295
|
break;
|
|
15028
15296
|
case "extinguish": {
|
|
15029
15297
|
const f = this.fires.get(`${ev.object}|${ev.part}`);
|
|
15030
|
-
|
|
15298
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15031
15299
|
if (f) {
|
|
15032
15300
|
this.stopFire(`${ev.object}|${ev.part}`);
|
|
15033
15301
|
this.vfx.burst("steam", f.point, [0, 1, 0], 14, 1.2);
|
|
15034
15302
|
}
|
|
15035
|
-
|
|
15303
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15036
15304
|
this.activate(ev.object, ev.part);
|
|
15037
15305
|
this.sound("extinguish", f?.point ?? this.rootPoint(ev.object), 0.6);
|
|
15038
15306
|
break;
|
|
15039
15307
|
}
|
|
15040
15308
|
case "burnout": {
|
|
15041
15309
|
this.stopFire(`${ev.object}|${ev.part}`);
|
|
15042
|
-
|
|
15043
|
-
this.
|
|
15310
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15311
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15044
15312
|
this.vfx.burst("ash", ev.point, [0, 1, 0], 16, 1);
|
|
15045
15313
|
this.vfx.burst("smoke", ev.point, [0, 1, 0], 6, 0.8, { color: SMOKE_TONES.grey });
|
|
15046
15314
|
const pv = this.partVis(ev.object, ev.part);
|
|
@@ -15108,7 +15376,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15108
15376
|
break;
|
|
15109
15377
|
}
|
|
15110
15378
|
case "explode":
|
|
15111
|
-
|
|
15379
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15380
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15112
15381
|
this.onExplode(ev);
|
|
15113
15382
|
break;
|
|
15114
15383
|
case "destroyed":
|
|
@@ -15227,7 +15496,20 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15227
15496
|
const pv = b?.parts.get(ev.part);
|
|
15228
15497
|
if (!b || !pv) return;
|
|
15229
15498
|
const def = this.world.materials.get(pv.material);
|
|
15230
|
-
|
|
15499
|
+
const stair = ev.crack.stair;
|
|
15500
|
+
if (stair && !def?.visual?.transparent) {
|
|
15501
|
+
const wp = new this.THREE.Vector3(ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
15502
|
+
const seed = hashNumbers(ev.time, ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
15503
|
+
const width = Math.max(stair.width, MIN_DRAWN_CRACK_WIDTH);
|
|
15504
|
+
const normal = this.worldDir(b, ev.crack.normal);
|
|
15505
|
+
const toward2 = this.worldDir(b, stair.along);
|
|
15506
|
+
const look = { length: ev.crack.length, step: stair.step, width, color: SETTLEMENT_CRACK_COLOR, seed };
|
|
15507
|
+
for (const face of [wp, wp.clone().addScaledVector(normal, -stair.through)]) {
|
|
15508
|
+
const out = face === wp ? normal : normal.clone().negate();
|
|
15509
|
+
const mv = this.nearestMesh(pv, face);
|
|
15510
|
+
if (mv) this.visuals.addStairCrack(mv, face, out, toward2, look);
|
|
15511
|
+
}
|
|
15512
|
+
} else if (def?.visual?.transparent) {
|
|
15231
15513
|
const wp = new this.THREE.Vector3(ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
15232
15514
|
const mv = this.nearestMesh(pv, wp);
|
|
15233
15515
|
const seed = hashNumbers(ev.time, ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
@@ -15797,9 +16079,25 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15797
16079
|
}
|
|
15798
16080
|
stopFire(key) {
|
|
15799
16081
|
const fire2 = this.fires.get(key);
|
|
15800
|
-
if (
|
|
15801
|
-
|
|
15802
|
-
|
|
16082
|
+
if (fire2) {
|
|
16083
|
+
if (fire2.handle !== void 0) this.vfx.stop(fire2.handle);
|
|
16084
|
+
this.fires.delete(key);
|
|
16085
|
+
}
|
|
16086
|
+
this.endBurnSound(key);
|
|
16087
|
+
}
|
|
16088
|
+
/** A part's fire loop starts; one already running for the part (it caught again) is ended first, so the host never counts a fire twice. */
|
|
16089
|
+
startBurnSound(object, part, point, detail) {
|
|
16090
|
+
const key = `${object}|${part}`;
|
|
16091
|
+
this.endBurnSound(key);
|
|
16092
|
+
this.burnSounds.set(key, { object, point, detail });
|
|
16093
|
+
this.sound("burn_loop", point, 0.5, detail);
|
|
16094
|
+
}
|
|
16095
|
+
/** The part's fire loop ends, with the point and the fuel it started with; nothing when it has none running. */
|
|
16096
|
+
endBurnSound(key) {
|
|
16097
|
+
const started = this.burnSounds.get(key);
|
|
16098
|
+
if (!started) return;
|
|
16099
|
+
this.burnSounds.delete(key);
|
|
16100
|
+
this.sound("burn_end", started.point, 0.5, started.detail);
|
|
15803
16101
|
}
|
|
15804
16102
|
// ----------------------------------------------------------------------------------------------------------------------------------
|
|
15805
16103
|
// Fire, heat, char, melt, leaks
|
|
@@ -15825,6 +16123,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15825
16123
|
const ps = pv ? this.world.part(a.object, a.part) : null;
|
|
15826
16124
|
if (!pv || !ps) {
|
|
15827
16125
|
this.active.delete(key);
|
|
16126
|
+
this.stopFire(key);
|
|
15828
16127
|
continue;
|
|
15829
16128
|
}
|
|
15830
16129
|
const def = this.world.materials.get(pv.material);
|
|
@@ -15944,6 +16243,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15944
16243
|
for (const home of homes) this.restoreHome(home);
|
|
15945
16244
|
for (const [key, a] of [...this.active]) if (homes.has(a.object)) this.active.delete(key);
|
|
15946
16245
|
for (const [key, f] of [...this.fires]) if (homes.has(f.object)) this.stopFire(key);
|
|
16246
|
+
for (const [key, started] of [...this.burnSounds]) if (homes.has(started.object)) this.endBurnSound(key);
|
|
15947
16247
|
for (let i = this.leaks.length - 1; i >= 0; i--) if (homes.has(this.leaks[i].object)) this.leaks.splice(i, 1);
|
|
15948
16248
|
for (const home of homes) {
|
|
15949
16249
|
this.fragments.removeHome(home);
|
|
@@ -15956,6 +16256,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15956
16256
|
for (const b of [...this.bounds.values()]) {
|
|
15957
16257
|
for (const [pid, pv] of [...b.parts]) {
|
|
15958
16258
|
if (pv.home !== home) continue;
|
|
16259
|
+
this.settlement.forget(pv);
|
|
15959
16260
|
this.visuals.restorePart(pv);
|
|
15960
16261
|
this.tagPart(pv, home);
|
|
15961
16262
|
if (b !== homeBound && homeBound) {
|
|
@@ -15977,8 +16278,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15977
16278
|
this.slices.length = 0;
|
|
15978
16279
|
this.active.clear();
|
|
15979
16280
|
for (const key of [...this.fires.keys()]) this.stopFire(key);
|
|
16281
|
+
for (const key of [...this.burnSounds.keys()]) this.endBurnSound(key);
|
|
15980
16282
|
this.leaks.length = 0;
|
|
15981
16283
|
this.trickles.length = 0;
|
|
16284
|
+
this.settlement.clear();
|
|
15982
16285
|
for (const id of [...this.bounds.keys()]) if (this.bounds.has(id)) this.restore(id);
|
|
15983
16286
|
for (const b of [...this.bounds.values()]) {
|
|
15984
16287
|
if (b.isSplit) {
|
|
@@ -18167,6 +18470,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18167
18470
|
}
|
|
18168
18471
|
};
|
|
18169
18472
|
var DEFAULT_FIRE = { perFire: 0.08, max: 0.45 };
|
|
18473
|
+
var FIRE_FADE_SECONDS = 0.4;
|
|
18170
18474
|
var DEFAULT_CRACKLES = { base: 2, perSqrtFire: 3, max: 14, volume: 0.5 };
|
|
18171
18475
|
var DEFAULT_INDOOR_CONFINEMENT = 1.3;
|
|
18172
18476
|
function createDestructionSound(engine, options = {}) {
|
|
@@ -18188,6 +18492,11 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18188
18492
|
const loops = /* @__PURE__ */ new Map();
|
|
18189
18493
|
const fires = [];
|
|
18190
18494
|
let nextCrackle = 0;
|
|
18495
|
+
const fading = [];
|
|
18496
|
+
const fadeOut = (handle) => {
|
|
18497
|
+
handle.set({ volume: 0 });
|
|
18498
|
+
fading.push({ handle, left: FIRE_FADE_SECONDS });
|
|
18499
|
+
};
|
|
18191
18500
|
const fuelFor = (detail) => detail?.fuel ?? (detail?.material !== void 0 ? fuelOf[detail.material] : void 0) ?? defaultFuel;
|
|
18192
18501
|
const setFire = () => {
|
|
18193
18502
|
if (options.burnLoop === false) return;
|
|
@@ -18198,7 +18507,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18198
18507
|
}
|
|
18199
18508
|
for (const [id, handle] of loops) {
|
|
18200
18509
|
if (count.has(id)) continue;
|
|
18201
|
-
handle
|
|
18510
|
+
fadeOut(handle);
|
|
18202
18511
|
loops.delete(id);
|
|
18203
18512
|
}
|
|
18204
18513
|
for (const [id, n] of count) {
|
|
@@ -18225,8 +18534,15 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18225
18534
|
else if (best >= 0) fires.splice(best, 1);
|
|
18226
18535
|
};
|
|
18227
18536
|
const reset = () => {
|
|
18537
|
+
for (const handle of loops.values()) fadeOut(handle);
|
|
18538
|
+
loops.clear();
|
|
18539
|
+
fires.length = 0;
|
|
18540
|
+
};
|
|
18541
|
+
const dispose = () => {
|
|
18228
18542
|
for (const handle of loops.values()) handle.stop();
|
|
18229
18543
|
loops.clear();
|
|
18544
|
+
for (const { handle } of fading) handle.stop();
|
|
18545
|
+
fading.length = 0;
|
|
18230
18546
|
fires.length = 0;
|
|
18231
18547
|
};
|
|
18232
18548
|
const blastSound = (point, volume, detail) => {
|
|
@@ -18273,6 +18589,13 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18273
18589
|
engine.play(sound, { position: point, volume: volume * (rule.volumeScale ?? 1), intensity: Math.min(1, Math.max(0, volume)), ...params ? { params } : {} });
|
|
18274
18590
|
},
|
|
18275
18591
|
update(dt) {
|
|
18592
|
+
for (let i = fading.length - 1; i >= 0; i--) {
|
|
18593
|
+
const entry = fading[i];
|
|
18594
|
+
entry.left -= dt;
|
|
18595
|
+
if (entry.left > 0) continue;
|
|
18596
|
+
entry.handle.stop();
|
|
18597
|
+
fading.splice(i, 1);
|
|
18598
|
+
}
|
|
18276
18599
|
if (!crackles || fires.length === 0 || options.burnLoop === false) return;
|
|
18277
18600
|
const weight = fires.reduce((sum, f) => sum + FIRE_CRACKLE_OF[f.fuel], 0);
|
|
18278
18601
|
if (weight <= 0) return;
|
|
@@ -18298,7 +18621,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18298
18621
|
return by;
|
|
18299
18622
|
},
|
|
18300
18623
|
reset,
|
|
18301
|
-
dispose
|
|
18624
|
+
dispose
|
|
18302
18625
|
};
|
|
18303
18626
|
}
|
|
18304
18627
|
|