@react-three/rapier 0.5.2 → 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.2",
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
 
@@ -103,14 +105,61 @@ Objects work inside other transformed objects as well. Simulation runs in world
103
105
  import { Box } from "@react-three/drei";
104
106
  import { RigidBody, CuboidCollider } from "@react-three/rapier";
105
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
+
106
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
+
107
151
  return (
108
- <group position={[2, 5, 0]} rotation={[0, 0.3, 2]}>
109
- <RigidBody>
110
- <Box />
111
- <CuboidCollider args={[0.5, 0.5, 0.5]} />
112
- </RigidBody>
113
- </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>
114
163
  );
115
164
  };
116
165
  ```
@@ -170,19 +219,22 @@ return (
170
219
 
171
220
  WIP
172
221
 
173
- ## Roadmap?
222
+ ---
223
+
224
+ ## Roadmap
174
225
 
175
226
  In order, but also not necessarily:
176
227
 
177
- - [x] Draft of all base shapes
178
- - [x] Draft of all base joints
228
+ - [x] RigidBodies, Colliders
229
+ - [x] Joints
179
230
  - [x] Nested objects retain world transforms
180
231
  - [x] Nested objects retain correct collider scale
181
232
  - [x] Automatic colliders based on rigidbody children
182
233
  - [x] Translation and rotational constraints
183
234
  - [x] Collision events
184
- - [ ] Colliders outside RigidBodies
185
- - [ ] InstancedMesh support
235
+ - [x] Colliders outside RigidBodies
236
+ - [x] InstancedMesh support
237
+ - [ ] Normalize and improve collision events (add events to single Colliders, InstancedRigidBodies, etc)
186
238
  - [ ] Docs
187
239
  - [ ] CodeSandbox examples
188
240
  - [ ] Helpers, for things like Vehicle, Rope, Player, etc