@adatechnology/game-destruction-three 0.24.0 → 0.24.2
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.global.js +122 -8
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +85 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -540,6 +540,7 @@ var FragmentSystem = class {
|
|
|
540
540
|
rouse(f) {
|
|
541
541
|
f.asleep = false;
|
|
542
542
|
f.rest = 0;
|
|
543
|
+
f.floor = null;
|
|
543
544
|
f.mesh.matrixAutoUpdate = true;
|
|
544
545
|
}
|
|
545
546
|
/** What lies inside the disc looks at the ground again: it was dug or heaped under it. */
|
|
@@ -585,6 +586,7 @@ var FragmentSystem = class {
|
|
|
585
586
|
if (!f.asleep || f.dying) continue;
|
|
586
587
|
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
587
588
|
const ext = Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z;
|
|
589
|
+
f.floor = null;
|
|
588
590
|
if (f.mesh.position.y - ext > this.floorUnder(f) + SUPPORT_GAP) this.rouse(f);
|
|
589
591
|
}
|
|
590
592
|
}
|
|
@@ -3547,6 +3549,28 @@ var SettlementView = class {
|
|
|
3547
3549
|
}
|
|
3548
3550
|
};
|
|
3549
3551
|
|
|
3552
|
+
// src/emitter-anchor.ts
|
|
3553
|
+
function anchorOnMesh(THREE, mv, point, normal) {
|
|
3554
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
3555
|
+
const inverse = new THREE.Matrix4().copy(mv.mesh.matrixWorld).invert();
|
|
3556
|
+
const local = new THREE.Vector3(point[0], point[1], point[2]).applyMatrix4(inverse);
|
|
3557
|
+
const localNormal = new THREE.Vector3(normal[0], normal[1], normal[2]).transformDirection(inverse);
|
|
3558
|
+
return { mv, local: [local.x, local.y, local.z], localNormal: [localNormal.x, localNormal.y, localNormal.z] };
|
|
3559
|
+
}
|
|
3560
|
+
function inScene(object) {
|
|
3561
|
+
let top = object;
|
|
3562
|
+
while (top.parent) top = top.parent;
|
|
3563
|
+
return top.isScene === true;
|
|
3564
|
+
}
|
|
3565
|
+
function anchorWorld(anchor, shown, point, normal) {
|
|
3566
|
+
const mesh = anchor.mv.mesh;
|
|
3567
|
+
if (!shown || !inScene(mesh)) return false;
|
|
3568
|
+
mesh.updateWorldMatrix(true, false);
|
|
3569
|
+
point.set(anchor.local[0], anchor.local[1], anchor.local[2]).applyMatrix4(mesh.matrixWorld);
|
|
3570
|
+
normal.set(anchor.localNormal[0], anchor.localNormal[1], anchor.localNormal[2]).transformDirection(mesh.matrixWorld);
|
|
3571
|
+
return true;
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3550
3574
|
// src/renderer.ts
|
|
3551
3575
|
var rendererCount = 0;
|
|
3552
3576
|
var COLLAPSE_CLOUD_KG = 1e3;
|
|
@@ -4240,11 +4264,11 @@ var Renderer = class {
|
|
|
4240
4264
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
4241
4265
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
4242
4266
|
this.settlement.update(dt);
|
|
4267
|
+
this.pieceSys.update(dt);
|
|
4268
|
+
this.fragments.update(dt);
|
|
4243
4269
|
this.updateActive(dt);
|
|
4244
4270
|
this.updateLeaks(dt);
|
|
4245
4271
|
this.updateTrickles(dt);
|
|
4246
|
-
this.pieceSys.update(dt);
|
|
4247
|
-
this.fragments.update(dt);
|
|
4248
4272
|
this.ground.update(dt);
|
|
4249
4273
|
this.ownVfx?.update(dt);
|
|
4250
4274
|
this.syncTransforms();
|
|
@@ -4635,9 +4659,12 @@ var Renderer = class {
|
|
|
4635
4659
|
break;
|
|
4636
4660
|
}
|
|
4637
4661
|
}
|
|
4662
|
+
/** Where the object's root is now, in the world: a body that tipped or fell is there, not where it was bound. */
|
|
4638
4663
|
rootPoint(objectId) {
|
|
4639
4664
|
const b = this.bounds.get(objectId);
|
|
4640
|
-
|
|
4665
|
+
if (!b) return [0, 0, 0];
|
|
4666
|
+
const p = b.root.getWorldPosition(new this.THREE.Vector3());
|
|
4667
|
+
return [p.x, p.y, p.z];
|
|
4641
4668
|
}
|
|
4642
4669
|
sound(key, point, volume, detail) {
|
|
4643
4670
|
if (detail) this.o.onSound?.(key, point, volume, detail);
|
|
@@ -4803,15 +4830,19 @@ var Renderer = class {
|
|
|
4803
4830
|
const core = def?.visual?.innerColor;
|
|
4804
4831
|
if (core !== void 0) this.vfx.burst("chips", ev.point, [normal.x, normal.y, normal.z], 5, 2.5, { color: core });
|
|
4805
4832
|
else this.playEvent({ kind: "spall", material: this.impactMaterial(def) }, ev.point);
|
|
4806
|
-
if (core !== void 0) this.trickleFrom(ev.point, [normal.x, normal.y, normal.z], core);
|
|
4833
|
+
if (core !== void 0) this.trickleFrom(ev.point, [normal.x, normal.y, normal.z], core, mv);
|
|
4807
4834
|
if (mv.mesh.userData.drawnSpalls?.includes(ev.part)) return;
|
|
4808
4835
|
this.visuals.addSpall(mv, wp, normal, Math.sqrt(ev.area / Math.PI), core ?? fallbackColor(pv.material, def));
|
|
4809
4836
|
}
|
|
4810
|
-
/**
|
|
4811
|
-
|
|
4837
|
+
/**
|
|
4838
|
+
* Grit and dust go on falling from where a blow broke a hard face (masonry, concrete, wood) for `TRICKLE_SECONDS`, a pinch at a time and less and
|
|
4839
|
+
* less. The place is held on the mesh it broke on (`mv`), so it falls with the object when it tips or a piece of it comes away.
|
|
4840
|
+
*/
|
|
4841
|
+
trickleFrom(point, normal, color, mv) {
|
|
4812
4842
|
if (this.trickles.length >= TRICKLE_MAX) this.trickles.shift();
|
|
4813
4843
|
const total = TRICKLE_SECONDS[0] + (TRICKLE_SECONDS[1] - TRICKLE_SECONDS[0]) * this.rng();
|
|
4814
|
-
|
|
4844
|
+
const anchor = mv ? anchorOnMesh(this.THREE, mv, point, normal) : null;
|
|
4845
|
+
this.trickles.push({ point: [point[0], point[1], point[2]], normal, anchor, color, left: total, total, next: TRICKLE_EVERY });
|
|
4815
4846
|
}
|
|
4816
4847
|
updateTrickles(dt) {
|
|
4817
4848
|
for (let i = this.trickles.length - 1; i >= 0; i--) {
|
|
@@ -4823,6 +4854,14 @@ var Renderer = class {
|
|
|
4823
4854
|
continue;
|
|
4824
4855
|
}
|
|
4825
4856
|
if (t.next > 0) continue;
|
|
4857
|
+
if (t.anchor) {
|
|
4858
|
+
if (!anchorWorld(t.anchor, this.visuals.shown(t.anchor.mv), this.v1, this.v2)) {
|
|
4859
|
+
this.trickles.splice(i, 1);
|
|
4860
|
+
continue;
|
|
4861
|
+
}
|
|
4862
|
+
t.point = [this.v1.x, this.v1.y, this.v1.z];
|
|
4863
|
+
t.normal = [this.v2.x, this.v2.y, this.v2.z];
|
|
4864
|
+
}
|
|
4826
4865
|
const share = t.left / t.total;
|
|
4827
4866
|
t.next = TRICKLE_EVERY / Math.max(share, 0.25);
|
|
4828
4867
|
const out = [t.normal[0] * 0.2, -1, t.normal[2] * 0.2];
|
|
@@ -4866,7 +4905,9 @@ var Renderer = class {
|
|
|
4866
4905
|
const tone3 = fr.unit && fdef?.visual?.unitColor !== void 0 ? fdef.visual.unitColor : fr.inner && fdef?.visual?.innerColor !== void 0 ? fdef.visual.innerColor : fdef === def ? color : fallbackColor(fr.material, fdef);
|
|
4867
4906
|
this.fragments.spawn(fr, this.fragments.materialFor(fr.material, tone3, false), ev.object, maxAlive);
|
|
4868
4907
|
}
|
|
4869
|
-
if (def?.visual?.innerColor !== void 0 || pv?.material === "concrete" || pv?.material === "brick")
|
|
4908
|
+
if (def?.visual?.innerColor !== void 0 || pv?.material === "concrete" || pv?.material === "brick") {
|
|
4909
|
+
this.trickleFrom(ev.center, [0, 0, 0], color, pv ? this.nearestMesh(pv, new this.THREE.Vector3(ev.center[0], ev.center[1], ev.center[2])) : null);
|
|
4910
|
+
}
|
|
4870
4911
|
if (ev.torn) {
|
|
4871
4912
|
this.impactSound(pv?.material ?? "", ev.center, 0.5, ev.blow);
|
|
4872
4913
|
return;
|
|
@@ -4969,6 +5010,41 @@ var Renderer = class {
|
|
|
4969
5010
|
this.fragments.spawn(fragment, material, objectId, this.maxFragments, true);
|
|
4970
5011
|
});
|
|
4971
5012
|
}
|
|
5013
|
+
/**
|
|
5014
|
+
* What goes on at a part (its fire, its leak, its burn sound, its heat) moves with the part to the object a split made of it: it goes on where the
|
|
5015
|
+
* part is, as it falls, not where the object stood, and does not end because the part has a new id.
|
|
5016
|
+
*/
|
|
5017
|
+
followSplit(from, to) {
|
|
5018
|
+
for (const part of to.parts.keys()) {
|
|
5019
|
+
const was = `${from.id}|${part}`;
|
|
5020
|
+
const now = `${to.id}|${part}`;
|
|
5021
|
+
const fire2 = this.fires.get(was);
|
|
5022
|
+
if (fire2) {
|
|
5023
|
+
this.fires.delete(was);
|
|
5024
|
+
fire2.object = to.id;
|
|
5025
|
+
this.fires.set(now, fire2);
|
|
5026
|
+
}
|
|
5027
|
+
const sound = this.burnSounds.get(was);
|
|
5028
|
+
if (sound) {
|
|
5029
|
+
this.burnSounds.delete(was);
|
|
5030
|
+
this.burnSounds.set(now, { ...sound, object: to.id });
|
|
5031
|
+
}
|
|
5032
|
+
if (this.active.delete(was)) this.active.set(now, { object: to.id, part });
|
|
5033
|
+
}
|
|
5034
|
+
from.root.updateWorldMatrix(true, false);
|
|
5035
|
+
to.root.updateWorldMatrix(true, false);
|
|
5036
|
+
const into = new this.THREE.Matrix4().copy(to.root.matrixWorld).invert();
|
|
5037
|
+
for (const leak of this.leaks) {
|
|
5038
|
+
if (leak.object !== from.id || !to.parts.has(leak.part)) continue;
|
|
5039
|
+
leak.object = to.id;
|
|
5040
|
+
const point = leak.localPoint ? this.v1.set(...leak.localPoint).applyMatrix4(from.root.matrixWorld) : this.v1.set(...leak.point);
|
|
5041
|
+
const direction = leak.localDirection ? this.v2.set(...leak.localDirection).transformDirection(from.root.matrixWorld) : this.v2.set(...leak.direction);
|
|
5042
|
+
point.applyMatrix4(into);
|
|
5043
|
+
direction.transformDirection(into);
|
|
5044
|
+
leak.localPoint = [point.x, point.y, point.z];
|
|
5045
|
+
leak.localDirection = [direction.x, direction.y, direction.z];
|
|
5046
|
+
}
|
|
5047
|
+
}
|
|
4972
5048
|
/** Turn every loose group of the object (a detach, a collapse) into a piece of its own. */
|
|
4973
5049
|
splitLoose(objectId) {
|
|
4974
5050
|
if (!this.autoSplit) return;
|
|
@@ -5039,6 +5115,7 @@ var Renderer = class {
|
|
|
5039
5115
|
}
|
|
5040
5116
|
this.bounds.set(newId, nb);
|
|
5041
5117
|
for (const pv of nb.parts.values()) this.tagPart(pv, newId);
|
|
5118
|
+
this.followSplit(from, nb);
|
|
5042
5119
|
const meshes = this.meshesOf(nb);
|
|
5043
5120
|
if (meshes.length === 0) return;
|
|
5044
5121
|
const { half, center } = this.measure(group, meshes);
|