@adatechnology/game-destruction-three 0.22.1 → 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 +324 -19
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +310 -19
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -254,13 +254,35 @@ function buildBrokenBoardGeometry(THREE, seed) {
|
|
|
254
254
|
}
|
|
255
255
|
return faceted(THREE, positions);
|
|
256
256
|
}
|
|
257
|
+
function buildRubbleGeometry(THREE, seed) {
|
|
258
|
+
const rnd = createRng(9e3 + seed);
|
|
259
|
+
const base = new THREE.BoxGeometry(1, 1, 1, 2, 2, 2).toNonIndexed();
|
|
260
|
+
const source = base.getAttribute("position");
|
|
261
|
+
const moved = /* @__PURE__ */ new Map();
|
|
262
|
+
const positions = [];
|
|
263
|
+
for (let i = 0; i < source.count; i++) {
|
|
264
|
+
const p = [source.getX(i), source.getY(i), source.getZ(i)];
|
|
265
|
+
const key = p.map((x) => x.toFixed(3)).join(",");
|
|
266
|
+
let out = moved.get(key);
|
|
267
|
+
if (!out) {
|
|
268
|
+
const outer = p.filter((x) => Math.abs(x) > 0.49).length;
|
|
269
|
+
const bite = outer === 3 ? 0.08 + 0.3 * rnd() : outer === 2 ? 0.1 * rnd() : 0;
|
|
270
|
+
out = p.map((x) => Math.abs(x) > 0.49 ? x - Math.sign(x) * bite * (0.4 + 0.6 * rnd()) : x);
|
|
271
|
+
moved.set(key, out);
|
|
272
|
+
}
|
|
273
|
+
positions.push(out[0], out[1], out[2]);
|
|
274
|
+
}
|
|
275
|
+
base.dispose();
|
|
276
|
+
return faceted(THREE, positions);
|
|
277
|
+
}
|
|
257
278
|
|
|
258
279
|
// src/fragments.ts
|
|
259
280
|
var BUILDERS = {
|
|
260
281
|
sliver: buildSliverGeometry,
|
|
261
282
|
lump: buildLumpGeometry,
|
|
262
283
|
veneer: buildVeneerGeometry,
|
|
263
|
-
board: buildBrokenBoardGeometry
|
|
284
|
+
board: buildBrokenBoardGeometry,
|
|
285
|
+
rubble: buildRubbleGeometry
|
|
264
286
|
};
|
|
265
287
|
var SHEET_MAX = 4e-3;
|
|
266
288
|
var SHEET_AIR = 2.5;
|
|
@@ -369,6 +391,7 @@ var FragmentSystem = class {
|
|
|
369
391
|
if (f.shape === "chunk" && form === "granules") return this.sharedGeometry("lump", seed);
|
|
370
392
|
if (f.shape === "scrap" && form === "plies") return this.sharedGeometry("veneer", seed);
|
|
371
393
|
if (f.shape === "slab" && (form === "slivers" || form === "plies")) return this.sharedGeometry("board", seed);
|
|
394
|
+
if (f.shape === "chunk" && this.o.crumbles?.(f.material)) return this.sharedGeometry("rubble", seed);
|
|
372
395
|
return this.box;
|
|
373
396
|
}
|
|
374
397
|
markParts() {
|
|
@@ -377,18 +400,18 @@ var FragmentSystem = class {
|
|
|
377
400
|
return { geometry: this.markGeometry, material: this.markMaterial };
|
|
378
401
|
}
|
|
379
402
|
/**
|
|
380
|
-
* 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
|
|
403
|
+
* 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
|
|
381
404
|
* glass materials. A host draws them at load so the first blast does not upload these buffers in the middle of a frame.
|
|
382
405
|
*/
|
|
383
406
|
warmMeshes() {
|
|
384
407
|
const opaque = this.materialFor("warm", 8421504, false);
|
|
385
408
|
const glass2 = this.materialFor("warm", 8421504, true);
|
|
386
409
|
const geometries = [this.box, ...Array.from({ length: SHARD_SHAPES }, (_, index) => this.shardGeometry(index))];
|
|
387
|
-
const
|
|
410
|
+
const shaped = ["sliver", "lump", "veneer", "board", "rubble"].flatMap((shape) => Array.from({ length: FRAGMENT_SHAPE_VARIANTS }, (_, index) => this.sharedGeometry(shape, index)));
|
|
388
411
|
const { geometry, material } = this.markParts();
|
|
389
412
|
return [
|
|
390
413
|
...geometries.flatMap((shared) => [new this.THREE.Mesh(shared, opaque), new this.THREE.Mesh(shared, glass2)]),
|
|
391
|
-
...
|
|
414
|
+
...shaped.map((shared) => new this.THREE.Mesh(shared, opaque)),
|
|
392
415
|
new this.THREE.Mesh(geometry, material)
|
|
393
416
|
];
|
|
394
417
|
}
|
|
@@ -2329,6 +2352,47 @@ function shellDisplacementAt(THREE, worldPoint, shells, out) {
|
|
|
2329
2352
|
return Math.sqrt(nearest) * nearestScale;
|
|
2330
2353
|
}
|
|
2331
2354
|
|
|
2355
|
+
// src/stair-crack.ts
|
|
2356
|
+
function stairCrackPath(spec) {
|
|
2357
|
+
const rnd = createRng(spec.seed);
|
|
2358
|
+
const run = Math.max(0.02, spec.step[0] / 2);
|
|
2359
|
+
const rise = Math.max(0.02, spec.step[1]);
|
|
2360
|
+
const points = [[0, 0]];
|
|
2361
|
+
let h = 0;
|
|
2362
|
+
let u = 0;
|
|
2363
|
+
let walked = 0;
|
|
2364
|
+
while (walked < spec.length) {
|
|
2365
|
+
const along2 = run * (rnd() < 0.2 ? 2 : 1);
|
|
2366
|
+
h += along2;
|
|
2367
|
+
points.push([h, u]);
|
|
2368
|
+
u += rise;
|
|
2369
|
+
points.push([h, u]);
|
|
2370
|
+
walked += along2 + rise;
|
|
2371
|
+
}
|
|
2372
|
+
return points;
|
|
2373
|
+
}
|
|
2374
|
+
function stairCrackStrip(points, width, taper) {
|
|
2375
|
+
const out = [];
|
|
2376
|
+
const n = points.length - 1;
|
|
2377
|
+
for (let k = 0; k < n; k++) {
|
|
2378
|
+
const [h0, u0] = points[k];
|
|
2379
|
+
const [h1, u1] = points[k + 1];
|
|
2380
|
+
const length = Math.hypot(h1 - h0, u1 - u0) || 1;
|
|
2381
|
+
const half0 = width * (1 - (1 - taper) * k / n) / 2;
|
|
2382
|
+
const half1 = width * (1 - (1 - taper) * (k + 1) / n) / 2;
|
|
2383
|
+
const sh = -(u1 - u0) / length;
|
|
2384
|
+
const su = (h1 - h0) / length;
|
|
2385
|
+
const eh = (h1 - h0) / length * half0;
|
|
2386
|
+
const eu = (u1 - u0) / length * half0;
|
|
2387
|
+
const a = [h0 - eh - sh * half0, u0 - eu - su * half0];
|
|
2388
|
+
const b = [h1 + eh - sh * half1, u1 + eu - su * half1];
|
|
2389
|
+
const c = [h1 + eh + sh * half1, u1 + eu + su * half1];
|
|
2390
|
+
const d = [h0 - eh + sh * half0, u0 - eu + su * half0];
|
|
2391
|
+
out.push(...a, ...b, ...c, ...a, ...c, ...d);
|
|
2392
|
+
}
|
|
2393
|
+
return out;
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2332
2396
|
// src/visual.ts
|
|
2333
2397
|
var POS_ATTR = "position";
|
|
2334
2398
|
function positionAttr(geo) {
|
|
@@ -2433,6 +2497,8 @@ var collapseForeign = (mesh, arr) => {
|
|
|
2433
2497
|
}
|
|
2434
2498
|
};
|
|
2435
2499
|
var DECAL_SNAP = 0.03;
|
|
2500
|
+
var STAIR_CRACK_LIFT = 2e-3;
|
|
2501
|
+
var STAIR_CRACK_TAPER = 0.35;
|
|
2436
2502
|
var Visuals = class {
|
|
2437
2503
|
constructor(THREE, lowQuality, decalCap) {
|
|
2438
2504
|
__publicField(this, "THREE", THREE);
|
|
@@ -2926,6 +2992,71 @@ var Visuals = class {
|
|
|
2926
2992
|
lines.renderOrder = 2;
|
|
2927
2993
|
this.addDecal(mv, { obj: lines, geometry: geo });
|
|
2928
2994
|
}
|
|
2995
|
+
/**
|
|
2996
|
+
* A stair-step crack through the joints of a wall (settlement): from `worldPoint` on the face whose outward normal is `worldNormal`, climbing toward
|
|
2997
|
+
* `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
|
|
2998
|
+
* part's marks: it goes with them (cleared, restored, disposed).
|
|
2999
|
+
*/
|
|
3000
|
+
addStairCrack(mv, worldPoint, worldNormal, worldToward, spec) {
|
|
3001
|
+
const mesh = mv.mesh;
|
|
3002
|
+
mesh.updateWorldMatrix(true, false);
|
|
3003
|
+
const n = worldNormal.clone().normalize();
|
|
3004
|
+
const up = new this.THREE.Vector3(0, 1, 0).addScaledVector(n, -n.y).normalize();
|
|
3005
|
+
const side = worldToward.clone().addScaledVector(n, -worldToward.dot(n)).addScaledVector(up, -worldToward.dot(up));
|
|
3006
|
+
if (side.lengthSq() < 1e-8) side.crossVectors(up, n);
|
|
3007
|
+
side.normalize();
|
|
3008
|
+
const start = this.onFace(mesh, worldPoint, n).clone().addScaledVector(n, STAIR_CRACK_LIFT);
|
|
3009
|
+
const flat = stairCrackStrip(stairCrackPath({ length: spec.length, step: spec.step, seed: spec.seed }), spec.width, STAIR_CRACK_TAPER);
|
|
3010
|
+
const flip = new this.THREE.Vector3().crossVectors(side, up).dot(n) < 0;
|
|
3011
|
+
const verts = [];
|
|
3012
|
+
const point = this.a;
|
|
3013
|
+
for (let i = 0; i < flat.length; i += 6) {
|
|
3014
|
+
const order = flip ? [0, 2, 1] : [0, 1, 2];
|
|
3015
|
+
for (const k of order) {
|
|
3016
|
+
point.copy(start).addScaledVector(side, flat[i + k * 2]).addScaledVector(up, flat[i + k * 2 + 1]);
|
|
3017
|
+
mesh.worldToLocal(point);
|
|
3018
|
+
verts.push(point.x, point.y, point.z);
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
const geo = new this.THREE.BufferGeometry();
|
|
3022
|
+
geo.setAttribute("position", new this.THREE.Float32BufferAttribute(verts, 3));
|
|
3023
|
+
const strip = new this.THREE.Mesh(geo, this.kit.patchMaterial(spec.color));
|
|
3024
|
+
strip.renderOrder = 2;
|
|
3025
|
+
this.addDecal(mv, { obj: strip, geometry: geo });
|
|
3026
|
+
}
|
|
3027
|
+
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
3028
|
+
// Settlement
|
|
3029
|
+
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
3030
|
+
/**
|
|
3031
|
+
* 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
|
|
3032
|
+
* one end tilts. Writes the geometry unless `write` is false (several parts of one merged mesh are then written once by `commit`).
|
|
3033
|
+
*/
|
|
3034
|
+
sink(mv, dropAt, write = true) {
|
|
3035
|
+
if (!this.ownGeometry(mv)) return false;
|
|
3036
|
+
const mesh = mv.mesh;
|
|
3037
|
+
mesh.updateWorldMatrix(true, false);
|
|
3038
|
+
const scale = mesh.matrixWorld.getMaxScaleOnAxis() || 1;
|
|
3039
|
+
const down = this.b.set(0, -1, 0).transformDirection(this.m4.copy(mesh.matrixWorld).invert());
|
|
3040
|
+
const work = mv.host ? mv.host.work : mv.work;
|
|
3041
|
+
const from = mv.range ? mv.range[0] * 3 : 0;
|
|
3042
|
+
const to = mv.range ? mv.range[1] * 3 : work.length;
|
|
3043
|
+
const point = this.a;
|
|
3044
|
+
for (let i = from; i < to; i += 3) {
|
|
3045
|
+
const d = dropAt(point.set(work[i], work[i + 1], work[i + 2]).applyMatrix4(mesh.matrixWorld)) / scale;
|
|
3046
|
+
work[i] += down.x * d;
|
|
3047
|
+
work[i + 1] += down.y * d;
|
|
3048
|
+
work[i + 2] += down.z * d;
|
|
3049
|
+
}
|
|
3050
|
+
for (const decal of mv.decals) decal.obj.position.addScaledVector(down, dropAt(decal.obj.getWorldPosition(point)) / scale);
|
|
3051
|
+
mv.touched = true;
|
|
3052
|
+
if (write) this.commit(mv);
|
|
3053
|
+
return true;
|
|
3054
|
+
}
|
|
3055
|
+
/** Writes what `sink` moved into the geometry. */
|
|
3056
|
+
commit(mv) {
|
|
3057
|
+
const pos = positionAttr(mv.mesh.geometry);
|
|
3058
|
+
if (pos) this.writePositions(mv, pos);
|
|
3059
|
+
}
|
|
2929
3060
|
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
2930
3061
|
// Char and heat glow
|
|
2931
3062
|
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
@@ -3321,6 +3452,7 @@ var Visuals = class {
|
|
|
3321
3452
|
}
|
|
3322
3453
|
restorePart(pv) {
|
|
3323
3454
|
for (const mv of pv.meshes) this.restoreMesh(mv);
|
|
3455
|
+
delete pv.settled;
|
|
3324
3456
|
pv.charApplied = 0;
|
|
3325
3457
|
pv.glowApplied = 0;
|
|
3326
3458
|
pv.meltApplied = 0;
|
|
@@ -3331,6 +3463,78 @@ var Visuals = class {
|
|
|
3331
3463
|
}
|
|
3332
3464
|
};
|
|
3333
3465
|
|
|
3466
|
+
// src/settlement.ts
|
|
3467
|
+
import { settlementAt } from "@adatechnology/game-destruction";
|
|
3468
|
+
var SETTLE_SECONDS = 1.2;
|
|
3469
|
+
var SETTLE_REDRAW = 0.1;
|
|
3470
|
+
var dropOf = (line, point) => line ? settlementAt(line, point) : 0;
|
|
3471
|
+
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]);
|
|
3472
|
+
var SettlementView = class {
|
|
3473
|
+
constructor(THREE, visuals) {
|
|
3474
|
+
__publicField(this, "visuals", visuals);
|
|
3475
|
+
__publicField(this, "moving", /* @__PURE__ */ new Map());
|
|
3476
|
+
__publicField(this, "local");
|
|
3477
|
+
__publicField(this, "inverse");
|
|
3478
|
+
this.local = new THREE.Vector3();
|
|
3479
|
+
this.inverse = new THREE.Matrix4();
|
|
3480
|
+
}
|
|
3481
|
+
/** The parts of an object (`root` draws it in object space) and their settlement now: those that changed start going to it. */
|
|
3482
|
+
follow(root, parts) {
|
|
3483
|
+
for (const [pv, target] of parts) {
|
|
3484
|
+
if (!target || pv.gone !== "none" || sameLine(this.moving.get(pv)?.target ?? pv.settled, target)) continue;
|
|
3485
|
+
this.finish(pv);
|
|
3486
|
+
this.moving.set(pv, { pv, root, start: pv.settled, target, shown: 0, elapsed: 0, lastDrawn: -SETTLE_REDRAW });
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
get count() {
|
|
3490
|
+
return this.moving.size;
|
|
3491
|
+
}
|
|
3492
|
+
update(dt) {
|
|
3493
|
+
for (const s of this.moving.values()) {
|
|
3494
|
+
s.elapsed += dt;
|
|
3495
|
+
const done = s.elapsed >= SETTLE_SECONDS;
|
|
3496
|
+
if (!done && s.elapsed - s.lastDrawn < SETTLE_REDRAW) continue;
|
|
3497
|
+
s.lastDrawn = s.elapsed;
|
|
3498
|
+
const t = Math.min(1, s.elapsed / SETTLE_SECONDS);
|
|
3499
|
+
this.draw(s, t * t * (3 - 2 * t));
|
|
3500
|
+
if (done) {
|
|
3501
|
+
s.pv.settled = s.target;
|
|
3502
|
+
this.moving.delete(s.pv);
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
/** Draws the rest of a part's settlement at once (it is about to be split off or put back). */
|
|
3507
|
+
finish(pv) {
|
|
3508
|
+
const s = this.moving.get(pv);
|
|
3509
|
+
if (!s) return;
|
|
3510
|
+
this.draw(s, 1);
|
|
3511
|
+
pv.settled = s.target;
|
|
3512
|
+
this.moving.delete(pv);
|
|
3513
|
+
}
|
|
3514
|
+
/** Forget a part without drawing (it was put back as it was). */
|
|
3515
|
+
forget(pv) {
|
|
3516
|
+
this.moving.delete(pv);
|
|
3517
|
+
}
|
|
3518
|
+
clear() {
|
|
3519
|
+
this.moving.clear();
|
|
3520
|
+
}
|
|
3521
|
+
draw(s, shown) {
|
|
3522
|
+
const share = shown - s.shown;
|
|
3523
|
+
if (share <= 0) return;
|
|
3524
|
+
s.shown = shown;
|
|
3525
|
+
s.root.updateWorldMatrix(true, false);
|
|
3526
|
+
this.inverse.copy(s.root.matrixWorld).invert();
|
|
3527
|
+
const dropAt = (world) => {
|
|
3528
|
+
const p = this.local.copy(world).applyMatrix4(this.inverse);
|
|
3529
|
+
const at = [p.x, p.y, p.z];
|
|
3530
|
+
return (dropOf(s.target, at) - dropOf(s.start, at)) * share;
|
|
3531
|
+
};
|
|
3532
|
+
const writes = /* @__PURE__ */ new Map();
|
|
3533
|
+
for (const mv of s.pv.meshes) if (this.visuals.sink(mv, dropAt, false)) writes.set(mv.host ?? mv, mv);
|
|
3534
|
+
for (const mv of writes.values()) this.visuals.commit(mv);
|
|
3535
|
+
}
|
|
3536
|
+
};
|
|
3537
|
+
|
|
3334
3538
|
// src/renderer.ts
|
|
3335
3539
|
var rendererCount = 0;
|
|
3336
3540
|
var COLLAPSE_CLOUD_KG = 1e3;
|
|
@@ -3340,6 +3544,8 @@ var CHIP_DECAL_EDGE = 0.05;
|
|
|
3340
3544
|
var WOOD_RIM = 1.5;
|
|
3341
3545
|
var IMPACT_TAGS = ["metal", "glass", "wood"];
|
|
3342
3546
|
var GLOW_FROM_C = 430;
|
|
3547
|
+
var MIN_DRAWN_CRACK_WIDTH = 4e-3;
|
|
3548
|
+
var SETTLEMENT_CRACK_COLOR = 2827296;
|
|
3343
3549
|
var QUEUE_CAP = 4e3;
|
|
3344
3550
|
var TRICKLE_SECONDS = [2, 5];
|
|
3345
3551
|
var TRICKLE_EVERY = 0.25;
|
|
@@ -3559,6 +3765,8 @@ var Renderer = class {
|
|
|
3559
3765
|
});
|
|
3560
3766
|
__publicField(this, "unsubscribe");
|
|
3561
3767
|
__publicField(this, "visuals");
|
|
3768
|
+
/** The parts the ground went down under, drawn going down (`subside`). */
|
|
3769
|
+
__publicField(this, "settlement");
|
|
3562
3770
|
__publicField(this, "fragments");
|
|
3563
3771
|
__publicField(this, "ground");
|
|
3564
3772
|
__publicField(this, "pieceSys");
|
|
@@ -3567,6 +3775,8 @@ var Renderer = class {
|
|
|
3567
3775
|
__publicField(this, "fires", /* @__PURE__ */ new Map());
|
|
3568
3776
|
/** Primed parts burning in the effects world until they go off: their burn loop ends when they are put out. */
|
|
3569
3777
|
__publicField(this, "primedBurning", /* @__PURE__ */ new Set());
|
|
3778
|
+
/** 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. */
|
|
3779
|
+
__publicField(this, "burnSounds", /* @__PURE__ */ new Map());
|
|
3570
3780
|
__publicField(this, "leaks", []);
|
|
3571
3781
|
__publicField(this, "homeTags", []);
|
|
3572
3782
|
__publicField(this, "throttles", /* @__PURE__ */ new Map());
|
|
@@ -3601,6 +3811,7 @@ var Renderer = class {
|
|
|
3601
3811
|
this.v2 = new THREE.Vector3();
|
|
3602
3812
|
const maxParticles = Math.max(8, Math.floor((o.maxParticles ?? 2500) * (this.low ? 0.5 : 1)));
|
|
3603
3813
|
this.visuals = new Visuals(THREE, this.low, 600);
|
|
3814
|
+
this.settlement = new SettlementView(THREE, this.visuals);
|
|
3604
3815
|
this.ground = new GroundSpots(THREE, o.scene, this.groundAt, 48);
|
|
3605
3816
|
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");
|
|
3606
3817
|
this.vfx = o.vfx ?? createVfx({ profile: this.quality, gravity: this.gravity, groundAt: this.groundAt, sprites: { capacity: maxParticles, density: this.low ? 0.6 : 1 } });
|
|
@@ -3615,7 +3826,8 @@ var Renderer = class {
|
|
|
3615
3826
|
gravity: this.gravity,
|
|
3616
3827
|
max: this.maxFragments,
|
|
3617
3828
|
life: o.fragmentLife ?? 12,
|
|
3618
|
-
formOf: (id) => this.world.materials.get(id)?.splitForm
|
|
3829
|
+
formOf: (id) => this.world.materials.get(id)?.splitForm,
|
|
3830
|
+
crumbles: (id) => this.world.materials.get(id)?.fracture === "crumble"
|
|
3619
3831
|
});
|
|
3620
3832
|
this.cages = new RebarCages(THREE, o.scene);
|
|
3621
3833
|
this.pieceSys = new PieceSystem(THREE, {
|
|
@@ -4010,6 +4222,7 @@ var Renderer = class {
|
|
|
4010
4222
|
this.checkBroken();
|
|
4011
4223
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
4012
4224
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
4225
|
+
this.settlement.update(dt);
|
|
4013
4226
|
this.updateActive(dt);
|
|
4014
4227
|
this.updateLeaks(dt);
|
|
4015
4228
|
this.updateTrickles(dt);
|
|
@@ -4085,6 +4298,18 @@ var Renderer = class {
|
|
|
4085
4298
|
node.quaternion.set(q[0], q[1], q[2], q[3]);
|
|
4086
4299
|
node.updateMatrixWorld(true);
|
|
4087
4300
|
}
|
|
4301
|
+
/** The ground went down under some parts of an object: each part with a settlement (`PartState.settlement`) starts going down to it. */
|
|
4302
|
+
onSubside(objectId) {
|
|
4303
|
+
const b = this.bounds.get(objectId);
|
|
4304
|
+
const state = this.world.state(objectId);
|
|
4305
|
+
if (!b || !state) return;
|
|
4306
|
+
const parts = [];
|
|
4307
|
+
for (const ps of state.parts) {
|
|
4308
|
+
const pv = b.parts.get(ps.id);
|
|
4309
|
+
if (pv && ps.settlement) parts.push([pv, ps.settlement]);
|
|
4310
|
+
}
|
|
4311
|
+
this.settlement.follow(b.soilNode ?? b.root, parts);
|
|
4312
|
+
}
|
|
4088
4313
|
syncTransforms() {
|
|
4089
4314
|
for (const b of this.bounds.values()) this.syncOne(b);
|
|
4090
4315
|
}
|
|
@@ -4235,9 +4460,15 @@ var Renderer = class {
|
|
|
4235
4460
|
case "debris":
|
|
4236
4461
|
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));
|
|
4237
4462
|
break;
|
|
4238
|
-
case "fracture":
|
|
4463
|
+
case "fracture": {
|
|
4464
|
+
const pv = this.partVis(ev.object, ev.part);
|
|
4465
|
+
if (pv) this.settlement.forget(pv);
|
|
4239
4466
|
this.onFracture(ev);
|
|
4240
4467
|
break;
|
|
4468
|
+
}
|
|
4469
|
+
case "subside":
|
|
4470
|
+
this.onSubside(ev.object);
|
|
4471
|
+
break;
|
|
4241
4472
|
case "detach":
|
|
4242
4473
|
this.onDetach(ev);
|
|
4243
4474
|
break;
|
|
@@ -4247,6 +4478,10 @@ var Renderer = class {
|
|
|
4247
4478
|
case "collapse": {
|
|
4248
4479
|
const root = this.bounds.get(ev.object)?.root;
|
|
4249
4480
|
const furniture = !!root && kitOriginOf(root)?.kind === "furniture";
|
|
4481
|
+
for (const part of ev.parts) {
|
|
4482
|
+
const pv = this.partVis(ev.object, part);
|
|
4483
|
+
if (pv) this.settlement.finish(pv);
|
|
4484
|
+
}
|
|
4250
4485
|
this.splitLoose(ev.object);
|
|
4251
4486
|
if (!furniture || ev.mass >= COLLAPSE_CLOUD_KG) this.playEvent({ kind: "collapse" }, this.rootPoint(ev.object));
|
|
4252
4487
|
else this.vfx.burst("dust", this.rootPoint(ev.object), [0, 1, 0], clamp(Math.round(ev.mass / 4), 4, 24), 0.8);
|
|
@@ -4264,7 +4499,7 @@ var Renderer = class {
|
|
|
4264
4499
|
this.startFire(ev);
|
|
4265
4500
|
this.activate(ev.object, ev.part);
|
|
4266
4501
|
this.sound("ignite", ev.point, 0.7);
|
|
4267
|
-
this.
|
|
4502
|
+
this.startBurnSound(ev.object, ev.part, ev.point, this.burning(ev.object, ev.part));
|
|
4268
4503
|
break;
|
|
4269
4504
|
case "primed":
|
|
4270
4505
|
if (ev.trigger !== "explosion") {
|
|
@@ -4272,7 +4507,7 @@ var Renderer = class {
|
|
|
4272
4507
|
this.primedBurning.add(`${ev.object}|${ev.part}`);
|
|
4273
4508
|
this.activate(ev.object, ev.part);
|
|
4274
4509
|
this.sound("primed", ev.point, 0.7, { seconds: ev.delay });
|
|
4275
|
-
this.
|
|
4510
|
+
if (!this.burnSounds.has(`${ev.object}|${ev.part}`)) this.startBurnSound(ev.object, ev.part, ev.point, { fuel: "gas" });
|
|
4276
4511
|
}
|
|
4277
4512
|
break;
|
|
4278
4513
|
case "spall":
|
|
@@ -4294,20 +4529,20 @@ var Renderer = class {
|
|
|
4294
4529
|
break;
|
|
4295
4530
|
case "extinguish": {
|
|
4296
4531
|
const f = this.fires.get(`${ev.object}|${ev.part}`);
|
|
4297
|
-
|
|
4532
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
4298
4533
|
if (f) {
|
|
4299
4534
|
this.stopFire(`${ev.object}|${ev.part}`);
|
|
4300
4535
|
this.vfx.burst("steam", f.point, [0, 1, 0], 14, 1.2);
|
|
4301
4536
|
}
|
|
4302
|
-
|
|
4537
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
4303
4538
|
this.activate(ev.object, ev.part);
|
|
4304
4539
|
this.sound("extinguish", f?.point ?? this.rootPoint(ev.object), 0.6);
|
|
4305
4540
|
break;
|
|
4306
4541
|
}
|
|
4307
4542
|
case "burnout": {
|
|
4308
4543
|
this.stopFire(`${ev.object}|${ev.part}`);
|
|
4309
|
-
|
|
4310
|
-
this.
|
|
4544
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
4545
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
4311
4546
|
this.vfx.burst("ash", ev.point, [0, 1, 0], 16, 1);
|
|
4312
4547
|
this.vfx.burst("smoke", ev.point, [0, 1, 0], 6, 0.8, { color: SMOKE_TONES.grey });
|
|
4313
4548
|
const pv = this.partVis(ev.object, ev.part);
|
|
@@ -4375,7 +4610,8 @@ var Renderer = class {
|
|
|
4375
4610
|
break;
|
|
4376
4611
|
}
|
|
4377
4612
|
case "explode":
|
|
4378
|
-
|
|
4613
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
4614
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
4379
4615
|
this.onExplode(ev);
|
|
4380
4616
|
break;
|
|
4381
4617
|
case "destroyed":
|
|
@@ -4494,7 +4730,20 @@ var Renderer = class {
|
|
|
4494
4730
|
const pv = b?.parts.get(ev.part);
|
|
4495
4731
|
if (!b || !pv) return;
|
|
4496
4732
|
const def = this.world.materials.get(pv.material);
|
|
4497
|
-
|
|
4733
|
+
const stair = ev.crack.stair;
|
|
4734
|
+
if (stair && !def?.visual?.transparent) {
|
|
4735
|
+
const wp = new this.THREE.Vector3(ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
4736
|
+
const seed = hashNumbers(ev.time, ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
4737
|
+
const width = Math.max(stair.width, MIN_DRAWN_CRACK_WIDTH);
|
|
4738
|
+
const normal = this.worldDir(b, ev.crack.normal);
|
|
4739
|
+
const toward = this.worldDir(b, stair.along);
|
|
4740
|
+
const look = { length: ev.crack.length, step: stair.step, width, color: SETTLEMENT_CRACK_COLOR, seed };
|
|
4741
|
+
for (const face of [wp, wp.clone().addScaledVector(normal, -stair.through)]) {
|
|
4742
|
+
const out = face === wp ? normal : normal.clone().negate();
|
|
4743
|
+
const mv = this.nearestMesh(pv, face);
|
|
4744
|
+
if (mv) this.visuals.addStairCrack(mv, face, out, toward, look);
|
|
4745
|
+
}
|
|
4746
|
+
} else if (def?.visual?.transparent) {
|
|
4498
4747
|
const wp = new this.THREE.Vector3(ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
4499
4748
|
const mv = this.nearestMesh(pv, wp);
|
|
4500
4749
|
const seed = hashNumbers(ev.time, ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
@@ -5064,9 +5313,25 @@ var Renderer = class {
|
|
|
5064
5313
|
}
|
|
5065
5314
|
stopFire(key) {
|
|
5066
5315
|
const fire2 = this.fires.get(key);
|
|
5067
|
-
if (
|
|
5068
|
-
|
|
5069
|
-
|
|
5316
|
+
if (fire2) {
|
|
5317
|
+
if (fire2.handle !== void 0) this.vfx.stop(fire2.handle);
|
|
5318
|
+
this.fires.delete(key);
|
|
5319
|
+
}
|
|
5320
|
+
this.endBurnSound(key);
|
|
5321
|
+
}
|
|
5322
|
+
/** 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. */
|
|
5323
|
+
startBurnSound(object, part, point, detail) {
|
|
5324
|
+
const key = `${object}|${part}`;
|
|
5325
|
+
this.endBurnSound(key);
|
|
5326
|
+
this.burnSounds.set(key, { object, point, detail });
|
|
5327
|
+
this.sound("burn_loop", point, 0.5, detail);
|
|
5328
|
+
}
|
|
5329
|
+
/** The part's fire loop ends, with the point and the fuel it started with; nothing when it has none running. */
|
|
5330
|
+
endBurnSound(key) {
|
|
5331
|
+
const started = this.burnSounds.get(key);
|
|
5332
|
+
if (!started) return;
|
|
5333
|
+
this.burnSounds.delete(key);
|
|
5334
|
+
this.sound("burn_end", started.point, 0.5, started.detail);
|
|
5070
5335
|
}
|
|
5071
5336
|
// ----------------------------------------------------------------------------------------------------------------------------------
|
|
5072
5337
|
// Fire, heat, char, melt, leaks
|
|
@@ -5092,6 +5357,7 @@ var Renderer = class {
|
|
|
5092
5357
|
const ps = pv ? this.world.part(a.object, a.part) : null;
|
|
5093
5358
|
if (!pv || !ps) {
|
|
5094
5359
|
this.active.delete(key);
|
|
5360
|
+
this.stopFire(key);
|
|
5095
5361
|
continue;
|
|
5096
5362
|
}
|
|
5097
5363
|
const def = this.world.materials.get(pv.material);
|
|
@@ -5211,6 +5477,7 @@ var Renderer = class {
|
|
|
5211
5477
|
for (const home of homes) this.restoreHome(home);
|
|
5212
5478
|
for (const [key, a] of [...this.active]) if (homes.has(a.object)) this.active.delete(key);
|
|
5213
5479
|
for (const [key, f] of [...this.fires]) if (homes.has(f.object)) this.stopFire(key);
|
|
5480
|
+
for (const [key, started] of [...this.burnSounds]) if (homes.has(started.object)) this.endBurnSound(key);
|
|
5214
5481
|
for (let i = this.leaks.length - 1; i >= 0; i--) if (homes.has(this.leaks[i].object)) this.leaks.splice(i, 1);
|
|
5215
5482
|
for (const home of homes) {
|
|
5216
5483
|
this.fragments.removeHome(home);
|
|
@@ -5223,6 +5490,7 @@ var Renderer = class {
|
|
|
5223
5490
|
for (const b of [...this.bounds.values()]) {
|
|
5224
5491
|
for (const [pid, pv] of [...b.parts]) {
|
|
5225
5492
|
if (pv.home !== home) continue;
|
|
5493
|
+
this.settlement.forget(pv);
|
|
5226
5494
|
this.visuals.restorePart(pv);
|
|
5227
5495
|
this.tagPart(pv, home);
|
|
5228
5496
|
if (b !== homeBound && homeBound) {
|
|
@@ -5244,8 +5512,10 @@ var Renderer = class {
|
|
|
5244
5512
|
this.slices.length = 0;
|
|
5245
5513
|
this.active.clear();
|
|
5246
5514
|
for (const key of [...this.fires.keys()]) this.stopFire(key);
|
|
5515
|
+
for (const key of [...this.burnSounds.keys()]) this.endBurnSound(key);
|
|
5247
5516
|
this.leaks.length = 0;
|
|
5248
5517
|
this.trickles.length = 0;
|
|
5518
|
+
this.settlement.clear();
|
|
5249
5519
|
for (const id of [...this.bounds.keys()]) if (this.bounds.has(id)) this.restore(id);
|
|
5250
5520
|
for (const b of [...this.bounds.values()]) {
|
|
5251
5521
|
if (b.isSplit) {
|
|
@@ -5883,6 +6153,7 @@ var DESTRUCTION_SOUND_KEYS = {
|
|
|
5883
6153
|
}
|
|
5884
6154
|
};
|
|
5885
6155
|
var DEFAULT_FIRE = { perFire: 0.08, max: 0.45 };
|
|
6156
|
+
var FIRE_FADE_SECONDS = 0.4;
|
|
5886
6157
|
var DEFAULT_CRACKLES = { base: 2, perSqrtFire: 3, max: 14, volume: 0.5 };
|
|
5887
6158
|
var DEFAULT_INDOOR_CONFINEMENT = 1.3;
|
|
5888
6159
|
function createDestructionSound(engine, options = {}) {
|
|
@@ -5904,6 +6175,11 @@ function createDestructionSound(engine, options = {}) {
|
|
|
5904
6175
|
const loops = /* @__PURE__ */ new Map();
|
|
5905
6176
|
const fires = [];
|
|
5906
6177
|
let nextCrackle = 0;
|
|
6178
|
+
const fading = [];
|
|
6179
|
+
const fadeOut = (handle) => {
|
|
6180
|
+
handle.set({ volume: 0 });
|
|
6181
|
+
fading.push({ handle, left: FIRE_FADE_SECONDS });
|
|
6182
|
+
};
|
|
5907
6183
|
const fuelFor = (detail) => detail?.fuel ?? (detail?.material !== void 0 ? fuelOf[detail.material] : void 0) ?? defaultFuel;
|
|
5908
6184
|
const setFire = () => {
|
|
5909
6185
|
if (options.burnLoop === false) return;
|
|
@@ -5914,7 +6190,7 @@ function createDestructionSound(engine, options = {}) {
|
|
|
5914
6190
|
}
|
|
5915
6191
|
for (const [id, handle] of loops) {
|
|
5916
6192
|
if (count.has(id)) continue;
|
|
5917
|
-
handle
|
|
6193
|
+
fadeOut(handle);
|
|
5918
6194
|
loops.delete(id);
|
|
5919
6195
|
}
|
|
5920
6196
|
for (const [id, n] of count) {
|
|
@@ -5941,8 +6217,15 @@ function createDestructionSound(engine, options = {}) {
|
|
|
5941
6217
|
else if (best >= 0) fires.splice(best, 1);
|
|
5942
6218
|
};
|
|
5943
6219
|
const reset = () => {
|
|
6220
|
+
for (const handle of loops.values()) fadeOut(handle);
|
|
6221
|
+
loops.clear();
|
|
6222
|
+
fires.length = 0;
|
|
6223
|
+
};
|
|
6224
|
+
const dispose = () => {
|
|
5944
6225
|
for (const handle of loops.values()) handle.stop();
|
|
5945
6226
|
loops.clear();
|
|
6227
|
+
for (const { handle } of fading) handle.stop();
|
|
6228
|
+
fading.length = 0;
|
|
5946
6229
|
fires.length = 0;
|
|
5947
6230
|
};
|
|
5948
6231
|
const blastSound = (point, volume, detail) => {
|
|
@@ -5989,6 +6272,13 @@ function createDestructionSound(engine, options = {}) {
|
|
|
5989
6272
|
engine.play(sound, { position: point, volume: volume * (rule.volumeScale ?? 1), intensity: Math.min(1, Math.max(0, volume)), ...params ? { params } : {} });
|
|
5990
6273
|
},
|
|
5991
6274
|
update(dt) {
|
|
6275
|
+
for (let i = fading.length - 1; i >= 0; i--) {
|
|
6276
|
+
const entry = fading[i];
|
|
6277
|
+
entry.left -= dt;
|
|
6278
|
+
if (entry.left > 0) continue;
|
|
6279
|
+
entry.handle.stop();
|
|
6280
|
+
fading.splice(i, 1);
|
|
6281
|
+
}
|
|
5992
6282
|
if (!crackles || fires.length === 0 || options.burnLoop === false) return;
|
|
5993
6283
|
const weight = fires.reduce((sum, f) => sum + FIRE_CRACKLE_OF[f.fuel], 0);
|
|
5994
6284
|
if (weight <= 0) return;
|
|
@@ -6014,7 +6304,7 @@ function createDestructionSound(engine, options = {}) {
|
|
|
6014
6304
|
return by;
|
|
6015
6305
|
},
|
|
6016
6306
|
reset,
|
|
6017
|
-
dispose
|
|
6307
|
+
dispose
|
|
6018
6308
|
};
|
|
6019
6309
|
}
|
|
6020
6310
|
|
|
@@ -6076,6 +6366,7 @@ export {
|
|
|
6076
6366
|
DESTRUCTION_SOUND_KEYS,
|
|
6077
6367
|
DRAG_SOUNDS,
|
|
6078
6368
|
EXPLOSION_BOOM,
|
|
6369
|
+
FIRE_FADE_SECONDS,
|
|
6079
6370
|
FIRE_FALLOFF,
|
|
6080
6371
|
FIRE_LOOP,
|
|
6081
6372
|
FIRE_SOUNDS,
|