@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,97 @@
1
+ import { RawColliderSet } from "../raw";
2
+ import { Collider, ColliderDesc, ColliderHandle } from "./collider";
3
+ import { ImpulseJointHandle, IslandManager, RigidBodyHandle, RigidBodySet, SoftBodySet, SoftMeshBinding } from "../dynamics";
4
+ /**
5
+ * A set of rigid bodies that can be handled by a physics pipeline.
6
+ *
7
+ * To avoid leaking WASM resources, this MUST be freed manually with `colliderSet.free()`
8
+ * once you are done using it (and all the rigid-bodies it created).
9
+ */
10
+ export declare class ColliderSet {
11
+ raw: RawColliderSet;
12
+ private map;
13
+ /**
14
+ * Release the WASM memory occupied by this collider set.
15
+ */
16
+ free(): void;
17
+ constructor(raw?: RawColliderSet);
18
+ /** @internal */
19
+ castClosure<Res>(f?: (collider: Collider) => Res): (handle: ColliderHandle) => Res | undefined;
20
+ /** @internal */
21
+ finalizeDeserialization(bodies: RigidBodySet): void;
22
+ /**
23
+ * Creates a new collider and return its integer handle.
24
+ *
25
+ * @param bodies - The set of bodies where the collider's parent can be found.
26
+ * @param desc - The collider's description.
27
+ * @param parentHandle - The integer handle of the rigid-body this collider is attached to.
28
+ */
29
+ createCollider(bodies: RigidBodySet, desc: ColliderDesc, parentHandle: RigidBodyHandle): Collider;
30
+ /**
31
+ * Creates a collider holding a soft body's deformable collision mesh: a polyline (2D) or a
32
+ * triangle mesh (3D) built with the `DEFORMABLE` flag, whose vertices follow the cluster
33
+ * of the parent proxy through `binding`.
34
+ *
35
+ * Returns `null` when the binding fails: the parent is not a live cluster proxy, the shape
36
+ * is not a deformable mesh, or a vertex could not be bound.
37
+ *
38
+ * @param bodies - The set of bodies where the parent proxy can be found.
39
+ * @param softBodies - The set of soft bodies owning the cluster.
40
+ * @param desc - The collider's description.
41
+ * @param binding - How the mesh follows the cluster.
42
+ * @param parentHandle - The handle of the cluster proxy (see `SoftBody.rootBody`,
43
+ * `SoftBody.clusterProxy`).
44
+ */
45
+ createDeformableCollider(bodies: RigidBodySet, softBodies: SoftBodySet, desc: ColliderDesc, binding: SoftMeshBinding, parentHandle: RigidBodyHandle): Collider | null;
46
+ /**
47
+ * Wraps the colliders the engine created on its own (the deformable collision meshes of
48
+ * soft bodies) that have no JavaScript wrapper yet.
49
+ */
50
+ mapNewColliders(bodies: RigidBodySet): void;
51
+ /**
52
+ * Drops the wrappers of the colliders the engine removed on its own (the colliders of
53
+ * removed soft bodies and clusters).
54
+ */
55
+ unmapRemovedColliders(): void;
56
+ /**
57
+ * Remove a collider from this set.
58
+ *
59
+ * @param handle - The integer handle of the collider to remove.
60
+ * @param bodies - The set of rigid-body containing the rigid-body the collider is attached to.
61
+ * @param wakeUp - If `true`, the rigid-body the removed collider is attached to will be woken-up automatically.
62
+ */
63
+ remove(handle: ColliderHandle, islands: IslandManager, bodies: RigidBodySet, softBodies: SoftBodySet, wakeUp: boolean): void;
64
+ /**
65
+ * Internal function, do not call directly.
66
+ * @param handle
67
+ */
68
+ unmap(handle: ImpulseJointHandle): void;
69
+ /**
70
+ * Gets the rigid-body with the given handle.
71
+ *
72
+ * @param handle - The handle of the rigid-body to retrieve.
73
+ */
74
+ get(handle: ColliderHandle): Collider | null;
75
+ /**
76
+ * The number of colliders on this set.
77
+ */
78
+ len(): number;
79
+ /**
80
+ * Does this set contain a collider with the given handle?
81
+ *
82
+ * @param handle - The collider handle to check.
83
+ */
84
+ contains(handle: ColliderHandle): boolean;
85
+ /**
86
+ * Applies the given closure to each collider contained by this set.
87
+ *
88
+ * @param f - The closure to apply.
89
+ */
90
+ forEach(f: (collider: Collider) => void): void;
91
+ /**
92
+ * Gets all colliders in the list.
93
+ *
94
+ * @returns collider list.
95
+ */
96
+ getAll(): Collider[];
97
+ }
@@ -0,0 +1,36 @@
1
+ import { Vector } from "../math";
2
+ import { RawShapeContact } from "../raw";
3
+ /**
4
+ * The contact info between two shapes.
5
+ */
6
+ export declare class ShapeContact {
7
+ /**
8
+ * Distance between the two contact points.
9
+ * If this is negative, this contact represents a penetration.
10
+ */
11
+ distance: number;
12
+ /**
13
+ * Position of the contact on the first shape.
14
+ */
15
+ point1: Vector;
16
+ /**
17
+ * Position of the contact on the second shape.
18
+ */
19
+ point2: Vector;
20
+ /**
21
+ * Contact normal, pointing towards the exterior of the first shape.
22
+ */
23
+ normal1: Vector;
24
+ /**
25
+ * Contact normal, pointing towards the exterior of the second shape.
26
+ * If these contact data are expressed in world-space, this normal is equal to -normal1.
27
+ */
28
+ normal2: Vector;
29
+ constructor(dist: number, point1: Vector, point2: Vector, normal1: Vector, normal2: Vector);
30
+ /**
31
+ * @param raw - The raw contact returned by the WASM query. It is freed by this method.
32
+ * @param target - If provided, this object is populated and returned instead of
33
+ * allocating a new one.
34
+ */
35
+ static fromBuffer(raw: RawShapeContact, target?: ShapeContact): ShapeContact;
36
+ }
@@ -0,0 +1,6 @@
1
+ export declare enum FeatureType {
2
+ Vertex = 0,
3
+ Edge = 1,
4
+ Face = 2,
5
+ Unknown = 3
6
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./broad_phase";
2
+ export * from "./narrow_phase";
3
+ export * from "./shape";
4
+ export * from "./collider";
5
+ export * from "./collider_set";
6
+ export * from "./feature";
7
+ export * from "./ray";
8
+ export * from "./point";
9
+ export * from "./toi";
10
+ export * from "./interaction_groups";
11
+ export * from "./contact";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Pairwise filtering using bit masks.
3
+ *
4
+ * This filtering method is based on two 16-bit values:
5
+ * - The interaction groups (the 16 left-most bits of `self.0`).
6
+ * - The interaction mask (the 16 right-most bits of `self.0`).
7
+ *
8
+ * An interaction is allowed between two filters `a` and `b` two conditions
9
+ * are met simultaneously:
10
+ * - The interaction groups of `a` has at least one bit set to `1` in common with the interaction mask of `b`.
11
+ * - The interaction groups of `b` has at least one bit set to `1` in common with the interaction mask of `a`.
12
+ * In other words, interactions are allowed between two filter iff. the following condition is met:
13
+ *
14
+ * ```
15
+ * ((a >> 16) & b) != 0 && ((b >> 16) & a) != 0
16
+ * ```
17
+ */
18
+ export type InteractionGroups = number;
@@ -0,0 +1,140 @@
1
+ import { RawNarrowPhase, RawContactManifold } from "../raw";
2
+ import { ColliderHandle } from "./collider";
3
+ import { RigidBodySet } from "../dynamics";
4
+ import { Vector } from "../math";
5
+ /**
6
+ * The narrow-phase used for precise collision-detection.
7
+ *
8
+ * To avoid leaking WASM resources, this MUST be freed manually with `narrowPhase.free()`
9
+ * once you are done using it.
10
+ */
11
+ export declare class NarrowPhase {
12
+ raw: RawNarrowPhase;
13
+ tempManifold: TempContactManifold;
14
+ /**
15
+ * Release the WASM memory occupied by this narrow-phase.
16
+ */
17
+ free(): void;
18
+ constructor(raw?: RawNarrowPhase);
19
+ /**
20
+ * Enumerates all the colliders potentially in contact with the given collider.
21
+ *
22
+ * @param collider1 - The second collider involved in the contact.
23
+ * @param f - Closure that will be called on each collider that is in contact with `collider1`.
24
+ */
25
+ contactPairsWith(collider1: ColliderHandle, f: (collider2: ColliderHandle) => void): void;
26
+ /**
27
+ * Enumerates all the colliders intersecting the given colliders, assuming one of them
28
+ * is a sensor.
29
+ */
30
+ intersectionPairsWith(collider1: ColliderHandle, f: (collider2: ColliderHandle) => void): void;
31
+ /**
32
+ * Iterates through all the contact manifolds between the given pair of colliders.
33
+ *
34
+ * @param collider1 - The first collider involved in the contact.
35
+ * @param collider2 - The second collider involved in the contact.
36
+ * @param bodies - The set of rigid-bodies the colliders are attached to. Solver contacts are
37
+ * anchored in body-local space, so this is needed to read them back in world-space.
38
+ * @param f - Closure that will be called on each contact manifold between the two colliders. If the second argument
39
+ * passed to this closure is `true`, then the contact manifold data is flipped, i.e., methods like `localNormal1`
40
+ * actually apply to the `collider2` and fields like `localNormal2` apply to the `collider1`.
41
+ */
42
+ contactPair(collider1: ColliderHandle, collider2: ColliderHandle, bodies: RigidBodySet, f: (manifold: TempContactManifold, flipped: boolean) => void): void;
43
+ /**
44
+ * Visits the manifolds consumed by the solver, including clustered contacts.
45
+ * Original geometric manifolds remain available through contactPair().
46
+ * The view is valid only during the callback. Do not step, free, or mutate
47
+ * the world in the callback. Copy values that must survive the call.
48
+ * Clustered contacts do not preserve geometric subshape identifiers.
49
+ */
50
+ solverContactPair(collider1: ColliderHandle, collider2: ColliderHandle, bodies: RigidBodySet, f: (manifold: SolverContactManifold, flipped: boolean) => void): void;
51
+ /**
52
+ * Returns `true` if `collider1` and `collider2` intersect and at least one of them is a sensor.
53
+ * @param collider1 − The first collider involved in the intersection.
54
+ * @param collider2 − The second collider involved in the intersection.
55
+ */
56
+ intersectionPair(collider1: ColliderHandle, collider2: ColliderHandle): boolean;
57
+ }
58
+ export declare class TempContactManifold {
59
+ raw: RawContactManifold;
60
+ /** The bodies the manifold's solver contacts are anchored to. */
61
+ bodies: RigidBodySet;
62
+ free(): void;
63
+ constructor(raw: RawContactManifold, bodies?: RigidBodySet);
64
+ /**
65
+ * The contact normal of the manifold, expressed in world-space.
66
+ *
67
+ * @param {Vector?} target - The object to be populated. If provided,
68
+ * the function returns this object instead of creating a new one.
69
+ */
70
+ normal(target?: Vector): Vector;
71
+ /**
72
+ * The contact normal of the manifold, expressed in the local-space of the first shape.
73
+ *
74
+ * @param {Vector?} target - The object to be populated. If provided,
75
+ * the function returns this object instead of creating a new one.
76
+ */
77
+ localNormal1(target?: Vector): Vector;
78
+ /**
79
+ * The contact normal of the manifold, expressed in the local-space of the second shape.
80
+ *
81
+ * @param {Vector?} target - The object to be populated. If provided,
82
+ * the function returns this object instead of creating a new one.
83
+ */
84
+ localNormal2(target?: Vector): Vector;
85
+ subshape1(): number;
86
+ subshape2(): number;
87
+ numContacts(): number;
88
+ /**
89
+ * The local-space contact point on the first shape, for the `i`-th contact.
90
+ *
91
+ * @param {number} i - The index of the contact to read.
92
+ * @param {Vector?} target - The object to be populated. If provided,
93
+ * the function returns this object instead of creating a new one.
94
+ */
95
+ localContactPoint1(i: number, target?: Vector): Vector | null;
96
+ /**
97
+ * The local-space contact point on the second shape, for the `i`-th contact.
98
+ *
99
+ * @param {number} i - The index of the contact to read.
100
+ * @param {Vector?} target - The object to be populated. If provided,
101
+ * the function returns this object instead of creating a new one.
102
+ */
103
+ localContactPoint2(i: number, target?: Vector): Vector | null;
104
+ contactDist(i: number): number;
105
+ contactFid1(i: number): number;
106
+ contactFid2(i: number): number;
107
+ contactImpulse(i: number): number;
108
+ contactTangentImpulseX(i: number): number;
109
+ contactTangentImpulseY(i: number): number;
110
+ numSolverContacts(): number;
111
+ /**
112
+ * The world-space position of the `i`-th solver contact point.
113
+ *
114
+ * @param {number} i - The index of the solver contact to read.
115
+ * @param {Vector?} target - The object to be populated. If provided,
116
+ * the function returns this object instead of creating a new one.
117
+ */
118
+ solverContactPoint(i: number, target?: Vector): Vector | null;
119
+ solverContactDist(i: number): number;
120
+ /**
121
+ * The friction coefficient applied to this manifold's solver contacts. It is combined
122
+ * once per manifold, so every solver contact of this manifold shares it.
123
+ */
124
+ friction(): number;
125
+ /**
126
+ * The restitution coefficient applied to this manifold's solver contacts. It is
127
+ * combined once per manifold, so every solver contact of this manifold shares it.
128
+ */
129
+ restitution(): number;
130
+ /**
131
+ * The tangent (surface) velocity of the `i`-th solver contact point.
132
+ *
133
+ * @param {number} i - The index of the solver contact to read.
134
+ * @param {Vector?} target - The object to be populated. If provided,
135
+ * the function returns this object instead of creating a new one.
136
+ */
137
+ solverContactTangentVelocity(i: number, target?: Vector): Vector;
138
+ }
139
+ /** Read-only solver view; geometric subshape and local-surface queries are excluded. */
140
+ export type SolverContactManifold = Pick<TempContactManifold, 'normal' | 'numSolverContacts' | 'solverContactPoint' | 'solverContactDist' | 'friction' | 'restitution' | 'solverContactTangentVelocity'>;
@@ -0,0 +1,58 @@
1
+ import { Collider } from "./collider";
2
+ import { Vector } from "../math";
3
+ import { RawPointColliderProjection, RawPointProjection } from "../raw";
4
+ import { FeatureType } from "./feature";
5
+ import { ColliderSet } from "./collider_set";
6
+ /**
7
+ * The projection of a point on a collider.
8
+ */
9
+ export declare class PointProjection {
10
+ /**
11
+ * The projection of the point on the collider.
12
+ */
13
+ point: Vector;
14
+ /**
15
+ * Is the point inside of the collider?
16
+ */
17
+ isInside: boolean;
18
+ constructor(point: Vector, isInside: boolean);
19
+ /**
20
+ * @param raw - The raw projection returned by the WASM query. It is freed by this method.
21
+ * @param target - If provided, this object is populated and returned instead of
22
+ * allocating a new one.
23
+ */
24
+ static fromBuffer(raw: RawPointProjection, target?: PointProjection): PointProjection;
25
+ }
26
+ /**
27
+ * The projection of a point on a collider (includes the collider handle).
28
+ */
29
+ export declare class PointColliderProjection {
30
+ /**
31
+ * The collider hit by the ray.
32
+ */
33
+ collider: Collider;
34
+ /**
35
+ * The projection of the point on the collider.
36
+ */
37
+ point: Vector;
38
+ /**
39
+ * Is the point inside of the collider?
40
+ */
41
+ isInside: boolean;
42
+ /**
43
+ * The type of the geometric feature the point was projected on.
44
+ */
45
+ featureType: FeatureType;
46
+ /**
47
+ * The id of the geometric feature the point was projected on.
48
+ */
49
+ featureId: number | undefined;
50
+ constructor(collider: Collider, point: Vector, isInside: boolean, featureType?: FeatureType, featureId?: number);
51
+ /**
52
+ * @param colliderSet - The set the projected-on collider belongs to.
53
+ * @param raw - The raw projection returned by the WASM query. It is freed by this method.
54
+ * @param target - If provided, this object is populated and returned instead of
55
+ * allocating a new one.
56
+ */
57
+ static fromBuffer(colliderSet: ColliderSet, raw: RawPointColliderProjection, target?: PointColliderProjection): PointColliderProjection;
58
+ }
@@ -0,0 +1,108 @@
1
+ import { Vector } from "../math";
2
+ import { RawRayColliderIntersection, RawRayColliderHit, RawRayIntersection } from "../raw";
3
+ import { Collider } from "./collider";
4
+ import { FeatureType } from "./feature";
5
+ import { ColliderSet } from "./collider_set";
6
+ /**
7
+ * A ray. This is a directed half-line.
8
+ */
9
+ export declare class Ray {
10
+ /**
11
+ * The starting point of the ray.
12
+ */
13
+ origin: Vector;
14
+ /**
15
+ * The direction of propagation of the ray.
16
+ */
17
+ dir: Vector;
18
+ /**
19
+ * Builds a ray from its origin and direction.
20
+ *
21
+ * @param origin - The ray's starting point.
22
+ * @param dir - The ray's direction of propagation.
23
+ */
24
+ constructor(origin: Vector, dir: Vector);
25
+ pointAt(t: number): Vector;
26
+ }
27
+ /**
28
+ * The intersection between a ray and a collider.
29
+ */
30
+ export declare class RayIntersection {
31
+ /**
32
+ * The time-of-impact of the ray with the collider.
33
+ *
34
+ * The hit point is obtained from the ray's origin and direction: `origin + dir * timeOfImpact`.
35
+ */
36
+ timeOfImpact: number;
37
+ /**
38
+ * The normal of the collider at the hit point.
39
+ */
40
+ normal: Vector;
41
+ /**
42
+ * The type of the geometric feature the point was projected on.
43
+ */
44
+ featureType: FeatureType;
45
+ /**
46
+ * The id of the geometric feature the point was projected on.
47
+ */
48
+ featureId: number | undefined;
49
+ constructor(timeOfImpact: number, normal: Vector, featureType?: FeatureType, featureId?: number);
50
+ /**
51
+ * @param raw - The raw intersection returned by the WASM query. It is freed by this method.
52
+ * @param target - If provided, this object is populated and returned instead of
53
+ * allocating a new one.
54
+ */
55
+ static fromBuffer(raw: RawRayIntersection, target?: RayIntersection): RayIntersection;
56
+ }
57
+ /**
58
+ * The intersection between a ray and a collider (includes the collider handle).
59
+ */
60
+ export declare class RayColliderIntersection {
61
+ /**
62
+ * The collider hit by the ray.
63
+ */
64
+ collider: Collider;
65
+ /**
66
+ * The time-of-impact of the ray with the collider.
67
+ *
68
+ * The hit point is obtained from the ray's origin and direction: `origin + dir * timeOfImpact`.
69
+ */
70
+ timeOfImpact: number;
71
+ /**
72
+ * The normal of the collider at the hit point.
73
+ */
74
+ normal: Vector;
75
+ /**
76
+ * The type of the geometric feature the point was projected on.
77
+ */
78
+ featureType: FeatureType;
79
+ /**
80
+ * The id of the geometric feature the point was projected on.
81
+ */
82
+ featureId: number | undefined;
83
+ constructor(collider: Collider, timeOfImpact: number, normal: Vector, featureType?: FeatureType, featureId?: number);
84
+ /**
85
+ * @param colliderSet - The set the hit collider belongs to.
86
+ * @param raw - The raw intersection returned by the WASM query. It is freed by this method.
87
+ * @param target - If provided, this object is populated and returned instead of
88
+ * allocating a new one.
89
+ */
90
+ static fromBuffer(colliderSet: ColliderSet, raw: RawRayColliderIntersection, target?: RayColliderIntersection): RayColliderIntersection;
91
+ }
92
+ /**
93
+ * The time of impact between a ray and a collider.
94
+ */
95
+ export declare class RayColliderHit {
96
+ /**
97
+ * The handle of the collider hit by the ray.
98
+ */
99
+ collider: Collider;
100
+ /**
101
+ * The time-of-impact of the ray with the collider.
102
+ *
103
+ * The hit point is obtained from the ray's origin and direction: `origin + dir * timeOfImpact`.
104
+ */
105
+ timeOfImpact: number;
106
+ constructor(collider: Collider, timeOfImpact: number);
107
+ static fromRaw(colliderSet: ColliderSet, raw: RawRayColliderHit): RayColliderHit;
108
+ }