@react-three/rapier 0.5.2 → 0.6.2

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.2",
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="https://raw.githubusercontent.com/pmndrs/react-three-rapier/HEAD/packages/react-three-rapier/misc/hero.svg" alt="@react-three/rapier" />
3
+ </p>
2
4
 
3
5
  <p align="center">⚠️ Under heavy development. All APIs are subject to change. ⚠️</p>
4
6
 
@@ -103,14 +105,69 @@ 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, and scales, of
143
+ // the instances by providing an array equal to the instance count
144
+ const positions = Array.from({ length: COUNT }, (_, index) => [index, 0, 0]);
145
+
146
+ const rotations = Array.from({ length: COUNT }, (_, index) => [
147
+ Math.random(),
148
+ Math.random(),
149
+ Math.random(),
150
+ ]);
151
+
152
+ const scales = Array.from({ length: COUNT }, (_, index) => [
153
+ Math.random(),
154
+ Math.random(),
155
+ Math.random(),
156
+ ]);
157
+
107
158
  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>
159
+ <InstancedRigidBodies
160
+ ref={instancedApi}
161
+ positions={positions}
162
+ rotations={rotations}
163
+ scales={scales}
164
+ colliders="ball"
165
+ >
166
+ <instancedMesh args={[undefined, undefined, COUNT]}>
167
+ <sphereBufferGeometry args={[0.2]} />
168
+ <meshPhysicalGeometry color="blue" />
169
+ </instancedMesh>
170
+ </InstancedRigidBodies>
114
171
  );
115
172
  };
116
173
  ```
@@ -170,19 +227,22 @@ return (
170
227
 
171
228
  WIP
172
229
 
173
- ## Roadmap?
230
+ ---
231
+
232
+ ## Roadmap
174
233
 
175
234
  In order, but also not necessarily:
176
235
 
177
- - [x] Draft of all base shapes
178
- - [x] Draft of all base joints
236
+ - [x] RigidBodies, Colliders
237
+ - [x] Joints
179
238
  - [x] Nested objects retain world transforms
180
239
  - [x] Nested objects retain correct collider scale
181
240
  - [x] Automatic colliders based on rigidbody children
182
241
  - [x] Translation and rotational constraints
183
242
  - [x] Collision events
184
- - [ ] Colliders outside RigidBodies
185
- - [ ] InstancedMesh support
243
+ - [x] Colliders outside RigidBodies
244
+ - [x] InstancedMesh support
245
+ - [ ] Normalize and improve collision events (add events to single Colliders, InstancedRigidBodies, etc)
186
246
  - [ ] Docs
187
247
  - [ ] CodeSandbox examples
188
248
  - [ ] Helpers, for things like Vehicle, Rope, Player, etc