@adatechnology/game-destruction-three 0.29.1 → 0.29.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -2
- package/dist/index.global.js +70 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +70 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -2756,11 +2756,22 @@ var sameShape = (a, b) => near(a.center, b.center) && near(a.half, b.half) && ne
|
|
|
2756
2756
|
var sameBox = (a, b) => a === b || sameShape(a, b) && sameFriction(a.friction, b.friction);
|
|
2757
2757
|
var sameSolids = (a, b) => a.length === b.length && a.every((s, i) => sameBox(s, b[i]));
|
|
2758
2758
|
var NONE = /* @__PURE__ */ new Set();
|
|
2759
|
+
var MESH_ORIGIN = [0, 0, 0];
|
|
2760
|
+
var MESH_ROTATION = [0, 0, 0, 1];
|
|
2759
2761
|
var partOfKey = (key) => {
|
|
2760
2762
|
const colon = key.lastIndexOf(":");
|
|
2761
2763
|
return colon < 0 || !/^\d+$/.test(key.slice(colon + 1)) ? key : key.slice(0, colon);
|
|
2762
2764
|
};
|
|
2763
2765
|
var hasSize = (s) => s.half[0] > 0 && s.half[1] > 0 && s.half[2] > 0;
|
|
2766
|
+
var orientedReach = (s) => {
|
|
2767
|
+
const [x, y, z, w] = s.rotation;
|
|
2768
|
+
const row = (a, b, c) => Math.abs(a) * s.half[0] + Math.abs(b) * s.half[1] + Math.abs(c) * s.half[2];
|
|
2769
|
+
return [
|
|
2770
|
+
row(1 - 2 * (y * y + z * z), 2 * (x * y - z * w), 2 * (x * z + y * w)),
|
|
2771
|
+
row(2 * (x * y + z * w), 1 - 2 * (x * x + z * z), 2 * (y * z - x * w)),
|
|
2772
|
+
row(2 * (x * z - y * w), 2 * (y * z + x * w), 1 - 2 * (x * x + y * y))
|
|
2773
|
+
];
|
|
2774
|
+
};
|
|
2764
2775
|
var shapeOf = (s) => s.mesh ? { kind: "trimesh", vertices: s.mesh.vertices, indices: s.mesh.indices } : { kind: "box", half: s.half };
|
|
2765
2776
|
var EngineStatics = class {
|
|
2766
2777
|
constructor(world, material) {
|
|
@@ -2775,6 +2786,8 @@ var EngineStatics = class {
|
|
|
2775
2786
|
__publicField(this, "ownerOf", /* @__PURE__ */ new Map());
|
|
2776
2787
|
/** The part of the object each held body draws (the key without its mesh number): what a blow on the body hits. */
|
|
2777
2788
|
__publicField(this, "partOf", /* @__PURE__ */ new Map());
|
|
2789
|
+
/** The box around the meshes of each object that has any (min x, y, z then max x, y, z): the triangles are what the engine meets, but the world tests the volume the part is drawn in. */
|
|
2790
|
+
__publicField(this, "meshBounds", /* @__PURE__ */ new Map());
|
|
2778
2791
|
/** Changes whenever an answer of `covers` may have (an object came, went, or was fitted again). */
|
|
2779
2792
|
__publicField(this, "coverageRevision", 0);
|
|
2780
2793
|
__publicField(this, "unsure", NONE);
|
|
@@ -2803,6 +2816,7 @@ var EngineStatics = class {
|
|
|
2803
2816
|
if (now.has(id)) continue;
|
|
2804
2817
|
for (const h of f.held.values()) this.release(h, f.settled);
|
|
2805
2818
|
this.bodies.delete(id);
|
|
2819
|
+
this.meshBounds.delete(id);
|
|
2806
2820
|
this.coverageRevision++;
|
|
2807
2821
|
}
|
|
2808
2822
|
const budget = { triangles: TRIANGLES_PER_UPDATE };
|
|
@@ -2819,6 +2833,7 @@ var EngineStatics = class {
|
|
|
2819
2833
|
clear() {
|
|
2820
2834
|
for (const f of this.bodies.values()) for (const h of f.held.values()) this.drop(h.id);
|
|
2821
2835
|
this.bodies.clear();
|
|
2836
|
+
this.meshBounds.clear();
|
|
2822
2837
|
this.coverageRevision++;
|
|
2823
2838
|
this.changed.clear();
|
|
2824
2839
|
}
|
|
@@ -2875,6 +2890,22 @@ var EngineStatics = class {
|
|
|
2875
2890
|
}
|
|
2876
2891
|
f.waiting = waiting;
|
|
2877
2892
|
if (waiting === 0) f.settled = true;
|
|
2893
|
+
this.boundMeshes(f);
|
|
2894
|
+
}
|
|
2895
|
+
boundMeshes(f) {
|
|
2896
|
+
let bounds;
|
|
2897
|
+
for (const h of f.held.values()) {
|
|
2898
|
+
const s = h.solid;
|
|
2899
|
+
if (!s.mesh) continue;
|
|
2900
|
+
bounds ?? (bounds = new Float64Array([Infinity, Infinity, Infinity, -Infinity, -Infinity, -Infinity]));
|
|
2901
|
+
const reach = orientedReach(s);
|
|
2902
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
2903
|
+
bounds[axis] = Math.min(bounds[axis], s.center[axis] - reach[axis]);
|
|
2904
|
+
bounds[axis + 3] = Math.max(bounds[axis + 3], s.center[axis] + reach[axis]);
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
if (bounds) this.meshBounds.set(f.objectId, bounds);
|
|
2908
|
+
else this.meshBounds.delete(f.objectId);
|
|
2878
2909
|
}
|
|
2879
2910
|
/** The held part takes the new solid: its shape where that changed, its surface where that did (only the friction: the same shape, no new one). */
|
|
2880
2911
|
reshape(h, solid) {
|
|
@@ -2883,7 +2914,8 @@ var EngineStatics = class {
|
|
|
2883
2914
|
if (!sameFriction(was.friction, solid.friction)) this.world.setMaterial(h.id, this.materialOf(solid));
|
|
2884
2915
|
this.changed.add(h.id);
|
|
2885
2916
|
if (sameShape(was, solid)) return;
|
|
2886
|
-
if (
|
|
2917
|
+
if (solid.mesh) this.world.setPose(h.id, MESH_ORIGIN, MESH_ROTATION, false);
|
|
2918
|
+
else this.world.setPose(h.id, solid.center, solid.rotation, false);
|
|
2887
2919
|
this.world.setShape(h.id, shapeOf(solid));
|
|
2888
2920
|
}
|
|
2889
2921
|
describe(solid) {
|
|
@@ -3531,6 +3563,26 @@ var GroundSchedule = class {
|
|
|
3531
3563
|
var RAY_MARGIN = 0.25;
|
|
3532
3564
|
var LONGEST_RAY = 2e3;
|
|
3533
3565
|
var FIXED_ONLY = { layers: ["static"] };
|
|
3566
|
+
var segmentMeetsBox = (origin, direction, length, box) => {
|
|
3567
|
+
let enter = 0;
|
|
3568
|
+
let leave = length;
|
|
3569
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
3570
|
+
const low = box[axis] - RAY_MARGIN;
|
|
3571
|
+
const high = box[axis + 3] + RAY_MARGIN;
|
|
3572
|
+
const step = direction[axis];
|
|
3573
|
+
const start = origin[axis];
|
|
3574
|
+
if (Math.abs(step) < 1e-12) {
|
|
3575
|
+
if (start < low || start > high) return false;
|
|
3576
|
+
continue;
|
|
3577
|
+
}
|
|
3578
|
+
const a = (low - start) / step;
|
|
3579
|
+
const b = (high - start) / step;
|
|
3580
|
+
enter = Math.max(enter, Math.min(a, b));
|
|
3581
|
+
leave = Math.min(leave, Math.max(a, b));
|
|
3582
|
+
if (enter > leave) return false;
|
|
3583
|
+
}
|
|
3584
|
+
return true;
|
|
3585
|
+
};
|
|
3534
3586
|
var createEngineRayBroadPhase = (world, statics) => {
|
|
3535
3587
|
const hits = [];
|
|
3536
3588
|
const inside = [];
|
|
@@ -3557,6 +3609,12 @@ var createEngineRayBroadPhase = (world, statics) => {
|
|
|
3557
3609
|
metList.push(owner);
|
|
3558
3610
|
}
|
|
3559
3611
|
}
|
|
3612
|
+
for (const [owner, bounds] of statics.meshBounds) {
|
|
3613
|
+
if (!met.has(owner) && segmentMeetsBox(origin, direction, maxDistance, bounds)) {
|
|
3614
|
+
met.add(owner);
|
|
3615
|
+
metList.push(owner);
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3560
3618
|
const around = world.overlapSphere(from, RAY_MARGIN, inside, FIXED_ONLY);
|
|
3561
3619
|
for (let i = 0; i < around; i++) {
|
|
3562
3620
|
const owner = statics.ownerOf.get(inside[i]);
|
|
@@ -4224,6 +4282,7 @@ var EnginePieces = class {
|
|
|
4224
4282
|
isSlipping: false
|
|
4225
4283
|
};
|
|
4226
4284
|
this.links.set(b, link);
|
|
4285
|
+
if (b.held) this.passThroughHolder(id, true);
|
|
4227
4286
|
this.byUser.set(user, b);
|
|
4228
4287
|
this.byBody.set(id, b);
|
|
4229
4288
|
this.bodyIds.add(id);
|
|
@@ -4234,14 +4293,16 @@ var EnginePieces = class {
|
|
|
4234
4293
|
bodyDesc(b, user) {
|
|
4235
4294
|
const c = this.centre(b);
|
|
4236
4295
|
const q = b.root.quaternion;
|
|
4296
|
+
const shape = this.shapeOf(b);
|
|
4237
4297
|
return {
|
|
4238
|
-
shape
|
|
4298
|
+
shape,
|
|
4239
4299
|
motion: b.held ? "kinematic" : "dynamic",
|
|
4240
4300
|
position: [c.x, c.y, c.z],
|
|
4241
4301
|
rotation: [q.x, q.y, q.z, q.w],
|
|
4242
4302
|
mass: b.mass,
|
|
4243
4303
|
inertia: this.inertiaOf(b),
|
|
4244
4304
|
centreAtOrigin: true,
|
|
4305
|
+
keepPartContacts: shape.kind === "compound" && shape.children.length > 1,
|
|
4245
4306
|
material: this.material(b),
|
|
4246
4307
|
layer: "debris",
|
|
4247
4308
|
// no air drag: the kit's pieces never had any (a round piece's rolling resistance is the adapter's, `rolling`)
|
|
@@ -4257,6 +4318,10 @@ var EnginePieces = class {
|
|
|
4257
4318
|
angularVelocity: [b.angularVelocity[0], b.angularVelocity[1], b.angularVelocity[2]]
|
|
4258
4319
|
};
|
|
4259
4320
|
}
|
|
4321
|
+
passThroughHolder(id, ignore) {
|
|
4322
|
+
const holder = this.o.heldIgnores?.();
|
|
4323
|
+
if (holder !== void 0) this.world.ignorePair(id, holder, ignore);
|
|
4324
|
+
}
|
|
4260
4325
|
/** Brings the body of a piece up to date with what changed on the piece since the last step (moved, pushed, picked up, put to sleep). */
|
|
4261
4326
|
sync(b, dt, h) {
|
|
4262
4327
|
const c = this.centre(b);
|
|
@@ -4267,6 +4332,7 @@ var EnginePieces = class {
|
|
|
4267
4332
|
if (b.held !== link.held) {
|
|
4268
4333
|
link.held = b.held;
|
|
4269
4334
|
this.world.setMotion(link.id, b.held ? "kinematic" : "dynamic");
|
|
4335
|
+
this.passThroughHolder(link.id, b.held);
|
|
4270
4336
|
}
|
|
4271
4337
|
if (b.held) {
|
|
4272
4338
|
this.world.moveKinematic(link.id, [c.x, c.y, c.z], [q.x, q.y, q.z, q.w], h);
|
|
@@ -5340,6 +5406,7 @@ var PieceSystem = class {
|
|
|
5340
5406
|
onKnock: o.onKnock,
|
|
5341
5407
|
onHardLanding: o.onHardLanding,
|
|
5342
5408
|
...o.tilesUnderParts ? { tilesUnderParts: true } : {},
|
|
5409
|
+
...o.heldIgnores ? { heldIgnores: o.heldIgnores } : {},
|
|
5343
5410
|
...o.groundWorker ? { groundWorker: o.groundWorker } : {},
|
|
5344
5411
|
...o.groundWorkerFrames !== void 0 ? { groundWorkerFrames: o.groundWorkerFrames } : {}
|
|
5345
5412
|
}) : null;
|
|
@@ -9688,6 +9755,7 @@ var Renderer = class {
|
|
|
9688
9755
|
scene: o.scene,
|
|
9689
9756
|
maxAwake: o.maxAwakePieces ?? Infinity,
|
|
9690
9757
|
...o.tilesUnderParts ? { tilesUnderParts: true } : {},
|
|
9758
|
+
...o.heldIgnores ? { heldIgnores: o.heldIgnores } : {},
|
|
9691
9759
|
...o.groundWorker ? { groundWorker: o.groundWorker } : {},
|
|
9692
9760
|
...o.groundWorkerFrames !== void 0 ? { groundWorkerFrames: o.groundWorkerFrames } : {},
|
|
9693
9761
|
...this.blastDebris ? { keep: { maxLive: this.blastDebris.maxLivePieces, far: this.blastDebris.far, ...o.focus ? { focus: o.focus } : {}, onFade: (b) => this.fadePiece(b) } } : {},
|