@margoengine/physics2d 0.1.0 → 1.0.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/LICENSE +201 -201
- package/NOTICE +4 -4
- package/README.md +566 -521
- package/dist/body.d.ts +19 -7
- package/dist/composites.d.ts +161 -0
- package/dist/composites.js +183 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +446 -101
- package/dist/joint.d.ts +129 -2
- package/dist/{kernel-D6zM0ozJ.js → kernel-DkjP8dvA.js} +1 -1
- package/dist/kernel.d.ts +5 -0
- package/dist/physics.d.ts +68 -0
- package/dist/physics2d-scalar.wasm +0 -0
- package/dist/physics2d.wasm +0 -0
- package/dist/shapes.d.ts +7 -0
- package/package.json +64 -60
package/dist/joint.d.ts
CHANGED
|
@@ -23,6 +23,13 @@ export interface MotorOptions2D {
|
|
|
23
23
|
export type JointOptions2D = {
|
|
24
24
|
anchorA?: Vec2D;
|
|
25
25
|
anchorB?: Vec2D;
|
|
26
|
+
/**
|
|
27
|
+
* Break the joint when it holds body B by more than this force, N (default none: it never breaks). It goes once a step is
|
|
28
|
+
* done, with a `jointbreak` event (Box2D's joint force threshold).
|
|
29
|
+
*/
|
|
30
|
+
breakForce?: number;
|
|
31
|
+
/** Break it when it holds body B by more than this torque, N m (default none). */
|
|
32
|
+
breakTorque?: number;
|
|
26
33
|
/** Let the two bodies collide with each other (default false). */
|
|
27
34
|
collide?: boolean;
|
|
28
35
|
/**
|
|
@@ -41,9 +48,18 @@ export type JointOptions2D = {
|
|
|
41
48
|
limits?: readonly [number, number];
|
|
42
49
|
motor?: MotorOptions2D;
|
|
43
50
|
} | {
|
|
51
|
+
/**
|
|
52
|
+
* Welds B to A. `linearHertz` and `angularHertz` (default 0, rigid) make the weld a spring on the point and on the
|
|
53
|
+
* angle with damping ratios `linearDampingRatio` and `angularDampingRatio` (default 1): Box2D's soft weld, Planck's
|
|
54
|
+
* `frequencyHz`, for a bending plank or a wobbly stack of parts.
|
|
55
|
+
*/
|
|
44
56
|
type: 'fixed';
|
|
45
57
|
angleA?: number;
|
|
46
58
|
angleB?: number;
|
|
59
|
+
linearHertz?: number;
|
|
60
|
+
angularHertz?: number;
|
|
61
|
+
linearDampingRatio?: number;
|
|
62
|
+
angularDampingRatio?: number;
|
|
47
63
|
} | {
|
|
48
64
|
/**
|
|
49
65
|
* Any mix of the three locks of a plane joint: `lockX` and `lockY` hold the anchors' offset along the first and the
|
|
@@ -69,6 +85,92 @@ export type JointOptions2D = {
|
|
|
69
85
|
restLength: number;
|
|
70
86
|
stiffness: number;
|
|
71
87
|
damping?: number;
|
|
88
|
+
} | {
|
|
89
|
+
/**
|
|
90
|
+
* Pulls body B's anchor to `target` (world units, a point in the world) by a spring of `hertz` (default 5) and damping
|
|
91
|
+
* ratio `damping` (default 0.7), its pull capped at `maxForce` N (default no cap): Box2D's and Planck's mouse joint,
|
|
92
|
+
* Matter's mouse constraint, for dragging a body. Body A only holds the target (a fixed body); move it with
|
|
93
|
+
* `joint.setTarget`. `anchorA` is ignored.
|
|
94
|
+
*/
|
|
95
|
+
type: 'target';
|
|
96
|
+
target: Vec2D;
|
|
97
|
+
hertz?: number;
|
|
98
|
+
damping?: number;
|
|
99
|
+
maxForce?: number;
|
|
100
|
+
} | {
|
|
101
|
+
/**
|
|
102
|
+
* Drives body B to sit `linearOffset` (world units, in A's frame, default [0, 0]) from A and turned `angularOffset`
|
|
103
|
+
* (radians, default 0) from it, at most `maxForce` N and `maxTorque` N m, taking back `correctionFactor` (0 to 1,
|
|
104
|
+
* default 0.3) of the error each substep: Box2D's and Planck.js's motor joint, to move a body by force (a platform, a
|
|
105
|
+
* character's body). The anchors are not used.
|
|
106
|
+
*/
|
|
107
|
+
type: 'motor';
|
|
108
|
+
linearOffset?: Vec2D;
|
|
109
|
+
angularOffset?: number;
|
|
110
|
+
maxForce: number;
|
|
111
|
+
maxTorque: number;
|
|
112
|
+
correctionFactor?: number;
|
|
113
|
+
} | {
|
|
114
|
+
/**
|
|
115
|
+
* Holds the relative speed at the anchors and the relative spin at zero, with at most `maxForce` N and `maxTorque` N m:
|
|
116
|
+
* Box2D's and Planck.js's friction joint, a top-down game's ground friction (body A the ground).
|
|
117
|
+
*/
|
|
118
|
+
type: 'friction';
|
|
119
|
+
maxForce: number;
|
|
120
|
+
maxTorque: number;
|
|
121
|
+
} | {
|
|
122
|
+
/**
|
|
123
|
+
* A wheel on a suspension (Box2D's and Planck.js's wheel joint): B's anchor rides the line through A's anchor along
|
|
124
|
+
* `axis` (A's frame), B turns freely, a spring of `hertz` (default 1; 0 for none) and damping ratio `damping` (default
|
|
125
|
+
* 0.7) pulls it back along the line whatever the load, `limits` bound the travel (world units) and `motor` drives the
|
|
126
|
+
* wheel's turn (radians).
|
|
127
|
+
*/
|
|
128
|
+
type: 'wheel';
|
|
129
|
+
axis: Vec2D;
|
|
130
|
+
hertz?: number;
|
|
131
|
+
damping?: number;
|
|
132
|
+
limits?: readonly [number, number];
|
|
133
|
+
motor?: MotorOptions2D;
|
|
134
|
+
} | {
|
|
135
|
+
/**
|
|
136
|
+
* A rope over two pulleys fixed in the world (Box2D's and Planck.js's pulley joint): A's anchor hangs from
|
|
137
|
+
* `groundA` and B's from `groundB` (world units), and A's strand plus `ratio` (default 1) times B's stays at
|
|
138
|
+
* `length` (world units, default the two strands' lengths when the joint is made). A ratio of 2 is a block and
|
|
139
|
+
* tackle: B moves half as far as A.
|
|
140
|
+
*/
|
|
141
|
+
type: 'pulley';
|
|
142
|
+
groundA: Vec2D;
|
|
143
|
+
groundB: Vec2D;
|
|
144
|
+
ratio?: number;
|
|
145
|
+
length?: number;
|
|
146
|
+
} | {
|
|
147
|
+
/**
|
|
148
|
+
* Box2D's distance joint: the anchors held `length` apart (world units, default their distance when the joint is
|
|
149
|
+
* made), rigidly, or by a `spring` of `hertz` and damping ratio `damping` (default 0.7) on the line's own
|
|
150
|
+
* effective mass (hertz 0 lets the length go free), kept within `limits` [min, max] (world units), with a `motor`
|
|
151
|
+
* on the length (world units). A rope is a distance joint with a spring of 0 Hz and an upper limit.
|
|
152
|
+
*/
|
|
153
|
+
type: 'distance';
|
|
154
|
+
length?: number;
|
|
155
|
+
spring?: {
|
|
156
|
+
hertz: number;
|
|
157
|
+
damping?: number;
|
|
158
|
+
};
|
|
159
|
+
limits?: readonly [number, number];
|
|
160
|
+
motor?: MotorOptions2D;
|
|
161
|
+
} | {
|
|
162
|
+
/**
|
|
163
|
+
* Gears two joints together (Planck.js's gear joint): `jointA`'s coordinate plus `ratio` (default 1, below 0 to turn
|
|
164
|
+
* the same way) times `jointB`'s stays as it was when the gear was made. Each is a revolute joint (its coordinate
|
|
165
|
+
* the turn, radians, past any number of turns) or a prismatic joint (its travel, world units) from its carrier (its
|
|
166
|
+
* body A, which may move: gears on a car's body) to this joint's body: `jointA` holds body A, `jointB` body B. Two
|
|
167
|
+
* gears of radii rA and rB mesh at ratio rB / rA; a pinion of radius r on a rack at ratio 1 / r or -1 / r, the sign
|
|
168
|
+
* setting which way the rack runs. Removing either joint removes the gear. The anchors are not used.
|
|
169
|
+
*/
|
|
170
|
+
type: 'gear';
|
|
171
|
+
jointA: Joint2D;
|
|
172
|
+
jointB: Joint2D;
|
|
173
|
+
ratio?: number;
|
|
72
174
|
});
|
|
73
175
|
/** @internal Writes a joint's buffer words (kernel/src/api.rs, `joint_create`) and returns the unit of its limits. */
|
|
74
176
|
export declare function writeJoint(kernel: Kernel, o: JointOptions2D, k: number): number;
|
|
@@ -83,20 +185,45 @@ export declare class Joint2D {
|
|
|
83
185
|
private readonly type;
|
|
84
186
|
private readonly unit;
|
|
85
187
|
private readonly onRemove;
|
|
188
|
+
/** Kernel metres a world unit. @internal */
|
|
189
|
+
private readonly scale;
|
|
190
|
+
/** The options it was made with (a gear reads its joints' carriers from them). @internal */
|
|
191
|
+
readonly spec?: JointOptions2D | undefined;
|
|
86
192
|
private removed;
|
|
87
193
|
/** @internal */
|
|
88
194
|
constructor(kernel: Kernel, world: number,
|
|
89
195
|
/** The kernel's handle. @internal */
|
|
90
|
-
handle: number, bodyA: Body2D, bodyB: Body2D, type: JointOptions2D['type'], unit: number, onRemove: (joint: Joint2D) => void
|
|
196
|
+
handle: number, bodyA: Body2D, bodyB: Body2D, type: JointOptions2D['type'], unit: number, onRemove: (joint: Joint2D) => void,
|
|
197
|
+
/** Kernel metres a world unit. @internal */
|
|
198
|
+
scale?: number,
|
|
199
|
+
/** The options it was made with (a gear reads its joints' carriers from them). @internal */
|
|
200
|
+
spec?: JointOptions2D | undefined);
|
|
201
|
+
/** A target joint's target: moves where it pulls body B's anchor to (world units), and wakes the bodies. */
|
|
202
|
+
setTarget(target: Vec2D): this;
|
|
91
203
|
private get limited();
|
|
92
|
-
/** Revolute: radians. Prismatic: world units. */
|
|
204
|
+
/** Revolute: radians. Prismatic and wheel: world units along the line. */
|
|
93
205
|
setLimits(min: number, max: number): this;
|
|
94
206
|
/** Removes the limits. */
|
|
95
207
|
clearLimits(): this;
|
|
96
208
|
setMotor(motor: MotorOptions2D): this;
|
|
97
209
|
/** Turns the motor off. */
|
|
98
210
|
clearMotor(): this;
|
|
211
|
+
/**
|
|
212
|
+
* The force this joint put on body B in its last step's last substep, N (kernel units, y down): how hard it holds B. Zero
|
|
213
|
+
* before its first step and, after a `restore`, until the next step.
|
|
214
|
+
*/
|
|
215
|
+
get force(): [number, number];
|
|
216
|
+
/** The torque this joint put on body B about B's centre of mass in its last substep, N m. */
|
|
217
|
+
get torque(): number;
|
|
218
|
+
/** @internal */
|
|
219
|
+
reaction(): [number, number, number];
|
|
220
|
+
/** Whether the joint was removed (by `remove`, its bodies' removal, or breaking). */
|
|
221
|
+
get isRemoved(): boolean;
|
|
99
222
|
remove(): void;
|
|
100
223
|
/** @internal */
|
|
101
224
|
free(): void;
|
|
102
225
|
}
|
|
226
|
+
/** A world point in `body`'s own frame, from its origin (world units). */
|
|
227
|
+
/** @internal A point in `body`'s frame, in the world. */
|
|
228
|
+
export declare function worldOf(body: Body2D, x: number, y: number): [number, number];
|
|
229
|
+
export declare function localTo(body: Body2D, x: number, y: number): [number, number];
|
|
@@ -147,7 +147,7 @@ async function p(e, t) {
|
|
|
147
147
|
return n = new f(await s(e, t, {
|
|
148
148
|
file: "physics2d.wasm",
|
|
149
149
|
version: "1",
|
|
150
|
-
interface:
|
|
150
|
+
interface: 3796861126,
|
|
151
151
|
imports: { env: {
|
|
152
152
|
clock: () => performance.now(),
|
|
153
153
|
hook_filter: (e, t) => n?.hooks ? +!!n.hooks.filter(e, t) : 1,
|
package/dist/kernel.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ interface Exports {
|
|
|
46
46
|
body_set_soft_ccd(world: number, body: number, distance: number): number;
|
|
47
47
|
project_point(world: number): number;
|
|
48
48
|
aabb_query(world: number): number;
|
|
49
|
+
explosion(world: number): number;
|
|
49
50
|
contacts_of(world: number, shape: number): number;
|
|
50
51
|
world_set_hooks(world: number, on: number): number;
|
|
51
52
|
world_snapshot(world: number): number;
|
|
@@ -58,12 +59,16 @@ interface Exports {
|
|
|
58
59
|
shape_move(world: number, shape: number): number;
|
|
59
60
|
shapes_join_seams(world: number, count: number): number;
|
|
60
61
|
shape_set_mass(world: number, shape: number, mode: number): number;
|
|
62
|
+
shape_set_rolling_resistance(world: number, shape: number, value: number): number;
|
|
63
|
+
shape_rolling_resistance(world: number, shape: number): number;
|
|
61
64
|
shape_mass(world: number, shape: number): number;
|
|
62
65
|
shape_read(world: number, shape: number): number;
|
|
63
66
|
joint_create(world: number, a: number, b: number, collide: number): number;
|
|
64
67
|
joint_remove(world: number, joint: number): number;
|
|
65
68
|
joint_set_limits(world: number, joint: number, has: number, lo: number, hi: number): number;
|
|
66
69
|
joint_set_motor(world: number, joint: number, has: number): number;
|
|
70
|
+
joint_force(world: number, joint: number): number;
|
|
71
|
+
joint_set_anchor_a(world: number, joint: number, x: number, y: number): number;
|
|
67
72
|
events_read(world: number): number;
|
|
68
73
|
force_events_read(world: number): number;
|
|
69
74
|
ray_cast(world: number): number;
|
package/dist/physics.d.ts
CHANGED
|
@@ -62,6 +62,12 @@ export interface CollisionEvent2D {
|
|
|
62
62
|
colliderB: Collider2D;
|
|
63
63
|
/** True when either collider is a sensor. */
|
|
64
64
|
sensor: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* For `contactstart`: the contact as it began (Planck's world manifold, Matter's collision, Box2D's hit event): the
|
|
67
|
+
* normal from A to B, its points and how fast the two closed (`ContactPair2D.approachSpeed`). Absent on the other
|
|
68
|
+
* events.
|
|
69
|
+
*/
|
|
70
|
+
contact?: ContactPair2D;
|
|
65
71
|
}
|
|
66
72
|
/** A contact pushed with more total force than a collider's `contactForceThreshold` in the last step. */
|
|
67
73
|
export interface ContactForceEvent2D {
|
|
@@ -85,6 +91,22 @@ export interface Physics2DEventMap {
|
|
|
85
91
|
/** Before each fixed step, with the step length. Drive character controllers and kinematic bodies here. */
|
|
86
92
|
beforestep: number;
|
|
87
93
|
afterstep: number;
|
|
94
|
+
/** A joint held body B past its `breakForce` or `breakTorque` and was removed (once the step was done). */
|
|
95
|
+
jointbreak: JointBreakEvent2D;
|
|
96
|
+
/** A dynamic body fell asleep this step (Matter.js's `sleepStart`); watched only while a `sleep` or `wake` listener is on. */
|
|
97
|
+
sleep: SleepEvent2D;
|
|
98
|
+
/** A sleeping dynamic body woke this step (Matter.js's `sleepEnd`), by a contact, a joint or a call. */
|
|
99
|
+
wake: SleepEvent2D;
|
|
100
|
+
}
|
|
101
|
+
/** A body that fell asleep or woke. */
|
|
102
|
+
export interface SleepEvent2D {
|
|
103
|
+
body: Body2D;
|
|
104
|
+
}
|
|
105
|
+
/** A joint that broke: it, and the force (N) and torque (N m) it held body B by in its last substep. */
|
|
106
|
+
export interface JointBreakEvent2D {
|
|
107
|
+
joint: Joint2D;
|
|
108
|
+
force: [number, number];
|
|
109
|
+
torque: number;
|
|
88
110
|
}
|
|
89
111
|
/** A closest point of a collider to a point. */
|
|
90
112
|
export interface ProjectedPoint2D extends Hit2D {
|
|
@@ -105,6 +127,11 @@ export interface ContactPair2D {
|
|
|
105
127
|
distance: number;
|
|
106
128
|
}>;
|
|
107
129
|
impulse: number;
|
|
130
|
+
/**
|
|
131
|
+
* How fast the two closed along the normal when the last step began, world units a second (0 or more): a hit's
|
|
132
|
+
* strength, Box2D's hit-event approach speed, for sounds and damage. 0 for a sensor's overlap.
|
|
133
|
+
*/
|
|
134
|
+
approachSpeed: number;
|
|
108
135
|
solverActive: boolean;
|
|
109
136
|
touching: boolean;
|
|
110
137
|
}
|
|
@@ -156,6 +183,19 @@ export type DebugColour2D = 'fixed' | 'awake' | 'sleeping' | 'kinematic' | 'sens
|
|
|
156
183
|
/** Colours for the lines of `debugRender`: red, green, blue and alpha from 0 to 1 for any of the kinds; the others keep the defaults. */
|
|
157
184
|
export type DebugStyle2D = Partial<Record<DebugColour2D, readonly [number, number, number, number]>>;
|
|
158
185
|
/** Limits which colliders a scene query can hit. */
|
|
186
|
+
/** {@link Physics2D.explode}'s blast. */
|
|
187
|
+
export interface Explosion2D {
|
|
188
|
+
/** The blast's centre, world units. */
|
|
189
|
+
position: Vec2D;
|
|
190
|
+
/** Within this distance (world units) a shape takes the full push. */
|
|
191
|
+
radius: number;
|
|
192
|
+
/** Past `radius` the push falls linearly to nothing over this distance (world units, default 0). */
|
|
193
|
+
falloff?: number;
|
|
194
|
+
/** The impulse a metre of a shape's width facing the blast takes, N s per metre (kernel units). */
|
|
195
|
+
impulsePerLength: number;
|
|
196
|
+
/** Which colliders it pushes (groups, an excluded collider or body, a predicate), as the queries take. */
|
|
197
|
+
filter?: QueryFilter2D;
|
|
198
|
+
}
|
|
159
199
|
export interface QueryFilter2D {
|
|
160
200
|
/** Packed interaction groups of the query, see `interactionGroups`. */
|
|
161
201
|
groups?: number;
|
|
@@ -299,10 +339,17 @@ export declare class Physics2D implements EnginePlugin, BodyOwner2D {
|
|
|
299
339
|
private readonly bodies;
|
|
300
340
|
private movers;
|
|
301
341
|
private readonly byShape;
|
|
342
|
+
private nextColliderUid;
|
|
343
|
+
private readonly touchingPairs;
|
|
344
|
+
private readonly carriedPairs;
|
|
302
345
|
private readonly joints;
|
|
303
346
|
private readonly controllers;
|
|
304
347
|
private readonly listeners;
|
|
305
348
|
private readonly events;
|
|
349
|
+
/** Joints with a break threshold: force (N) and torque (N m). */
|
|
350
|
+
private readonly breakable;
|
|
351
|
+
/** Each gear with the two joints it gears. */
|
|
352
|
+
private gears;
|
|
306
353
|
private dispatching;
|
|
307
354
|
private syncAlpha;
|
|
308
355
|
private gravityValue;
|
|
@@ -412,6 +459,8 @@ export declare class Physics2D implements EnginePlugin, BodyOwner2D {
|
|
|
412
459
|
step(): void;
|
|
413
460
|
/** Reads every moving body's pose in one call. */
|
|
414
461
|
private readPoses;
|
|
462
|
+
private pairKey;
|
|
463
|
+
private pushCollisionEvent;
|
|
415
464
|
private collectEvents;
|
|
416
465
|
/** Writes body poses to their sprites, interpolated by `alpha` between the last two steps. */
|
|
417
466
|
sync(alpha?: number): void;
|
|
@@ -428,6 +477,8 @@ export declare class Physics2D implements EnginePlugin, BodyOwner2D {
|
|
|
428
477
|
addTileMap(map: TileMapSource, options?: TileMapBodyOptions): Body2D;
|
|
429
478
|
/** @internal */
|
|
430
479
|
addCollider(body: Body2D, options: ColliderOptions2D): Collider2D;
|
|
480
|
+
/** @internal Replaces a collider's kernel shapes in place for multi-shape or non-convex `setShape`. */
|
|
481
|
+
replaceColliderShapes(collider: Collider2D, shape: ShapeOptions2D, parts: Described[]): void;
|
|
431
482
|
private createShapes;
|
|
432
483
|
/** @internal */
|
|
433
484
|
removeCollider(collider: Collider2D): void;
|
|
@@ -446,6 +497,14 @@ export declare class Physics2D implements EnginePlugin, BodyOwner2D {
|
|
|
446
497
|
* true and `distance` the way to that point (Rapier's `projectPoint(point, solid)`).
|
|
447
498
|
*/
|
|
448
499
|
projectPoint(point: Vec2D, filter?: QueryFilter2D, solid?: boolean): ProjectedPoint2D | null;
|
|
500
|
+
/**
|
|
501
|
+
* Pushes the dynamic bodies around a blast (Box2D's explosion): each circle, capsule and polygon within `radius` plus
|
|
502
|
+
* `falloff` of `position` takes an impulse away from the centre at its nearest point, `impulsePerLength` times the width
|
|
503
|
+
* it shows the blast (its extent across the line to the centre), in full within `radius` and falling linearly to
|
|
504
|
+
* nothing over `falloff`. A shape the centre is inside is pushed through its centre of mass. Segments, chains, voxels
|
|
505
|
+
* and sensors are not pushed. Returns the colliders pushed.
|
|
506
|
+
*/
|
|
507
|
+
explode(blast: Explosion2D): Collider2D[];
|
|
449
508
|
/** The bodies with a collider whose bounds meet the box from `min` to `max` (world units). */
|
|
450
509
|
intersectionsWithBox(min: Vec2D, max: Vec2D, filter?: QueryFilter2D): Body2D[];
|
|
451
510
|
/**
|
|
@@ -478,7 +537,11 @@ export declare class Physics2D implements EnginePlugin, BodyOwner2D {
|
|
|
478
537
|
private anchor;
|
|
479
538
|
/** Joins two bodies. Anchors are in each body's local space, world units. */
|
|
480
539
|
addJoint(bodyA: Body2D, bodyB: Body2D, options: JointOptions2D): Joint2D;
|
|
540
|
+
/** Removes each breakable joint that held body B past its threshold this step, and reports it. */
|
|
541
|
+
private breakJoints;
|
|
481
542
|
removeJoint(joint: Joint2D): void;
|
|
543
|
+
/** A gear's two sides from the joints it gears: each joint's body B is the gear's body, its body A the carrier. */
|
|
544
|
+
private gearSides;
|
|
482
545
|
/**
|
|
483
546
|
* Joins bodies into a tree of one-degree-of-freedom joints hanging from `root` and gives the whole its joint space: see
|
|
484
547
|
* {@link Articulation2D}. `links` come parent before child.
|
|
@@ -522,6 +585,7 @@ export declare class Physics2D implements EnginePlugin, BodyOwner2D {
|
|
|
522
585
|
* @throws RangeError when `bytes` is not a snapshot of this package.
|
|
523
586
|
*/
|
|
524
587
|
restore(bytes: Uint8Array): void;
|
|
588
|
+
private resyncTouchingPairs;
|
|
525
589
|
/**
|
|
526
590
|
* Lines that draw the world, in world units: `vertices` holds x1, y1, x2, y2 for each line, `colors` its colour code (0 fixed, 1 awake,
|
|
527
591
|
* 2 sleeping, 3 kinematic, 4 sensor, 5 joint, 6 contact point, 7 contact normal, 8 broad phase box, 9 and 10 a body's x and y axes,
|
|
@@ -542,6 +606,10 @@ export declare class Physics2D implements EnginePlugin, BodyOwner2D {
|
|
|
542
606
|
}): DebugLines2D;
|
|
543
607
|
/** Adds a listener; returns a function that removes it. */
|
|
544
608
|
on<K extends keyof Physics2DEventMap>(type: K, listener: (event: Physics2DEventMap[K]) => void): () => void;
|
|
609
|
+
/** Each dynamic body's sleep as of the last step, kept while a `sleep` or `wake` listener is on (null otherwise). */
|
|
610
|
+
private asleep;
|
|
611
|
+
/** The dynamic bodies whose sleep changed since the last step, as `sleep` and `wake` events. */
|
|
612
|
+
private sleepEvents;
|
|
545
613
|
private emit;
|
|
546
614
|
dispose(): void;
|
|
547
615
|
[Symbol.dispose]: () => void;
|
|
Binary file
|
package/dist/physics2d.wasm
CHANGED
|
Binary file
|
package/dist/shapes.d.ts
CHANGED
|
@@ -119,6 +119,13 @@ export interface ColliderSettings2D {
|
|
|
119
119
|
rotation?: number;
|
|
120
120
|
friction?: number;
|
|
121
121
|
restitution?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Coefficient of rolling resistance, 0 or more (default 0, none; Box2D's rolling resistance): a contact resists the
|
|
124
|
+
* two bodies' relative turn with a torque of up to this times its normal force times the rolling radius (the larger
|
|
125
|
+
* of the two shapes' core radii: a circle's or capsule's radius), so a rolling ball slows and stops. Of two colliders
|
|
126
|
+
* the larger applies. Car tyres on tarmac are about 0.01, a steel wheel on rail 0.001, a ball on grass 0.05 to 0.1.
|
|
127
|
+
*/
|
|
128
|
+
rollingResistance?: number;
|
|
122
129
|
/**
|
|
123
130
|
* How a contact combines this collider's friction with the other's (default `CoefficientCombineRule2D.Average`): of two
|
|
124
131
|
* colliders' rules the later of Average, Min, Multiply, Max, ClampedSum, GeometricMean wins, as in Rapier.
|
package/package.json
CHANGED
|
@@ -1,60 +1,64 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@margoengine/physics2d",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "2D rigid-body physics for Margo Engine on its own 2D kernel (Rust to Wasm): fixed-step plugin with interpolation, sprite-driven bodies, joints, queries, events, a character controller and tile map colliders.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"margoengine",
|
|
7
|
-
"webgpu",
|
|
8
|
-
"2d",
|
|
9
|
-
"physics",
|
|
10
|
-
"wasm"
|
|
11
|
-
],
|
|
12
|
-
"homepage": "https://margoengine.com",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
19
|
-
"directory": "packages/physics2d"
|
|
20
|
-
},
|
|
21
|
-
"license": "Apache-2.0",
|
|
22
|
-
"author": "Scott Campbell",
|
|
23
|
-
"type": "module",
|
|
24
|
-
"publishConfig": {
|
|
25
|
-
"access": "public"
|
|
26
|
-
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "node scripts/build.js",
|
|
29
|
-
"test": "npm run build && node --test tests/*.test.js",
|
|
30
|
-
"prepack": "npm run build",
|
|
31
|
-
"test:gpu:kernel-browsers": "cd ../.. && npm run test:physics2d-kernel-browsers"
|
|
32
|
-
},
|
|
33
|
-
"sideEffects": false,
|
|
34
|
-
"exports": {
|
|
35
|
-
".": {
|
|
36
|
-
"types": "./dist/index.d.ts",
|
|
37
|
-
"import": "./dist/index.js"
|
|
38
|
-
},
|
|
39
|
-
"./outline": {
|
|
40
|
-
"types": "./dist/outline.d.ts",
|
|
41
|
-
"import": "./dist/outline.js"
|
|
42
|
-
},
|
|
43
|
-
"./
|
|
44
|
-
"types": "./dist/
|
|
45
|
-
"import": "./dist/
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
"@margoengine/
|
|
59
|
-
|
|
60
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@margoengine/physics2d",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "2D rigid-body physics for Margo Engine on its own 2D kernel (Rust to Wasm): fixed-step plugin with interpolation, sprite-driven bodies, joints, queries, events, a character controller and tile map colliders.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"margoengine",
|
|
7
|
+
"webgpu",
|
|
8
|
+
"2d",
|
|
9
|
+
"physics",
|
|
10
|
+
"wasm"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://margoengine.com",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
19
|
+
"directory": "packages/physics2d"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"author": "Scott Campbell",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "node scripts/build.js",
|
|
29
|
+
"test": "npm run build && node --test tests/*.test.js",
|
|
30
|
+
"prepack": "npm run build",
|
|
31
|
+
"test:gpu:kernel-browsers": "cd ../.. && npm run test:physics2d-kernel-browsers"
|
|
32
|
+
},
|
|
33
|
+
"sideEffects": false,
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./outline": {
|
|
40
|
+
"types": "./dist/outline.d.ts",
|
|
41
|
+
"import": "./dist/outline.js"
|
|
42
|
+
},
|
|
43
|
+
"./composites": {
|
|
44
|
+
"types": "./dist/composites.d.ts",
|
|
45
|
+
"import": "./dist/composites.js"
|
|
46
|
+
},
|
|
47
|
+
"./vehicle": {
|
|
48
|
+
"types": "./dist/vehicle.d.ts",
|
|
49
|
+
"import": "./dist/vehicle.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"LICENSE",
|
|
55
|
+
"NOTICE"
|
|
56
|
+
],
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@margoengine/geometry": "^1.0.0",
|
|
59
|
+
"@margoengine/math": "^1.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@margoengine/core": "^1.0.0"
|
|
63
|
+
}
|
|
64
|
+
}
|