@react-three/rapier 0.8.2 → 0.10.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/dist/declarations/src/Attractor.d.ts +51 -0
- package/dist/declarations/src/MeshCollider.d.ts +4 -1
- package/dist/declarations/src/Physics.d.ts +43 -6
- package/dist/declarations/src/index.d.ts +2 -1
- package/dist/declarations/src/{bitmasks.d.ts → interaction-groups.d.ts} +0 -0
- package/dist/declarations/src/types.d.ts +35 -9
- package/dist/declarations/src/utils-collider.d.ts +1 -1
- package/dist/react-three-rapier.cjs.dev.js +946 -706
- package/dist/react-three-rapier.cjs.prod.js +946 -706
- package/dist/react-three-rapier.esm.js +948 -709
- package/package.json +1 -1
- package/readme.md +143 -39
@@ -0,0 +1,51 @@
|
|
1
|
+
import { InteractionGroups, RigidBody } from "@dimforge/rapier3d-compat";
|
2
|
+
import { FC } from "react";
|
3
|
+
import { Object3D } from "three";
|
4
|
+
import { Object3DProps } from "@react-three/fiber";
|
5
|
+
declare type GravityType = "static" | "linear" | "newtonian";
|
6
|
+
interface AttractorProps {
|
7
|
+
/**
|
8
|
+
* The relative position of this attractor
|
9
|
+
*/
|
10
|
+
position?: Object3DProps["position"];
|
11
|
+
/**
|
12
|
+
* The strength of the attractor.
|
13
|
+
* Positive values attract, negative values repel.
|
14
|
+
*
|
15
|
+
* @default 1
|
16
|
+
*/
|
17
|
+
strength?: number;
|
18
|
+
/**
|
19
|
+
* The range of the attractor. Will not affect objects outside of this range.
|
20
|
+
*
|
21
|
+
* @default 10
|
22
|
+
* @min 0
|
23
|
+
*/
|
24
|
+
range?: number;
|
25
|
+
/**
|
26
|
+
* The type of gravity to use.
|
27
|
+
* - static: The gravity is constant and does not change over time.
|
28
|
+
* - linear: The gravity is linearly interpolated the closer the object is to the attractor.
|
29
|
+
* - newtonian: The gravity is calculated using the newtonian gravity formula.
|
30
|
+
* @default "static"
|
31
|
+
*/
|
32
|
+
type?: GravityType;
|
33
|
+
/**
|
34
|
+
* The mass of the attractor. Used when type is `newtonian`.
|
35
|
+
* @default 6.673e-11
|
36
|
+
*/
|
37
|
+
gravitationalConstant?: number;
|
38
|
+
/**
|
39
|
+
* The collision groups that this attractor will apply effects to. If a RigidBody contains one or more colliders that are in one of the mask group, it will be affected by this attractor.
|
40
|
+
* If not specified, the attractor will apply effects to all RigidBodies.
|
41
|
+
*/
|
42
|
+
collisionGroups?: InteractionGroups;
|
43
|
+
}
|
44
|
+
export interface AttractorState extends Required<Omit<AttractorProps, "position" | "collisionGroups">> {
|
45
|
+
object: Object3D;
|
46
|
+
collisionGroups?: InteractionGroups;
|
47
|
+
}
|
48
|
+
export declare type AttractorStateMap = Map<Object3D["uuid"], AttractorState>;
|
49
|
+
export declare const applyAttractorForceOnRigidBody: (rigidBody: RigidBody, { object, strength, range, gravitationalConstant, collisionGroups, type }: AttractorState) => void;
|
50
|
+
export declare const Attractor: FC<AttractorProps>;
|
51
|
+
export {};
|
@@ -4,5 +4,8 @@ interface MeshColliderProps {
|
|
4
4
|
children: ReactNode;
|
5
5
|
type: RigidBodyAutoCollider;
|
6
6
|
}
|
7
|
-
export declare const MeshCollider:
|
7
|
+
export declare const MeshCollider: {
|
8
|
+
(props: MeshColliderProps): JSX.Element;
|
9
|
+
displayName: string;
|
10
|
+
};
|
8
11
|
export {};
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import React, { FC, ReactNode } from "react";
|
2
1
|
import type Rapier from "@dimforge/rapier3d-compat";
|
3
|
-
import { CollisionEnterHandler, CollisionExitHandler, IntersectionEnterHandler, IntersectionExitHandler, RigidBodyAutoCollider, Vector3Array, WorldApi } from "./types";
|
4
2
|
import { Collider, ColliderHandle, RigidBody, RigidBodyHandle } from "@dimforge/rapier3d-compat";
|
3
|
+
import React, { FC, ReactNode } from "react";
|
5
4
|
import { Matrix4, Object3D, Vector3 } from "three";
|
5
|
+
import { CollisionEnterHandler, CollisionExitHandler, ContactForceHandler, IntersectionEnterHandler, IntersectionExitHandler, RigidBodyAutoCollider, Vector3Array, WorldApi } from "./types";
|
6
|
+
import { AttractorStateMap } from "./Attractor";
|
6
7
|
export interface RigidBodyState {
|
7
8
|
rigidBody: RigidBody;
|
8
9
|
object: Object3D;
|
@@ -21,32 +22,61 @@ export interface ColliderState {
|
|
21
22
|
object: Object3D;
|
22
23
|
/**
|
23
24
|
* The parent of which this collider needs to base its
|
24
|
-
* world position on
|
25
|
+
* world position on, can be empty
|
25
26
|
*/
|
26
|
-
worldParent
|
27
|
+
worldParent?: Object3D;
|
27
28
|
}
|
28
29
|
export declare type ColliderStateMap = Map<Collider["handle"], ColliderState>;
|
29
30
|
export interface RapierContext {
|
30
31
|
rapier: typeof Rapier;
|
31
32
|
world: WorldApi;
|
33
|
+
/**
|
34
|
+
* @internal
|
35
|
+
*/
|
32
36
|
rigidBodyStates: RigidBodyStateMap;
|
37
|
+
/**
|
38
|
+
* @internal
|
39
|
+
*/
|
33
40
|
colliderStates: ColliderStateMap;
|
41
|
+
/**
|
42
|
+
* @internal
|
43
|
+
*/
|
34
44
|
rigidBodyEvents: EventMap;
|
45
|
+
/**
|
46
|
+
* @internal
|
47
|
+
*/
|
35
48
|
colliderEvents: EventMap;
|
49
|
+
/**
|
50
|
+
* @internal
|
51
|
+
*/
|
52
|
+
attractorStates: AttractorStateMap;
|
36
53
|
physicsOptions: {
|
37
54
|
colliders: RigidBodyAutoCollider;
|
38
55
|
};
|
39
56
|
isPaused: boolean;
|
57
|
+
/**
|
58
|
+
* Step the physics world one step
|
59
|
+
*
|
60
|
+
* @param deltaTime The delta time to step the world with
|
61
|
+
*
|
62
|
+
* @example
|
63
|
+
* ```
|
64
|
+
* step(1/60)
|
65
|
+
* ```
|
66
|
+
*/
|
67
|
+
step: (deltaTime: number) => void;
|
40
68
|
}
|
41
69
|
export declare const RapierContext: React.Context<RapierContext | undefined>;
|
42
|
-
export declare type
|
70
|
+
export declare type EventMapValue = {
|
43
71
|
onSleep?(): void;
|
44
72
|
onWake?(): void;
|
45
73
|
onCollisionEnter?: CollisionEnterHandler;
|
46
74
|
onCollisionExit?: CollisionExitHandler;
|
47
75
|
onIntersectionEnter?: IntersectionEnterHandler;
|
48
76
|
onIntersectionExit?: IntersectionExitHandler;
|
49
|
-
|
77
|
+
onContactForce?: ContactForceHandler;
|
78
|
+
};
|
79
|
+
export declare type EventMap = Map<ColliderHandle | RigidBodyHandle, EventMapValue>;
|
50
80
|
interface RapierWorldProps {
|
51
81
|
children: ReactNode;
|
52
82
|
/**
|
@@ -82,6 +112,13 @@ interface RapierWorldProps {
|
|
82
112
|
* @defaultValue undefined
|
83
113
|
*/
|
84
114
|
updatePriority?: number;
|
115
|
+
/**
|
116
|
+
* Interpolate the world transform using the frame delta times.
|
117
|
+
* Has no effect if timeStep is set to "vary".
|
118
|
+
*
|
119
|
+
* @default true
|
120
|
+
**/
|
121
|
+
interpolate?: boolean;
|
85
122
|
}
|
86
123
|
export declare const Physics: FC<RapierWorldProps>;
|
87
124
|
export {};
|
@@ -9,5 +9,6 @@ export { MeshCollider } from "./MeshCollider";
|
|
9
9
|
export { Debug } from "./Debug";
|
10
10
|
export { InstancedRigidBodies } from "./InstancedRigidBodies";
|
11
11
|
export * from "./AnyCollider";
|
12
|
+
export { Attractor } from "./Attractor";
|
12
13
|
export * from "./hooks";
|
13
|
-
export * from "./
|
14
|
+
export * from "./interaction-groups";
|
File without changes
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { MutableRefObject } from "react";
|
2
2
|
import { CoefficientCombineRule, Collider as RapierCollider, InteractionGroups, RigidBody as RapierRigidBody, TempContactManifold } from "@dimforge/rapier3d-compat";
|
3
|
-
import {
|
4
|
-
import { ColliderProps } from ".";
|
3
|
+
import { Rotation, Vector } from "@dimforge/rapier3d-compat/math";
|
5
4
|
import { Object3DProps } from "@react-three/fiber";
|
6
5
|
import { Object3D } from "three";
|
6
|
+
import { ColliderProps } from ".";
|
7
|
+
import { createColliderApi, createJointApi, createRigidBodyApi, createWorldApi } from "./api";
|
7
8
|
export { CoefficientCombineRule as CoefficientCombineRule } from "@dimforge/rapier3d-compat";
|
8
9
|
export { RapierRigidBody, RapierCollider };
|
9
|
-
import { Rotation, Vector } from "@dimforge/rapier3d-compat/math";
|
10
10
|
export declare type RefGetter<T> = MutableRefObject<() => T | undefined>;
|
11
11
|
export declare type RigidBodyAutoCollider = "ball" | "cuboid" | "hull" | "trimesh" | false;
|
12
12
|
export interface UseRigidBodyAPI {
|
@@ -74,6 +74,10 @@ export declare type ColliderShape = "cuboid" | "trimesh" | "ball" | "capsule" |
|
|
74
74
|
export declare type Vector3Array = [x: number, y: number, z: number];
|
75
75
|
export declare type Boolean3Array = [x: boolean, y: boolean, z: boolean];
|
76
76
|
export interface UseColliderOptions<ColliderArgs extends Array<unknown>> {
|
77
|
+
/**
|
78
|
+
* The optional name passed to THREE's Object3D
|
79
|
+
*/
|
80
|
+
name?: string;
|
77
81
|
/**
|
78
82
|
* The shape of your collider
|
79
83
|
*/
|
@@ -136,6 +140,10 @@ export interface UseColliderOptions<ColliderArgs extends Array<unknown>> {
|
|
136
140
|
* Callback when this, or another collider stops intersecting, and at least one of them is a `sensor`.
|
137
141
|
*/
|
138
142
|
onIntersectionExit?: IntersectionExitHandler;
|
143
|
+
/**
|
144
|
+
* Callback when this, or another collider triggers a contact force event
|
145
|
+
*/
|
146
|
+
onContactForce?: ContactForceHandler;
|
139
147
|
/**
|
140
148
|
* The bit mask configuring the groups and mask for collision handling.
|
141
149
|
*/
|
@@ -175,26 +183,44 @@ export interface UseColliderOptions<ColliderArgs extends Array<unknown>> {
|
|
175
183
|
*/
|
176
184
|
sensor?: boolean;
|
177
185
|
}
|
178
|
-
export declare type
|
186
|
+
export declare type CollisionTarget = {
|
179
187
|
rigidBody?: RapierRigidBody;
|
180
188
|
collider: RapierCollider;
|
181
|
-
manifold: TempContactManifold;
|
182
|
-
flipped: boolean;
|
183
189
|
rigidBodyObject?: Object3D;
|
184
190
|
colliderObject?: Object3D;
|
185
191
|
};
|
186
|
-
export declare type
|
192
|
+
export declare type CollisionPayload = {
|
193
|
+
/** the object firing the event */
|
194
|
+
target: CollisionTarget;
|
195
|
+
/** the other object involved in the event */
|
196
|
+
other: CollisionTarget;
|
197
|
+
/** deprecated use `payload.other.rigidBody` instead */
|
187
198
|
rigidBody?: RapierRigidBody;
|
199
|
+
/** deprecated use `payload.other.collider` instead */
|
188
200
|
collider: RapierCollider;
|
201
|
+
/** deprecated use `payload.other.rigidBodyObject` instead */
|
189
202
|
rigidBodyObject?: Object3D;
|
203
|
+
/** deprecated use `payload.other.colliderObject` instead */
|
190
204
|
colliderObject?: Object3D;
|
191
205
|
};
|
192
|
-
export declare type
|
193
|
-
|
206
|
+
export declare type CollisionEnterPayload = CollisionPayload & {
|
207
|
+
manifold: TempContactManifold;
|
208
|
+
flipped: boolean;
|
209
|
+
};
|
210
|
+
export declare type CollisionExitPayload = CollisionPayload;
|
211
|
+
export declare type IntersectionEnterPayload = CollisionPayload;
|
212
|
+
export declare type IntersectionExitPayload = CollisionPayload;
|
213
|
+
export declare type ContactForcePayload = CollisionPayload & {
|
214
|
+
totalForce: Vector;
|
215
|
+
totalForceMagnitude: number;
|
216
|
+
maxForceDirection: Vector;
|
217
|
+
maxForceMagnitude: number;
|
218
|
+
};
|
194
219
|
export declare type CollisionEnterHandler = (payload: CollisionEnterPayload) => void;
|
195
220
|
export declare type CollisionExitHandler = (payload: CollisionExitPayload) => void;
|
196
221
|
export declare type IntersectionEnterHandler = (payload: IntersectionEnterPayload) => void;
|
197
222
|
export declare type IntersectionExitHandler = (payload: IntersectionExitPayload) => void;
|
223
|
+
export declare type ContactForceHandler = (payload: ContactForcePayload) => void;
|
198
224
|
export interface UseRigidBodyOptions extends ColliderProps {
|
199
225
|
/**
|
200
226
|
* Specify the type of this rigid body
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Collider, RigidBody } from "@dimforge/rapier3d-compat";
|
2
2
|
import { MutableRefObject } from "react";
|
3
|
-
import {
|
3
|
+
import { BufferGeometry, Object3D, Vector3 } from "three";
|
4
4
|
import { ColliderProps, RigidBodyProps } from ".";
|
5
5
|
import { WorldApi } from "./api";
|
6
6
|
import { ColliderState, ColliderStateMap, EventMap } from "./Physics";
|