@react-three/rapier 0.5.0 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/rapier",
3
- "version": "0.5.0",
3
+ "version": "0.6.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",
package/readme.md CHANGED
@@ -1,4 +1,6 @@
1
- <h1 align="center">@react-three/rapier 🗡</h1>
1
+ <p align="center">
2
+ <img src="misc/hero.svg" />
3
+ </p>
2
4
 
3
5
  <p align="center">⚠️ Under heavy development. All APIs are subject to change. ⚠️</p>
4
6
 
@@ -60,19 +62,39 @@ Turn off automatic collider generation globally, but apply auto generation local
60
62
  ```tsx
61
63
  const Scene = () => (
62
64
  <Physics colliders={false}>
65
+ {/* Use an automatic CuboidCollider for all meshes inside this RigidBody */}
63
66
  <RigidBody colliders="cuboid">
64
67
  <Box />
65
68
  </RigidBody>
66
69
 
70
+ {/* Use an automatic BallCollider for all meshes inside this RigidBody */}
67
71
  <RigidBody position={[0, 10, 0]} colliders="ball">
68
72
  <Sphere />
69
73
  </RigidBody>
70
74
 
75
+ {/* Make a compound shape with two custom BallColliders */}
71
76
  <RigidBody position={[0, 10, 0]}>
72
77
  <Sphere />
73
78
  <BallCollider args={0.5} />
74
79
  <BallCollider args={0.5} position={[1, 0, 0]} />
75
80
  </RigidBody>
81
+
82
+ {/* Make a compound shape with two custom BallColliders, an automatic BallCollider,
83
+ Two automatic MeshColliders, based on two different shape strategies */}
84
+ <RigidBody position={[0, 10, 0]} colliders='ball'>
85
+ <MeshCollider type="trimesh">
86
+ <mesh ... />
87
+ </MeshCollider>
88
+
89
+ <MeshCollider type="hull">
90
+ <mesh ... />
91
+ </MeshCollider>
92
+
93
+ <Sphere />
94
+
95
+ <BallCollider args={0.5} />
96
+ <BallCollider args={0.5} position={[1, 0, 0]} />
97
+ </RigidBody>
76
98
  </Physics>
77
99
  );
78
100
  ```
@@ -83,14 +105,61 @@ Objects work inside other transformed objects as well. Simulation runs in world
83
105
  import { Box } from "@react-three/drei";
84
106
  import { RigidBody, CuboidCollider } from "@react-three/rapier";
85
107
 
108
+ const Scene = () => (
109
+ <group position={[2, 5, 0]} rotation={[0, 0.3, 2]}>
110
+ <RigidBody>
111
+ <Box />
112
+ <CuboidCollider args={[0.5, 0.5, 0.5]} />
113
+ </RigidBody>
114
+ </group>
115
+ );
116
+ ```
117
+
118
+ ## Instanced Meshes
119
+
120
+ Instanced meshes can also be used and have automatic colliders generated from their mesh.
121
+
122
+ By wrapping the `InstancedMesh` in `<InstancedRigidBodies />`, each instance will be attached to an individual `RigidBody`.
123
+
124
+ ```tsx
125
+ import { InstancedRigidBodies } from "@react-three/rapier";
126
+
127
+ const COUNT = 1000;
128
+
86
129
  const Scene = () => {
130
+ const instancedApi = useRef<InstancedRigidBodyApi>(null);
131
+
132
+ useEffect(() => {
133
+ // You can access individual instanced by their index
134
+ instancedApi.at(40).applyImpulse({ x: 0, y: 10, z: 0 });
135
+
136
+ // Or update all instances as if they were in an array
137
+ instancedApi.forEach((api) => {
138
+ api.applyImpulse({ x: 0, y: 10, z: 0 });
139
+ });
140
+ }, []);
141
+
142
+ // We can set the initial positions, and rotations, of the instances by providing an array equal to the instance count
143
+ const positions = Array.from({ length: COUNT }, (_, index) => [index, 0, 0]);
144
+
145
+ const rotations = Array.from({ length: COUNT }, (_, index) => [
146
+ Math.random(),
147
+ Math.random(),
148
+ Math.random(),
149
+ ]);
150
+
87
151
  return (
88
- <group position={[2, 5, 0]} rotation={[0, 0.3, 2]}>
89
- <RigidBody>
90
- <Box />
91
- <CuboidCollider args={[0.5, 0.5, 0.5]} />
92
- </RigidBody>
93
- </group>
152
+ <InstancedRigidBodies
153
+ ref={instancedApi}
154
+ positions={positions}
155
+ rotations={rotations}
156
+ colliders="ball"
157
+ >
158
+ <instancedMesh args={[undefined, undefined, COUNT]}>
159
+ <sphereBufferGeometry args={[0.2]} />
160
+ <meshPhysicalGeometry color="blue" />
161
+ </instancedMesh>
162
+ </InstancedRigidBodies>
94
163
  );
95
164
  };
