@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.d.ts
CHANGED
|
@@ -482,6 +482,8 @@ declare const DEFAULT_FIRE: {
|
|
|
482
482
|
readonly perFire: 0.08;
|
|
483
483
|
readonly max: 0.45;
|
|
484
484
|
};
|
|
485
|
+
/** A fire loop that ends fades out over this many seconds (moved on by `update`) before it is stopped. */
|
|
486
|
+
declare const FIRE_FADE_SECONDS = 0.4;
|
|
485
487
|
declare const DEFAULT_CRACKLES: {
|
|
486
488
|
readonly base: 2;
|
|
487
489
|
readonly perSqrtFire: 3;
|
|
@@ -525,4 +527,4 @@ declare function blastFireSampleBank(manifest: SfxManifest, options?: BlastFireS
|
|
|
525
527
|
/** Every particle kind the renderer can emit (the game's sprite kinds, see `@adatechnology/game-vfx`). */
|
|
526
528
|
type ParticleKind = SpriteKind;
|
|
527
529
|
|
|
528
|
-
export { BIG_BLAST_RADIUS, BLAST_FALLOFF, BLAST_FAR_DISTANCE, BLAST_FAR_FALLOFF, BLAST_FIRE_SAMPLES, BLAST_KINDS, BLAST_KIND_OF, BLAST_SOUNDS, BLAST_SOUND_OF, BURN_LOOP, type BindOptions, type BlastFireSampleBankOptions, type BlastFireSampleDefaults, type BlastKind, DEFAULT_CRACKLES, DEFAULT_FIRE, DEFAULT_INDOOR_CONFINEMENT, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, DRAG_SOUNDS, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EXPLOSION_BOOM, type ExplodeOptions, FIRE_FALLOFF, FIRE_LOOP, FIRE_SOUNDS, type FragmentLifeRule, GRENADE_PIN_PULL, IMPACT_FAMILY_TAGS, IMPACT_SOUNDS, IMPACT_SOUND_KEYS, type ImpactFamily, type ImpactKeys, type LooseBody, type MakePieceOptions, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, ROCKET_MOTOR_LOOP, type RendererOptions, SCENE_SOUNDS, SMOKE_HISS_LOOP, type SolidBox, type SoundDetail, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, blastFireSampleBank, breakSoundKeys, createDestructionRenderer, createDestructionSound, dragSoundKey, heatColor, impactFamily, impactKey, impactSoundIds, impactSoundKeys, ricochetSoundKeys, shotKey, specFromObject3D };
|
|
530
|
+
export { BIG_BLAST_RADIUS, BLAST_FALLOFF, BLAST_FAR_DISTANCE, BLAST_FAR_FALLOFF, BLAST_FIRE_SAMPLES, BLAST_KINDS, BLAST_KIND_OF, BLAST_SOUNDS, BLAST_SOUND_OF, BURN_LOOP, type BindOptions, type BlastFireSampleBankOptions, type BlastFireSampleDefaults, type BlastKind, DEFAULT_CRACKLES, DEFAULT_FIRE, DEFAULT_INDOOR_CONFINEMENT, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, DRAG_SOUNDS, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EXPLOSION_BOOM, type ExplodeOptions, FIRE_FADE_SECONDS, FIRE_FALLOFF, FIRE_LOOP, FIRE_SOUNDS, type FragmentLifeRule, GRENADE_PIN_PULL, IMPACT_FAMILY_TAGS, IMPACT_SOUNDS, IMPACT_SOUND_KEYS, type ImpactFamily, type ImpactKeys, type LooseBody, type MakePieceOptions, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, ROCKET_MOTOR_LOOP, type RendererOptions, SCENE_SOUNDS, SMOKE_HISS_LOOP, type SolidBox, type SoundDetail, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, blastFireSampleBank, breakSoundKeys, createDestructionRenderer, createDestructionSound, dragSoundKey, heatColor, impactFamily, impactKey, impactSoundIds, impactSoundKeys, ricochetSoundKeys, shotKey, specFromObject3D };
|
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
|
}
|
|
@@ -11389,10 +11413,24 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
11389
11413
|
maxSettlement: 0.05,
|
|
11390
11414
|
crackDistortion: 1 / 300,
|
|
11391
11415
|
damageDistortion: 1 / 150,
|
|
11416
|
+
bearingCrackDistortion: 1 / 500,
|
|
11417
|
+
bearingDamageDistortion: 1 / 300,
|
|
11392
11418
|
distortionDamage: 0.3,
|
|
11393
11419
|
bridgeSpanDepth: 10,
|
|
11394
11420
|
beamRebarRatio: 4e-3
|
|
11395
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
|
+
};
|
|
11396
11434
|
var WIND_DEFAULTS = {
|
|
11397
11435
|
speed: 40,
|
|
11398
11436
|
direction: [1, 0, 0],
|
|
@@ -12743,6 +12781,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
12743
12781
|
};
|
|
12744
12782
|
var RESTING_HOLD_COS = Math.cos(Math.PI / 6);
|
|
12745
12783
|
var BLAST_REFERENCE_RESISTANCE = 200 * 1900 * 0.13;
|
|
12784
|
+
var ARCH_ANGLE = Math.PI / 3;
|
|
12746
12785
|
var assemblies_default = [
|
|
12747
12786
|
{
|
|
12748
12787
|
id: "brick_wall_plastered",
|
|
@@ -13080,6 +13119,47 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13080
13119
|
return Math.sqrt(nearest) * nearestScale;
|
|
13081
13120
|
}
|
|
13082
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
|
+
|
|
13083
13163
|
// src/visual.ts
|
|
13084
13164
|
var POS_ATTR = "position";
|
|
13085
13165
|
function positionAttr(geo) {
|
|
@@ -13184,6 +13264,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13184
13264
|
}
|
|
13185
13265
|
};
|
|
13186
13266
|
var DECAL_SNAP = 0.03;
|
|
13267
|
+
var STAIR_CRACK_LIFT = 2e-3;
|
|
13268
|
+
var STAIR_CRACK_TAPER = 0.35;
|
|
13187
13269
|
var Visuals = class {
|
|
13188
13270
|
constructor(THREE, lowQuality, decalCap) {
|
|
13189
13271
|
__publicField(this, "THREE", THREE);
|
|
@@ -13677,6 +13759,71 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
13677
13759
|
lines.renderOrder = 2;
|
|
13678
13760
|
this.addDecal(mv, { obj: lines, geometry: geo });
|
|
13679
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
|
+
}
|
|
13680
13827
|
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
13681
13828
|
// Char and heat glow
|
|
13682
13829
|
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
@@ -14072,6 +14219,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14072
14219
|
}
|
|
14073
14220
|
restorePart(pv) {
|
|
14074
14221
|
for (const mv of pv.meshes) this.restoreMesh(mv);
|
|
14222
|
+
delete pv.settled;
|
|
14075
14223
|
pv.charApplied = 0;
|
|
14076
14224
|
pv.glowApplied = 0;
|
|
14077
14225
|
pv.meltApplied = 0;
|
|
@@ -14082,6 +14230,77 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14082
14230
|
}
|
|
14083
14231
|
};
|
|
14084
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
|
+
|
|
14085
14304
|
// src/renderer.ts
|
|
14086
14305
|
var rendererCount = 0;
|
|
14087
14306
|
var COLLAPSE_CLOUD_KG = 1e3;
|
|
@@ -14091,6 +14310,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14091
14310
|
var WOOD_RIM = 1.5;
|
|
14092
14311
|
var IMPACT_TAGS = ["metal", "glass", "wood"];
|
|
14093
14312
|
var GLOW_FROM_C = 430;
|
|
14313
|
+
var MIN_DRAWN_CRACK_WIDTH = 4e-3;
|
|
14314
|
+
var SETTLEMENT_CRACK_COLOR = 2827296;
|
|
14094
14315
|
var QUEUE_CAP = 4e3;
|
|
14095
14316
|
var TRICKLE_SECONDS = [2, 5];
|
|
14096
14317
|
var TRICKLE_EVERY = 0.25;
|
|
@@ -14310,6 +14531,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14310
14531
|
});
|
|
14311
14532
|
__publicField(this, "unsubscribe");
|
|
14312
14533
|
__publicField(this, "visuals");
|
|
14534
|
+
/** The parts the ground went down under, drawn going down (`subside`). */
|
|
14535
|
+
__publicField(this, "settlement");
|
|
14313
14536
|
__publicField(this, "fragments");
|
|
14314
14537
|
__publicField(this, "ground");
|
|
14315
14538
|
__publicField(this, "pieceSys");
|
|
@@ -14318,6 +14541,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14318
14541
|
__publicField(this, "fires", /* @__PURE__ */ new Map());
|
|
14319
14542
|
/** Primed parts burning in the effects world until they go off: their burn loop ends when they are put out. */
|
|
14320
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());
|
|
14321
14546
|
__publicField(this, "leaks", []);
|
|
14322
14547
|
__publicField(this, "homeTags", []);
|
|
14323
14548
|
__publicField(this, "throttles", /* @__PURE__ */ new Map());
|
|
@@ -14352,6 +14577,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14352
14577
|
this.v2 = new THREE.Vector3();
|
|
14353
14578
|
const maxParticles = Math.max(8, Math.floor((o.maxParticles ?? 2500) * (this.low ? 0.5 : 1)));
|
|
14354
14579
|
this.visuals = new Visuals(THREE, this.low, 600);
|
|
14580
|
+
this.settlement = new SettlementView(THREE, this.visuals);
|
|
14355
14581
|
this.ground = new GroundSpots(THREE, o.scene, this.groundAt, 48);
|
|
14356
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");
|
|
14357
14583
|
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 +14592,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14366
14592
|
gravity: this.gravity,
|
|
14367
14593
|
max: this.maxFragments,
|
|
14368
14594
|
life: o.fragmentLife ?? 12,
|
|
14369
|
-
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"
|
|
14370
14597
|
});
|
|
14371
14598
|
this.cages = new RebarCages(THREE, o.scene);
|
|
14372
14599
|
this.pieceSys = new PieceSystem(THREE, {
|
|
@@ -14761,6 +14988,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14761
14988
|
this.checkBroken();
|
|
14762
14989
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
14763
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);
|
|
14764
14992
|
this.updateActive(dt);
|
|
14765
14993
|
this.updateLeaks(dt);
|
|
14766
14994
|
this.updateTrickles(dt);
|
|
@@ -14836,6 +15064,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14836
15064
|
node.quaternion.set(q[0], q[1], q[2], q[3]);
|
|
14837
15065
|
node.updateMatrixWorld(true);
|
|
14838
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
|
+
}
|
|
14839
15079
|
syncTransforms() {
|
|
14840
15080
|
for (const b of this.bounds.values()) this.syncOne(b);
|
|
14841
15081
|
}
|
|
@@ -14986,9 +15226,15 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14986
15226
|
case "debris":
|
|
14987
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));
|
|
14988
15228
|
break;
|
|
14989
|
-
case "fracture":
|
|
15229
|
+
case "fracture": {
|
|
15230
|
+
const pv = this.partVis(ev.object, ev.part);
|
|
15231
|
+
if (pv) this.settlement.forget(pv);
|
|
14990
15232
|
this.onFracture(ev);
|
|
14991
15233
|
break;
|
|
15234
|
+
}
|
|
15235
|
+
case "subside":
|
|
15236
|
+
this.onSubside(ev.object);
|
|
15237
|
+
break;
|
|
14992
15238
|
case "detach":
|
|
14993
15239
|
this.onDetach(ev);
|
|
14994
15240
|
break;
|
|
@@ -14998,6 +15244,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14998
15244
|
case "collapse": {
|
|
14999
15245
|
const root = this.bounds.get(ev.object)?.root;
|
|
15000
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
|
+
}
|
|
15001
15251
|
this.splitLoose(ev.object);
|
|
15002
15252
|
if (!furniture || ev.mass >= COLLAPSE_CLOUD_KG) this.playEvent({ kind: "collapse" }, this.rootPoint(ev.object));
|
|
15003
15253
|
else this.vfx.burst("dust", this.rootPoint(ev.object), [0, 1, 0], clamp6(Math.round(ev.mass / 4), 4, 24), 0.8);
|
|
@@ -15015,7 +15265,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15015
15265
|
this.startFire(ev);
|
|
15016
15266
|
this.activate(ev.object, ev.part);
|
|
15017
15267
|
this.sound("ignite", ev.point, 0.7);
|
|
15018
|
-
this.
|
|
15268
|
+
this.startBurnSound(ev.object, ev.part, ev.point, this.burning(ev.object, ev.part));
|
|
15019
15269
|
break;
|
|
15020
15270
|
case "primed":
|
|
15021
15271
|
if (ev.trigger !== "explosion") {
|
|
@@ -15023,7 +15273,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15023
15273
|
this.primedBurning.add(`${ev.object}|${ev.part}`);
|
|
15024
15274
|
this.activate(ev.object, ev.part);
|
|
15025
15275
|
this.sound("primed", ev.point, 0.7, { seconds: ev.delay });
|
|
15026
|
-
this.
|
|
15276
|
+
if (!this.burnSounds.has(`${ev.object}|${ev.part}`)) this.startBurnSound(ev.object, ev.part, ev.point, { fuel: "gas" });
|
|
15027
15277
|
}
|
|
15028
15278
|
break;
|
|
15029
15279
|
case "spall":
|
|
@@ -15045,20 +15295,20 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15045
15295
|
break;
|
|
15046
15296
|
case "extinguish": {
|
|
15047
15297
|
const f = this.fires.get(`${ev.object}|${ev.part}`);
|
|
15048
|
-
|
|
15298
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15049
15299
|
if (f) {
|
|
15050
15300
|
this.stopFire(`${ev.object}|${ev.part}`);
|
|
15051
15301
|
this.vfx.burst("steam", f.point, [0, 1, 0], 14, 1.2);
|
|
15052
15302
|
}
|
|
15053
|
-
|
|
15303
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15054
15304
|
this.activate(ev.object, ev.part);
|
|
15055
15305
|
this.sound("extinguish", f?.point ?? this.rootPoint(ev.object), 0.6);
|
|
15056
15306
|
break;
|
|
15057
15307
|
}
|
|
15058
15308
|
case "burnout": {
|
|
15059
15309
|
this.stopFire(`${ev.object}|${ev.part}`);
|
|
15060
|
-
|
|
15061
|
-
this.
|
|
15310
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15311
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15062
15312
|
this.vfx.burst("ash", ev.point, [0, 1, 0], 16, 1);
|
|
15063
15313
|
this.vfx.burst("smoke", ev.point, [0, 1, 0], 6, 0.8, { color: SMOKE_TONES.grey });
|
|
15064
15314
|
const pv = this.partVis(ev.object, ev.part);
|
|
@@ -15126,7 +15376,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15126
15376
|
break;
|
|
15127
15377
|
}
|
|
15128
15378
|
case "explode":
|
|
15129
|
-
|
|
15379
|
+
this.primedBurning.delete(`${ev.object}|${ev.part}`);
|
|
15380
|
+
this.endBurnSound(`${ev.object}|${ev.part}`);
|
|
15130
15381
|
this.onExplode(ev);
|
|
15131
15382
|
break;
|
|
15132
15383
|
case "destroyed":
|
|
@@ -15245,7 +15496,20 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15245
15496
|
const pv = b?.parts.get(ev.part);
|
|
15246
15497
|
if (!b || !pv) return;
|
|
15247
15498
|
const def = this.world.materials.get(pv.material);
|
|
15248
|
-
|
|
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) {
|
|
15249
15513
|
const wp = new this.THREE.Vector3(ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
15250
15514
|
const mv = this.nearestMesh(pv, wp);
|
|
15251
15515
|
const seed = hashNumbers(ev.time, ev.worldPoint[0], ev.worldPoint[1], ev.worldPoint[2]);
|
|
@@ -15815,9 +16079,25 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15815
16079
|
}
|
|
15816
16080
|
stopFire(key) {
|
|
15817
16081
|
const fire2 = this.fires.get(key);
|
|
15818
|
-
if (
|
|
15819
|
-
|
|
15820
|
-
|
|
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);
|
|
15821
16101
|
}
|
|
15822
16102
|
// ----------------------------------------------------------------------------------------------------------------------------------
|
|
15823
16103
|
// Fire, heat, char, melt, leaks
|
|
@@ -15843,6 +16123,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15843
16123
|
const ps = pv ? this.world.part(a.object, a.part) : null;
|
|
15844
16124
|
if (!pv || !ps) {
|
|
15845
16125
|
this.active.delete(key);
|
|
16126
|
+
this.stopFire(key);
|
|
15846
16127
|
continue;
|
|
15847
16128
|
}
|
|
15848
16129
|
const def = this.world.materials.get(pv.material);
|
|
@@ -15962,6 +16243,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15962
16243
|
for (const home of homes) this.restoreHome(home);
|
|
15963
16244
|
for (const [key, a] of [...this.active]) if (homes.has(a.object)) this.active.delete(key);
|
|
15964
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);
|
|
15965
16247
|
for (let i = this.leaks.length - 1; i >= 0; i--) if (homes.has(this.leaks[i].object)) this.leaks.splice(i, 1);
|
|
15966
16248
|
for (const home of homes) {
|
|
15967
16249
|
this.fragments.removeHome(home);
|
|
@@ -15974,6 +16256,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15974
16256
|
for (const b of [...this.bounds.values()]) {
|
|
15975
16257
|
for (const [pid, pv] of [...b.parts]) {
|
|
15976
16258
|
if (pv.home !== home) continue;
|
|
16259
|
+
this.settlement.forget(pv);
|
|
15977
16260
|
this.visuals.restorePart(pv);
|
|
15978
16261
|
this.tagPart(pv, home);
|
|
15979
16262
|
if (b !== homeBound && homeBound) {
|
|
@@ -15995,8 +16278,10 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15995
16278
|
this.slices.length = 0;
|
|
15996
16279
|
this.active.clear();
|
|
15997
16280
|
for (const key of [...this.fires.keys()]) this.stopFire(key);
|
|
16281
|
+
for (const key of [...this.burnSounds.keys()]) this.endBurnSound(key);
|
|
15998
16282
|
this.leaks.length = 0;
|
|
15999
16283
|
this.trickles.length = 0;
|
|
16284
|
+
this.settlement.clear();
|
|
16000
16285
|
for (const id of [...this.bounds.keys()]) if (this.bounds.has(id)) this.restore(id);
|
|
16001
16286
|
for (const b of [...this.bounds.values()]) {
|
|
16002
16287
|
if (b.isSplit) {
|
|
@@ -18185,6 +18470,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18185
18470
|
}
|
|
18186
18471
|
};
|
|
18187
18472
|
var DEFAULT_FIRE = { perFire: 0.08, max: 0.45 };
|
|
18473
|
+
var FIRE_FADE_SECONDS = 0.4;
|
|
18188
18474
|
var DEFAULT_CRACKLES = { base: 2, perSqrtFire: 3, max: 14, volume: 0.5 };
|
|
18189
18475
|
var DEFAULT_INDOOR_CONFINEMENT = 1.3;
|
|
18190
18476
|
function createDestructionSound(engine, options = {}) {
|
|
@@ -18206,6 +18492,11 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18206
18492
|
const loops = /* @__PURE__ */ new Map();
|
|
18207
18493
|
const fires = [];
|
|
18208
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
|
+
};
|
|
18209
18500
|
const fuelFor = (detail) => detail?.fuel ?? (detail?.material !== void 0 ? fuelOf[detail.material] : void 0) ?? defaultFuel;
|
|
18210
18501
|
const setFire = () => {
|
|
18211
18502
|
if (options.burnLoop === false) return;
|
|
@@ -18216,7 +18507,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18216
18507
|
}
|
|
18217
18508
|
for (const [id, handle] of loops) {
|
|
18218
18509
|
if (count.has(id)) continue;
|
|
18219
|
-
handle
|
|
18510
|
+
fadeOut(handle);
|
|
18220
18511
|
loops.delete(id);
|
|
18221
18512
|
}
|
|
18222
18513
|
for (const [id, n] of count) {
|
|
@@ -18243,8 +18534,15 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18243
18534
|
else if (best >= 0) fires.splice(best, 1);
|
|
18244
18535
|
};
|
|
18245
18536
|
const reset = () => {
|
|
18537
|
+
for (const handle of loops.values()) fadeOut(handle);
|
|
18538
|
+
loops.clear();
|
|
18539
|
+
fires.length = 0;
|
|
18540
|
+
};
|
|
18541
|
+
const dispose = () => {
|
|
18246
18542
|
for (const handle of loops.values()) handle.stop();
|
|
18247
18543
|
loops.clear();
|
|
18544
|
+
for (const { handle } of fading) handle.stop();
|
|
18545
|
+
fading.length = 0;
|
|
18248
18546
|
fires.length = 0;
|
|
18249
18547
|
};
|
|
18250
18548
|
const blastSound = (point, volume, detail) => {
|
|
@@ -18291,6 +18589,13 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18291
18589
|
engine.play(sound, { position: point, volume: volume * (rule.volumeScale ?? 1), intensity: Math.min(1, Math.max(0, volume)), ...params ? { params } : {} });
|
|
18292
18590
|
},
|
|
18293
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
|
+
}
|
|
18294
18599
|
if (!crackles || fires.length === 0 || options.burnLoop === false) return;
|
|
18295
18600
|
const weight = fires.reduce((sum, f) => sum + FIRE_CRACKLE_OF[f.fuel], 0);
|
|
18296
18601
|
if (weight <= 0) return;
|
|
@@ -18316,7 +18621,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
18316
18621
|
return by;
|
|
18317
18622
|
},
|
|
18318
18623
|
reset,
|
|
18319
|
-
dispose
|
|
18624
|
+
dispose
|
|
18320
18625
|
};
|
|
18321
18626
|
}
|
|
18322
18627
|
|