@adatechnology/game-destruction-three 0.22.1 → 0.23.1
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 +359 -23
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +345 -23
- 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,14 +9472,37 @@ 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
|
};
|
|
9505
|
+
var FLOOR_REMEASURE = 0.5;
|
|
9482
9506
|
var SHEET_MAX = 4e-3;
|
|
9483
9507
|
var SHEET_AIR = 2.5;
|
|
9484
9508
|
var SHEET_SWAY = 3;
|
|
@@ -9586,6 +9610,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9586
9610
|
if (f.shape === "chunk" && form === "granules") return this.sharedGeometry("lump", seed);
|
|
9587
9611
|
if (f.shape === "scrap" && form === "plies") return this.sharedGeometry("veneer", seed);
|
|
9588
9612
|
if (f.shape === "slab" && (form === "slivers" || form === "plies")) return this.sharedGeometry("board", seed);
|
|
9613
|
+
if (f.shape === "chunk" && this.o.crumbles?.(f.material)) return this.sharedGeometry("rubble", seed);
|
|
9589
9614
|
return this.box;
|
|
9590
9615
|
}
|
|
9591
9616
|
markParts() {
|
|
@@ -9594,18 +9619,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9594
9619
|
return { geometry: this.markGeometry, material: this.markMaterial };
|
|
9595
9620
|
}
|
|
9596
9621
|
/**
|
|
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
|
|
9622
|
+
* 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
9623
|
* glass materials. A host draws them at load so the first blast does not upload these buffers in the middle of a frame.
|
|
9599
9624
|
*/
|
|
9600
9625
|
warmMeshes() {
|
|
9601
9626
|
const opaque = this.materialFor("warm", 8421504, false);
|
|
9602
9627
|
const glass2 = this.materialFor("warm", 8421504, true);
|
|
9603
9628
|
const geometries = [this.box, ...Array.from({ length: SHARD_SHAPES }, (_, index) => this.shardGeometry(index))];
|
|
9604
|
-
const
|
|
9629
|
+
const shaped = ["sliver", "lump", "veneer", "board", "rubble"].flatMap((shape) => Array.from({ length: FRAGMENT_SHAPE_VARIANTS }, (_, index) => this.sharedGeometry(shape, index)));
|
|
9605
9630
|
const { geometry, material } = this.markParts();
|
|
9606
9631
|
return [
|
|
9607
9632
|
...geometries.flatMap((shared) => [new this.THREE.Mesh(shared, opaque), new this.THREE.Mesh(shared, glass2)]),
|
|
9608
|
-
...
|
|
9633
|
+
...shaped.map((shared) => new this.THREE.Mesh(shared, opaque)),
|
|
9609
9634
|
new this.THREE.Mesh(geometry, material)
|
|
9610
9635
|
];
|
|
9611
9636
|
}
|
|
@@ -9667,6 +9692,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9667
9692
|
this.o.scene.add(mesh2);
|
|
9668
9693
|
const live = {
|
|
9669
9694
|
mesh: mesh2,
|
|
9695
|
+
floor: null,
|
|
9670
9696
|
home,
|
|
9671
9697
|
vel: new this.THREE.Vector3(f.velocity[0], f.velocity[1], f.velocity[2]),
|
|
9672
9698
|
ang: new this.THREE.Vector3(f.angularVelocity[0], f.angularVelocity[1], f.angularVelocity[2]),
|
|
@@ -9683,7 +9709,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9683
9709
|
born: this.tick,
|
|
9684
9710
|
life: lasting ? 0 : Math.max(0, typeof this.o.life === "function" ? this.o.life(f, home) : this.o.life)
|
|
9685
9711
|
};
|
|
9686
|
-
if (lasting ||
|
|
9712
|
+
if (lasting || isBig(f.size)) {
|
|
9687
9713
|
live.body = {
|
|
9688
9714
|
mass: f.mass,
|
|
9689
9715
|
push: (x, z) => {
|
|
@@ -9777,8 +9803,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9777
9803
|
if (!f.asleep || f.dying) continue;
|
|
9778
9804
|
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
9779
9805
|
const ext = Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z;
|
|
9780
|
-
if (f.mesh.position.y - ext > this.
|
|
9806
|
+
if (f.mesh.position.y - ext > this.floorUnder(f) + SUPPORT_GAP) this.rouse(f);
|
|
9807
|
+
}
|
|
9808
|
+
}
|
|
9809
|
+
/** What a fragment lands on: measured where it is, and again only once it moved `FLOOR_REMEASURE` m off that spot (a ray down is not free). */
|
|
9810
|
+
floorUnder(f) {
|
|
9811
|
+
const p = f.mesh.position;
|
|
9812
|
+
if (!this.o.surfaceAt) return this.o.groundAt(p.x, p.z);
|
|
9813
|
+
const at3 = f.floor;
|
|
9814
|
+
if (!at3 || Math.abs(at3.x - p.x) > FLOOR_REMEASURE || Math.abs(at3.z - p.z) > FLOOR_REMEASURE || p.y < at3.y - FLOOR_REMEASURE) {
|
|
9815
|
+
f.floor = { x: p.x, z: p.z, y: this.o.surfaceAt(p.x, p.y, p.z) };
|
|
9781
9816
|
}
|
|
9817
|
+
return f.floor.y;
|
|
9782
9818
|
}
|
|
9783
9819
|
step(f, dt, g) {
|
|
9784
9820
|
const mesh2 = f.mesh;
|
|
@@ -9794,7 +9830,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9794
9830
|
const h = f.half;
|
|
9795
9831
|
const sc = f.dying ? f.fade : 1;
|
|
9796
9832
|
const ext = (Math.abs(e[1]) * h.x + Math.abs(e[5]) * h.y + Math.abs(e[9]) * h.z) * sc;
|
|
9797
|
-
const gy = this.
|
|
9833
|
+
const gy = this.floorUnder(f);
|
|
9798
9834
|
let contact = false;
|
|
9799
9835
|
if (mesh2.position.y - ext < gy) {
|
|
9800
9836
|
contact = true;
|
|
@@ -11389,10 +11425,24 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
11389
11425
|
maxSettlement: 0.05,
|
|
11390
11426
|
crackDistortion: 1 / 300,
|
|
11391
11427
|
damageDistortion: 1 / 150,
|
|
11428
|
+
bearingCrackDistortion: 1 / 500,
|
|
11429
|
+
bearingDamageDistortion: 1 / 300,
|
|
11392
11430
|
distortionDamage: 0.3,
|
|
11393
11431
|
bridgeSpanDepth: 10,
|
|
11394
11432
|
beamRebarRatio: 4e-3
|
|
11395
11433
|
};
|
|
11434
|
+
var clampNumber = (v, a, b) => Math.max(a, Math.min(b, v));
|
|
11435
|
+
var settlementAt = (settlement, point) => {
|
|
11436
|
+
const d = [settlement.to[0] - settlement.from[0], settlement.to[1] - settlement.from[1], settlement.to[2] - settlement.from[2]];
|
|
11437
|
+
const length2 = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
|
|
11438
|
+
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;
|
|
11439
|
+
const drops = settlement.drop;
|
|
11440
|
+
if (drops.length === 0) return 0;
|
|
11441
|
+
const at3 = t * (drops.length - 1);
|
|
11442
|
+
const i = Math.floor(at3);
|
|
11443
|
+
const j = Math.min(drops.length - 1, i + 1);
|
|
11444
|
+
return drops[i] + (drops[j] - drops[i]) * (at3 - i);
|
|
11445
|
+
};
|
|
11396
11446
|
var WIND_DEFAULTS = {
|
|
11397
11447
|
speed: 40,
|
|
11398
11448
|
direction: [1, 0, 0],
|
|
@@ -12743,6 +12793,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
12743
12793
|
};
|
|
12744
12794
|
var RESTING_HOLD_COS = Math.cos(Math.PI / 6);
|
|
12745
12795
|
var BLAST_REFERENCE_RESISTANCE = 200 * 1900 * 0.13;
|
|
12796
|
+
var ARCH_ANGLE = Math.PI / 3;
|
|
12746
12797
|
var assemblies_default = [
|
|
12747
12798
|
{
|
|
12748
12799
|
id: "brick_wall_plastered",
|
|
@@ -13080,6 +13131,47 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13080
13131
|
return Math.sqrt(nearest) * nearestScale;
|
|
13081
13132
|
}
|
|
13082
13133
|
|
|
13134
|
+
// src/stair-crack.ts
|
|
13135
|
+
function stairCrackPath(spec) {
|
|
13136
|
+
const rnd2 = createRng(spec.seed);
|
|
13137
|
+
const run = Math.max(0.02, spec.step[0] / 2);
|
|
13138
|
+
const rise = Math.max(0.02, spec.step[1]);
|
|
13139
|
+
const points = [[0, 0]];
|
|
13140
|
+
let h = 0;
|
|
13141
|
+
let u = 0;
|
|
13142
|
+
let walked = 0;
|
|
13143
|
+
while (walked < spec.length) {
|
|
13144
|
+
const along2 = run * (rnd2() < 0.2 ? 2 : 1);
|
|
13145
|
+
h += along2;
|
|
13146
|
+
points.push([h, u]);
|
|
13147
|
+
u += rise;
|
|
13148
|
+
points.push([h, u]);
|
|
13149
|
+
walked += along2 + rise;
|
|
13150
|
+
}
|
|
13151
|
+
return points;
|
|
13152
|
+
}
|
|
13153
|
+
function stairCrackStrip(points, width, taper) {
|
|
13154
|
+
const out = [];
|
|
13155
|
+
const n = points.length - 1;
|
|
13156
|
+
for (let k = 0; k < n; k++) {
|
|
13157
|
+
const [h0, u0] = points[k];
|
|
13158
|
+
const [h1, u1] = points[k + 1];
|
|
13159
|
+
const length = Math.hypot(h1 - h0, u1 - u0) || 1;
|
|
13160
|
+
const half0 = width * (1 - (1 - taper) * k / n) / 2;
|
|
13161
|
+
const half1 = width * (1 - (1 - taper) * (k + 1) / n) / 2;
|
|
13162
|
+
const sh = -(u1 - u0) / length;
|
|
13163
|
+
const su = (h1 - h0) / length;
|
|
13164
|
+
const eh = (h1 - h0) / length * half0;
|
|
13165
|
+
const eu = (u1 - u0) / length * half0;
|
|
13166
|
+
const a = [h0 - eh - sh * half0, u0 - eu - su * half0];
|
|
13167
|
+
const b = [h1 + eh - sh * half1, u1 + eu - su * half1];
|
|
13168
|
+
const c = [h1 + eh + sh * half1, u1 + eu + su * half1];
|
|
13169
|
+
const d = [h0 - eh + sh * half0, u0 - eu + su * half0];
|
|
13170
|
+
out.push(...a, ...b, ...c, ...a, ...c, ...d);
|
|
13171
|
+
}
|
|
13172
|
+
return out;
|
|
13173
|
+
}
|
|
13174
|
+
|
|
13083
13175
|
// src/visual.ts
|
|
13084
13176
|
var POS_ATTR = "position";
|
|
13085
13177
|
function positionAttr(geo) {
|
|
@@ -13184,6 +13276,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13184
13276
|
}
|
|
13185
13277
|
};
|
|
13186
13278
|
var DECAL_SNAP = 0.03;
|
|
13279
|
+
var STAIR_CRACK_LIFT = 2e-3;
|
|
13280
|
+
var STAIR_CRACK_TAPER = 0.35;
|
|
13187
13281
|
var Visuals = class {
|
|
13188
13282
|
constructor(THREE, lowQuality, decalCap) {
|
|
13189
13283
|
__publicField(this, "THREE", THREE);
|
|
@@ -13677,6 +13771,71 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13677
13771
|
lines.renderOrder = 2;
|
|
13678
13772
|
this.addDecal(mv, { obj: lines, geometry: geo });
|
|
13679
13773
|
}
|
|
13774
|
+
/**
|
|
13775
|
+
* A stair-step crack through the joints of a wall (settlement): from `worldPoint` on the face whose outward normal is `worldNormal`, climbing toward
|
|
13776
|
+
* `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
|
|
13777
|
+
* part's marks: it goes with them (cleared, restored, disposed).
|
|
13778
|
+
*/
|
|
13779
|
+
addStairCrack(mv, worldPoint, worldNormal, worldToward, spec) {
|
|
13780
|
+
const mesh2 = mv.mesh;
|
|
13781
|
+
mesh2.updateWorldMatrix(true, false);
|
|
13782
|
+
const n = worldNormal.clone().normalize();
|
|
13783
|
+
const up = new this.THREE.Vector3(0, 1, 0).addScaledVector(n, -n.y).normalize();
|
|
13784
|
+
const side = worldToward.clone().addScaledVector(n, -worldToward.dot(n)).addScaledVector(up, -worldToward.dot(up));
|
|
13785
|
+
if (side.lengthSq() < 1e-8) side.crossVectors(up, n);
|
|
13786
|
+
side.normalize();
|
|
13787
|
+
const start = this.onFace(mesh2, worldPoint, n).clone().addScaledVector(n, STAIR_CRACK_LIFT);
|
|
13788
|
+
const flat = stairCrackStrip(stairCrackPath({ length: spec.length, step: spec.step, seed: spec.seed }), spec.width, STAIR_CRACK_TAPER);
|
|
13789
|
+
const flip = new this.THREE.Vector3().crossVectors(side, up).dot(n) < 0;
|
|
13790
|
+
const verts = [];
|
|
13791
|
+
const point = this.a;
|
|
13792
|
+
for (let i = 0; i < flat.length; i += 6) {
|
|
13793
|
+
const order = flip ? [0, 2, 1] : [0, 1, 2];
|
|
13794
|
+
for (const k of order) {
|
|
13795
|
+
point.copy(start).addScaledVector(side, flat[i + k * 2]).addScaledVector(up, flat[i + k * 2 + 1]);
|
|
13796
|
+
mesh2.worldToLocal(point);
|
|
13797
|
+
verts.push(point.x, point.y, point.z);
|
|
13798
|
+
}
|
|
13799
|
+
}
|
|
13800
|
+
const geo = new this.THREE.BufferGeometry();
|
|
13801
|
+
geo.setAttribute("position", new this.THREE.Float32BufferAttribute(verts, 3));
|
|
13802
|
+
const strip = new this.THREE.Mesh(geo, this.kit.patchMaterial(spec.color));
|
|
13803
|
+
strip.renderOrder = 2;
|
|
13804
|
+
this.addDecal(mv, { obj: strip, geometry: geo });
|
|
13805
|
+
}
|
|
13806
|
+
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
13807
|
+
// Settlement
|
|
13808
|
+
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
13809
|
+
/**
|
|
13810
|
+
* 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
|
|
13811
|
+
* one end tilts. Writes the geometry unless `write` is false (several parts of one merged mesh are then written once by `commit`).
|
|
13812
|
+
*/
|
|
13813
|
+
sink(mv, dropAt, write = true) {
|
|
13814
|
+
if (!this.ownGeometry(mv)) return false;
|
|
13815
|
+
const mesh2 = mv.mesh;
|
|
13816
|
+
mesh2.updateWorldMatrix(true, false);
|
|
13817
|
+
const scale = mesh2.matrixWorld.getMaxScaleOnAxis() || 1;
|
|
13818
|
+
const down = this.b.set(0, -1, 0).transformDirection(this.m4.copy(mesh2.matrixWorld).invert());
|
|
13819
|
+
const work = mv.host ? mv.host.work : mv.work;
|
|
13820
|
+
const from = mv.range ? mv.range[0] * 3 : 0;
|
|
13821
|
+
const to = mv.range ? mv.range[1] * 3 : work.length;
|
|
13822
|
+
const point = this.a;
|
|
13823
|
+
for (let i = from; i < to; i += 3) {
|
|
13824
|
+
const d = dropAt(point.set(work[i], work[i + 1], work[i + 2]).applyMatrix4(mesh2.matrixWorld)) / scale;
|
|
13825
|
+
work[i] += down.x * d;
|
|
13826
|
+
work[i + 1] += down.y * d;
|
|
13827
|
+
work[i + 2] += down.z * d;
|
|
13828
|
+
}
|
|
13829
|
+
for (const decal2 of mv.decals) decal2.obj.position.addScaledVector(down, dropAt(decal2.obj.getWorldPosition(point)) / scale);
|
|
13830
|
+
mv.touched = true;
|
|
13831
|
+
if (write) this.commit(mv);
|
|
13832
|
+
return true;
|
|
13833
|
+
}
|
|
13834
|
+
/** Writes what `sink` moved into the geometry. */
|
|
13835
|
+
commit(mv) {
|
|
13836
|
+
const pos = positionAttr(mv.mesh.geometry);
|
|
13837
|
+
if (pos) this.writePositions(mv, pos);
|
|
13838
|
+
}
|
|
13680
13839
|
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
13681
13840
|
// Char and heat glow
|
|
13682
13841
|
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
@@ -14072,6 +14231,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14072
14231
|
}
|
|
14073
14232
|
restorePart(pv) {
|
|
14074
14233
|
for (const mv of pv.meshes) this.restoreMesh(mv);
|
|
14234
|
+
delete pv.settled;
|
|
14075
14235
|
pv.charApplied = 0;
|
|
14076
14236
|
pv.glowApplied = 0;
|
|
14077
14237
|
pv.meltApplied = 0;
|
|
@@ -14082,6 +14242,77 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14082
14242
|
}
|
|
14083
14243
|
};
|
|
14084
14244
|
|
|
14245
|
+
// src/settlement.ts
|
|
14246
|
+
var SETTLE_SECONDS = 1.2;
|
|
14247
|
+
var SETTLE_REDRAW = 0.1;
|
|
14248
|
+
var dropOf = (line, point) => line ? settlementAt(line, point) : 0;
|
|
14249
|
+
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]);
|
|
14250
|
+
var SettlementView = class {
|
|
14251
|
+
constructor(THREE, visuals) {
|
|
14252
|
+
__publicField(this, "visuals", visuals);
|
|
14253
|
+
__publicField(this, "moving", /* @__PURE__ */ new Map());
|
|
14254
|
+
__publicField(this, "local");
|
|
14255
|
+
__publicField(this, "inverse");
|
|
14256
|
+
this.local = new THREE.Vector3();
|
|
14257
|
+
this.inverse = new THREE.Matrix4();
|
|
14258
|
+
}
|
|
14259
|
+
/** The parts of an object (`root` draws it in object space) and their settlement now: those that changed start going to it. */
|
|
14260
|
+
follow(root, parts) {
|
|
14261
|
+
for (const [pv, target] of parts) {
|
|
14262
|
+
if (!target || pv.gone !== "none" || sameLine(this.moving.get(pv)?.target ?? pv.settled, target)) continue;
|
|
14263
|
+
this.finish(pv);
|
|
14264
|
+
this.moving.set(pv, { pv, root, start: pv.settled, target, shown: 0, elapsed: 0, lastDrawn: -SETTLE_REDRAW });
|
|
14265
|
+
}
|
|
14266
|
+
}
|
|
14267
|
+
get count() {
|
|
14268
|
+
return this.moving.size;
|
|
14269
|
+
}
|
|
14270
|
+
update(dt) {
|
|
14271
|
+
for (const s of this.moving.values()) {
|
|
14272
|
+
s.elapsed += dt;
|
|
14273
|
+
const done = s.elapsed >= SETTLE_SECONDS;
|
|
14274
|
+
if (!done && s.elapsed - s.lastDrawn < SETTLE_REDRAW) continue;
|
|
14275
|
+
s.lastDrawn = s.elapsed;
|
|
14276
|
+
const t = Math.min(1, s.elapsed / SETTLE_SECONDS);
|
|
14277
|
+
this.draw(s, t * t * (3 - 2 * t));
|
|
14278
|
+
if (done) {
|
|
14279
|
+
s.pv.settled = s.target;
|
|
14280
|
+
this.moving.delete(s.pv);
|
|
14281
|
+
}
|
|
14282
|
+
}
|
|
14283
|
+
}
|
|
14284
|
+
/** Draws the rest of a part's settlement at once (it is about to be split off or put back). */
|
|
14285
|
+
finish(pv) {
|
|
14286
|
+
const s = this.moving.get(pv);
|
|
14287
|
+
if (!s) return;
|
|
14288
|
+
this.draw(s, 1);
|
|
14289
|
+
pv.settled = s.target;
|
|
14290
|
+
this.moving.delete(pv);
|
|
14291
|
+
}
|
|
14292
|
+
/** Forget a part without drawing (it was put back as it was). */
|
|
14293
|
+
forget(pv) {
|
|
14294
|
+
this.moving.delete(pv);
|
|
14295
|
+
}
|
|
14296
|
+
clear() {
|
|
14297
|
+
this.moving.clear();
|
|
14298
|
+
}
|
|
14299
|
+
draw(s, shown) {
|
|
14300
|
+
const share = shown - s.shown;
|
|
14301
|
+
if (share <= 0) return;
|
|
14302
|
+
s.shown = shown;
|
|
14303
|
+
s.root.updateWorldMatrix(true, false);
|
|
14304
|
+
this.inverse.copy(s.root.matrixWorld).invert();
|
|
14305
|
+
const dropAt = (world) => {
|
|
14306
|
+
const p = this.local.copy(world).applyMatrix4(this.inverse);
|
|
14307
|
+
const at3 = [p.x, p.y, p.z];
|
|
14308
|
+
return (dropOf(s.target, at3) - dropOf(s.start, at3)) * share;
|
|
14309
|
+
};
|
|
14310
|
+
const writes = /* @__PURE__ */ new Map();
|
|
14311
|
+
for (const mv of s.pv.meshes) if (this.visuals.sink(mv, dropAt, false)) writes.set(mv.host ?? mv, mv);
|
|
14312
|
+
for (const mv of writes.values()) this.visuals.commit(mv);
|
|
14313
|
+
}
|
|
14314
|
+
};
|
|
14315
|
+
|
|
14085
14316
|
// src/renderer.ts
|
|
14086
14317
|
var rendererCount = 0;
|
|
14087
14318
|
var COLLAPSE_CLOUD_KG = 1e3;
|
|
@@ -14091,6 +14322,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14091
14322
|
var WOOD_RIM = 1.5;
|
|
14092
14323
|
var IMPACT_TAGS = ["metal", "glass", "wood"];
|
|
14093
14324
|
var GLOW_FROM_C = 430;
|
|
14325
|
+
var MIN_DRAWN_CRACK_WIDTH = 4e-3;
|
|
14326
|
+
var SETTLEMENT_CRACK_COLOR = 2827296;
|
|
14094
14327
|
var QUEUE_CAP = 4e3;
|
|
14095
14328
|
var TRICKLE_SECONDS = [2, 5];
|
|
14096
14329
|
var TRICKLE_EVERY = 0.25;
|
|
@@ -14114,6 +14347,9 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14114
14347
|
var MIN_FRAGMENTS_PER_SLICE = 8;
|
|
14115
14348
|
var STATIC_REFRESH = 0.5;
|
|
14116
14349
|
var STATIC_REFRESH_SLICE_MS = 1;
|
|
14350
|
+
var SURFACE_RAYS = 4;
|
|
14351
|
+
var SURFACE_INSIDE = 5e-3;
|
|
14352
|
+
var SURFACE_STEP = 0.15;
|
|
14117
14353
|
var STATIC_SPAN = 3;
|
|
14118
14354
|
var FEET_BAND = 0.03;
|
|
14119
14355
|
var TIP_MIN_HEIGHT = 0.3;
|
|
@@ -14310,6 +14546,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14310
14546
|
});
|
|
14311
14547
|
__publicField(this, "unsubscribe");
|
|
14312
14548
|
__publicField(this, "visuals");
|
|
14549
|
+
/** The parts the ground went down under, drawn going down (`subside`). */
|
|
14550
|
+
__publicField(this, "settlement");
|
|
14313
14551
|
__publicField(this, "fragments");
|
|
14314
14552
|
__publicField(this, "ground");
|
|
14315
14553
|
__publicField(this, "pieceSys");
|
|
@@ -14318,6 +14556,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14318
14556
|
__publicField(this, "fires", /* @__PURE__ */ new Map());
|
|
14319
14557
|
/** Primed parts burning in the effects world until they go off: their burn loop ends when they are put out. */
|
|
14320
14558
|
__publicField(this, "primedBurning", /* @__PURE__ */ new Set());
|
|
14559
|
+
/** 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. */
|
|
14560
|
+
__publicField(this, "burnSounds", /* @__PURE__ */ new Map());
|
|
14321
14561
|
__publicField(this, "leaks", []);
|
|
14322
14562
|
__publicField(this, "homeTags", []);
|
|
14323
14563
|
__publicField(this, "throttles", /* @__PURE__ */ new Map());
|
|
@@ -14352,6 +14592,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14352
14592
|
this.v2 = new THREE.Vector3();
|
|
14353
14593
|
const maxParticles = Math.max(8, Math.floor((o.maxParticles ?? 2500) * (this.low ? 0.5 : 1)));
|
|
14354
14594
|
this.visuals = new Visuals(THREE, this.low, 600);
|
|
14595
|
+
this.settlement = new SettlementView(THREE, this.visuals);
|
|
14355
14596
|
this.ground = new GroundSpots(THREE, o.scene, this.groundAt, 48);
|
|
14356
14597
|
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");
|
|
14357
14598
|
this.vfx = o.vfx ?? createVfx({ profile: this.quality, gravity: this.gravity, groundAt: this.groundAt, sprites: { capacity: maxParticles, density: this.low ? 0.6 : 1 } });
|
|
@@ -14366,7 +14607,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14366
14607
|
gravity: this.gravity,
|
|
14367
14608
|
max: this.maxFragments,
|
|
14368
14609
|
life: o.fragmentLife ?? 12,
|
|
14369
|
-
formOf: (id) => this.world.materials.get(id)?.splitForm
|
|
14610
|
+
formOf: (id) => this.world.materials.get(id)?.splitForm,
|
|
14611
|
+
crumbles: (id) => this.world.materials.get(id)?.fracture === "crumble",
|
|
14612
|
+
// rubble lands on what is still built (a slab, a wall's top, a floor), not only on the terrain under it
|
|
14613
|
+
surfaceAt: (x, y, z) => this.surfaceAt(x, y, z)
|
|
14370
14614
|
});
|
|
14371
14615
|
this.cages = new RebarCages(THREE, o.scene);
|
|
14372
14616
|
this.pieceSys = new PieceSystem(THREE, {
|
|
@@ -14761,6 +15005,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14761
15005
|
this.checkBroken();
|
|
14762
15006
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
14763
15007
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
15008
|
+
this.settlement.update(dt);
|
|
14764
15009
|
this.updateActive(dt);
|
|
14765
15010
|
this.updateLeaks(dt);
|
|
14766
15011
|
this.updateTrickles(dt);
|
|
@@ -14836,6 +15081,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14836
15081
|
node.quaternion.set(q[0], q[1], q[2], q[3]);
|
|
14837
15082
|
node.updateMatrixWorld(true);
|
|
14838
15083
|
}
|
|
15084
|
+
/** The ground went down under some parts of an object: each part with a settlement (`PartState.settlement`) starts going down to it. */
|
|
15085
|
+
onSubside(objectId) {
|
|
15086
|
+
const b = this.bounds.get(objectId);
|
|
15087
|
+
const state = this.world.state(objectId);
|
|
15088
|
+
if (!b || !state) return;
|
|
15089
|
+
const parts = [];
|
|
15090
|
+
for (const ps of state.parts) {
|
|
15091
|
+
const pv = b.parts.get(ps.id);
|
|
15092
|
+
if (pv && ps.settlement) parts.push([pv, ps.settlement]);
|
|
15093
|
+
}
|
|
15094
|
+
this.settlement.follow(b.soilNode ?? b.root, parts);
|
|
15095
|
+
}
|
|
14839
15096
|
syncTransforms() {
|
|
14840
15097
|
for (const b of this.bounds.values()) this.syncOne(b);
|
|
14841
15098
|
}
|
|
@@ -14986,9 +15243,15 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14986
15243
|
case "debris":
|
|
14987
15244
|
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));
|
|
14988
15245
|
break;
|
|
14989
|
-
case "fracture":
|
|
15246
|
+
case "fracture": {
|
|
15247
|
+
const pv = this.partVis(ev.object, ev.part);
|
|
15248
|
+
if (pv) this.settlement.forget(pv);
|
|
14990
15249
|
this.onFracture(ev);
|
|
14991
15250
|
break;
|
|
15251
|
+
}
|
|
15252
|
+
case "subside":
|
|
15253
|
+
this.onSubside(ev.object);
|
|
15254
|
+
break;
|
|
14992
15255
|
case "detach":
|
|
14993
15256
|
this.onDetach(ev);
|
|
14994
15257
|
break;
|
|
@@ -14998,6 +15261,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14998
15261
|
case "collapse": {
|
|
14999
15262
|
const root = this.bounds.get(ev.object)?.root;
|
|
15000
15263
|
const furniture = !!root && kitOriginOf(root)?.kind === "furniture";
|
|
15264
|
+
for (const part of ev.parts) {
|
|
15265
|
+
const pv = this.partVis(ev.object, part);
|
|
15266
|
+
if (pv) this.settlement.finish(pv);
|
|
15267
|
+
}
|
|
15001
15268
|
this.splitLoose(ev.object);
|
|
15002
15269
|
if (!furniture || ev.mass >= COLLAPSE_CLOUD_KG) this.playEvent({ kind: "collapse" }, this.rootPoint(ev.object));
|
|
15003
15270
|
else this.vfx.burst("dust", this.rootPoint(ev.object), [0, 1, 0], clamp6(Math.round(ev.mass / 4), 4, 24), 0.8);
|
|
@@ -15015,7 +15282,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15015
15282
|
this.startFire(ev);
|
|
15016
15283
|
this.activate(ev.object, ev.part);
|
|
15017
15284
|
this.sound("ignite", ev.point, 0.7);
|
|
15018
|
-
this.
|
|
15285
|
+
this.startBurnSound(ev.object, ev.part, ev.point, this.burning(ev.object, ev.part));
|
|
15019
15286
|
break;
|
|
15020
15287
|
case "primed":
|
|
15021
15288
|
if (ev.trigger !== "explosion") {
|
|
@@ -15023,7 +15290,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15023
15290
|
this.primedBurning.add(`${ev.object}|${ev.part}`);
|
|
15024
15291
|
this.activate(ev.object, ev.part);
|
|
15025
15292
|
this.sound("primed", ev.point, 0.7, { seconds: ev.delay });
|
|
15026
|
-
this.
|
|
15293
|
+
if (!this.burnSounds.has(`${ev.object}|${ev.part}`)) this.startBurnSound(ev.object, ev.part, ev.point, { fuel: "gas" });
|
|
15027
15294
|
}
|
|
15028
15295
|
break;
|
|
15029
15296
|
case "spall":
|
|
@@ -15045,20 +15312,20 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15045
15312
|
break;
|
|
15046
15313
|
case "extinguish": {
|
|
15047
15314
|
const f = this.fires.get(`${ev.object}|${ev.part}`);
|
|
15048
|
-
|
|
15315
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15049
15316
|
if (f) {
|
|
15050
15317
|
this.stopFire(`${ev.object}|${ev.part}`);
|
|
15051
15318
|
this.vfx.burst("steam", f.point, [0, 1, 0], 14, 1.2);
|
|
15052
15319
|
}
|
|
15053
|
-
|
|
15320
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15054
15321
|
this.activate(ev.object, ev.part);
|
|
15055
15322
|
this.sound("extinguish", f?.point ?? this.rootPoint(ev.object), 0.6);
|
|
15056
15323
|
break;
|
|
15057
15324
|
}
|
|
15058
15325
|
case "burnout": {
|
|
15059
15326
|
this.stopFire(`${ev.object}|${ev.part}`);
|
|
15060
|
-
|
|
15061
|
-
this.
|
|
15327
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15328
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15062
15329
|
this.vfx.burst("ash", ev.point, [0, 1, 0], 16, 1);
|
|
15063
15330
|
this.vfx.burst("smoke", ev.point, [0, 1, 0], 6, 0.8, { color: SMOKE_TONES.grey });
|
|
15064
15331
|
const pv = this.partVis(ev.object, ev.part);
|
|
@@ -15126,7 +15393,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15126
15393
|
break;
|
|
15127
15394
|
}
|
|
15128
15395
|
case "explode":
|
|
15129
|
-
|
|
15396
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15397
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15130
15398
|
this.onExplode(ev);
|
|
15131
15399
|
break;
|
|
15132
15400
|
case "destroyed":
|
|
@@ -15154,7 +15422,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15154
15422
|
}
|
|
15155
15423
|
/** Current colour of the part's first mesh (char included), or null. */
|
|
15156
15424
|
partColor(pv, def) {
|
|
15157
|
-
const
|
|
15425
|
+
const size = (m) => m.range ? m.range[1] - m.range[0] : m.mesh.geometry.getAttribute("position")?.count ?? 0;
|
|
15426
|
+
const mv = pv.meshes.reduce((best, m) => !best || size(m) > size(best) ? m : best, void 0);
|
|
15158
15427
|
if (!mv) return null;
|
|
15159
15428
|
const mat = materialsOf2(mv.mesh.material)[0];
|
|
15160
15429
|
const c = mat?.color;
|
|
@@ -15245,7 +15514,20 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15245
15514
|
const pv = b?.parts.get(ev.part);
|
|
15246
15515
|
if (!b || !pv) return;
|
|
15247
15516
|
const def = this.world.materials.get(pv.material);
|
|
15248
|
-
|
|
15517
|
+
const stair = ev.crack.stair;
|
|
15518
|
+
if (stair && !def?.visual?.transparent) {
|
|
15519
|
+
const wp = new this.THREE.Vector3(ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
15520
|
+
const seed = hashNumbers(ev.time, ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
15521
|
+
const width = Math.max(stair.width, MIN_DRAWN_CRACK_WIDTH);
|
|
15522
|
+
const normal = this.worldDir(b, ev.crack.normal);
|
|
15523
|
+
const toward2 = this.worldDir(b, stair.along);
|
|
15524
|
+
const look = { length: ev.crack.length, step: stair.step, width, color: SETTLEMENT_CRACK_COLOR, seed };
|
|
15525
|
+
for (const face of [wp, wp.clone().addScaledVector(normal, -stair.through)]) {
|
|
15526
|
+
const out = face === wp ? normal : normal.clone().negate();
|
|
15527
|
+
const mv = this.nearestMesh(pv, face);
|
|
15528
|
+
if (mv) this.visuals.addStairCrack(mv, face, out, toward2, look);
|
|
15529
|
+
}
|
|
15530
|
+
} else if (def?.visual?.transparent) {
|
|
15249
15531
|
const wp = new this.THREE.Vector3(ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
15250
15532
|
const mv = this.nearestMesh(pv, wp);
|
|
15251
15533
|
const seed = hashNumbers(ev.time, ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
@@ -15661,6 +15943,19 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15661
15943
|
}
|
|
15662
15944
|
return "";
|
|
15663
15945
|
}
|
|
15946
|
+
/** The top of the ground or of a standing part of the world under (x, z), below height y: a ray straight down through the destruction world. */
|
|
15947
|
+
surfaceAt(x, y, z) {
|
|
15948
|
+
const ground = this.groundAt(x, z);
|
|
15949
|
+
if (y <= ground || typeof this.world.raycast !== "function") return ground;
|
|
15950
|
+
let from = y;
|
|
15951
|
+
for (let k = 0; k < SURFACE_RAYS && from > ground; k++) {
|
|
15952
|
+
const hit = this.world.raycast([x, from, z], [0, -1, 0], from - ground);
|
|
15953
|
+
if (!hit) return ground;
|
|
15954
|
+
if (hit.distance > SURFACE_INSIDE) return Math.max(ground, hit.point[1]);
|
|
15955
|
+
from -= SURFACE_STEP;
|
|
15956
|
+
}
|
|
15957
|
+
return ground;
|
|
15958
|
+
}
|
|
15664
15959
|
/** `staticTopAt` without the boxes of `objectId` itself. */
|
|
15665
15960
|
staticTopAtBut(objectId, x, z, y, step) {
|
|
15666
15961
|
let top = -Infinity;
|
|
@@ -15815,9 +16110,25 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15815
16110
|
}
|
|
15816
16111
|
stopFire(key) {
|
|
15817
16112
|
const fire2 = this.fires.get(key);
|
|
15818
|
-
if (
|
|
15819
|
-
|
|
15820
|
-
|
|
16113
|
+
if (fire2) {
|
|
16114
|
+
if (fire2.handle !== void 0) this.vfx.stop(fire2.handle);
|
|
16115
|
+
this.fires.delete(key);
|
|
16116
|
+
}
|
|
16117
|
+
this.endBurnSound(key);
|
|
16118
|
+
}
|
|
16119
|
+
/** 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. */
|
|
16120
|
+
startBurnSound(object, part, point, detail) {
|
|
16121
|
+
const key = `${object}|${part}`;
|
|
16122
|
+
this.endBurnSound(key);
|
|
16123
|
+
this.burnSounds.set(key, { object, point, detail });
|
|
16124
|
+
this.sound("burn_loop", point, 0.5, detail);
|
|
16125
|
+
}
|
|
16126
|
+
/** The part's fire loop ends, with the point and the fuel it started with; nothing when it has none running. */
|
|
16127
|
+
endBurnSound(key) {
|
|
16128
|
+
const started = this.burnSounds.get(key);
|
|
16129
|
+
if (!started) return;
|
|
16130
|
+
this.burnSounds.delete(key);
|
|
16131
|
+
this.sound("burn_end", started.point, 0.5, started.detail);
|
|
15821
16132
|
}
|
|
15822
16133
|
// ----------------------------------------------------------------------------------------------------------------------------------
|
|
15823
16134
|
// Fire, heat, char, melt, leaks
|
|
@@ -15843,6 +16154,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15843
16154
|
const ps = pv ? this.world.part(a.object, a.part) : null;
|
|
15844
16155
|
if (!pv || !ps) {
|
|
15845
16156
|
this.active.delete(key);
|
|
16157
|
+
this.stopFire(key);
|
|
15846
16158
|
continue;
|
|
15847
16159
|
}
|
|
15848
16160
|
const def = this.world.materials.get(pv.material);
|
|
@@ -15962,6 +16274,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15962
16274
|
for (const home of homes) this.restoreHome(home);
|
|
15963
16275
|
for (const [key, a] of [...this.active]) if (homes.has(a.object)) this.active.delete(key);
|
|
15964
16276
|
for (const [key, f] of [...this.fires]) if (homes.has(f.object)) this.stopFire(key);
|
|
16277
|
+
for (const [key, started] of [...this.burnSounds]) if (homes.has(started.object)) this.endBurnSound(key);
|
|
15965
16278
|
for (let i = this.leaks.length - 1; i >= 0; i--) if (homes.has(this.leaks[i].object)) this.leaks.splice(i, 1);
|
|
15966
16279
|
for (const home of homes) {
|
|
15967
16280
|
this.fragments.removeHome(home);
|
|
@@ -15974,6 +16287,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15974
16287
|
for (const b of [...this.bounds.values()]) {
|
|
15975
16288
|
for (const [pid, pv] of [...b.parts]) {
|
|
15976
16289
|
if (pv.home !== home) continue;
|
|
16290
|
+
this.settlement.forget(pv);
|
|
15977
16291
|
this.visuals.restorePart(pv);
|
|
15978
16292
|
this.tagPart(pv, home);
|
|
15979
16293
|
if (b !== homeBound && homeBound) {
|
|
@@ -15995,8 +16309,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15995
16309
|
this.slices.length = 0;
|
|
15996
16310
|
this.active.clear();
|
|
15997
16311
|
for (const key of [...this.fires.keys()]) this.stopFire(key);
|
|
16312
|
+
for (const key of [...this.burnSounds.keys()]) this.endBurnSound(key);
|
|
15998
16313
|
this.leaks.length = 0;
|
|
15999
16314
|
this.trickles.length = 0;
|
|
16315
|
+
this.settlement.clear();
|
|
16000
16316
|
for (const id of [...this.bounds.keys()]) if (this.bounds.has(id)) this.restore(id);
|
|
16001
16317
|
for (const b of [...this.bounds.values()]) {
|
|
16002
16318
|
if (b.isSplit) {
|
|
@@ -18185,6 +18501,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18185
18501
|
}
|
|
18186
18502
|
};
|
|
18187
18503
|
var DEFAULT_FIRE = { perFire: 0.08, max: 0.45 };
|
|
18504
|
+
var FIRE_FADE_SECONDS = 0.4;
|
|
18188
18505
|
var DEFAULT_CRACKLES = { base: 2, perSqrtFire: 3, max: 14, volume: 0.5 };
|
|
18189
18506
|
var DEFAULT_INDOOR_CONFINEMENT = 1.3;
|
|
18190
18507
|
function createDestructionSound(engine, options = {}) {
|
|
@@ -18206,6 +18523,11 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18206
18523
|
const loops = /* @__PURE__ */ new Map();
|
|
18207
18524
|
const fires = [];
|
|
18208
18525
|
let nextCrackle = 0;
|
|
18526
|
+
const fading = [];
|
|
18527
|
+
const fadeOut = (handle) => {
|
|
18528
|
+
handle.set({ volume: 0 });
|
|
18529
|
+
fading.push({ handle, left: FIRE_FADE_SECONDS });
|
|
18530
|
+
};
|
|
18209
18531
|
const fuelFor = (detail) => detail?.fuel ?? (detail?.material !== void 0 ? fuelOf[detail.material] : void 0) ?? defaultFuel;
|
|
18210
18532
|
const setFire = () => {
|
|
18211
18533
|
if (options.burnLoop === false) return;
|
|
@@ -18216,7 +18538,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18216
18538
|
}
|
|
18217
18539
|
for (const [id, handle] of loops) {
|
|
18218
18540
|
if (count.has(id)) continue;
|
|
18219
|
-
handle
|
|
18541
|
+
fadeOut(handle);
|
|
18220
18542
|
loops.delete(id);
|
|
18221
18543
|
}
|
|
18222
18544
|
for (const [id, n] of count) {
|
|
@@ -18243,8 +18565,15 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18243
18565
|
else if (best >= 0) fires.splice(best, 1);
|
|
18244
18566
|
};
|
|
18245
18567
|
const reset = () => {
|
|
18568
|
+
for (const handle of loops.values()) fadeOut(handle);
|
|
18569
|
+
loops.clear();
|
|
18570
|
+
fires.length = 0;
|
|
18571
|
+
};
|
|
18572
|
+
const dispose = () => {
|
|
18246
18573
|
for (const handle of loops.values()) handle.stop();
|
|
18247
18574
|
loops.clear();
|
|
18575
|
+
for (const { handle } of fading) handle.stop();
|
|
18576
|
+
fading.length = 0;
|
|
18248
18577
|
fires.length = 0;
|
|
18249
18578
|
};
|
|
18250
18579
|
const blastSound = (point, volume, detail) => {
|
|
@@ -18291,6 +18620,13 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18291
18620
|
engine.play(sound, { position: point, volume: volume * (rule.volumeScale ?? 1), intensity: Math.min(1, Math.max(0, volume)), ...params ? { params } : {} });
|
|
18292
18621
|
},
|
|
18293
18622
|
update(dt) {
|
|
18623
|
+
for (let i = fading.length - 1; i >= 0; i--) {
|
|
18624
|
+
const entry = fading[i];
|
|
18625
|
+
entry.left -= dt;
|
|
18626
|
+
if (entry.left > 0) continue;
|
|
18627
|
+
entry.handle.stop();
|
|
18628
|
+
fading.splice(i, 1);
|
|
18629
|
+
}
|
|
18294
18630
|
if (!crackles || fires.length === 0 || options.burnLoop === false) return;
|
|
18295
18631
|
const weight = fires.reduce((sum, f) => sum + FIRE_CRACKLE_OF[f.fuel], 0);
|
|
18296
18632
|
if (weight <= 0) return;
|
|
@@ -18316,7 +18652,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18316
18652
|
return by;
|
|
18317
18653
|
},
|
|
18318
18654
|
reset,
|
|
18319
|
-
dispose
|
|
18655
|
+
dispose
|
|
18320
18656
|
};
|
|
18321
18657
|
}
|
|
18322
18658
|
|