@adatechnology/game-destruction-three 0.24.0 → 0.24.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.global.js +83 -8
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +83 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -14407,6 +14407,28 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
14407
14407
|
}
|
|
14408
14408
|
};
|
|
14409
14409
|
|
|
14410
|
+
// src/emitter-anchor.ts
|
|
14411
|
+
function anchorOnMesh(THREE, mv, point, normal) {
|
|
14412
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
14413
|
+
const inverse = new THREE.Matrix4().copy(mv.mesh.matrixWorld).invert();
|
|
14414
|
+
const local2 = new THREE.Vector3(point[0], point[1], point[2]).applyMatrix4(inverse);
|
|
14415
|
+
const localNormal = new THREE.Vector3(normal[0], normal[1], normal[2]).transformDirection(inverse);
|
|
14416
|
+
return { mv, local: [local2.x, local2.y, local2.z], localNormal: [localNormal.x, localNormal.y, localNormal.z] };
|
|
14417
|
+
}
|
|
14418
|
+
function inScene(object) {
|
|
14419
|
+
let top = object;
|
|
14420
|
+
while (top.parent) top = top.parent;
|
|
14421
|
+
return top.isScene === true;
|
|
14422
|
+
}
|
|
14423
|
+
function anchorWorld(anchor, shown, point, normal) {
|
|
14424
|
+
const mesh2 = anchor.mv.mesh;
|
|
14425
|
+
if (!shown || !inScene(mesh2)) return false;
|
|
14426
|
+
mesh2.updateWorldMatrix(true, false);
|
|
14427
|
+
point.set(anchor.local[0], anchor.local[1], anchor.local[2]).applyMatrix4(mesh2.matrixWorld);
|
|
14428
|
+
normal.set(anchor.localNormal[0], anchor.localNormal[1], anchor.localNormal[2]).transformDirection(mesh2.matrixWorld);
|
|
14429
|
+
return true;
|
|
14430
|
+
}
|
|
14431
|
+
|
|
14410
14432
|
// src/renderer.ts
|
|
14411
14433
|
var rendererCount = 0;
|
|
14412
14434
|
var COLLAPSE_CLOUD_KG = 1e3;
|
|
@@ -15100,11 +15122,11 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15100
15122
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
15101
15123
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
15102
15124
|
this.settlement.update(dt);
|
|
15125
|
+
this.pieceSys.update(dt);
|
|
15126
|
+
this.fragments.update(dt);
|
|
15103
15127
|
this.updateActive(dt);
|
|
15104
15128
|
this.updateLeaks(dt);
|
|
15105
15129
|
this.updateTrickles(dt);
|
|
15106
|
-
this.pieceSys.update(dt);
|
|
15107
|
-
this.fragments.update(dt);
|
|
15108
15130
|
this.ground.update(dt);
|
|
15109
15131
|
this.ownVfx?.update(dt);
|
|
15110
15132
|
this.syncTransforms();
|
|
@@ -15495,9 +15517,12 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15495
15517
|
break;
|
|
15496
15518
|
}
|
|
15497
15519
|
}
|
|
15520
|
+
/** Where the object's root is now, in the world: a body that tipped or fell is there, not where it was bound. */
|
|
15498
15521
|
rootPoint(objectId) {
|
|
15499
15522
|
const b = this.bounds.get(objectId);
|
|
15500
|
-
|
|
15523
|
+
if (!b) return [0, 0, 0];
|
|
15524
|
+
const p = b.root.getWorldPosition(new this.THREE.Vector3());
|
|
15525
|
+
return [p.x, p.y, p.z];
|
|
15501
15526
|
}
|
|
15502
15527
|
sound(key, point, volume, detail) {
|
|
15503
15528
|
if (detail) this.o.onSound?.(key, point, volume, detail);
|
|
@@ -15663,15 +15688,19 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15663
15688
|
const core = def?.visual?.innerColor;
|
|
15664
15689
|
if (core !== void 0) this.vfx.burst("chips", ev.point, [normal.x, normal.y, normal.z], 5, 2.5, { color: core });
|
|
15665
15690
|
else this.playEvent({ kind: "spall", material: this.impactMaterial(def) }, ev.point);
|
|
15666
|
-
if (core !== void 0) this.trickleFrom(ev.point, [normal.x, normal.y, normal.z], core);
|
|
15691
|
+
if (core !== void 0) this.trickleFrom(ev.point, [normal.x, normal.y, normal.z], core, mv);
|
|
15667
15692
|
if (mv.mesh.userData.drawnSpalls?.includes(ev.part)) return;
|
|
15668
15693
|
this.visuals.addSpall(mv, wp, normal, Math.sqrt(ev.area / Math.PI), core ?? fallbackColor(pv.material, def));
|
|
15669
15694
|
}
|
|
15670
|
-
/**
|
|
15671
|
-
|
|
15695
|
+
/**
|
|
15696
|
+
* 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
|
|
15697
|
+
* 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.
|
|
15698
|
+
*/
|
|
15699
|
+
trickleFrom(point, normal, color, mv) {
|
|
15672
15700
|
if (this.trickles.length >= TRICKLE_MAX) this.trickles.shift();
|
|
15673
15701
|
const total = TRICKLE_SECONDS[0] + (TRICKLE_SECONDS[1] - TRICKLE_SECONDS[0]) * this.rng();
|
|
15674
|
-
|
|
15702
|
+
const anchor = mv ? anchorOnMesh(this.THREE, mv, point, normal) : null;
|
|
15703
|
+
this.trickles.push({ point: [point[0], point[1], point[2]], normal, anchor, color, left: total, total, next: TRICKLE_EVERY });
|
|
15675
15704
|
}
|
|
15676
15705
|
updateTrickles(dt) {
|
|
15677
15706
|
for (let i = this.trickles.length - 1; i >= 0; i--) {
|
|
@@ -15683,6 +15712,14 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15683
15712
|
continue;
|
|
15684
15713
|
}
|
|
15685
15714
|
if (t.next > 0) continue;
|
|
15715
|
+
if (t.anchor) {
|
|
15716
|
+
if (!anchorWorld(t.anchor, this.visuals.shown(t.anchor.mv), this.v1, this.v2)) {
|
|
15717
|
+
this.trickles.splice(i, 1);
|
|
15718
|
+
continue;
|
|
15719
|
+
}
|
|
15720
|
+
t.point = [this.v1.x, this.v1.y, this.v1.z];
|
|
15721
|
+
t.normal = [this.v2.x, this.v2.y, this.v2.z];
|
|
15722
|
+
}
|
|
15686
15723
|
const share = t.left / t.total;
|
|
15687
15724
|
t.next = TRICKLE_EVERY / Math.max(share, 0.25);
|
|
15688
15725
|
const out = [t.normal[0] * 0.2, -1, t.normal[2] * 0.2];
|
|
@@ -15726,7 +15763,9 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15726
15763
|
const tone = 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);
|
|
15727
15764
|
this.fragments.spawn(fr, this.fragments.materialFor(fr.material, tone, false), ev.object, maxAlive);
|
|
15728
15765
|
}
|
|
15729
|
-
if (def?.visual?.innerColor !== void 0 || pv?.material === "concrete" || pv?.material === "brick")
|
|
15766
|
+
if (def?.visual?.innerColor !== void 0 || pv?.material === "concrete" || pv?.material === "brick") {
|
|
15767
|
+
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);
|
|
15768
|
+
}
|
|
15730
15769
|
if (ev.torn) {
|
|
15731
15770
|
this.impactSound(pv?.material ?? "", ev.center, 0.5, ev.blow);
|
|
15732
15771
|
return;
|
|
@@ -15829,6 +15868,41 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15829
15868
|
this.fragments.spawn(fragment, material, objectId, this.maxFragments, true);
|
|
15830
15869
|
});
|
|
15831
15870
|
}
|
|
15871
|
+
/**
|
|
15872
|
+
* 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
|
|
15873
|
+
* part is, as it falls, not where the object stood, and does not end because the part has a new id.
|
|
15874
|
+
*/
|
|
15875
|
+
followSplit(from, to) {
|
|
15876
|
+
for (const part of to.parts.keys()) {
|
|
15877
|
+
const was = `${from.id}|${part}`;
|
|
15878
|
+
const now = `${to.id}|${part}`;
|
|
15879
|
+
const fire2 = this.fires.get(was);
|
|
15880
|
+
if (fire2) {
|
|
15881
|
+
this.fires.delete(was);
|
|
15882
|
+
fire2.object = to.id;
|
|
15883
|
+
this.fires.set(now, fire2);
|
|
15884
|
+
}
|
|
15885
|
+
const sound = this.burnSounds.get(was);
|
|
15886
|
+
if (sound) {
|
|
15887
|
+
this.burnSounds.delete(was);
|
|
15888
|
+
this.burnSounds.set(now, { ...sound, object: to.id });
|
|
15889
|
+
}
|
|
15890
|
+
if (this.active.delete(was)) this.active.set(now, { object: to.id, part });
|
|
15891
|
+
}
|
|
15892
|
+
from.root.updateWorldMatrix(true, false);
|
|
15893
|
+
to.root.updateWorldMatrix(true, false);
|
|
15894
|
+
const into = new this.THREE.Matrix4().copy(to.root.matrixWorld).invert();
|
|
15895
|
+
for (const leak of this.leaks) {
|
|
15896
|
+
if (leak.object !== from.id || !to.parts.has(leak.part)) continue;
|
|
15897
|
+
leak.object = to.id;
|
|
15898
|
+
const point = leak.localPoint ? this.v1.set(...leak.localPoint).applyMatrix4(from.root.matrixWorld) : this.v1.set(...leak.point);
|
|
15899
|
+
const direction = leak.localDirection ? this.v2.set(...leak.localDirection).transformDirection(from.root.matrixWorld) : this.v2.set(...leak.direction);
|
|
15900
|
+
point.applyMatrix4(into);
|
|
15901
|
+
direction.transformDirection(into);
|
|
15902
|
+
leak.localPoint = [point.x, point.y, point.z];
|
|
15903
|
+
leak.localDirection = [direction.x, direction.y, direction.z];
|
|
15904
|
+
}
|
|
15905
|
+
}
|
|
15832
15906
|
/** Turn every loose group of the object (a detach, a collapse) into a piece of its own. */
|
|
15833
15907
|
splitLoose(objectId) {
|
|
15834
15908
|
if (!this.autoSplit) return;
|
|
@@ -15899,6 +15973,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
15899
15973
|
}
|
|
15900
15974
|
this.bounds.set(newId, nb);
|
|
15901
15975
|
for (const pv of nb.parts.values()) this.tagPart(pv, newId);
|
|
15976
|
+
this.followSplit(from, nb);
|
|
15902
15977
|
const meshes = this.meshesOf(nb);
|
|
15903
15978
|
if (meshes.length === 0) return;
|
|
15904
15979
|
const { half, center } = this.measure(group, meshes);
|