@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.
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var useAsset = require('use-asset');
7
7
  var fiber = require('@react-three/fiber');
8
- var rapier3dCompat = require('@dimforge/rapier3d-compat');
9
8
  var three = require('three');
9
+ var rapier3dCompat = require('@dimforge/rapier3d-compat');
10
10
 
11
11
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
12
12
 
@@ -63,7 +63,7 @@ const scaleColliderArgs = (shape, args, scale) => {
63
63
  const scaleArray = [scale.x, scale.y, scale.z];
64
64
  return newArgs.map((arg, index) => scaleArray[index] * arg);
65
65
  };
66
- const createColliderFromOptions = (options, world, body, scale = {
66
+ const createColliderFromOptions = (options, world, rigidBodyHandle, scale = {
67
67
  x: 1,
68
68
  y: 1,
69
69
  z: 1
@@ -105,12 +105,13 @@ const createColliderFromOptions = (options, world, body, scale = {
105
105
  });
106
106
  }
107
107
 
108
- const collider = world.createCollider(colliderDesc, body.handle);
108
+ const collider = world.createCollider(colliderDesc, rigidBodyHandle);
109
109
  return collider;
110
110
  };
111
111
  const createCollidersFromChildren = (object, rigidBody, type, world) => {
112
112
  const colliders = [];
113
113
  let desc;
114
+ let offset = new three.Vector3();
114
115
  object.traverse(child => {
115
116
  if ("isMesh" in child) {
116
117
  const {
@@ -137,6 +138,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
137
138
  boundingBox
138
139
  } = geometry;
139
140
  const size = boundingBox.getSize(new three.Vector3());
141
+ boundingBox.getCenter(offset);
140
142
  desc = rapier3dCompat.ColliderDesc.cuboid(size.x / 2 * scale.x, size.y / 2 * scale.y, size.z / 2 * scale.z);
141
143
  }
142
144
  break;
@@ -148,6 +150,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
148
150
  boundingSphere
149
151
  } = geometry;
150
152
  const radius = boundingSphere.radius * scale.x;
153
+ offset.copy(boundingSphere.center);
151
154
  desc = rapier3dCompat.ColliderDesc.ball(radius);
152
155
  }
153
156
  break;
@@ -172,7 +175,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
172
175
 
173
176
 
174
177
  const parentWorldScale = child.parent.getWorldScale(new three.Vector3());
175
- desc.setTranslation(x * parentWorldScale.x, y * parentWorldScale.y, z * parentWorldScale.z).setRotation({
178
+ desc.setTranslation((x + offset.x) * parentWorldScale.x, (y + offset.y) * parentWorldScale.y, (z + offset.z) * parentWorldScale.z).setRotation({
176
179
  x: rx,
177
180
  y: ry,
178
181
  z: rz,
@@ -196,6 +199,99 @@ const scaleVertices = (vertices, scale) => {
196
199
  return scaledVerts;
197
200
  };
198
201
 
202
+ // TODO: Flesh this out
203
+ const createRigidBodyApi = ref => {
204
+ return {
205
+ raw: () => ref.current(),
206
+
207
+ get handle() {
208
+ return ref.current().handle;
209
+ },
210
+
211
+ applyImpulse({
212
+ x,
213
+ y,
214
+ z
215
+ }) {
216
+ ref.current().applyImpulse({
217
+ x,
218
+ y,
219
+ z
220
+ }, true);
221
+ },
222
+
223
+ applyTorqueImpulse({
224
+ x,
225
+ y,
226
+ z
227
+ }) {
228
+ ref.current().applyTorqueImpulse({
229
+ x,
230
+ y,
231
+ z
232
+ }, true);
233
+ },
234
+
235
+ translation() {
236
+ const {
237
+ x,
238
+ y,
239
+ z
240
+ } = ref.current().translation();
241
+ return new three.Vector3(x, y, z);
242
+ },
243
+
244
+ rotation() {
245
+ const {
246
+ x,
247
+ y,
248
+ z,
249
+ w
250
+ } = ref.current().rotation();
251
+ return new three.Quaternion(x, y, z, w);
252
+ }
253
+
254
+ };
255
+ }; // TODO: Flesh this out
256
+
257
+ const createColliderApi = ref => {
258
+ return {
259
+ raw: () => ref.current(),
260
+
261
+ get handle() {
262
+ return ref.current().handle;
263
+ }
264
+
265
+ };
266
+ };
267
+ const createWorldApi = ref => {
268
+ return {
269
+ raw: () => ref.current(),
270
+ getCollider: handle => ref.current().getCollider(handle),
271
+ getRigidBody: handle => ref.current().getRigidBody(handle),
272
+ createRigidBody: desc => ref.current().createRigidBody(desc),
273
+ createCollider: (desc, rigidBodyHandle) => ref.current().createCollider(desc, rigidBodyHandle),
274
+ removeRigidBody: rigidBody => ref.current().removeRigidBody(rigidBody),
275
+ removeCollider: collider => ref.current().removeCollider(collider, true),
276
+ createImpulseJoint: (params, rigidBodyA, rigidBodyB) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB),
277
+ removeImpulseJoint: joint => ref.current().removeImpulseJoint(joint, true),
278
+ forEachCollider: callback => ref.current().forEachCollider(callback)
279
+ };
280
+ }; // TODO: Broken currently, waiting for Rapier3D to fix
281
+
282
+ const createJointApi = ref => {
283
+ return {
284
+ raw: () => ref.current(),
285
+
286
+ get handle() {
287
+ return ref.current().handle;
288
+ },
289
+
290
+ configureMotorPosition: (targetPos, stiffness, damping) => ref.current().configureMotorPosition(targetPos, stiffness, damping),
291
+ configureMotorVelocity: (targetVel, damping) => ref.current().configureMotorVelocity(targetVel, damping)
292
+ };
293
+ };
294
+
199
295
  const RapierContext = /*#__PURE__*/React.createContext(undefined);
200
296
 
201
297
  const importRapier = async () => {
@@ -210,30 +306,81 @@ const Physics = ({
210
306
  children
211
307
  }) => {
212
308
  const rapier = useAsset.useAsset(importRapier);
213
- const stepFuncs = React.useRef([]);
214
- const world = React.useMemo(() => {
215
- if (!rapier.World) return null;
216
- let world = new rapier.World(vectorArrayToObject(_gravity));
217
- return world;
218
- }, [rapier]);
309
+ const worldRef = React.useRef();
310
+ const getWorldRef = React.useRef(() => {
311
+ if (!worldRef.current) {
312
+ const world = new rapier.World(vectorArrayToObject(_gravity));
313
+ worldRef.current = world;
314
+ }
315
+
316
+ return worldRef.current;
317
+ });
318
+ const [colliderMeshes] = React.useState(() => new Map());
319
+ const [rigidBodyMeshes] = React.useState(() => new Map()); // Init world
320
+
321
+ React.useLayoutEffect(() => {
322
+ const world = getWorldRef.current();
323
+ return () => {
324
+ if (world) {
325
+ world.free();
326
+ worldRef.current = undefined;
327
+ }
328
+ };
329
+ }, []);
219
330
  const time = React.useRef(performance.now());
220
331
  fiber.useFrame(context => {
221
- // Set timestep to current delta, to allow for variable frame rates
332
+ const world = worldRef.current;
333
+ if (!world) return; // Set timestep to current delta, to allow for variable frame rates
222
334
  // We cap the delta at 100, so that the physics simulation doesn't get wild
335
+
223
336
  const now = performance.now();
224
337
  const delta = Math.min(100, now - time.current);
225
338
  world.timestep = delta / 1000;
226
- world.step(); // Run all step funcs
339
+ world.step(); // Update meshes
227
340
 
228
- stepFuncs.current.forEach(func => func());
341
+ rigidBodyMeshes.forEach((mesh, handle) => {
342
+ const rigidBody = world.getRigidBody(handle);
343
+
344
+ if (!rigidBody || rigidBody.isSleeping() || rigidBody.isFixed() || !mesh.parent) {
345
+ return;
346
+ }
347
+
348
+ const {
349
+ x,
350
+ y,
351
+ z
352
+ } = rigidBody.translation();
353
+ const {
354
+ x: rx,
355
+ y: ry,
356
+ z: rz,
357
+ w: rw
358
+ } = rigidBody.rotation();
359
+ const scale = mesh.getWorldScale(new three.Vector3()); // haha matrixes I have no idea what I'm doing :)
360
+
361
+ const o = new three.Object3D();
362
+ o.position.set(x, y, z);
363
+ o.rotation.setFromQuaternion(new three.Quaternion(rx, ry, rz, rw));
364
+ o.scale.set(scale.x, scale.y, scale.z);
365
+ o.updateMatrix();
366
+ o.applyMatrix4(mesh.parent.matrixWorld.clone().invert());
367
+ o.updateMatrix();
368
+ mesh.position.setFromMatrixPosition(o.matrix);
369
+ mesh.rotation.setFromRotationMatrix(o.matrix);
370
+ });
229
371
  time.current = now;
230
372
  });
373
+ const api = React.useMemo(() => createWorldApi(getWorldRef), []);
231
374
  const context = React.useMemo(() => ({
232
- RAPIER: rapier,
233
- world,
234
- colliders: _colliders,
235
- stepFuncs: stepFuncs.current
236
- }), [rapier]);
375
+ rapier,
376
+ world: api,
377
+ physicsOptions: {
378
+ colliders: _colliders,
379
+ gravity: _gravity
380
+ },
381
+ colliderMeshes,
382
+ rigidBodyMeshes
383
+ }), []);
237
384
  return /*#__PURE__*/React__default["default"].createElement(RapierContext.Provider, {
238
385
  value: context
239
386
  }, children);
@@ -282,64 +429,44 @@ function _objectSpread2(target) {
282
429
 
283
430
  const useRapier = () => {
284
431
  return React.useContext(RapierContext);
285
- }; // Private hook for updating the simulations on objects
286
-
287
- const useRapierStep = callback => {
288
- const {
289
- stepFuncs
290
- } = useRapier();
291
- React.useEffect(() => {
292
- stepFuncs.push(callback);
293
- return () => {
294
- const index = stepFuncs.indexOf(callback);
295
- stepFuncs.splice(index, 1);
296
- };
297
- }, [callback]);
298
432
  };
299
- const useCollider = (body, options = {}) => {
433
+ const useRigidBody = (options = {}) => {
300
434
  const {
301
- RAPIER,
302
- world
303
- } = useRapier();
304
- const collider = React.useMemo(() => {
305
- return createColliderFromOptions(options, world, body);
306
- }, []);
307
- React.useEffect(() => {
308
- return () => {
309
- world.removeCollider(collider, false);
310
- };
311
- }, []);
312
- return [collider];
313
- };
314
- const useRigidBody = options => {
315
- const {
316
- RAPIER,
317
- world
435
+ rapier,
436
+ world,
437
+ rigidBodyMeshes,
438
+ physicsOptions
318
439
  } = useRapier();
319
440
  const ref = React.useRef(); // Create rigidbody
320
441
 
321
- const rigidBody = React.useMemo(() => {
322
- var _options$linearVeloci, _options$angularVeloc, _options$gravityScale, _options$canSleep, _options$ccd;
323
-
324
- 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];
325
- 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];
326
- const gravityScale = (_options$gravityScale = options === null || options === void 0 ? void 0 : options.gravityScale) !== null && _options$gravityScale !== void 0 ? _options$gravityScale : 1;
327
- const canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
328
- const ccdEnabled = (_options$ccd = options === null || options === void 0 ? void 0 : options.ccd) !== null && _options$ccd !== void 0 ? _options$ccd : false;
329
- const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
330
- (options === null || options === void 0 ? void 0 : options.position) || [0, 0, 0];
331
- (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
332
- const rigidBodyDesc = new RAPIER.RigidBodyDesc(type).setLinvel(lvx, lvy, lvz).setAngvel({
333
- x: avx,
334
- y: avy,
335
- z: avz
336
- }).setGravityScale(gravityScale).setCanSleep(canSleep).setCcdEnabled(ccdEnabled).setTranslation(0, 0, 0);
337
- const body = world.createRigidBody(rigidBodyDesc);
338
- return body;
339
- }, []); // Setup
442
+ const rigidBodyRef = React.useRef();
443
+ const getRigidBodyRef = React.useRef(() => {
444
+ if (!rigidBodyRef.current) {
445
+ var _options$linearVeloci, _options$angularVeloc, _options$gravityScale, _options$canSleep, _options$ccd;
446
+
447
+ const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
448
+ 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];
449
+ 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];
450
+ const gravityScale = (_options$gravityScale = options === null || options === void 0 ? void 0 : options.gravityScale) !== null && _options$gravityScale !== void 0 ? _options$gravityScale : 1;
451
+ const canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
452
+ const ccdEnabled = (_options$ccd = options === null || options === void 0 ? void 0 : options.ccd) !== null && _options$ccd !== void 0 ? _options$ccd : false;
453
+ const desc = new rapier.RigidBodyDesc(type).setLinvel(lvx, lvy, lvz).setAngvel({
454
+ x: avx,
455
+ y: avy,
456
+ z: avz
457
+ }).setGravityScale(gravityScale).setCanSleep(canSleep).setCcdEnabled(ccdEnabled);
458
+ const rigidBody = world.createRigidBody(desc);
459
+ rigidBodyRef.current = rigidBody;
460
+ }
461
+
462
+ return rigidBodyRef.current;
463
+ }); // Setup
340
464
 
341
465
  React.useEffect(() => {
342
- var _ref$current$parent, _options$colliders;
466
+ var _ref$current$parent, _ref, _options$colliders;
467
+
468
+ const rigidBody = getRigidBodyRef.current();
469
+ rigidBodyRef.current = rigidBody;
343
470
 
344
471
  if (!ref.current) {
345
472
  ref.current = new three.Object3D();
@@ -372,43 +499,42 @@ const useRigidBody = options => {
372
499
  }, false);
373
500
  rigidBody.resetForces(false);
374
501
  rigidBody.resetTorques(false);
375
- const colliderSetting = (_options$colliders = options === null || options === void 0 ? void 0 : options.colliders) !== null && _options$colliders !== void 0 ? _options$colliders : false;
502
+ 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;
376
503
  const autoColliders = colliderSetting !== false ? createCollidersFromChildren(ref.current, rigidBody, colliderSetting, world) : [];
504
+ rigidBody.wakeUp();
505
+ rigidBodyMeshes.set(rigidBody.handle, ref.current);
377
506
  return () => {
507
+ autoColliders.forEach(collider => world.removeCollider(collider));
378
508
  world.removeRigidBody(rigidBody);
379
- autoColliders.forEach(collider => world.removeCollider(collider, false));
509
+ rigidBodyRef.current = undefined;
510
+ rigidBodyMeshes.delete(rigidBody.handle);
380
511
  };
381
512
  }, []);
382
- useRapierStep(() => {
383
- if (rigidBody && ref.current) {
384
- const {
385
- x,
386
- y,
387
- z
388
- } = rigidBody.translation();
389
- const {
390
- x: rx,
391
- y: ry,
392
- z: rz,
393
- w: rw
394
- } = rigidBody.rotation();
395
- const scale = ref.current.getWorldScale(new three.Vector3());
396
-
397
- if (ref.current.parent) {
398
- // haha matrixes I have no idea what I'm doing :)
399
- const o = new three.Object3D();
400
- o.position.set(x, y, z);
401
- o.rotation.setFromQuaternion(new three.Quaternion(rx, ry, rz, rw));
402
- o.scale.set(scale.x, scale.y, scale.z);
403
- o.updateMatrix();
404
- o.applyMatrix4(ref.current.parent.matrixWorld.clone().invert());
405
- o.updateMatrix();
406
- ref.current.position.setFromMatrixPosition(o.matrix);
407
- ref.current.rotation.setFromRotationMatrix(o.matrix);
408
- }
513
+ const api = React.useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
514
+ return [ref, api];
515
+ };
516
+ const useCollider = (body, options = {}) => {
517
+ const {
518
+ world
519
+ } = useRapier();
520
+ const colliderRef = React.useRef();
521
+ const objectRef = React.useRef();
522
+ const getColliderRef = React.useRef(() => {
523
+ if (!colliderRef.current) {
524
+ colliderRef.current = createColliderFromOptions(options, world, body.handle);
409
525
  }
526
+
527
+ return colliderRef.current;
410
528
  });
411
- return [ref, rigidBody];
529
+ React.useEffect(() => {
530
+ const collider = getColliderRef.current();
531
+ return () => {
532
+ if (collider) world.removeCollider(collider);
533
+ colliderRef.current = undefined;
534
+ };
535
+ }, []);
536
+ const api = React.useMemo(() => createColliderApi(getColliderRef), []);
537
+ return [objectRef, api];
412
538
  };
413
539
  const useRigidBodyWithCollider = (rigidBodyOptions, colliderOptions) => {
414
540
  const {
@@ -421,9 +547,9 @@ const useRigidBodyWithCollider = (rigidBodyOptions, colliderOptions) => {
421
547
  }
422
548
 
423
549
  const scale = ref.current.getWorldScale(new three.Vector3());
424
- const collider = createColliderFromOptions(colliderOptions, world, rigidBody, scale);
550
+ const collider = createColliderFromOptions(colliderOptions, world, rigidBody.handle, scale);
425
551
  return () => {
426
- world.removeCollider(collider, false);
552
+ world.removeCollider(collider);
427
553
  };
428
554
  }, []);
429
555
  return [ref, rigidBody];
@@ -549,20 +675,42 @@ const useRoundConvexMesh = (rigidBodyOptions = {}, colliderOptions = {}) => {
549
675
 
550
676
  const useImpulseJoint = (body1, body2, params) => {
551
677
  const {
552
- world,
553
- RAPIER
678
+ world
554
679
  } = useRapier();
555
- React.useLayoutEffect(() => {
556
- let joint;
680
+ const jointRef = React.useRef();
681
+ const getJointRef = React.useRef(() => {
682
+ if (!jointRef.current) {
683
+ let rb1;
684
+ let rb2;
685
+
686
+ if ('handle' in body1 && 'handle' in body2) {
687
+ rb1 = world.getRigidBody(body1.handle);
688
+ rb2 = world.getRigidBody(body2.handle);
689
+ jointRef.current = world.createImpulseJoint(params, rb1, rb2);
690
+ }
557
691
 
558
- if (body1 && body2 && params) {
559
- joint = world.createImpulseJoint(params, body1.current, body2.current);
692
+ if ('current' in body1 && body1.current && 'current' in body2 && body2.current) {
693
+ rb1 = world.getRigidBody(body1.current.handle);
694
+ rb2 = world.getRigidBody(body2.current.handle);
695
+ const newJoint = world.createImpulseJoint(params, rb1, rb2);
696
+ jointRef.current = newJoint;
697
+ }
560
698
  }
561
699
 
700
+ return jointRef.current;
701
+ });
702
+ React.useEffect(() => {
703
+ const joint = getJointRef.current();
562
704
  return () => {
563
- if (joint) world.removeImpulseJoint(joint, true);
705
+ if (joint) {
706
+ console.log('remove joint', joint);
707
+ world.removeImpulseJoint(joint);
708
+ jointRef.current = undefined;
709
+ }
564
710
  };
565
- }, [body1, body2]);
711
+ }, []);
712
+ const api = React.useMemo(() => createJointApi(getJointRef), []);
713
+ return api;
566
714
  };
567
715
  /**
568
716
  *
@@ -573,9 +721,9 @@ const useImpulseJoint = (body1, body2, params) => {
573
721
 
574
722
  const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor, body2LocalFrame]) => {
575
723
  const {
576
- RAPIER
724
+ rapier
577
725
  } = useRapier();
578
- return useImpulseJoint(body1, body2, RAPIER.JointData.fixed(vectorArrayToObject(body1Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToObject(body1LocalFrame)), {}, {
726
+ return useImpulseJoint(body1, body2, rapier.JointData.fixed(vectorArrayToObject(body1Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToObject(body1LocalFrame)), {}, {
579
727
  w: 1
580
728
  }), vectorArrayToObject(body2Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToObject(body2LocalFrame)), {}, {
581
729
  w: 1
@@ -590,9 +738,9 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
590
738
 
591
739
  const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
592
740
  const {
593
- RAPIER
741
+ rapier
594
742
  } = useRapier();
595
- return useImpulseJoint(body1, body2, RAPIER.JointData.spherical(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor)));
743
+ return useImpulseJoint(body1, body2, rapier.JointData.spherical(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor)));
596
744
  };
597
745
  /**
598
746
  * The revolute joint prevents any relative movement between two rigid-bodies, except for relative
@@ -602,9 +750,9 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
602
750
 
603
751
  const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
604
752
  const {
605
- RAPIER
753
+ rapier
606
754
  } = useRapier();
607
- return useImpulseJoint(body1, body2, RAPIER.JointData.revolute(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
755
+ return useImpulseJoint(body1, body2, rapier.JointData.revolute(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
608
756
  };
609
757
  /**
610
758
  * The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
@@ -614,9 +762,9 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
614
762
 
615
763
  const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
616
764
  const {
617
- RAPIER
765
+ rapier
618
766
  } = useRapier();
619
- return useImpulseJoint(body1, body2, RAPIER.JointData.prismatic(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
767
+ return useImpulseJoint(body1, body2, rapier.JointData.prismatic(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
620
768
  };
621
769
 
622
770
  function _extends() {
@@ -671,7 +819,8 @@ function _objectWithoutProperties(source, excluded) {
671
819
  return target;
672
820
  }
673
821
 
674
- const _excluded = ["children"];
822
+ const _excluded = ["children"],
823
+ _excluded2 = ["children"];
675
824
  const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
676
825
 
677
826
  const useParentRigidBody = () => React.useContext(RigidBodyContext); // RigidBody
@@ -683,28 +832,36 @@ const RigidBody = /*#__PURE__*/React.forwardRef((_ref, ref) => {
683
832
  } = _ref,
684
833
  props = _objectWithoutProperties(_ref, _excluded);
685
834
 
686
- const [group, rigidBody] = useRigidBody(props);
835
+ const [object, rigidBody] = useRigidBody(props);
687
836
  React.useImperativeHandle(ref, () => rigidBody);
688
837
  return /*#__PURE__*/React__default["default"].createElement(RigidBodyContext.Provider, {
689
- value: [group, rigidBody]
690
- }, /*#__PURE__*/React__default["default"].createElement("group", {
691
- ref: group
838
+ value: [object, rigidBody]
839
+ }, /*#__PURE__*/React__default["default"].createElement("object3D", {
840
+ ref: object
692
841
  }, children));
693
842
  }); // Colliders
694
843
 
695
- const AnyCollider = props => {
844
+ const AnyCollider = _ref2 => {
845
+ let {
846
+ children
847
+ } = _ref2,
848
+ props = _objectWithoutProperties(_ref2, _excluded2);
849
+
696
850
  const {
697
851
  world
698
852
  } = useRapier();
699
- const [object, rigidBody] = useParentRigidBody();
853
+ const [, rigidBody] = useParentRigidBody();
854
+ const ref = React.useRef(null);
700
855
  React.useEffect(() => {
701
- const scale = object.current.getWorldScale(new three.Vector3());
702
- const collider = createColliderFromOptions(props, world, rigidBody, scale);
856
+ const scale = ref.current.getWorldScale(new three.Vector3());
857
+ const collider = createColliderFromOptions(props, world, rigidBody.handle, scale);
703
858
  return () => {
704
- world.removeCollider(collider, false);
859
+ world.removeCollider(collider);
705
860
  };
706
861
  }, []);
707
- return null;
862
+ return /*#__PURE__*/React__default["default"].createElement("object3D", {
863
+ ref: ref
864
+ }, children);
708
865
  };
709
866
 
710
867
  const CuboidCollider = props => {
@@ -853,7 +1010,7 @@ const Debug = () => {
853
1010
 
854
1011
  fiber.useFrame(() => {
855
1012
  const newColliders = [];
856
- world.colliders.forEachCollider(collider => {
1013
+ world.forEachCollider(collider => {
857
1014
  newColliders.push(collider.handle);
858
1015
  });
859
1016
  setColliders(newColliders);