@adatechnology/game-destruction-three 1.0.0 → 1.1.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/README.md +8 -0
- package/dist/index.d.ts +26 -5
- package/dist/index.global.js +741 -125
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +611 -100
- 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 +12 -12
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;
|
|
@@ -3710,6 +3822,13 @@ var TAPER_MIN = 2e-3;
|
|
|
3710
3822
|
var RING_SEGMENTS = 16;
|
|
3711
3823
|
var TOPPLE = 3;
|
|
3712
3824
|
var HOLD_MARGIN = 4;
|
|
3825
|
+
var HOLD_MARGIN_REAL = 6;
|
|
3826
|
+
var holdPush = (params) => {
|
|
3827
|
+
const e = Math.abs(params.edge);
|
|
3828
|
+
const arm = params.height * params.height + e * e;
|
|
3829
|
+
if (arm <= 0) return 0;
|
|
3830
|
+
return Math.min(HOLD_MARGIN * params.gravity * e / arm, HOLD_MARGIN_REAL * params.gravity * e / (params.turning + arm));
|
|
3831
|
+
};
|
|
3713
3832
|
var SIDE_DEAD = 0.01;
|
|
3714
3833
|
var BOX_FOOT = 0.02;
|
|
3715
3834
|
var PUSH_SPIN = 0.3;
|
|
@@ -4166,7 +4285,7 @@ var EnginePieces = class {
|
|
|
4166
4285
|
return { kind: "compound", children: [{ shape: { kind: "cylinder", halfHeight: b.halfExtents[round.axis], radius: round.radius }, position: [0, 0, 0], rotation }] };
|
|
4167
4286
|
}
|
|
4168
4287
|
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 })) };
|
|
4288
|
+
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
4289
|
}
|
|
4171
4290
|
return { kind: "box", half: b.halfExtents };
|
|
4172
4291
|
}
|
|
@@ -4472,11 +4591,24 @@ var EnginePieces = class {
|
|
|
4472
4591
|
/**
|
|
4473
4592
|
* The push (rad/s2) that turns a piece about the edge of its support at `edge` (m from its centre, `height` m above it): the kit's `TOPPLE`, and on a support narrow both ways (a leg, a pole: a plate on its
|
|
4474
4593
|
* edge is narrow one way only) at least what beats gravity's hold (at most `g |edge| / (height^2 + edge^2)` for any shape: a 5 cm leg 74 cm tall held against `TOPPLE` alone and stood for ever). Not where only
|
|
4475
|
-
* the contacts of one instant sit off its centre: a box rocking on a table's edge reads like that, and stays.
|
|
4594
|
+
* the contacts of one instant sit off its centre: a box rocking on a table's edge reads like that, and stays. `turning` is the piece's own inertia about that edge's
|
|
4595
|
+
* axis (`turningOf`): the strong push is bounded by it (`holdPush`).
|
|
4476
4596
|
*/
|
|
4477
|
-
topplePush(edge, height, isNarrow) {
|
|
4597
|
+
topplePush(edge, height, isNarrow, turning) {
|
|
4478
4598
|
const push = TOPPLE * Math.min(height, 1);
|
|
4479
|
-
return isNarrow ? Math.max(push,
|
|
4599
|
+
return isNarrow ? Math.max(push, holdPush({ edge, height, gravity: this.o.gravity, turning })) : push;
|
|
4600
|
+
}
|
|
4601
|
+
/**
|
|
4602
|
+
* The moment of inertia of the piece per kilogram (m²) about the world axis `axis` (0 x, 2 z) through its centre of mass, as the box it is: what resists its turning
|
|
4603
|
+
* about the edge it would go over (`holdPush`).
|
|
4604
|
+
*/
|
|
4605
|
+
turningOf(b, axis) {
|
|
4606
|
+
const [hx, hy, hz] = b.halfExtents;
|
|
4607
|
+
const { x, y, z, w } = b.root.quaternion;
|
|
4608
|
+
const ax = axis === 0 ? 1 - 2 * (y * y + z * z) : 2 * (x * z - y * w);
|
|
4609
|
+
const ay = axis === 0 ? 2 * (x * y - z * w) : 2 * (y * z + x * w);
|
|
4610
|
+
const az = axis === 0 ? 2 * (x * z + y * w) : 1 - 2 * (x * x + y * y);
|
|
4611
|
+
return ((hy * hy + hz * hz) * ax * ax + (hx * hx + hz * hz) * ay * ay + (hx * hx + hy * hy) * az * az) / 3;
|
|
4480
4612
|
}
|
|
4481
4613
|
topple(b, dt) {
|
|
4482
4614
|
const link = this.links.get(b);
|
|
@@ -4544,7 +4676,7 @@ var EnginePieces = class {
|
|
|
4544
4676
|
const v = b.velocity;
|
|
4545
4677
|
if (wx <= wz) {
|
|
4546
4678
|
const edge = dirX > 0 ? x1 : x0;
|
|
4547
|
-
const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN) * dt : 0;
|
|
4679
|
+
const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN, this.turningOf(b, 2)) * dt : 0;
|
|
4548
4680
|
const rx = -edge;
|
|
4549
4681
|
const ry = -low;
|
|
4550
4682
|
w[2] += dw;
|
|
@@ -4552,7 +4684,7 @@ var EnginePieces = class {
|
|
|
4552
4684
|
v[1] += dw * rx;
|
|
4553
4685
|
} else {
|
|
4554
4686
|
const edge = dirZ > 0 ? z1 : z0;
|
|
4555
|
-
const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN) * dt : 0;
|
|
4687
|
+
const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN, this.turningOf(b, 0)) * dt : 0;
|
|
4556
4688
|
const rz = -edge;
|
|
4557
4689
|
const ry = -low;
|
|
4558
4690
|
w[0] += dw;
|
|
@@ -6671,10 +6803,10 @@ function bendPositions(positions, from, to, point, axis, side, angle, radius) {
|
|
|
6671
6803
|
const turn2 = angle * share * share * (3 - 2 * share);
|
|
6672
6804
|
const cos = Math.cos(turn2);
|
|
6673
6805
|
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 *
|
|
6806
|
+
const dot3 = kx * rx + ky * ry + kz * rz;
|
|
6807
|
+
positions[i] = point[0] + rx * cos + (ky * rz - kz * ry) * sin + kx * dot3 * (1 - cos);
|
|
6808
|
+
positions[i + 1] = point[1] + ry * cos + (kz * rx - kx * rz) * sin + ky * dot3 * (1 - cos);
|
|
6809
|
+
positions[i + 2] = point[2] + rz * cos + (kx * ry - ky * rx) * sin + kz * dot3 * (1 - cos);
|
|
6678
6810
|
}
|
|
6679
6811
|
}
|
|
6680
6812
|
|
|
@@ -6843,9 +6975,9 @@ var MeshRayProbe = class {
|
|
|
6843
6975
|
const grown = new Uint32Array(size);
|
|
6844
6976
|
grown.set(this.candidates);
|
|
6845
6977
|
this.candidates = grown;
|
|
6846
|
-
const
|
|
6847
|
-
|
|
6848
|
-
this.triangles =
|
|
6978
|
+
const numbers2 = new Uint32Array(Math.max(this.triangles.length, Math.ceil(size / 3)));
|
|
6979
|
+
numbers2.set(this.triangles);
|
|
6980
|
+
this.triangles = numbers2;
|
|
6849
6981
|
this.candidateIndex = new this.THREE.BufferAttribute(this.candidates, 1);
|
|
6850
6982
|
}
|
|
6851
6983
|
};
|
|
@@ -8440,6 +8572,9 @@ var COLLAPSE_CLOUD_KG = 1e3;
|
|
|
8440
8572
|
var REBAR_COLOR = 7628380;
|
|
8441
8573
|
var STEEL_DENSITY = 7850;
|
|
8442
8574
|
var CHIP_DECAL_EDGE = 0.05;
|
|
8575
|
+
var CHIP_GAP_REACH = 0.03;
|
|
8576
|
+
var CHIP_GAP_SHADE = 0.4;
|
|
8577
|
+
var CHIP_GAP_WIDTH = 1.15;
|
|
8443
8578
|
var CRATER_RADIUS2 = 2.5;
|
|
8444
8579
|
var CRATER_MIN_RADIUS = 0.012;
|
|
8445
8580
|
var CRATER_LIGHTEN = 0.12;
|
|
@@ -8471,10 +8606,71 @@ var HINGE_STILL_SPEED = 0.2;
|
|
|
8471
8606
|
var HINGE_STILL_SPIN = 0.5;
|
|
8472
8607
|
var PREFIT_SLICE_MS = 1;
|
|
8473
8608
|
var CONTACT_MESHES = 12;
|
|
8474
|
-
var PART_BOX_MESHES =
|
|
8609
|
+
var PART_BOX_MESHES = 96;
|
|
8475
8610
|
var ROUND_SAMPLES = 400;
|
|
8476
|
-
var
|
|
8611
|
+
var ROUND_SIDES2 = 0.12;
|
|
8477
8612
|
var ROUND_SLACK = 1.12;
|
|
8613
|
+
var ROUND_FILL = 0.9;
|
|
8614
|
+
var FILL_GRID = 8;
|
|
8615
|
+
var hullRadiusAt = (profile, radius, at) => {
|
|
8616
|
+
if (!profile || profile.length < 2) return radius;
|
|
8617
|
+
const hull = [];
|
|
8618
|
+
for (const point of profile) {
|
|
8619
|
+
while (hull.length >= 2) {
|
|
8620
|
+
const [a, ra] = hull[hull.length - 2];
|
|
8621
|
+
const [b, rb] = hull[hull.length - 1];
|
|
8622
|
+
if ((b - a) * (point[1] - ra) - (rb - ra) * (point[0] - a) >= 0) hull.pop();
|
|
8623
|
+
else break;
|
|
8624
|
+
}
|
|
8625
|
+
hull.push(point);
|
|
8626
|
+
}
|
|
8627
|
+
if (at <= hull[0][0]) return hull[0][1];
|
|
8628
|
+
for (let i = 1; i < hull.length; i++) {
|
|
8629
|
+
const [a, ra] = hull[i - 1];
|
|
8630
|
+
const [b, rb] = hull[i];
|
|
8631
|
+
if (at <= b) return ra + (rb - ra) * (at - a) / (b - a || 1);
|
|
8632
|
+
}
|
|
8633
|
+
return hull[hull.length - 1][1];
|
|
8634
|
+
};
|
|
8635
|
+
var insideDrawn = (mesh, built, x, y, z) => {
|
|
8636
|
+
if (built) {
|
|
8637
|
+
for (const solid of built) {
|
|
8638
|
+
const [qx, qy, qz, qw] = solid.rotation;
|
|
8639
|
+
const px = x - solid.center[0], py = y - solid.center[1], pz = z - solid.center[2];
|
|
8640
|
+
const tx = 2 * (-qy * pz + qz * py), ty = 2 * (-qz * px + qx * pz), tz = 2 * (-qx * py + qy * px);
|
|
8641
|
+
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;
|
|
8642
|
+
const [hx, hy, hz] = solid.half;
|
|
8643
|
+
if (solid.kind === "cylinder" || solid.kind === "cone") {
|
|
8644
|
+
if (Math.abs(ly) <= hy && (lx / hx) ** 2 + (lz / hz) ** 2 <= 1) return true;
|
|
8645
|
+
} else if (solid.kind === "sphere") {
|
|
8646
|
+
if ((lx / hx) ** 2 + (ly / hy) ** 2 + (lz / hz) ** 2 <= 1) return true;
|
|
8647
|
+
} else if (Math.abs(lx) <= hx && Math.abs(ly) <= hy && Math.abs(lz) <= hz) return true;
|
|
8648
|
+
}
|
|
8649
|
+
return false;
|
|
8650
|
+
}
|
|
8651
|
+
const geometry = mesh.geometry;
|
|
8652
|
+
const p = geometry.parameters ?? {};
|
|
8653
|
+
const n = (key, fallback) => typeof p[key] === "number" ? p[key] : fallback;
|
|
8654
|
+
switch (geometry.type) {
|
|
8655
|
+
case "BoxGeometry":
|
|
8656
|
+
return Math.abs(x) <= n("width", 1) / 2 && Math.abs(y) <= n("height", 1) / 2 && Math.abs(z) <= n("depth", 1) / 2;
|
|
8657
|
+
case "CylinderGeometry":
|
|
8658
|
+
case "ConeGeometry": {
|
|
8659
|
+
const h = n("height", 1) / 2;
|
|
8660
|
+
if (Math.abs(y) > h || p.openEnded === true) return false;
|
|
8661
|
+
const top = geometry.type === "ConeGeometry" ? 0 : n("radiusTop", 1);
|
|
8662
|
+
const bottom = geometry.type === "ConeGeometry" ? n("radius", 1) : n("radiusBottom", 1);
|
|
8663
|
+
return Math.hypot(x, z) <= bottom + (top - bottom) * (y + h) / (2 * h || 1);
|
|
8664
|
+
}
|
|
8665
|
+
case "SphereGeometry":
|
|
8666
|
+
return Math.hypot(x, y, z) <= n("radius", 1);
|
|
8667
|
+
default: {
|
|
8668
|
+
if (!geometry.boundingBox) geometry.computeBoundingBox();
|
|
8669
|
+
const box = geometry.boundingBox;
|
|
8670
|
+
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;
|
|
8671
|
+
}
|
|
8672
|
+
}
|
|
8673
|
+
};
|
|
8478
8674
|
var RIM_POINTS = 12;
|
|
8479
8675
|
var rimPoints = (round, half) => {
|
|
8480
8676
|
const out = [];
|
|
@@ -8532,6 +8728,16 @@ var profileOf = (points, axis, half, radius) => {
|
|
|
8532
8728
|
};
|
|
8533
8729
|
var BROKEN_GAP = 0.03;
|
|
8534
8730
|
var BROKEN_SAMPLES = [[0.5, 0.5], [0.1, 0.1], [0.9, 0.1], [0.1, 0.9], [0.9, 0.9]];
|
|
8731
|
+
var UNDERMINED_MAX = 64;
|
|
8732
|
+
var UNDERMINED_RIM = 0.04;
|
|
8733
|
+
var UNDERMINED_RIM_DROP = 0.05;
|
|
8734
|
+
var UNDERMINED_RIM_RISE = 0.1;
|
|
8735
|
+
var UNDERMINED_STAND = 0.4;
|
|
8736
|
+
var UNDERMINED_KEEP = 0.6;
|
|
8737
|
+
var SOLIDS_MAX = 64;
|
|
8738
|
+
var UNDERMINED_PUSH = 0.6;
|
|
8739
|
+
var UNDERMINED_STILL = 0.05;
|
|
8740
|
+
var SOLID_WELD = 1e-4;
|
|
8535
8741
|
var UNCHECKED_KINDS = /* @__PURE__ */ new Set(["structure", "room", "ground"]);
|
|
8536
8742
|
var FIRE_CEILING_SECONDS = 3600;
|
|
8537
8743
|
var GENERIC_REFERENCE_RADIUS = 15;
|
|
@@ -8679,6 +8885,8 @@ var Renderer = class {
|
|
|
8679
8885
|
__publicField(this, "pieceBoxes", /* @__PURE__ */ new WeakMap());
|
|
8680
8886
|
/** Objects broken since the last update: `checkBroken` looks at what is left of them. */
|
|
8681
8887
|
__publicField(this, "broken", /* @__PURE__ */ new Set());
|
|
8888
|
+
/** Discs of ground that changed since the last update (`wakeRegion`): `checkUndermined` looks at what stood on them. */
|
|
8889
|
+
__publicField(this, "undermined", []);
|
|
8682
8890
|
__publicField(this, "staticAt", 0);
|
|
8683
8891
|
__publicField(this, "queue", []);
|
|
8684
8892
|
/** 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 +9458,8 @@ var Renderer = class {
|
|
|
9250
9458
|
mv.mesh.updateWorldMatrix(true, false);
|
|
9251
9459
|
m4.multiplyMatrices(inv, mv.mesh.matrixWorld);
|
|
9252
9460
|
const stride = Math.max(1, Math.floor(pos.count / ROUND_SAMPLES));
|
|
9253
|
-
for (let
|
|
9254
|
-
p.fromBufferAttribute(pos,
|
|
9461
|
+
for (let i2 = 0; i2 < pos.count; i2 += stride) {
|
|
9462
|
+
p.fromBufferAttribute(pos, i2).applyMatrix4(m4);
|
|
9255
9463
|
points.push([p.x - cx, p.y - cy, p.z - cz]);
|
|
9256
9464
|
}
|
|
9257
9465
|
}
|
|
@@ -9259,22 +9467,64 @@ var Renderer = class {
|
|
|
9259
9467
|
const drawn = new Float64Array(3);
|
|
9260
9468
|
for (const q of points) for (let k = 0; k < 3; k++) drawn[k] = Math.max(drawn[k], Math.abs(q[k]));
|
|
9261
9469
|
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[
|
|
9470
|
+
const [i2, j2] = axis2 === 0 ? [1, 2] : axis2 === 1 ? [0, 2] : [0, 1];
|
|
9471
|
+
if (Math.abs(half[i2] - half[j2]) > ROUND_SIDES2 * Math.max(half[i2], half[j2])) return null;
|
|
9472
|
+
if (Math.abs(drawn[i2] - drawn[j2]) > ROUND_SIDES2 * Math.max(drawn[i2], drawn[j2])) return null;
|
|
9473
|
+
const reach = (drawn[i2] + drawn[j2]) / 2;
|
|
9474
|
+
for (const q of points) if (Math.hypot(q[i2], q[j2]) > reach * ROUND_SLACK) return null;
|
|
9475
|
+
return (half[i2] + half[j2]) / 2;
|
|
9268
9476
|
};
|
|
9269
9477
|
const radii = [0, 1, 2].map(fits);
|
|
9270
9478
|
if (radii.every((r) => r !== null)) {
|
|
9271
9479
|
const radius2 = (half[0] + half[1] + half[2]) / 3;
|
|
9480
|
+
if (this.drawnShareOf(b, body, (q) => Math.hypot(q[0], q[1], q[2]) <= radius2) < ROUND_FILL) return null;
|
|
9272
9481
|
return { kind: "sphere", axis: 1, radius: radius2, inertia: body.inertiaGiven ?? this.inertiaOf(b, body, "sphere", 1, radius2) };
|
|
9273
9482
|
}
|
|
9274
9483
|
const axis = [0, 1, 2].find((k) => radii[k] !== null);
|
|
9275
9484
|
if (axis === void 0) return null;
|
|
9276
9485
|
const radius = radii[axis] ?? 0;
|
|
9277
|
-
|
|
9486
|
+
const profile = profileOf(points, axis, half[axis], radius);
|
|
9487
|
+
const [i, j] = axis === 0 ? [1, 2] : axis === 1 ? [0, 2] : [0, 1];
|
|
9488
|
+
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;
|
|
9489
|
+
return { kind: "cylinder", axis, radius, inertia: body.inertiaGiven ?? this.inertiaOf(b, body, "cylinder", axis, radius), profile };
|
|
9490
|
+
}
|
|
9491
|
+
/** 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`). */
|
|
9492
|
+
hullOf(mv, lb, scale) {
|
|
9493
|
+
const own = [];
|
|
9494
|
+
this.visuals.rangePoints(mv, new this.THREE.Matrix4(), own);
|
|
9495
|
+
const c = lb.getCenter(new this.THREE.Vector3());
|
|
9496
|
+
const out = [];
|
|
9497
|
+
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));
|
|
9498
|
+
return out;
|
|
9499
|
+
}
|
|
9500
|
+
/**
|
|
9501
|
+
* 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
|
|
9502
|
+
* 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).
|
|
9503
|
+
*/
|
|
9504
|
+
drawnShareOf(b, body, inside) {
|
|
9505
|
+
const inv = specFrameInverse(this.THREE, b.root);
|
|
9506
|
+
const meshes = this.meshesOf(b).filter((mv) => this.visuals.shown(mv) && !mv.host).map((mv) => {
|
|
9507
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
9508
|
+
return { mesh: mv.mesh, built: builtSolidsOf(mv.mesh), back: new this.THREE.Matrix4().multiplyMatrices(inv, mv.mesh.matrixWorld).invert() };
|
|
9509
|
+
});
|
|
9510
|
+
const [cx, cy, cz] = body.localCenter;
|
|
9511
|
+
const half = body.halfExtents;
|
|
9512
|
+
const p = new this.THREE.Vector3();
|
|
9513
|
+
let shape = 0;
|
|
9514
|
+
let drawn = 0;
|
|
9515
|
+
for (let a = 0; a < FILL_GRID; a++) for (let c = 0; c < FILL_GRID; c++) for (let d = 0; d < FILL_GRID; d++) {
|
|
9516
|
+
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)];
|
|
9517
|
+
if (!inside(q)) continue;
|
|
9518
|
+
shape++;
|
|
9519
|
+
for (const m of meshes) {
|
|
9520
|
+
p.set(q[0] + cx, q[1] + cy, q[2] + cz).applyMatrix4(m.back);
|
|
9521
|
+
if (insideDrawn(m.mesh, m.built, p.x, p.y, p.z)) {
|
|
9522
|
+
drawn++;
|
|
9523
|
+
break;
|
|
9524
|
+
}
|
|
9525
|
+
}
|
|
9526
|
+
}
|
|
9527
|
+
return shape === 0 ? 1 : drawn / shape;
|
|
9278
9528
|
}
|
|
9279
9529
|
pieces() {
|
|
9280
9530
|
return [...this.pieceSys.list];
|
|
@@ -9364,6 +9614,7 @@ var Renderer = class {
|
|
|
9364
9614
|
this.work?.beginFrame();
|
|
9365
9615
|
if (!this.attached) this.drainQueue();
|
|
9366
9616
|
this.checkBroken();
|
|
9617
|
+
this.checkUndermined();
|
|
9367
9618
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
9368
9619
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
9369
9620
|
this.settlement.update(dt);
|
|
@@ -10422,9 +10673,33 @@ var Renderer = class {
|
|
|
10422
10673
|
const rotation = new T.Quaternion(ev.rotation[0], ev.rotation[1], ev.rotation[2], ev.rotation[3]);
|
|
10423
10674
|
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
10675
|
this.vfx.peekWorkshop()?.decals.clearInside(ev.center, [half.x, half.y, half.z], ev.rotation);
|
|
10676
|
+
if (pv) this.drawChipGap(pv, ev, center, rotation);
|
|
10425
10677
|
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
10678
|
this.impactSound(pv?.material ?? "", ev.center, 0.7, ev.blow);
|
|
10427
10679
|
}
|
|
10680
|
+
/**
|
|
10681
|
+
* 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,
|
|
10682
|
+
* 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.
|
|
10683
|
+
*/
|
|
10684
|
+
drawChipGap(pv, ev, center, rotation) {
|
|
10685
|
+
const mv = this.nearestMesh(pv, center);
|
|
10686
|
+
if (!mv || mv.mesh.userData.drawnSpalls?.includes(ev.part)) return;
|
|
10687
|
+
const def = this.world.materials.get(pv.material);
|
|
10688
|
+
const inner = def?.visual?.innerColor ?? fallbackColor(def);
|
|
10689
|
+
const color = [16, 8, 0].reduce((hex, shift) => hex | Math.round((inner >> shift & 255) * CHIP_GAP_SHADE) << shift, 0);
|
|
10690
|
+
const box = this.visuals.worldBox(mv, new this.THREE.Box3());
|
|
10691
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
10692
|
+
for (const side of [-1, 1]) {
|
|
10693
|
+
const normal = new this.THREE.Vector3(axis === 0 ? side : 0, axis === 1 ? side : 0, axis === 2 ? side : 0).applyQuaternion(rotation);
|
|
10694
|
+
const face = center.clone().addScaledVector(normal, ev.size[axis] / 2);
|
|
10695
|
+
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";
|
|
10696
|
+
const surface = normal[k] > 0 ? box.max[k] : box.min[k];
|
|
10697
|
+
if (Math.abs(face[k] - surface) > CHIP_GAP_REACH) continue;
|
|
10698
|
+
face[k] = surface;
|
|
10699
|
+
this.visuals.addSpall(mv, face, normal, Math.min(ev.size[(axis + 1) % 3], ev.size[(axis + 2) % 3]) / 2 * CHIP_GAP_WIDTH, color);
|
|
10700
|
+
}
|
|
10701
|
+
}
|
|
10702
|
+
}
|
|
10428
10703
|
onFracture(ev) {
|
|
10429
10704
|
const b = this.bounds.get(ev.object);
|
|
10430
10705
|
const pv = b?.parts.get(ev.part);
|
|
@@ -10615,7 +10890,7 @@ var Renderer = class {
|
|
|
10615
10890
|
if (!old.round) this.setContacts(b, old, this.meshesOf(b).filter((mv) => this.visuals.shown(mv)));
|
|
10616
10891
|
} else if (old.partBoxes) this.fitPartBoxes(b, old);
|
|
10617
10892
|
if (!this.splittingAtLoad) old.sleeping = false;
|
|
10618
|
-
} else if (kitOriginOf3(b.root)?.kind === "furniture" && !this.splittingAtLoad) {
|
|
10893
|
+
} else if (kitOriginOf3(b.root)?.kind === "furniture" && !this.splittingAtLoad && !this.heldByWorld(objectId)) {
|
|
10619
10894
|
const piece = this.makePiece(objectId);
|
|
10620
10895
|
piece.apart = true;
|
|
10621
10896
|
this.tipIfTopHeavy(b, true);
|
|
@@ -10901,9 +11176,10 @@ var Renderer = class {
|
|
|
10901
11176
|
if (!body.round) this.setContacts(b, body, left);
|
|
10902
11177
|
}
|
|
10903
11178
|
body.sleeping = false;
|
|
11179
|
+
if (!structural && !body.round && !body.held && kitOriginOf3(b.root)?.kind === "furniture" && Math.hypot(...body.velocity) <= UNDERMINED_STILL) this.goOverIfBalanced(b, body, left);
|
|
10904
11180
|
return;
|
|
10905
11181
|
}
|
|
10906
|
-
if (structural) return;
|
|
11182
|
+
if (structural || this.heldByWorld(objectId)) return;
|
|
10907
11183
|
const boxOf = (mv) => this.visuals.worldBox(mv, new this.THREE.Box3());
|
|
10908
11184
|
const whole = [...b.parts.values()].flatMap((pv) => pv.meshes).map(boxOf).filter((one) => !one.isEmpty());
|
|
10909
11185
|
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 +11242,7 @@ var Renderer = class {
|
|
|
10966
11242
|
}
|
|
10967
11243
|
releaseIfFloating(objectId) {
|
|
10968
11244
|
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;
|
|
11245
|
+
if (!b || b.piece || this.pieceSys.get(objectId) || !this.autoSplit || UNCHECKED_KINDS.has(this.kindOf(b)) || this.heldByWorld(objectId)) return false;
|
|
10970
11246
|
const boxes = this.shownBoxes(objectId);
|
|
10971
11247
|
if (boxes.length === 0) return false;
|
|
10972
11248
|
const whole = new this.THREE.Box3();
|
|
@@ -10985,6 +11261,145 @@ var Renderer = class {
|
|
|
10985
11261
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
10986
11262
|
return true;
|
|
10987
11263
|
}
|
|
11264
|
+
/**
|
|
11265
|
+
* 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
|
|
11266
|
+
* 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
|
|
11267
|
+
* 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
|
|
11268
|
+
* 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
|
|
11269
|
+
* what lay on it slides or falls off. Structures answer to their own load path.
|
|
11270
|
+
*/
|
|
11271
|
+
checkUndermined() {
|
|
11272
|
+
if (this.undermined.length === 0) return;
|
|
11273
|
+
const discs = this.undermined.splice(0);
|
|
11274
|
+
const inDisc = (x, z, d) => Math.hypot(x - d.x, z - d.z) <= d.radius;
|
|
11275
|
+
for (const b of [...this.bounds.values()]) {
|
|
11276
|
+
if (this.kindOf(b) !== "furniture" && !this.o.shoveable?.(b.id)) continue;
|
|
11277
|
+
const was = b.piece ?? this.pieceSys.get(b.id) ?? null;
|
|
11278
|
+
if (was && (was.held || Math.hypot(...was.velocity) > UNDERMINED_STILL)) continue;
|
|
11279
|
+
const meshes = this.meshesOf(b).filter((mv) => this.visuals.shown(mv));
|
|
11280
|
+
const boxes = meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty());
|
|
11281
|
+
if (boxes.length === 0) continue;
|
|
11282
|
+
const reach = boxes.reduce((all, one) => all.union(one), new this.THREE.Box3());
|
|
11283
|
+
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;
|
|
11284
|
+
const feet = this.lowPoints(meshes);
|
|
11285
|
+
if (!feet) continue;
|
|
11286
|
+
const { floor, points } = feet;
|
|
11287
|
+
const held = [];
|
|
11288
|
+
const lost = [];
|
|
11289
|
+
for (const point of points) (this.holdsAt(b.id, point[0], point[1], floor) ? held : lost).push(point);
|
|
11290
|
+
if (lost.length === 0) continue;
|
|
11291
|
+
if (!lost.some(([x, z]) => discs.some((d) => inDisc(x, z, d) && this.stoodBeside(x, z, d, floor)))) continue;
|
|
11292
|
+
const centre = centreOfBoxes(boxes);
|
|
11293
|
+
if (this.standsWith(held, points, centre, floor)) continue;
|
|
11294
|
+
let body;
|
|
11295
|
+
if (was) body = was;
|
|
11296
|
+
else {
|
|
11297
|
+
const piece = this.makePiece(b.id);
|
|
11298
|
+
body = b.piece ?? piece;
|
|
11299
|
+
body.apart = true;
|
|
11300
|
+
this.setContacts(b, body, meshes, true);
|
|
11301
|
+
}
|
|
11302
|
+
const gx = lost.reduce((sum, p) => sum + p[0], 0) / lost.length - centre[0];
|
|
11303
|
+
const gz = lost.reduce((sum, p) => sum + p[1], 0) / lost.length - centre[2];
|
|
11304
|
+
const length = Math.hypot(gx, gz);
|
|
11305
|
+
body.sleeping = false;
|
|
11306
|
+
body.still = 0;
|
|
11307
|
+
body.calmAt = null;
|
|
11308
|
+
if (held.length > 0 && length > 1e-6) this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + gx, floor, centre[2] + gz]);
|
|
11309
|
+
if (!was) this.o.onLoosened?.(b.id, body, "ground");
|
|
11310
|
+
}
|
|
11311
|
+
}
|
|
11312
|
+
/**
|
|
11313
|
+
* 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
|
|
11314
|
+
* that polygon (its weight does the rest); one that stands on nothing falls by itself.
|
|
11315
|
+
*/
|
|
11316
|
+
goOverIfBalanced(b, body, meshes) {
|
|
11317
|
+
const feet = this.lowPoints(meshes);
|
|
11318
|
+
if (!feet) return;
|
|
11319
|
+
const held = feet.points.filter(([x, z]) => this.holdsAt(b.id, x, z, feet.floor));
|
|
11320
|
+
if (held.length < 3) return;
|
|
11321
|
+
const centre = centreOfBoxes(meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty()));
|
|
11322
|
+
if (this.standsWith(held, null, centre, feet.floor)) return;
|
|
11323
|
+
const inside = insideBy(convexHull(held), [centre[0], centre[2]]);
|
|
11324
|
+
const reach = this.reachAlong(body, inside.out.x, inside.out.z);
|
|
11325
|
+
this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + inside.out.x * reach, feet.floor, centre[2] + inside.out.z * reach]);
|
|
11326
|
+
}
|
|
11327
|
+
/** How far (m) the box of a piece reaches from its middle along the level direction (x, z), turned as it is: the support of its box that way. */
|
|
11328
|
+
reachAlong(body, x, z) {
|
|
11329
|
+
const e = new this.THREE.Matrix4().makeRotationFromQuaternion(body.root.quaternion).elements;
|
|
11330
|
+
const [hx, hy, hz] = body.halfExtents;
|
|
11331
|
+
return hx * Math.abs(e[0] * x + e[2] * z) + hy * Math.abs(e[4] * x + e[6] * z) + hz * Math.abs(e[8] * x + e[10] * z);
|
|
11332
|
+
}
|
|
11333
|
+
/**
|
|
11334
|
+
* 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
|
|
11335
|
+
* 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).
|
|
11336
|
+
*/
|
|
11337
|
+
standsWith(held, all, centre, floor) {
|
|
11338
|
+
if (held.length < 3) return false;
|
|
11339
|
+
const now = insideBy(convexHull([...held]), [centre[0], centre[2]]).depth;
|
|
11340
|
+
if (now > UNDERMINED_STAND * (centre[1] - floor)) return true;
|
|
11341
|
+
return all !== null && now >= UNDERMINED_KEEP * insideBy(convexHull([...all]), [centre[0], centre[2]]).depth;
|
|
11342
|
+
}
|
|
11343
|
+
/**
|
|
11344
|
+
* 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
|
|
11345
|
+
* 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
|
|
11346
|
+
* 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.
|
|
11347
|
+
*/
|
|
11348
|
+
lowPoints(meshes) {
|
|
11349
|
+
const faces = [];
|
|
11350
|
+
let floor = Infinity;
|
|
11351
|
+
for (const mv of meshes) {
|
|
11352
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
11353
|
+
const points = [];
|
|
11354
|
+
this.visuals.rangePoints(mv, mv.mesh.matrixWorld, points);
|
|
11355
|
+
const count = points.length / 3;
|
|
11356
|
+
const index = mv.mesh.geometry.getIndex()?.array;
|
|
11357
|
+
const from = mv.range ? mv.range[0] : 0;
|
|
11358
|
+
const total = index ? index.length : count;
|
|
11359
|
+
for (let i = 0; i + 2 < total; i += 3) {
|
|
11360
|
+
const a = (index ? index[i] : i) - from, b = (index ? index[i + 1] : i + 1) - from, c = (index ? index[i + 2] : i + 2) - from;
|
|
11361
|
+
if (a < 0 || b < 0 || c < 0 || a >= count || b >= count || c >= count) continue;
|
|
11362
|
+
for (const k of [a, b, c]) {
|
|
11363
|
+
faces.push(points[k * 3], points[k * 3 + 1], points[k * 3 + 2]);
|
|
11364
|
+
floor = Math.min(floor, points[k * 3 + 1]);
|
|
11365
|
+
}
|
|
11366
|
+
}
|
|
11367
|
+
}
|
|
11368
|
+
if (faces.length === 0) return null;
|
|
11369
|
+
const out = [];
|
|
11370
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11371
|
+
const add = (x, z) => {
|
|
11372
|
+
const key = `${Math.round(x * 1e3)},${Math.round(z * 1e3)}`;
|
|
11373
|
+
if (seen.has(key)) return;
|
|
11374
|
+
seen.add(key);
|
|
11375
|
+
out.push([x, z]);
|
|
11376
|
+
};
|
|
11377
|
+
for (let i = 0; i < faces.length; i += 9) {
|
|
11378
|
+
if (faces[i + 1] > floor + FEET_BAND || faces[i + 4] > floor + FEET_BAND || faces[i + 7] > floor + FEET_BAND) continue;
|
|
11379
|
+
const ax = faces[i], az = faces[i + 2], bx = faces[i + 3], bz = faces[i + 5], cx = faces[i + 6], cz = faces[i + 8];
|
|
11380
|
+
add(ax, az);
|
|
11381
|
+
add(bx, bz);
|
|
11382
|
+
add(cx, cz);
|
|
11383
|
+
add((ax + bx) / 2, (az + bz) / 2);
|
|
11384
|
+
add((bx + cx) / 2, (bz + cz) / 2);
|
|
11385
|
+
add((ax + cx) / 2, (az + cz) / 2);
|
|
11386
|
+
add((ax + bx + cx) / 3, (az + bz + cz) / 3);
|
|
11387
|
+
}
|
|
11388
|
+
return out.length > 0 ? { floor, points: out } : null;
|
|
11389
|
+
}
|
|
11390
|
+
/** 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`. */
|
|
11391
|
+
holdsAt(objectId, x, z, y) {
|
|
11392
|
+
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;
|
|
11393
|
+
}
|
|
11394
|
+
/** 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. */
|
|
11395
|
+
stoodBeside(x, z, d, floor) {
|
|
11396
|
+
const fx = x - d.x, fz = z - d.z;
|
|
11397
|
+
const length = Math.hypot(fx, fz);
|
|
11398
|
+
const ux = length > 1e-6 ? fx / length : 1, uz = length > 1e-6 ? fz / length : 0;
|
|
11399
|
+
const reach = d.radius + UNDERMINED_RIM;
|
|
11400
|
+
const ground = this.groundAt(d.x + ux * reach, d.z + uz * reach);
|
|
11401
|
+
return ground >= floor - BROKEN_GAP - UNDERMINED_RIM_DROP && ground <= floor + UNDERMINED_RIM_RISE;
|
|
11402
|
+
}
|
|
10988
11403
|
/** 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
11404
|
standsOn(objectId, boxes) {
|
|
10990
11405
|
if (boxes.length === 0) return false;
|
|
@@ -11001,6 +11416,10 @@ var Renderer = class {
|
|
|
11001
11416
|
return false;
|
|
11002
11417
|
}
|
|
11003
11418
|
/** 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. */
|
|
11419
|
+
/** 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. */
|
|
11420
|
+
heldByWorld(objectId) {
|
|
11421
|
+
return this.world.fixedInPlace(objectId);
|
|
11422
|
+
}
|
|
11004
11423
|
kindOf(b) {
|
|
11005
11424
|
for (let o = b.root; o; o = o.parent) {
|
|
11006
11425
|
const kind = kitOriginOf3(o)?.kind;
|
|
@@ -11039,7 +11458,7 @@ var Renderer = class {
|
|
|
11039
11458
|
* 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
11459
|
* on its parts.
|
|
11041
11460
|
*/
|
|
11042
|
-
setContacts(b, body, meshes) {
|
|
11461
|
+
setContacts(b, body, meshes, fitWhole = false) {
|
|
11043
11462
|
if (meshes.length > PART_BOX_MESHES) {
|
|
11044
11463
|
body.contacts = void 0;
|
|
11045
11464
|
body.partBoxes = void 0;
|
|
@@ -11056,7 +11475,7 @@ var Renderer = class {
|
|
|
11056
11475
|
this.visuals.localBox(mv, lb);
|
|
11057
11476
|
if (lb.isEmpty()) continue;
|
|
11058
11477
|
m4.multiplyMatrices(inv, mv.mesh.matrixWorld);
|
|
11059
|
-
this.partBoxesOf(mv, { lb, m4, from: [cx, cy, cz] }, boxes);
|
|
11478
|
+
this.partBoxesOf(mv, { lb, m4, from: [cx, cy, cz], fitWhole }, boxes);
|
|
11060
11479
|
lb.applyMatrix4(m4);
|
|
11061
11480
|
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
11481
|
}
|
|
@@ -11177,28 +11596,67 @@ var Renderer = class {
|
|
|
11177
11596
|
return own;
|
|
11178
11597
|
}
|
|
11179
11598
|
/**
|
|
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
|
|
11599
|
+
* 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`);
|
|
11600
|
+
* 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
11601
|
* of those vertices in the merged mesh's space is the box around a tilted sheet, mostly air.
|
|
11183
11602
|
*/
|
|
11184
11603
|
partBoxesOf(mv, at, out) {
|
|
11185
11604
|
const [cx, cy, cz] = at.from;
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
const
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
|
|
11198
|
-
|
|
11199
|
-
|
|
11200
|
-
|
|
11605
|
+
const built = mv.range ? null : builtSolidsOf(mv.mesh);
|
|
11606
|
+
const solids = at.fitWhole && !mv.range && !built ? solidBoxesOf(mv.mesh.geometry) : null;
|
|
11607
|
+
if (solids) {
|
|
11608
|
+
const pos2 = new this.THREE.Vector3();
|
|
11609
|
+
const quat2 = new this.THREE.Quaternion();
|
|
11610
|
+
const scale2 = new this.THREE.Vector3();
|
|
11611
|
+
at.m4.decompose(pos2, quat2, scale2);
|
|
11612
|
+
for (const box of solids) {
|
|
11613
|
+
const c2 = new this.THREE.Vector3((box[0] + box[3]) / 2, (box[1] + box[4]) / 2, (box[2] + box[5]) / 2).applyMatrix4(at.m4);
|
|
11614
|
+
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)];
|
|
11615
|
+
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half: half2, rotation: [quat2.x, quat2.y, quat2.z, quat2.w] });
|
|
11616
|
+
}
|
|
11617
|
+
return;
|
|
11618
|
+
}
|
|
11619
|
+
if (built) {
|
|
11620
|
+
const pos2 = new this.THREE.Vector3();
|
|
11621
|
+
const quat2 = new this.THREE.Quaternion();
|
|
11622
|
+
const scale2 = new this.THREE.Vector3();
|
|
11623
|
+
at.m4.decompose(pos2, quat2, scale2);
|
|
11624
|
+
const c2 = new this.THREE.Vector3();
|
|
11625
|
+
const q = new this.THREE.Quaternion();
|
|
11626
|
+
const even = (Math.abs(scale2.x) + Math.abs(scale2.y) + Math.abs(scale2.z)) / 3;
|
|
11627
|
+
for (const solid of built) {
|
|
11628
|
+
c2.set(solid.center[0], solid.center[1], solid.center[2]).applyMatrix4(at.m4);
|
|
11629
|
+
q.set(solid.rotation[0], solid.rotation[1], solid.rotation[2], solid.rotation[3]);
|
|
11630
|
+
const turned = Math.abs(q.w) < 1 - 1e-9;
|
|
11631
|
+
const s = turned ? [even, even, even] : [Math.abs(scale2.x), Math.abs(scale2.y), Math.abs(scale2.z)];
|
|
11632
|
+
q.premultiply(quat2).normalize();
|
|
11633
|
+
const round = isRoundSolid(solid) && Math.abs(s[0] - s[2]) <= 1e-9;
|
|
11634
|
+
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 } : {} });
|
|
11635
|
+
}
|
|
11636
|
+
return;
|
|
11637
|
+
}
|
|
11638
|
+
const own = [];
|
|
11639
|
+
this.visuals.rangePoints(mv, new this.THREE.Matrix4(), own);
|
|
11640
|
+
const drawn = hollowBoxesOf(own, mv.range ? RANGED : OWN_MESH);
|
|
11641
|
+
if (drawn) {
|
|
11642
|
+
const pos2 = new this.THREE.Vector3();
|
|
11643
|
+
const quat2 = new this.THREE.Quaternion();
|
|
11644
|
+
const scale2 = new this.THREE.Vector3();
|
|
11645
|
+
at.m4.decompose(pos2, quat2, scale2);
|
|
11646
|
+
const c2 = new this.THREE.Vector3();
|
|
11647
|
+
const q = new this.THREE.Quaternion();
|
|
11648
|
+
const even = (Math.abs(scale2.x) + Math.abs(scale2.y) + Math.abs(scale2.z)) / 3;
|
|
11649
|
+
for (const box of drawn) {
|
|
11650
|
+
c2.set(box.center[0], box.center[1], box.center[2]).applyMatrix4(at.m4);
|
|
11651
|
+
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)];
|
|
11652
|
+
if (box.rotation) q.set(box.rotation[0], box.rotation[1], box.rotation[2], box.rotation[3]).premultiply(quat2).normalize();
|
|
11653
|
+
else q.copy(quat2);
|
|
11654
|
+
const thin = mv.range ? 0 : 5e-3;
|
|
11655
|
+
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] });
|
|
11201
11656
|
}
|
|
11657
|
+
return;
|
|
11658
|
+
}
|
|
11659
|
+
if (mv.range) {
|
|
11202
11660
|
if (isRigidPose(at.m4.elements)) {
|
|
11203
11661
|
const turn2 = new this.THREE.Quaternion().setFromRotationMatrix(at.m4);
|
|
11204
11662
|
const c2 = new this.THREE.Vector3();
|
|
@@ -11221,11 +11679,14 @@ var Renderer = class {
|
|
|
11221
11679
|
at.m4.decompose(pos, quat, scale);
|
|
11222
11680
|
const c = at.lb.getCenter(new this.THREE.Vector3()).applyMatrix4(at.m4);
|
|
11223
11681
|
const size = at.lb.getSize(new this.THREE.Vector3());
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11682
|
+
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)];
|
|
11683
|
+
const geometry = mv.mesh.geometry;
|
|
11684
|
+
const params = geometry.parameters ?? {};
|
|
11685
|
+
const whole = typeof params.thetaLength !== "number" || Math.abs(params.thetaLength - 2 * Math.PI) < 1e-6;
|
|
11686
|
+
const cylinder = geometry.type === "CylinderGeometry" && !mv.range;
|
|
11687
|
+
const straight = cylinder && whole && params.openEnded !== true && isRoundSolid({ kind: params.radiusTop === params.radiusBottom ? "cylinder" : "cone", half });
|
|
11688
|
+
const curved = !mv.range && !straight && (cylinder || geometry.type === "ConeGeometry" || geometry.type === "SphereGeometry");
|
|
11689
|
+
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
11690
|
}
|
|
11230
11691
|
/**
|
|
11231
11692
|
* 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 +12263,7 @@ var Renderer = class {
|
|
|
11802
12263
|
wakeRegion(x, z, radius) {
|
|
11803
12264
|
this.fragments.wakeRegion(x, z, radius);
|
|
11804
12265
|
this.pieceSys.wakeRegion(x, z, radius);
|
|
12266
|
+
if (this.autoSplit && this.undermined.length < UNDERMINED_MAX) this.undermined.push({ x, z, radius });
|
|
11805
12267
|
}
|
|
11806
12268
|
stats() {
|
|
11807
12269
|
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 +12322,55 @@ function lighten(color, t) {
|
|
|
11860
12322
|
};
|
|
11861
12323
|
return ch(16) | ch(8) | ch(0);
|
|
11862
12324
|
}
|
|
12325
|
+
function solidBoxesOf(geometry) {
|
|
12326
|
+
const position = geometry.getAttribute("position");
|
|
12327
|
+
if (!position || position.count <= 24) return null;
|
|
12328
|
+
const parent = new Int32Array(position.count);
|
|
12329
|
+
for (let i = 0; i < parent.length; i++) parent[i] = i;
|
|
12330
|
+
const find = (i) => {
|
|
12331
|
+
while (parent[i] !== i) {
|
|
12332
|
+
parent[i] = parent[parent[i]];
|
|
12333
|
+
i = parent[i];
|
|
12334
|
+
}
|
|
12335
|
+
return i;
|
|
12336
|
+
};
|
|
12337
|
+
const join = (a, b) => {
|
|
12338
|
+
const ra = find(a), rb = find(b);
|
|
12339
|
+
if (ra !== rb) parent[ra] = rb;
|
|
12340
|
+
};
|
|
12341
|
+
const corners = /* @__PURE__ */ new Map();
|
|
12342
|
+
for (let i = 0; i < position.count; i++) {
|
|
12343
|
+
const key = `${Math.round(position.getX(i) / SOLID_WELD)},${Math.round(position.getY(i) / SOLID_WELD)},${Math.round(position.getZ(i) / SOLID_WELD)}`;
|
|
12344
|
+
const first = corners.get(key);
|
|
12345
|
+
if (first === void 0) corners.set(key, i);
|
|
12346
|
+
else join(i, first);
|
|
12347
|
+
}
|
|
12348
|
+
const index = geometry.getIndex();
|
|
12349
|
+
const triangles2 = index ? index.count / 3 : position.count / 3;
|
|
12350
|
+
for (let t = 0; t < triangles2; t++) {
|
|
12351
|
+
const a = index ? index.getX(t * 3) : t * 3;
|
|
12352
|
+
join(a, index ? index.getX(t * 3 + 1) : t * 3 + 1);
|
|
12353
|
+
join(a, index ? index.getX(t * 3 + 2) : t * 3 + 2);
|
|
12354
|
+
}
|
|
12355
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
12356
|
+
for (let i = 0; i < position.count; i++) {
|
|
12357
|
+
const root = find(i);
|
|
12358
|
+
const x = position.getX(i), y = position.getY(i), z = position.getZ(i);
|
|
12359
|
+
const box = boxes.get(root);
|
|
12360
|
+
if (!box) {
|
|
12361
|
+
if (boxes.size >= SOLIDS_MAX) return null;
|
|
12362
|
+
boxes.set(root, [x, y, z, x, y, z]);
|
|
12363
|
+
continue;
|
|
12364
|
+
}
|
|
12365
|
+
box[0] = Math.min(box[0], x);
|
|
12366
|
+
box[1] = Math.min(box[1], y);
|
|
12367
|
+
box[2] = Math.min(box[2], z);
|
|
12368
|
+
box[3] = Math.max(box[3], x);
|
|
12369
|
+
box[4] = Math.max(box[4], y);
|
|
12370
|
+
box[5] = Math.max(box[5], z);
|
|
12371
|
+
}
|
|
12372
|
+
return boxes.size > 1 ? [...boxes.values()] : null;
|
|
12373
|
+
}
|
|
11863
12374
|
function convexHull(points) {
|
|
11864
12375
|
const sorted = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
11865
12376
|
if (sorted.length < 3) return sorted;
|