@adatechnology/game-destruction-three 0.22.0 → 0.22.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.
@@ -10367,16 +10367,29 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10367
10367
  }
10368
10368
  }
10369
10369
  update(dt) {
10370
- const steps = this.collisionSteps(dt);
10371
- for (let i = 0; i < steps; i++) this.step(dt / steps);
10370
+ const { steps, near } = this.collisionSteps(dt);
10371
+ if (steps === 1) {
10372
+ this.time += dt;
10373
+ this.step(dt);
10374
+ return;
10375
+ }
10376
+ const start = this.time;
10377
+ this.time = start + dt;
10378
+ const far = (b) => !near.has(b);
10379
+ this.step(dt, { moves: far, meets: (a, b) => far(a) && far(b) });
10380
+ for (let i = 0; i < steps; i++) {
10381
+ this.time = start + dt * (i + 1) / steps;
10382
+ this.step(dt / steps, { moves: (b) => near.has(b), meets: (a, b) => near.has(a) || near.has(b) });
10383
+ }
10372
10384
  }
10373
10385
  /**
10374
10386
  * Steps of an update: one, or more while a round piece and a piece it could meet within the update close in fast enough to pass through each other between two (closing at
10375
10387
  * their two speeds they cover at most the round one's radius per step: two cans at 3.6 m/s close 12 cm in a frame, a can is 7 cm across; a plank thrown at a can still counts).
10376
- * A round piece with nothing in reach takes one step, so its sweep against the world (the costly part) runs once.
10388
+ * A round piece with nothing in reach takes one step, so its sweep against the world (the costly part) runs once; `near` holds the pieces of the pairs that need more.
10377
10389
  */
10378
10390
  collisionSteps(dt) {
10379
10391
  let need = 1;
10392
+ const near = /* @__PURE__ */ new Set();
10380
10393
  const p = this.p;
10381
10394
  const speedOf = (b) => b.held ? 0 : Math.hypot(b.velocity[0], b.velocity[1], b.velocity[2]);
10382
10395
  for (const b of this.list) {
@@ -10393,13 +10406,17 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10393
10406
  const reach = closing * dt + rb + Math.hypot(o.halfExtents[0], o.halfExtents[1], o.halfExtents[2]);
10394
10407
  const oc = this.centerOf(o, p);
10395
10408
  if (Math.abs(oc.x - cx) > reach || Math.abs(oc.y - cy) > reach || Math.abs(oc.z - cz) > reach) continue;
10396
- need = Math.max(need, Math.ceil(closing * dt / radius));
10409
+ const pair = Math.ceil(closing * dt / radius);
10410
+ if (pair < 2) continue;
10411
+ need = Math.max(need, pair);
10412
+ near.add(b);
10413
+ near.add(o);
10397
10414
  }
10398
10415
  }
10399
- return Math.max(1, Math.min(MAX_COLLISION_STEPS, need));
10416
+ return { steps: Math.max(1, Math.min(MAX_COLLISION_STEPS, need)), near };
10400
10417
  }
10401
- step(dt) {
10402
- this.time += dt;
10418
+ /** A step of `dt`: the pieces `only.moves` takes move (all when absent) and the pairs `only.meets` takes meet, so each pair meets in one of the steps of an update. */
10419
+ step(dt, only) {
10403
10420
  this.solids = this.list.map((body) => {
10404
10421
  const c = this.centerOf(body, new this.THREE.Vector3());
10405
10422
  const h = body.halfExtents;
@@ -10460,14 +10477,14 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10460
10477
  b.calmAt = null;
10461
10478
  continue;
10462
10479
  }
10463
- if (b.sleeping) continue;
10480
+ if (b.sleeping || only && !only.moves(b)) continue;
10464
10481
  this.integrate(b, dt);
10465
10482
  if (b.sleeping) continue;
10466
10483
  const v = b.velocity;
10467
10484
  const w = b.angularVelocity;
10468
10485
  if (Math.hypot(v[0], v[1], v[2]) > WAKE_ABOVE_SPEED || Math.hypot(w[0], w[1], w[2]) > WAKE_ABOVE_SPIN) this.wakeAbove(b);
10469
10486
  }
10470
- this.collide(dt);
10487
+ this.collide(dt, only?.meets);
10471
10488
  }
10472
10489
  /** A few sleeping pieces each update (`SUPPORT_CHECKS`, in turn) look under them again: one whose table broke, or whose shelf fell over, falls. */
10473
10490
  wakeUnsupported() {
@@ -10969,7 +10986,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10969
10986
  * Pieces against each other. Candidates by sweep and prune along x on their bounding spheres (sorted once per step: fifty cans cost a sort and a handful of pairs, not
10970
10987
  * 1225); a pair with a round piece in it meets by its shapes (`shapeContact`) and exchanges an impulse, two boxes are only pushed apart (`separatePair`).
10971
10988
  */
10972
- collide(dt) {
10989
+ collide(dt, meets) {
10973
10990
  const n = this.list.length;
10974
10991
  if (n < 2) return;
10975
10992
  const centers = this.list.map((b) => {
@@ -10987,6 +11004,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10987
11004
  const a = this.list[i];
10988
11005
  const b = this.list[j];
10989
11006
  if ((a.held || a.sleeping) && (b.held || b.sleeping)) continue;
11007
+ if (meets && !meets(a, b)) continue;
10990
11008
  const r = radii[i] + radii[j];
10991
11009
  const ca = centers[i];
10992
11010
  const cb = centers[j];