@absolutejs/rapier3d 0.0.0-stage → 0.1.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.
Files changed (50) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +56 -2
  3. package/absolutejs/README.md +57 -0
  4. package/dist/provenance.json +10 -0
  5. package/dist/rapier.mjs +1 -0
  6. package/dist/types/coarena.d.ts +15 -0
  7. package/dist/types/control/character_controller.d.ts +191 -0
  8. package/dist/types/control/index.d.ts +3 -0
  9. package/dist/types/control/pid_controller.d.ts +50 -0
  10. package/dist/types/control/ray_cast_vehicle_controller.d.ts +277 -0
  11. package/dist/types/dynamics/ccd_solver.d.ts +15 -0
  12. package/dist/types/dynamics/coefficient_combine_rule.d.ts +13 -0
  13. package/dist/types/dynamics/impulse_joint.d.ts +359 -0
  14. package/dist/types/dynamics/impulse_joint_set.d.ts +84 -0
  15. package/dist/types/dynamics/index.d.ts +12 -0
  16. package/dist/types/dynamics/integration_parameters.d.ts +101 -0
  17. package/dist/types/dynamics/island_manager.d.ts +24 -0
  18. package/dist/types/dynamics/multibody_joint.d.ts +42 -0
  19. package/dist/types/dynamics/multibody_joint_set.d.ts +81 -0
  20. package/dist/types/dynamics/rigid_body.d.ts +839 -0
  21. package/dist/types/dynamics/rigid_body_set.d.ts +90 -0
  22. package/dist/types/dynamics/soft_body.d.ts +1210 -0
  23. package/dist/types/dynamics/soft_body_set.d.ts +99 -0
  24. package/dist/types/exports.d.ts +8 -0
  25. package/dist/types/geometry/broad_phase.d.ts +162 -0
  26. package/dist/types/geometry/collider.d.ts +1016 -0
  27. package/dist/types/geometry/collider_set.d.ts +97 -0
  28. package/dist/types/geometry/contact.d.ts +36 -0
  29. package/dist/types/geometry/feature.d.ts +6 -0
  30. package/dist/types/geometry/index.d.ts +11 -0
  31. package/dist/types/geometry/interaction_groups.d.ts +18 -0
  32. package/dist/types/geometry/narrow_phase.d.ts +140 -0
  33. package/dist/types/geometry/point.d.ts +58 -0
  34. package/dist/types/geometry/ray.d.ts +108 -0
  35. package/dist/types/geometry/shape.d.ts +681 -0
  36. package/dist/types/geometry/toi.d.ts +59 -0
  37. package/dist/types/init.d.ts +3 -0
  38. package/dist/types/math.d.ts +98 -0
  39. package/dist/types/pipeline/debug_render_pipeline.d.ts +40 -0
  40. package/dist/types/pipeline/event_queue.d.ts +113 -0
  41. package/dist/types/pipeline/index.d.ts +7 -0
  42. package/dist/types/pipeline/physics_hooks.d.ts +39 -0
  43. package/dist/types/pipeline/physics_pipeline.d.ts +12 -0
  44. package/dist/types/pipeline/query_pipeline.d.ts +38 -0
  45. package/dist/types/pipeline/serialization_pipeline.d.ts +37 -0
  46. package/dist/types/pipeline/world.d.ts +674 -0
  47. package/dist/types/rapier.d.ts +3 -0
  48. package/dist/types/rapier_wasm3d.d.ts +2908 -0
  49. package/dist/types/raw.d.ts +1 -0
  50. package/package.json +33 -4
