@codexo/exojs-physics 0.16.2 → 0.18.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 +13 -45
- package/dist/esm/Collider.d.ts +0 -33
- package/dist/esm/Collider.d.ts.map +1 -1
- package/dist/esm/Collider.js +10 -1
- package/dist/esm/Collider.js.map +1 -1
- package/dist/esm/ContactGraph.d.ts +22 -14
- package/dist/esm/ContactGraph.d.ts.map +1 -1
- package/dist/esm/ContactGraph.js +43 -5
- package/dist/esm/ContactGraph.js.map +1 -1
- package/dist/esm/ContactModifier.d.ts +0 -23
- package/dist/esm/ContactModifier.d.ts.map +1 -1
- package/dist/esm/PhysicsBody.d.ts +0 -81
- package/dist/esm/PhysicsBody.d.ts.map +1 -1
- package/dist/esm/PhysicsBody.js +37 -8
- package/dist/esm/PhysicsBody.js.map +1 -1
- package/dist/esm/PhysicsWorld.d.ts +63 -41
- package/dist/esm/PhysicsWorld.d.ts.map +1 -1
- package/dist/esm/PhysicsWorld.js +162 -36
- package/dist/esm/PhysicsWorld.js.map +1 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +22 -6
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +1 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.js +45 -11
- package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +1 -1
- package/dist/esm/collision/chainAdjacency.d.ts +1 -28
- package/dist/esm/collision/chainAdjacency.d.ts.map +1 -1
- package/dist/esm/joints/DistanceJoint.d.ts +2 -4
- package/dist/esm/joints/DistanceJoint.d.ts.map +1 -1
- package/dist/esm/joints/DistanceJoint.js +8 -5
- package/dist/esm/joints/DistanceJoint.js.map +1 -1
- package/dist/esm/joints/Joint.d.ts +59 -9
- package/dist/esm/joints/Joint.d.ts.map +1 -1
- package/dist/esm/joints/Joint.js +39 -3
- package/dist/esm/joints/Joint.js.map +1 -1
- package/dist/esm/joints/MouseJoint.d.ts +0 -3
- package/dist/esm/joints/MouseJoint.d.ts.map +1 -1
- package/dist/esm/joints/MouseJoint.js +4 -1
- package/dist/esm/joints/MouseJoint.js.map +1 -1
- package/dist/esm/joints/PrismaticJoint.d.ts +2 -4
- package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -1
- package/dist/esm/joints/PrismaticJoint.js +5 -2
- package/dist/esm/joints/PrismaticJoint.js.map +1 -1
- package/dist/esm/joints/RevoluteJoint.d.ts +4 -9
- package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -1
- package/dist/esm/joints/RevoluteJoint.js +42 -33
- package/dist/esm/joints/RevoluteJoint.js.map +1 -1
- package/dist/esm/joints/WeldJoint.d.ts +2 -4
- package/dist/esm/joints/WeldJoint.d.ts.map +1 -1
- package/dist/esm/joints/WeldJoint.js +12 -9
- package/dist/esm/joints/WeldJoint.js.map +1 -1
- package/dist/esm/joints/WheelJoint.d.ts +2 -4
- package/dist/esm/joints/WheelJoint.d.ts.map +1 -1
- package/dist/esm/joints/WheelJoint.js +8 -5
- package/dist/esm/joints/WheelJoint.js.map +1 -1
- package/dist/esm/physicsBuildInfo.js +2 -2
- package/dist/esm/public.d.ts +1 -1
- package/dist/esm/public.d.ts.map +1 -1
- package/dist/esm/shapes/ChainEdgeShape.d.ts +1 -29
- package/dist/esm/shapes/ChainEdgeShape.d.ts.map +1 -1
- package/dist/esm/shapes/ChainShape.d.ts +0 -6
- package/dist/esm/shapes/ChainShape.d.ts.map +1 -1
- package/dist/esm/shapes/decompose.d.ts +1 -23
- package/dist/esm/shapes/decompose.d.ts.map +1 -1
- package/dist/esm/solver/ContactSolver.d.ts.map +1 -1
- package/dist/esm/solver/ContactSolver.js +16 -3
- package/dist/esm/solver/ContactSolver.js.map +1 -1
- package/dist/esm/solver/tolerances.d.ts +1 -33
- package/dist/esm/solver/tolerances.d.ts.map +1 -1
- package/dist/esm/solver/tolerances.js +14 -16
- package/dist/esm/solver/tolerances.js.map +1 -1
- package/dist/esm/sort.d.ts +1 -17
- package/dist/esm/sort.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/esm/PhysicsWorld.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { aabbOverlap, createAabb } from "./Aabb.js";
|
|
2
2
|
import { shouldCollide } from "./types.js";
|
|
3
3
|
import { Collider, authoredCollider } from "./Collider.js";
|
|
4
|
+
import { softConstraint } from "./joints/Joint.js";
|
|
4
5
|
import { PhysicsBody } from "./PhysicsBody.js";
|
|
6
|
+
import { bodyPairKey } from "./ContactGraph.js";
|
|
5
7
|
import { sleepPenetrationTolerance } from "./solver/tolerances.js";
|
|
6
8
|
import { NativePhysicsBackend } from "./backend/NativePhysicsBackend.js";
|
|
7
9
|
import { BindingRegistry } from "./binding/BindingRegistry.js";
|
|
@@ -59,13 +61,33 @@ const assertBodyKeepsItsMass = (collider, pendingRemovals) => {
|
|
|
59
61
|
*/
|
|
60
62
|
const isMovingBoundary = (body) => body._teleported || body.linearVelocityX !== 0 || body.linearVelocityY !== 0 || body.angularVelocity !== 0;
|
|
61
63
|
/**
|
|
62
|
-
* `true` while a contact
|
|
63
|
-
*
|
|
64
|
-
* same separation the solver's
|
|
65
|
-
* and the constraint it gates therefore agree by
|
|
64
|
+
* `true` while a contact carries overlap the push-out is still working off, so
|
|
65
|
+
* neither of its bodies may bank sleep time. Read from the manifold detection
|
|
66
|
+
* just produced, which is the same separation the solver's bias is about to act
|
|
67
|
+
* on - the sleep gate and the constraint it gates therefore agree by
|
|
68
|
+
* construction.
|
|
69
|
+
*
|
|
70
|
+
* Depth alone cannot answer this. A loaded contact rests at the depth its own
|
|
71
|
+
* soft-constraint deflection holds it at, and in a dense pile that is several
|
|
72
|
+
* times the depth a lone body on a floor reaches; a depth-only gate therefore
|
|
73
|
+
* never lets such a pile sleep, and the scene keeps being solved in full long
|
|
74
|
+
* after it stopped moving. Progress is the distinguishing quantity: either the
|
|
75
|
+
* last step still closed the overlap, or the contact has reached its
|
|
76
|
+
* equilibrium and waiting changes nothing about it.
|
|
77
|
+
*
|
|
78
|
+
* A point with no penetration history - a fresh overlap, or one whose contact
|
|
79
|
+
* was disabled last step - counts as unresolved whatever its depth, so geometry
|
|
80
|
+
* appearing inside a sleeping body reopens the sleep decision.
|
|
66
81
|
*/
|
|
67
|
-
const isUnresolved = (
|
|
68
|
-
|
|
82
|
+
const isUnresolved = (record, dt) => {
|
|
83
|
+
const manifold = record.manifold;
|
|
84
|
+
const stall = 1 * dt;
|
|
85
|
+
for (let i = 0; i < manifold.pointCount; i++) {
|
|
86
|
+
const penetration = (i === 0 ? manifold.points[0] : manifold.points[1]).penetration;
|
|
87
|
+
if (penetration <= .75) continue;
|
|
88
|
+
const previous = i === 0 ? record.previousPenetration[0] : record.previousPenetration[1];
|
|
89
|
+
if (previous < 0 || Math.abs(previous - penetration) > stall) return true;
|
|
90
|
+
}
|
|
69
91
|
return false;
|
|
70
92
|
};
|
|
71
93
|
/**
|
|
@@ -231,6 +253,29 @@ var PhysicsWorld = class {
|
|
|
231
253
|
/** Pooled scratch for re-syncing a single body's broad-phase leaves. */
|
|
232
254
|
_leafScratch = [];
|
|
233
255
|
_joints = [];
|
|
256
|
+
/**
|
|
257
|
+
* The joints `_prepare` left active this fixed step, in `_joints` order -
|
|
258
|
+
* what the sub-step warm-start and solve passes iterate instead of the full
|
|
259
|
+
* list. Reused across steps; a scene whose joints are all asleep leaves it
|
|
260
|
+
* empty and the sub-steps touch no joint at all.
|
|
261
|
+
*/
|
|
262
|
+
_activeJoints = [];
|
|
263
|
+
/**
|
|
264
|
+
* The bodies this fixed step's sub-steps integrate (non-static and awake),
|
|
265
|
+
* collected once per step. Reused across steps; sleep state cannot change
|
|
266
|
+
* between the sub-steps, so the snapshot stays valid for all of them.
|
|
267
|
+
*/
|
|
268
|
+
_steppedBodies = [];
|
|
269
|
+
/**
|
|
270
|
+
* Body pairs the live joints have taken out of collision, reference-counted:
|
|
271
|
+
* several joints may connect one pair, and the pair collides again only once
|
|
272
|
+
* the last of them is gone.
|
|
273
|
+
*
|
|
274
|
+
* Keyed on the pair rather than expressed through collision filters, because
|
|
275
|
+
* a ragdoll limb has to keep colliding with everything except the limb it is
|
|
276
|
+
* jointed to - which a category/mask pair cannot say.
|
|
277
|
+
*/
|
|
278
|
+
_uncollidableJointPairs = /* @__PURE__ */ new Map();
|
|
234
279
|
_bindings = new BindingRegistry();
|
|
235
280
|
_query;
|
|
236
281
|
_commands = [];
|
|
@@ -302,6 +347,7 @@ var PhysicsWorld = class {
|
|
|
302
347
|
this.interpolation = options.interpolation ?? false;
|
|
303
348
|
this.frameAlphaSource = options.frameAlphaSource ?? (() => this.timeStepper.alpha);
|
|
304
349
|
this._query = new QueryEngine(this._detectionColliders, this._backend.spatialIndex);
|
|
350
|
+
this._backend.contactGraph._useUncollidablePairs(this._uncollidableJointPairs);
|
|
305
351
|
}
|
|
306
352
|
/** Live bodies (read-only view). */
|
|
307
353
|
get bodies() {
|
|
@@ -403,10 +449,17 @@ var PhysicsWorld = class {
|
|
|
403
449
|
*/
|
|
404
450
|
addJoint(joint) {
|
|
405
451
|
this._assertAlive();
|
|
452
|
+
if (joint.bodyA === joint.bodyB) throw new Error("PhysicsWorld.addJoint: a joint needs two different bodies.");
|
|
453
|
+
if (joint.bodyA.destroyed || joint.bodyB.destroyed) throw new Error("PhysicsWorld.addJoint: a joint cannot constrain a destroyed body.");
|
|
406
454
|
joint.bodyA.wake();
|
|
407
455
|
joint.bodyB.wake();
|
|
408
456
|
this._defer(() => {
|
|
409
|
-
if (
|
|
457
|
+
if (joint.bodyA._isForeignTo(this) || joint.bodyB._isForeignTo(this)) throw new Error("PhysicsWorld.addJoint: a joint cannot constrain a body of another world.");
|
|
458
|
+
if (joint.bodyA.destroyed || joint.bodyB.destroyed) return;
|
|
459
|
+
if (!this._joints.includes(joint)) {
|
|
460
|
+
this._joints.push(joint);
|
|
461
|
+
this._holdPairApart(joint, 1);
|
|
462
|
+
}
|
|
410
463
|
});
|
|
411
464
|
return joint;
|
|
412
465
|
}
|
|
@@ -416,10 +469,26 @@ var PhysicsWorld = class {
|
|
|
416
469
|
joint.bodyB.wake();
|
|
417
470
|
this._defer(() => {
|
|
418
471
|
const index = this._joints.indexOf(joint);
|
|
419
|
-
if (index !== -1)
|
|
472
|
+
if (index !== -1) {
|
|
473
|
+
this._joints.splice(index, 1);
|
|
474
|
+
this._holdPairApart(joint, -1);
|
|
475
|
+
}
|
|
420
476
|
});
|
|
421
477
|
}
|
|
422
478
|
/**
|
|
479
|
+
* Reference-count one joint's claim that its two bodies do not collide.
|
|
480
|
+
*
|
|
481
|
+
* Driven from the deferred add and remove rather than from the constructor,
|
|
482
|
+
* so the set describes the joints the world is actually stepping.
|
|
483
|
+
*/
|
|
484
|
+
_holdPairApart(joint, delta) {
|
|
485
|
+
if (joint.collideConnected || joint.bodyA.id < 0 || joint.bodyB.id < 0) return;
|
|
486
|
+
const key = bodyPairKey(joint.bodyA.id, joint.bodyB.id);
|
|
487
|
+
const held = (this._uncollidableJointPairs.get(key) ?? 0) + delta;
|
|
488
|
+
if (held > 0) this._uncollidableJointPairs.set(key, held);
|
|
489
|
+
else this._uncollidableJointPairs.delete(key);
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
423
492
|
* Advance the world by `frameDeltaSeconds`. Accumulates into fixed steps; each
|
|
424
493
|
* fixed step runs detection once, then a TGS-Soft sub-step loop (integrate
|
|
425
494
|
* gravity, solve contacts with a soft bias, integrate positions, relax) and a
|
|
@@ -506,23 +575,47 @@ var PhysicsWorld = class {
|
|
|
506
575
|
if (this.contactModifier !== null) this._backend.applyContactModifier(this.contactModifier);
|
|
507
576
|
if (this.enableSleeping) this._updateSleeping(this.timeStepper.fixedDelta);
|
|
508
577
|
this._backend.prepareSolve(h, contactHertz, dampingRatio);
|
|
509
|
-
if (hasJoints) this._prepareJoints(h);
|
|
578
|
+
if (hasJoints) this._prepareJoints(h, contactHertz, dampingRatio);
|
|
510
579
|
if (hasBullets) this._recordBulletPositions();
|
|
580
|
+
const stepped = this._collectSteppedBodies();
|
|
511
581
|
for (let subStep = 0; subStep < subStepCount; subStep++) {
|
|
512
|
-
for (const body of
|
|
582
|
+
for (const body of stepped) body._integrateVelocity(h, gravityX, gravityY);
|
|
513
583
|
this._backend.warmStart();
|
|
514
584
|
if (hasJoints) this._warmStartJoints();
|
|
515
585
|
this._backend.solveVelocities(true);
|
|
516
586
|
if (hasJoints) this._solveJoints(true);
|
|
517
|
-
for (const body of
|
|
587
|
+
for (const body of stepped) body._integratePosition(h);
|
|
518
588
|
this._backend.solveVelocities(false);
|
|
519
589
|
if (hasJoints) this._solveJoints(false);
|
|
520
590
|
}
|
|
521
591
|
this._backend.applyRestitution();
|
|
522
|
-
for (const body of
|
|
592
|
+
for (const body of stepped) body._finalizePosition();
|
|
523
593
|
if (hasBullets) this._advanceBullets();
|
|
524
594
|
}
|
|
525
595
|
/**
|
|
596
|
+
* Collect the bodies this step touches: non-static and awake. The sub-step
|
|
597
|
+
* integrators and the finalize pass all reject a static or sleeping body
|
|
598
|
+
* anyway, so filtering here changes nothing but how often the rejection is
|
|
599
|
+
* paid - once per step instead of once per body per sub-step.
|
|
600
|
+
*
|
|
601
|
+
* Nothing between this call and the end of the step changes a body's sleep
|
|
602
|
+
* state, so one snapshot serves every pass.
|
|
603
|
+
*
|
|
604
|
+
* A sleeping body needs nothing from the finalize pass: every API that puts a
|
|
605
|
+
* force on a body or teleports it wakes the body first, so it cannot reach
|
|
606
|
+
* this set carrying either, and `_setSleeping` does the rest as it goes to
|
|
607
|
+
* sleep. A static body can, because nothing ever takes it out of this set, so
|
|
608
|
+
* its per-step inputs are dropped here instead - at the same point in the step
|
|
609
|
+
* the finalize pass used to, after the island pass has read the teleport flag.
|
|
610
|
+
*/
|
|
611
|
+
_collectSteppedBodies() {
|
|
612
|
+
const stepped = this._steppedBodies;
|
|
613
|
+
stepped.length = 0;
|
|
614
|
+
for (const body of this._bodies) if (body.type === "static") body._clearStepInputs();
|
|
615
|
+
else if (!body.isSleeping) stepped.push(body);
|
|
616
|
+
return stepped;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
526
619
|
* Link a body to a scene node; the node tracks the body after each step.
|
|
527
620
|
* Destroying the node is enough to end the link - the next step drops it
|
|
528
621
|
* rather than writing into the node's released transform, so an explicit
|
|
@@ -574,6 +667,7 @@ var PhysicsWorld = class {
|
|
|
574
667
|
this._colliders.length = 0;
|
|
575
668
|
this._detectionColliders.length = 0;
|
|
576
669
|
this._joints.length = 0;
|
|
670
|
+
this._uncollidableJointPairs.clear();
|
|
577
671
|
this._commands.length = 0;
|
|
578
672
|
this._bindings.clear();
|
|
579
673
|
this._backend.destroy();
|
|
@@ -582,9 +676,11 @@ var PhysicsWorld = class {
|
|
|
582
676
|
this.onSensorEnter.destroy();
|
|
583
677
|
this.onSensorExit.destroy();
|
|
584
678
|
}
|
|
679
|
+
/** @internal */
|
|
585
680
|
_allocateColliderId() {
|
|
586
681
|
return this._nextColliderId++;
|
|
587
682
|
}
|
|
683
|
+
/** @internal */
|
|
588
684
|
_registerCollider(collider) {
|
|
589
685
|
this._defer(() => {
|
|
590
686
|
if (collider.destroyed) return;
|
|
@@ -619,27 +715,31 @@ var PhysicsWorld = class {
|
|
|
619
715
|
* any member does (e.g. an awake body merges into it via a new contact).
|
|
620
716
|
* A boundary that is itself moving resets the sleep timer of every dynamic
|
|
621
717
|
* body it touches, so a platform keeps its passengers awake however slowly it
|
|
622
|
-
* travels; so does a contact
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
* set is id-sorted.
|
|
718
|
+
* travels; so does a contact whose overlap the push-out is still working off,
|
|
719
|
+
* because that push-out moves bodies without showing up in their velocity and
|
|
720
|
+
* a body would otherwise be frozen embedded. Deterministic: union-find roots
|
|
721
|
+
* break ties by lower index and the contact set is id-sorted.
|
|
627
722
|
*/
|
|
628
723
|
_updateSleeping(dt) {
|
|
629
724
|
const bodies = this._bodies;
|
|
630
725
|
const count = bodies.length;
|
|
631
726
|
const parent = this._islandParent;
|
|
632
727
|
const minSleep = this._islandMinSleep;
|
|
728
|
+
const timeToSleep = this.timeToSleep;
|
|
729
|
+
let settled = true;
|
|
633
730
|
for (let i = 0; i < count; i++) {
|
|
634
731
|
const body = bodies[i];
|
|
635
732
|
body._islandIndex = i;
|
|
636
733
|
parent[i] = i;
|
|
637
734
|
minSleep[i] = Infinity;
|
|
638
|
-
if (body.type === "dynamic" && !body.isSleeping)
|
|
735
|
+
if (body.type === "dynamic" && !body.isSleeping) {
|
|
736
|
+
body._accumulateSleepTime(dt, this.sleepLinearVelocity, this.sleepAngularVelocity);
|
|
737
|
+
settled = false;
|
|
738
|
+
}
|
|
639
739
|
}
|
|
640
740
|
parent.length = count;
|
|
641
741
|
minSleep.length = count;
|
|
642
|
-
this._unionContactIslands();
|
|
742
|
+
if (!this._unionContactIslands(dt) && settled) return;
|
|
643
743
|
for (const joint of this._joints) {
|
|
644
744
|
const bodyA = joint.bodyA;
|
|
645
745
|
const bodyB = joint.bodyB;
|
|
@@ -652,7 +752,6 @@ var PhysicsWorld = class {
|
|
|
652
752
|
if (body._sleepTime < minSleep[root]) minSleep[root] = body._sleepTime;
|
|
653
753
|
}
|
|
654
754
|
}
|
|
655
|
-
const timeToSleep = this.timeToSleep;
|
|
656
755
|
for (let i = 0; i < count; i++) {
|
|
657
756
|
const body = bodies[i];
|
|
658
757
|
if (body.type === "dynamic") body._setSleeping(minSleep[this._find(i)] >= timeToSleep);
|
|
@@ -665,12 +764,15 @@ var PhysicsWorld = class {
|
|
|
665
764
|
* of a slow-moving platform awake - and the solver skips a contact whose
|
|
666
765
|
* dynamic side is asleep, letting the platform drive straight through it.
|
|
667
766
|
*
|
|
668
|
-
* The same traversal resets the sleep timer of both sides of a contact
|
|
669
|
-
*
|
|
670
|
-
* stays awake until the overlap
|
|
671
|
-
*
|
|
767
|
+
* The same traversal resets the sleep timer of both sides of a contact the
|
|
768
|
+
* push-out is still working off (see {@link isUnresolved}), so the island it
|
|
769
|
+
* belongs to stays awake until the overlap has reached the depth the contact's
|
|
770
|
+
* own load holds it at.
|
|
771
|
+
*
|
|
772
|
+
* Returns whether any sleep timer was reset.
|
|
672
773
|
*/
|
|
673
|
-
_unionContactIslands() {
|
|
774
|
+
_unionContactIslands(dt) {
|
|
775
|
+
let reset = false;
|
|
674
776
|
for (const contact of this._backend.contactGraph.solidContacts) {
|
|
675
777
|
if (!contact.enabled) continue;
|
|
676
778
|
const bodyA = contact.a.body;
|
|
@@ -678,13 +780,20 @@ var PhysicsWorld = class {
|
|
|
678
780
|
const dynamicA = bodyA.type === "dynamic";
|
|
679
781
|
const dynamicB = bodyB.type === "dynamic";
|
|
680
782
|
if (dynamicA && dynamicB) this._union(bodyA._islandIndex, bodyB._islandIndex);
|
|
681
|
-
else if (dynamicA && isMovingBoundary(bodyB))
|
|
682
|
-
|
|
683
|
-
|
|
783
|
+
else if (dynamicA && isMovingBoundary(bodyB)) {
|
|
784
|
+
bodyA._sleepTime = 0;
|
|
785
|
+
reset = true;
|
|
786
|
+
} else if (dynamicB && isMovingBoundary(bodyA)) {
|
|
787
|
+
bodyB._sleepTime = 0;
|
|
788
|
+
reset = true;
|
|
789
|
+
}
|
|
790
|
+
if ((dynamicA || dynamicB) && isUnresolved(contact, dt)) {
|
|
684
791
|
if (dynamicA) bodyA._sleepTime = 0;
|
|
685
792
|
if (dynamicB) bodyB._sleepTime = 0;
|
|
793
|
+
reset = true;
|
|
686
794
|
}
|
|
687
795
|
}
|
|
796
|
+
return reset;
|
|
688
797
|
}
|
|
689
798
|
/** Union-find union by lower index (deterministic roots). */
|
|
690
799
|
_union(a, b) {
|
|
@@ -703,17 +812,23 @@ var PhysicsWorld = class {
|
|
|
703
812
|
}
|
|
704
813
|
return index;
|
|
705
814
|
}
|
|
706
|
-
/** Build each joint's per-frame constraint data (once per fixed step). */
|
|
707
|
-
_prepareJoints(h) {
|
|
708
|
-
|
|
815
|
+
/** Build each joint's per-frame constraint data and collect the active ones (once per fixed step). */
|
|
816
|
+
_prepareJoints(h, contactHertz, dampingRatio) {
|
|
817
|
+
const rigid = softConstraint(2 * contactHertz, dampingRatio, h);
|
|
818
|
+
const active = this._activeJoints;
|
|
819
|
+
active.length = 0;
|
|
820
|
+
for (const joint of this._joints) {
|
|
821
|
+
joint._prepare(h, rigid);
|
|
822
|
+
if (joint._active) active.push(joint);
|
|
823
|
+
}
|
|
709
824
|
}
|
|
710
|
-
/** Re-apply each joint's accumulated impulse (each sub-step). */
|
|
825
|
+
/** Re-apply each active joint's accumulated impulse (each sub-step). */
|
|
711
826
|
_warmStartJoints() {
|
|
712
|
-
for (const joint of this.
|
|
827
|
+
for (const joint of this._activeJoints) joint._warmStart();
|
|
713
828
|
}
|
|
714
|
-
/** One joint velocity pass (each sub-step, after the contacts). */
|
|
829
|
+
/** One joint velocity pass over the active joints (each sub-step, after the contacts). */
|
|
715
830
|
_solveJoints(useBias) {
|
|
716
|
-
for (const joint of this.
|
|
831
|
+
for (const joint of this._activeJoints) joint._solve(useBias);
|
|
717
832
|
}
|
|
718
833
|
/** Whether any dynamic body is flagged for continuous collision (bullet mode). */
|
|
719
834
|
_hasBullets() {
|
|
@@ -794,7 +909,7 @@ var PhysicsWorld = class {
|
|
|
794
909
|
this._ccdBroadPhaseCandidates += candidates.length;
|
|
795
910
|
for (const other of candidates) {
|
|
796
911
|
const target = authoredCollider(other);
|
|
797
|
-
if (target.isSensor || other.body === body || !shouldCollide(collider.filter, target.filter)) continue;
|
|
912
|
+
if (target.isSensor || other.body === body || !shouldCollide(collider.filter, target.filter) || this._uncollidableJointPairs.has(bodyPairKey(body.id, other.body.id))) continue;
|
|
798
913
|
if (!aabbOverlap(swept, other.aabb)) continue;
|
|
799
914
|
this._ccdSweepTests++;
|
|
800
915
|
if (sweepProxies(collider, dx, dy, other, hit) && hit.t < best.t) {
|
|
@@ -833,10 +948,21 @@ var PhysicsWorld = class {
|
|
|
833
948
|
this._teardownBody(body);
|
|
834
949
|
}
|
|
835
950
|
_teardownBody(body) {
|
|
951
|
+
this._removeJointsOf(body);
|
|
836
952
|
for (const collider of body.colliders) this._detachCollider(collider);
|
|
837
953
|
this._bindings.unbind(body);
|
|
838
954
|
body._markDestroyed();
|
|
839
955
|
}
|
|
956
|
+
/** Drop every joint incident to `body`, releasing the pair claims they held. */
|
|
957
|
+
_removeJointsOf(body) {
|
|
958
|
+
for (let index = this._joints.length - 1; index >= 0; index -= 1) {
|
|
959
|
+
const joint = this._joints[index];
|
|
960
|
+
if (joint === void 0 || joint.bodyA !== body && joint.bodyB !== body) continue;
|
|
961
|
+
this._joints.splice(index, 1);
|
|
962
|
+
this._holdPairApart(joint, -1);
|
|
963
|
+
(joint.bodyA === body ? joint.bodyB : joint.bodyA).wake();
|
|
964
|
+
}
|
|
965
|
+
}
|
|
840
966
|
_removeCollider(collider) {
|
|
841
967
|
this._detachCollider(collider);
|
|
842
968
|
collider.body._removeCollider(collider);
|