@adatechnology/game-destruction-three 0.23.0 → 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.global.js +36 -5
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +36 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -284,6 +284,7 @@ var BUILDERS = {
|
|
|
284
284
|
board: buildBrokenBoardGeometry,
|
|
285
285
|
rubble: buildRubbleGeometry
|
|
286
286
|
};
|
|
287
|
+
var FLOOR_REMEASURE = 0.5;
|
|
287
288
|
var SHEET_MAX = 4e-3;
|
|
288
289
|
var SHEET_AIR = 2.5;
|
|
289
290
|
var SHEET_SWAY = 3;
|
|
@@ -473,6 +474,7 @@ var FragmentSystem = class {
|
|
|
473
474
|
this.o.scene.add(mesh);
|
|
474
475
|
const live = {
|
|
475
476
|
mesh,
|
|
477
|
+
floor: null,
|
|
476
478
|
home,
|
|
477
479
|
vel: new this.THREE.Vector3(f.velocity[0], f.velocity[1], f.velocity[2]),
|
|
478
480
|
ang: new this.THREE.Vector3(f.angularVelocity[0], f.angularVelocity[1], f.angularVelocity[2]),
|
|
@@ -489,7 +491,7 @@ var FragmentSystem = class {
|
|
|
489
491
|
born: this.tick,
|
|
490
492
|
life: lasting ? 0 : Math.max(0, typeof this.o.life === "function" ? this.o.life(f, home) : this.o.life)
|
|
491
493
|
};
|
|
492
|
-
if (lasting ||
|
|
494
|
+
if (lasting || isBig(f.size)) {
|
|
493
495
|
live.body = {
|
|
494
496
|
mass: f.mass,
|
|
495
497
|
push: (x, z) => {
|
|
@@ -583,9 +585,19 @@ var FragmentSystem = class {
|
|
|
583
585
|
if (!f.asleep || f.dying) continue;
|
|
584
586
|
const e = this.m.makeRotationFromQuaternion(f.mesh.quaternion).elements;
|
|
585
587
|
const ext = Math.abs(e[1]) * f.half.x + Math.abs(e[5]) * f.half.y + Math.abs(e[9]) * f.half.z;
|
|
586
|
-
if (f.mesh.position.y - ext > this.
|
|
588
|
+
if (f.mesh.position.y - ext > this.floorUnder(f) + SUPPORT_GAP) this.rouse(f);
|
|
587
589
|
}
|
|
588
590
|
}
|
|
591
|
+
/** 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). */
|
|
592
|
+
floorUnder(f) {
|
|
593
|
+
const p = f.mesh.position;
|
|
594
|
+
if (!this.o.surfaceAt) return this.o.groundAt(p.x, p.z);
|
|
595
|
+
const at = f.floor;
|
|
596
|
+
if (!at || Math.abs(at.x - p.x) > FLOOR_REMEASURE || Math.abs(at.z - p.z) > FLOOR_REMEASURE || p.y < at.y - FLOOR_REMEASURE) {
|
|
597
|
+
f.floor = { x: p.x, z: p.z, y: this.o.surfaceAt(p.x, p.y, p.z) };
|
|
598
|
+
}
|
|
599
|
+
return f.floor.y;
|
|
600
|
+
}
|
|
589
601
|
step(f, dt, g) {
|
|
590
602
|
const mesh = f.mesh;
|
|
591
603
|
f.vel.y -= g * dt;
|
|
@@ -600,7 +612,7 @@ var FragmentSystem = class {
|
|
|
600
612
|
const h = f.half;
|
|
601
613
|
const sc = f.dying ? f.fade : 1;
|
|
602
614
|
const ext = (Math.abs(e[1]) * h.x + Math.abs(e[5]) * h.y + Math.abs(e[9]) * h.z) * sc;
|
|
603
|
-
const gy = this.
|
|
615
|
+
const gy = this.floorUnder(f);
|
|
604
616
|
let contact = false;
|
|
605
617
|
if (mesh.position.y - ext < gy) {
|
|
606
618
|
contact = true;
|
|
@@ -3569,6 +3581,9 @@ var STRUCTURAL_EVENTS = /* @__PURE__ */ new Set([
|
|
|
3569
3581
|
var MIN_FRAGMENTS_PER_SLICE = 8;
|
|
3570
3582
|
var STATIC_REFRESH = 0.5;
|
|
3571
3583
|
var STATIC_REFRESH_SLICE_MS = 1;
|
|
3584
|
+
var SURFACE_RAYS = 4;
|
|
3585
|
+
var SURFACE_INSIDE = 5e-3;
|
|
3586
|
+
var SURFACE_STEP = 0.15;
|
|
3572
3587
|
var STATIC_SPAN = 3;
|
|
3573
3588
|
var FEET_BAND = 0.03;
|
|
3574
3589
|
var TIP_MIN_HEIGHT = 0.3;
|
|
@@ -3827,7 +3842,9 @@ var Renderer = class {
|
|
|
3827
3842
|
max: this.maxFragments,
|
|
3828
3843
|
life: o.fragmentLife ?? 12,
|
|
3829
3844
|
formOf: (id) => this.world.materials.get(id)?.splitForm,
|
|
3830
|
-
crumbles: (id) => this.world.materials.get(id)?.fracture === "crumble"
|
|
3845
|
+
crumbles: (id) => this.world.materials.get(id)?.fracture === "crumble",
|
|
3846
|
+
// rubble lands on what is still built (a slab, a wall's top, a floor), not only on the terrain under it
|
|
3847
|
+
surfaceAt: (x, y, z) => this.surfaceAt(x, y, z)
|
|
3831
3848
|
});
|
|
3832
3849
|
this.cages = new RebarCages(THREE, o.scene);
|
|
3833
3850
|
this.pieceSys = new PieceSystem(THREE, {
|
|
@@ -4639,7 +4656,8 @@ var Renderer = class {
|
|
|
4639
4656
|
}
|
|
4640
4657
|
/** Current colour of the part's first mesh (char included), or null. */
|
|
4641
4658
|
partColor(pv, def) {
|
|
4642
|
-
const
|
|
4659
|
+
const size = (m) => m.range ? m.range[1] - m.range[0] : m.mesh.geometry.getAttribute("position")?.count ?? 0;
|
|
4660
|
+
const mv = pv.meshes.reduce((best, m) => !best || size(m) > size(best) ? m : best, void 0);
|
|
4643
4661
|
if (!mv) return null;
|
|
4644
4662
|
const mat = materialsOf2(mv.mesh.material)[0];
|
|
4645
4663
|
const c = mat?.color;
|
|
@@ -5159,6 +5177,19 @@ var Renderer = class {
|
|
|
5159
5177
|
}
|
|
5160
5178
|
return "";
|
|
5161
5179
|
}
|
|
5180
|
+
/** 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. */
|
|
5181
|
+
surfaceAt(x, y, z) {
|
|
5182
|
+
const ground = this.groundAt(x, z);
|
|
5183
|
+
if (y <= ground || typeof this.world.raycast !== "function") return ground;
|
|
5184
|
+
let from = y;
|
|
5185
|
+
for (let k = 0; k < SURFACE_RAYS && from > ground; k++) {
|
|
5186
|
+
const hit = this.world.raycast([x, from, z], [0, -1, 0], from - ground);
|
|
5187
|
+
if (!hit) return ground;
|
|
5188
|
+
if (hit.distance > SURFACE_INSIDE) return Math.max(ground, hit.point[1]);
|
|
5189
|
+
from -= SURFACE_STEP;
|
|
5190
|
+
}
|
|
5191
|
+
return ground;
|
|
5192
|
+
}
|
|
5162
5193
|
/** `staticTopAt` without the boxes of `objectId` itself. */
|
|
5163
5194
|
staticTopAtBut(objectId, x, z, y, step) {
|
|
5164
5195
|
let top = -Infinity;
|