@adatechnology/game-destruction-three 0.28.2 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.global.js +28 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -270,7 +270,7 @@ in `@adatechnology/game-vfx` (`patchSpriteKinds(SPRITE_KINDS, { dust: { life: [1
|
|
|
270
270
|
|
|
271
271
|
## Engine hits and ray broad phase
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
Three options, off by default (the kit-defaults preset turns `contactHits` and `blastQuery` on when a loop steps the pieces), for a renderer whose pieces are in a `PhysicsLoop`: `contactHits: true` turns the engine's strongest blow on each fixed drawn part into a `blunt` hit of the world (`hitPart`, energy about `impulse × closing speed / 2`, direction the other body was going, at most 32 parts a frame, blows under 30 N s or closing slower than 1.5 m/s ignored, so a pile settling on a part does not hit; `{ minImpulse, minApproach, hitsMax, contactRadius }` to tune): a flying piece into a wall, a slab onto a crate, so a blast's cascade takes the next wall by itself. `blastQuery` (`PhysicsServices.blast`): a blast shoves the pieces the engine finds within its radius, in the order and with the push of the walk over every piece it replaces. `rayBroadPhase: true` lets the engine's fixed bodies narrow the objects the world's rays read.
|
|
274
274
|
|
|
275
275
|
## Português
|
|
276
276
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { WorkerCoordinator, KitOrigin, DeferredQueue, DeferredQueueOptions, Warm
|
|
|
4
4
|
import { HeightPatch } from '@adatechnology/game-terrain';
|
|
5
5
|
import { WorkerLike, WorkerScopeLike } from '@adatechnology/game-shapes';
|
|
6
6
|
import * as THREE_NS from 'three';
|
|
7
|
-
import { Quat, WorkBudgetOptions, PhysicsLoop, SeamWorld, PhysicsEngine, WorldDesc } from '@adatechnology/game-physics';
|
|
7
|
+
import { Quat, WorkBudgetOptions, PhysicsLoop, SeamWorld, PhysicsEngine, WorldDesc, BlastQuery } from '@adatechnology/game-physics';
|
|
8
8
|
export { DEFAULT_WORK_BUDGET_MS, isPhysicsLoop, physicsPieceCount } from '@adatechnology/game-physics';
|
|
9
9
|
import { VfxWorld, SpriteKind } from '@adatechnology/game-vfx';
|
|
10
10
|
import { LoopRecipe, SoundBank, SoundRecipe, Falloff, AudioEngine, VoiceGroup, SampleDefaults, SfxManifest } from '@adatechnology/game-audio';
|
|
@@ -141,6 +141,8 @@ interface EngineImpactsOptions {
|
|
|
141
141
|
readonly minImpulse?: number;
|
|
142
142
|
/** Most fixed parts hit in a frame, in the order the engine met them. Default 32. */
|
|
143
143
|
readonly hitsMax?: number;
|
|
144
|
+
/** Blows closing slower than this (m/s) do nothing: a pile settling or resting on a part presses with impulse but does not hit. Default 1.5. */
|
|
145
|
+
readonly minApproach?: number;
|
|
144
146
|
/** The radius (m) of the blunt contact. Default 0.1. */
|
|
145
147
|
readonly contactRadius?: number;
|
|
146
148
|
}
|
|
@@ -361,6 +363,8 @@ interface RendererOptions {
|
|
|
361
363
|
rayBroadPhase?: boolean;
|
|
362
364
|
/** A blow of the engine on a fixed part of the drawn world (a flying piece into a wall) becomes a `blunt` hit of the world, with the energy of the blow (`engine-impacts.ts`); `true` for the defaults. Needs the pieces in a `PhysicsLoop`. Off by default. */
|
|
363
365
|
contactHits?: boolean | EngineImpactsOptions;
|
|
366
|
+
/** The engine's blast query (`PhysicsServices.blast`): a blast shoves the pieces it finds within its radius instead of measuring every piece in the system. Needs the pieces in a `PhysicsLoop`. Off by default. */
|
|
367
|
+
blastQuery?: BlastQuery;
|
|
364
368
|
/** Scene that receives fragments, loose pieces, decals and particles. */
|
|
365
369
|
scene: THREE_NS.Scene;
|
|
366
370
|
world: DestructionWorld;
|
package/dist/index.global.js
CHANGED
|
@@ -13970,15 +13970,18 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13970
13970
|
// src/engine-impacts.ts
|
|
13971
13971
|
var DEFAULT_MIN_IMPULSE = 30;
|
|
13972
13972
|
var DEFAULT_HITS_MAX = 32;
|
|
13973
|
+
var DEFAULT_MIN_APPROACH = 1.5;
|
|
13973
13974
|
var DEFAULT_CONTACT_RADIUS = 0.1;
|
|
13974
13975
|
var createEngineImpacts = (loop, statics, destruction, options = {}) => {
|
|
13975
13976
|
const hitsMax = options.hitsMax ?? DEFAULT_HITS_MAX;
|
|
13976
13977
|
const radius = options.contactRadius ?? DEFAULT_CONTACT_RADIUS;
|
|
13978
|
+
const minApproach = options.minApproach ?? DEFAULT_MIN_APPROACH;
|
|
13977
13979
|
return createImpactReader(loop, {
|
|
13978
13980
|
minImpulse: options.minImpulse ?? DEFAULT_MIN_IMPULSE,
|
|
13979
13981
|
bodiesMax: hitsMax,
|
|
13980
13982
|
accepts: (body) => statics.ownerOf.has(body),
|
|
13981
13983
|
onImpact: (impact3) => {
|
|
13984
|
+
if (impact3.approach < minApproach) return;
|
|
13982
13985
|
const object = statics.ownerOf.get(impact3.body);
|
|
13983
13986
|
const part = statics.partOf.get(impact3.body);
|
|
13984
13987
|
if (object === void 0 || part === void 0 || destruction.part(object, part) === null) return;
|
|
@@ -14514,6 +14517,14 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14514
14517
|
if (tile.patch) this.schedule?.givePatch(tile.patch.heights);
|
|
14515
14518
|
this.tiles.delete(key);
|
|
14516
14519
|
}
|
|
14520
|
+
/** The piece a body of the engine is, or undefined (a fixed body, someone else's). */
|
|
14521
|
+
pieceOfBody(body) {
|
|
14522
|
+
return this.byBody.get(body);
|
|
14523
|
+
}
|
|
14524
|
+
/** Whether the piece has a body in the engine yet (a piece made this frame has none until the next update). */
|
|
14525
|
+
hasBody(piece) {
|
|
14526
|
+
return this.links.has(piece);
|
|
14527
|
+
}
|
|
14517
14528
|
/** The fixed bodies as a broad phase for the destruction world's rays (`engine-rays.ts`). */
|
|
14518
14529
|
rayBroadPhase() {
|
|
14519
14530
|
return createEngineRayBroadPhase(this.world, this.statics);
|
|
@@ -16068,6 +16079,21 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16068
16079
|
contactHits(destruction, options) {
|
|
16069
16080
|
return this.engine && this.loop ? createEngineImpacts(this.loop, this.engine.statics, destruction, options) : null;
|
|
16070
16081
|
}
|
|
16082
|
+
/**
|
|
16083
|
+
* The pieces a blast at `point` can reach: the bodies the engine's `blastQuery` finds within `radius` (the pieces among them), in the order of `list`, and the pieces that have no
|
|
16084
|
+
* body yet. The pieces are not walked one by one to measure each one's distance; the caller still takes the distance to the centre of each, as before.
|
|
16085
|
+
*/
|
|
16086
|
+
piecesInBlast(blastQuery, point, radius) {
|
|
16087
|
+
const engine = this.engine;
|
|
16088
|
+
if (!engine) return [...this.list];
|
|
16089
|
+
const found = blastQuery.run({ origin: point, radius });
|
|
16090
|
+
const reached = /* @__PURE__ */ new Set();
|
|
16091
|
+
for (let i = 0; i < found.bodyCount; i++) {
|
|
16092
|
+
const piece = engine.pieceOfBody(found.bodies[i]);
|
|
16093
|
+
if (piece) reached.add(piece);
|
|
16094
|
+
}
|
|
16095
|
+
return this.list.filter((piece) => reached.has(piece) || !engine.hasBody(piece));
|
|
16096
|
+
}
|
|
16071
16097
|
/** The engine's fixed bodies as the broad phase of the world's rays, or null when the pieces are not in the engine. */
|
|
16072
16098
|
rayBroadPhase() {
|
|
16073
16099
|
return this.engine?.rayBroadPhase() ?? null;
|
|
@@ -32033,7 +32059,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
32033
32059
|
const point = [c.x + (this.rng() - 0.5) * spread2, c.y + spread2 * 0.5, c.z + (this.rng() - 0.5) * spread2];
|
|
32034
32060
|
reach2(distance, { objectId: pc.objectId, generation: pc.generation, impulse, point }, [c.x, c.y, c.z]);
|
|
32035
32061
|
};
|
|
32036
|
-
|
|
32062
|
+
const reached = this.o.blastQuery ? this.pieceSys.piecesInBlast(this.o.blastQuery, p, ev.radius) : [...this.pieceSys.list];
|
|
32063
|
+
for (const pc of reached) shove(pc);
|
|
32037
32064
|
if (this.o.shoveable) this.loosen(p, ev.radius, energy, reachOf2, policy, reach2);
|
|
32038
32065
|
this.advanceWakes(0);
|
|
32039
32066
|
this.fragments.blast(p, ev.radius, Math.min(20, Math.sqrt(energy) * 0.08));
|