@react-three/rapier 0.6.8 → 0.7.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/AnyCollider.d.ts +24 -11
- package/dist/declarations/src/InstancedRigidBodies.d.ts +2 -2
- package/dist/declarations/src/MeshCollider.d.ts +1 -1
- package/dist/declarations/src/Physics.d.ts +40 -26
- package/dist/declarations/src/RigidBody.d.ts +2 -5
- package/dist/declarations/src/bitmasks.d.ts +34 -0
- package/dist/declarations/src/hooks.d.ts +3 -1
- package/dist/declarations/src/index.d.ts +4 -0
- package/dist/declarations/src/shared-objects.d.ts +3 -0
- package/dist/declarations/src/types.d.ts +81 -18
- package/dist/declarations/src/utils-collider.d.ts +36 -0
- package/dist/declarations/src/utils-rigidbody.d.ts +20 -0
- package/dist/declarations/src/utils.d.ts +5 -46
- package/dist/react-three-rapier.cjs.dev.js +824 -657
- package/dist/react-three-rapier.cjs.prod.js +824 -657
- package/dist/react-three-rapier.esm.js +824 -660
- package/package.json +4 -4
- package/readme.md +80 -10
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-three/rapier",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.7.0",
|
4
4
|
"source": "src/index.ts",
|
5
5
|
"main": "dist/react-three-rapier.cjs.js",
|
6
6
|
"module": "dist/react-three-rapier.esm.js",
|
@@ -20,12 +20,12 @@
|
|
20
20
|
"peerDependencies": {
|
21
21
|
"@react-three/fiber": "^8.0.12",
|
22
22
|
"react": "^18.0.0",
|
23
|
-
"three": "
|
24
|
-
"three-stdlib": "^2.15.0"
|
23
|
+
"three": ">=0.139.2"
|
25
24
|
},
|
26
25
|
"dependencies": {
|
27
26
|
"@dimforge/rapier3d-compat": "0.9.0",
|
28
|
-
"use-asset": "^1.0.4"
|
27
|
+
"use-asset": "^1.0.4",
|
28
|
+
"three-stdlib": "^2.15.0"
|
29
29
|
},
|
30
30
|
"repository": "https://github.com/pmndrs/react-three-rapier/tree/master/packages/react-three-rapier"
|
31
31
|
}
|
package/readme.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
<p align="center">
|
2
|
-
<img src="https://raw.githubusercontent.com/pmndrs/react-three-rapier/HEAD/packages/react-three-rapier/misc/hero.svg" alt="@react-three/rapier"
|
2
|
+
<a href="#"><img src="https://raw.githubusercontent.com/pmndrs/react-three-rapier/HEAD/packages/react-three-rapier/misc/hero.svg" alt="@react-three/rapier" /></a>
|
3
3
|
</p>
|
4
4
|
|
5
5
|
<p align="center">
|
6
|
-
<img src="https://img.shields.io/npm/v/@react-three/rapier?style=for-the-badge&colorA=0099DA&colorB=ffffff"
|
7
|
-
<img src="https://img.shields.io/discord/740090768164651008?style=for-the-badge&colorA=0099DA&colorB=ffffff&label=discord&logo=discord&logoColor=ffffff
|
6
|
+
<a href="https://www.npmjs.com/package/@react-three/rapier"><img src="https://img.shields.io/npm/v/@react-three/rapier?style=for-the-badge&colorA=0099DA&colorB=ffffff" /></a>
|
7
|
+
<a href="https://discord.gg/ZZjjNvJ"><img src="https://img.shields.io/discord/740090768164651008?style=for-the-badge&colorA=0099DA&colorB=ffffff&label=discord&logo=discord&logoColor=ffffff" /></a>
|
8
8
|
</p>
|
9
9
|
|
10
10
|
<p align="center">⚠️ Under heavy development. All APIs are subject to change. ⚠️</p>
|
@@ -141,7 +141,7 @@ const Scene = () => {
|
|
141
141
|
instancedApi.at(40).applyImpulse({ x: 0, y: 10, z: 0 });
|
142
142
|
|
143
143
|
// Or update all instances as if they were in an array
|
144
|
-
instancedApi.forEach(
|
144
|
+
instancedApi.forEach(api => {
|
145
145
|
api.applyImpulse({ x: 0, y: 10, z: 0 });
|
146
146
|
});
|
147
147
|
}, []);
|
@@ -153,13 +153,13 @@ const Scene = () => {
|
|
153
153
|
const rotations = Array.from({ length: COUNT }, (_, index) => [
|
154
154
|
Math.random(),
|
155
155
|
Math.random(),
|
156
|
-
Math.random()
|
156
|
+
Math.random()
|
157
157
|
]);
|
158
158
|
|
159
159
|
const scales = Array.from({ length: COUNT }, (_, index) => [
|
160
160
|
Math.random(),
|
161
161
|
Math.random(),
|
162
|
-
Math.random()
|
162
|
+
Math.random()
|
163
163
|
]);
|
164
164
|
|
165
165
|
return (
|
@@ -210,9 +210,9 @@ const Scene = () => {
|
|
210
210
|
};
|
211
211
|
```
|
212
212
|
|
213
|
-
## Events
|
213
|
+
## Collision Events
|
214
214
|
|
215
|
-
You can subscribe collision and state events on
|
215
|
+
You can subscribe to collision and state events on a RigidBody:
|
216
216
|
|
217
217
|
```tsx
|
218
218
|
const RigidBottle = () => {
|
@@ -235,6 +235,76 @@ return (
|
|
235
235
|
}
|
236
236
|
```
|
237
237
|
|
238
|
+
You may also subscribe to collision events on individual Colliders:
|
239
|
+
|
240
|
+
```tsx
|
241
|
+
<CuboidCollider
|
242
|
+
onCollisionEnter={payload => {
|
243
|
+
/* ... */
|
244
|
+
}}
|
245
|
+
onCollisionExit={payload => {
|
246
|
+
/* ... */
|
247
|
+
}}
|
248
|
+
/>
|
249
|
+
```
|
250
|
+
|
251
|
+
The `payload` object for all collision callbacks contains the following properties:
|
252
|
+
|
253
|
+
- `target`
|
254
|
+
The other rigidbody that was involved in the collision event.
|
255
|
+
- `collider`
|
256
|
+
The other collider that was involved in the collision event.
|
257
|
+
- `manifold` (enter only)
|
258
|
+
The [contact manifold](https://rapier.rs/javascript3d/classes/TempContactManifold.html) generated by the collision event.
|
259
|
+
- `flipped` (enter only)
|
260
|
+
`true` if the data in the `manifold` [is flipped](https://rapier.rs/javascript3d/classes/World.html#contactPair).
|
261
|
+
|
262
|
+
### Configuring collision and solver groups
|
263
|
+
|
264
|
+
Both `<RigidBody>` as well as all collider components allow you to configure `collisionsGroups` and `solverGroups` properties that configures which groups the colliders are in, and what other groups they should interact with in potential collision and solving events (you will find more details on this in the [Rapier documentation](https://rapier.rs/docs/user_guides/javascript/colliders/#collision-groups-and-solver-groups).)
|
265
|
+
|
266
|
+
Since these are set as bitmasks and bitmasks can get a bit unwieldy to generate, this library provides a helper called `interactionGroups` that can be used to generate bitmasks from numbers and arrays of groups, where groups are identified using numbers from 0 to 15.
|
267
|
+
|
268
|
+
The first argument is the group, or an array of groups, that the collider is a member of; the second argument is the group, or an array of groups, that the collider should interact with.
|
269
|
+
|
270
|
+
Here the collider is in group 0, and interacts with colliders from groups 0, 1 and 2:
|
271
|
+
|
272
|
+
```tsx
|
273
|
+
<CapsuleCollider collisionGroups={interactionGroups(0, [0, 1, 2])} />
|
274
|
+
```
|
275
|
+
|
276
|
+
This collider is in multiple groups, but only interacts with colliders from a single group:
|
277
|
+
|
278
|
+
```tsx
|
279
|
+
<CapsuleCollider collisionGroups={interactionGroups([0, 5], 7)} />
|
280
|
+
```
|
281
|
+
|
282
|
+
When the second argument is omitted, the collider will interact with all groups:
|
283
|
+
|
284
|
+
```tsx
|
285
|
+
<CapsuleCollider collisionGroups={interactionGroups(12)} />
|
286
|
+
```
|
287
|
+
|
288
|
+
> **Note** Please remember that in Rapier, for a collision (or solving) event to occur, both colliders involved in the event must match the related interaction groups -- a one-way match will be ignored.
|
289
|
+
|
290
|
+
> **Note** By default, colliders are members of all groups, and will interact with all other groups.
|
291
|
+
|
292
|
+
## Sensors
|
293
|
+
|
294
|
+
A Collider can be set to be a sensor, which means that it will not generate any contact points, and will not be affected by forces. This is useful for detecting when a collider enters or leaves another collider, without affecting the other collider.
|
295
|
+
|
296
|
+
```tsx
|
297
|
+
<RigidBody>
|
298
|
+
<GoalPosts />
|
299
|
+
|
300
|
+
<CuboidCollider
|
301
|
+
args={[5, 5, 1]}
|
302
|
+
sensor
|
303
|
+
onIntersectionEnter={() => console.log("Goal!")}
|
304
|
+
/>
|
305
|
+
</RigidBody>
|
306
|
+
```
|
307
|
+
|
238
308
|
## Joints
|
239
309
|
|
240
310
|
WIP
|
@@ -255,7 +325,7 @@ In order, but also not necessarily:
|
|
255
325
|
- [x] Colliders outside RigidBodies
|
256
326
|
- [x] InstancedMesh support
|
257
327
|
- [x] Timestep improvements for determinism
|
258
|
-
- [
|
328
|
+
- [x] Normalize and improve collision events (add events to single Colliders)
|
329
|
+
- [ ] Add collision events to InstancedRigidBodies
|
259
330
|
- [ ] Docs
|
260
331
|
- [ ] CodeSandbox examples
|
261
|
-
- [ ] Helpers, for things like Vehicle, Rope, Player, etc
|