@adatechnology/game-destruction-three 1.0.0 → 1.1.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/README.md +8 -0
- package/dist/index.d.ts +26 -5
- package/dist/index.global.js +710 -120
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +580 -95
- package/dist/index.js.map +1 -1
- package/dist/worker-kinds.d.ts +16 -0
- package/dist/worker-kinds.js +40 -2
- package/dist/worker-kinds.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -742,18 +742,18 @@ function slerpInto(out, a, ai, b, bi, t) {
|
|
|
742
742
|
let by = b[bi + 1];
|
|
743
743
|
let bz = b[bi + 2];
|
|
744
744
|
let bw = b[bi + 3];
|
|
745
|
-
let
|
|
746
|
-
if (
|
|
745
|
+
let dot3 = ax * bx + ay * by + az * bz + aw * bw;
|
|
746
|
+
if (dot3 < 0) {
|
|
747
747
|
bx = -bx;
|
|
748
748
|
by = -by;
|
|
749
749
|
bz = -bz;
|
|
750
750
|
bw = -bw;
|
|
751
|
-
|
|
751
|
+
dot3 = -dot3;
|
|
752
752
|
}
|
|
753
753
|
let from = 1 - t;
|
|
754
754
|
let to = t;
|
|
755
|
-
if (
|
|
756
|
-
const angle = Math.acos(
|
|
755
|
+
if (dot3 < 0.9995) {
|
|
756
|
+
const angle = Math.acos(dot3);
|
|
757
757
|
const sine = Math.sin(angle);
|
|
758
758
|
from = Math.sin((1 - t) * angle) / sine;
|
|
759
759
|
to = Math.sin(t * angle) / sine;
|
|
@@ -1590,10 +1590,26 @@ var squareBoxOf = (box) => {
|
|
|
1590
1590
|
return { center: box.center, half };
|
|
1591
1591
|
};
|
|
1592
1592
|
|
|
1593
|
+
// src/built-solids.ts
|
|
1594
|
+
var numbers = (value, count) => Array.isArray(value) && value.length === count && value.every((v) => typeof v === "number" && Number.isFinite(v));
|
|
1595
|
+
var isBuiltSolid = (value) => {
|
|
1596
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1597
|
+
const solid = value;
|
|
1598
|
+
return numbers(solid.center, 3) && numbers(solid.half, 3) && numbers(solid.rotation, 4) && (solid.kind === void 0 || typeof solid.kind === "string");
|
|
1599
|
+
};
|
|
1600
|
+
var builtSolidsOf = (mesh) => {
|
|
1601
|
+
const list = mesh.userData.solids;
|
|
1602
|
+
if (!Array.isArray(list) || list.length === 0 || !list.every(isBuiltSolid)) return null;
|
|
1603
|
+
return list;
|
|
1604
|
+
};
|
|
1605
|
+
var ROUND_SIDES = 0.05;
|
|
1606
|
+
var isRoundSolid = (solid) => solid.kind === "cylinder" && Math.abs(solid.half[0] - solid.half[2]) <= ROUND_SIDES * Math.max(solid.half[0], solid.half[2]);
|
|
1607
|
+
|
|
1593
1608
|
// src/static-part-job.ts
|
|
1594
1609
|
import { fitOrientedBox, hugs } from "@adatechnology/game-shapes";
|
|
1595
1610
|
var FIT = 0.01;
|
|
1596
1611
|
var FILL = 0.5;
|
|
1612
|
+
var SOLID = 0.5;
|
|
1597
1613
|
var MIN_HALF = 5e-3;
|
|
1598
1614
|
var COLLAPSED = 2e-3;
|
|
1599
1615
|
var MIN_FACE = 1e-6;
|
|
@@ -1630,10 +1646,11 @@ function measureStaticPart(job) {
|
|
|
1630
1646
|
const size = [high[0] - low[0], high[1] - low[1], high[2] - low[2]];
|
|
1631
1647
|
const s = [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])];
|
|
1632
1648
|
if (Math.max(size[0] * s[0], size[1] * s[1], size[2] * s[2]) < COLLAPSED) return [];
|
|
1649
|
+
if (job.solids && job.solids.length > 0) return job.solids.map((solid) => builtSolidIn(solid, pos, quat, scale));
|
|
1633
1650
|
const centre = [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2];
|
|
1634
1651
|
const half = [size[0] / 2, size[1] / 2, size[2] / 2];
|
|
1635
1652
|
const straight = { center: centre, half, axes: IDENTITY, tolerance: [FIT / s[0], FIT / s[1], FIT / s[2]] };
|
|
1636
|
-
if (hugs(points, straight) && fillsFaces(points, found, from, straight)) {
|
|
1653
|
+
if (hugs(points, straight) && fillsFaces(points, found, from, straight) && fillsVolume(points, found, from, straight)) {
|
|
1637
1654
|
const [cx, cy, cz] = turn(centre[0] * scale[0], centre[1] * scale[1], centre[2] * scale[2], quat);
|
|
1638
1655
|
return [{ center: [cx + pos[0], cy + pos[1], cz + pos[2]], half: [Math.max(MIN_HALF, half[0] * s[0]), Math.max(MIN_HALF, half[1] * s[1]), Math.max(MIN_HALF, half[2] * s[2])], rotation: [quat[0], quat[1], quat[2], quat[3]] }];
|
|
1639
1656
|
}
|
|
@@ -1646,9 +1663,24 @@ function measureStaticPart(job) {
|
|
|
1646
1663
|
world[i + 2] = e[2] * x + e[6] * y + e[10] * z + e[14];
|
|
1647
1664
|
}
|
|
1648
1665
|
const turned = fitOrientedBox(world);
|
|
1649
|
-
if (turned && fitsTurned(world, turned) && fillsFaces(world, found, from, turnedBox(turned))) return [turned];
|
|
1666
|
+
if (turned && fitsTurned(world, turned) && fillsFaces(world, found, from, turnedBox(turned)) && fillsVolume(world, found, from, turnedBox(turned))) return [turned];
|
|
1650
1667
|
return [trimeshOf(world, from, found)];
|
|
1651
1668
|
}
|
|
1669
|
+
var builtSolidIn = (solid, pos, quat, scale) => {
|
|
1670
|
+
const [cx, cy, cz] = turn(solid.center[0] * scale[0], solid.center[1] * scale[1], solid.center[2] * scale[2], quat);
|
|
1671
|
+
const [ax, ay, az, aw] = quat;
|
|
1672
|
+
const [bx, by, bz, bw] = solid.rotation;
|
|
1673
|
+
const turned = Math.abs(bw) < 1 - 1e-9;
|
|
1674
|
+
const even = (Math.abs(scale[0]) + Math.abs(scale[1]) + Math.abs(scale[2])) / 3;
|
|
1675
|
+
const s = turned ? [even, even, even] : [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])];
|
|
1676
|
+
return {
|
|
1677
|
+
...isRoundSolid(solid) && Math.abs(s[0] - s[2]) <= 1e-9 ? { round: true } : {},
|
|
1678
|
+
center: [cx + pos[0], cy + pos[1], cz + pos[2]],
|
|
1679
|
+
half: [Math.max(MIN_HALF, solid.half[0] * s[0]), Math.max(MIN_HALF, solid.half[1] * s[1]), Math.max(MIN_HALF, solid.half[2] * s[2])],
|
|
1680
|
+
// the mesh's turn, then the solid's own
|
|
1681
|
+
rotation: [aw * bx + ax * bw + ay * bz - az * by, aw * by - ax * bz + ay * bw + az * bx, aw * bz + ax * by - ay * bx + az * bw, aw * bw - ax * bx - ay * by - az * bz]
|
|
1682
|
+
};
|
|
1683
|
+
};
|
|
1652
1684
|
var staticSolidsTransfer = (solids) => {
|
|
1653
1685
|
const out = [];
|
|
1654
1686
|
for (const solid of solids) if (solid.mesh) out.push(solid.mesh.vertices.buffer, solid.mesh.indices.buffer);
|
|
@@ -1687,6 +1719,21 @@ var fillsFaces = (points, found, from, box) => {
|
|
|
1687
1719
|
}
|
|
1688
1720
|
return true;
|
|
1689
1721
|
};
|
|
1722
|
+
var fillsVolume = (points, found, from, box) => {
|
|
1723
|
+
if (found.length === 0) return true;
|
|
1724
|
+
const whole = 8 * box.half[0] * box.half[1] * box.half[2];
|
|
1725
|
+
if (!(whole > 0)) return true;
|
|
1726
|
+
const [cx, cy, cz] = box.center;
|
|
1727
|
+
let six = 0;
|
|
1728
|
+
for (let i = 0; i + 2 < found.length; i += 3) {
|
|
1729
|
+
const a = (found[i] - from) * 3, b = (found[i + 1] - from) * 3, c = (found[i + 2] - from) * 3;
|
|
1730
|
+
const ax = points[a] - cx, ay = points[a + 1] - cy, az = points[a + 2] - cz;
|
|
1731
|
+
const bx = points[b] - cx, by = points[b + 1] - cy, bz = points[b + 2] - cz;
|
|
1732
|
+
const dx = points[c] - cx, dy = points[c + 1] - cy, dz = points[c + 2] - cz;
|
|
1733
|
+
six += ax * (by * dz - bz * dy) + ay * (bz * dx - bx * dz) + az * (bx * dy - by * dx);
|
|
1734
|
+
}
|
|
1735
|
+
return Math.abs(six) / 6 >= whole * SOLID;
|
|
1736
|
+
};
|
|
1690
1737
|
var trimeshOf = (world, from, found) => {
|
|
1691
1738
|
const indices = new Uint32Array(found.length);
|
|
1692
1739
|
for (let i = 0; i < found.length; i++) indices[i] = found[i] - from;
|
|
@@ -2632,6 +2679,7 @@ var jobOf = (THREE, mv, points, matrix, local) => {
|
|
|
2632
2679
|
const quat = new THREE.Quaternion();
|
|
2633
2680
|
const scale = new THREE.Vector3();
|
|
2634
2681
|
mv.mesh.matrixWorld.decompose(pos, quat, scale);
|
|
2682
|
+
const built = mv.range ? null : builtSolidsOf(mv.mesh);
|
|
2635
2683
|
return {
|
|
2636
2684
|
points,
|
|
2637
2685
|
matrix: Float64Array.from(matrix),
|
|
@@ -2639,7 +2687,9 @@ var jobOf = (THREE, mv, points, matrix, local) => {
|
|
|
2639
2687
|
quaternion: [quat.x, quat.y, quat.z, quat.w],
|
|
2640
2688
|
scale: [scale.x, scale.y, scale.z],
|
|
2641
2689
|
found: Uint32Array.from(trianglesOfPart(mv, local)),
|
|
2642
|
-
from: local.from
|
|
2690
|
+
from: local.from,
|
|
2691
|
+
// a mesh of its own that says what it was built from is held by that (a part of a merged mesh is only some of its mesh)
|
|
2692
|
+
...built ? { solids: built } : {}
|
|
2643
2693
|
};
|
|
2644
2694
|
};
|
|
2645
2695
|
var trianglesOfRanges = (mv, ranges) => {
|
|
@@ -2683,41 +2733,99 @@ var trianglesOfPart = (mv, local) => mv.host ? trianglesOfRanges(mv, mv.host.sha
|
|
|
2683
2733
|
var BOX_VERTICES = 24;
|
|
2684
2734
|
var MAX_BOXES = 16;
|
|
2685
2735
|
var CORNER = 1e-4;
|
|
2686
|
-
var
|
|
2687
|
-
var
|
|
2736
|
+
var RANGED = { share: 0.5, turned: false };
|
|
2737
|
+
var OWN_MESH = { share: 0.8, turned: true };
|
|
2738
|
+
var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
2739
|
+
var quaternionOf = (x, y, z) => {
|
|
2740
|
+
const [m00, m10, m20] = x;
|
|
2741
|
+
const [m01, m11, m21] = y;
|
|
2742
|
+
const [m02, m12, m22] = z;
|
|
2743
|
+
const trace = m00 + m11 + m22;
|
|
2744
|
+
if (trace > 0) {
|
|
2745
|
+
const s2 = 0.5 / Math.sqrt(trace + 1);
|
|
2746
|
+
return [(m21 - m12) * s2, (m02 - m20) * s2, (m10 - m01) * s2, 0.25 / s2];
|
|
2747
|
+
}
|
|
2748
|
+
if (m00 > m11 && m00 > m22) {
|
|
2749
|
+
const s2 = 2 * Math.sqrt(1 + m00 - m11 - m22);
|
|
2750
|
+
return [0.25 * s2, (m01 + m10) / s2, (m02 + m20) / s2, (m21 - m12) / s2];
|
|
2751
|
+
}
|
|
2752
|
+
if (m11 > m22) {
|
|
2753
|
+
const s2 = 2 * Math.sqrt(1 + m11 - m00 - m22);
|
|
2754
|
+
return [(m01 + m10) / s2, 0.25 * s2, (m12 + m21) / s2, (m02 - m20) / s2];
|
|
2755
|
+
}
|
|
2756
|
+
const s = 2 * Math.sqrt(1 + m22 - m00 - m11);
|
|
2757
|
+
return [(m02 + m20) / s, (m12 + m21) / s, 0.25 * s, (m10 - m01) / s];
|
|
2758
|
+
};
|
|
2759
|
+
var straightBoxOf = (points, first) => {
|
|
2760
|
+
const low = [Infinity, Infinity, Infinity];
|
|
2761
|
+
const high = [-Infinity, -Infinity, -Infinity];
|
|
2762
|
+
for (let v = first; v < first + BOX_VERTICES; v++) {
|
|
2763
|
+
for (let k = 0; k < 3; k++) {
|
|
2764
|
+
low[k] = Math.min(low[k], points[v * 3 + k]);
|
|
2765
|
+
high[k] = Math.max(high[k], points[v * 3 + k]);
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
const corners = /* @__PURE__ */ new Set();
|
|
2769
|
+
for (let v = first; v < first + BOX_VERTICES; v++) {
|
|
2770
|
+
let corner = 0;
|
|
2771
|
+
for (let k = 0; k < 3; k++) {
|
|
2772
|
+
const x = points[v * 3 + k];
|
|
2773
|
+
if (Math.abs(x - high[k]) <= CORNER) corner |= 1 << k;
|
|
2774
|
+
else if (Math.abs(x - low[k]) > CORNER) return null;
|
|
2775
|
+
}
|
|
2776
|
+
corners.add(corner);
|
|
2777
|
+
}
|
|
2778
|
+
if (corners.size !== 8) return null;
|
|
2779
|
+
return { center: [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2], half: [(high[0] - low[0]) / 2, (high[1] - low[1]) / 2, (high[2] - low[2]) / 2] };
|
|
2780
|
+
};
|
|
2781
|
+
var turnedBoxOf = (points, first) => {
|
|
2782
|
+
const corners = [];
|
|
2783
|
+
for (let v = first; v < first + BOX_VERTICES; v++) {
|
|
2784
|
+
const p = [points[v * 3], points[v * 3 + 1], points[v * 3 + 2]];
|
|
2785
|
+
if (!corners.some((c) => Math.abs(c[0] - p[0]) <= CORNER && Math.abs(c[1] - p[1]) <= CORNER && Math.abs(c[2] - p[2]) <= CORNER)) corners.push(p);
|
|
2786
|
+
}
|
|
2787
|
+
if (corners.length !== 8) return null;
|
|
2788
|
+
const origin = corners[0];
|
|
2789
|
+
const edges = corners.slice(1).map((c) => [c[0] - origin[0], c[1] - origin[1], c[2] - origin[2]]);
|
|
2790
|
+
const lengths = edges.map((e) => Math.hypot(e[0], e[1], e[2]));
|
|
2791
|
+
const square = (i, j) => Math.abs(dot(edges[i], edges[j])) <= CORNER * (lengths[i] + lengths[j] + 1);
|
|
2792
|
+
for (let i = 0; i < 7; i++) for (let j = i + 1; j < 7; j++) for (let k = j + 1; k < 7; k++) {
|
|
2793
|
+
if (!square(i, j) || !square(i, k) || !square(j, k)) continue;
|
|
2794
|
+
const [a, b, c] = [edges[i], edges[j], edges[k]];
|
|
2795
|
+
const sums = [[0, 0, 0], a, b, c, [a[0] + b[0], a[1] + b[1], a[2] + b[2]], [a[0] + c[0], a[1] + c[1], a[2] + c[2]], [b[0] + c[0], b[1] + c[1], b[2] + c[2]], [a[0] + b[0] + c[0], a[1] + b[1] + c[1], a[2] + b[2] + c[2]]];
|
|
2796
|
+
const found = sums.every((s) => corners.some((p) => Math.abs(p[0] - origin[0] - s[0]) <= 4 * CORNER && Math.abs(p[1] - origin[1] - s[1]) <= 4 * CORNER && Math.abs(p[2] - origin[2] - s[2]) <= 4 * CORNER));
|
|
2797
|
+
if (!found) continue;
|
|
2798
|
+
const [la, lb, lc] = [lengths[i], lengths[j], lengths[k]];
|
|
2799
|
+
if (la <= 0 || lb <= 0 || lc <= 0) return null;
|
|
2800
|
+
const x = [a[0] / la, a[1] / la, a[2] / la];
|
|
2801
|
+
const y = [b[0] / lb, b[1] / lb, b[2] / lb];
|
|
2802
|
+
let z = [c[0] / lc, c[1] / lc, c[2] / lc];
|
|
2803
|
+
const cross2 = [x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0]];
|
|
2804
|
+
if (dot(cross2, z) < 0) z = [-z[0], -z[1], -z[2]];
|
|
2805
|
+
const far2 = sums[7];
|
|
2806
|
+
return { center: [origin[0] + far2[0] / 2, origin[1] + far2[1] / 2, origin[2] + far2[2] / 2], half: [la / 2, lb / 2, lc / 2], rotation: quaternionOf(x, y, z) };
|
|
2807
|
+
}
|
|
2808
|
+
return null;
|
|
2809
|
+
};
|
|
2810
|
+
var hollowBoxesOf = (points, rule = RANGED) => {
|
|
2688
2811
|
const count = points.length / 3;
|
|
2689
|
-
if (count % BOX_VERTICES !== 0 || count / BOX_VERTICES < 2 || count / BOX_VERTICES > MAX_BOXES) return null;
|
|
2812
|
+
if (count % BOX_VERTICES !== 0 || count / BOX_VERTICES < (rule.turned ? 1 : 2) || count / BOX_VERTICES > MAX_BOXES) return null;
|
|
2690
2813
|
const boxes = [];
|
|
2691
|
-
const
|
|
2814
|
+
const low = [Infinity, Infinity, Infinity];
|
|
2815
|
+
const high = [-Infinity, -Infinity, -Infinity];
|
|
2692
2816
|
for (let first = 0; first < count; first += BOX_VERTICES) {
|
|
2693
|
-
const
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
high[k] = Math.max(high[k], points[v * 3 + k]);
|
|
2699
|
-
}
|
|
2700
|
-
}
|
|
2701
|
-
const corners = /* @__PURE__ */ new Set();
|
|
2702
|
-
for (let v = first; v < first + BOX_VERTICES; v++) {
|
|
2703
|
-
let corner = 0;
|
|
2704
|
-
for (let k = 0; k < 3; k++) {
|
|
2705
|
-
const x = points[v * 3 + k];
|
|
2706
|
-
if (Math.abs(x - high[k]) <= CORNER) corner |= 1 << k;
|
|
2707
|
-
else if (Math.abs(x - low[k]) > CORNER) return null;
|
|
2708
|
-
}
|
|
2709
|
-
corners.add(corner);
|
|
2710
|
-
}
|
|
2711
|
-
if (corners.size !== 8) return null;
|
|
2817
|
+
const box = straightBoxOf(points, first) ?? (rule.turned ? turnedBoxOf(points, first) : null);
|
|
2818
|
+
if (!box) return null;
|
|
2819
|
+
boxes.push(box);
|
|
2820
|
+
}
|
|
2821
|
+
for (let i = 0; i < points.length; i += 3) {
|
|
2712
2822
|
for (let k = 0; k < 3; k++) {
|
|
2713
|
-
|
|
2714
|
-
|
|
2823
|
+
low[k] = Math.min(low[k], points[i + k]);
|
|
2824
|
+
high[k] = Math.max(high[k], points[i + k]);
|
|
2715
2825
|
}
|
|
2716
|
-
boxes.push({ low, high });
|
|
2717
2826
|
}
|
|
2718
|
-
const
|
|
2719
|
-
|
|
2720
|
-
return filled < HOLLOW * volume(all.low, all.high) ? boxes : null;
|
|
2827
|
+
const filled = boxes.reduce((sum, box) => sum + 8 * box.half[0] * box.half[1] * box.half[2], 0);
|
|
2828
|
+
return filled < rule.share * (high[0] - low[0]) * (high[1] - low[1]) * (high[2] - low[2]) ? boxes : null;
|
|
2721
2829
|
};
|
|
2722
2830
|
|
|
2723
2831
|
// src/rigid-pose.ts
|
|
@@ -2772,7 +2880,11 @@ var orientedReach = (s) => {
|
|
|
2772
2880
|
row(2 * (x * z - y * w), 2 * (y * z + x * w), 1 - 2 * (x * x + y * y))
|
|
2773
2881
|
];
|
|
2774
2882
|
};
|
|
2775
|
-
var shapeOf = (s) =>
|
|
2883
|
+
var shapeOf = (s) => {
|
|
2884
|
+
if (s.mesh) return { kind: "trimesh", vertices: s.mesh.vertices, indices: s.mesh.indices };
|
|
2885
|
+
if (s.round) return { kind: "cylinder", halfHeight: s.half[1], radius: (s.half[0] + s.half[2]) / 2 };
|
|
2886
|
+
return { kind: "box", half: s.half };
|
|
2887
|
+
};
|
|
2776
2888
|
var EngineStatics = class {
|
|
2777
2889
|
constructor(world, material) {
|
|
2778
2890
|
__publicField(this, "world", world);
|
|
@@ -3018,30 +3130,30 @@ var GROUND_ROLLING_DAMPING = 0.3;
|
|
|
3018
3130
|
var SEGMENT_BOX_ROUNDS = 4;
|
|
3019
3131
|
var PARALLEL = 1e-4;
|
|
3020
3132
|
var sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
3021
|
-
var
|
|
3133
|
+
var dot2 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
3022
3134
|
var along = (a, d, t) => [a[0] + d[0] * t, a[1] + d[1] * t, a[2] + d[2] * t];
|
|
3023
3135
|
var clamp01 = (t) => t < 0 ? 0 : t > 1 ? 1 : t;
|
|
3024
3136
|
var nearestOnSegment = (from, to, p) => {
|
|
3025
3137
|
const d = sub(to, from);
|
|
3026
|
-
const len2 =
|
|
3027
|
-
return len2 < 1e-12 ? from : along(from, d, clamp01(
|
|
3138
|
+
const len2 = dot2(d, d);
|
|
3139
|
+
return len2 < 1e-12 ? from : along(from, d, clamp01(dot2(sub(p, from), d) / len2));
|
|
3028
3140
|
};
|
|
3029
3141
|
var nearestOfSegments = (p1, q1, p2, q2) => {
|
|
3030
3142
|
const d1 = sub(q1, p1);
|
|
3031
3143
|
const d2 = sub(q2, p2);
|
|
3032
3144
|
const r = sub(p1, p2);
|
|
3033
|
-
const a =
|
|
3034
|
-
const e =
|
|
3035
|
-
const f =
|
|
3145
|
+
const a = dot2(d1, d1);
|
|
3146
|
+
const e = dot2(d2, d2);
|
|
3147
|
+
const f = dot2(d2, r);
|
|
3036
3148
|
let s = 0;
|
|
3037
3149
|
let t = 0;
|
|
3038
3150
|
if (a < 1e-12 && e < 1e-12) return [p1, p2];
|
|
3039
3151
|
if (a < 1e-12) t = clamp01(f / e);
|
|
3040
3152
|
else {
|
|
3041
|
-
const c =
|
|
3153
|
+
const c = dot2(d1, r);
|
|
3042
3154
|
if (e < 1e-12) s = clamp01(-c / a);
|
|
3043
3155
|
else {
|
|
3044
|
-
const b =
|
|
3156
|
+
const b = dot2(d1, d2);
|
|
3045
3157
|
const denom = a * e - b * b;
|
|
3046
3158
|
if (denom > PARALLEL * a * e) s = clamp01((b * f - c * e) / denom);
|
|
3047
3159
|
else {
|
|
@@ -3155,8 +3267,8 @@ var boxBox = (a, b) => {
|
|
|
3155
3267
|
}
|
|
3156
3268
|
const normal = [nx, ny, nz];
|
|
3157
3269
|
const mid = [(a.c[0] + b.c[0]) / 2, (a.c[1] + b.c[1]) / 2, (a.c[2] + b.c[2]) / 2];
|
|
3158
|
-
const middle = (
|
|
3159
|
-
return { point: along(mid, normal, middle -
|
|
3270
|
+
const middle = (dot2(a.c, normal) - reachAlong2(a, nx, ny, nz) + dot2(b.c, normal) + reachAlong2(b, nx, ny, nz)) / 2;
|
|
3271
|
+
return { point: along(mid, normal, middle - dot2(mid, normal)), normal, depth };
|
|
3160
3272
|
};
|
|
3161
3273
|
var LEVEL_SHARE = 1e-3;
|
|
3162
3274
|
var boxBoxAlongGround = (a, b) => {
|
|
@@ -3642,7 +3754,7 @@ var sameTurn = (a, b) => {
|
|
|
3642
3754
|
return a.rotation.every((v, i) => Math.abs(v - b.rotation[i]) < FLUSH);
|
|
3643
3755
|
};
|
|
3644
3756
|
var flushAxis = (a, b) => {
|
|
3645
|
-
if (!sameTurn(a, b)) return -1;
|
|
3757
|
+
if (a.round || b.round || a.hull || b.hull || !sameTurn(a, b)) return -1;
|
|
3646
3758
|
let along2 = -1;
|
|
3647
3759
|
for (let axis = 0; axis < 3; axis++) {
|
|
3648
3760
|
const same2 = Math.abs(a.half[axis] - b.half[axis]) < FLUSH && Math.abs(a.center[axis] - b.center[axis]) < FLUSH;
|
|
@@ -4166,7 +4278,7 @@ var EnginePieces = class {
|
|
|
4166
4278
|
return { kind: "compound", children: [{ shape: { kind: "cylinder", halfHeight: b.halfExtents[round.axis], radius: round.radius }, position: [0, 0, 0], rotation }] };
|
|
4167
4279
|
}
|
|
4168
4280
|
if (b.partBoxes && b.partBoxes.length > 0) {
|
|
4169
|
-
return { kind: "compound", children: mergeFlushBoxes(b.partBoxes).map((part, i) => ({ shape: { kind: "box", half: part.half }, position: part.center, ...part.rotation ? { rotation: part.rotation } : {}, tag: i })) };
|
|
4281
|
+
return { kind: "compound", children: mergeFlushBoxes(b.partBoxes).map((part, i) => ({ shape: part.hull ? { kind: "convex", points: [...part.hull] } : part.round ? { kind: "cylinder", halfHeight: part.half[1], radius: (part.half[0] + part.half[2]) / 2 } : { kind: "box", half: part.half }, position: part.center, ...part.rotation ? { rotation: part.rotation } : {}, tag: i })) };
|
|
4170
4282
|
}
|
|
4171
4283
|
return { kind: "box", half: b.halfExtents };
|
|
4172
4284
|
}
|
|
@@ -6671,10 +6783,10 @@ function bendPositions(positions, from, to, point, axis, side, angle, radius) {
|
|
|
6671
6783
|
const turn2 = angle * share * share * (3 - 2 * share);
|
|
6672
6784
|
const cos = Math.cos(turn2);
|
|
6673
6785
|
const sin = Math.sin(turn2);
|
|
6674
|
-
const
|
|
6675
|
-
positions[i] = point[0] + rx * cos + (ky * rz - kz * ry) * sin + kx *
|
|
6676
|
-
positions[i + 1] = point[1] + ry * cos + (kz * rx - kx * rz) * sin + ky *
|
|
6677
|
-
positions[i + 2] = point[2] + rz * cos + (kx * ry - ky * rx) * sin + kz *
|
|
6786
|
+
const dot3 = kx * rx + ky * ry + kz * rz;
|
|
6787
|
+
positions[i] = point[0] + rx * cos + (ky * rz - kz * ry) * sin + kx * dot3 * (1 - cos);
|
|
6788
|
+
positions[i + 1] = point[1] + ry * cos + (kz * rx - kx * rz) * sin + ky * dot3 * (1 - cos);
|
|
6789
|
+
positions[i + 2] = point[2] + rz * cos + (kx * ry - ky * rx) * sin + kz * dot3 * (1 - cos);
|
|
6678
6790
|
}
|
|
6679
6791
|
}
|
|
6680
6792
|
|
|
@@ -6843,9 +6955,9 @@ var MeshRayProbe = class {
|
|
|
6843
6955
|
const grown = new Uint32Array(size);
|
|
6844
6956
|
grown.set(this.candidates);
|
|
6845
6957
|
this.candidates = grown;
|
|
6846
|
-
const
|
|
6847
|
-
|
|
6848
|
-
this.triangles =
|
|
6958
|
+
const numbers2 = new Uint32Array(Math.max(this.triangles.length, Math.ceil(size / 3)));
|
|
6959
|
+
numbers2.set(this.triangles);
|
|
6960
|
+
this.triangles = numbers2;
|
|
6849
6961
|
this.candidateIndex = new this.THREE.BufferAttribute(this.candidates, 1);
|
|
6850
6962
|
}
|
|
6851
6963
|
};
|
|
@@ -8440,6 +8552,9 @@ var COLLAPSE_CLOUD_KG = 1e3;
|
|
|
8440
8552
|
var REBAR_COLOR = 7628380;
|
|
8441
8553
|
var STEEL_DENSITY = 7850;
|
|
8442
8554
|
var CHIP_DECAL_EDGE = 0.05;
|
|
8555
|
+
var CHIP_GAP_REACH = 0.03;
|
|
8556
|
+
var CHIP_GAP_SHADE = 0.4;
|
|
8557
|
+
var CHIP_GAP_WIDTH = 1.15;
|
|
8443
8558
|
var CRATER_RADIUS2 = 2.5;
|
|
8444
8559
|
var CRATER_MIN_RADIUS = 0.012;
|
|
8445
8560
|
var CRATER_LIGHTEN = 0.12;
|
|
@@ -8471,10 +8586,71 @@ var HINGE_STILL_SPEED = 0.2;
|
|
|
8471
8586
|
var HINGE_STILL_SPIN = 0.5;
|
|
8472
8587
|
var PREFIT_SLICE_MS = 1;
|
|
8473
8588
|
var CONTACT_MESHES = 12;
|
|
8474
|
-
var PART_BOX_MESHES =
|
|
8589
|
+
var PART_BOX_MESHES = 96;
|
|
8475
8590
|
var ROUND_SAMPLES = 400;
|
|
8476
|
-
var
|
|
8591
|
+
var ROUND_SIDES2 = 0.12;
|
|
8477
8592
|
var ROUND_SLACK = 1.12;
|
|
8593
|
+
var ROUND_FILL = 0.9;
|
|
8594
|
+
var FILL_GRID = 8;
|
|
8595
|
+
var hullRadiusAt = (profile, radius, at) => {
|
|
8596
|
+
if (!profile || profile.length < 2) return radius;
|
|
8597
|
+
const hull = [];
|
|
8598
|
+
for (const point of profile) {
|
|
8599
|
+
while (hull.length >= 2) {
|
|
8600
|
+
const [a, ra] = hull[hull.length - 2];
|
|
8601
|
+
const [b, rb] = hull[hull.length - 1];
|
|
8602
|
+
if ((b - a) * (point[1] - ra) - (rb - ra) * (point[0] - a) >= 0) hull.pop();
|
|
8603
|
+
else break;
|
|
8604
|
+
}
|
|
8605
|
+
hull.push(point);
|
|
8606
|
+
}
|
|
8607
|
+
if (at <= hull[0][0]) return hull[0][1];
|
|
8608
|
+
for (let i = 1; i < hull.length; i++) {
|
|
8609
|
+
const [a, ra] = hull[i - 1];
|
|
8610
|
+
const [b, rb] = hull[i];
|
|
8611
|
+
if (at <= b) return ra + (rb - ra) * (at - a) / (b - a || 1);
|
|
8612
|
+
}
|
|
8613
|
+
return hull[hull.length - 1][1];
|
|
8614
|
+
};
|
|
8615
|
+
var insideDrawn = (mesh, built, x, y, z) => {
|
|
8616
|
+
if (built) {
|
|
8617
|
+
for (const solid of built) {
|
|
8618
|
+
const [qx, qy, qz, qw] = solid.rotation;
|
|
8619
|
+
const px = x - solid.center[0], py = y - solid.center[1], pz = z - solid.center[2];
|
|
8620
|
+
const tx = 2 * (-qy * pz + qz * py), ty = 2 * (-qz * px + qx * pz), tz = 2 * (-qx * py + qy * px);
|
|
8621
|
+
const lx = px + qw * tx - qy * tz + qz * ty, ly = py + qw * ty - qz * tx + qx * tz, lz = pz + qw * tz - qx * ty + qy * tx;
|
|
8622
|
+
const [hx, hy, hz] = solid.half;
|
|
8623
|
+
if (solid.kind === "cylinder" || solid.kind === "cone") {
|
|
8624
|
+
if (Math.abs(ly) <= hy && (lx / hx) ** 2 + (lz / hz) ** 2 <= 1) return true;
|
|
8625
|
+
} else if (solid.kind === "sphere") {
|
|
8626
|
+
if ((lx / hx) ** 2 + (ly / hy) ** 2 + (lz / hz) ** 2 <= 1) return true;
|
|
8627
|
+
} else if (Math.abs(lx) <= hx && Math.abs(ly) <= hy && Math.abs(lz) <= hz) return true;
|
|
8628
|
+
}
|
|
8629
|
+
return false;
|
|
8630
|
+
}
|
|
8631
|
+
const geometry = mesh.geometry;
|
|
8632
|
+
const p = geometry.parameters ?? {};
|
|
8633
|
+
const n = (key, fallback) => typeof p[key] === "number" ? p[key] : fallback;
|
|
8634
|
+
switch (geometry.type) {
|
|
8635
|
+
case "BoxGeometry":
|
|
8636
|
+
return Math.abs(x) <= n("width", 1) / 2 && Math.abs(y) <= n("height", 1) / 2 && Math.abs(z) <= n("depth", 1) / 2;
|
|
8637
|
+
case "CylinderGeometry":
|
|
8638
|
+
case "ConeGeometry": {
|
|
8639
|
+
const h = n("height", 1) / 2;
|
|
8640
|
+
if (Math.abs(y) > h || p.openEnded === true) return false;
|
|
8641
|
+
const top = geometry.type === "ConeGeometry" ? 0 : n("radiusTop", 1);
|
|
8642
|
+
const bottom = geometry.type === "ConeGeometry" ? n("radius", 1) : n("radiusBottom", 1);
|
|
8643
|
+
return Math.hypot(x, z) <= bottom + (top - bottom) * (y + h) / (2 * h || 1);
|
|
8644
|
+
}
|
|
8645
|
+
case "SphereGeometry":
|
|
8646
|
+
return Math.hypot(x, y, z) <= n("radius", 1);
|
|
8647
|
+
default: {
|
|
8648
|
+
if (!geometry.boundingBox) geometry.computeBoundingBox();
|
|
8649
|
+
const box = geometry.boundingBox;
|
|
8650
|
+
return !!box && x >= box.min.x && x <= box.max.x && y >= box.min.y && y <= box.max.y && z >= box.min.z && z <= box.max.z;
|
|
8651
|
+
}
|
|
8652
|
+
}
|
|
8653
|
+
};
|
|
8478
8654
|
var RIM_POINTS = 12;
|
|
8479
8655
|
var rimPoints = (round, half) => {
|
|
8480
8656
|
const out = [];
|
|
@@ -8532,6 +8708,16 @@ var profileOf = (points, axis, half, radius) => {
|
|
|
8532
8708
|
};
|
|
8533
8709
|
var BROKEN_GAP = 0.03;
|
|
8534
8710
|
var BROKEN_SAMPLES = [[0.5, 0.5], [0.1, 0.1], [0.9, 0.1], [0.1, 0.9], [0.9, 0.9]];
|
|
8711
|
+
var UNDERMINED_MAX = 64;
|
|
8712
|
+
var UNDERMINED_RIM = 0.04;
|
|
8713
|
+
var UNDERMINED_RIM_DROP = 0.05;
|
|
8714
|
+
var UNDERMINED_RIM_RISE = 0.1;
|
|
8715
|
+
var UNDERMINED_STAND = 0.4;
|
|
8716
|
+
var UNDERMINED_KEEP = 0.6;
|
|
8717
|
+
var SOLIDS_MAX = 64;
|
|
8718
|
+
var UNDERMINED_PUSH = 0.6;
|
|
8719
|
+
var UNDERMINED_STILL = 0.05;
|
|
8720
|
+
var SOLID_WELD = 1e-4;
|
|
8535
8721
|
var UNCHECKED_KINDS = /* @__PURE__ */ new Set(["structure", "room", "ground"]);
|
|
8536
8722
|
var FIRE_CEILING_SECONDS = 3600;
|
|
8537
8723
|
var GENERIC_REFERENCE_RADIUS = 15;
|
|
@@ -8679,6 +8865,8 @@ var Renderer = class {
|
|
|
8679
8865
|
__publicField(this, "pieceBoxes", /* @__PURE__ */ new WeakMap());
|
|
8680
8866
|
/** Objects broken since the last update: `checkBroken` looks at what is left of them. */
|
|
8681
8867
|
__publicField(this, "broken", /* @__PURE__ */ new Set());
|
|
8868
|
+
/** Discs of ground that changed since the last update (`wakeRegion`): `checkUndermined` looks at what stood on them. */
|
|
8869
|
+
__publicField(this, "undermined", []);
|
|
8682
8870
|
__publicField(this, "staticAt", 0);
|
|
8683
8871
|
__publicField(this, "queue", []);
|
|
8684
8872
|
/** The cover of each body around a part of the world that went off, read as the event is emitted: before the blast tore or moved anything. */
|
|
@@ -9250,8 +9438,8 @@ var Renderer = class {
|
|
|
9250
9438
|
mv.mesh.updateWorldMatrix(true, false);
|
|
9251
9439
|
m4.multiplyMatrices(inv, mv.mesh.matrixWorld);
|
|
9252
9440
|
const stride = Math.max(1, Math.floor(pos.count / ROUND_SAMPLES));
|
|
9253
|
-
for (let
|
|
9254
|
-
p.fromBufferAttribute(pos,
|
|
9441
|
+
for (let i2 = 0; i2 < pos.count; i2 += stride) {
|
|
9442
|
+
p.fromBufferAttribute(pos, i2).applyMatrix4(m4);
|
|
9255
9443
|
points.push([p.x - cx, p.y - cy, p.z - cz]);
|
|
9256
9444
|
}
|
|
9257
9445
|
}
|
|
@@ -9259,22 +9447,64 @@ var Renderer = class {
|
|
|
9259
9447
|
const drawn = new Float64Array(3);
|
|
9260
9448
|
for (const q of points) for (let k = 0; k < 3; k++) drawn[k] = Math.max(drawn[k], Math.abs(q[k]));
|
|
9261
9449
|
const fits = (axis2) => {
|
|
9262
|
-
const [
|
|
9263
|
-
if (Math.abs(half[
|
|
9264
|
-
if (Math.abs(drawn[
|
|
9265
|
-
const reach = (drawn[
|
|
9266
|
-
for (const q of points) if (Math.hypot(q[
|
|
9267
|
-
return (half[
|
|
9450
|
+
const [i2, j2] = axis2 === 0 ? [1, 2] : axis2 === 1 ? [0, 2] : [0, 1];
|
|
9451
|
+
if (Math.abs(half[i2] - half[j2]) > ROUND_SIDES2 * Math.max(half[i2], half[j2])) return null;
|
|
9452
|
+
if (Math.abs(drawn[i2] - drawn[j2]) > ROUND_SIDES2 * Math.max(drawn[i2], drawn[j2])) return null;
|
|
9453
|
+
const reach = (drawn[i2] + drawn[j2]) / 2;
|
|
9454
|
+
for (const q of points) if (Math.hypot(q[i2], q[j2]) > reach * ROUND_SLACK) return null;
|
|
9455
|
+
return (half[i2] + half[j2]) / 2;
|
|
9268
9456
|
};
|
|
9269
9457
|
const radii = [0, 1, 2].map(fits);
|
|
9270
9458
|
if (radii.every((r) => r !== null)) {
|
|
9271
9459
|
const radius2 = (half[0] + half[1] + half[2]) / 3;
|
|
9460
|
+
if (this.drawnShareOf(b, body, (q) => Math.hypot(q[0], q[1], q[2]) <= radius2) < ROUND_FILL) return null;
|
|
9272
9461
|
return { kind: "sphere", axis: 1, radius: radius2, inertia: body.inertiaGiven ?? this.inertiaOf(b, body, "sphere", 1, radius2) };
|
|
9273
9462
|
}
|
|
9274
9463
|
const axis = [0, 1, 2].find((k) => radii[k] !== null);
|
|
9275
9464
|
if (axis === void 0) return null;
|
|
9276
9465
|
const radius = radii[axis] ?? 0;
|
|
9277
|
-
|
|
9466
|
+
const profile = profileOf(points, axis, half[axis], radius);
|
|
9467
|
+
const [i, j] = axis === 0 ? [1, 2] : axis === 1 ? [0, 2] : [0, 1];
|
|
9468
|
+
if (this.drawnShareOf(b, body, (q) => Math.abs(q[axis]) <= half[axis] && Math.hypot(q[i], q[j]) <= hullRadiusAt(profile, radius, q[axis])) < ROUND_FILL) return null;
|
|
9469
|
+
return { kind: "cylinder", axis, radius, inertia: body.inertiaGiven ?? this.inertiaOf(b, body, "cylinder", axis, radius), profile };
|
|
9470
|
+
}
|
|
9471
|
+
/** The vertices of a mesh about the centre of its box (`lb`, its own space), scaled as it is drawn: the points of the hull the engine holds it by (`PartBox.hull`). */
|
|
9472
|
+
hullOf(mv, lb, scale) {
|
|
9473
|
+
const own = [];
|
|
9474
|
+
this.visuals.rangePoints(mv, new this.THREE.Matrix4(), own);
|
|
9475
|
+
const c = lb.getCenter(new this.THREE.Vector3());
|
|
9476
|
+
const out = [];
|
|
9477
|
+
for (let i = 0; i < own.length; i += 3) out.push((own[i] - c.x) * Math.abs(scale.x), (own[i + 1] - c.y) * Math.abs(scale.y), (own[i + 2] - c.z) * Math.abs(scale.z));
|
|
9478
|
+
return out;
|
|
9479
|
+
}
|
|
9480
|
+
/**
|
|
9481
|
+
* The share of a round body the engine would hold (`inside`: a point from the piece's centre of mass) that is drawn: a grid of points through its box (`FILL_GRID`), those
|
|
9482
|
+
* inside the body, and of them those inside a primitive of the piece (`insideDrawn`). Primitives that overlap count once (a lamp's glow over its shade).
|
|
9483
|
+
*/
|
|
9484
|
+
drawnShareOf(b, body, inside) {
|
|
9485
|
+
const inv = specFrameInverse(this.THREE, b.root);
|
|
9486
|
+
const meshes = this.meshesOf(b).filter((mv) => this.visuals.shown(mv) && !mv.host).map((mv) => {
|
|
9487
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
9488
|
+
return { mesh: mv.mesh, built: builtSolidsOf(mv.mesh), back: new this.THREE.Matrix4().multiplyMatrices(inv, mv.mesh.matrixWorld).invert() };
|
|
9489
|
+
});
|
|
9490
|
+
const [cx, cy, cz] = body.localCenter;
|
|
9491
|
+
const half = body.halfExtents;
|
|
9492
|
+
const p = new this.THREE.Vector3();
|
|
9493
|
+
let shape = 0;
|
|
9494
|
+
let drawn = 0;
|
|
9495
|
+
for (let a = 0; a < FILL_GRID; a++) for (let c = 0; c < FILL_GRID; c++) for (let d = 0; d < FILL_GRID; d++) {
|
|
9496
|
+
const q = [half[0] * ((a + 0.5) / FILL_GRID * 2 - 1), half[1] * ((c + 0.5) / FILL_GRID * 2 - 1), half[2] * ((d + 0.5) / FILL_GRID * 2 - 1)];
|
|
9497
|
+
if (!inside(q)) continue;
|
|
9498
|
+
shape++;
|
|
9499
|
+
for (const m of meshes) {
|
|
9500
|
+
p.set(q[0] + cx, q[1] + cy, q[2] + cz).applyMatrix4(m.back);
|
|
9501
|
+
if (insideDrawn(m.mesh, m.built, p.x, p.y, p.z)) {
|
|
9502
|
+
drawn++;
|
|
9503
|
+
break;
|
|
9504
|
+
}
|
|
9505
|
+
}
|
|
9506
|
+
}
|
|
9507
|
+
return shape === 0 ? 1 : drawn / shape;
|
|
9278
9508
|
}
|
|
9279
9509
|
pieces() {
|
|
9280
9510
|
return [...this.pieceSys.list];
|
|
@@ -9364,6 +9594,7 @@ var Renderer = class {
|
|
|
9364
9594
|
this.work?.beginFrame();
|
|
9365
9595
|
if (!this.attached) this.drainQueue();
|
|
9366
9596
|
this.checkBroken();
|
|
9597
|
+
this.checkUndermined();
|
|
9367
9598
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
9368
9599
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
9369
9600
|
this.settlement.update(dt);
|
|
@@ -10422,9 +10653,33 @@ var Renderer = class {
|
|
|
10422
10653
|
const rotation = new T.Quaternion(ev.rotation[0], ev.rotation[1], ev.rotation[2], ev.rotation[3]);
|
|
10423
10654
|
for (const part of this.bounds.get(ev.object)?.parts.values() ?? []) for (const mv of part.meshes) this.visuals.clearDecals(mv, center, half, rotation);
|
|
10424
10655
|
this.vfx.peekWorkshop()?.decals.clearInside(ev.center, [half.x, half.y, half.z], ev.rotation);
|
|
10656
|
+
if (pv) this.drawChipGap(pv, ev, center, rotation);
|
|
10425
10657
|
this.vfx.burst("dust", ev.center, [0, 1, 0], ev.units ? Math.min(40, 8 + ev.units.length) : 8, ev.units ? 1.6 : 0.8, { color });
|
|
10426
10658
|
this.impactSound(pv?.material ?? "", ev.center, 0.7, ev.blow);
|
|
10427
10659
|
}
|
|
10660
|
+
/**
|
|
10661
|
+
* The gap a unit leaves in an object the renderer draws whole (a concrete pole, a block, a post): on each outer face the unit reached, the broken inside of its material,
|
|
10662
|
+
* as wide as the unit there, so the bars it bared show in a hole and not on a smooth face. A drawing that cuts its own gaps (the house's breach, `drawnSpalls`) takes none.
|
|
10663
|
+
*/
|
|
10664
|
+
drawChipGap(pv, ev, center, rotation) {
|
|
10665
|
+
const mv = this.nearestMesh(pv, center);
|
|
10666
|
+
if (!mv || mv.mesh.userData.drawnSpalls?.includes(ev.part)) return;
|
|
10667
|
+
const def = this.world.materials.get(pv.material);
|
|
10668
|
+
const inner = def?.visual?.innerColor ?? fallbackColor(def);
|
|
10669
|
+
const color = [16, 8, 0].reduce((hex, shift) => hex | Math.round((inner >> shift & 255) * CHIP_GAP_SHADE) << shift, 0);
|
|
10670
|
+
const box = this.visuals.worldBox(mv, new this.THREE.Box3());
|
|
10671
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
10672
|
+
for (const side of [-1, 1]) {
|
|
10673
|
+
const normal = new this.THREE.Vector3(axis === 0 ? side : 0, axis === 1 ? side : 0, axis === 2 ? side : 0).applyQuaternion(rotation);
|
|
10674
|
+
const face = center.clone().addScaledVector(normal, ev.size[axis] / 2);
|
|
10675
|
+
const k = Math.abs(normal.x) >= Math.abs(normal.y) && Math.abs(normal.x) >= Math.abs(normal.z) ? "x" : Math.abs(normal.y) >= Math.abs(normal.z) ? "y" : "z";
|
|
10676
|
+
const surface = normal[k] > 0 ? box.max[k] : box.min[k];
|
|
10677
|
+
if (Math.abs(face[k] - surface) > CHIP_GAP_REACH) continue;
|
|
10678
|
+
face[k] = surface;
|
|
10679
|
+
this.visuals.addSpall(mv, face, normal, Math.min(ev.size[(axis + 1) % 3], ev.size[(axis + 2) % 3]) / 2 * CHIP_GAP_WIDTH, color);
|
|
10680
|
+
}
|
|
10681
|
+
}
|
|
10682
|
+
}
|
|
10428
10683
|
onFracture(ev) {
|
|
10429
10684
|
const b = this.bounds.get(ev.object);
|
|
10430
10685
|
const pv = b?.parts.get(ev.part);
|
|
@@ -10615,7 +10870,7 @@ var Renderer = class {
|
|
|
10615
10870
|
if (!old.round) this.setContacts(b, old, this.meshesOf(b).filter((mv) => this.visuals.shown(mv)));
|
|
10616
10871
|
} else if (old.partBoxes) this.fitPartBoxes(b, old);
|
|
10617
10872
|
if (!this.splittingAtLoad) old.sleeping = false;
|
|
10618
|
-
} else if (kitOriginOf3(b.root)?.kind === "furniture" && !this.splittingAtLoad) {
|
|
10873
|
+
} else if (kitOriginOf3(b.root)?.kind === "furniture" && !this.splittingAtLoad && !this.heldByWorld(objectId)) {
|
|
10619
10874
|
const piece = this.makePiece(objectId);
|
|
10620
10875
|
piece.apart = true;
|
|
10621
10876
|
this.tipIfTopHeavy(b, true);
|
|
@@ -10901,9 +11156,10 @@ var Renderer = class {
|
|
|
10901
11156
|
if (!body.round) this.setContacts(b, body, left);
|
|
10902
11157
|
}
|
|
10903
11158
|
body.sleeping = false;
|
|
11159
|
+
if (!structural && !body.round && !body.held && kitOriginOf3(b.root)?.kind === "furniture" && Math.hypot(...body.velocity) <= UNDERMINED_STILL) this.goOverIfBalanced(b, body, left);
|
|
10904
11160
|
return;
|
|
10905
11161
|
}
|
|
10906
|
-
if (structural) return;
|
|
11162
|
+
if (structural || this.heldByWorld(objectId)) return;
|
|
10907
11163
|
const boxOf = (mv) => this.visuals.worldBox(mv, new this.THREE.Box3());
|
|
10908
11164
|
const whole = [...b.parts.values()].flatMap((pv) => pv.meshes).map(boxOf).filter((one) => !one.isEmpty());
|
|
10909
11165
|
if (!this.standsOn(objectId, whole.map((one) => [one.min.x, one.min.y, one.min.z, one.max.x, one.max.y, one.max.z]))) return;
|
|
@@ -10966,7 +11222,7 @@ var Renderer = class {
|
|
|
10966
11222
|
}
|
|
10967
11223
|
releaseIfFloating(objectId) {
|
|
10968
11224
|
const b = this.bounds.get(objectId);
|
|
10969
|
-
if (!b || b.piece || this.pieceSys.get(objectId) || !this.autoSplit || UNCHECKED_KINDS.has(this.kindOf(b))) return false;
|
|
11225
|
+
if (!b || b.piece || this.pieceSys.get(objectId) || !this.autoSplit || UNCHECKED_KINDS.has(this.kindOf(b)) || this.heldByWorld(objectId)) return false;
|
|
10970
11226
|
const boxes = this.shownBoxes(objectId);
|
|
10971
11227
|
if (boxes.length === 0) return false;
|
|
10972
11228
|
const whole = new this.THREE.Box3();
|
|
@@ -10985,6 +11241,139 @@ var Renderer = class {
|
|
|
10985
11241
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
10986
11242
|
return true;
|
|
10987
11243
|
}
|
|
11244
|
+
/**
|
|
11245
|
+
* The ground changed under what stands on feet (`wakeRegion`: a hole shot, dug or blown in the floor): furniture and what the host lets move (`shoveable`), not a piece yet or
|
|
11246
|
+
* a piece lying still. It looks at its feet again (`lowPoints`): a point of them with nothing left under it (`holdsAt`) no longer holds. While the points that still hold keep its
|
|
11247
|
+
* centre inside their polygon by `UNDERMINED_STAND` it stands (a cabinet on a full base over a small hole); otherwise it becomes a piece if it was not one, its corner over the
|
|
11248
|
+
* gap is started down, and the engine takes it into the hole by its own weight: a bed with a leg over the hole goes down on that corner until its frame meets the floor, and
|
|
11249
|
+
* what lay on it slides or falls off. Structures answer to their own load path.
|
|
11250
|
+
*/
|
|
11251
|
+
checkUndermined() {
|
|
11252
|
+
if (this.undermined.length === 0) return;
|
|
11253
|
+
const discs = this.undermined.splice(0);
|
|
11254
|
+
const inDisc = (x, z, d) => Math.hypot(x - d.x, z - d.z) <= d.radius;
|
|
11255
|
+
for (const b of [...this.bounds.values()]) {
|
|
11256
|
+
if (this.kindOf(b) !== "furniture" && !this.o.shoveable?.(b.id)) continue;
|
|
11257
|
+
const was = b.piece ?? this.pieceSys.get(b.id) ?? null;
|
|
11258
|
+
if (was && (was.held || Math.hypot(...was.velocity) > UNDERMINED_STILL)) continue;
|
|
11259
|
+
const meshes = this.meshesOf(b).filter((mv) => this.visuals.shown(mv));
|
|
11260
|
+
const boxes = meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty());
|
|
11261
|
+
if (boxes.length === 0) continue;
|
|
11262
|
+
const reach = boxes.reduce((all, one) => all.union(one), new this.THREE.Box3());
|
|
11263
|
+
if (!discs.some((d) => Math.hypot(Math.max(reach.min.x - d.x, 0, d.x - reach.max.x), Math.max(reach.min.z - d.z, 0, d.z - reach.max.z)) <= d.radius)) continue;
|
|
11264
|
+
const feet = this.lowPoints(meshes);
|
|
11265
|
+
if (!feet) continue;
|
|
11266
|
+
const { floor, points } = feet;
|
|
11267
|
+
const held = [];
|
|
11268
|
+
const lost = [];
|
|
11269
|
+
for (const point of points) (this.holdsAt(b.id, point[0], point[1], floor) ? held : lost).push(point);
|
|
11270
|
+
if (lost.length === 0) continue;
|
|
11271
|
+
if (!lost.some(([x, z]) => discs.some((d) => inDisc(x, z, d) && this.stoodBeside(x, z, d, floor)))) continue;
|
|
11272
|
+
const centre = centreOfBoxes(boxes);
|
|
11273
|
+
if (this.standsWith(held, points, centre, floor)) continue;
|
|
11274
|
+
let body;
|
|
11275
|
+
if (was) body = was;
|
|
11276
|
+
else {
|
|
11277
|
+
const piece = this.makePiece(b.id);
|
|
11278
|
+
body = b.piece ?? piece;
|
|
11279
|
+
body.apart = true;
|
|
11280
|
+
this.setContacts(b, body, meshes, true);
|
|
11281
|
+
}
|
|
11282
|
+
const gx = lost.reduce((sum, p) => sum + p[0], 0) / lost.length - centre[0];
|
|
11283
|
+
const gz = lost.reduce((sum, p) => sum + p[1], 0) / lost.length - centre[2];
|
|
11284
|
+
const length = Math.hypot(gx, gz);
|
|
11285
|
+
body.sleeping = false;
|
|
11286
|
+
body.still = 0;
|
|
11287
|
+
body.calmAt = null;
|
|
11288
|
+
if (held.length > 0 && length > 1e-6) this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + gx, floor, centre[2] + gz]);
|
|
11289
|
+
if (!was) this.o.onLoosened?.(b.id, body, "ground");
|
|
11290
|
+
}
|
|
11291
|
+
}
|
|
11292
|
+
/**
|
|
11293
|
+
* A piece whose feet that still hold keep its centre inside their polygon by less than `UNDERMINED_STAND` per metre of its height is started down over the nearest edge of
|
|
11294
|
+
* that polygon (its weight does the rest); one that stands on nothing falls by itself.
|
|
11295
|
+
*/
|
|
11296
|
+
goOverIfBalanced(b, body, meshes) {
|
|
11297
|
+
const feet = this.lowPoints(meshes);
|
|
11298
|
+
if (!feet) return;
|
|
11299
|
+
const held = feet.points.filter(([x, z]) => this.holdsAt(b.id, x, z, feet.floor));
|
|
11300
|
+
if (held.length < 3) return;
|
|
11301
|
+
const centre = centreOfBoxes(meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty()));
|
|
11302
|
+
if (this.standsWith(held, null, centre, feet.floor)) return;
|
|
11303
|
+
const inside = insideBy(convexHull(held), [centre[0], centre[2]]);
|
|
11304
|
+
const reach = Math.max(body.halfExtents[0], body.halfExtents[2]);
|
|
11305
|
+
this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + inside.out.x * reach, feet.floor, centre[2] + inside.out.z * reach]);
|
|
11306
|
+
}
|
|
11307
|
+
/**
|
|
11308
|
+
* Whether what stands on the points `held` of its feet (`all` of them whole) stays up with its centre at `centre`: the centre is inside what holds by `UNDERMINED_STAND` per metre of its height above `floor`, or it keeps
|
|
11309
|
+
* most of the hold it had (`UNDERMINED_KEEP` of how far inside its whole feet `all` the centre was; null when those are gone with a leg).
|
|
11310
|
+
*/
|
|
11311
|
+
standsWith(held, all, centre, floor) {
|
|
11312
|
+
if (held.length < 3) return false;
|
|
11313
|
+
const now = insideBy(convexHull([...held]), [centre[0], centre[2]]).depth;
|
|
11314
|
+
if (now > UNDERMINED_STAND * (centre[1] - floor)) return true;
|
|
11315
|
+
return all !== null && now >= UNDERMINED_KEEP * insideBy(convexHull([...all]), [centre[0], centre[2]]).depth;
|
|
11316
|
+
}
|
|
11317
|
+
/**
|
|
11318
|
+
* Where `meshes` touch the floor, (x, z) in the world, and how high that floor is (their lowest drawn point); null with nothing drawn. The bottom faces (triangles
|
|
11319
|
+
* within `FEET_BAND` of the lowest point) give their corners, the middles of their sides and their own middles: the base of a cabinet is held along its edges and
|
|
11320
|
+
* across, not only at its four corners, and a mesh merged from a frame and its legs is held under each leg, not in the air between them.
|
|
11321
|
+
*/
|
|
11322
|
+
lowPoints(meshes) {
|
|
11323
|
+
const faces = [];
|
|
11324
|
+
let floor = Infinity;
|
|
11325
|
+
for (const mv of meshes) {
|
|
11326
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
11327
|
+
const points = [];
|
|
11328
|
+
this.visuals.rangePoints(mv, mv.mesh.matrixWorld, points);
|
|
11329
|
+
const count = points.length / 3;
|
|
11330
|
+
const index = mv.mesh.geometry.getIndex()?.array;
|
|
11331
|
+
const from = mv.range ? mv.range[0] : 0;
|
|
11332
|
+
const total = index ? index.length : count;
|
|
11333
|
+
for (let i = 0; i + 2 < total; i += 3) {
|
|
11334
|
+
const a = (index ? index[i] : i) - from, b = (index ? index[i + 1] : i + 1) - from, c = (index ? index[i + 2] : i + 2) - from;
|
|
11335
|
+
if (a < 0 || b < 0 || c < 0 || a >= count || b >= count || c >= count) continue;
|
|
11336
|
+
for (const k of [a, b, c]) {
|
|
11337
|
+
faces.push(points[k * 3], points[k * 3 + 1], points[k * 3 + 2]);
|
|
11338
|
+
floor = Math.min(floor, points[k * 3 + 1]);
|
|
11339
|
+
}
|
|
11340
|
+
}
|
|
11341
|
+
}
|
|
11342
|
+
if (faces.length === 0) return null;
|
|
11343
|
+
const out = [];
|
|
11344
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11345
|
+
const add = (x, z) => {
|
|
11346
|
+
const key = `${Math.round(x * 1e3)},${Math.round(z * 1e3)}`;
|
|
11347
|
+
if (seen.has(key)) return;
|
|
11348
|
+
seen.add(key);
|
|
11349
|
+
out.push([x, z]);
|
|
11350
|
+
};
|
|
11351
|
+
for (let i = 0; i < faces.length; i += 9) {
|
|
11352
|
+
if (faces[i + 1] > floor + FEET_BAND || faces[i + 4] > floor + FEET_BAND || faces[i + 7] > floor + FEET_BAND) continue;
|
|
11353
|
+
const ax = faces[i], az = faces[i + 2], bx = faces[i + 3], bz = faces[i + 5], cx = faces[i + 6], cz = faces[i + 8];
|
|
11354
|
+
add(ax, az);
|
|
11355
|
+
add(bx, bz);
|
|
11356
|
+
add(cx, cz);
|
|
11357
|
+
add((ax + bx) / 2, (az + bz) / 2);
|
|
11358
|
+
add((bx + cx) / 2, (bz + cz) / 2);
|
|
11359
|
+
add((ax + cx) / 2, (az + cz) / 2);
|
|
11360
|
+
add((ax + bx + cx) / 3, (az + bz + cz) / 3);
|
|
11361
|
+
}
|
|
11362
|
+
return out.length > 0 ? { floor, points: out } : null;
|
|
11363
|
+
}
|
|
11364
|
+
/** Whether the ground, a fixed top or a piece (not `objectId` itself) is within `BROKEN_GAP` under the point (x, z) of a foot at height `y`. */
|
|
11365
|
+
holdsAt(objectId, x, z, y) {
|
|
11366
|
+
return Math.max(this.groundAt(x, z), this.staticTopAtBut(objectId, x, z, y, BROKEN_GAP), this.pieceSys.topAt(x, z, y, BROKEN_GAP, objectId)) >= y - BROKEN_GAP;
|
|
11367
|
+
}
|
|
11368
|
+
/** Whether the ground just past the disc `d`, on the way from its middle to the foot at (x, z), is where the object's feet (`floor`) were: it stood on the ground that went. */
|
|
11369
|
+
stoodBeside(x, z, d, floor) {
|
|
11370
|
+
const fx = x - d.x, fz = z - d.z;
|
|
11371
|
+
const length = Math.hypot(fx, fz);
|
|
11372
|
+
const ux = length > 1e-6 ? fx / length : 1, uz = length > 1e-6 ? fz / length : 0;
|
|
11373
|
+
const reach = d.radius + UNDERMINED_RIM;
|
|
11374
|
+
const ground = this.groundAt(d.x + ux * reach, d.z + uz * reach);
|
|
11375
|
+
return ground >= floor - BROKEN_GAP - UNDERMINED_RIM_DROP && ground <= floor + UNDERMINED_RIM_RISE;
|
|
11376
|
+
}
|
|
10988
11377
|
/** Whether the lowest of `boxes` (world boxes of the object `objectId`) has the ground, a fixed top or a piece within `BROKEN_GAP` under it. */
|
|
10989
11378
|
standsOn(objectId, boxes) {
|
|
10990
11379
|
if (boxes.length === 0) return false;
|
|
@@ -11001,6 +11390,10 @@ var Renderer = class {
|
|
|
11001
11390
|
return false;
|
|
11002
11391
|
}
|
|
11003
11392
|
/** The kind of kit piece a bound object is, by the mark on its root or the nearest one above it (a house binds a group inside its marked root); '' when unmarked. */
|
|
11393
|
+
/** Whether what is left of the object is fixed where it was laid and still anchored (`DestructionWorld.fixedInPlace`): it stands by its load path, it is never let go as a piece. */
|
|
11394
|
+
heldByWorld(objectId) {
|
|
11395
|
+
return this.world.fixedInPlace(objectId);
|
|
11396
|
+
}
|
|
11004
11397
|
kindOf(b) {
|
|
11005
11398
|
for (let o = b.root; o; o = o.parent) {
|
|
11006
11399
|
const kind = kitOriginOf3(o)?.kind;
|
|
@@ -11039,7 +11432,7 @@ var Renderer = class {
|
|
|
11039
11432
|
* what holds it and it goes over until the top meets the floor. Past `CONTACT_MESHES` meshes it keeps the corners of its box; up to `PART_BOX_MESHES`, what lands on it lands
|
|
11040
11433
|
* on its parts.
|
|
11041
11434
|
*/
|
|
11042
|
-
setContacts(b, body, meshes) {
|
|
11435
|
+
setContacts(b, body, meshes, fitWhole = false) {
|
|
11043
11436
|
if (meshes.length > PART_BOX_MESHES) {
|
|
11044
11437
|
body.contacts = void 0;
|
|
11045
11438
|
body.partBoxes = void 0;
|
|
@@ -11056,7 +11449,7 @@ var Renderer = class {
|
|
|
11056
11449
|
this.visuals.localBox(mv, lb);
|
|
11057
11450
|
if (lb.isEmpty()) continue;
|
|
11058
11451
|
m4.multiplyMatrices(inv, mv.mesh.matrixWorld);
|
|
11059
|
-
this.partBoxesOf(mv, { lb, m4, from: [cx, cy, cz] }, boxes);
|
|
11452
|
+
this.partBoxesOf(mv, { lb, m4, from: [cx, cy, cz], fitWhole }, boxes);
|
|
11060
11453
|
lb.applyMatrix4(m4);
|
|
11061
11454
|
for (let i = 0; i < 8; i++) points.push([(i & 1 ? lb.max.x : lb.min.x) - cx, (i & 2 ? lb.max.y : lb.min.y) - cy, (i & 4 ? lb.max.z : lb.min.z) - cz]);
|
|
11062
11455
|
}
|
|
@@ -11177,28 +11570,67 @@ var Renderer = class {
|
|
|
11177
11570
|
return own;
|
|
11178
11571
|
}
|
|
11179
11572
|
/**
|
|
11180
|
-
* The boxes of one mesh in the piece's frame, from its centre of mass, turned as the mesh is drawn: a
|
|
11181
|
-
* place in the piece; a part drawn by a range of a merged mesh (a roof sheet in the house's roof mesh) is fitted to its own vertices (`fitOrientedBoxes`), since the box
|
|
11573
|
+
* The boxes of one mesh in the piece's frame, from its centre of mass, turned as the mesh is drawn: a mesh drawn as boxes round the air is those boxes (`hollowBoxesOf`);
|
|
11574
|
+
* else a plain mesh is its geometry's box in its own space, turned by its place in the piece; a part drawn by a range of a merged mesh (a roof sheet in the house's roof mesh) is fitted to its own vertices (`fitOrientedBoxes`), since the box
|
|
11182
11575
|
* of those vertices in the merged mesh's space is the box around a tilted sheet, mostly air.
|
|
11183
11576
|
*/
|
|
11184
11577
|
partBoxesOf(mv, at, out) {
|
|
11185
11578
|
const [cx, cy, cz] = at.from;
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
const
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
const half = [Math.abs((box.high[0] - box.low[0]) * scale2.x) / 2, Math.abs((box.high[1] - box.low[1]) * scale2.y) / 2, Math.abs((box.high[2] - box.low[2]) * scale2.z) / 2];
|
|
11198
|
-
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half, rotation: [quat2.x, quat2.y, quat2.z, quat2.w] });
|
|
11199
|
-
}
|
|
11200
|
-
return;
|
|
11579
|
+
const built = mv.range ? null : builtSolidsOf(mv.mesh);
|
|
11580
|
+
const solids = at.fitWhole && !mv.range && !built ? solidBoxesOf(mv.mesh.geometry) : null;
|
|
11581
|
+
if (solids) {
|
|
11582
|
+
const pos2 = new this.THREE.Vector3();
|
|
11583
|
+
const quat2 = new this.THREE.Quaternion();
|
|
11584
|
+
const scale2 = new this.THREE.Vector3();
|
|
11585
|
+
at.m4.decompose(pos2, quat2, scale2);
|
|
11586
|
+
for (const box of solids) {
|
|
11587
|
+
const c2 = new this.THREE.Vector3((box[0] + box[3]) / 2, (box[1] + box[4]) / 2, (box[2] + box[5]) / 2).applyMatrix4(at.m4);
|
|
11588
|
+
const half2 = [Math.max(5e-3, Math.abs((box[3] - box[0]) * scale2.x) / 2), Math.max(5e-3, Math.abs((box[4] - box[1]) * scale2.y) / 2), Math.max(5e-3, Math.abs((box[5] - box[2]) * scale2.z) / 2)];
|
|
11589
|
+
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half: half2, rotation: [quat2.x, quat2.y, quat2.z, quat2.w] });
|
|
11201
11590
|
}
|
|
11591
|
+
return;
|
|
11592
|
+
}
|
|
11593
|
+
if (built) {
|
|
11594
|
+
const pos2 = new this.THREE.Vector3();
|
|
11595
|
+
const quat2 = new this.THREE.Quaternion();
|
|
11596
|
+
const scale2 = new this.THREE.Vector3();
|
|
11597
|
+
at.m4.decompose(pos2, quat2, scale2);
|
|
11598
|
+
const c2 = new this.THREE.Vector3();
|
|
11599
|
+
const q = new this.THREE.Quaternion();
|
|
11600
|
+
const even = (Math.abs(scale2.x) + Math.abs(scale2.y) + Math.abs(scale2.z)) / 3;
|
|
11601
|
+
for (const solid of built) {
|
|
11602
|
+
c2.set(solid.center[0], solid.center[1], solid.center[2]).applyMatrix4(at.m4);
|
|
11603
|
+
q.set(solid.rotation[0], solid.rotation[1], solid.rotation[2], solid.rotation[3]);
|
|
11604
|
+
const turned = Math.abs(q.w) < 1 - 1e-9;
|
|
11605
|
+
const s = turned ? [even, even, even] : [Math.abs(scale2.x), Math.abs(scale2.y), Math.abs(scale2.z)];
|
|
11606
|
+
q.premultiply(quat2).normalize();
|
|
11607
|
+
const round = isRoundSolid(solid) && Math.abs(s[0] - s[2]) <= 1e-9;
|
|
11608
|
+
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half: [Math.max(5e-3, solid.half[0] * s[0]), Math.max(5e-3, solid.half[1] * s[1]), Math.max(5e-3, solid.half[2] * s[2])], rotation: [q.x, q.y, q.z, q.w], ...round ? { round: true } : {} });
|
|
11609
|
+
}
|
|
11610
|
+
return;
|
|
11611
|
+
}
|
|
11612
|
+
const own = [];
|
|
11613
|
+
this.visuals.rangePoints(mv, new this.THREE.Matrix4(), own);
|
|
11614
|
+
const drawn = hollowBoxesOf(own, mv.range ? RANGED : OWN_MESH);
|
|
11615
|
+
if (drawn) {
|
|
11616
|
+
const pos2 = new this.THREE.Vector3();
|
|
11617
|
+
const quat2 = new this.THREE.Quaternion();
|
|
11618
|
+
const scale2 = new this.THREE.Vector3();
|
|
11619
|
+
at.m4.decompose(pos2, quat2, scale2);
|
|
11620
|
+
const c2 = new this.THREE.Vector3();
|
|
11621
|
+
const q = new this.THREE.Quaternion();
|
|
11622
|
+
const even = (Math.abs(scale2.x) + Math.abs(scale2.y) + Math.abs(scale2.z)) / 3;
|
|
11623
|
+
for (const box of drawn) {
|
|
11624
|
+
c2.set(box.center[0], box.center[1], box.center[2]).applyMatrix4(at.m4);
|
|
11625
|
+
const half2 = box.rotation ? [box.half[0] * even, box.half[1] * even, box.half[2] * even] : [Math.abs(box.half[0] * scale2.x), Math.abs(box.half[1] * scale2.y), Math.abs(box.half[2] * scale2.z)];
|
|
11626
|
+
if (box.rotation) q.set(box.rotation[0], box.rotation[1], box.rotation[2], box.rotation[3]).premultiply(quat2).normalize();
|
|
11627
|
+
else q.copy(quat2);
|
|
11628
|
+
const thin = mv.range ? 0 : 5e-3;
|
|
11629
|
+
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half: [Math.max(thin, half2[0]), Math.max(thin, half2[1]), Math.max(thin, half2[2])], rotation: [q.x, q.y, q.z, q.w] });
|
|
11630
|
+
}
|
|
11631
|
+
return;
|
|
11632
|
+
}
|
|
11633
|
+
if (mv.range) {
|
|
11202
11634
|
if (isRigidPose(at.m4.elements)) {
|
|
11203
11635
|
const turn2 = new this.THREE.Quaternion().setFromRotationMatrix(at.m4);
|
|
11204
11636
|
const c2 = new this.THREE.Vector3();
|
|
@@ -11221,11 +11653,14 @@ var Renderer = class {
|
|
|
11221
11653
|
at.m4.decompose(pos, quat, scale);
|
|
11222
11654
|
const c = at.lb.getCenter(new this.THREE.Vector3()).applyMatrix4(at.m4);
|
|
11223
11655
|
const size = at.lb.getSize(new this.THREE.Vector3());
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11656
|
+
const half = [Math.max(5e-3, Math.abs(size.x * scale.x) / 2), Math.max(5e-3, Math.abs(size.y * scale.y) / 2), Math.max(5e-3, Math.abs(size.z * scale.z) / 2)];
|
|
11657
|
+
const geometry = mv.mesh.geometry;
|
|
11658
|
+
const params = geometry.parameters ?? {};
|
|
11659
|
+
const whole = typeof params.thetaLength !== "number" || Math.abs(params.thetaLength - 2 * Math.PI) < 1e-6;
|
|
11660
|
+
const cylinder = geometry.type === "CylinderGeometry" && !mv.range;
|
|
11661
|
+
const straight = cylinder && whole && params.openEnded !== true && isRoundSolid({ kind: params.radiusTop === params.radiusBottom ? "cylinder" : "cone", half });
|
|
11662
|
+
const curved = !mv.range && !straight && (cylinder || geometry.type === "ConeGeometry" || geometry.type === "SphereGeometry");
|
|
11663
|
+
out.push({ center: [c.x - cx, c.y - cy, c.z - cz], half, rotation: [quat.x, quat.y, quat.z, quat.w], ...straight ? { round: true } : {}, ...curved ? { hull: this.hullOf(mv, at.lb, scale) } : {} });
|
|
11229
11664
|
}
|
|
11230
11665
|
/**
|
|
11231
11666
|
* A piece of furniture standing on feet too close for its height (a board on two legs in a line, a lone leg) does not stay up: the box of a piece hides that its weight is up
|
|
@@ -11802,6 +12237,7 @@ var Renderer = class {
|
|
|
11802
12237
|
wakeRegion(x, z, radius) {
|
|
11803
12238
|
this.fragments.wakeRegion(x, z, radius);
|
|
11804
12239
|
this.pieceSys.wakeRegion(x, z, radius);
|
|
12240
|
+
if (this.autoSplit && this.undermined.length < UNDERMINED_MAX) this.undermined.push({ x, z, radius });
|
|
11805
12241
|
}
|
|
11806
12242
|
stats() {
|
|
11807
12243
|
return { fragments: this.fragments.count, particles: this.vfx.sprites().live + this.ownedVfxParticles(), pieces: this.pieceSys.list.length, decals: this.visuals.decalCount + this.ground.count };
|
|
@@ -11860,6 +12296,55 @@ function lighten(color, t) {
|
|
|
11860
12296
|
};
|
|
11861
12297
|
return ch(16) | ch(8) | ch(0);
|
|
11862
12298
|
}
|
|
12299
|
+
function solidBoxesOf(geometry) {
|
|
12300
|
+
const position = geometry.getAttribute("position");
|
|
12301
|
+
if (!position || position.count <= 24) return null;
|
|
12302
|
+
const parent = new Int32Array(position.count);
|
|
12303
|
+
for (let i = 0; i < parent.length; i++) parent[i] = i;
|
|
12304
|
+
const find = (i) => {
|
|
12305
|
+
while (parent[i] !== i) {
|
|
12306
|
+
parent[i] = parent[parent[i]];
|
|
12307
|
+
i = parent[i];
|
|
12308
|
+
}
|
|
12309
|
+
return i;
|
|
12310
|
+
};
|
|
12311
|
+
const join = (a, b) => {
|
|
12312
|
+
const ra = find(a), rb = find(b);
|
|
12313
|
+
if (ra !== rb) parent[ra] = rb;
|
|
12314
|
+
};
|
|
12315
|
+
const corners = /* @__PURE__ */ new Map();
|
|
12316
|
+
for (let i = 0; i < position.count; i++) {
|
|
12317
|
+
const key = `${Math.round(position.getX(i) / SOLID_WELD)},${Math.round(position.getY(i) / SOLID_WELD)},${Math.round(position.getZ(i) / SOLID_WELD)}`;
|
|
12318
|
+
const first = corners.get(key);
|
|
12319
|
+
if (first === void 0) corners.set(key, i);
|
|
12320
|
+
else join(i, first);
|
|
12321
|
+
}
|
|
12322
|
+
const index = geometry.getIndex();
|
|
12323
|
+
const triangles2 = index ? index.count / 3 : position.count / 3;
|
|
12324
|
+
for (let t = 0; t < triangles2; t++) {
|
|
12325
|
+
const a = index ? index.getX(t * 3) : t * 3;
|
|
12326
|
+
join(a, index ? index.getX(t * 3 + 1) : t * 3 + 1);
|
|
12327
|
+
join(a, index ? index.getX(t * 3 + 2) : t * 3 + 2);
|
|
12328
|
+
}
|
|
12329
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
12330
|
+
for (let i = 0; i < position.count; i++) {
|
|
12331
|
+
const root = find(i);
|
|
12332
|
+
const x = position.getX(i), y = position.getY(i), z = position.getZ(i);
|
|
12333
|
+
const box = boxes.get(root);
|
|
12334
|
+
if (!box) {
|
|
12335
|
+
if (boxes.size >= SOLIDS_MAX) return null;
|
|
12336
|
+
boxes.set(root, [x, y, z, x, y, z]);
|
|
12337
|
+
continue;
|
|
12338
|
+
}
|
|
12339
|
+
box[0] = Math.min(box[0], x);
|
|
12340
|
+
box[1] = Math.min(box[1], y);
|
|
12341
|
+
box[2] = Math.min(box[2], z);
|
|
12342
|
+
box[3] = Math.max(box[3], x);
|
|
12343
|
+
box[4] = Math.max(box[4], y);
|
|
12344
|
+
box[5] = Math.max(box[5], z);
|
|
12345
|
+
}
|
|
12346
|
+
return boxes.size > 1 ? [...boxes.values()] : null;
|
|
12347
|
+
}
|
|
11863
12348
|
function convexHull(points) {
|
|
11864
12349
|
const sorted = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
11865
12350
|
if (sorted.length < 3) return sorted;
|