@@ -0,0 +1,59 @@
1
+ import { Collider } from "./collider";
2
+ import { Vector } from "../math";
3
+ /**
4
+ * The result of a shape-cast between two shapes, returned by the pairwise casts
5
+ * `Shape.castShape` and `Collider.castShape`.
6
+ *
7
+ * The first shape is the one the cast is called on (the shape or collider `this`), and the
8
+ * second shape is the `shape2` argument. Each witness point and normal is expressed in the
9
+ * local-space of its own shape, i.e., relative to that shape's pose (it does not depend on
10
+ * the shape's translation along the cast).
11
+ */
12
+ export declare class ShapeCastHit {
13
+ /**
14
+ * The time of impact of the two shapes.
15
+ */
16
+ time_of_impact: number;
17
+ /**
18
+ * The contact point on the first shape at the time of impact, expressed in the
19
+ * local-space of the first shape.
20
+ */
21
+ witness1: Vector;
22
+ /**
23
+ * The contact point on the second shape at the time of impact, expressed in the
24
+ * local-space of the second shape.
25
+ */
26
+ witness2: Vector;
27
+ /**
28
+ * The outward normal on the first shape at the time of impact, expressed in the
29
+ * local-space of the first shape.
30
+ */
31
+ normal1: Vector;
32
+ /**
33
+ * The outward normal on the second shape at the time of impact, expressed in the
34
+ * local-space of the second shape.
35
+ */
36
+ normal2: Vector;
37
+ constructor(time_of_impact: number, witness1: Vector, witness2: Vector, normal1: Vector, normal2: Vector);
38
+ static fromBuffer(collider: Collider, buffer: Float32Array, target?: ShapeCastHit): ShapeCastHit;
39
+ }
40
+ /**
41
+ * The result of a shape-cast that hit a collider.
42
+ *
43
+ * The frames of the witness points and normals depend on the query that returned it:
44
+ * - `World.castShape` (and `BroadPhase.castShape`): `witness1` and `normal1` lie on the hit
45
+ * `collider` and are expressed in world-space; `witness2` and `normal2` lie on the cast
46
+ * shape and are expressed in its local-space (relative to its pose, so they do not depend
47
+ * on its translation along the cast).
48
+ * - `Collider.castCollider`: `witness1` and `normal1` lie on the collider the cast is called
49
+ * on and are expressed in its local-space; `witness2` and `normal2` lie on the hit
50
+ * `collider` (the `collider2` argument) and are expressed in its local-space.
51
+ */
52
+ export declare class ColliderShapeCastHit extends ShapeCastHit {
53
+ /**
54
+ * The collider hit by the shape-cast.
55
+ */
56
+ collider: Collider;
57
+ constructor(collider: Collider, time_of_impact: number, witness1: Vector, witness2: Vector, normal1: Vector, normal2: Vector);
58
+ static fromBuffer(collider: Collider, buffer: Float32Array, target?: ColliderShapeCastHit): ColliderShapeCastHit;
59
+ }
@@ -0,0 +1,3 @@
1
+ import { type InitInput } from './rapier_wasm3d.js';
2
+ /** Initialize once; concurrent callers share the same initialization. */
3
+ export declare function init(input?: InitInput | Promise<InitInput>): Promise<void>;
@@ -0,0 +1,98 @@
1
+ import { RawVector, RawRotation } from "./raw";
2
+ import { RawSdpMatrix3 } from "./raw";
3
+ export declare const scratchBuffer: Float32Array<ArrayBuffer>;
4
+ export interface Vector {
5
+ x: number;
6
+ y: number;
7
+ z: number;
8
+ }
9
+ /**
10
+ * A 3D vector.
11
+ */
12
+ export declare class Vector3 implements Vector {
13
+ x: number;
14
+ y: number;
15
+ z: number;
16
+ constructor(x: number, y: number, z: number);
17
+ }
18
+ export declare class VectorOps {
19
+ static new(x: number, y: number, z: number): Vector;
20
+ static intoRaw(v: Vector): RawVector;
21
+ static zeros(): Vector;
22
+ static fromBuffer(buffer: Float32Array, target?: Vector): Vector;
23
+ static fromRaw(raw: RawVector): Vector;
24
+ static copy(out: Vector, input: Vector): void;
25
+ }
26
+ export interface Rotation {
27
+ x: number;
28
+ y: number;
29
+ z: number;
30
+ w: number;
31
+ }
32
+ /**
33
+ * A quaternion.
34
+ */
35
+ export declare class Quaternion implements Rotation {
36
+ x: number;
37
+ y: number;
38
+ z: number;
39
+ w: number;
40
+ constructor(x: number, y: number, z: number, w: number);
41
+ }
42
+ export declare class RotationOps {
43
+ static identity(): Rotation;
44
+ static fromBuffer(buffer: Float32Array, target?: Rotation): Rotation;
45
+ static fromRaw(raw: RawRotation): Rotation;
46
+ static intoRaw(rot: Rotation): RawRotation;
47
+ static copy(out: Rotation, input: Rotation): void;
48
+ }
49
+ /**
50
+ * A 3D symmetric-positive-definite matrix.
51
+ */
52
+ export declare class SdpMatrix3 {
53
+ /**
54
+ * Row major list of the upper-triangular part of the symmetric matrix.
55
+ */
56
+ elements: Float32Array;
57
+ /**
58
+ * Matrix element at row 1, column 1.
59
+ */
60
+ get m11(): number;
61
+ /**
62
+ * Matrix element at row 1, column 2.
63
+ */
64
+ get m12(): number;
65
+ /**
66
+ * Matrix element at row 2, column 1.
67
+ */
68
+ get m21(): number;
69
+ /**
70
+ * Matrix element at row 1, column 3.
71
+ */
72
+ get m13(): number;
73
+ /**
74
+ * Matrix element at row 3, column 1.
75
+ */
76
+ get m31(): number;
77
+ /**
78
+ * Matrix element at row 2, column 2.
79
+ */
80
+ get m22(): number;
81
+ /**
82
+ * Matrix element at row 2, column 3.
83
+ */
84
+ get m23(): number;
85
+ /**
86
+ * Matrix element at row 3, column 2.
87
+ */
88
+ get m32(): number;
89
+ /**
90
+ * Matrix element at row 3, column 3.
91
+ */
92
+ get m33(): number;
93
+ constructor(elements: Float32Array);
94
+ }
95
+ export declare class SdpMatrix3Ops {
96
+ static fromBuffer(buffer: Float32Array, target?: SdpMatrix3): SdpMatrix3;
97
+ static fromRaw(raw: RawSdpMatrix3): SdpMatrix3;
98
+ }
@@ -0,0 +1,40 @@
1
+ import { RawDebugRenderPipeline } from "../raw";
2
+ import { ImpulseJointSet, MultibodyJointSet, RigidBodySet, SoftBodySet } from "../dynamics";
3
+ import { Collider, ColliderSet, NarrowPhase } from "../geometry";
4
+ import { QueryFilterFlags } from "./query_pipeline";
5
+ /**
6
+ * The vertex and color buffers for debug-rendering the physics scene.
7
+ */
8
+ export declare class DebugRenderBuffers {
9
+ /**
10
+ * The lines to render. This is a flat array containing all the lines
11
+ * to render. Each line is described as two consecutive point. Each
12
+ * point is described as two (in 2D) or three (in 3D) consecutive
13
+ * floats. For example, in 2D, the array: `[1, 2, 3, 4, 5, 6, 7, 8]`
14
+ * describes the two segments `[[1, 2], [3, 4]]` and `[[5, 6], [7, 8]]`.
15
+ */
16
+ vertices: Float32Array;
17
+ /**
18
+ * The color buffer. There is one color per vertex, and each color
19
+ * has four consecutive components (in RGBA format).
20
+ */
21
+ colors: Float32Array;
22
+ constructor(vertices: Float32Array, colors: Float32Array);
23
+ }
24
+ /**
25
+ * A pipeline for rendering the physics scene.
26
+ *
27
+ * To avoid leaking WASM resources, this MUST be freed manually with `debugRenderPipeline.free()`
28
+ * once you are done using it (and all the rigid-bodies it created).
29
+ */
30
+ export declare class DebugRenderPipeline {
31
+ raw: RawDebugRenderPipeline;
32
+ vertices: Float32Array;
33
+ colors: Float32Array;
34
+ /**
35
+ * Release the WASM memory occupied by this serialization pipeline.
36
+ */
37
+ free(): void;
38
+ constructor(raw?: RawDebugRenderPipeline);
39
+ render(bodies: RigidBodySet, colliders: ColliderSet, soft_bodies: SoftBodySet, impulse_joints: ImpulseJointSet, multibody_joints: MultibodyJointSet, narrow_phase: NarrowPhase, filterFlags?: QueryFilterFlags, filterPredicate?: (collider: Collider) => boolean): void;
40
+ }
@@ -0,0 +1,113 @@
1
+ import { RawContactForceEvent, RawEventQueue } from "../raw";
2
+ import { SoftBodyTearEvent } from "../dynamics";
3
+ import { ColliderHandle } from "../geometry";
4
+ import { Vector } from "../math";
5
+ /**
6
+ * Flags indicating what events are enabled for colliders.
7
+ */
8
+ export declare enum ActiveEvents {
9
+ NONE = 0,
10
+ /**
11
+ * Enable collision events.
12
+ */
13
+ COLLISION_EVENTS = 1,
14
+ /**
15
+ * Enable contact force events.
16
+ */
17
+ CONTACT_FORCE_EVENTS = 2
18
+ }
19
+ /**
20
+ * Event occurring when the sum of the magnitudes of the
21
+ * contact forces between two colliders exceed a threshold.
22
+ *
23
+ * This object should **not** be stored anywhere. Its properties can only be
24
+ * read from within the closure given to `EventHandler.drainContactForceEvents`.
25
+ */
26
+ export declare class TempContactForceEvent {
27
+ raw: RawContactForceEvent;
28
+ free(): void;
29
+ /**
30
+ * The first collider involved in the contact.
31
+ */
32
+ collider1(): ColliderHandle;
33
+ /**
34
+ * The second collider involved in the contact.
35
+ */
36
+ collider2(): ColliderHandle;
37
+ /**
38
+ * The sum of all the forces between the two colliders.
39
+ */
40
+ totalForce(target?: Vector): Vector;
41
+ /**
42
+ * The sum of the magnitudes of each force between the two colliders.
43
+ *
44
+ * Note that this is **not** the same as the magnitude of `self.total_force`.
45
+ * Here we are summing the magnitude of all the forces, instead of taking
46
+ * the magnitude of their sum.
47
+ */
48
+ totalForceMagnitude(): number;
49
+ /**
50
+ * The world-space (unit) direction of the force with strongest magnitude.
51
+ */
52
+ maxForceDirection(target?: Vector): Vector;
53
+ /**
54
+ * The magnitude of the largest force at a contact point of this contact pair.
55
+ */
56
+ maxForceMagnitude(): number;
57
+ }
58
+ /**
59
+ * A structure responsible for collecting events generated
60
+ * by the physics engine.
61
+ *
62
+ * To avoid leaking WASM resources, this MUST be freed manually with `eventQueue.free()`
63
+ * once you are done using it.
64
+ */
65
+ export declare class EventQueue {
66
+ raw: RawEventQueue;
67
+ /**
68
+ * Creates a new event collector.
69
+ *
70
+ * @param autoDrain -setting this to `true` is strongly recommended. If true, the collector will
71
+ * be automatically drained before each `world.step(collector)`. If false, the collector will
72
+ * keep all events in memory unless it is manually drained/cleared; this may lead to unbounded use of
73
+ * RAM if no drain is performed.
74
+ */
75
+ constructor(autoDrain: boolean, raw?: RawEventQueue);
76
+ /**
77
+ * Release the WASM memory occupied by this event-queue.
78
+ */
79
+ free(): void;
80
+ /**
81
+ * Applies the given javascript closure on each collision event of this collector, then clear
82
+ * the internal collision event buffer.
83
+ *
84
+ * @param f - JavaScript closure applied to each collision event. The
85
+ * closure must take three arguments: two integers representing the handles of the colliders
86
+ * involved in the collision, and a boolean indicating if the collision started (true) or stopped
87
+ * (false).
88
+ */
89
+ drainCollisionEvents(f: (handle1: ColliderHandle, handle2: ColliderHandle, started: boolean) => void): void;
90
+ /**
91
+ * Applies the given javascript closure on each contact force event of this collector, then clear
92
+ * the internal collision event buffer.
93
+ *
94
+ * @param f - JavaScript closure applied to each collision event. The
95
+ * closure must take one `TempContactForceEvent` argument.
96
+ */
97
+ drainContactForceEvents(f: (event: TempContactForceEvent) => void): void;
98
+ /**
99
+ * Applies the given javascript closure on each soft-body tear event of this collector,
100
+ * then clears the internal tear event buffer.
101
+ *
102
+ * The pieces a tear split off are only wrapped once `World.mapNewSoftBodies` (called by
103
+ * `World.step` after draining) ran; the event itself is only valid inside the closure.
104
+ *
105
+ * @param f - JavaScript closure applied to each tear event. The closure must take one
106
+ * `SoftBodyTearEvent` argument.
107
+ */
108
+ drainSoftBodyTearEvents(f: (event: SoftBodyTearEvent) => void): void;
109
+ /**
110
+ * Removes all events contained by this collector
111
+ */
112
+ clear(): void;
113
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./world";
2
+ export * from "./physics_pipeline";
3
+ export * from "./serialization_pipeline";
4
+ export * from "./event_queue";
5
+ export * from "./physics_hooks";
6
+ export * from "./debug_render_pipeline";
7
+ export * from "./query_pipeline";
@@ -0,0 +1,39 @@
1
+ import { RigidBodyHandle } from "../dynamics";
2
+ import { ColliderHandle } from "../geometry";
3
+ export declare enum ActiveHooks {
4
+ NONE = 0,
5
+ FILTER_CONTACT_PAIRS = 1,
6
+ FILTER_INTERSECTION_PAIRS = 2
7
+ }
8
+ export declare enum SolverFlags {
9
+ EMPTY = 0,
10
+ COMPUTE_IMPULSE = 1
11
+ }
12
+ export interface PhysicsHooks {
13
+ /**
14
+ * Function that determines if contacts computation should happen between two colliders, and how the
15
+ * constraints solver should behave for these contacts.
16
+ *
17
+ * This will only be executed and taken into account if at least one of the involved colliders contains the
18
+ * `ActiveHooks.FILTER_CONTACT_PAIR` flag in its active hooks.
19
+ *
20
+ * @param collider1 − Handle of the first collider involved in the potential contact.
21
+ * @param collider2 − Handle of the second collider involved in the potential contact.
22
+ * @param body1 − Handle of the first body involved in the potential contact.
23
+ * @param body2 − Handle of the second body involved in the potential contact.
24
+ */
25
+ filterContactPair(collider1: ColliderHandle, collider2: ColliderHandle, body1: RigidBodyHandle, body2: RigidBodyHandle): SolverFlags | null;
26
+ /**
27
+ * Function that determines if intersection computation should happen between two colliders (where at least
28
+ * one is a sensor).
29
+ *
30
+ * This will only be executed and taken into account if `one of the involved colliders contains the
31
+ * `ActiveHooks.FILTER_INTERSECTION_PAIR` flag in its active hooks.
32
+ *
33
+ * @param collider1 − Handle of the first collider involved in the potential contact.
34
+ * @param collider2 − Handle of the second collider involved in the potential contact.
35
+ * @param body1 − Handle of the first body involved in the potential contact.
36
+ * @param body2 − Handle of the second body involved in the potential contact.
37
+ */
38
+ filterIntersectionPair(collider1: ColliderHandle, collider2: ColliderHandle, body1: RigidBodyHandle, body2: RigidBodyHandle): boolean;
39
+ }
@@ -0,0 +1,12 @@
1
+ import { RawPhysicsPipeline } from "../raw";
2
+ import { Vector } from "../math";
3
+ import { IntegrationParameters, ImpulseJointSet, MultibodyJointSet, RigidBodySet, CCDSolver, IslandManager, SoftBodySet } from "../dynamics";
4
+ import { BroadPhase, ColliderSet, NarrowPhase } from "../geometry";
5
+ import { EventQueue } from "./event_queue";
6
+ import { PhysicsHooks } from "./physics_hooks";
7
+ export declare class PhysicsPipeline {
8
+ raw: RawPhysicsPipeline;
9
+ free(): void;
10
+ constructor(raw?: RawPhysicsPipeline);
11
+ step(gravity: Vector, integrationParameters: IntegrationParameters, islands: IslandManager, broadPhase: BroadPhase, narrowPhase: NarrowPhase, bodies: RigidBodySet, colliders: ColliderSet, softBodies: SoftBodySet, impulseJoints: ImpulseJointSet, multibodyJoints: MultibodyJointSet, ccdSolver: CCDSolver, eventQueue?: EventQueue, hooks?: PhysicsHooks): void;
12
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Flags for excluding whole sets of colliders from a scene query.
3
+ */
4
+ export declare enum QueryFilterFlags {
5
+ /**
6
+ * Exclude from the query any collider attached to a fixed rigid-body and colliders with no rigid-body attached.
7
+ */
8
+ EXCLUDE_FIXED = 1,
9
+ /**
10
+ * Exclude from the query any collider attached to a dynamic rigid-body.
11
+ */
12
+ EXCLUDE_KINEMATIC = 2,
13
+ /**
14
+ * Exclude from the query any collider attached to a kinematic rigid-body.
15
+ */
16
+ EXCLUDE_DYNAMIC = 4,
17
+ /**
18
+ * Exclude from the query any collider that is a sensor.
19
+ */
20
+ EXCLUDE_SENSORS = 8,
21
+ /**
22
+ * Exclude from the query any collider that is not a sensor.
23
+ */
24
+ EXCLUDE_SOLIDS = 16,
25
+ /**
26
+ * Excludes all colliders not attached to a dynamic rigid-body.
27
+ */
28
+ ONLY_DYNAMIC = 3,
29
+ /**
30
+ * Excludes all colliders not attached to a kinematic rigid-body.
31
+ */
32
+ ONLY_KINEMATIC = 5,
33
+ /**
34
+ * Exclude all colliders attached to a non-fixed rigid-body
35
+ * (this will not exclude colliders not attached to any rigid-body).
36
+ */
37
+ ONLY_FIXED = 6
38
+ }
@@ -0,0 +1,37 @@
1
+ import { RawSerializationPipeline } from "../raw";
2
+ import { Vector } from "../math";
3
+ import { IntegrationParameters, IslandManager, ImpulseJointSet, MultibodyJointSet, RigidBodySet, SoftBodySet } from "../dynamics";
4
+ import { BroadPhase, ColliderSet, NarrowPhase } from "../geometry";
5
+ import { World } from "./world";
6
+ /**
7
+ * A pipeline for serializing the physics scene.
8
+ *
9
+ * To avoid leaking WASM resources, this MUST be freed manually with `serializationPipeline.free()`
10
+ * once you are done using it (and all the rigid-bodies it created).
11
+ */
12
+ export declare class SerializationPipeline {
13
+ raw: RawSerializationPipeline;
14
+ /**
15
+ * Release the WASM memory occupied by this serialization pipeline.
16
+ */
17
+ free(): void;
18
+ constructor(raw?: RawSerializationPipeline);
19
+ /**
20
+ * Serialize a complete physics state into a single byte array.
21
+ * @param gravity - The current gravity affecting the simulation.
22
+ * @param integrationParameters - The integration parameters of the simulation.
23
+ * @param broadPhase - The broad-phase of the simulation.
24
+ * @param narrowPhase - The narrow-phase of the simulation.
25
+ * @param bodies - The rigid-bodies taking part into the simulation.
26
+ * @param colliders - The colliders taking part into the simulation.
27
+ * @param impulseJoints - The impulse joints taking part into the simulation.
28
+ * @param multibodyJoints - The multibody joints taking part into the simulation.
29
+ */
30
+ serializeAll(gravity: Vector, integrationParameters: IntegrationParameters, islands: IslandManager, broadPhase: BroadPhase, narrowPhase: NarrowPhase, bodies: RigidBodySet, colliders: ColliderSet, softBodies: SoftBodySet, impulseJoints: ImpulseJointSet, multibodyJoints: MultibodyJointSet): Uint8Array;
31
+ /**
32
+ * Deserialize the complete physics state from a single byte array.
33
+ *
34
+ * @param data - The byte array to deserialize.
35
+ */
36
+ deserializeAll(data: Uint8Array): World;
37
+ }