@codexo/exojs-physics 0.19.1 → 0.20.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 +8 -73
- package/{dist/esm/debug/index.d.ts → debug.d.ts} +1 -2
- package/debug.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +17 -23
- package/dist/esm/Aabb.d.ts +0 -10
- package/dist/esm/Aabb.d.ts.map +0 -1
- package/dist/esm/Aabb.js +0 -16
- package/dist/esm/Aabb.js.map +0 -1
- package/dist/esm/Collider.d.ts +0 -107
- package/dist/esm/Collider.d.ts.map +0 -1
- package/dist/esm/Collider.js +0 -284
- package/dist/esm/Collider.js.map +0 -1
- package/dist/esm/ContactGraph.d.ts +0 -154
- package/dist/esm/ContactGraph.d.ts.map +0 -1
- package/dist/esm/ContactGraph.js +0 -383
- package/dist/esm/ContactGraph.js.map +0 -1
- package/dist/esm/ContactModifier.d.ts +0 -62
- package/dist/esm/ContactModifier.d.ts.map +0 -1
- package/dist/esm/ContactModifier.js +0 -49
- package/dist/esm/ContactModifier.js.map +0 -1
- package/dist/esm/PhysicsBody.d.ts +0 -186
- package/dist/esm/PhysicsBody.d.ts.map +0 -1
- package/dist/esm/PhysicsBody.js +0 -526
- package/dist/esm/PhysicsBody.js.map +0 -1
- package/dist/esm/PhysicsBodyComponent.d.ts +0 -45
- package/dist/esm/PhysicsBodyComponent.d.ts.map +0 -1
- package/dist/esm/PhysicsBodyComponent.js +0 -77
- package/dist/esm/PhysicsBodyComponent.js.map +0 -1
- package/dist/esm/PhysicsWorld.d.ts +0 -567
- package/dist/esm/PhysicsWorld.d.ts.map +0 -1
- package/dist/esm/PhysicsWorld.js +0 -1096
- package/dist/esm/PhysicsWorld.js.map +0 -1
- package/dist/esm/TimeStepper.d.ts +0 -40
- package/dist/esm/TimeStepper.d.ts.map +0 -1
- package/dist/esm/TimeStepper.js +0 -59
- package/dist/esm/TimeStepper.js.map +0 -1
- package/dist/esm/backend/NativePhysicsBackend.d.ts +0 -28
- package/dist/esm/backend/NativePhysicsBackend.d.ts.map +0 -1
- package/dist/esm/backend/NativePhysicsBackend.js +0 -52
- package/dist/esm/backend/NativePhysicsBackend.js.map +0 -1
- package/dist/esm/backend/PhysicsBackend.d.ts +0 -38
- package/dist/esm/backend/PhysicsBackend.d.ts.map +0 -1
- package/dist/esm/binding/BindingRegistry.d.ts +0 -48
- package/dist/esm/binding/BindingRegistry.d.ts.map +0 -1
- package/dist/esm/binding/BindingRegistry.js +0 -81
- package/dist/esm/binding/BindingRegistry.js.map +0 -1
- package/dist/esm/binding/PhysicsBinding.d.ts +0 -37
- package/dist/esm/binding/PhysicsBinding.d.ts.map +0 -1
- package/dist/esm/binding/PhysicsBinding.js +0 -54
- package/dist/esm/binding/PhysicsBinding.js.map +0 -1
- package/dist/esm/binding/nodeWorldTransform.d.ts +0 -18
- package/dist/esm/binding/nodeWorldTransform.d.ts.map +0 -1
- package/dist/esm/binding/nodeWorldTransform.js +0 -41
- package/dist/esm/binding/nodeWorldTransform.js.map +0 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +0 -84
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +0 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.js +0 -183
- package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +0 -1
- package/dist/esm/broadphase/BroadPhase.d.ts +0 -25
- package/dist/esm/broadphase/BroadPhase.d.ts.map +0 -1
- package/dist/esm/broadphase/index.d.ts +0 -3
- package/dist/esm/broadphase/index.d.ts.map +0 -1
- package/dist/esm/collision/CollisionProxy.d.ts +0 -15
- package/dist/esm/collision/CollisionProxy.d.ts.map +0 -1
- package/dist/esm/collision/Manifold.d.ts +0 -34
- package/dist/esm/collision/Manifold.d.ts.map +0 -1
- package/dist/esm/collision/Manifold.js +0 -37
- package/dist/esm/collision/Manifold.js.map +0 -1
- package/dist/esm/collision/chainAdjacency.d.ts +0 -2
- package/dist/esm/collision/chainAdjacency.d.ts.map +0 -1
- package/dist/esm/collision/chainAdjacency.js +0 -44
- package/dist/esm/collision/chainAdjacency.js.map +0 -1
- package/dist/esm/collision/dispatch.d.ts +0 -35
- package/dist/esm/collision/dispatch.d.ts.map +0 -1
- package/dist/esm/collision/dispatch.js +0 -58
- package/dist/esm/collision/dispatch.js.map +0 -1
- package/dist/esm/collision/index.d.ts +0 -5
- package/dist/esm/collision/index.d.ts.map +0 -1
- package/dist/esm/collision/narrowphase.d.ts +0 -17
- package/dist/esm/collision/narrowphase.d.ts.map +0 -1
- package/dist/esm/collision/narrowphase.js +0 -555
- package/dist/esm/collision/narrowphase.js.map +0 -1
- package/dist/esm/collision/segments.d.ts +0 -19
- package/dist/esm/collision/segments.d.ts.map +0 -1
- package/dist/esm/collision/segments.js +0 -36
- package/dist/esm/collision/segments.js.map +0 -1
- package/dist/esm/collision/sweep.d.ts +0 -35
- package/dist/esm/collision/sweep.d.ts.map +0 -1
- package/dist/esm/collision/sweep.js +0 -437
- package/dist/esm/collision/sweep.js.map +0 -1
- package/dist/esm/debug/PhysicsDebugDraw.d.ts +0 -72
- package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +0 -1
- package/dist/esm/debug/PhysicsDebugDraw.js +0 -239
- package/dist/esm/debug/PhysicsDebugDraw.js.map +0 -1
- package/dist/esm/debug/index.d.ts.map +0 -1
- package/dist/esm/debug/index.js +0 -3
- package/dist/esm/events.d.ts +0 -36
- package/dist/esm/events.d.ts.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -25
- package/dist/esm/joints/DistanceJoint.d.ts +0 -70
- package/dist/esm/joints/DistanceJoint.d.ts.map +0 -1
- package/dist/esm/joints/DistanceJoint.js +0 -167
- package/dist/esm/joints/DistanceJoint.js.map +0 -1
- package/dist/esm/joints/Joint.d.ts +0 -76
- package/dist/esm/joints/Joint.d.ts.map +0 -1
- package/dist/esm/joints/Joint.js +0 -62
- package/dist/esm/joints/Joint.js.map +0 -1
- package/dist/esm/joints/MouseJoint.d.ts +0 -55
- package/dist/esm/joints/MouseJoint.d.ts.map +0 -1
- package/dist/esm/joints/MouseJoint.js +0 -139
- package/dist/esm/joints/MouseJoint.js.map +0 -1
- package/dist/esm/joints/PrismaticJoint.d.ts +0 -84
- package/dist/esm/joints/PrismaticJoint.d.ts.map +0 -1
- package/dist/esm/joints/PrismaticJoint.js +0 -218
- package/dist/esm/joints/PrismaticJoint.js.map +0 -1
- package/dist/esm/joints/RevoluteJoint.d.ts +0 -77
- package/dist/esm/joints/RevoluteJoint.d.ts.map +0 -1
- package/dist/esm/joints/RevoluteJoint.js +0 -204
- package/dist/esm/joints/RevoluteJoint.js.map +0 -1
- package/dist/esm/joints/WeldJoint.d.ts +0 -60
- package/dist/esm/joints/WeldJoint.d.ts.map +0 -1
- package/dist/esm/joints/WeldJoint.js +0 -166
- package/dist/esm/joints/WeldJoint.js.map +0 -1
- package/dist/esm/joints/WheelJoint.d.ts +0 -91
- package/dist/esm/joints/WheelJoint.d.ts.map +0 -1
- package/dist/esm/joints/WheelJoint.js +0 -235
- package/dist/esm/joints/WheelJoint.js.map +0 -1
- package/dist/esm/math.d.ts +0 -29
- package/dist/esm/math.d.ts.map +0 -1
- package/dist/esm/math.js +0 -60
- package/dist/esm/math.js.map +0 -1
- package/dist/esm/physicsBuildInfo.d.ts +0 -16
- package/dist/esm/physicsBuildInfo.d.ts.map +0 -1
- package/dist/esm/physicsBuildInfo.js +0 -10
- package/dist/esm/physicsBuildInfo.js.map +0 -1
- package/dist/esm/public.d.ts +0 -34
- package/dist/esm/public.d.ts.map +0 -1
- package/dist/esm/query/QueryEngine.d.ts +0 -95
- package/dist/esm/query/QueryEngine.d.ts.map +0 -1
- package/dist/esm/query/QueryEngine.js +0 -512
- package/dist/esm/query/QueryEngine.js.map +0 -1
- package/dist/esm/query/SpatialIndex.d.ts +0 -34
- package/dist/esm/query/SpatialIndex.d.ts.map +0 -1
- package/dist/esm/shapes/AnyShape.d.ts +0 -14
- package/dist/esm/shapes/AnyShape.d.ts.map +0 -1
- package/dist/esm/shapes/BoxShape.d.ts +0 -12
- package/dist/esm/shapes/BoxShape.d.ts.map +0 -1
- package/dist/esm/shapes/BoxShape.js +0 -41
- package/dist/esm/shapes/BoxShape.js.map +0 -1
- package/dist/esm/shapes/CapsuleShape.d.ts +0 -30
- package/dist/esm/shapes/CapsuleShape.d.ts.map +0 -1
- package/dist/esm/shapes/CapsuleShape.js +0 -88
- package/dist/esm/shapes/CapsuleShape.js.map +0 -1
- package/dist/esm/shapes/ChainEdgeShape.d.ts +0 -2
- package/dist/esm/shapes/ChainEdgeShape.d.ts.map +0 -1
- package/dist/esm/shapes/ChainEdgeShape.js +0 -66
- package/dist/esm/shapes/ChainEdgeShape.js.map +0 -1
- package/dist/esm/shapes/ChainShape.d.ts +0 -46
- package/dist/esm/shapes/ChainShape.d.ts.map +0 -1
- package/dist/esm/shapes/ChainShape.js +0 -85
- package/dist/esm/shapes/ChainShape.js.map +0 -1
- package/dist/esm/shapes/CircleShape.d.ts +0 -14
- package/dist/esm/shapes/CircleShape.d.ts.map +0 -1
- package/dist/esm/shapes/CircleShape.js +0 -31
- package/dist/esm/shapes/CircleShape.js.map +0 -1
- package/dist/esm/shapes/PolygonShape.d.ts +0 -24
- package/dist/esm/shapes/PolygonShape.d.ts.map +0 -1
- package/dist/esm/shapes/PolygonShape.js +0 -153
- package/dist/esm/shapes/PolygonShape.js.map +0 -1
- package/dist/esm/shapes/SegmentShape.d.ts +0 -31
- package/dist/esm/shapes/SegmentShape.d.ts.map +0 -1
- package/dist/esm/shapes/SegmentShape.js +0 -62
- package/dist/esm/shapes/SegmentShape.js.map +0 -1
- package/dist/esm/shapes/Shape.d.ts +0 -37
- package/dist/esm/shapes/Shape.d.ts.map +0 -1
- package/dist/esm/shapes/Shape.js +0 -15
- package/dist/esm/shapes/Shape.js.map +0 -1
- package/dist/esm/shapes/convexParts.d.ts +0 -21
- package/dist/esm/shapes/convexParts.d.ts.map +0 -1
- package/dist/esm/shapes/convexParts.js +0 -26
- package/dist/esm/shapes/convexParts.js.map +0 -1
- package/dist/esm/shapes/decompose.d.ts +0 -2
- package/dist/esm/shapes/decompose.d.ts.map +0 -1
- package/dist/esm/shapes/decompose.js +0 -272
- package/dist/esm/shapes/decompose.js.map +0 -1
- package/dist/esm/shapes/index.d.ts +0 -9
- package/dist/esm/shapes/index.d.ts.map +0 -1
- package/dist/esm/solver/ContactSolver.d.ts +0 -94
- package/dist/esm/solver/ContactSolver.d.ts.map +0 -1
- package/dist/esm/solver/ContactSolver.js +0 -457
- package/dist/esm/solver/ContactSolver.js.map +0 -1
- package/dist/esm/solver/tolerances.d.ts +0 -2
- package/dist/esm/solver/tolerances.d.ts.map +0 -1
- package/dist/esm/solver/tolerances.js +0 -36
- package/dist/esm/solver/tolerances.js.map +0 -1
- package/dist/esm/sort.d.ts +0 -2
- package/dist/esm/sort.d.ts.map +0 -1
- package/dist/esm/sort.js +0 -44
- package/dist/esm/sort.js.map +0 -1
- package/dist/esm/types.d.ts +0 -35
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -26
- package/dist/esm/types.js.map +0 -1
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { PhysicsBody } from '../PhysicsBody';
|
|
2
|
-
/**
|
|
3
|
-
* Soft-constraint factors for one sub-step, as the solver's "soft step" uses
|
|
4
|
-
* them: how fast a position error is turned into a bias velocity, how much of
|
|
5
|
-
* the solved impulse is applied, and how much of the accumulated impulse is
|
|
6
|
-
* relaxed away again.
|
|
7
|
-
*/
|
|
8
|
-
export interface JointSoftness {
|
|
9
|
-
readonly biasRate: number;
|
|
10
|
-
readonly massScale: number;
|
|
11
|
-
readonly impulseScale: number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Soft factors for a constraint of `hertz` stiffness at `dampingRatio`, over a
|
|
15
|
-
* sub-step of `h` seconds.
|
|
16
|
-
*
|
|
17
|
-
* The same formulation the contact solver uses. A joint asked for no stiffness
|
|
18
|
-
* of its own still gets these rather than a raw Baumgarte term: an unscaled
|
|
19
|
-
* `0.2 / h` bias applies the full position correction as a velocity every
|
|
20
|
-
* sub-step and relaxes none of the impulse it accumulated, which a single joint
|
|
21
|
-
* absorbs and a serial chain does not - each link hands its neighbour an
|
|
22
|
-
* over-correction that the next sub-step corrects again.
|
|
23
|
-
*/
|
|
24
|
-
export declare const softConstraint: (hertz: number, dampingRatio: number, h: number) => JointSoftness;
|
|
25
|
-
/** Options every joint accepts, whatever it constrains. */
|
|
26
|
-
export interface JointOptions {
|
|
27
|
-
/**
|
|
28
|
-
* Whether the two bodies this joint connects also collide with each other.
|
|
29
|
-
* Default `true`.
|
|
30
|
-
*
|
|
31
|
-
* `false` is what a chain, a ragdoll, a pendulum or a vehicle assembly
|
|
32
|
-
* usually wants, and what Box2D defaults to: a joint already decides how its
|
|
33
|
-
* two bodies may move relative to one another, so letting their touching
|
|
34
|
-
* colliders push each other apart at the same time gives the pair two
|
|
35
|
-
* constraint systems with different opinions, plus a contact per link that
|
|
36
|
-
* nothing needs.
|
|
37
|
-
*
|
|
38
|
-
* The default is nevertheless `true`, which is the behaviour every joint has
|
|
39
|
-
* had so far: an existing scene built against it would change shape under an
|
|
40
|
-
* update that flipped it. Nothing else argues for `true` any more - a chain
|
|
41
|
-
* of seven links and up used to gain energy without these contacts, and that
|
|
42
|
-
* defect is fixed in the joint solver rather than damped by them - so the
|
|
43
|
-
* default is a compatibility choice and is free to be revisited.
|
|
44
|
-
*
|
|
45
|
-
* Nothing about a contact is weakened under `true`: the narrow phase
|
|
46
|
-
* produces it, the contact graph holds it, collision events fire, a
|
|
47
|
-
* {@link ContactModifier} sees it and the solver resolves it, exactly as for
|
|
48
|
-
* any unjointed pair.
|
|
49
|
-
*
|
|
50
|
-
* It is fixed at construction, and it follows the joint's presence in the
|
|
51
|
-
* world rather than {@link Joint.enabled}: disabling a joint suspends its
|
|
52
|
-
* constraint, and a ragdoll whose joints are momentarily disabled must not
|
|
53
|
-
* start pushing its own limbs apart. Removing the joint from the world does
|
|
54
|
-
* let the pair collide again, and both bodies are woken so they respond to it.
|
|
55
|
-
*/
|
|
56
|
-
collideConnected?: boolean;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Base class for a two-body constraint solved alongside contacts in the
|
|
60
|
-
* sub-step loop. Concrete joints (distance, revolute, weld) implement the
|
|
61
|
-
* three solver hooks; the world owns the joint list and drives them, and joins
|
|
62
|
-
* the two bodies into one sleep island so a jointed pair sleeps and wakes
|
|
63
|
-
* together.
|
|
64
|
-
*/
|
|
65
|
-
export declare abstract class Joint {
|
|
66
|
-
/** First constrained body. */
|
|
67
|
-
readonly bodyA: PhysicsBody;
|
|
68
|
-
/** Second constrained body. */
|
|
69
|
-
readonly bodyB: PhysicsBody;
|
|
70
|
-
/** Whether {@link bodyA} and {@link bodyB} also collide with each other; see {@link JointOptions.collideConnected}. */
|
|
71
|
-
readonly collideConnected: boolean;
|
|
72
|
-
/** When `false`, the joint is skipped by the solver (but still tracked by the world). */
|
|
73
|
-
enabled: boolean;
|
|
74
|
-
protected constructor(bodyA: PhysicsBody, bodyB: PhysicsBody, collideConnected?: boolean);
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=Joint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Joint.d.ts","sourceRoot":"","sources":["../../../src/joints/Joint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,UAAW,MAAM,gBAAgB,MAAM,KAAK,MAAM,KAAG,aAW/E,CAAC;AAEF,2DAA2D;AAC3D,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,8BAAsB,KAAK;IACzB,8BAA8B;IAC9B,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,+BAA+B;IAC/B,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,uHAAuH;IACvH,SAAgB,gBAAgB,EAAE,OAAO,CAAC;IAC1C,yFAAyF;IAClF,OAAO,UAAQ;IAWtB,SAAS,aAAa,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,gBAAgB,UAAO,EAIpF;CAYF"}
|
package/dist/esm/joints/Joint.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
//#region src/joints/Joint.ts
|
|
2
|
-
/**
|
|
3
|
-
* Soft factors for a constraint of `hertz` stiffness at `dampingRatio`, over a
|
|
4
|
-
* sub-step of `h` seconds.
|
|
5
|
-
*
|
|
6
|
-
* The same formulation the contact solver uses. A joint asked for no stiffness
|
|
7
|
-
* of its own still gets these rather than a raw Baumgarte term: an unscaled
|
|
8
|
-
* `0.2 / h` bias applies the full position correction as a velocity every
|
|
9
|
-
* sub-step and relaxes none of the impulse it accumulated, which a single joint
|
|
10
|
-
* absorbs and a serial chain does not - each link hands its neighbour an
|
|
11
|
-
* over-correction that the next sub-step corrects again.
|
|
12
|
-
*/
|
|
13
|
-
const softConstraint = (hertz, dampingRatio, h) => {
|
|
14
|
-
if (hertz <= 0) return {
|
|
15
|
-
biasRate: 0,
|
|
16
|
-
massScale: 1,
|
|
17
|
-
impulseScale: 0
|
|
18
|
-
};
|
|
19
|
-
const omega = 2 * Math.PI * hertz;
|
|
20
|
-
const a1 = 2 * dampingRatio + h * omega;
|
|
21
|
-
const a2 = h * omega * a1;
|
|
22
|
-
const a3 = 1 / (1 + a2);
|
|
23
|
-
return {
|
|
24
|
-
biasRate: omega / a1,
|
|
25
|
-
massScale: a2 * a3,
|
|
26
|
-
impulseScale: a3
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Base class for a two-body constraint solved alongside contacts in the
|
|
31
|
-
* sub-step loop. Concrete joints (distance, revolute, weld) implement the
|
|
32
|
-
* three solver hooks; the world owns the joint list and drives them, and joins
|
|
33
|
-
* the two bodies into one sleep island so a jointed pair sleeps and wakes
|
|
34
|
-
* together.
|
|
35
|
-
*/
|
|
36
|
-
var Joint = class {
|
|
37
|
-
/** First constrained body. */
|
|
38
|
-
bodyA;
|
|
39
|
-
/** Second constrained body. */
|
|
40
|
-
bodyB;
|
|
41
|
-
/** Whether {@link bodyA} and {@link bodyB} also collide with each other; see {@link JointOptions.collideConnected}. */
|
|
42
|
-
collideConnected;
|
|
43
|
-
/** When `false`, the joint is skipped by the solver (but still tracked by the world). */
|
|
44
|
-
enabled = true;
|
|
45
|
-
/**
|
|
46
|
-
* @internal - whether this joint solves this frame. Set in {@link _prepare}
|
|
47
|
-
* (disabled, sleeping or two static bodies → `false`), and read by the world
|
|
48
|
-
* right after it to collect the joints the sub-steps actually have to touch.
|
|
49
|
-
* A subclass may still clear it inside `_prepare` once it knows there is
|
|
50
|
-
* nothing to solve (a slack rope limit, say).
|
|
51
|
-
*/
|
|
52
|
-
_active = false;
|
|
53
|
-
constructor(bodyA, bodyB, collideConnected = true) {
|
|
54
|
-
this.bodyA = bodyA;
|
|
55
|
-
this.bodyB = bodyB;
|
|
56
|
-
this.collideConnected = collideConnected;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
//#endregion
|
|
61
|
-
export { Joint, softConstraint };
|
|
62
|
-
//# sourceMappingURL=Joint.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Joint.js","names":[],"sources":["../../../src/joints/Joint.ts"],"sourcesContent":["import type { PhysicsBody } from '../PhysicsBody';\n\n/**\n * Soft-constraint factors for one sub-step, as the solver's \"soft step\" uses\n * them: how fast a position error is turned into a bias velocity, how much of\n * the solved impulse is applied, and how much of the accumulated impulse is\n * relaxed away again.\n */\nexport interface JointSoftness {\n readonly biasRate: number;\n readonly massScale: number;\n readonly impulseScale: number;\n}\n\n/**\n * Soft factors for a constraint of `hertz` stiffness at `dampingRatio`, over a\n * sub-step of `h` seconds.\n *\n * The same formulation the contact solver uses. A joint asked for no stiffness\n * of its own still gets these rather than a raw Baumgarte term: an unscaled\n * `0.2 / h` bias applies the full position correction as a velocity every\n * sub-step and relaxes none of the impulse it accumulated, which a single joint\n * absorbs and a serial chain does not - each link hands its neighbour an\n * over-correction that the next sub-step corrects again.\n */\nexport const softConstraint = (hertz: number, dampingRatio: number, h: number): JointSoftness => {\n if (hertz <= 0) {\n return { biasRate: 0, massScale: 1, impulseScale: 0 };\n }\n\n const omega = 2 * Math.PI * hertz;\n const a1 = 2 * dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n return { biasRate: omega / a1, massScale: a2 * a3, impulseScale: a3 };\n};\n\n/** Options every joint accepts, whatever it constrains. */\nexport interface JointOptions {\n /**\n * Whether the two bodies this joint connects also collide with each other.\n * Default `true`.\n *\n * `false` is what a chain, a ragdoll, a pendulum or a vehicle assembly\n * usually wants, and what Box2D defaults to: a joint already decides how its\n * two bodies may move relative to one another, so letting their touching\n * colliders push each other apart at the same time gives the pair two\n * constraint systems with different opinions, plus a contact per link that\n * nothing needs.\n *\n * The default is nevertheless `true`, which is the behaviour every joint has\n * had so far: an existing scene built against it would change shape under an\n * update that flipped it. Nothing else argues for `true` any more - a chain\n * of seven links and up used to gain energy without these contacts, and that\n * defect is fixed in the joint solver rather than damped by them - so the\n * default is a compatibility choice and is free to be revisited.\n *\n * Nothing about a contact is weakened under `true`: the narrow phase\n * produces it, the contact graph holds it, collision events fire, a\n * {@link ContactModifier} sees it and the solver resolves it, exactly as for\n * any unjointed pair.\n *\n * It is fixed at construction, and it follows the joint's presence in the\n * world rather than {@link Joint.enabled}: disabling a joint suspends its\n * constraint, and a ragdoll whose joints are momentarily disabled must not\n * start pushing its own limbs apart. Removing the joint from the world does\n * let the pair collide again, and both bodies are woken so they respond to it.\n */\n collideConnected?: boolean;\n}\n\n/**\n * Base class for a two-body constraint solved alongside contacts in the\n * sub-step loop. Concrete joints (distance, revolute, weld) implement the\n * three solver hooks; the world owns the joint list and drives them, and joins\n * the two bodies into one sleep island so a jointed pair sleeps and wakes\n * together.\n */\nexport abstract class Joint {\n /** First constrained body. */\n public readonly bodyA: PhysicsBody;\n /** Second constrained body. */\n public readonly bodyB: PhysicsBody;\n /** Whether {@link bodyA} and {@link bodyB} also collide with each other; see {@link JointOptions.collideConnected}. */\n public readonly collideConnected: boolean;\n /** When `false`, the joint is skipped by the solver (but still tracked by the world). */\n public enabled = true;\n\n /**\n * @internal - whether this joint solves this frame. Set in {@link _prepare}\n * (disabled, sleeping or two static bodies → `false`), and read by the world\n * right after it to collect the joints the sub-steps actually have to touch.\n * A subclass may still clear it inside `_prepare` once it knows there is\n * nothing to solve (a slack rope limit, say).\n */\n public _active = false;\n\n protected constructor(bodyA: PhysicsBody, bodyB: PhysicsBody, collideConnected = true) {\n this.bodyA = bodyA;\n this.bodyB = bodyB;\n this.collideConnected = collideConnected;\n }\n\n /**\n * @internal - build this frame's constraint data; called once per fixed step\n * after detection. `rigid` carries the solver's soft factors for a joint that\n * asks for no stiffness of its own.\n */\n public abstract _prepare(h: number, rigid: JointSoftness): void;\n /** @internal - re-apply the accumulated impulse; called each sub-step (TGS-Soft warm-start). */\n public abstract _warmStart(): void;\n /** @internal - one velocity pass; `useBias` is the soft-bias pass, `false` the relax pass. */\n public abstract _solve(useBias: boolean): void;\n}\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAa,kBAAkB,OAAe,cAAsB,MAA6B;CAC/F,IAAI,SAAS,GACX,OAAO;EAAE,UAAU;EAAG,WAAW;EAAG,cAAc;CAAE;CAGtD,MAAM,QAAQ,IAAI,KAAK,KAAK;CAC5B,MAAM,KAAK,IAAI,eAAe,IAAI;CAClC,MAAM,KAAK,IAAI,QAAQ;CACvB,MAAM,KAAK,KAAK,IAAI;CAEpB,OAAO;EAAE,UAAU,QAAQ;EAAI,WAAW,KAAK;EAAI,cAAc;CAAG;AACtE;;;;;;;;AA2CA,IAAsB,QAAtB,MAA4B;;CAE1B,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAO,UAAU;;;;;;;;CASjB,AAAO,UAAU;CAEjB,AAAU,YAAY,OAAoB,OAAoB,mBAAmB,MAAM;EACrF,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,mBAAmB;CAC1B;AAYF"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { PointLike } from '@codexo/exojs';
|
|
2
|
-
import { PhysicsBody } from '../PhysicsBody';
|
|
3
|
-
import { Joint } from './Joint';
|
|
4
|
-
/** Construction options for a {@link MouseJoint}. */
|
|
5
|
-
export interface MouseJointOptions {
|
|
6
|
-
/** The body to drag. */
|
|
7
|
-
body: PhysicsBody;
|
|
8
|
-
/** World point to pull the body toward - also the grab point on the body at creation. */
|
|
9
|
-
target: Readonly<PointLike>;
|
|
10
|
-
/** Soft-spring frequency in Hz (higher = snappier). Default `5`. */
|
|
11
|
-
hertz?: number;
|
|
12
|
-
/** Soft-spring damping ratio. Default `0.7`. */
|
|
13
|
-
dampingRatio?: number;
|
|
14
|
-
/** Maximum pulling force - clamps the per-step impulse so heavy bodies lag. Default `Infinity`. */
|
|
15
|
-
maxForce?: number;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Softly pulls a single body's grab point toward a movable **target** point
|
|
19
|
-
* (typically the mouse cursor). The grab point is fixed on the body at creation;
|
|
20
|
-
* update {@link target} each frame to drag. A soft constraint bounded by
|
|
21
|
-
* {@link maxForce} - solved in the sub-step loop, warm-started. Internally the
|
|
22
|
-
* "other" body is a private static ground sentinel, so this is a single-body
|
|
23
|
-
* constraint that touches only the dragged body.
|
|
24
|
-
*/
|
|
25
|
-
export declare class MouseJoint extends Joint {
|
|
26
|
-
/** Soft-spring frequency in Hz. */
|
|
27
|
-
hertz: number;
|
|
28
|
-
/** Soft-spring damping ratio. */
|
|
29
|
-
dampingRatio: number;
|
|
30
|
-
/** Maximum pulling force. */
|
|
31
|
-
maxForce: number;
|
|
32
|
-
private readonly _localAnchorX;
|
|
33
|
-
private readonly _localAnchorY;
|
|
34
|
-
private _targetX;
|
|
35
|
-
private _targetY;
|
|
36
|
-
private _rx;
|
|
37
|
-
private _ry;
|
|
38
|
-
private _cx;
|
|
39
|
-
private _cy;
|
|
40
|
-
private _invK11;
|
|
41
|
-
private _invK12;
|
|
42
|
-
private _invK22;
|
|
43
|
-
private _biasRate;
|
|
44
|
-
private _massScale;
|
|
45
|
-
private _impulseScale;
|
|
46
|
-
private _impulseX;
|
|
47
|
-
private _impulseY;
|
|
48
|
-
private _maxImpulse;
|
|
49
|
-
constructor(options: MouseJointOptions);
|
|
50
|
-
/** The world point the body is pulled toward. Reassigning wakes the body so a drag tracks live. */
|
|
51
|
-
get target(): Readonly<PointLike>;
|
|
52
|
-
set target(value: Readonly<PointLike>);
|
|
53
|
-
private _applyImpulse;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=MouseJoint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MouseJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/MouseJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAsB,MAAM,SAAS,CAAC;AAEpD,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC,wBAAwB;IACxB,IAAI,EAA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, applyTransform } from "../math.js";
|
|
2
|
-
import { Joint } from "./Joint.js";
|
|
3
|
-
import { PhysicsBody } from "../PhysicsBody.js";
|
|
4
|
-
|
|
5
|
-
//#region src/joints/MouseJoint.ts
|
|
6
|
-
/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */
|
|
7
|
-
const scratch = {
|
|
8
|
-
x: 0,
|
|
9
|
-
y: 0
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Softly pulls a single body's grab point toward a movable **target** point
|
|
13
|
-
* (typically the mouse cursor). The grab point is fixed on the body at creation;
|
|
14
|
-
* update {@link target} each frame to drag. A soft constraint bounded by
|
|
15
|
-
* {@link maxForce} - solved in the sub-step loop, warm-started. Internally the
|
|
16
|
-
* "other" body is a private static ground sentinel, so this is a single-body
|
|
17
|
-
* constraint that touches only the dragged body.
|
|
18
|
-
*/
|
|
19
|
-
var MouseJoint = class extends Joint {
|
|
20
|
-
/** Soft-spring frequency in Hz. */
|
|
21
|
-
hertz;
|
|
22
|
-
/** Soft-spring damping ratio. */
|
|
23
|
-
dampingRatio;
|
|
24
|
-
/** Maximum pulling force. */
|
|
25
|
-
maxForce;
|
|
26
|
-
_localAnchorX;
|
|
27
|
-
_localAnchorY;
|
|
28
|
-
_targetX;
|
|
29
|
-
_targetY;
|
|
30
|
-
_rx = 0;
|
|
31
|
-
_ry = 0;
|
|
32
|
-
_cx = 0;
|
|
33
|
-
_cy = 0;
|
|
34
|
-
_invK11 = 0;
|
|
35
|
-
_invK12 = 0;
|
|
36
|
-
_invK22 = 0;
|
|
37
|
-
_biasRate = 0;
|
|
38
|
-
_massScale = 1;
|
|
39
|
-
_impulseScale = 0;
|
|
40
|
-
_impulseX = 0;
|
|
41
|
-
_impulseY = 0;
|
|
42
|
-
_maxImpulse = 0;
|
|
43
|
-
constructor(options) {
|
|
44
|
-
super(new PhysicsBody({
|
|
45
|
-
type: "static",
|
|
46
|
-
position: options.target
|
|
47
|
-
}), options.body);
|
|
48
|
-
applyInverseTransform(options.body.transform, options.target.x, options.target.y, scratch);
|
|
49
|
-
this._localAnchorX = scratch.x;
|
|
50
|
-
this._localAnchorY = scratch.y;
|
|
51
|
-
this._targetX = options.target.x;
|
|
52
|
-
this._targetY = options.target.y;
|
|
53
|
-
this.hertz = options.hertz ?? 5;
|
|
54
|
-
this.dampingRatio = options.dampingRatio ?? .7;
|
|
55
|
-
this.maxForce = options.maxForce ?? Infinity;
|
|
56
|
-
}
|
|
57
|
-
/** The world point the body is pulled toward. Reassigning wakes the body so a drag tracks live. */
|
|
58
|
-
get target() {
|
|
59
|
-
return {
|
|
60
|
-
x: this._targetX,
|
|
61
|
-
y: this._targetY
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
set target(value) {
|
|
65
|
-
this._targetX = value.x;
|
|
66
|
-
this._targetY = value.y;
|
|
67
|
-
this.bodyB.wake();
|
|
68
|
-
}
|
|
69
|
-
/** @internal */
|
|
70
|
-
_prepare(h, _rigid) {
|
|
71
|
-
const body = this.bodyB;
|
|
72
|
-
this._active = this.enabled && !body.isSleeping && body.invMass > 0;
|
|
73
|
-
if (!this._active) return;
|
|
74
|
-
applyTransform(body.transform, this._localAnchorX, this._localAnchorY, scratch);
|
|
75
|
-
this._rx = scratch.x - body.worldCenterOfMassX;
|
|
76
|
-
this._ry = scratch.y - body.worldCenterOfMassY;
|
|
77
|
-
this._cx = scratch.x - this._targetX;
|
|
78
|
-
this._cy = scratch.y - this._targetY;
|
|
79
|
-
const m = body.invMass;
|
|
80
|
-
const i = body.invInertia;
|
|
81
|
-
const k11 = m + i * this._ry * this._ry;
|
|
82
|
-
const k12 = -i * this._rx * this._ry;
|
|
83
|
-
const k22 = m + i * this._rx * this._rx;
|
|
84
|
-
const det = k11 * k22 - k12 * k12;
|
|
85
|
-
const invDet = det !== 0 ? 1 / det : 0;
|
|
86
|
-
this._invK11 = invDet * k22;
|
|
87
|
-
this._invK12 = -invDet * k12;
|
|
88
|
-
this._invK22 = invDet * k11;
|
|
89
|
-
this._maxImpulse = this.maxForce * h;
|
|
90
|
-
const omega = 2 * Math.PI * this.hertz;
|
|
91
|
-
const a1 = 2 * this.dampingRatio + h * omega;
|
|
92
|
-
const a2 = h * omega * a1;
|
|
93
|
-
const a3 = 1 / (1 + a2);
|
|
94
|
-
this._biasRate = omega / a1;
|
|
95
|
-
this._massScale = a2 * a3;
|
|
96
|
-
this._impulseScale = a3;
|
|
97
|
-
}
|
|
98
|
-
/** @internal */
|
|
99
|
-
_warmStart() {
|
|
100
|
-
if (!this._active) return;
|
|
101
|
-
this._applyImpulse(this._impulseX, this._impulseY);
|
|
102
|
-
}
|
|
103
|
-
/** @internal */
|
|
104
|
-
_solve(useBias) {
|
|
105
|
-
if (!this._active) return;
|
|
106
|
-
const body = this.bodyB;
|
|
107
|
-
const cdotX = body.linearVelocityX - body.angularVelocity * this._ry;
|
|
108
|
-
const cdotY = body.linearVelocityY + body.angularVelocity * this._rx;
|
|
109
|
-
const rhsX = cdotX + (useBias ? this._biasRate * this._cx : 0);
|
|
110
|
-
const rhsY = cdotY + (useBias ? this._biasRate * this._cy : 0);
|
|
111
|
-
const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;
|
|
112
|
-
const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;
|
|
113
|
-
let impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;
|
|
114
|
-
let impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;
|
|
115
|
-
const oldX = this._impulseX;
|
|
116
|
-
const oldY = this._impulseY;
|
|
117
|
-
this._impulseX += impulseX;
|
|
118
|
-
this._impulseY += impulseY;
|
|
119
|
-
const magnitude = Math.hypot(this._impulseX, this._impulseY);
|
|
120
|
-
if (magnitude > this._maxImpulse) {
|
|
121
|
-
const scale = this._maxImpulse / magnitude;
|
|
122
|
-
this._impulseX *= scale;
|
|
123
|
-
this._impulseY *= scale;
|
|
124
|
-
}
|
|
125
|
-
impulseX = this._impulseX - oldX;
|
|
126
|
-
impulseY = this._impulseY - oldY;
|
|
127
|
-
this._applyImpulse(impulseX, impulseY);
|
|
128
|
-
}
|
|
129
|
-
_applyImpulse(jx, jy) {
|
|
130
|
-
const body = this.bodyB;
|
|
131
|
-
body.linearVelocityX += body.invMass * jx;
|
|
132
|
-
body.linearVelocityY += body.invMass * jy;
|
|
133
|
-
body.angularVelocity += body.invInertia * (this._rx * jy - this._ry * jx);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
//#endregion
|
|
138
|
-
export { MouseJoint };
|
|
139
|
-
//# sourceMappingURL=MouseJoint.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MouseJoint.js","names":[],"sources":["../../../src/joints/MouseJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport { PhysicsBody } from '../PhysicsBody';\nimport { Joint, type JointSoftness } from './Joint';\n\n/** Construction options for a {@link MouseJoint}. */\nexport interface MouseJointOptions {\n /** The body to drag. */\n body: PhysicsBody;\n /** World point to pull the body toward - also the grab point on the body at creation. */\n target: Readonly<PointLike>;\n /** Soft-spring frequency in Hz (higher = snappier). Default `5`. */\n hertz?: number;\n /** Soft-spring damping ratio. Default `0.7`. */\n dampingRatio?: number;\n /** Maximum pulling force - clamps the per-step impulse so heavy bodies lag. Default `Infinity`. */\n maxForce?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Softly pulls a single body's grab point toward a movable **target** point\n * (typically the mouse cursor). The grab point is fixed on the body at creation;\n * update {@link target} each frame to drag. A soft constraint bounded by\n * {@link maxForce} - solved in the sub-step loop, warm-started. Internally the\n * \"other\" body is a private static ground sentinel, so this is a single-body\n * constraint that touches only the dragged body.\n */\nexport class MouseJoint extends Joint {\n /** Soft-spring frequency in Hz. */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** Maximum pulling force. */\n public maxForce: number;\n\n private readonly _localAnchorX: number;\n private readonly _localAnchorY: number;\n private _targetX: number;\n private _targetY: number;\n\n private _rx = 0;\n private _ry = 0;\n private _cx = 0;\n private _cy = 0;\n private _invK11 = 0;\n private _invK12 = 0;\n private _invK22 = 0;\n private _biasRate = 0;\n private _massScale = 1;\n private _impulseScale = 0;\n private _impulseX = 0;\n private _impulseY = 0;\n private _maxImpulse = 0;\n\n public constructor(options: MouseJointOptions) {\n // Single-body constraint: a private static ground stands in for bodyA so the\n // island/solver machinery (which assumes two bodies) sees a static anchor that\n // it never integrates, unions or mutates.\n super(new PhysicsBody({ type: 'static', position: options.target }), options.body);\n\n applyInverseTransform(options.body.transform, options.target.x, options.target.y, scratch);\n this._localAnchorX = scratch.x;\n this._localAnchorY = scratch.y;\n this._targetX = options.target.x;\n this._targetY = options.target.y;\n\n this.hertz = options.hertz ?? 5;\n this.dampingRatio = options.dampingRatio ?? 0.7;\n this.maxForce = options.maxForce ?? Infinity;\n }\n\n /** The world point the body is pulled toward. Reassigning wakes the body so a drag tracks live. */\n public get target(): Readonly<PointLike> {\n return { x: this._targetX, y: this._targetY };\n }\n\n public set target(value: Readonly<PointLike>) {\n this._targetX = value.x;\n this._targetY = value.y;\n this.bodyB.wake();\n }\n\n /** @internal */\n public override _prepare(h: number, _rigid: JointSoftness): void {\n const body = this.bodyB;\n\n this._active = this.enabled && !body.isSleeping && body.invMass > 0;\n\n if (!this._active) {\n return;\n }\n\n applyTransform(body.transform, this._localAnchorX, this._localAnchorY, scratch);\n this._rx = scratch.x - body.worldCenterOfMassX;\n this._ry = scratch.y - body.worldCenterOfMassY;\n this._cx = scratch.x - this._targetX;\n this._cy = scratch.y - this._targetY;\n\n const m = body.invMass;\n const i = body.invInertia;\n\n // 2×2 effective-mass matrix K (only the dragged body contributes) and its inverse.\n const k11 = m + i * this._ry * this._ry;\n const k12 = -i * this._rx * this._ry;\n const k22 = m + i * this._rx * this._rx;\n const det = k11 * k22 - k12 * k12;\n const invDet = det !== 0 ? 1 / det : 0;\n\n this._invK11 = invDet * k22;\n this._invK12 = -invDet * k12;\n this._invK22 = invDet * k11;\n this._maxImpulse = this.maxForce * h;\n\n const omega = 2 * Math.PI * this.hertz;\n const a1 = 2 * this.dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n this._biasRate = omega / a1;\n this._massScale = a2 * a3;\n this._impulseScale = a3;\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n this._applyImpulse(this._impulseX, this._impulseY);\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const body = this.bodyB;\n\n // Velocity of the grab point.\n const cdotX = body.linearVelocityX - body.angularVelocity * this._ry;\n const cdotY = body.linearVelocityY + body.angularVelocity * this._rx;\n const rhsX = cdotX + (useBias ? this._biasRate * this._cx : 0);\n const rhsY = cdotY + (useBias ? this._biasRate * this._cy : 0);\n\n const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;\n const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;\n let impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;\n let impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;\n\n // Clamp the accumulated impulse magnitude to maxForce·h (a heavy body lags).\n const oldX = this._impulseX;\n const oldY = this._impulseY;\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n\n const magnitude = Math.hypot(this._impulseX, this._impulseY);\n\n if (magnitude > this._maxImpulse) {\n const scale = this._maxImpulse / magnitude;\n\n this._impulseX *= scale;\n this._impulseY *= scale;\n }\n\n impulseX = this._impulseX - oldX;\n impulseY = this._impulseY - oldY;\n this._applyImpulse(impulseX, impulseY);\n }\n\n private _applyImpulse(jx: number, jy: number): void {\n const body = this.bodyB;\n\n body.linearVelocityX += body.invMass * jx;\n body.linearVelocityY += body.invMass * jy;\n body.angularVelocity += body.invInertia * (this._rx * jy - this._ry * jx);\n }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AK,UAAU;EACrD,MAAM,UAAU,KAAK,UAAU,OAAO,KAAK,UAAU;EACrD,IAAI,WAAW,CAAC,KAAK,aAAa,UAAU,KAAK,gBAAgB,KAAK;EACtE,IAAI,WAAW,CAAC,KAAK,aAAa,UAAU,KAAK,gBAAgB,KAAK;EAGtE,MAAM,OAAO,KAAK;EAClB,MAAM,OAAO,KAAK;EAClB,KAAK,aAAa;EAClB,KAAK,aAAa;EAElB,MAAM,YAAY,KAAK,MAAM,KAAK,WAAW,KAAK,SAAS;EAE3D,IAAI,YAAY,KAAK,aAAa;GAChC,MAAM,QAAQ,KAAK,cAAc;GAEjC,KAAK,aAAa;GAClB,KAAK,aAAa;EACpB;EAEA,WAAW,KAAK,YAAY;EAC5B,WAAW,KAAK,YAAY;EAC5B,KAAK,cAAc,UAAU,QAAQ;CACvC;CAEA,AAAQ,cAAc,IAAY,IAAkB;EAClD,MAAM,OAAO,KAAK;EAElB,KAAK,mBAAmB,KAAK,UAAU;EACvC,KAAK,mBAAmB,KAAK,UAAU;EACvC,KAAK,mBAAmB,KAAK,cAAc,KAAK,MAAM,KAAK,KAAK,MAAM;CACxE;AACF"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { PointLike } from '@codexo/exojs';
|
|
2
|
-
import type { PhysicsBody } from '../PhysicsBody';
|
|
3
|
-
import type { JointOptions } from './Joint';
|
|
4
|
-
import { Joint } from './Joint';
|
|
5
|
-
/** Construction options for a {@link PrismaticJoint}. */
|
|
6
|
-
export interface PrismaticJointOptions extends JointOptions {
|
|
7
|
-
/** First body (often a static rail anchor). */
|
|
8
|
-
bodyA: PhysicsBody;
|
|
9
|
-
/** Second body (the slider). */
|
|
10
|
-
bodyB: PhysicsBody;
|
|
11
|
-
/** Shared world-space anchor at creation. */
|
|
12
|
-
anchor: Readonly<PointLike>;
|
|
13
|
-
/** Slide axis in world space at creation (normalised internally). The body may only translate along this axis. */
|
|
14
|
-
axis: Readonly<PointLike>;
|
|
15
|
-
/** Enable the linear motor (drives translation along the axis toward {@link motorSpeed}). Default `false`. */
|
|
16
|
-
enableMotor?: boolean;
|
|
17
|
-
/** Target translation speed along the axis (px/s). Default `0`. */
|
|
18
|
-
motorSpeed?: number;
|
|
19
|
-
/** Maximum motor force - clamps the per-step motor impulse. Default `0`. */
|
|
20
|
-
maxMotorForce?: number;
|
|
21
|
-
/** Enable the translation limit (keeps the axis translation in `[lowerTranslation, upperTranslation]`). Default `false`. */
|
|
22
|
-
enableLimit?: boolean;
|
|
23
|
-
/** Lower translation limit along the axis (relative to the creation position). Default `0`. */
|
|
24
|
-
lowerTranslation?: number;
|
|
25
|
-
/** Upper translation limit along the axis. Default `0`. */
|
|
26
|
-
upperTranslation?: number;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Constrains a body to **slide along a single axis** relative to another: the
|
|
30
|
-
* perpendicular translation and the relative rotation are locked (a 2×2 block);
|
|
31
|
-
* only translation along the axis is free, optionally driven by a motor and/or
|
|
32
|
-
* bounded by a translation limit. Solved in the sub-step loop, warm-started.
|
|
33
|
-
*/
|
|
34
|
-
export declare class PrismaticJoint extends Joint {
|
|
35
|
-
/** When `true`, the motor drives the axis translation toward {@link motorSpeed}. */
|
|
36
|
-
enableMotor: boolean;
|
|
37
|
-
/** Target translation speed along the axis (px/s). */
|
|
38
|
-
motorSpeed: number;
|
|
39
|
-
/** Maximum motor force. */
|
|
40
|
-
maxMotorForce: number;
|
|
41
|
-
/** When `true`, the axis translation is constrained to `[lowerTranslation, upperTranslation]`. */
|
|
42
|
-
enableLimit: boolean;
|
|
43
|
-
/** Lower translation limit along the axis. */
|
|
44
|
-
lowerTranslation: number;
|
|
45
|
-
/** Upper translation limit along the axis. */
|
|
46
|
-
upperTranslation: number;
|
|
47
|
-
private readonly _localAnchorAx;
|
|
48
|
-
private readonly _localAnchorAy;
|
|
49
|
-
private readonly _localAnchorBx;
|
|
50
|
-
private readonly _localAnchorBy;
|
|
51
|
-
private readonly _localAxisAx;
|
|
52
|
-
private readonly _localAxisAy;
|
|
53
|
-
private readonly _referenceAngle;
|
|
54
|
-
private _axisX;
|
|
55
|
-
private _axisY;
|
|
56
|
-
private _perpX;
|
|
57
|
-
private _perpY;
|
|
58
|
-
private _a1;
|
|
59
|
-
private _a2;
|
|
60
|
-
private _s1;
|
|
61
|
-
private _s2;
|
|
62
|
-
private _k11;
|
|
63
|
-
private _k12;
|
|
64
|
-
private _k22;
|
|
65
|
-
private _cPerp;
|
|
66
|
-
private _cAngle;
|
|
67
|
-
private _translation;
|
|
68
|
-
private _axialMass;
|
|
69
|
-
private _h;
|
|
70
|
-
private _invH;
|
|
71
|
-
private _perpImpulse;
|
|
72
|
-
private _angularImpulse;
|
|
73
|
-
private _motorImpulse;
|
|
74
|
-
private _lowerImpulse;
|
|
75
|
-
private _upperImpulse;
|
|
76
|
-
constructor(options: PrismaticJointOptions);
|
|
77
|
-
/** Relative velocity projected onto the axis (plus the rotation cross terms). */
|
|
78
|
-
private _axisVelocity;
|
|
79
|
-
/** Relative velocity projected onto the perpendicular (plus the rotation cross terms). */
|
|
80
|
-
private _perpVelocity;
|
|
81
|
-
private _applyAxial;
|
|
82
|
-
private _applyBlock;
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=PrismaticJoint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismaticJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/PrismaticJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,yDAAyD;AACzD,MAAM,WAAW,qBAAsB,SAAQ,YAAY;IACzD,+CAA+C;IAC/C,KAAK,EAAE,WAAW,CAAC;IACn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