@adatechnology/game-destruction-three 0.28.2 → 0.29.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/dist/index.js CHANGED
@@ -3233,15 +3233,18 @@ function shapeContact(a, b) {
3233
3233
  import { createImpactReader } from "@adatechnology/game-physics";
3234
3234
  var DEFAULT_MIN_IMPULSE = 30;
3235
3235
  var DEFAULT_HITS_MAX = 32;
3236
+ var DEFAULT_MIN_APPROACH = 1.5;
3236
3237
  var DEFAULT_CONTACT_RADIUS = 0.1;
3237
3238
  var createEngineImpacts = (loop, statics, destruction, options = {}) => {
3238
3239
  const hitsMax = options.hitsMax ?? DEFAULT_HITS_MAX;
3239
3240
  const radius = options.contactRadius ?? DEFAULT_CONTACT_RADIUS;
3241
+ const minApproach = options.minApproach ?? DEFAULT_MIN_APPROACH;
3240
3242
  return createImpactReader(loop, {
3241
3243
  minImpulse: options.minImpulse ?? DEFAULT_MIN_IMPULSE,
3242
3244
  bodiesMax: hitsMax,
3243
3245
  accepts: (body) => statics.ownerOf.has(body),
3244
3246
  onImpact: (impact2) => {
3247
+ if (impact2.approach < minApproach) return;
3245
3248
  const object = statics.ownerOf.get(impact2.body);
3246
3249
  const part = statics.partOf.get(impact2.body);
3247
3250
  if (object === void 0 || part === void 0 || destruction.part(object, part) === null) return;
@@ -3781,6 +3784,14 @@ var EnginePieces = class {
3781
3784
  if (tile.patch) this.schedule?.givePatch(tile.patch.heights);
3782
3785
  this.tiles.delete(key);
3783
3786
  }
3787
+ /** The piece a body of the engine is, or undefined (a fixed body, someone else's). */
3788
+ pieceOfBody(body) {
3789
+ return this.byBody.get(body);
3790
+ }
3791
+ /** Whether the piece has a body in the engine yet (a piece made this frame has none until the next update). */
3792
+ hasBody(piece) {
3793
+ return this.links.has(piece);
3794
+ }
3784
3795
  /** The fixed bodies as a broad phase for the destruction world's rays (`engine-rays.ts`). */
3785
3796
  rayBroadPhase() {
3786
3797
  return createEngineRayBroadPhase(this.world, this.statics);
@@ -4158,7 +4169,7 @@ var EnginePieces = class {
4158
4169
  }
4159
4170
  /** A round piece rolls to a stop by its surface's rolling resistance (the adapter's rule; the engine has none). */
4160
4171
  rollingOf(b) {
4161
- return b.round ? { coefficient: b.friction?.rolling ?? ROLLING_RESISTANCE, radius: b.round.radius } : void 0;
4172
+ return b.round ? { coefficient: b.friction?.rolling ?? ROLLING_RESISTANCE, radius: b.round.radius, damping: b.friction?.rollingDamping ?? PIECE_ROLLING_DAMPING } : void 0;
4162
4173
  }
4163
4174
  material(b) {
4164
4175
  return {
@@ -4774,11 +4785,13 @@ var EnginePieces = class {
4774
4785
  /** The surface of the tile's bodies: the ground's own rolling resistance at its middle (`tileRollingAt`), one shared object per value; `GROUND` without the host's. */
4775
4786
  groundMaterial(ix, iz) {
4776
4787
  const rolling = this.o.groundRollingAt ? tileRollingAt(this.o.groundRollingAt, ix * TILE, iz * TILE) : void 0;
4777
- if (rolling === void 0 || rolling === ROLLING_RESISTANCE) return GROUND;
4778
- let material = this.groundMaterials.get(rolling);
4788
+ const damping = this.o.groundRollingDampingAt ? tileRollingAt(this.o.groundRollingDampingAt, ix * TILE, iz * TILE) : void 0;
4789
+ if ((rolling === void 0 || rolling === ROLLING_RESISTANCE) && damping === void 0) return GROUND;
4790
+ const key = `${rolling ?? ROLLING_RESISTANCE}|${damping ?? ""}`;
4791
+ let material = this.groundMaterials.get(key);
4779
4792
  if (!material) {
4780
- material = { ...GROUND, rolling };
4781
- this.groundMaterials.set(rolling, material);
4793
+ material = { ...GROUND, rolling: rolling ?? ROLLING_RESISTANCE, ...damping === void 0 ? {} : { rollingDamping: damping } };
4794
+ this.groundMaterials.set(key, material);
4782
4795
  }
4783
4796
  return material;
4784
4797
  }
@@ -5313,6 +5326,7 @@ var PieceSystem = class {
5313
5326
  this.engine = resolved ? new EnginePieces(THREE, resolved.loop.world, {
5314
5327
  groundAt: o.terrainAt ?? o.groundAt,
5315
5328
  ...o.terrainRollingAt ? { groundRollingAt: o.terrainRollingAt } : {},
5329
+ ...o.terrainRollingDampingAt ? { groundRollingDampingAt: o.terrainRollingDampingAt } : {},
5316
5330
  ...o.terrainRangeAt ? { groundRange: o.terrainRangeAt } : {},
5317
5331
  // the grid stands for `terrainAt` alone: without it the tiles read `groundAt`, which the grid may not be (a lot flattened, a slab)
5318
5332
  ...o.terrainGridAt && o.terrainAt ? { groundGrid: o.terrainGridAt } : {},
@@ -5336,6 +5350,21 @@ var PieceSystem = class {
5336
5350
  contactHits(destruction, options) {
5337
5351
  return this.engine && this.loop ? createEngineImpacts(this.loop, this.engine.statics, destruction, options) : null;
5338
5352
  }
5353
+ /**
5354
+ * 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
5355
+ * 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.
5356
+ */
5357
+ piecesInBlast(blastQuery, point, radius) {
5358
+ const engine = this.engine;
5359
+ if (!engine) return [...this.list];
5360
+ const found = blastQuery.run({ origin: point, radius });
5361
+ const reached = /* @__PURE__ */ new Set();
5362
+ for (let i = 0; i < found.bodyCount; i++) {
5363
+ const piece = engine.pieceOfBody(found.bodies[i]);
5364
+ if (piece) reached.add(piece);
5365
+ }
5366
+ return this.list.filter((piece) => reached.has(piece) || !engine.hasBody(piece));
5367
+ }
5339
5368
  /** The engine's fixed bodies as the broad phase of the world's rays, or null when the pieces are not in the engine. */
5340
5369
  rayBroadPhase() {
5341
5370
  return this.engine?.rayBroadPhase() ?? null;
@@ -12054,7 +12083,8 @@ var Renderer = class {
12054
12083
  const point = [c.x + (this.rng() - 0.5) * spread, c.y + spread * 0.5, c.z + (this.rng() - 0.5) * spread];
12055
12084
  reach(distance, { objectId: pc.objectId, generation: pc.generation, impulse, point }, [c.x, c.y, c.z]);
12056
12085
  };
12057
- for (const pc of [...this.pieceSys.list]) shove(pc);
12086
+ const reached = this.o.blastQuery ? this.pieceSys.piecesInBlast(this.o.blastQuery, p, ev.radius) : [...this.pieceSys.list];
12087
+ for (const pc of reached) shove(pc);
12058
12088
  if (this.o.shoveable) this.loosen(p, ev.radius, energy, reachOf2, policy, reach);
12059
12089
  this.advanceWakes(0);
12060
12090
  this.fragments.blast(p, ev.radius, Math.min(20, Math.sqrt(energy) * 0.08));