@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/worker-kinds.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ interface StaticSolid {
|
|
|
55
55
|
readonly mesh?: StaticMesh;
|
|
56
56
|
/** Names the part across lists (a part measured again is the same part): without it, the place in the list. */
|
|
57
57
|
readonly key?: string;
|
|
58
|
+
/** A round primitive: a cylinder along the solid's own y, its radius the mean of its x and z halves (see `PartBox.round`). */
|
|
59
|
+
readonly round?: true;
|
|
58
60
|
/** The Coulomb friction and rolling resistance of the part's material; without it the body has the ground's. */
|
|
59
61
|
readonly friction?: {
|
|
60
62
|
readonly static: number;
|
|
@@ -64,6 +66,18 @@ interface StaticSolid {
|
|
|
64
66
|
};
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
/**
|
|
70
|
+
* One solid a mesh was built from (spec 019): its own box in the mesh's space, turned as it was drawn (`rotation`: x, y, z, w). The builder of the mesh lists them in
|
|
71
|
+
* `userData.solids` (`ShapeSolid` of game-shapes, by the mesh api of game-interactables-three): the piece is then held by what was drawn, with no vertex read back.
|
|
72
|
+
*/
|
|
73
|
+
interface BuiltSolid {
|
|
74
|
+
readonly center: readonly [number, number, number];
|
|
75
|
+
readonly half: readonly [number, number, number];
|
|
76
|
+
readonly rotation: readonly [number, number, number, number];
|
|
77
|
+
/** What drew it (`'box'`, `'cylinder'`...): a cylinder is held as a cylinder along its own y. */
|
|
78
|
+
readonly kind?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
/**
|
|
68
82
|
* One fixed drawn part to measure (`measureStaticPart`): plain arrays, so it crosses to a worker (`destruction.static-colliders`). The main thread reads the vertices,
|
|
69
83
|
* the triangles and the mesh's world matrix (with three's own `decompose` of it); the measuring is here.
|
|
@@ -80,6 +94,8 @@ interface StaticPartJob {
|
|
|
80
94
|
/** The triangles of the part as vertex numbers of the host (three each), `from` its first vertex. */
|
|
81
95
|
readonly found: Uint32Array;
|
|
82
96
|
readonly from: number;
|
|
97
|
+
/** The solids the mesh was built from (`builtSolidsOf`), in the mesh's frame: with them the part is those boxes, and nothing is measured. */
|
|
98
|
+
readonly solids?: readonly BuiltSolid[];
|
|
83
99
|
}
|
|
84
100
|
|
|
85
101
|
/**
|
package/dist/worker-kinds.js
CHANGED
|
@@ -774,8 +774,15 @@ var jobTransferOf = (job) => buffersOf([job.samples, job.band, job.patch?.height
|
|
|
774
774
|
|
|
775
775
|
// src/static-part-job.ts
|
|
776
776
|
import { fitOrientedBox, hugs } from "@adatechnology/game-shapes";
|
|
777
|
+
|
|
778
|
+
// src/built-solids.ts
|
|
779
|
+
var ROUND_SIDES = 0.05;
|
|
780
|
+
var isRoundSolid = (solid) => solid.kind === "cylinder" && Math.abs(solid.half[0] - solid.half[2]) <= ROUND_SIDES * Math.max(solid.half[0], solid.half[2]);
|
|
781
|
+
|
|
782
|
+
// src/static-part-job.ts
|
|
777
783
|
var FIT = 0.01;
|
|
778
784
|
var FILL = 0.5;
|
|
785
|
+
var SOLID = 0.5;
|
|
779
786
|
var MIN_HALF = 5e-3;
|
|
780
787
|
var COLLAPSED = 2e-3;
|
|
781
788
|
var MIN_FACE = 1e-6;
|
|
@@ -812,10 +819,11 @@ function measureStaticPart(job) {
|
|
|
812
819
|
const size = [high[0] - low[0], high[1] - low[1], high[2] - low[2]];
|
|
813
820
|
const s = [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])];
|
|
814
821
|
if (Math.max(size[0] * s[0], size[1] * s[1], size[2] * s[2]) < COLLAPSED) return [];
|
|
822
|
+
if (job.solids && job.solids.length > 0) return job.solids.map((solid) => builtSolidIn(solid, pos, quat, scale));
|
|
815
823
|
const centre = [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2];
|
|
816
824
|
const half = [size[0] / 2, size[1] / 2, size[2] / 2];
|
|
817
825
|
const straight = { center: centre, half, axes: IDENTITY, tolerance: [FIT / s[0], FIT / s[1], FIT / s[2]] };
|
|
818
|
-
if (hugs(points, straight) && fillsFaces(points, found, from, straight)) {
|
|
826
|
+
if (hugs(points, straight) && fillsFaces(points, found, from, straight) && fillsVolume(points, found, from, straight)) {
|
|
819
827
|
const [cx, cy, cz] = turn(centre[0] * scale[0], centre[1] * scale[1], centre[2] * scale[2], quat);
|
|
820
828
|
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]] }];
|
|
821
829
|
}
|
|
@@ -828,9 +836,24 @@ function measureStaticPart(job) {
|
|
|
828
836
|
world[i + 2] = e[2] * x + e[6] * y + e[10] * z + e[14];
|
|
829
837
|
}
|
|
830
838
|
const turned = fitOrientedBox(world);
|
|
831
|
-
if (turned && fitsTurned(world, turned) && fillsFaces(world, found, from, turnedBox(turned))) return [turned];
|
|
839
|
+
if (turned && fitsTurned(world, turned) && fillsFaces(world, found, from, turnedBox(turned)) && fillsVolume(world, found, from, turnedBox(turned))) return [turned];
|
|
832
840
|
return [trimeshOf(world, from, found)];
|
|
833
841
|
}
|
|
842
|
+
var builtSolidIn = (solid, pos, quat, scale) => {
|
|
843
|
+
const [cx, cy, cz] = turn(solid.center[0] * scale[0], solid.center[1] * scale[1], solid.center[2] * scale[2], quat);
|
|
844
|
+
const [ax, ay, az, aw] = quat;
|
|
845
|
+
const [bx, by, bz, bw] = solid.rotation;
|
|
846
|
+
const turned = Math.abs(bw) < 1 - 1e-9;
|
|
847
|
+
const even = (Math.abs(scale[0]) + Math.abs(scale[1]) + Math.abs(scale[2])) / 3;
|
|
848
|
+
const s = turned ? [even, even, even] : [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])];
|
|
849
|
+
return {
|
|
850
|
+
...isRoundSolid(solid) && Math.abs(s[0] - s[2]) <= 1e-9 ? { round: true } : {},
|
|
851
|
+
center: [cx + pos[0], cy + pos[1], cz + pos[2]],
|
|
852
|
+
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])],
|
|
853
|
+
// the mesh's turn, then the solid's own
|
|
854
|
+
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]
|
|
855
|
+
};
|
|
856
|
+
};
|
|
834
857
|
var staticSolidsTransfer = (solids) => {
|
|
835
858
|
const out = [];
|
|
836
859
|
for (const solid of solids) if (solid.mesh) out.push(solid.mesh.vertices.buffer, solid.mesh.indices.buffer);
|
|
@@ -869,6 +892,21 @@ var fillsFaces = (points, found, from, box) => {
|
|
|
869
892
|
}
|
|
870
893
|
return true;
|
|
871
894
|
};
|
|
895
|
+
var fillsVolume = (points, found, from, box) => {
|
|
896
|
+
if (found.length === 0) return true;
|
|
897
|
+
const whole = 8 * box.half[0] * box.half[1] * box.half[2];
|
|
898
|
+
if (!(whole > 0)) return true;
|
|
899
|
+
const [cx, cy, cz] = box.center;
|
|
900
|
+
let six = 0;
|
|
901
|
+
for (let i = 0; i + 2 < found.length; i += 3) {
|
|
902
|
+
const a = (found[i] - from) * 3, b = (found[i + 1] - from) * 3, c = (found[i + 2] - from) * 3;
|
|
903
|
+
const ax = points[a] - cx, ay = points[a + 1] - cy, az = points[a + 2] - cz;
|
|
904
|
+
const bx = points[b] - cx, by = points[b + 1] - cy, bz = points[b + 2] - cz;
|
|
905
|
+
const dx = points[c] - cx, dy = points[c + 1] - cy, dz = points[c + 2] - cz;
|
|
906
|
+
six += ax * (by * dz - bz * dy) + ay * (bz * dx - bx * dz) + az * (bx * dy - by * dx);
|
|
907
|
+
}
|
|
908
|
+
return Math.abs(six) / 6 >= whole * SOLID;
|
|
909
|
+
};
|
|
872
910
|
var trimeshOf = (world, from, found) => {
|
|
873
911
|
const indices = new Uint32Array(found.length);
|
|
874
912
|
for (let i = 0; i < found.length; i++) indices[i] = found[i] - from;
|