96
165
  ```
@@ -150,19 +219,22 @@ return (
150
219
 
151
220
  WIP
152
221
 
153
- ## Roadmap?
222
+ ---
223
+
224
+ ## Roadmap
154
225
 
155
226
  In order, but also not necessarily:
156
227
 
157
- - [x] Draft of all base shapes
158
- - [x] Draft of all base joints
228
+ - [x] RigidBodies, Colliders
229
+ - [x] Joints
159
230
  - [x] Nested objects retain world transforms
160
231
  - [x] Nested objects retain correct collider scale
161
232
  - [x] Automatic colliders based on rigidbody children
162
233
  - [x] Translation and rotational constraints
163
234
  - [x] Collision events
164
- - [ ] Colliders outside RigidBodies
165
- - [ ] InstancedMesh support
235
+ - [x] Colliders outside RigidBodies
236
+ - [x] InstancedMesh support
237
+ - [ ] Normalize and improve collision events (add events to single Colliders, InstancedRigidBodies, etc)
166
238
  - [ ] Docs
167
239
  - [ ] CodeSandbox examples
168
240
  - [ ] Helpers, for things like Vehicle, Rope, Player, etc
package/CHANGELOG.md DELETED
@@ -1,87 +0,0 @@
1
- # @react-three/rapier
2
-
3
- ## 0.5.0
4
-
5
- ### Minor Changes
6
-
7
- - a3be5f6: Remove hooks api in favor of better fleshed out components
8
-
9
- ### Patch Changes
10
-
11
- - a3be5f6: Update types for Joints -- now only allow RefObjects of RigidBodyApi
12
- - a3be5f6: Fix setKinematicRotation (convert Vector3 to Quaternion)
13
- - a3be5f6: Update to @dimforge/rapier3d-compat@0.9.0
14
- - a3be5f6: Allow setting the physics timeStep
15
- - a3be5f6: Add rotational and transitional constraits to RigidBody
16
- - a3be5f6: Allow updating the gravity at runtime
17
-
18
- ## 0.4.3
19
-
20
- ### Patch Changes
21
-
22
- - f7a8a2d: Rigid body creation hooks should not use auto colliders
23
- - 663eeb5: Fix default collider setting
24
-
25
- ## 0.4.2
26
-
27
- ### Patch Changes
28
-
29
- - 387b32c: Add restitution and friction as props for auto-generated colliders on RigidBody
30
-
31
- ## 0.4.1
32
-
33
- ### Patch Changes
34
-
35
- - bb7a269: Add useful proxied api methods to rigidbody
36
-
37
- ## 0.4.0
38
-
39
- ### Minor Changes
40
-
41
- - dd535aa: Update to @dimforge/rapier3d-compat@0.8.1, pinned version
42
-
43
- ### Patch Changes
44
-
45
- - dd535aa: Better <Physics /> lifecycle making reinitialization more stable
46
-
47
- ## 0.3.1
48
-
49
- ### Patch Changes
50
-
51
- - 37d2621: Pin rapier3d version to 0.8.0-alpha.2
52
-
53
- ## 0.3.0
54
-
55
- ### Minor Changes
56
-
57
- - 7e36172: Add collision and sleep/awake events
58
-
59
- ## 0.2.0
60
-
61
- ### Minor Changes
62
-
63
- - 584ce08: Expose joint api, however no joint is returned when created (rapier bug?)
64
-
65
- ### Patch Changes
66
-
67
- - 584ce08: All parts now uses a more rigid initiation process
68
- - 584ce08: Apply bounding box offset for auto colliders
69
- - 584ce08: Use single update loop instead of individual rigid body callbacks
70
-
71
- ## 0.1.2
72
-
73
- ### Patch Changes
74
-
75
- - 4f7440c: fix: make global colliders setting progate to children
76
-
77
- ## 0.1.1
78
-
79
- ### Patch Changes
80
-
81
- - 260e6d1: Fix Physics "colliders" value not being applied in children by default
82
-
83
- ## 0.1.0
84
-
85
- ### Minor Changes
86
-
87
- - First release with base functionality of RigidBodies in Rapier