@react-three/rapier 0.1.0 → 0.2.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.
@@ -1,9 +1,9 @@
1
- import React, { useRef, useMemo, createContext, useContext, useEffect, useLayoutEffect, forwardRef, useImperativeHandle, useState, memo } from 'react';
1
+ import React, { useRef, useState, useLayoutEffect, useMemo, createContext, useContext, useEffect, forwardRef, useImperativeHandle, memo } from 'react';
2
2
  import { useAsset } from 'use-asset';
3
3
  import { useFrame } from '@react-three/fiber';
4
+ import { Vector3, Quaternion, Object3D, Euler, CylinderBufferGeometry, BufferGeometry, BufferAttribute, SphereBufferGeometry, BoxBufferGeometry } from 'three';
4
5
  import { ColliderDesc, CoefficientCombineRule, ShapeType } from '@dimforge/rapier3d-compat';
5
6
  export { CoefficientCombineRule, Collider as RapierCollider, RigidBody as RapierRigidBody } from '@dimforge/rapier3d-compat';
6
- import { Quaternion, Vector3, Object3D, Euler, CylinderBufferGeometry, BufferGeometry, BufferAttribute, SphereBufferGeometry, BoxBufferGeometry } from 'three';
7
7
 
8
8
  const vectorArrayToObject = arr => {
9
9
  const [x, y, z] = arr;
@@ -38,7 +38,7 @@ const scaleColliderArgs = (shape, args, scale) => {
38
38
  const scaleArray = [scale.x, scale.y, scale.z];
39
39
  return newArgs.map((arg, index) => scaleArray[index] * arg);
40
40
  };
41
- const createColliderFromOptions = (options, world, body, scale = {
41
+ const createColliderFromOptions = (options, world, rigidBodyHandle, scale = {
42
42
  x: 1,
43
43
  y: 1,
44
44
  z: 1
@@ -80,12 +80,13 @@ const createColliderFromOptions = (options, world, body, scale = {
80
80
  });
81
81
  }
82
82
 
83
- const collider = world.createCollider(colliderDesc, body.handle);
83
+ const collider = world.createCollider(colliderDesc, rigidBodyHandle);
84
84
  return collider;
85
85
  };
86
86
  const createCollidersFromChildren = (object, rigidBody, type, world) => {
87
87
  const colliders = [];
88
88
  let desc;
89
+ let offset = new Vector3();
89
90
  object.traverse(child => {
90
91
  if ("isMesh" in child) {
91
92
  const {
@@ -112,6 +113,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
112
113
  boundingBox
113
114
  } = geometry;
114
115
  const size = boundingBox.getSize(new Vector3());
116
+ boundingBox.getCenter(offset);
115
117
  desc = ColliderDesc.cuboid(size.x / 2 * scale.x, size.y / 2 * scale.y, size.z / 2 * scale.z);
116
118
  }
117
119
  break;
@@ -123,6 +125,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
123
125
  boundingSphere
124
126
  } = geometry;
125
127
  const radius = boundingSphere.radius * scale.x;
128
+ offset.copy(boundingSphere.center);
126
129
  desc = ColliderDesc.ball(radius);
127
130
  }
128
131
  break;
@@ -147,7 +150,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
147
150
 
148
151
 
149
152
  const parentWorldScale = child.parent.getWorldScale(new Vector3());
150
- desc.setTranslation(x * parentWorldScale.x, y * parentWorldScale.y, z * parentWorldScale.z).setRotation({
153
+ desc.setTranslation((x + offset.x) * parentWorldScale.x, (y + offset.y) * parentWorldScale.y, (z + offset.z) * parentWorldScale.z).setRotation({
151
154
  x: rx,
152
155
  y: ry,
153
156
  z: rz,
@@ -171,6 +174,99 @@ const scaleVertices = (vertices, scale) => {
171
174
  return scaledVerts;
172
175
  };
173
176
 
177
+ // TODO: Flesh this out
178
+ const createRigidBodyApi = ref => {
179
+ return {
180
+ raw: () => ref.current(),
181
+
182
+ get handle() {
183
+ return ref.current().handle;
184
+ },
185
+
186
+ applyImpulse({
187
+ x,
188
+ y,
189
+ z
190
+ }) {
191
+ ref.current().applyImpulse({
192
+ x,
193
+ y,
194
+ z
195
+ }, true);
196
+ },
197
+
198
+ applyTorqueImpulse({
199
+ x,
200
+ y,
201
+ z
202
+ }) {
203
+ ref.current().applyTorqueImpulse({
204
+ x,
205
+ y,
206
+ z
207
+ }, true);
208
+ },
209
+
210
+ translation() {
211
+ const {
212
+ x,
213
+ y,
214
+ z
215
+ } = ref.current().translation();
216
+ return new Vector3(x, y, z);
217
+ },
218
+
219
+ rotation() {
220
+ const {
221
+ x,
222
+ y,
223
+ z,
224
+ w
225
+ } = ref.current().rotation();
226
+ return new Quaternion(x, y, z, w);
227
+ }
228
+
229
+ };
230
+ }; // TODO: Flesh this out
231
+
232
+ const createColliderApi = ref => {
233
+ return {
234
+ raw: () => ref.current(),
235
+
236
+ get handle() {
237
+ return ref.current().handle;
238
+ }
239
+
240
+ };
241
+ };
242
+ const createWorldApi = ref => {
243
+ return {
244
+ raw: () => ref.current(),
245
+ getCollider: handle => ref.current().getCollider(handle),
246
+ getRigidBody: handle => ref.current().getRigidBody(handle),
247
+ createRigidBody: desc => ref.current().createRigidBody(desc),
248
+ createCollider: (desc, rigidBodyHandle) => ref.current().createCollider(desc, rigidBodyHandle),
249
+ removeRigidBody: rigidBody => ref.current().removeRigidBody(rigidBody),
250
+ removeCollider: collider => ref.current().removeCollider(collider, true),
251
+ createImpulseJoint: (params, rigidBodyA, rigidBodyB) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB),
252
+ removeImpulseJoint: joint => ref.current().removeImpulseJoint(joint, true),
253
+ forEachCollider: callback => ref.current().forEachCollider(callback)
254
+ };
255
+ }; // TODO: Broken currently, waiting for Rapier3D to fix
256
+
257
+ const createJointApi = ref => {
258
+ return {
259
+ raw: () => ref.current(),
260
+
261
+ get handle() {
262
+ return ref.current().handle;
263
+ },
264
+
265
+ configureMotorPosition: (targetPos, stiffness, damping) => ref.current().configureMotorPosition(targetPos, stiffness, damping),
266
+ configureMotorVelocity: (targetVel, damping) => ref.current().configureMotorVelocity(targetVel, damping)
267
+ };
268
+ };
269
+
174
270
  const RapierContext = /*#__PURE__*/createContext(undefined);
175
271
 
176
272
  const importRapier = async () => {
@@ -185,30 +281,81 @@ const Physics = ({
185
281
  children
186
282
  }) => {
187
283
  const rapier = useAsset(importRapier);
188
- const stepFuncs = useRef([]);
189
- const world = useMemo(() => {
190
- if (!rapier.World) return null;
191
- let world = new rapier.World(vectorArrayToObject(_gravity));
192
- return world;
193
- }, [rapier]);
284
+ const worldRef = useRef();
285
+ const getWorldRef = useRef(() => {
286
+ if (!worldRef.current) {
287
+ const world = new rapier.World(vectorArrayToObject(_gravity));
288
+ worldRef.current = world;
289
+ }
290
+
291
+ return worldRef.current;
292
+ });
293
+ const [colliderMeshes] = useState(() => new Map());
294
+ const [rigidBodyMeshes] = useState(() => new Map()); // Init world
295
+
296
+ useLayoutEffect(() => {
297
+ const world = getWorldRef.current();
298
+ return () => {
299
+ if (world) {
300
+ world.free();
301
+ worldRef.current = undefined;
302
+ }
303
+ };
304
+ }, []);
194
305
  const time = useRef(performance.now());
195
306
  useFrame(context => {
196
- // Set timestep to current delta, to allow for variable frame rates
307
+ const world = worldRef.current;
308
+ if (!world) return; // Set timestep to current delta, to allow for variable frame rates
197
309
  // We cap the delta at 100, so that the physics simulation doesn't get wild
310
+
198
311
  const now = performance.now();
199
312
  const delta = Math.min(100, now - time.current);
200
313
  world.timestep = delta / 1000;
201
- world.step(); // Run all step funcs
314
+ world.step(); // Update meshes
315
+
316
+ rigidBodyMeshes.forEach((mesh, handle) => {
317
+ const rigidBody = world.getRigidBody(handle);
202
318
 
203
- stepFuncs.current.forEach(func => func());
319
+ if (!rigidBody || rigidBody.isSleeping() || rigidBody.isFixed() || !mesh.parent) {
320
+ return;
321
+ }
322
+
323
+ const {
324
+ x,
325
+ y,
326
+ z
327
+ } = rigidBody.translation();
328
+ const {
329
+ x: rx,
330
+ y: ry,
331
+ z: rz,
332
+ w: rw
333
+ } = rigidBody.rotation();
334
+ const scale = mesh.getWorldScale(new Vector3()); // haha matrixes I have no idea what I'm doing :)
335
+
336
+ const o = new Object3D();
337
+ o.position.set(x, y, z);
338
+ o.rotation.setFromQuaternion(new Quaternion(rx, ry, rz, rw));
339
+ o.scale.set(scale.x, scale.y, scale.z);
340
+ o.updateMatrix();
341
+ o.applyMatrix4(mesh.parent.matrixWorld.clone().invert());
342
+ o.updateMatrix();
343
+ mesh.position.setFromMatrixPosition(o.matrix);
344
+ mesh.rotation.setFromRotationMatrix(o.matrix);
345
+ });
204
346
  time.current = now;
205
347
  });
348
+ const api = useMemo(() => createWorldApi(getWorldRef), []);
206
349
  const context = useMemo(() => ({
207
- RAPIER: rapier,
208
- world,
209
- colliders: _colliders,
210
- stepFuncs: stepFuncs.current
211
- }), [rapier]);
350
+ rapier,
351
+ world: api,
352
+ physicsOptions: {
353
+ colliders: _colliders,
354
+ gravity: _gravity
355
+ },
356
+ colliderMeshes,
357
+ rigidBodyMeshes
358
+ }), []);
212
359
  return /*#__PURE__*/React.createElement(RapierContext.Provider, {
213
360
  value: context
214
361
  }, children);
@@ -257,64 +404,44 @@ function _objectSpread2(target) {
257
404
 
258
405
  const useRapier = () => {
259
406
  return useContext(RapierContext);
260
- }; // Private hook for updating the simulations on objects
261
-
262
- const useRapierStep = callback => {
263
- const {
264
- stepFuncs
265
- } = useRapier();
266
- useEffect(() => {
267
- stepFuncs.push(callback);
268
- return () => {
269
- const index = stepFuncs.indexOf(callback);
270
- stepFuncs.splice(index, 1);
271
- };
272
- }, [callback]);
273
- };
274
- const useCollider = (body, options = {}) => {
275
- const {
276
- RAPIER,
277
- world
278
- } = useRapier();
279
- const collider = useMemo(() => {
280
- return createColliderFromOptions(options, world, body);
281
- }, []);
282
- useEffect(() => {
283
- return () => {
284
- world.removeCollider(collider, false);
285
- };
286
- }, []);
287
- return [collider];
288
407
  };
289
- const useRigidBody = options => {
408
+ const useRigidBody = (options = {}) => {
290
409
  const {
291
- RAPIER,
292
- world
410
+ rapier,
411
+ world,
412
+ rigidBodyMeshes,
413
+ physicsOptions
293
414
  } = useRapier();
294
415
  const ref = useRef(); // Create rigidbody
295
416
 
296
- const rigidBody = useMemo(() => {
297
- var _options$linearVeloci, _options$angularVeloc, _options$gravityScale, _options$canSleep, _options$ccd;
298
-
299
- const [lvx, lvy, lvz] = (_options$linearVeloci = options === null || options === void 0 ? void 0 : options.linearVelocity) !== null && _options$linearVeloci !== void 0 ? _options$linearVeloci : [0, 0, 0];
300
- const [avx, avy, avz] = (_options$angularVeloc = options === null || options === void 0 ? void 0 : options.angularVelocity) !== null && _options$angularVeloc !== void 0 ? _options$angularVeloc : [0, 0, 0];
301
- const gravityScale = (_options$gravityScale = options === null || options === void 0 ? void 0 : options.gravityScale) !== null && _options$gravityScale !== void 0 ? _options$gravityScale : 1;
302
- const canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
303
- const ccdEnabled = (_options$ccd = options === null || options === void 0 ? void 0 : options.ccd) !== null && _options$ccd !== void 0 ? _options$ccd : false;
304
- const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
305
- (options === null || options === void 0 ? void 0 : options.position) || [0, 0, 0];
306
- (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
307
- const rigidBodyDesc = new RAPIER.RigidBodyDesc(type).setLinvel(lvx, lvy, lvz).setAngvel({
308
- x: avx,
309
- y: avy,
310
- z: avz
311
- }).setGravityScale(gravityScale).setCanSleep(canSleep).setCcdEnabled(ccdEnabled).setTranslation(0, 0, 0);
312
- const body = world.createRigidBody(rigidBodyDesc);
313
- return body;
314
- }, []); // Setup
417
+ const rigidBodyRef = useRef();
418
+ const getRigidBodyRef = useRef(() => {
419
+ if (!rigidBodyRef.current) {
420
+ var _options$linearVeloci, _options$angularVeloc, _options$gravityScale, _options$canSleep, _options$ccd;
421
+
422
+ const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
423
+ const [lvx, lvy, lvz] = (_options$linearVeloci = options === null || options === void 0 ? void 0 : options.linearVelocity) !== null && _options$linearVeloci !== void 0 ? _options$linearVeloci : [0, 0, 0];
424
+ const [avx, avy, avz] = (_options$angularVeloc = options === null || options === void 0 ? void 0 : options.angularVelocity) !== null && _options$angularVeloc !== void 0 ? _options$angularVeloc : [0, 0, 0];
425
+ const gravityScale = (_options$gravityScale = options === null || options === void 0 ? void 0 : options.gravityScale) !== null && _options$gravityScale !== void 0 ? _options$gravityScale : 1;
426
+ const canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
427
+ const ccdEnabled = (_options$ccd = options === null || options === void 0 ? void 0 : options.ccd) !== null && _options$ccd !== void 0 ? _options$ccd : false;
428
+ const desc = new rapier.RigidBodyDesc(type).setLinvel(lvx, lvy, lvz).setAngvel({
429
+ x: avx,
430
+ y: avy,
431
+ z: avz
432
+ }).setGravityScale(gravityScale).setCanSleep(canSleep).setCcdEnabled(ccdEnabled);
433
+ const rigidBody = world.createRigidBody(desc);
434
+ rigidBodyRef.current = rigidBody;
435
+ }
436
+
437
+ return rigidBodyRef.current;
438
+ }); // Setup
315
439
 
316
440
  useEffect(() => {
317
- var _ref$current$parent, _options$colliders;
441
+ var _ref$current$parent, _ref, _options$colliders;
442
+
443
+ const rigidBody = getRigidBodyRef.current();
444
+ rigidBodyRef.current = rigidBody;
318
445
 
319
446
  if (!ref.current) {
320
447
  ref.current = new Object3D();
@@ -347,43 +474,42 @@ const useRigidBody = options => {
347
474
  }, false);
348
475
  rigidBody.resetForces(false);
349
476
  rigidBody.resetTorques(false);
350
- const colliderSetting = (_options$colliders = options === null || options === void 0 ? void 0 : options.colliders) !== null && _options$colliders !== void 0 ? _options$colliders : false;
477
+ const colliderSetting = (_ref = (_options$colliders = options === null || options === void 0 ? void 0 : options.colliders) !== null && _options$colliders !== void 0 ? _options$colliders : physicsOptions.colliders) !== null && _ref !== void 0 ? _ref : false;
351
478
  const autoColliders = colliderSetting !== false ? createCollidersFromChildren(ref.current, rigidBody, colliderSetting, world) : [];
479
+ rigidBody.wakeUp();
480
+ rigidBodyMeshes.set(rigidBody.handle, ref.current);
352
481
  return () => {
482
+ autoColliders.forEach(collider => world.removeCollider(collider));
353
483
  world.removeRigidBody(rigidBody);
354
- autoColliders.forEach(collider => world.removeCollider(collider, false));
484
+ rigidBodyRef.current = undefined;
485
+ rigidBodyMeshes.delete(rigidBody.handle);
355
486
  };
356
487
  }, []);
357
- useRapierStep(() => {
358
- if (rigidBody && ref.current) {
359
- const {
360
- x,
361
- y,
362
- z
363
- } = rigidBody.translation();
364
- const {
365
- x: rx,
366
- y: ry,
367
- z: rz,
368
- w: rw
369
- } = rigidBody.rotation();
370
- const scale = ref.current.getWorldScale(new Vector3());
371
-
372
- if (ref.current.parent) {
373
- // haha matrixes I have no idea what I'm doing :)
374
- const o = new Object3D();
375
- o.position.set(x, y, z);
376
- o.rotation.setFromQuaternion(new Quaternion(rx, ry, rz, rw));
377
- o.scale.set(scale.x, scale.y, scale.z);
378
- o.updateMatrix();
379
- o.applyMatrix4(ref.current.parent.matrixWorld.clone().invert());
380
- o.updateMatrix();
381
- ref.current.position.setFromMatrixPosition(o.matrix);
382
- ref.current.rotation.setFromRotationMatrix(o.matrix);
383
- }
488
+ const api = useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
489
+ return [ref, api];
490
+ };
491
+ const useCollider = (body, options = {}) => {
492
+ const {
493
+ world
494
+ } = useRapier();
495
+ const colliderRef = useRef();
496
+ const objectRef = useRef();
497
+ const getColliderRef = useRef(() => {
498
+ if (!colliderRef.current) {
499
+ colliderRef.current = createColliderFromOptions(options, world, body.handle);
384
500
  }
501
+
502
+ return colliderRef.current;
385
503
  });
386
- return [ref, rigidBody];
504
+ useEffect(() => {
505
+ const collider = getColliderRef.current();
506
+ return () => {
507
+ if (collider) world.removeCollider(collider);
508
+ colliderRef.current = undefined;
509
+ };
510
+ }, []);
511
+ const api = useMemo(() => createColliderApi(getColliderRef), []);
512
+ return [objectRef, api];
387
513
  };
388
514
  const useRigidBodyWithCollider = (rigidBodyOptions, colliderOptions) => {
389
515
  const {
@@ -396,9 +522,9 @@ const useRigidBodyWithCollider = (rigidBodyOptions, colliderOptions) => {
396
522
  }
397
523
 
398
524
  const scale = ref.current.getWorldScale(new Vector3());
399
- const collider = createColliderFromOptions(colliderOptions, world, rigidBody, scale);
525
+ const collider = createColliderFromOptions(colliderOptions, world, rigidBody.handle, scale);
400
526
  return () => {
401
- world.removeCollider(collider, false);
527
+ world.removeCollider(collider);
402
528
  };
403
529
  }, []);
404
530
  return [ref, rigidBody];
@@ -524,20 +650,42 @@ const useRoundConvexMesh = (rigidBodyOptions = {}, colliderOptions = {}) => {
524
650
 
525
651
  const useImpulseJoint = (body1, body2, params) => {
526
652
  const {
527
- world,
528
- RAPIER
653
+ world
529
654
  } = useRapier();
530
- useLayoutEffect(() => {
531
- let joint;
655
+ const jointRef = useRef();
656
+ const getJointRef = useRef(() => {
657
+ if (!jointRef.current) {
658
+ let rb1;
659
+ let rb2;
660
+
661
+ if ('handle' in body1 && 'handle' in body2) {
662
+ rb1 = world.getRigidBody(body1.handle);
663
+ rb2 = world.getRigidBody(body2.handle);
664
+ jointRef.current = world.createImpulseJoint(params, rb1, rb2);
665
+ }
532
666
 
533
- if (body1 && body2 && params) {
534
- joint = world.createImpulseJoint(params, body1.current, body2.current);
667
+ if ('current' in body1 && body1.current && 'current' in body2 && body2.current) {
668
+ rb1 = world.getRigidBody(body1.current.handle);
669
+ rb2 = world.getRigidBody(body2.current.handle);
670
+ const newJoint = world.createImpulseJoint(params, rb1, rb2);
671
+ jointRef.current = newJoint;
672
+ }
535
673
  }
536
674
 
675
+ return jointRef.current;
676
+ });
677
+ useEffect(() => {
678
+ const joint = getJointRef.current();
537
679
  return () => {
538
- if (joint) world.removeImpulseJoint(joint, true);
680
+ if (joint) {
681
+ console.log('remove joint', joint);
682
+ world.removeImpulseJoint(joint);
683
+ jointRef.current = undefined;
684
+ }
539
685
  };
540
- }, [body1, body2]);
686
+ }, []);
687
+ const api = useMemo(() => createJointApi(getJointRef), []);
688
+ return api;
541
689
  };
542
690
  /**
543
691
  *
@@ -548,9 +696,9 @@ const useImpulseJoint = (body1, body2, params) => {
548
696
 
549
697
  const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor, body2LocalFrame]) => {
550
698
  const {
551
- RAPIER
699
+ rapier
552
700
  } = useRapier();
553
- return useImpulseJoint(body1, body2, RAPIER.JointData.fixed(vectorArrayToObject(body1Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToObject(body1LocalFrame)), {}, {
701
+ return useImpulseJoint(body1, body2, rapier.JointData.fixed(vectorArrayToObject(body1Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToObject(body1LocalFrame)), {}, {
554
702
  w: 1
555
703
  }), vectorArrayToObject(body2Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToObject(body2LocalFrame)), {}, {
556
704
  w: 1
@@ -565,9 +713,9 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
565
713
 
566
714
  const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
567
715
  const {
568
- RAPIER
716
+ rapier
569
717
  } = useRapier();
570
- return useImpulseJoint(body1, body2, RAPIER.JointData.spherical(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor)));
718
+ return useImpulseJoint(body1, body2, rapier.JointData.spherical(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor)));
571
719
  };
572
720
  /**
573
721
  * The revolute joint prevents any relative movement between two rigid-bodies, except for relative
@@ -577,9 +725,9 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
577
725
 
578
726
  const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
579
727
  const {
580
- RAPIER
728
+ rapier
581
729
  } = useRapier();
582
- return useImpulseJoint(body1, body2, RAPIER.JointData.revolute(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
730
+ return useImpulseJoint(body1, body2, rapier.JointData.revolute(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
583
731
  };
584
732
  /**
585
733
  * The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
@@ -589,9 +737,9 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
589
737
 
590
738
  const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
591
739
  const {
592
- RAPIER
740
+ rapier
593
741
  } = useRapier();
594
- return useImpulseJoint(body1, body2, RAPIER.JointData.prismatic(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
742
+ return useImpulseJoint(body1, body2, rapier.JointData.prismatic(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
595
743
  };
596
744
 
597
745
  function _extends() {
@@ -646,7 +794,8 @@ function _objectWithoutProperties(source, excluded) {
646
794
  return target;
647
795
  }
648
796
 
649
- const _excluded = ["children"];
797
+ const _excluded = ["children"],
798
+ _excluded2 = ["children"];
650
799
  const RigidBodyContext = /*#__PURE__*/createContext(undefined);
651
800
 
652
801
  const useParentRigidBody = () => useContext(RigidBodyContext); // RigidBody
@@ -658,28 +807,36 @@ const RigidBody = /*#__PURE__*/forwardRef((_ref, ref) => {
658
807
  } = _ref,
659
808
  props = _objectWithoutProperties(_ref, _excluded);
660
809
 
661
- const [group, rigidBody] = useRigidBody(props);
810
+ const [object, rigidBody] = useRigidBody(props);
662
811
  useImperativeHandle(ref, () => rigidBody);
663
812
  return /*#__PURE__*/React.createElement(RigidBodyContext.Provider, {
664
- value: [group, rigidBody]
665
- }, /*#__PURE__*/React.createElement("group", {
666
- ref: group
813
+ value: [object, rigidBody]
814
+ }, /*#__PURE__*/React.createElement("object3D", {
815
+ ref: object
667
816
  }, children));
668
817
  }); // Colliders
669
818
 
670
- const AnyCollider = props => {
819
+ const AnyCollider = _ref2 => {
820
+ let {
821
+ children
822
+ } = _ref2,
823
+ props = _objectWithoutProperties(_ref2, _excluded2);
824
+
671
825
  const {
672
826
  world
673
827
  } = useRapier();
674
- const [object, rigidBody] = useParentRigidBody();
828
+ const [, rigidBody] = useParentRigidBody();
829
+ const ref = useRef(null);
675
830
  useEffect(() => {
676
- const scale = object.current.getWorldScale(new Vector3());
677
- const collider = createColliderFromOptions(props, world, rigidBody, scale);
831
+ const scale = ref.current.getWorldScale(new Vector3());
832
+ const collider = createColliderFromOptions(props, world, rigidBody.handle, scale);
678
833
  return () => {
679
- world.removeCollider(collider, false);
834
+ world.removeCollider(collider);
680
835
  };
681
836
  }, []);
682
- return null;
837
+ return /*#__PURE__*/React.createElement("object3D", {
838
+ ref: ref
839
+ }, children);
683
840
  };
684
841
 
685
842
  const CuboidCollider = props => {
@@ -828,7 +985,7 @@ const Debug = () => {
828
985
 
829
986
  useFrame(() => {
830
987
  const newColliders = [];
831
- world.colliders.forEachCollider(collider => {
988
+ world.forEachCollider(collider => {
832
989
  newColliders.push(collider.handle);
833
990
  });
834
991
  setColliders(newColliders);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/rapier",
3
- "version": "0.1.0",
3
+ "version": "0.2.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",