@react-three/rapier 0.4.3 → 0.5.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.
@@ -38,6 +38,11 @@ const vectorArrayToObject = arr => {
38
38
  z
39
39
  };
40
40
  };
41
+ const quaternion = new three.Quaternion();
42
+ const euler = new three.Euler();
43
+ const vector3ToQuaternion = v => {
44
+ return quaternion.setFromEuler(euler.setFromVector3(v));
45
+ };
41
46
  const rigidBodyTypeMap = {
42
47
  fixed: 1,
43
48
  dynamic: 0,
@@ -63,11 +68,13 @@ const scaleColliderArgs = (shape, args, scale) => {
63
68
  const scaleArray = [scale.x, scale.y, scale.z];
64
69
  return newArgs.map((arg, index) => scaleArray[index] * arg);
65
70
  };
66
- const createColliderFromOptions = (options, world, rigidBody, scale = {
67
- x: 1,
68
- y: 1,
69
- z: 1
70
- }, hasCollisionEvents = false) => {
71
+ const createColliderFromOptions = ({
72
+ options,
73
+ world,
74
+ rigidBody,
75
+ scale,
76
+ hasCollisionEvents
77
+ }) => {
71
78
  var _options$shape, _options$args, _options$restitution, _options$restitutionC, _options$friction, _options$frictionComb;
72
79
 
73
80
  const mass = (options === null || options === void 0 ? void 0 : options.mass) || 1;
@@ -76,15 +83,16 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
76
83
  const [cmx, cmy, cmz] = (options === null || options === void 0 ? void 0 : options.centerOfMass) || [0, 0, 0];
77
84
  const [pix, piy, piz] = (options === null || options === void 0 ? void 0 : options.principalAngularInertia) || [mass * 0.2, mass * 0.2, mass * 0.2];
78
85
  const [x, y, z] = (options === null || options === void 0 ? void 0 : options.position) || [0, 0, 0];
79
- const [rx, ry, rz] = (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0]; // @ts-ignore
86
+ const [rx, ry, rz] = (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
87
+ const qRotation = vector3ToQuaternion(new three.Vector3(rx, ry, rz)); // @ts-ignore
80
88
 
81
89
  const scaledArgs = scaleColliderArgs(options.shape, colliderArgs, scale);
82
90
  let colliderDesc = rapier3dCompat.ColliderDesc[colliderShape]( // @ts-ignore
83
91
  ...scaledArgs).setTranslation(x * scale.x, y * scale.y, z * scale.z).setRotation({
84
- x: rx,
85
- y: ry,
86
- z: rz,
87
- w: 1
92
+ x: qRotation.x,
93
+ y: qRotation.y,
94
+ z: qRotation.z,
95
+ w: qRotation.w
88
96
  }).setRestitution((_options$restitution = options === null || options === void 0 ? void 0 : options.restitution) !== null && _options$restitution !== void 0 ? _options$restitution : 0).setRestitutionCombineRule((_options$restitutionC = options === null || options === void 0 ? void 0 : options.restitutionCombineRule) !== null && _options$restitutionC !== void 0 ? _options$restitutionC : rapier3dCompat.CoefficientCombineRule.Average).setFriction((_options$friction = options === null || options === void 0 ? void 0 : options.friction) !== null && _options$friction !== void 0 ? _options$friction : 0.7).setFrictionCombineRule((_options$frictionComb = options === null || options === void 0 ? void 0 : options.frictionCombineRule) !== null && _options$frictionComb !== void 0 ? _options$frictionComb : rapier3dCompat.CoefficientCombineRule.Average);
89
97
 
90
98
  if (hasCollisionEvents) {
@@ -92,6 +100,8 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
92
100
  } // If any of the mass properties are specified, add mass properties
93
101
 
94
102
 
103
+ const qMassRot = vector3ToQuaternion(new three.Vector3(0, 0, 0));
104
+
95
105
  if (options !== null && options !== void 0 && options.mass || options !== null && options !== void 0 && options.centerOfMass || options !== null && options !== void 0 && options.principalAngularInertia) {
96
106
  colliderDesc.setDensity(0);
97
107
  colliderDesc.setMassProperties(mass, {
@@ -103,23 +113,33 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
103
113
  y: piy,
104
114
  z: piz
105
115
  }, {
106
- x: 0,
107
- y: 0,
108
- z: 0,
109
- w: 1
116
+ x: qMassRot.x,
117
+ y: qMassRot.y,
118
+ z: qMassRot.z,
119
+ w: qMassRot.w
110
120
  });
111
121
  }
112
122
 
113
123
  const collider = world.createCollider(colliderDesc, rigidBody);
114
124
  return collider;
115
125
  };
116
- const createCollidersFromChildren = (object, rigidBody, options, world) => {
126
+
127
+ const isChildOfMeshCollider = child => {
128
+ let flag = false;
129
+ child.traverseAncestors(a => {
130
+ if (a.userData.r3RapierType === "MeshCollider") flag = true;
131
+ });
132
+ return flag;
133
+ };
134
+
135
+ const createCollidersFromChildren = (object, rigidBody, options, world, ignoreMeshColliders = true) => {
117
136
  const hasCollisionEvents = !!(options.onCollisionEnter || options.onCollisionExit);
118
137
  const colliders = [];
119
138
  let desc;
120
139
  let offset = new three.Vector3();
121
140
  object.traverse(child => {
122
141
  if ("isMesh" in child) {
142
+ if (ignoreMeshColliders && isChildOfMeshCollider(child)) return;
123
143
  const {
124
144
  geometry
125
145
  } = child;
@@ -190,7 +210,8 @@ const createCollidersFromChildren = (object, rigidBody, options, world) => {
190
210
  if (hasCollisionEvents) desc.setActiveEvents(rapier3dCompat.ActiveEvents.COLLISION_EVENTS);
191
211
  if (Number.isFinite(options.friction)) desc.setFriction(options.friction);
192
212
  if (Number.isFinite(options.restitution)) desc.setRestitution(options.restitution);
193
- const collider = world.createCollider(desc, rigidBody);
213
+ const actualRigidBody = world.getRigidBody(rigidBody === null || rigidBody === void 0 ? void 0 : rigidBody.handle);
214
+ const collider = world.createCollider(desc, actualRigidBody);
194
215
  colliders.push(collider);
195
216
  }
196
217
  });
@@ -208,47 +229,6 @@ const scaleVertices = (vertices, scale) => {
208
229
  return scaledVerts;
209
230
  };
210
231
 
211
- function _defineProperty(obj, key, value) {
212
- if (key in obj) {
213
- Object.defineProperty(obj, key, {
214
- value: value,
215
- enumerable: true,
216
- configurable: true,
217
- writable: true
218
- });
219
- } else {
220
- obj[key] = value;
221
- }
222
-
223
- return obj;
224
- }
225
-
226
- function ownKeys(object, enumerableOnly) {
227
- var keys = Object.keys(object);
228
-
229
- if (Object.getOwnPropertySymbols) {
230
- var symbols = Object.getOwnPropertySymbols(object);
231
- enumerableOnly && (symbols = symbols.filter(function (sym) {
232
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
233
- })), keys.push.apply(keys, symbols);
234
- }
235
-
236
- return keys;
237
- }
238
-
239
- function _objectSpread2(target) {
240
- for (var i = 1; i < arguments.length; i++) {
241
- var source = null != arguments[i] ? arguments[i] : {};
242
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
243
- _defineProperty(target, key, source[key]);
244
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
245
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
246
- });
247
- }
248
-
249
- return target;
250
- }
251
-
252
232
  const createRigidBodyApi = ref => {
253
233
  return {
254
234
  raw: () => ref.current(),
@@ -293,9 +273,19 @@ const createRigidBodyApi = ref => {
293
273
  return new three.Quaternion(x, y, z, w);
294
274
  },
295
275
 
296
- setRotation: rotation => ref.current().setRotation(_objectSpread2(_objectSpread2({}, rotation), {}, {
297
- w: 1
298
- }), true),
276
+ setRotation: ({
277
+ x,
278
+ y,
279
+ z
280
+ }) => {
281
+ const q = vector3ToQuaternion(new three.Vector3(x, y, z));
282
+ ref.current().setRotation({
283
+ x: q.x,
284
+ y: q.y,
285
+ z: q.z,
286
+ w: q.w
287
+ }, true);
288
+ },
299
289
 
300
290
  linvel() {
301
291
  const {
@@ -318,12 +308,26 @@ const createRigidBodyApi = ref => {
318
308
  },
319
309
 
320
310
  setAngvel: velocity => ref.current().setAngvel(velocity, true),
321
- setNextKinematicRotation: rotation => ref.current().setNextKinematicRotation(_objectSpread2(_objectSpread2({}, rotation), {}, {
322
- w: 1
323
- })),
311
+ setNextKinematicRotation: ({
312
+ x,
313
+ y,
314
+ z
315
+ }) => {
316
+ const q = vector3ToQuaternion(new three.Vector3(x, y, z));
317
+ ref.current().setNextKinematicRotation({
318
+ x: q.x,
319
+ y: q.y,
320
+ z: q.z,
321
+ w: q.w
322
+ });
323
+ },
324
324
  setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
325
325
  resetForces: () => ref.current().resetForces(true),
326
- resetTorques: () => ref.current().resetTorques(true)
326
+ resetTorques: () => ref.current().resetTorques(true),
327
+ lockRotations: locked => ref.current().lockRotations(locked, true),
328
+ lockTranslations: locked => ref.current().lockTranslations(locked, true),
329
+ setEnabledRotations: (x, y, z) => ref.current().setEnabledRotations(x, y, z, true),
330
+ setEnabledTranslations: (x, y, z) => ref.current().setEnabledTranslations(x, y, z, true)
327
331
  };
328
332
  }; // TODO: Flesh this out
329
333
 
@@ -348,7 +352,16 @@ const createWorldApi = ref => {
348
352
  removeCollider: collider => ref.current().removeCollider(collider, true),
349
353
  createImpulseJoint: (params, rigidBodyA, rigidBodyB) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB, true),
350
354
  removeImpulseJoint: joint => ref.current().removeImpulseJoint(joint, true),
351
- forEachCollider: callback => ref.current().forEachCollider(callback)
355
+ forEachCollider: callback => ref.current().forEachCollider(callback),
356
+ setGravity: ({
357
+ x,
358
+ y,
359
+ z
360
+ }) => ref.current().gravity = {
361
+ x,
362
+ y,
363
+ z
364
+ }
352
365
  };
353
366
  }; // TODO: Broken currently, waiting for Rapier3D to fix
354
367
 
@@ -376,7 +389,8 @@ const importRapier = async () => {
376
389
  const Physics = ({
377
390
  colliders: _colliders = 'cuboid',
378
391
  gravity: _gravity = [0, -9.81, 0],
379
- children
392
+ children,
393
+ timeStep: _timeStep = 'vary'
380
394
  }) => {
381
395
  const rapier = useAsset.useAsset(importRapier);
382
396
  const worldRef = React.useRef();
@@ -401,7 +415,15 @@ const Physics = ({
401
415
  worldRef.current = undefined;
402
416
  }
403
417
  };
404
- }, []);
418
+ }, []); // Update gravity
419
+
420
+ React.useEffect(() => {
421
+ const world = worldRef.current;
422
+
423
+ if (world) {
424
+ world.gravity = vectorArrayToObject(_gravity);
425
+ }
426
+ }, [_gravity]);
405
427
  const time = React.useRef(performance.now());
406
428
  fiber.useFrame(context => {
407
429
  const world = worldRef.current;
@@ -410,7 +432,13 @@ const Physics = ({
410
432
 
411
433
  const now = performance.now();
412
434
  const delta = Math.min(100, now - time.current);
413
- world.timestep = delta / 1000;
435
+
436
+ if (_timeStep === 'vary') {
437
+ world.timestep = delta / 1000;
438
+ } else {
439
+ world.timestep = _timeStep;
440
+ }
441
+
414
442
  world.step(eventQueue); // Update meshes
415
443
 
416
444
  rigidBodyMeshes.forEach((mesh, handle) => {
@@ -523,6 +551,47 @@ const Physics = ({
523
551
  }, children);
524
552
  };
525
553
 
554
+ function _defineProperty(obj, key, value) {
555
+ if (key in obj) {
556
+ Object.defineProperty(obj, key, {
557
+ value: value,
558
+ enumerable: true,
559
+ configurable: true,
560
+ writable: true
561
+ });
562
+ } else {
563
+ obj[key] = value;
564
+ }
565
+
566
+ return obj;
567
+ }
568
+
569
+ function ownKeys(object, enumerableOnly) {
570
+ var keys = Object.keys(object);
571
+
572
+ if (Object.getOwnPropertySymbols) {
573
+ var symbols = Object.getOwnPropertySymbols(object);
574
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
575
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
576
+ })), keys.push.apply(keys, symbols);
577
+ }
578
+
579
+ return keys;
580
+ }
581
+
582
+ function _objectSpread2(target) {
583
+ for (var i = 1; i < arguments.length; i++) {
584
+ var source = null != arguments[i] ? arguments[i] : {};
585
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
586
+ _defineProperty(target, key, source[key]);
587
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
588
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
589
+ });
590
+ }
591
+
592
+ return target;
593
+ }
594
+
526
595
  const useRapier = () => {
527
596
  return React.useContext(RapierContext);
528
597
  };
@@ -539,7 +608,7 @@ const useRigidBody = (options = {}) => {
539
608
  const rigidBodyRef = React.useRef();
540
609
  const getRigidBodyRef = React.useRef(() => {
541
610
  if (!rigidBodyRef.current) {
542
- var _options$linearVeloci, _options$angularVeloc, _options$gravityScale, _options$canSleep, _options$ccd;
611
+ var _options$linearVeloci, _options$angularVeloc, _options$gravityScale, _options$canSleep, _options$ccd, _options$enabledRotat, _options$enabledTrans;
543
612
 
544
613
  const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
545
614
  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];
@@ -547,11 +616,15 @@ const useRigidBody = (options = {}) => {
547
616
  const gravityScale = (_options$gravityScale = options === null || options === void 0 ? void 0 : options.gravityScale) !== null && _options$gravityScale !== void 0 ? _options$gravityScale : 1;
548
617
  const canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
549
618
  const ccdEnabled = (_options$ccd = options === null || options === void 0 ? void 0 : options.ccd) !== null && _options$ccd !== void 0 ? _options$ccd : false;
619
+ const [erx, ery, erz] = (_options$enabledRotat = options === null || options === void 0 ? void 0 : options.enabledRotations) !== null && _options$enabledRotat !== void 0 ? _options$enabledRotat : [true, true, true];
620
+ const [etx, ety, etz] = (_options$enabledTrans = options === null || options === void 0 ? void 0 : options.enabledTranslations) !== null && _options$enabledTrans !== void 0 ? _options$enabledTrans : [true, true, true];
550
621
  const desc = new rapier.RigidBodyDesc(type).setLinvel(lvx, lvy, lvz).setAngvel({
551
622
  x: avx,
552
623
  y: avy,
553
624
  z: avz
554
- }).setGravityScale(gravityScale).setCanSleep(canSleep).setCcdEnabled(ccdEnabled);
625
+ }).setGravityScale(gravityScale).setCanSleep(canSleep).setCcdEnabled(ccdEnabled).enabledRotations(erx, ery, erz).enabledTranslations(etx, ety, etz);
626
+ if (options.lockRotations) desc.lockRotations();
627
+ if (options.lockTranslations) desc.lockTranslations();
555
628
  const rigidBody = world.createRigidBody(desc);
556
629
  rigidBodyRef.current = world.getRigidBody(rigidBody.handle);
557
630
  }
@@ -648,144 +721,6 @@ const useCollider = (body, options = {}) => {
648
721
  }, []);
649
722
  const api = React.useMemo(() => createColliderApi(getColliderRef), []);
650
723
  return [objectRef, api];
651
- };
652
- const useRigidBodyWithCollider = (rigidBodyOptions, colliderOptions) => {
653
- const {
654
- world
655
- } = useRapier();
656
- const [ref, rigidBody] = useRigidBody(_objectSpread2(_objectSpread2({}, rigidBodyOptions), {}, {
657
- colliders: false
658
- }));
659
- React.useEffect(() => {
660
- if (!colliderOptions) {
661
- return;
662
- }
663
-
664
- const scale = ref.current.getWorldScale(new three.Vector3());
665
- const collider = createColliderFromOptions(colliderOptions, world, world.getRigidBody(rigidBody.handle), scale);
666
- return () => {
667
- world.removeCollider(collider);
668
- };
669
- }, []);
670
- return [ref, rigidBody];
671
- };
672
- const useCuboid = (rigidBodyOptions = {}, colliderOptions = {}) => {
673
- var _colliderOptions$args;
674
-
675
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
676
- shape: "cuboid",
677
- args: (_colliderOptions$args = colliderOptions.args) !== null && _colliderOptions$args !== void 0 ? _colliderOptions$args : [0.5, 0.5, 0.5]
678
- }, colliderOptions));
679
- };
680
- const useBall = (rigidBodyOptions = {}, colliderOptions = {}) => {
681
- var _colliderOptions$args2;
682
-
683
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
684
- shape: "ball",
685
- args: (_colliderOptions$args2 = colliderOptions.args) !== null && _colliderOptions$args2 !== void 0 ? _colliderOptions$args2 : [0.5]
686
- }, colliderOptions));
687
- };
688
- const useCapsule = (rigidBodyOptions = {}, colliderOptions = {}) => {
689
- var _colliderOptions$args3;
690
-
691
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
692
- shape: "capsule",
693
- args: (_colliderOptions$args3 = colliderOptions.args) !== null && _colliderOptions$args3 !== void 0 ? _colliderOptions$args3 : [0.5, 0.5]
694
- }, colliderOptions));
695
- };
696
- const useHeightfield = (rigidBodyOptions = {}, colliderOptions = {}) => {
697
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
698
- shape: "heightfield"
699
- }, colliderOptions));
700
- };
701
- /**
702
- * Create a trimesh collider and rigid body.
703
- * Note that Trimeshes don't have mass unless provided.
704
- * See https://rapier.rs/docs/user_guides/javascript/rigid_bodies#mass-properties
705
- * for available properties.
706
- */
707
-
708
- const useTrimesh = (rigidBodyOptions = {}, colliderOptions = {}) => {
709
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
710
- shape: "trimesh"
711
- }, colliderOptions));
712
- };
713
-
714
- useTrimesh.fromMesh = (mesh, rigidBodyOptions = {}, colliderOptions = {}) => {
715
- var _mesh$geometry, _mesh$geometry$index;
716
-
717
- return useTrimesh(rigidBodyOptions, _objectSpread2({
718
- args: [mesh.geometry.attributes.position.array, ((_mesh$geometry = mesh.geometry) === null || _mesh$geometry === void 0 ? void 0 : (_mesh$geometry$index = _mesh$geometry.index) === null || _mesh$geometry$index === void 0 ? void 0 : _mesh$geometry$index.array) || []]
719
- }, colliderOptions));
720
- };
721
-
722
- const usePolyline = (rigidBodyOptions = {}, colliderOptions = {}) => {
723
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
724
- shape: "polyline"
725
- }, colliderOptions));
726
- };
727
- const useRoundCuboid = (rigidBodyOptions = {}, colliderOptions = {}) => {
728
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
729
- shape: "roundCuboid"
730
- }, colliderOptions));
731
- };
732
- const useCylinder = (rigidBodyOptions = {}, colliderOptions = {}) => {
733
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
734
- shape: "cylinder"
735
- }, colliderOptions));
736
- };
737
- const useRoundCylinder = (rigidBodyOptions = {}, colliderOptions = {}) => {
738
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
739
- shape: "roundCylinder"
740
- }, colliderOptions));
741
- };
742
- const useCone = (rigidBodyOptions = {}, colliderOptions = {}) => {
743
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
744
- shape: "cone"
745
- }, colliderOptions));
746
- };
747
- const useRoundCone = (rigidBodyOptions = {}, colliderOptions = {}) => {
748
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
749
- shape: "roundCone"
750
- }, colliderOptions));
751
- };
752
- const useConvexHull = (rigidBodyOptions = {}, colliderOptions = {}) => {
753
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
754
- shape: "convexHull"
755
- }, colliderOptions));
756
- };
757
-
758
- useConvexHull.fromMesh = (mesh, rigidBodyOptions = {}, colliderOptions = {}) => {
759
- var _mesh$geometry2, _mesh$geometry2$attri, _mesh$geometry2$attri2;
760
-
761
- return useConvexHull(rigidBodyOptions, _objectSpread2({
762
- args: [(mesh === null || mesh === void 0 ? void 0 : (_mesh$geometry2 = mesh.geometry) === null || _mesh$geometry2 === void 0 ? void 0 : (_mesh$geometry2$attri = _mesh$geometry2.attributes) === null || _mesh$geometry2$attri === void 0 ? void 0 : (_mesh$geometry2$attri2 = _mesh$geometry2$attri.position) === null || _mesh$geometry2$attri2 === void 0 ? void 0 : _mesh$geometry2$attri2.array) || []]
763
- }, colliderOptions));
764
- };
765
-
766
- const useRoundConvexHull = (rigidBodyOptions = {}, colliderOptions = {}) => {
767
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
768
- shape: "roundConvexHull"
769
- }, colliderOptions));
770
- };
771
- const useConvexMesh = (rigidBodyOptions = {}, colliderOptions = {}) => {
772
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
773
- shape: "convexMesh"
774
- }, colliderOptions));
775
- };
776
-
777
- useConvexMesh.fromMesh = (mesh, rigidBodyOptions = {}, colliderOptions = {}) => {
778
- var _mesh$geometry3, _mesh$geometry3$attri, _mesh$geometry3$attri2, _mesh$geometry4, _mesh$geometry4$index;
779
-
780
- return useConvexMesh(rigidBodyOptions, _objectSpread2({
781
- args: [mesh === null || mesh === void 0 ? void 0 : (_mesh$geometry3 = mesh.geometry) === null || _mesh$geometry3 === void 0 ? void 0 : (_mesh$geometry3$attri = _mesh$geometry3.attributes) === null || _mesh$geometry3$attri === void 0 ? void 0 : (_mesh$geometry3$attri2 = _mesh$geometry3$attri.position) === null || _mesh$geometry3$attri2 === void 0 ? void 0 : _mesh$geometry3$attri2.array, ((_mesh$geometry4 = mesh.geometry) === null || _mesh$geometry4 === void 0 ? void 0 : (_mesh$geometry4$index = _mesh$geometry4.index) === null || _mesh$geometry4$index === void 0 ? void 0 : _mesh$geometry4$index.array) || []]
782
- }, colliderOptions));
783
- };
784
-
785
- const useRoundConvexMesh = (rigidBodyOptions = {}, colliderOptions = {}) => {
786
- return useRigidBodyWithCollider(rigidBodyOptions, _objectSpread2({
787
- shape: "convexMesh"
788
- }, colliderOptions));
789
724
  }; // Joints
