@vworlds/vecs-physics 1.0.37 → 1.0.39
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/adapter/engine.d.ts +14 -4
- package/adapter/engine.js +9 -11
- package/adapter/engine.js.map +1 -1
- package/adapter/queries.d.ts +1 -1
- package/adapter/queries.js +1 -1
- package/adapter/queries.js.map +1 -1
- package/adapter/runtime.js +1 -1
- package/adapter/runtime.js.map +1 -1
- package/{components/body.js → body/components.js} +2 -2
- package/body/components.js.map +1 -0
- package/body/lifecycle.d.ts +4 -0
- package/body/lifecycle.js +153 -0
- package/body/lifecycle.js.map +1 -0
- package/body/mass.d.ts +4 -0
- package/body/mass.js +45 -0
- package/body/mass.js.map +1 -0
- package/body/module.d.ts +4 -0
- package/body/module.js +22 -0
- package/body/module.js.map +1 -0
- package/body/pose_in.d.ts +4 -0
- package/body/pose_in.js +90 -0
- package/body/pose_in.js.map +1 -0
- package/body/pose_out.d.ts +4 -0
- package/body/pose_out.js +59 -0
- package/body/pose_out.js.map +1 -0
- package/{components/body_tuning.js → body/tuning.js} +1 -1
- package/body/tuning.js.map +1 -0
- package/core/module.d.ts +30 -0
- package/core/module.js +77 -0
- package/core/module.js.map +1 -0
- package/core/reaper.d.ts +4 -0
- package/core/reaper.js +45 -0
- package/core/reaper.js.map +1 -0
- package/core/step.d.ts +4 -0
- package/core/step.js +22 -0
- package/core/step.js.map +1 -0
- package/debug/validation.d.ts +4 -0
- package/{systems/debug.js → debug/validation.js} +51 -35
- package/debug/validation.js.map +1 -0
- package/{components/events.js → events/components.js} +1 -1
- package/events/components.js.map +1 -0
- package/events/module.d.ts +4 -0
- package/events/module.js +13 -0
- package/events/module.js.map +1 -0
- package/events/opt_in.d.ts +4 -0
- package/events/opt_in.js +86 -0
- package/events/opt_in.js.map +1 -0
- package/events/publish.d.ts +4 -0
- package/{systems/events.js → events/publish.js} +43 -34
- package/events/publish.js.map +1 -0
- package/{components/force.js → forces/components.js} +1 -1
- package/forces/components.js.map +1 -0
- package/forces/gather.d.ts +4 -0
- package/forces/gather.js +42 -0
- package/forces/gather.js.map +1 -0
- package/forces/impulses.d.ts +4 -0
- package/forces/impulses.js +79 -0
- package/forces/impulses.js.map +1 -0
- package/forces/module.d.ts +4 -0
- package/forces/module.js +20 -0
- package/forces/module.js.map +1 -0
- package/forces/zero.d.ts +4 -0
- package/forces/zero.js +34 -0
- package/forces/zero.js.map +1 -0
- package/index.d.ts +9 -8
- package/index.js +10 -8
- package/index.js.map +1 -1
- package/joints/components.d.ts +116 -0
- package/joints/components.js +150 -0
- package/joints/components.js.map +1 -0
- package/joints/features.d.ts +4 -0
- package/joints/features.js +158 -0
- package/joints/features.js.map +1 -0
- package/joints/lifecycle.d.ts +4 -0
- package/joints/lifecycle.js +191 -0
- package/joints/lifecycle.js.map +1 -0
- package/joints/module.d.ts +4 -0
- package/joints/module.js +33 -0
- package/joints/module.js.map +1 -0
- package/joints/predicates.d.ts +9 -0
- package/joints/predicates.js +10 -0
- package/joints/predicates.js.map +1 -0
- package/{components/target.js → kinematic/components.js} +1 -1
- package/kinematic/components.js.map +1 -0
- package/kinematic/module.d.ts +4 -0
- package/kinematic/module.js +16 -0
- package/kinematic/module.js.map +1 -0
- package/kinematic/targets.d.ts +4 -0
- package/{systems/kinematic.js → kinematic/targets.js} +27 -20
- package/kinematic/targets.js.map +1 -0
- package/{components/material.js → materials/components.js} +1 -1
- package/materials/components.js.map +1 -0
- package/materials/module.d.ts +4 -0
- package/materials/module.js +18 -0
- package/materials/module.js.map +1 -0
- package/materials/sync.d.ts +4 -0
- package/materials/sync.js +136 -0
- package/materials/sync.js.map +1 -0
- package/module.d.ts +3 -27
- package/module.js +45 -141
- package/module.js.map +1 -1
- package/package.json +2 -2
- package/shapes/chain.d.ts +8 -0
- package/{systems/chain_lifecycle.js → shapes/chain.js} +41 -31
- package/shapes/chain.js.map +1 -0
- package/{components/geometry.js → shapes/components.js} +2 -2
- package/{components/geometry.js.map → shapes/components.js.map} +1 -1
- package/{systems/shape_lifecycle.d.ts → shapes/lifecycle.d.ts} +7 -5
- package/{systems/shape_lifecycle.js → shapes/lifecycle.js} +53 -42
- package/shapes/lifecycle.js.map +1 -0
- package/shapes/module.d.ts +4 -0
- package/shapes/module.js +34 -0
- package/shapes/module.js.map +1 -0
- package/{components/shape_pose.js → shapes/pose_components.js} +1 -1
- package/shapes/pose_components.js.map +1 -0
- package/shapes/pose_sync.d.ts +4 -0
- package/shapes/pose_sync.js +70 -0
- package/shapes/pose_sync.js.map +1 -0
- package/{systems/shape_predicates.d.ts → shapes/predicates.d.ts} +2 -2
- package/{systems/shape_predicates.js → shapes/predicates.js} +3 -3
- package/shapes/predicates.js.map +1 -0
- package/util/resolve_body.js +1 -1
- package/components/body.js.map +0 -1
- package/components/body_tuning.js.map +0 -1
- package/components/events.js.map +0 -1
- package/components/force.js.map +0 -1
- package/components/material.js.map +0 -1
- package/components/shape_pose.js.map +0 -1
- package/components/target.js.map +0 -1
- package/systems/chain_lifecycle.d.ts +0 -6
- package/systems/chain_lifecycle.js.map +0 -1
- package/systems/debug.d.ts +0 -4
- package/systems/debug.js.map +0 -1
- package/systems/event_opt_in_sync.d.ts +0 -3
- package/systems/event_opt_in_sync.js +0 -73
- package/systems/event_opt_in_sync.js.map +0 -1
- package/systems/events.d.ts +0 -3
- package/systems/events.js.map +0 -1
- package/systems/forces.d.ts +0 -3
- package/systems/forces.js +0 -35
- package/systems/forces.js.map +0 -1
- package/systems/impulse_accumulate.d.ts +0 -4
- package/systems/impulse_accumulate.js +0 -74
- package/systems/impulse_accumulate.js.map +0 -1
- package/systems/impulse_zero.d.ts +0 -3
- package/systems/impulse_zero.js +0 -27
- package/systems/impulse_zero.js.map +0 -1
- package/systems/index.d.ts +0 -15
- package/systems/index.js +0 -80
- package/systems/index.js.map +0 -1
- package/systems/kinematic.d.ts +0 -3
- package/systems/kinematic.js.map +0 -1
- package/systems/lifecycle.d.ts +0 -4
- package/systems/lifecycle.js +0 -177
- package/systems/lifecycle.js.map +0 -1
- package/systems/mass_recompute.d.ts +0 -3
- package/systems/mass_recompute.js +0 -38
- package/systems/mass_recompute.js.map +0 -1
- package/systems/material_filter_sync.d.ts +0 -3
- package/systems/material_filter_sync.js +0 -129
- package/systems/material_filter_sync.js.map +0 -1
- package/systems/pose_sync_in.d.ts +0 -3
- package/systems/pose_sync_in.js +0 -79
- package/systems/pose_sync_in.js.map +0 -1
- package/systems/pose_sync_out.d.ts +0 -3
- package/systems/pose_sync_out.js +0 -52
- package/systems/pose_sync_out.js.map +0 -1
- package/systems/shape_lifecycle.js.map +0 -1
- package/systems/shape_pose_sync.d.ts +0 -3
- package/systems/shape_pose_sync.js +0 -63
- package/systems/shape_pose_sync.js.map +0 -1
- package/systems/shape_predicates.js.map +0 -1
- package/systems/step.d.ts +0 -3
- package/systems/step.js +0 -15
- package/systems/step.js.map +0 -1
- /package/{components/body.d.ts → body/components.d.ts} +0 -0
- /package/{components/body_tuning.d.ts → body/tuning.d.ts} +0 -0
- /package/{components/events.d.ts → events/components.d.ts} +0 -0
- /package/{components/force.d.ts → forces/components.d.ts} +0 -0
- /package/{components/target.d.ts → kinematic/components.d.ts} +0 -0
- /package/{components/material.d.ts → materials/components.d.ts} +0 -0
- /package/{components/geometry.d.ts → shapes/components.d.ts} +0 -0
- /package/{components/shape_pose.d.ts → shapes/pose_components.d.ts} +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Joint components. A joint is its own entity that connects two bodies with a
|
|
2
|
+
// constraint. The connection is modelled with two relationships (`JointBodyA`,
|
|
3
|
+
// `JointBodyB`) so destroying a connected body cascade-destroys the joint and so
|
|
4
|
+
// joint creation is order-independent, mirroring shape↔body wiring via `ChildOf`.
|
|
5
|
+
//
|
|
6
|
+
// Each joint entity carries exactly one concrete joint-type component (every type
|
|
7
|
+
// implements the `Joint` umbrella, so `PhysicsModule` enforces mutual
|
|
8
|
+
// exclusivity). Optional, reusable feature components (`JointMotor`, `JointLimit`,
|
|
9
|
+
// `JointLinearSpring`, `JointAngularSpring`) layer behaviour on top: a feature is
|
|
10
|
+
// enabled exactly when its component is present, so features are set, tuned, and
|
|
11
|
+
// removed independently. Public API — see `docs/joints.md`.
|
|
12
|
+
//
|
|
13
|
+
// These are plain data classes: every field is initialised on the class body so
|
|
14
|
+
// `new C()` yields a valid, default-shaped instance (the Vecs zero-arg contract).
|
|
15
|
+
// No imports from behavior modules or adapter/ beyond the type-only `b2JointId` handle.
|
|
16
|
+
import { Relationship } from "@vworlds/vecs";
|
|
17
|
+
/**
|
|
18
|
+
* Empty umbrella marker for every concrete joint type. A joint entity carries
|
|
19
|
+
* exactly one of `RevoluteJoint`, `DistanceJoint`, `WeldJoint`, or `FilterJoint`;
|
|
20
|
+
* each implements `Joint` so queries and systems can match any joint without
|
|
21
|
+
* enumerating every concrete type. Holds the single Box2D handle, since every
|
|
22
|
+
* joint type maps to exactly one `b2JointId`.
|
|
23
|
+
*/
|
|
24
|
+
export class Joint {
|
|
25
|
+
constructor() {
|
|
26
|
+
/** @internal Engine-owned Box2D joint handle. Set by the joint lifecycle system. */
|
|
27
|
+
this._jointId = undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Relationship to the first connected body ("body A"). Set its `target` to the
|
|
32
|
+
* body entity. Destroying body A destroys the joint entity (Box2D destroys a
|
|
33
|
+
* body's joints with it). Anchors/limits/reference angle are expressed relative
|
|
34
|
+
* to A through {@link JointFrame}.
|
|
35
|
+
*/
|
|
36
|
+
export class JointBodyA extends Relationship {
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Relationship to the second connected body ("body B"). Set its `target` to the
|
|
40
|
+
* body entity. Destroying body B destroys the joint entity. The A/B roles are
|
|
41
|
+
* asymmetric: motors drive B relative to A and the reference angle is measured as
|
|
42
|
+
* B's rest angle relative to A.
|
|
43
|
+
*/
|
|
44
|
+
export class JointBodyB extends Relationship {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Where the joint attaches on each body and the bodies' rest orientation.
|
|
48
|
+
* `localAnchorA`/`localAnchorB` are anchor points in each body's local frame;
|
|
49
|
+
* `referenceAngle` is body B's angle relative to body A at rest (radians).
|
|
50
|
+
*
|
|
51
|
+
* Optional: a missing `JointFrame` anchors both bodies at their origins with a
|
|
52
|
+
* zero reference angle. `DistanceJoint` ignores `referenceAngle`.
|
|
53
|
+
*/
|
|
54
|
+
export class JointFrame {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.localAnchorA = { x: 0, y: 0 };
|
|
57
|
+
this.localAnchorB = { x: 0, y: 0 };
|
|
58
|
+
this.referenceAngle = 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Revolute (hinge) joint: pins the two bodies at a shared anchor and lets them
|
|
63
|
+
* rotate relative to each other. Add {@link JointMotor} to drive the rotation,
|
|
64
|
+
* {@link JointLimit} to clamp the angle (radians, relative to the reference
|
|
65
|
+
* angle), or {@link JointAngularSpring} for a soft rest angle.
|
|
66
|
+
*/
|
|
67
|
+
export class RevoluteJoint extends Joint {
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Distance joint: keeps the two anchor points a fixed `length` apart (a rigid
|
|
71
|
+
* rod by default). Add {@link JointLinearSpring} to make it springy,
|
|
72
|
+
* {@link JointLimit} to bound the separation (`lower`/`upper` become min/max
|
|
73
|
+
* length), or {@link JointMotor} to drive the length.
|
|
74
|
+
*/
|
|
75
|
+
export class DistanceJoint extends Joint {
|
|
76
|
+
constructor() {
|
|
77
|
+
super(...arguments);
|
|
78
|
+
this.length = 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Weld joint: rigidly fixes the two bodies' relative position and orientation
|
|
83
|
+
* (at the reference angle). Add {@link JointLinearSpring} and/or
|
|
84
|
+
* {@link JointAngularSpring} to make the weld soft along each axis.
|
|
85
|
+
*/
|
|
86
|
+
export class WeldJoint extends Joint {
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Filter joint: disables collision between the two connected bodies without
|
|
90
|
+
* otherwise constraining them. Carries no tunables; motor/limit/spring features
|
|
91
|
+
* do not apply.
|
|
92
|
+
*/
|
|
93
|
+
export class FilterJoint extends Joint {
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Optional motor feature. Present = motor enabled. Drives the joint toward
|
|
97
|
+
* `targetSpeed` (rad/s for revolute, m/s for distance) bounded by `maxForce`
|
|
98
|
+
* (interpreted as a torque for angular joints). Applies to `RevoluteJoint` and
|
|
99
|
+
* `DistanceJoint`.
|
|
100
|
+
*/
|
|
101
|
+
export class JointMotor {
|
|
102
|
+
constructor() {
|
|
103
|
+
this.targetSpeed = 0;
|
|
104
|
+
this.maxForce = 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Optional limit feature. Present = limit enabled. `lower`/`upper` are an angle
|
|
109
|
+
* range (radians) for `RevoluteJoint` and a length range (meters) for
|
|
110
|
+
* `DistanceJoint`.
|
|
111
|
+
*/
|
|
112
|
+
export class JointLimit {
|
|
113
|
+
constructor() {
|
|
114
|
+
this.lower = 0;
|
|
115
|
+
this.upper = 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Optional linear spring feature (soft constraint along the joint's linear axis).
|
|
120
|
+
* Present = spring enabled. `hertz` is the stiffness frequency, `dampingRatio`
|
|
121
|
+
* the damping. Applies to `DistanceJoint` and the linear axis of `WeldJoint`.
|
|
122
|
+
*/
|
|
123
|
+
export class JointLinearSpring {
|
|
124
|
+
constructor() {
|
|
125
|
+
this.hertz = 0;
|
|
126
|
+
this.dampingRatio = 0;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Optional angular spring feature (soft constraint on the relative angle).
|
|
131
|
+
* Present = spring enabled. Applies to `RevoluteJoint` and the angular axis of
|
|
132
|
+
* `WeldJoint`. Split from {@link JointLinearSpring} so a weld can carry both at
|
|
133
|
+
* once.
|
|
134
|
+
*/
|
|
135
|
+
export class JointAngularSpring {
|
|
136
|
+
constructor() {
|
|
137
|
+
this.hertz = 0;
|
|
138
|
+
this.dampingRatio = 0;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Optional base-joint settings. `collideConnected` lets the two connected bodies
|
|
143
|
+
* still collide with each other (off by default). Missing = Box2D defaults.
|
|
144
|
+
*/
|
|
145
|
+
export class JointSettings {
|
|
146
|
+
constructor() {
|
|
147
|
+
this.collideConnected = false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../../../src/joints/components.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+EAA+E;AAC/E,iFAAiF;AACjF,kFAAkF;AAClF,EAAE;AACF,kFAAkF;AAClF,sEAAsE;AACtE,mFAAmF;AACnF,kFAAkF;AAClF,iFAAiF;AACjF,4DAA4D;AAC5D,EAAE;AACF,gFAAgF;AAChF,kFAAkF;AAClF,wFAAwF;AAExF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAK7C;;;;;;GAMG;AACH,MAAM,OAAgB,KAAK;IAA3B;QACE,oFAAoF;QACpF,aAAQ,GAA0B,SAAS,CAAC;IAC9C,CAAC;CAAA;AAED;;;;;GAKG;AACH,MAAM,OAAO,UAAW,SAAQ,YAAY;CAAG;AAE/C;;;;;GAKG;AACH,MAAM,OAAO,UAAW,SAAQ,YAAY;CAAG;AAE/C;;;;;;;GAOG;AACH,MAAM,OAAO,UAAU;IAAvB;QACE,iBAAY,GAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACpC,iBAAY,GAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACpC,mBAAc,GAAG,CAAC,CAAC;IACrB,CAAC;CAAA;AAED;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;CAAG;AAE3C;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAAxC;;QACE,WAAM,GAAG,CAAC,CAAC;IACb,CAAC;CAAA;AAED;;;;GAIG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;CAAG;AAEvC;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;CAAG;AAEzC;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IAAvB;QACE,gBAAW,GAAG,CAAC,CAAC;QAChB,aAAQ,GAAG,CAAC,CAAC;IACf,CAAC;CAAA;AAED;;;;GAIG;AACH,MAAM,OAAO,UAAU;IAAvB;QACE,UAAK,GAAG,CAAC,CAAC;QACV,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QACE,UAAK,GAAG,CAAC,CAAC;QACV,iBAAY,GAAG,CAAC,CAAC;IACnB,CAAC;CAAA;AAED;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IAA/B;QACE,UAAK,GAAG,CAAC,CAAC;QACV,iBAAY,GAAG,CAAC,CAAC;IACnB,CAAC;CAAA;AAED;;;GAGG;AACH,MAAM,OAAO,aAAa;IAA1B;QACE,qBAAgB,GAAG,KAAK,CAAC;IAC3B,CAAC;CAAA"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Joint feature sync. Each optional feature (motor, limit, linear spring, angular
|
|
2
|
+
// spring) is owned by its own small reactive system, modelled on
|
|
3
|
+
// PhysicsMaterialFilterSync: presence of the component enables the feature, a
|
|
4
|
+
// change re-tunes it, and removal disables it. Creation-time presence is baked
|
|
5
|
+
// into the def by the lifecycle (`lifecycle.ts`); these systems own runtime
|
|
6
|
+
// add/change/remove on a live joint via in-place Box2D setters.
|
|
7
|
+
//
|
|
8
|
+
// Every setter is guarded by `b2Joint_IsValid`: the joint may not exist yet (a
|
|
9
|
+
// connected body hasn't appeared) or may have been reaped (a connected body was
|
|
10
|
+
// destroyed) by the time a callback runs.
|
|
11
|
+
import { Module } from "@vworlds/vecs";
|
|
12
|
+
import { getPhysicsEngine, PhysicsSystemTag, } from "../adapter/engine.js";
|
|
13
|
+
import { DistanceJoint, Joint, JointAngularSpring, JointLimit, JointLinearSpring, JointMotor, RevoluteJoint, WeldJoint, } from "./components.js";
|
|
14
|
+
import { PhysicsCoreModule } from "../core/module.js";
|
|
15
|
+
import { jointWithBothBodies } from "./predicates.js";
|
|
16
|
+
export class JointFeaturesModule extends Module {
|
|
17
|
+
init() {
|
|
18
|
+
const world = this.world;
|
|
19
|
+
world.module(PhysicsCoreModule);
|
|
20
|
+
const engine = getPhysicsEngine(world);
|
|
21
|
+
const phase = engine.phases.preStep;
|
|
22
|
+
const motor = world
|
|
23
|
+
.system("PhysicsJointMotorSync")
|
|
24
|
+
.with(JointMotor, jointWithBothBodies)
|
|
25
|
+
.phase(phase)
|
|
26
|
+
.add(PhysicsSystemTag);
|
|
27
|
+
motor.update({ watch: JointMotor, onEnter: true, inject: [Joint] }, (_e, value, [joint]) => {
|
|
28
|
+
withLiveJoint(engine, joint, (id) => applyMotor(engine.box2d, joint, id, value));
|
|
29
|
+
});
|
|
30
|
+
motor.exit([JointMotor, Joint], (_e, [, joint]) => {
|
|
31
|
+
withLiveJoint(engine, joint, (id) => disableMotor(engine.box2d, joint, id));
|
|
32
|
+
});
|
|
33
|
+
const limit = world
|
|
34
|
+
.system("PhysicsJointLimitSync")
|
|
35
|
+
.with(JointLimit, jointWithBothBodies)
|
|
36
|
+
.phase(phase)
|
|
37
|
+
.add(PhysicsSystemTag);
|
|
38
|
+
limit.update({ watch: JointLimit, onEnter: true, inject: [Joint] }, (_e, value, [joint]) => {
|
|
39
|
+
withLiveJoint(engine, joint, (id) => applyLimit(engine.box2d, joint, id, value));
|
|
40
|
+
});
|
|
41
|
+
limit.exit([JointLimit, Joint], (_e, [, joint]) => {
|
|
42
|
+
withLiveJoint(engine, joint, (id) => disableLimit(engine.box2d, joint, id));
|
|
43
|
+
});
|
|
44
|
+
const linear = world
|
|
45
|
+
.system("PhysicsJointLinearSpringSync")
|
|
46
|
+
.with(JointLinearSpring, jointWithBothBodies)
|
|
47
|
+
.phase(phase)
|
|
48
|
+
.add(PhysicsSystemTag);
|
|
49
|
+
linear.update({ watch: JointLinearSpring, onEnter: true, inject: [Joint] }, (_e, value, [joint]) => {
|
|
50
|
+
withLiveJoint(engine, joint, (id) => applyLinearSpring(engine.box2d, joint, id, value));
|
|
51
|
+
});
|
|
52
|
+
linear.exit([JointLinearSpring, Joint], (_e, [, joint]) => {
|
|
53
|
+
withLiveJoint(engine, joint, (id) => disableLinearSpring(engine.box2d, joint, id));
|
|
54
|
+
});
|
|
55
|
+
const angular = world
|
|
56
|
+
.system("PhysicsJointAngularSpringSync")
|
|
57
|
+
.with(JointAngularSpring, jointWithBothBodies)
|
|
58
|
+
.phase(phase)
|
|
59
|
+
.add(PhysicsSystemTag);
|
|
60
|
+
angular.update({ watch: JointAngularSpring, onEnter: true, inject: [Joint] }, (_e, value, [joint]) => {
|
|
61
|
+
withLiveJoint(engine, joint, (id) => applyAngularSpring(engine.box2d, joint, id, value));
|
|
62
|
+
});
|
|
63
|
+
angular.exit([JointAngularSpring, Joint], (_e, [, joint]) => {
|
|
64
|
+
withLiveJoint(engine, joint, (id) => disableAngularSpring(engine.box2d, joint, id));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Run `fn` only when the joint exists and its Box2D handle is still valid, then
|
|
69
|
+
* wake the connected bodies so a runtime feature change takes effect even if they
|
|
70
|
+
* had gone to sleep (Box2D's joint setters do not wake bodies on their own). */
|
|
71
|
+
function withLiveJoint(engine, joint, fn) {
|
|
72
|
+
const jointId = joint?._jointId;
|
|
73
|
+
if (jointId === undefined || !engine.box2d.b2Joint_IsValid(jointId)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
fn(jointId);
|
|
77
|
+
engine.box2d.b2Joint_WakeBodies(jointId);
|
|
78
|
+
}
|
|
79
|
+
function applyMotor(box2d, joint, jointId, motor) {
|
|
80
|
+
if (joint instanceof RevoluteJoint) {
|
|
81
|
+
box2d.b2RevoluteJoint_EnableMotor(jointId, true);
|
|
82
|
+
box2d.b2RevoluteJoint_SetMotorSpeed(jointId, motor.targetSpeed);
|
|
83
|
+
box2d.b2RevoluteJoint_SetMaxMotorTorque(jointId, motor.maxForce);
|
|
84
|
+
}
|
|
85
|
+
else if (joint instanceof DistanceJoint) {
|
|
86
|
+
box2d.b2DistanceJoint_EnableMotor(jointId, true);
|
|
87
|
+
box2d.b2DistanceJoint_SetMotorSpeed(jointId, motor.targetSpeed);
|
|
88
|
+
box2d.b2DistanceJoint_SetMaxMotorForce(jointId, motor.maxForce);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function disableMotor(box2d, joint, jointId) {
|
|
92
|
+
if (joint instanceof RevoluteJoint) {
|
|
93
|
+
box2d.b2RevoluteJoint_EnableMotor(jointId, false);
|
|
94
|
+
}
|
|
95
|
+
else if (joint instanceof DistanceJoint) {
|
|
96
|
+
box2d.b2DistanceJoint_EnableMotor(jointId, false);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function applyLimit(box2d, joint, jointId, limit) {
|
|
100
|
+
if (joint instanceof RevoluteJoint) {
|
|
101
|
+
box2d.b2RevoluteJoint_EnableLimit(jointId, true);
|
|
102
|
+
box2d.b2RevoluteJoint_SetLimits(jointId, limit.lower, limit.upper);
|
|
103
|
+
}
|
|
104
|
+
else if (joint instanceof DistanceJoint) {
|
|
105
|
+
box2d.b2DistanceJoint_EnableLimit(jointId, true);
|
|
106
|
+
box2d.b2DistanceJoint_SetLengthRange(jointId, limit.lower, limit.upper);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function disableLimit(box2d, joint, jointId) {
|
|
110
|
+
if (joint instanceof RevoluteJoint) {
|
|
111
|
+
box2d.b2RevoluteJoint_EnableLimit(jointId, false);
|
|
112
|
+
}
|
|
113
|
+
else if (joint instanceof DistanceJoint) {
|
|
114
|
+
box2d.b2DistanceJoint_EnableLimit(jointId, false);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function applyLinearSpring(box2d, joint, jointId, spring) {
|
|
118
|
+
if (joint instanceof DistanceJoint) {
|
|
119
|
+
box2d.b2DistanceJoint_EnableSpring(jointId, true);
|
|
120
|
+
box2d.b2DistanceJoint_SetSpringHertz(jointId, spring.hertz);
|
|
121
|
+
box2d.b2DistanceJoint_SetSpringDampingRatio(jointId, spring.dampingRatio);
|
|
122
|
+
}
|
|
123
|
+
else if (joint instanceof WeldJoint) {
|
|
124
|
+
box2d.b2WeldJoint_SetLinearHertz(jointId, spring.hertz);
|
|
125
|
+
box2d.b2WeldJoint_SetLinearDampingRatio(jointId, spring.dampingRatio);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function disableLinearSpring(box2d, joint, jointId) {
|
|
129
|
+
if (joint instanceof DistanceJoint) {
|
|
130
|
+
box2d.b2DistanceJoint_EnableSpring(jointId, false);
|
|
131
|
+
}
|
|
132
|
+
else if (joint instanceof WeldJoint) {
|
|
133
|
+
// A weld has no spring enable flag; zero hertz is a rigid weld.
|
|
134
|
+
box2d.b2WeldJoint_SetLinearHertz(jointId, 0);
|
|
135
|
+
box2d.b2WeldJoint_SetLinearDampingRatio(jointId, 0);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function applyAngularSpring(box2d, joint, jointId, spring) {
|
|
139
|
+
if (joint instanceof RevoluteJoint) {
|
|
140
|
+
box2d.b2RevoluteJoint_EnableSpring(jointId, true);
|
|
141
|
+
box2d.b2RevoluteJoint_SetSpringHertz(jointId, spring.hertz);
|
|
142
|
+
box2d.b2RevoluteJoint_SetSpringDampingRatio(jointId, spring.dampingRatio);
|
|
143
|
+
}
|
|
144
|
+
else if (joint instanceof WeldJoint) {
|
|
145
|
+
box2d.b2WeldJoint_SetAngularHertz(jointId, spring.hertz);
|
|
146
|
+
box2d.b2WeldJoint_SetAngularDampingRatio(jointId, spring.dampingRatio);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function disableAngularSpring(box2d, joint, jointId) {
|
|
150
|
+
if (joint instanceof RevoluteJoint) {
|
|
151
|
+
box2d.b2RevoluteJoint_EnableSpring(jointId, false);
|
|
152
|
+
}
|
|
153
|
+
else if (joint instanceof WeldJoint) {
|
|
154
|
+
box2d.b2WeldJoint_SetAngularHertz(jointId, 0);
|
|
155
|
+
box2d.b2WeldJoint_SetAngularDampingRatio(jointId, 0);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=features.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.js","sourceRoot":"","sources":["../../../../src/joints/features.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,iEAAiE;AACjE,8EAA8E;AAC9E,+EAA+E;AAC/E,4EAA4E;AAC5E,gEAAgE;AAChE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,0CAA0C;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GAGjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EACb,KAAK,EACL,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,SAAS,GACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,OAAO,mBAAoB,SAAQ,MAAM;IACtC,IAAI;QACT,MAAM,KAAK,GAAG,IAAI,CA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,CAAC,CAAC,CAAC;QAC9C,KAAK,CAAC,kCAAkC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// Joint lifecycle: creates/destroys the Box2D joint that backs a joint entity.
|
|
2
|
+
// Mirrors the shape lifecycle, but works over TWO bodies instead of one ChildOf
|
|
3
|
+
// parent: each system injects both connected bodies through the JointBodyA/B
|
|
4
|
+
// relationship targets and passes them in. Creation is order-independent: the
|
|
5
|
+
// `jointWithBothBodies` predicate only matches once both connected bodies carry a
|
|
6
|
+
// `Body`, and the relationship TargetTerms fan out reactively as bodies appear.
|
|
7
|
+
//
|
|
8
|
+
// Anchors and the reference angle are written straight into the def's embedded
|
|
9
|
+
// local-frame transforms (`def.base.localFrameA.p.Set(...)`,
|
|
10
|
+
// `...q.SetAngle(...)`), so joint creation allocates nothing beyond the def
|
|
11
|
+
// handle wrapped by `withAllocated`. Feature components (motor/limit/spring) are
|
|
12
|
+
// baked into the def here so creation-time presence works in any order; runtime
|
|
13
|
+
// changes are owned by the feature sync module (`features.ts`).
|
|
14
|
+
import { Module } from "@vworlds/vecs";
|
|
15
|
+
import { getPhysicsEngine, PhysicsSystemTag, } from "../adapter/engine.js";
|
|
16
|
+
import { Body } from "../body/components.js";
|
|
17
|
+
import { DistanceJoint, FilterJoint, Joint, JointAngularSpring, JointBodyA, JointBodyB, JointFrame, JointLimit, JointLinearSpring, JointMotor, JointSettings, RevoluteJoint, WeldJoint, } from "./components.js";
|
|
18
|
+
import { withAllocated } from "../adapter/disposal.js";
|
|
19
|
+
import { PhysicsCoreModule } from "../core/module.js";
|
|
20
|
+
import { jointWithBothBodies } from "./predicates.js";
|
|
21
|
+
// Inject the `Joint` plus both connected bodies (resolved through the
|
|
22
|
+
// JointBodyA/B relationship targets). Body terms are not in `.with`, so they
|
|
23
|
+
// resolve as `Body | undefined`.
|
|
24
|
+
const bodyAInject = { target: [JointBodyA, [Body]] };
|
|
25
|
+
const bodyBInject = { target: [JointBodyB, [Body]] };
|
|
26
|
+
export class JointLifecycleModule extends Module {
|
|
27
|
+
init() {
|
|
28
|
+
const world = this.world;
|
|
29
|
+
world.module(PhysicsCoreModule);
|
|
30
|
+
const engine = getPhysicsEngine(world);
|
|
31
|
+
const phase = engine.phases.preStep;
|
|
32
|
+
world
|
|
33
|
+
.system("PhysicsJointLifecycle")
|
|
34
|
+
.with(jointWithBothBodies)
|
|
35
|
+
.phase(phase)
|
|
36
|
+
.enter([Joint, bodyAInject, bodyBInject], (entity, [joint, bodyA, bodyB]) => {
|
|
37
|
+
createJointForEntity(engine, entity, joint, bodyA, bodyB);
|
|
38
|
+
})
|
|
39
|
+
// Inject `[Joint]` so the joint handle survives the post-`_destroy` exit
|
|
40
|
+
// snapshot, then defer the b2DestroyJoint to PhysicsReaper (validity-guarded,
|
|
41
|
+
// because a connected body's destroy may have detached this joint already).
|
|
42
|
+
.exit([Joint], (entity, [joint]) => {
|
|
43
|
+
destroyJointForEntity(engine, entity, true, joint);
|
|
44
|
+
})
|
|
45
|
+
// Type-component change (e.g. DistanceJoint.length): destroy + recreate now.
|
|
46
|
+
.update({ watch: Joint, inject: [bodyAInject, bodyBInject] }, (entity, joint, [bodyA, bodyB]) => {
|
|
47
|
+
recreateJointForEntity(engine, entity, joint, bodyA, bodyB);
|
|
48
|
+
})
|
|
49
|
+
.add(PhysicsSystemTag);
|
|
50
|
+
// JointFrame change: anchors/reference angle are create-time only, so recreate.
|
|
51
|
+
world
|
|
52
|
+
.system("PhysicsJointLifecycle:Frame")
|
|
53
|
+
.with(JointFrame, jointWithBothBodies)
|
|
54
|
+
.phase(phase)
|
|
55
|
+
.update({ watch: JointFrame, inject: [Joint, bodyAInject, bodyBInject] }, (entity, _frame, [joint, bodyA, bodyB]) => {
|
|
56
|
+
recreateJointForEntity(engine, entity, joint, bodyA, bodyB);
|
|
57
|
+
})
|
|
58
|
+
.add(PhysicsSystemTag);
|
|
59
|
+
// Retarget either body relationship: rebuild the joint on the new bodies.
|
|
60
|
+
world
|
|
61
|
+
.system("PhysicsJointLifecycle:Retarget")
|
|
62
|
+
.with(JointBodyA, JointBodyB, jointWithBothBodies)
|
|
63
|
+
.phase(phase)
|
|
64
|
+
.update({ watch: JointBodyA, inject: [Joint, bodyAInject, bodyBInject] }, (entity, _rel, [joint, bodyA, bodyB]) => {
|
|
65
|
+
recreateJointForEntity(engine, entity, joint, bodyA, bodyB);
|
|
66
|
+
})
|
|
67
|
+
.update({ watch: JointBodyB, inject: [Joint, bodyAInject, bodyBInject] }, (entity, _rel, [joint, bodyA, bodyB]) => {
|
|
68
|
+
recreateJointForEntity(engine, entity, joint, bodyA, bodyB);
|
|
69
|
+
})
|
|
70
|
+
.add(PhysicsSystemTag);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function recreateJointForEntity(engine, entity, joint, bodyA, bodyB) {
|
|
74
|
+
destroyJointForEntity(engine, entity, false, joint);
|
|
75
|
+
createJointForEntity(engine, entity, joint, bodyA, bodyB);
|
|
76
|
+
}
|
|
77
|
+
function createJointForEntity(engine, entity, joint, bodyA, bodyB) {
|
|
78
|
+
const bodyAId = bodyA?._bodyId;
|
|
79
|
+
const bodyBId = bodyB?._bodyId;
|
|
80
|
+
if (joint === undefined || bodyAId === undefined || bodyBId === undefined) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const jointId = createBox2dJoint(engine, entity, joint, bodyAId, bodyBId);
|
|
84
|
+
if (jointId !== undefined) {
|
|
85
|
+
joint._jointId = jointId;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// `deferDestroy` mirrors the shape lifecycle: an exit defers the b2DestroyJoint to
|
|
89
|
+
// PhysicsReaper (joint still live until then), an in-place recreate destroys now.
|
|
90
|
+
function destroyJointForEntity(engine, entity, deferDestroy, joint) {
|
|
91
|
+
const resolvedJoint = joint ?? entity.get(Joint);
|
|
92
|
+
const jointId = resolvedJoint?._jointId;
|
|
93
|
+
if (jointId === undefined) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (deferDestroy) {
|
|
97
|
+
engine.pendingJointDestroys.push(jointId);
|
|
98
|
+
}
|
|
99
|
+
else if (engine.box2d.b2Joint_IsValid(jointId)) {
|
|
100
|
+
engine.box2d.b2DestroyJoint(jointId, true);
|
|
101
|
+
}
|
|
102
|
+
const mutableJoint = entity.get(Joint);
|
|
103
|
+
if (mutableJoint !== undefined) {
|
|
104
|
+
mutableJoint._jointId = undefined;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function createBox2dJoint(engine, entity, joint, bodyAId, bodyBId) {
|
|
108
|
+
const box2d = engine.box2d;
|
|
109
|
+
const frame = entity.get(JointFrame);
|
|
110
|
+
const collideConnected = entity.get(JointSettings)?.collideConnected ?? false;
|
|
111
|
+
const motor = entity.get(JointMotor);
|
|
112
|
+
const limit = entity.get(JointLimit);
|
|
113
|
+
const linearSpring = entity.get(JointLinearSpring);
|
|
114
|
+
const angularSpring = entity.get(JointAngularSpring);
|
|
115
|
+
// Write anchors + reference angle into a def's embedded local frames. The
|
|
116
|
+
// reference angle (B's rest angle relative to A) is encoded on frame A's
|
|
117
|
+
// rotation; frame B stays identity.
|
|
118
|
+
const applyBase = (base) => {
|
|
119
|
+
base.bodyIdA = bodyAId;
|
|
120
|
+
base.bodyIdB = bodyBId;
|
|
121
|
+
base.localFrameA.p.Set(frame?.localAnchorA.x ?? 0, frame?.localAnchorA.y ?? 0);
|
|
122
|
+
base.localFrameA.q.SetAngle(frame?.referenceAngle ?? 0);
|
|
123
|
+
base.localFrameB.p.Set(frame?.localAnchorB.x ?? 0, frame?.localAnchorB.y ?? 0);
|
|
124
|
+
base.collideConnected = collideConnected;
|
|
125
|
+
};
|
|
126
|
+
if (joint instanceof RevoluteJoint) {
|
|
127
|
+
return withAllocated(box2d.b2DefaultRevoluteJointDef, (def) => {
|
|
128
|
+
applyBase(def.base);
|
|
129
|
+
if (motor !== undefined) {
|
|
130
|
+
def.enableMotor = true;
|
|
131
|
+
def.motorSpeed = motor.targetSpeed;
|
|
132
|
+
def.maxMotorTorque = motor.maxForce;
|
|
133
|
+
}
|
|
134
|
+
if (limit !== undefined) {
|
|
135
|
+
def.enableLimit = true;
|
|
136
|
+
def.lowerAngle = limit.lower;
|
|
137
|
+
def.upperAngle = limit.upper;
|
|
138
|
+
}
|
|
139
|
+
if (angularSpring !== undefined) {
|
|
140
|
+
def.enableSpring = true;
|
|
141
|
+
def.hertz = angularSpring.hertz;
|
|
142
|
+
def.dampingRatio = angularSpring.dampingRatio;
|
|
143
|
+
}
|
|
144
|
+
return box2d.b2CreateRevoluteJoint(engine.worldId, def);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (joint instanceof DistanceJoint) {
|
|
148
|
+
return withAllocated(box2d.b2DefaultDistanceJointDef, (def) => {
|
|
149
|
+
applyBase(def.base);
|
|
150
|
+
def.length = joint.length;
|
|
151
|
+
if (linearSpring !== undefined) {
|
|
152
|
+
def.enableSpring = true;
|
|
153
|
+
def.hertz = linearSpring.hertz;
|
|
154
|
+
def.dampingRatio = linearSpring.dampingRatio;
|
|
155
|
+
}
|
|
156
|
+
if (limit !== undefined) {
|
|
157
|
+
def.enableLimit = true;
|
|
158
|
+
def.minLength = limit.lower;
|
|
159
|
+
def.maxLength = limit.upper;
|
|
160
|
+
}
|
|
161
|
+
if (motor !== undefined) {
|
|
162
|
+
def.enableMotor = true;
|
|
163
|
+
def.motorSpeed = motor.targetSpeed;
|
|
164
|
+
def.maxMotorForce = motor.maxForce;
|
|
165
|
+
}
|
|
166
|
+
return box2d.b2CreateDistanceJoint(engine.worldId, def);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (joint instanceof WeldJoint) {
|
|
170
|
+
return withAllocated(box2d.b2DefaultWeldJointDef, (def) => {
|
|
171
|
+
applyBase(def.base);
|
|
172
|
+
if (linearSpring !== undefined) {
|
|
173
|
+
def.linearHertz = linearSpring.hertz;
|
|
174
|
+
def.linearDampingRatio = linearSpring.dampingRatio;
|
|
175
|
+
}
|
|
176
|
+
if (angularSpring !== undefined) {
|
|
177
|
+
def.angularHertz = angularSpring.hertz;
|
|
178
|
+
def.angularDampingRatio = angularSpring.dampingRatio;
|
|
179
|
+
}
|
|
180
|
+
return box2d.b2CreateWeldJoint(engine.worldId, def);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (joint instanceof FilterJoint) {
|
|
184
|
+
return withAllocated(box2d.b2DefaultFilterJointDef, (def) => {
|
|
185
|
+
applyBase(def.base);
|
|
186
|
+
return box2d.b2CreateFilterJoint(engine.worldId, def);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../../../src/joints/lifecycle.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gFAAgF;AAChF,6EAA6E;AAC7E,8EAA8E;AAC9E,kFAAkF;AAClF,gFAAgF;AAChF,EAAE;AACF,+EAA+E;AAC/E,6DAA6D;AAC7D,4EAA4E;AAC5E,iFAAiF;AACjF,gFAAgF;AAChF,gEAAgE;AAEhE,OAAO,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAEpD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GAKjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EACL,aAAa,EACb,WAAW,EACX,KAAK,EACL,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE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IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;QAC/B,OAAO,aAAa,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,GAAG,EAAE,EAAE;YACxD,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACpB,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;gBAC/B,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC;gBACrC,GAAG,CAAC,kBAAkB,GAAG,YAAY,CAAC,YAAY,CAAC;YACrD,CAAC;YACD,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;gBAChC,GAAG,CAAC,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC;gBACvC,GAAG,CAAC,mBAAmB,GAAG,aAAa,CAAC,YAAY,CAAC;YACvD,CAAC;YACD,OAAO,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,aAAa,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC,GAAG,EAAE,EAAE;YAC1D,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACpB,OAAO,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/joints/module.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Implements, Module } from "@vworlds/vecs";
|
|
2
|
+
import { BodyModule } from "../body/module.js";
|
|
3
|
+
import { PhysicsCoreModule } from "../core/module.js";
|
|
4
|
+
import { DistanceJoint, FilterJoint, Joint, JointAngularSpring, JointBodyA, JointBodyB, JointFrame, JointLimit, JointLinearSpring, JointMotor, JointSettings, RevoluteJoint, WeldJoint, } from "./components.js";
|
|
5
|
+
import { JointFeaturesModule } from "./features.js";
|
|
6
|
+
import { JointLifecycleModule } from "./lifecycle.js";
|
|
7
|
+
export class JointsModule extends Module {
|
|
8
|
+
init() {
|
|
9
|
+
const world = this.world;
|
|
10
|
+
world.module(PhysicsCoreModule);
|
|
11
|
+
world.module(BodyModule);
|
|
12
|
+
world.component(JointBodyA);
|
|
13
|
+
world.component(JointBodyB);
|
|
14
|
+
world.component(Joint);
|
|
15
|
+
world.component(RevoluteJoint);
|
|
16
|
+
world.component(DistanceJoint);
|
|
17
|
+
world.component(WeldJoint);
|
|
18
|
+
world.component(FilterJoint);
|
|
19
|
+
world.component(JointFrame);
|
|
20
|
+
world.component(JointMotor);
|
|
21
|
+
world.component(JointLimit);
|
|
22
|
+
world.component(JointLinearSpring);
|
|
23
|
+
world.component(JointAngularSpring);
|
|
24
|
+
world.component(JointSettings);
|
|
25
|
+
world.component(RevoluteJoint).set(Implements, { interfaces: [Joint] });
|
|
26
|
+
world.component(DistanceJoint).set(Implements, { interfaces: [Joint] });
|
|
27
|
+
world.component(WeldJoint).set(Implements, { interfaces: [Joint] });
|
|
28
|
+
world.component(FilterJoint).set(Implements, { interfaces: [Joint] });
|
|
29
|
+
world.module(JointLifecycleModule);
|
|
30
|
+
world.module(JointFeaturesModule);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../../src/joints/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,aAAa,EACb,WAAW,EACX,KAAK,EACL,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB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KAAK,CAAC,EAAE,CAAC,CAAC;QACxE,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACpE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAEtE,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACnC,KAAK,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Body } from "../body/components.js";
|
|
2
|
+
import { Joint, JointBodyA, JointBodyB } from "./components.js";
|
|
3
|
+
export declare const jointWithBothBodies: {
|
|
4
|
+
readonly all: readonly [typeof Joint, {
|
|
5
|
+
readonly target: readonly [typeof JointBodyA, readonly [typeof Body]];
|
|
6
|
+
}, {
|
|
7
|
+
readonly target: readonly [typeof JointBodyB, readonly [typeof Body]];
|
|
8
|
+
}];
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Body } from "../body/components.js";
|
|
2
|
+
import { Joint, JointBodyA, JointBodyB } from "./components.js";
|
|
3
|
+
// A joint is live only once BOTH connected bodies exist and carry a `Body`.
|
|
4
|
+
// `{ target: [JointBody*, [Body]] }` is a TargetTerm that fans out reactively when
|
|
5
|
+
// either target gains `Body`, so joint creation is order-independent (the joint
|
|
6
|
+
// entity can be created before, after, or between its bodies).
|
|
7
|
+
export const jointWithBothBodies = {
|
|
8
|
+
all: [Joint, { target: [JointBodyA, [Body]] }, { target: [JointBodyB, [Body]] }],
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=predicates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../../../../src/joints/predicates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEhE,4EAA4E;AAC5E,mFAAmF;AACnF,gFAAgF;AAChF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;CACxE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../../../src/kinematic/components.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,8EAA8E;AAC9E,yCAAyC;AAEzC,wDAAwD;AACxD,MAAM,OAAO,uBAAuB;IAApC;QACE,MAAC,GAAG,CAAC,CAAC;QACN,MAAC,GAAG,CAAC,CAAC;QACN,cAAS,GAAG,KAAK,CAAC;QAClB,SAAI,GAAG,IAAI,CAAC;IACd,CAAC;CAAA;AAED,kEAAkE;AAClE,MAAM,OAAO,uBAAuB;IAApC;QACE,UAAK,GAAG,CAAC,CAAC;QACV,cAAS,GAAG,KAAK,CAAC;QAClB,SAAI,GAAG,IAAI,CAAC;IACd,CAAC;CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Module } from "@vworlds/vecs";
|
|
2
|
+
import { BodyModule } from "../body/module.js";
|
|
3
|
+
import { PhysicsCoreModule } from "../core/module.js";
|
|
4
|
+
import { KinematicTargetPosition, KinematicTargetRotation } from "./components.js";
|
|
5
|
+
import { KinematicTargetsModule } from "./targets.js";
|
|
6
|
+
export class KinematicModule extends Module {
|
|
7
|
+
init() {
|
|
8
|
+
const world = this.world;
|
|
9
|
+
world.module(PhysicsCoreModule);
|
|
10
|
+
world.module(BodyModule);
|
|
11
|
+
world.component(KinematicTargetPosition);
|
|
12
|
+
world.component(KinematicTargetRotation);
|
|
13
|
+
world.module(KinematicTargetsModule);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=module.js.map
|