@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.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ export { Quat, Vec3 } from '@adatechnology/game-destruction';
|
|
|
3
3
|
import { WorkerCoordinator, KitOrigin, DeferredQueue, DeferredQueueOptions, WarmUpProbes, BlastShoveOptions, TaskKind, Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
|
|
4
4
|
import { HeightPatch } from '@adatechnology/game-terrain';
|
|
5
5
|
import { WorkerLike, WorkerScopeLike } from '@adatechnology/game-shapes';
|
|
6
|
-
import
|
|
7
|
-
import { Quat, WorkBudgetOptions, PhysicsLoop, SeamWorld, PhysicsEngine, WorldDesc, BlastQuery } from '@adatechnology/game-physics';
|
|
6
|
+
import { Quat, WorkBudgetOptions, PhysicsLoop, SeamWorld, PhysicsEngine, WorldDesc, BlastQuery, BodyId } from '@adatechnology/game-physics';
|
|
8
7
|
export { DEFAULT_WORK_BUDGET_MS, isPhysicsLoop, physicsPieceCount } from '@adatechnology/game-physics';
|
|
8
|
+
import * as THREE_NS from 'three';
|
|
9
9
|
import { VfxWorld, SpriteKind } from '@adatechnology/game-vfx';
|
|
10
10
|
import { LoopRecipe, SoundBank, SoundRecipe, Falloff, AudioEngine, VoiceGroup, SampleDefaults, SfxManifest } from '@adatechnology/game-audio';
|
|
11
11
|
|
|
@@ -408,6 +408,8 @@ interface RendererOptions {
|
|
|
408
408
|
* all of them, so a piece 23 m across and mostly air gets the tiles (and the solid under each) it touches, not 70. Default off: the same tiles as before (T3.8v).
|
|
409
409
|
*/
|
|
410
410
|
tilesUnderParts?: boolean;
|
|
411
|
+
/** With an engine: the body a piece in a hand passes through (the holder's own), so a carried thing wider than the arm's reach does not shove the holder. */
|
|
412
|
+
heldIgnores?: () => BodyId | undefined;
|
|
411
413
|
/**
|
|
412
414
|
* Fit the boxes a part drawn by a range of a merged mesh gets when it comes loose (`fitOrientedBoxes`) ahead of the blow, a part at a time with the time a frame has left, so the frame
|
|
413
415
|
* that splits a house reads them instead of fitting them. They are fitted in the space of the part's own vertices and carried to where the part is by its pose (a turn and a
|
package/dist/index.global.js
CHANGED
|
@@ -13494,11 +13494,22 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13494
13494
|
var sameBox = (a, b) => a === b || sameShape(a, b) && sameFriction(a.friction, b.friction);
|
|
13495
13495
|
var sameSolids = (a, b) => a.length === b.length && a.every((s, i) => sameBox(s, b[i]));
|
|
13496
13496
|
var NONE = /* @__PURE__ */ new Set();
|
|
13497
|
+
var MESH_ORIGIN = [0, 0, 0];
|
|
13498
|
+
var MESH_ROTATION = [0, 0, 0, 1];
|
|
13497
13499
|
var partOfKey = (key) => {
|
|
13498
13500
|
const colon = key.lastIndexOf(":");
|
|
13499
13501
|
return colon < 0 || !/^\d+$/.test(key.slice(colon + 1)) ? key : key.slice(0, colon);
|
|
13500
13502
|
};
|
|
13501
13503
|
var hasSize = (s) => s.half[0] > 0 && s.half[1] > 0 && s.half[2] > 0;
|
|
13504
|
+
var orientedReach = (s) => {
|
|
13505
|
+
const [x, y, z, w] = s.rotation;
|
|
13506
|
+
const row = (a, b, c) => Math.abs(a) * s.half[0] + Math.abs(b) * s.half[1] + Math.abs(c) * s.half[2];
|
|
13507
|
+
return [
|
|
13508
|
+
row(1 - 2 * (y * y + z * z), 2 * (x * y - z * w), 2 * (x * z + y * w)),
|
|
13509
|
+
row(2 * (x * y + z * w), 1 - 2 * (x * x + z * z), 2 * (y * z - x * w)),
|
|
13510
|
+
row(2 * (x * z - y * w), 2 * (y * z + x * w), 1 - 2 * (x * x + y * y))
|
|
13511
|
+
];
|
|
13512
|
+
};
|
|
13502
13513
|
var shapeOf = (s) => s.mesh ? { kind: "trimesh", vertices: s.mesh.vertices, indices: s.mesh.indices } : { kind: "box", half: s.half };
|
|
13503
13514
|
var EngineStatics = class {
|
|
13504
13515
|
constructor(world, material) {
|
|
@@ -13513,6 +13524,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13513
13524
|
__publicField(this, "ownerOf", /* @__PURE__ */ new Map());
|
|
13514
13525
|
/** The part of the object each held body draws (the key without its mesh number): what a blow on the body hits. */
|
|
13515
13526
|
__publicField(this, "partOf", /* @__PURE__ */ new Map());
|
|
13527
|
+
/** 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. */
|
|
13528
|
+
__publicField(this, "meshBounds", /* @__PURE__ */ new Map());
|
|
13516
13529
|
/** Changes whenever an answer of `covers` may have (an object came, went, or was fitted again). */
|
|
13517
13530
|
__publicField(this, "coverageRevision", 0);
|
|
13518
13531
|
__publicField(this, "unsure", NONE);
|
|
@@ -13541,6 +13554,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13541
13554
|
if (now.has(id)) continue;
|
|
13542
13555
|
for (const h of f.held.values()) this.release(h, f.settled);
|
|
13543
13556
|
this.bodies.delete(id);
|
|
13557
|
+
this.meshBounds.delete(id);
|
|
13544
13558
|
this.coverageRevision++;
|
|
13545
13559
|
}
|
|
13546
13560
|
const budget = { triangles: TRIANGLES_PER_UPDATE };
|
|
@@ -13557,6 +13571,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13557
13571
|
clear() {
|
|
13558
13572
|
for (const f of this.bodies.values()) for (const h of f.held.values()) this.drop(h.id);
|
|
13559
13573
|
this.bodies.clear();
|
|
13574
|
+
this.meshBounds.clear();
|
|
13560
13575
|
this.coverageRevision++;
|
|
13561
13576
|
this.changed.clear();
|
|
13562
13577
|
}
|
|
@@ -13613,6 +13628,22 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13613
13628
|
}
|
|
13614
13629
|
f.waiting = waiting;
|
|
13615
13630
|
if (waiting === 0) f.settled = true;
|
|
13631
|
+
this.boundMeshes(f);
|
|
13632
|
+
}
|
|
13633
|
+
boundMeshes(f) {
|
|
13634
|
+
let bounds;
|
|
13635
|
+
for (const h of f.held.values()) {
|
|
13636
|
+
const s = h.solid;
|
|
13637
|
+
if (!s.mesh) continue;
|
|
13638
|
+
bounds ?? (bounds = new Float64Array([Infinity, Infinity, Infinity, -Infinity, -Infinity, -Infinity]));
|
|
13639
|
+
const reach2 = orientedReach(s);
|
|
13640
|
+
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
13641
|
+
bounds[axis2] = Math.min(bounds[axis2], s.center[axis2] - reach2[axis2]);
|
|
13642
|
+
bounds[axis2 + 3] = Math.max(bounds[axis2 + 3], s.center[axis2] + reach2[axis2]);
|
|
13643
|
+
}
|
|
13644
|
+
}
|
|
13645
|
+
if (bounds) this.meshBounds.set(f.objectId, bounds);
|
|
13646
|
+
else this.meshBounds.delete(f.objectId);
|
|
13616
13647
|
}
|
|
13617
13648
|
/** 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). */
|
|
13618
13649
|
reshape(h, solid) {
|
|
@@ -13621,7 +13652,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13621
13652
|
if (!sameFriction(was.friction, solid.friction)) this.world.setMaterial(h.id, this.materialOf(solid));
|
|
13622
13653
|
this.changed.add(h.id);
|
|
13623
13654
|
if (sameShape(was, solid)) return;
|
|
13624
|
-
if (
|
|
13655
|
+
if (solid.mesh) this.world.setPose(h.id, MESH_ORIGIN, MESH_ROTATION, false);
|
|
13656
|
+
else this.world.setPose(h.id, solid.center, solid.rotation, false);
|
|
13625
13657
|
this.world.setShape(h.id, shapeOf(solid));
|
|
13626
13658
|
}
|
|
13627
13659
|
describe(solid) {
|
|
@@ -14264,6 +14296,26 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14264
14296
|
var RAY_MARGIN = 0.25;
|
|
14265
14297
|
var LONGEST_RAY = 2e3;
|
|
14266
14298
|
var FIXED_ONLY = { layers: ["static"] };
|
|
14299
|
+
var segmentMeetsBox = (origin, direction, length, box) => {
|
|
14300
|
+
let enter = 0;
|
|
14301
|
+
let leave = length;
|
|
14302
|
+
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
14303
|
+
const low = box[axis2] - RAY_MARGIN;
|
|
14304
|
+
const high = box[axis2 + 3] + RAY_MARGIN;
|
|
14305
|
+
const step = direction[axis2];
|
|
14306
|
+
const start = origin[axis2];
|
|
14307
|
+
if (Math.abs(step) < 1e-12) {
|
|
14308
|
+
if (start < low || start > high) return false;
|
|
14309
|
+
continue;
|
|
14310
|
+
}
|
|
14311
|
+
const a = (low - start) / step;
|
|
14312
|
+
const b = (high - start) / step;
|
|
14313
|
+
enter = Math.max(enter, Math.min(a, b));
|
|
14314
|
+
leave = Math.min(leave, Math.max(a, b));
|
|
14315
|
+
if (enter > leave) return false;
|
|
14316
|
+
}
|
|
14317
|
+
return true;
|
|
14318
|
+
};
|
|
14267
14319
|
var createEngineRayBroadPhase = (world, statics) => {
|
|
14268
14320
|
const hits = [];
|
|
14269
14321
|
const inside = [];
|
|
@@ -14290,6 +14342,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14290
14342
|
metList.push(owner);
|
|
14291
14343
|
}
|
|
14292
14344
|
}
|
|
14345
|
+
for (const [owner, bounds] of statics.meshBounds) {
|
|
14346
|
+
if (!met.has(owner) && segmentMeetsBox(origin, direction, maxDistance, bounds)) {
|
|
14347
|
+
met.add(owner);
|
|
14348
|
+
metList.push(owner);
|
|
14349
|
+
}
|
|
14350
|
+
}
|
|
14293
14351
|
const around = world.overlapSphere(from, RAY_MARGIN, inside, FIXED_ONLY);
|
|
14294
14352
|
for (let i = 0; i < around; i++) {
|
|
14295
14353
|
const owner = statics.ownerOf.get(inside[i]);
|
|
@@ -14957,6 +15015,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14957
15015
|
isSlipping: false
|
|
14958
15016
|
};
|
|
14959
15017
|
this.links.set(b, link);
|
|
15018
|
+
if (b.held) this.passThroughHolder(id, true);
|
|
14960
15019
|
this.byUser.set(user, b);
|
|
14961
15020
|
this.byBody.set(id, b);
|
|
14962
15021
|
this.bodyIds.add(id);
|
|
@@ -14967,14 +15026,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14967
15026
|
bodyDesc(b, user) {
|
|
14968
15027
|
const c = this.centre(b);
|
|
14969
15028
|
const q = b.root.quaternion;
|
|
15029
|
+
const shape = this.shapeOf(b);
|
|
14970
15030
|
return {
|
|
14971
|
-
shape
|
|
15031
|
+
shape,
|
|
14972
15032
|
motion: b.held ? "kinematic" : "dynamic",
|
|
14973
15033
|
position: [c.x, c.y, c.z],
|
|
14974
15034
|
rotation: [q.x, q.y, q.z, q.w],
|
|
14975
15035
|
mass: b.mass,
|
|
14976
15036
|
inertia: this.inertiaOf(b),
|
|
14977
15037
|
centreAtOrigin: true,
|
|
15038
|
+
keepPartContacts: shape.kind === "compound" && shape.children.length > 1,
|
|
14978
15039
|
material: this.material(b),
|
|
14979
15040
|
layer: "debris",
|
|
14980
15041
|
// no air drag: the kit's pieces never had any (a round piece's rolling resistance is the adapter's, `rolling`)
|
|
@@ -14990,6 +15051,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14990
15051
|
angularVelocity: [b.angularVelocity[0], b.angularVelocity[1], b.angularVelocity[2]]
|
|
14991
15052
|
};
|
|
14992
15053
|
}
|
|
15054
|
+
passThroughHolder(id, ignore) {
|
|
15055
|
+
const holder = this.o.heldIgnores?.();
|
|
15056
|
+
if (holder !== void 0) this.world.ignorePair(id, holder, ignore);
|
|
15057
|
+
}
|
|
14993
15058
|
/** 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). */
|
|
14994
15059
|
sync(b, dt, h) {
|
|
14995
15060
|
const c = this.centre(b);
|
|
@@ -15000,6 +15065,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15000
15065
|
if (b.held !== link.held) {
|
|
15001
15066
|
link.held = b.held;
|
|
15002
15067
|
this.world.setMotion(link.id, b.held ? "kinematic" : "dynamic");
|
|
15068
|
+
this.passThroughHolder(link.id, b.held);
|
|
15003
15069
|
}
|
|
15004
15070
|
if (b.held) {
|
|
15005
15071
|
this.world.moveKinematic(link.id, [c.x, c.y, c.z], [q.x, q.y, q.z, q.w], h);
|
|
@@ -16072,6 +16138,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16072
16138
|
onKnock: o.onKnock,
|
|
16073
16139
|
onHardLanding: o.onHardLanding,
|
|
16074
16140
|
...o.tilesUnderParts ? { tilesUnderParts: true } : {},
|
|
16141
|
+
...o.heldIgnores ? { heldIgnores: o.heldIgnores } : {},
|
|
16075
16142
|
...o.groundWorker ? { groundWorker: o.groundWorker } : {},
|
|
16076
16143
|
...o.groundWorkerFrames !== void 0 ? { groundWorkerFrames: o.groundWorkerFrames } : {}
|
|
16077
16144
|
}) : null;
|
|
@@ -29667,6 +29734,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29667
29734
|
scene: o.scene,
|
|
29668
29735
|
maxAwake: o.maxAwakePieces ?? Infinity,
|
|
29669
29736
|
...o.tilesUnderParts ? { tilesUnderParts: true } : {},
|
|
29737
|
+
...o.heldIgnores ? { heldIgnores: o.heldIgnores } : {},
|
|
29670
29738
|
...o.groundWorker ? { groundWorker: o.groundWorker } : {},
|
|
29671
29739
|
...o.groundWorkerFrames !== void 0 ? { groundWorkerFrames: o.groundWorkerFrames } : {},
|
|
29672
29740
|
...this.blastDebris ? { keep: { maxLive: this.blastDebris.maxLivePieces, far: this.blastDebris.far, ...o.focus ? { focus: o.focus } : {}, onFade: (b) => this.fadePiece(b) } } : {},
|