790
725
 
791
726
  const useImpulseJoint = (body1, body2, params) => {
@@ -798,12 +733,6 @@ const useImpulseJoint = (body1, body2, params) => {
798
733
  let rb1;
799
734
  let rb2;
800
735
 
801
- if ('handle' in body1 && 'handle' in body2) {
802
- rb1 = world.getRigidBody(body1.handle);
803
- rb2 = world.getRigidBody(body2.handle);
804
- jointRef.current = world.createImpulseJoint(params, rb1, rb2);
805
- }
806
-
807
736
  if ('current' in body1 && body1.current && 'current' in body2 && body2.current) {
808
737
  rb1 = world.getRigidBody(body1.current.handle);
809
738
  rb2 = world.getRigidBody(body2.current.handle);
@@ -946,29 +875,80 @@ const RigidBody = /*#__PURE__*/React.forwardRef((_ref, ref) => {
946
875
  } = _ref,
947
876
  props = _objectWithoutProperties(_ref, _excluded);
948
877
 
949
- const [object, rigidBody] = useRigidBody(props);
950
- React.useImperativeHandle(ref, () => rigidBody);
878
+ const [object, api] = useRigidBody(props);
879
+ React.useImperativeHandle(ref, () => api);
951
880
  return /*#__PURE__*/React__default["default"].createElement(RigidBodyContext.Provider, {
952
- value: [object, rigidBody, !!(props.onCollisionEnter || props.onCollisionExit)]
881
+ value: {
882
+ ref: object,
883
+ api,
884
+ hasCollisionEvents: !!(props.onCollisionEnter || props.onCollisionExit),
885
+ options: props
886
+ }
953
887
  }, /*#__PURE__*/React__default["default"].createElement("object3D", {
954
888
  ref: object
955
889
  }, children));
956
- }); // Colliders
890
+ });
891
+ const MeshCollider = ({
892
+ children,
893
+ type
894
+ }) => {
895
+ const {
896
+ physicsOptions,
897
+ world
898
+ } = useRapier();
899
+ const object = React.useRef(null);
900
+ const {
901
+ api,
902
+ options
903
+ } = useRigidBodyContext();
904
+ React.useEffect(() => {
905
+ let autoColliders = [];
906
+
907
+ if (object.current) {
908
+ var _ref2;
909
+
910
+ const colliderSetting = (_ref2 = type !== null && type !== void 0 ? type : physicsOptions.colliders) !== null && _ref2 !== void 0 ? _ref2 : false;
911
+ autoColliders = colliderSetting !== false ? createCollidersFromChildren(object.current, api, _objectSpread2(_objectSpread2({}, options), {}, {
912
+ colliders: colliderSetting
913
+ }), world, false) : [];
914
+ }
957
915
 
958
- const AnyCollider = _ref2 => {
916
+ return () => {
917
+ autoColliders.forEach(collider => {
918
+ world.removeCollider(collider);
919
+ });
920
+ };
921
+ }, []);
922
+ return /*#__PURE__*/React__default["default"].createElement("object3D", {
923
+ ref: object,
924
+ userData: {
925
+ r3RapierType: "MeshCollider"
926
+ }
927
+ }, children);
928
+ }; // Colliders
929
+
930
+ const AnyCollider = _ref3 => {
959
931
  let {
960
932
  children
961
- } = _ref2,
962
- props = _objectWithoutProperties(_ref2, _excluded2);
933
+ } = _ref3,
934
+ props = _objectWithoutProperties(_ref3, _excluded2);
963
935
 
964
936
  const {
965
937
  world
966
938
  } = useRapier();
967
- const [, rigidBody, hasCollisionEvents] = useRigidBodyContext();
939
+ const rigidBodyContext = useRigidBodyContext();
968
940
  const ref = React.useRef(null);
969
941
  React.useEffect(() => {
942
+ var _rigidBodyContext$api;
943
+
970
944
  const scale = ref.current.getWorldScale(new three.Vector3());
971
- const collider = createColliderFromOptions(props, world, rigidBody.raw(), scale, hasCollisionEvents);
945
+ const collider = createColliderFromOptions({
946
+ options: props,
947
+ world,
948
+ rigidBody: rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : (_rigidBodyContext$api = rigidBodyContext.api) === null || _rigidBodyContext$api === void 0 ? void 0 : _rigidBodyContext$api.raw(),
949
+ scale,
950
+ hasCollisionEvents: rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.hasCollisionEvents
951
+ });
972
952
  return () => {
973
953
  world.removeCollider(collider);
974
954
  };
@@ -1159,31 +1139,16 @@ exports.CuboidCollider = CuboidCollider;
1159
1139
  exports.CylinderCollider = CylinderCollider;
1160
1140
  exports.Debug = Debug;
1161
1141
  exports.HeightfieldCollider = HeightfieldCollider;
1142
+ exports.MeshCollider = MeshCollider;
1162
1143
  exports.Physics = Physics;
1163
1144
  exports.RigidBody = RigidBody;
1164
1145
  exports.RoundCuboidCollider = RoundCuboidCollider;
1165
1146
  exports.TrimeshCollider = TrimeshCollider;
1166
- exports.useBall = useBall;
1167
- exports.useCapsule = useCapsule;
1168
1147
  exports.useCollider = useCollider;
1169
- exports.useCone = useCone;
1170
- exports.useConvexHull = useConvexHull;
1171
- exports.useConvexMesh = useConvexMesh;
1172
- exports.useCuboid = useCuboid;
1173
- exports.useCylinder = useCylinder;
1174
1148
  exports.useFixedJoint = useFixedJoint;
1175
- exports.useHeightfield = useHeightfield;
1176
1149
  exports.useImpulseJoint = useImpulseJoint;
1177
- exports.usePolyline = usePolyline;
1178
1150
  exports.usePrismaticJoint = usePrismaticJoint;
1179
1151
  exports.useRapier = useRapier;
1180
1152
  exports.useRevoluteJoint = useRevoluteJoint;
1181
1153
  exports.useRigidBody = useRigidBody;
1182
- exports.useRigidBodyWithCollider = useRigidBodyWithCollider;
1183
- exports.useRoundCone = useRoundCone;
1184
- exports.useRoundConvexHull = useRoundConvexHull;
1185
- exports.useRoundConvexMesh = useRoundConvexMesh;
1186
- exports.useRoundCuboid = useRoundCuboid;
1187
- exports.useRoundCylinder = useRoundCylinder;
1188
1154
  exports.useSphericalJoint = useSphericalJoint;
1189
- exports.useTrimesh = useTrimesh;