@react-three/rapier 1.3.1 → 1.5.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.
Files changed (26) hide show
  1. package/dist/declarations/src/components/AnyCollider.d.ts +2 -2
  2. package/dist/declarations/src/components/InstancedRigidBodies.d.ts +2 -2
  3. package/dist/declarations/src/components/MeshCollider.d.ts +2 -2
  4. package/dist/declarations/src/components/Physics.d.ts +17 -4
  5. package/dist/declarations/src/components/RigidBody.d.ts +1 -1
  6. package/dist/declarations/src/hooks/hooks.d.ts +3 -3
  7. package/dist/declarations/src/hooks/joints.d.ts +1 -1
  8. package/dist/declarations/src/index.d.ts +15 -15
  9. package/dist/declarations/src/types.d.ts +52 -10
  10. package/dist/declarations/src/utils/interaction-groups.d.ts +1 -1
  11. package/dist/react-three-rapier.cjs.d.ts +1 -0
  12. package/dist/react-three-rapier.cjs.dev.js +162 -275
  13. package/dist/react-three-rapier.cjs.prod.js +162 -275
  14. package/dist/react-three-rapier.esm.js +162 -275
  15. package/package.json +8 -13
  16. package/readme.md +0 -2
  17. package/dist/declarations/src/components/Debug.d.ts +0 -2
  18. package/dist/declarations/src/components/FrameStepper.d.ts +0 -9
  19. package/dist/declarations/src/hooks/use-forwarded-ref.d.ts +0 -2
  20. package/dist/declarations/src/hooks/use-imperative-instance.d.ts +0 -5
  21. package/dist/declarations/src/utils/shared-objects.d.ts +0 -9
  22. package/dist/declarations/src/utils/singleton-proxy.d.ts +0 -11
  23. package/dist/declarations/src/utils/utils-collider.d.ts +0 -81
  24. package/dist/declarations/src/utils/utils-physics.d.ts +0 -1
  25. package/dist/declarations/src/utils/utils-rigidbody.d.ts +0 -24
  26. package/dist/declarations/src/utils/utils.d.ts +0 -14
@@ -31,45 +31,51 @@ function _interopNamespace(e) {
31
31
 
32
32
  var React__default = /*#__PURE__*/_interopDefault(React);
33
33
 
34
- function _defineProperty(obj, key, value) {
35
- if (key in obj) {
36
- Object.defineProperty(obj, key, {
37
- value: value,
38
- enumerable: true,
39
- configurable: true,
40
- writable: true
41
- });
42
- } else {
43
- obj[key] = value;
34
+ function _toPrimitive(t, r) {
35
+ if ("object" != typeof t || !t) return t;
36
+ var e = t[Symbol.toPrimitive];
37
+ if (void 0 !== e) {
38
+ var i = e.call(t, r || "default");
39
+ if ("object" != typeof i) return i;
40
+ throw new TypeError("@@toPrimitive must return a primitive value.");
44
41
  }
42
+ return ("string" === r ? String : Number)(t);
43
+ }
45
44
 
46
- return obj;
45
+ function _toPropertyKey(t) {
46
+ var i = _toPrimitive(t, "string");
47
+ return "symbol" == typeof i ? i : i + "";
47
48
  }
48
49
 
49
- function ownKeys(object, enumerableOnly) {
50
- var keys = Object.keys(object);
50
+ function _defineProperty(e, r, t) {
51
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
52
+ value: t,
53
+ enumerable: !0,
54
+ configurable: !0,
55
+ writable: !0
56
+ }) : e[r] = t, e;
57
+ }
51
58
 
59
+ function ownKeys(e, r) {
60
+ var t = Object.keys(e);
52
61
  if (Object.getOwnPropertySymbols) {
53
- var symbols = Object.getOwnPropertySymbols(object);
54
- enumerableOnly && (symbols = symbols.filter(function (sym) {
55
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
56
- })), keys.push.apply(keys, symbols);
62
+ var o = Object.getOwnPropertySymbols(e);
63
+ r && (o = o.filter(function (r) {
64
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
65
+ })), t.push.apply(t, o);
57
66
  }
58
-
59
- return keys;
67
+ return t;
60
68
  }
61
-
62
- function _objectSpread2(target) {
63
- for (var i = 1; i < arguments.length; i++) {
64
- var source = null != arguments[i] ? arguments[i] : {};
65
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
66
- _defineProperty(target, key, source[key]);
67
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
68
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
69
+ function _objectSpread2(e) {
70
+ for (var r = 1; r < arguments.length; r++) {
71
+ var t = null != arguments[r] ? arguments[r] : {};
72
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
73
+ _defineProperty(e, r, t[r]);
74
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
75
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
69
76
  });
70
77
  }
71
-
72
- return target;
78
+ return e;
73
79
  }
74
80
 
75
81
  const _quaternion = new three.Quaternion();
@@ -117,41 +123,33 @@ const rigidBodyTypeMap = {
117
123
  const rigidBodyTypeFromString = type => rigidBodyTypeMap[type];
118
124
  const scaleVertices = (vertices, scale) => {
119
125
  const scaledVerts = Array.from(vertices);
120
-
121
126
  for (let i = 0; i < vertices.length / 3; i++) {
122
127
  scaledVerts[i * 3] *= scale.x;
123
128
  scaledVerts[i * 3 + 1] *= scale.y;
124
129
  scaledVerts[i * 3 + 2] *= scale.z;
125
130
  }
126
-
127
131
  return scaledVerts;
128
132
  };
129
133
  const vectorToTuple = v => {
130
134
  if (!v) return [0];
131
-
132
135
  if (v instanceof three.Quaternion) {
133
136
  return [v.x, v.y, v.z, v.w];
134
137
  }
135
-
136
138
  if (v instanceof three.Vector3 || v instanceof three.Euler) {
137
139
  return [v.x, v.y, v.z];
138
140
  }
139
-
140
141
  if (Array.isArray(v)) {
141
142
  return v;
142
143
  }
143
-
144
144
  return [v];
145
145
  };
146
146
  function useConst(initialValue) {
147
147
  const ref = React.useRef();
148
-
149
148
  if (ref.current === undefined) {
150
149
  ref.current = {
151
150
  value: typeof initialValue === "function" ? initialValue() : initialValue
152
151
  };
153
152
  }
154
-
155
153
  return ref.current.value;
156
154
  }
157
155
 
@@ -170,7 +168,6 @@ const useRaf = callback => {
170
168
  cb.current(delta / 1000);
171
169
  lastFrame.current = now;
172
170
  };
173
-
174
171
  raf.current = requestAnimationFrame(loop);
175
172
  return () => cancelAnimationFrame(raf.current);
176
173
  }, []);
@@ -185,7 +182,6 @@ const UseFrameStepper = ({
185
182
  }, updatePriority);
186
183
  return null;
187
184
  };
188
-
189
185
  const RafStepper = ({
190
186
  onStep
191
187
  }) => {
@@ -194,7 +190,6 @@ const RafStepper = ({
194
190
  });
195
191
  return null;
196
192
  };
197
-
198
193
  const FrameStepper = ({
199
194
  onStep,
200
195
  type,
@@ -207,98 +202,80 @@ const FrameStepper = ({
207
202
  updatePriority: updatePriority
208
203
  });
209
204
  };
210
-
211
205
  var FrameStepper$1 = /*#__PURE__*/React.memo(FrameStepper);
212
206
 
213
- function _objectWithoutPropertiesLoose(source, excluded) {
214
- if (source == null) return {};
215
- var target = {};
216
- var sourceKeys = Object.keys(source);
217
- var key, i;
218
-
219
- for (i = 0; i < sourceKeys.length; i++) {
220
- key = sourceKeys[i];
221
- if (excluded.indexOf(key) >= 0) continue;
222
- target[key] = source[key];
207
+ function _objectWithoutPropertiesLoose(r, e) {
208
+ if (null == r) return {};
209
+ var t = {};
210
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
211
+ if (e.includes(n)) continue;
212
+ t[n] = r[n];
223
213
  }
224
-
225
- return target;
214
+ return t;
226
215
  }
227
216
 
228
- function _objectWithoutProperties(source, excluded) {
229
- if (source == null) return {};
230
- var target = _objectWithoutPropertiesLoose(source, excluded);
231
- var key, i;
232
-
217
+ function _objectWithoutProperties(e, t) {
218
+ if (null == e) return {};
219
+ var o,
220
+ r,
221
+ i = _objectWithoutPropertiesLoose(e, t);
233
222
  if (Object.getOwnPropertySymbols) {
234
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
235
-
236
- for (i = 0; i < sourceSymbolKeys.length; i++) {
237
- key = sourceSymbolKeys[i];
238
- if (excluded.indexOf(key) >= 0) continue;
239
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
240
- target[key] = source[key];
241
- }
223
+ var s = Object.getOwnPropertySymbols(e);
224
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
242
225
  }
243
-
244
- return target;
226
+ return i;
245
227
  }
246
228
 
247
- const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale"];
229
+ const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction"];
248
230
  const scaleColliderArgs = (shape, args, scale) => {
249
- const newArgs = args.slice(); // Heightfield uses a vector
231
+ const newArgs = args.slice();
250
232
 
233
+ // Heightfield uses a vector
251
234
  if (shape === "heightfield") {
252
235
  const s = newArgs[3];
253
236
  s.x *= scale.x;
254
237
  s.x *= scale.y;
255
238
  s.x *= scale.z;
256
239
  return newArgs;
257
- } // Trimesh and convex scale the vertices
258
-
240
+ }
259
241
 
242
+ // Trimesh and convex scale the vertices
260
243
  if (shape === "trimesh" || shape === "convexHull") {
261
244
  newArgs[0] = scaleVertices(newArgs[0], scale);
262
245
  return newArgs;
263
- } // Prepfill with some extra
264
-
246
+ }
265
247
 
248
+ // Prepfill with some extra
266
249
  const scaleArray = [scale.x, scale.y, scale.z, scale.x, scale.x];
267
250
  return newArgs.map((arg, index) => scaleArray[index] * arg);
268
251
  };
269
252
  const createColliderFromOptions = (options, world, scale, getRigidBody) => {
270
- const scaledArgs = scaleColliderArgs(options.shape, options.args, scale); // @ts-ignore
271
-
253
+ const scaledArgs = scaleColliderArgs(options.shape, options.args, scale);
254
+ // @ts-ignore
272
255
  const desc = rapier3dCompat.ColliderDesc[options.shape](...scaledArgs);
273
256
  return world.createCollider(desc, getRigidBody === null || getRigidBody === void 0 ? void 0 : getRigidBody());
274
257
  };
275
258
  const immutableColliderOptions = ["shape", "args"];
276
259
  const massPropertiesConflictError = "Please pick ONLY ONE of the `density`, `mass` and `massProperties` options.";
277
-
278
260
  const setColliderMassOptions = (collider, options) => {
279
261
  if (options.density !== undefined) {
280
262
  if (options.mass !== undefined || options.massProperties !== undefined) {
281
263
  throw new Error(massPropertiesConflictError);
282
264
  }
283
-
284
265
  collider.setDensity(options.density);
285
266
  return;
286
267
  }
287
-
288
268
  if (options.mass !== undefined) {
289
269
  if (options.massProperties !== undefined) {
290
270
  throw new Error(massPropertiesConflictError);
291
271
  }
292
-
293
272
  collider.setMass(options.mass);
294
273
  return;
295
274
  }
296
-
297
275
  if (options.massProperties !== undefined) {
298
276
  collider.setMassProperties(options.massProperties.mass, options.massProperties.centerOfMass, options.massProperties.principalAngularInertia, options.massProperties.angularInertiaLocalFrame);
299
277
  }
300
278
  };
301
-
302
279
  const mutableColliderOptions = {
303
280
  sensor: (collider, value) => {
304
281
  collider.setSensor(value);
@@ -321,6 +298,12 @@ const mutableColliderOptions = {
321
298
  restitutionCombineRule: (collider, value) => {
322
299
  collider.setRestitutionCombineRule(value);
323
300
  },
301
+ activeCollisionTypes: (collider, value) => {
302
+ collider.setActiveCollisionTypes(value);
303
+ },
304
+ contactSkin: (collider, value) => {
305
+ collider.setContactSkin(value);
306
+ },
324
307
  // To make sure the options all mutable options are listed
325
308
  quaternion: () => {},
326
309
  position: () => {},
@@ -330,23 +313,17 @@ const mutableColliderOptions = {
330
313
  const mutableColliderOptionKeys = Object.keys(mutableColliderOptions);
331
314
  const setColliderOptions = (collider, options, states) => {
332
315
  const state = states.get(collider.handle);
333
-
334
316
  if (state) {
335
317
  var _state$worldParent;
336
-
337
318
  // Update collider position based on the object's position
338
319
  const parentWorldScale = state.object.parent.getWorldScale(_vector3);
339
320
  const parentInvertedWorldMatrix = (_state$worldParent = state.worldParent) === null || _state$worldParent === void 0 ? void 0 : _state$worldParent.matrixWorld.clone().invert();
340
321
  state.object.updateWorldMatrix(true, false);
341
-
342
322
  _matrix4.copy(state.object.matrixWorld);
343
-
344
323
  if (parentInvertedWorldMatrix) {
345
324
  _matrix4.premultiply(parentInvertedWorldMatrix);
346
325
  }
347
-
348
326
  _matrix4.decompose(_position, _rotation, _scale);
349
-
350
327
  if (collider.parent()) {
351
328
  collider.setTranslationWrtParent({
352
329
  x: _position.x * parentWorldScale.x,
@@ -362,16 +339,17 @@ const setColliderOptions = (collider, options, states) => {
362
339
  });
363
340
  collider.setRotation(_rotation);
364
341
  }
365
-
366
342
  mutableColliderOptionKeys.forEach(key => {
367
343
  if (key in options) {
368
344
  const option = options[key];
369
- mutableColliderOptions[key](collider, // @ts-ignore Option does not want to fit into the function, but it will
345
+ mutableColliderOptions[key](collider,
346
+ // @ts-ignore Option does not want to fit into the function, but it will
370
347
  option, options);
371
348
  }
372
- }); // handle mass separately, because the assignments
373
- // are exclusive.
349
+ });
374
350
 
351
+ // handle mass separately, because the assignments
352
+ // are exclusive.
375
353
  setColliderMassOptions(collider, options);
376
354
  }
377
355
  };
@@ -385,7 +363,6 @@ const useUpdateColliderOptions = (getCollider, props, states) => {
385
363
  setColliderOptions(collider, props, states);
386
364
  }, [...mutablePropsAsFlatArray, getCollider]);
387
365
  };
388
-
389
366
  const isChildOfMeshCollider = child => {
390
367
  let flag = false;
391
368
  child.traverseAncestors(a => {
@@ -393,7 +370,6 @@ const isChildOfMeshCollider = child => {
393
370
  });
394
371
  return flag;
395
372
  };
396
-
397
373
  const createColliderState = (collider, object, rigidBodyObject) => {
398
374
  return {
399
375
  collider,
@@ -415,16 +391,13 @@ const createColliderPropsFromChildren = ({
415
391
  const childColliderProps = [];
416
392
  object.updateWorldMatrix(true, false);
417
393
  const invertedParentMatrixWorld = object.matrixWorld.clone().invert();
418
-
419
394
  const colliderFromChild = child => {
420
395
  if ("isMesh" in child) {
421
396
  if (_ignoreMeshColliders && isChildOfMeshCollider(child)) return;
422
397
  const worldScale = child.getWorldScale(_scale);
423
398
  const shape = autoColliderMap[options.colliders || "cuboid"];
424
399
  child.updateWorldMatrix(true, false);
425
-
426
400
  _matrix4.copy(child.matrixWorld).premultiply(invertedParentMatrixWorld).decompose(_position, _rotation, _scale);
427
-
428
401
  const rotationEuler = new three.Euler().setFromQuaternion(_rotation, "XYZ");
429
402
  const {
430
403
  geometry
@@ -433,7 +406,6 @@ const createColliderPropsFromChildren = ({
433
406
  args,
434
407
  offset
435
408
  } = getColliderArgsFromGeometry(geometry, options.colliders || "cuboid");
436
-
437
409
  const colliderProps = _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(options)), {}, {
438
410
  args: args,
439
411
  shape: shape,
@@ -441,17 +413,14 @@ const createColliderPropsFromChildren = ({
441
413
  position: [_position.x + offset.x * worldScale.x, _position.y + offset.y * worldScale.y, _position.z + offset.z * worldScale.z],
442
414
  scale: [worldScale.x, worldScale.y, worldScale.z]
443
415
  });
444
-
445
416
  childColliderProps.push(colliderProps);
446
417
  }
447
418
  };
448
-
449
419
  if (options.includeInvisible) {
450
420
  object.traverse(colliderFromChild);
451
421
  } else {
452
422
  object.traverseVisible(colliderFromChild);
453
423
  }
454
-
455
424
  return childColliderProps;
456
425
  };
457
426
  const getColliderArgsFromGeometry = (geometry, colliders) => {
@@ -468,7 +437,6 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
468
437
  offset: boundingBox.getCenter(new three.Vector3())
469
438
  };
470
439
  }
471
-
472
440
  case "ball":
473
441
  {
474
442
  geometry.computeBoundingSphere();
@@ -481,18 +449,15 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
481
449
  offset: boundingSphere.center
482
450
  };
483
451
  }
484
-
485
452
  case "trimesh":
486
453
  {
487
454
  var _clonedGeometry$index;
488
-
489
455
  const clonedGeometry = geometry.index ? geometry.clone() : threeStdlib.mergeVertices(geometry);
490
456
  return {
491
457
  args: [clonedGeometry.attributes.position.array, (_clonedGeometry$index = clonedGeometry.index) === null || _clonedGeometry$index === void 0 ? void 0 : _clonedGeometry$index.array],
492
458
  offset: new three.Vector3()
493
459
  };
494
460
  }
495
-
496
461
  case "hull":
497
462
  {
498
463
  const g = geometry.clone();
@@ -502,7 +467,6 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
502
467
  };
503
468
  }
504
469
  }
505
-
506
470
  return {
507
471
  args: [],
508
472
  offset: new three.Vector3()
@@ -528,7 +492,6 @@ activeEvents = {}) => {
528
492
  } = props;
529
493
  React.useEffect(() => {
530
494
  const collider = getCollider();
531
-
532
495
  if (collider) {
533
496
  const {
534
497
  collision: collisionEventsActive,
@@ -536,7 +499,6 @@ activeEvents = {}) => {
536
499
  } = getActiveCollisionEventsFromProps(props);
537
500
  const hasCollisionEvent = collisionEventsActive || activeEvents.collision;
538
501
  const hasContactForceEvent = contactForceEventsActive || activeEvents.contactForce;
539
-
540
502
  if (hasCollisionEvent && hasContactForceEvent) {
541
503
  collider.setActiveEvents(rapier3dCompat.ActiveEvents.COLLISION_EVENTS | rapier3dCompat.ActiveEvents.CONTACT_FORCE_EVENTS);
542
504
  } else if (hasCollisionEvent) {
@@ -544,7 +506,6 @@ activeEvents = {}) => {
544
506
  } else if (hasContactForceEvent) {
545
507
  collider.setActiveEvents(rapier3dCompat.ActiveEvents.CONTACT_FORCE_EVENTS);
546
508
  }
547
-
548
509
  events.set(collider.handle, {
549
510
  onCollisionEnter,
550
511
  onCollisionExit,
@@ -553,7 +514,6 @@ activeEvents = {}) => {
553
514
  onContactForce
554
515
  });
555
516
  }
556
-
557
517
  return () => {
558
518
  if (collider) {
559
519
  events.delete(collider.handle);
@@ -563,34 +523,33 @@ activeEvents = {}) => {
563
523
  };
564
524
  const cleanRigidBodyPropsForCollider = (props = {}) => {
565
525
  const rest = _objectWithoutProperties(props, _excluded$2);
566
-
567
526
  return rest;
568
527
  };
569
528
 
529
+ // Utils
570
530
  const useMutableCallback = fn => {
571
531
  const ref = React.useRef(fn);
572
532
  React.useEffect(() => {
573
533
  ref.current = fn;
574
534
  }, [fn]);
575
535
  return ref;
576
- }; // External hooks
536
+ };
577
537
 
538
+ // External hooks
578
539
  /**
579
540
  * Exposes the Rapier context, and world
580
541
  * @category Hooks
581
542
  */
582
-
583
-
584
543
  const useRapier = () => {
585
544
  const rapier = React.useContext(rapierContext);
586
545
  if (!rapier) throw new Error("react-three-rapier: useRapier must be used within <Physics />!");
587
546
  return rapier;
588
547
  };
548
+
589
549
  /**
590
550
  * Registers a callback to be called before the physics step
591
551
  * @category Hooks
592
552
  */
593
-
594
553
  const useBeforePhysicsStep = callback => {
595
554
  const {
596
555
  beforeStepCallbacks
@@ -603,11 +562,11 @@ const useBeforePhysicsStep = callback => {
603
562
  };
604
563
  }, []);
605
564
  };
565
+
606
566
  /**
607
567
  * Registers a callback to be called after the physics step
608
568
  * @category Hooks
609
569
  */
610
-
611
570
  const useAfterPhysicsStep = callback => {
612
571
  const {
613
572
  afterStepCallbacks
@@ -619,17 +578,16 @@ const useAfterPhysicsStep = callback => {
619
578
  afterStepCallbacks.delete(ref);
620
579
  };
621
580
  }, []);
622
- }; // Internal hooks
581
+ };
623
582
 
583
+ // Internal hooks
624
584
  /**
625
585
  * @internal
626
586
  */
627
-
628
587
  const useChildColliderProps = (ref, options, ignoreMeshColliders = true) => {
629
588
  const [colliderProps, setColliderProps] = React.useState([]);
630
589
  React.useEffect(() => {
631
590
  const object = ref.current;
632
-
633
591
  if (object && options.colliders !== false) {
634
592
  setColliderProps(createColliderPropsFromChildren({
635
593
  object: ref.current,
@@ -675,33 +633,26 @@ const createSingletonProxy = createInstance => {
675
633
  if (!instance) {
676
634
  instance = createInstance();
677
635
  }
678
-
679
636
  return Reflect.get(instance, prop);
680
637
  },
681
-
682
638
  set(target, prop, value) {
683
639
  if (!instance) {
684
640
  instance = createInstance();
685
641
  }
686
-
687
642
  return Reflect.set(instance, prop, value);
688
643
  }
689
-
690
644
  };
691
645
  const proxy = new Proxy({}, handler);
692
-
693
646
  const reset = () => {
694
647
  instance = undefined;
695
648
  };
696
-
697
649
  const set = newInstance => {
698
650
  instance = newInstance;
699
651
  };
652
+
700
653
  /**
701
654
  * Return the proxy and a reset function
702
655
  */
703
-
704
-
705
656
  return {
706
657
  proxy,
707
658
  reset,
@@ -710,10 +661,8 @@ const createSingletonProxy = createInstance => {
710
661
  };
711
662
 
712
663
  const rapierContext = /*#__PURE__*/React.createContext(undefined);
713
-
714
664
  const getCollisionPayloadFromSource = (target, other) => {
715
665
  var _target$collider$stat, _target$rigidBody$sta, _other$collider$state, _other$rigidBody$stat, _other$collider$state2, _other$rigidBody$stat2;
716
-
717
666
  return {
718
667
  target: {
719
668
  rigidBody: target.rigidBody.object,
@@ -733,13 +682,11 @@ const getCollisionPayloadFromSource = (target, other) => {
733
682
  rigidBodyObject: (_other$rigidBody$stat2 = other.rigidBody.state) === null || _other$rigidBody$stat2 === void 0 ? void 0 : _other$rigidBody$stat2.object
734
683
  };
735
684
  };
736
-
737
685
  const importRapier = async () => {
738
686
  let r = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@dimforge/rapier3d-compat')); });
739
687
  await r.init();
740
688
  return r;
741
689
  };
742
-
743
690
  /**
744
691
  * The main physics component used to create a physics world.
745
692
  * @category Components
@@ -762,7 +709,8 @@ const Physics = props => {
762
709
  numInternalPgsIterations = 1,
763
710
  minIslandSize = 128,
764
711
  maxCcdSubsteps = 1,
765
- erp = 0.8
712
+ contactNaturalFrequency = 30,
713
+ lengthUnit = 1
766
714
  } = props;
767
715
  const rapier = suspendReact.suspend(importRapier, ["@react-thee/rapier", importRapier]);
768
716
  const {
@@ -775,12 +723,12 @@ const Physics = props => {
775
723
  const eventQueue = useConst(() => new rapier3dCompat.EventQueue(false));
776
724
  const beforeStepCallbacks = useConst(() => new Set());
777
725
  const afterStepCallbacks = useConst(() => new Set());
726
+
778
727
  /**
779
728
  * Initiate the world
780
729
  * This creates a singleton proxy, so that the world is only created when
781
730
  * something within it is accessed.
782
731
  */
783
-
784
732
  const {
785
733
  proxy: worldProxy,
786
734
  reset: resetWorldProxy,
@@ -791,22 +739,23 @@ const Physics = props => {
791
739
  worldProxy.free();
792
740
  resetWorldProxy();
793
741
  };
794
- }, []); // Update mutable props
742
+ }, []);
795
743
 
744
+ // Update mutable props
796
745
  React.useEffect(() => {
797
746
  worldProxy.gravity = vector3ToRapierVector(gravity);
798
747
  worldProxy.integrationParameters.numSolverIterations = numSolverIterations;
799
748
  worldProxy.integrationParameters.numAdditionalFrictionIterations = numAdditionalFrictionIterations;
800
749
  worldProxy.integrationParameters.numInternalPgsIterations = numInternalPgsIterations;
801
- worldProxy.integrationParameters.allowedLinearError = allowedLinearError;
750
+ worldProxy.integrationParameters.normalizedAllowedLinearError = allowedLinearError;
802
751
  worldProxy.integrationParameters.minIslandSize = minIslandSize;
803
752
  worldProxy.integrationParameters.maxCcdSubsteps = maxCcdSubsteps;
804
- worldProxy.integrationParameters.predictionDistance = predictionDistance;
805
- worldProxy.integrationParameters.erp = erp;
806
- }, [worldProxy, ...gravity, numSolverIterations, numAdditionalFrictionIterations, numInternalPgsIterations, allowedLinearError, minIslandSize, maxCcdSubsteps, predictionDistance, erp]);
753
+ worldProxy.integrationParameters.normalizedPredictionDistance = predictionDistance;
754
+ worldProxy.lengthUnit = lengthUnit;
755
+ worldProxy.integrationParameters.contact_natural_frequency = contactNaturalFrequency;
756
+ }, [worldProxy, ...gravity, numSolverIterations, numAdditionalFrictionIterations, numInternalPgsIterations, allowedLinearError, minIslandSize, maxCcdSubsteps, predictionDistance, lengthUnit, contactNaturalFrequency]);
807
757
  const getSourceFromColliderHandle = React.useCallback(handle => {
808
758
  var _collider$parent;
809
-
810
759
  const collider = worldProxy.getCollider(handle);
811
760
  const colEvents = colliderEvents.get(handle);
812
761
  const colliderState = colliderStates.get(handle);
@@ -834,37 +783,36 @@ const Physics = props => {
834
783
  });
835
784
  const step = React.useCallback(dt => {
836
785
  const world = worldProxy;
786
+
837
787
  /* Check if the timestep is supposed to be variable. We'll do this here
838
788
  once so we don't have to string-check every frame. */
839
-
840
789
  const timeStepVariable = timeStep === "vary";
790
+
841
791
  /**
842
792
  * Fixed timeStep simulation progression
843
793
  * @see https://gafferongames.com/post/fix_your_timestep/
844
794
  */
845
795
 
846
796
  const clampedDelta = three.MathUtils.clamp(dt, 0, 0.5);
847
-
848
797
  const stepWorld = delta => {
849
798
  // Trigger beforeStep callbacks
850
799
  beforeStepCallbacks.forEach(callback => {
851
800
  callback.current(world);
852
801
  });
853
802
  world.timestep = delta;
854
- world.step(eventQueue); // Trigger afterStep callbacks
803
+ world.step(eventQueue);
855
804
 
805
+ // Trigger afterStep callbacks
856
806
  afterStepCallbacks.forEach(callback => {
857
807
  callback.current(world);
858
808
  });
859
809
  };
860
-
861
810
  if (timeStepVariable) {
862
811
  stepWorld(clampedDelta);
863
812
  } else {
864
813
  // don't step time forwards if paused
865
814
  // Increase accumulator
866
815
  steppingState.accumulator += clampedDelta;
867
-
868
816
  while (steppingState.accumulator >= timeStep) {
869
817
  // Set up previous state
870
818
  // needed for accurate interpolations if the world steps more than once
@@ -877,57 +825,48 @@ const Physics = props => {
877
825
  };
878
826
  });
879
827
  }
880
-
881
828
  stepWorld(timeStep);
882
829
  steppingState.accumulator -= timeStep;
883
830
  }
884
831
  }
832
+ const interpolationAlpha = timeStepVariable || !interpolate || paused ? 1 : steppingState.accumulator / timeStep;
885
833
 
886
- const interpolationAlpha = timeStepVariable || !interpolate || paused ? 1 : steppingState.accumulator / timeStep; // Update meshes
887
-
834
+ // Update meshes
888
835
  rigidBodyStates.forEach((state, handle) => {
889
836
  const rigidBody = world.getRigidBody(handle);
890
837
  const events = rigidBodyEvents.get(handle);
891
-
892
838
  if (events !== null && events !== void 0 && events.onSleep || events !== null && events !== void 0 && events.onWake) {
893
839
  if (rigidBody.isSleeping() && !state.isSleeping) {
894
840
  var _events$onSleep;
895
-
896
841
  events === null || events === void 0 ? void 0 : (_events$onSleep = events.onSleep) === null || _events$onSleep === void 0 ? void 0 : _events$onSleep.call(events);
897
842
  }
898
-
899
843
  if (!rigidBody.isSleeping() && state.isSleeping) {
900
844
  var _events$onWake;
901
-
902
845
  events === null || events === void 0 ? void 0 : (_events$onWake = events.onWake) === null || _events$onWake === void 0 ? void 0 : _events$onWake.call(events);
903
846
  }
904
-
905
847
  state.isSleeping = rigidBody.isSleeping();
906
848
  }
907
-
908
849
  if (!rigidBody || rigidBody.isSleeping() && !("isInstancedMesh" in state.object) || !state.setMatrix) {
909
850
  return;
910
- } // New states
911
-
851
+ }
912
852
 
853
+ // New states
913
854
  let t = rigidBody.translation();
914
855
  let r = rigidBody.rotation();
915
856
  let previousState = steppingState.previousState[handle];
916
-
917
857
  if (previousState) {
918
858
  // Get previous simulated world position
919
- _matrix4.compose(previousState.position, rapierQuaternionToQuaternion(previousState.rotation), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale); // Apply previous tick position
920
-
859
+ _matrix4.compose(previousState.position, rapierQuaternionToQuaternion(previousState.rotation), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale);
921
860
 
861
+ // Apply previous tick position
922
862
  if (state.meshType == "mesh") {
923
863
  state.object.position.copy(_position);
924
864
  state.object.quaternion.copy(_rotation);
925
865
  }
926
- } // Get new position
927
-
866
+ }
928
867
 
868
+ // Get new position
929
869
  _matrix4.compose(t, rapierQuaternionToQuaternion(r), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale);
930
-
931
870
  if (state.meshType == "instancedMesh") {
932
871
  state.setMatrix(_matrix4);
933
872
  } else {
@@ -938,19 +877,17 @@ const Physics = props => {
938
877
  });
939
878
  eventQueue.drainCollisionEvents((handle1, handle2, started) => {
940
879
  const source1 = getSourceFromColliderHandle(handle1);
941
- const source2 = getSourceFromColliderHandle(handle2); // Collision Events
880
+ const source2 = getSourceFromColliderHandle(handle2);
942
881
 
882
+ // Collision Events
943
883
  if (!(source1 !== null && source1 !== void 0 && source1.collider.object) || !(source2 !== null && source2 !== void 0 && source2.collider.object)) {
944
884
  return;
945
885
  }
946
-
947
886
  const collisionPayload1 = getCollisionPayloadFromSource(source1, source2);
948
887
  const collisionPayload2 = getCollisionPayloadFromSource(source2, source1);
949
-
950
888
  if (started) {
951
889
  world.contactPair(source1.collider.object, source2.collider.object, (manifold, flipped) => {
952
890
  var _source1$rigidBody$ev, _source1$rigidBody$ev2, _source2$rigidBody$ev, _source2$rigidBody$ev2, _source1$collider$eve, _source1$collider$eve2, _source2$collider$eve, _source2$collider$eve2;
953
-
954
891
  /* RigidBody events */
955
892
  (_source1$rigidBody$ev = source1.rigidBody.events) === null || _source1$rigidBody$ev === void 0 ? void 0 : (_source1$rigidBody$ev2 = _source1$rigidBody$ev.onCollisionEnter) === null || _source1$rigidBody$ev2 === void 0 ? void 0 : _source1$rigidBody$ev2.call(_source1$rigidBody$ev, _objectSpread2(_objectSpread2({}, collisionPayload1), {}, {
956
893
  manifold,
@@ -960,8 +897,8 @@ const Physics = props => {
960
897
  manifold,
961
898
  flipped
962
899
  }));
963
- /* Collider events */
964
900
 
901
+ /* Collider events */
965
902
  (_source1$collider$eve = source1.collider.events) === null || _source1$collider$eve === void 0 ? void 0 : (_source1$collider$eve2 = _source1$collider$eve.onCollisionEnter) === null || _source1$collider$eve2 === void 0 ? void 0 : _source1$collider$eve2.call(_source1$collider$eve, _objectSpread2(_objectSpread2({}, collisionPayload1), {}, {
966
903
  manifold,
967
904
  flipped
@@ -973,18 +910,16 @@ const Physics = props => {
973
910
  });
974
911
  } else {
975
912
  var _source1$rigidBody$ev3, _source1$rigidBody$ev4, _source2$rigidBody$ev3, _source2$rigidBody$ev4, _source1$collider$eve3, _source1$collider$eve4, _source2$collider$eve3, _source2$collider$eve4;
976
-
977
913
  (_source1$rigidBody$ev3 = source1.rigidBody.events) === null || _source1$rigidBody$ev3 === void 0 ? void 0 : (_source1$rigidBody$ev4 = _source1$rigidBody$ev3.onCollisionExit) === null || _source1$rigidBody$ev4 === void 0 ? void 0 : _source1$rigidBody$ev4.call(_source1$rigidBody$ev3, collisionPayload1);
978
914
  (_source2$rigidBody$ev3 = source2.rigidBody.events) === null || _source2$rigidBody$ev3 === void 0 ? void 0 : (_source2$rigidBody$ev4 = _source2$rigidBody$ev3.onCollisionExit) === null || _source2$rigidBody$ev4 === void 0 ? void 0 : _source2$rigidBody$ev4.call(_source2$rigidBody$ev3, collisionPayload2);
979
915
  (_source1$collider$eve3 = source1.collider.events) === null || _source1$collider$eve3 === void 0 ? void 0 : (_source1$collider$eve4 = _source1$collider$eve3.onCollisionExit) === null || _source1$collider$eve4 === void 0 ? void 0 : _source1$collider$eve4.call(_source1$collider$eve3, collisionPayload1);
980
916
  (_source2$collider$eve3 = source2.collider.events) === null || _source2$collider$eve3 === void 0 ? void 0 : (_source2$collider$eve4 = _source2$collider$eve3.onCollisionExit) === null || _source2$collider$eve4 === void 0 ? void 0 : _source2$collider$eve4.call(_source2$collider$eve3, collisionPayload2);
981
- } // Sensor Intersections
982
-
917
+ }
983
918
 
919
+ // Sensor Intersections
984
920
  if (started) {
985
921
  if (world.intersectionPair(source1.collider.object, source2.collider.object)) {
986
922
  var _source1$rigidBody$ev5, _source1$rigidBody$ev6, _source2$rigidBody$ev5, _source2$rigidBody$ev6, _source1$collider$eve5, _source1$collider$eve6, _source2$collider$eve5, _source2$collider$eve6;
987
-
988
923
  (_source1$rigidBody$ev5 = source1.rigidBody.events) === null || _source1$rigidBody$ev5 === void 0 ? void 0 : (_source1$rigidBody$ev6 = _source1$rigidBody$ev5.onIntersectionEnter) === null || _source1$rigidBody$ev6 === void 0 ? void 0 : _source1$rigidBody$ev6.call(_source1$rigidBody$ev5, collisionPayload1);
989
924
  (_source2$rigidBody$ev5 = source2.rigidBody.events) === null || _source2$rigidBody$ev5 === void 0 ? void 0 : (_source2$rigidBody$ev6 = _source2$rigidBody$ev5.onIntersectionEnter) === null || _source2$rigidBody$ev6 === void 0 ? void 0 : _source2$rigidBody$ev6.call(_source2$rigidBody$ev5, collisionPayload2);
990
925
  (_source1$collider$eve5 = source1.collider.events) === null || _source1$collider$eve5 === void 0 ? void 0 : (_source1$collider$eve6 = _source1$collider$eve5.onIntersectionEnter) === null || _source1$collider$eve6 === void 0 ? void 0 : _source1$collider$eve6.call(_source1$collider$eve5, collisionPayload1);
@@ -992,7 +927,6 @@ const Physics = props => {
992
927
  }
993
928
  } else {
994
929
  var _source1$rigidBody$ev7, _source1$rigidBody$ev8, _source2$rigidBody$ev7, _source2$rigidBody$ev8, _source1$collider$eve7, _source1$collider$eve8, _source2$collider$eve7, _source2$collider$eve8;
995
-
996
930
  (_source1$rigidBody$ev7 = source1.rigidBody.events) === null || _source1$rigidBody$ev7 === void 0 ? void 0 : (_source1$rigidBody$ev8 = _source1$rigidBody$ev7.onIntersectionExit) === null || _source1$rigidBody$ev8 === void 0 ? void 0 : _source1$rigidBody$ev8.call(_source1$rigidBody$ev7, collisionPayload1);
997
931
  (_source2$rigidBody$ev7 = source2.rigidBody.events) === null || _source2$rigidBody$ev7 === void 0 ? void 0 : (_source2$rigidBody$ev8 = _source2$rigidBody$ev7.onIntersectionExit) === null || _source2$rigidBody$ev8 === void 0 ? void 0 : _source2$rigidBody$ev8.call(_source2$rigidBody$ev7, collisionPayload2);
998
932
  (_source1$collider$eve7 = source1.collider.events) === null || _source1$collider$eve7 === void 0 ? void 0 : (_source1$collider$eve8 = _source1$collider$eve7.onIntersectionExit) === null || _source1$collider$eve8 === void 0 ? void 0 : _source1$collider$eve8.call(_source1$collider$eve7, collisionPayload1);
@@ -1001,14 +935,13 @@ const Physics = props => {
1001
935
  });
1002
936
  eventQueue.drainContactForceEvents(event => {
1003
937
  var _source1$rigidBody$ev9, _source1$rigidBody$ev10, _source2$rigidBody$ev9, _source2$rigidBody$ev10, _source1$collider$eve9, _source1$collider$eve10, _source2$collider$eve9, _source2$collider$eve10;
1004
-
1005
938
  const source1 = getSourceFromColliderHandle(event.collider1());
1006
- const source2 = getSourceFromColliderHandle(event.collider2()); // Collision Events
939
+ const source2 = getSourceFromColliderHandle(event.collider2());
1007
940
 
941
+ // Collision Events
1008
942
  if (!(source1 !== null && source1 !== void 0 && source1.collider.object) || !(source2 !== null && source2 !== void 0 && source2.collider.object)) {
1009
943
  return;
1010
944
  }
1011
-
1012
945
  const collisionPayload1 = getCollisionPayloadFromSource(source1, source2);
1013
946
  const collisionPayload2 = getCollisionPayloadFromSource(source2, source1);
1014
947
  (_source1$rigidBody$ev9 = source1.rigidBody.events) === null || _source1$rigidBody$ev9 === void 0 ? void 0 : (_source1$rigidBody$ev10 = _source1$rigidBody$ev9.onContactForce) === null || _source1$rigidBody$ev10 === void 0 ? void 0 : _source1$rigidBody$ev10.call(_source1$rigidBody$ev9, _objectSpread2(_objectSpread2({}, collisionPayload1), {}, {
@@ -1075,41 +1008,30 @@ const Physics = props => {
1075
1008
  };
1076
1009
 
1077
1010
  function _extends() {
1078
- _extends = Object.assign ? Object.assign.bind() : function (target) {
1079
- for (var i = 1; i < arguments.length; i++) {
1080
- var source = arguments[i];
1081
-
1082
- for (var key in source) {
1083
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1084
- target[key] = source[key];
1085
- }
1086
- }
1011
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
1012
+ for (var e = 1; e < arguments.length; e++) {
1013
+ var t = arguments[e];
1014
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
1087
1015
  }
1088
-
1089
- return target;
1090
- };
1091
- return _extends.apply(this, arguments);
1016
+ return n;
1017
+ }, _extends.apply(null, arguments);
1092
1018
  }
1093
1019
 
1094
1020
  /**
1095
1021
  * Initiate an instance and return a safe getter
1096
1022
  */
1097
-
1098
1023
  const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
1099
1024
  const ref = React.useRef();
1100
1025
  const getInstance = React.useCallback(() => {
1101
1026
  if (!ref.current) {
1102
1027
  ref.current = createFn();
1103
1028
  }
1104
-
1105
1029
  return ref.current;
1106
1030
  }, dependencyList);
1107
1031
  React.useEffect(() => {
1108
1032
  // Save the destroy function and instance
1109
1033
  const instance = getInstance();
1110
-
1111
1034
  const destroy = () => destroyFn(instance);
1112
-
1113
1035
  return () => {
1114
1036
  destroy();
1115
1037
  ref.current = undefined;
@@ -1122,7 +1044,6 @@ const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
1122
1044
  * Takes an object resembling a Vector3 and returs a Three.Vector3
1123
1045
  * @category Math helpers
1124
1046
  */
1125
-
1126
1047
  const vec3 = ({
1127
1048
  x,
1128
1049
  y,
@@ -1134,11 +1055,11 @@ const vec3 = ({
1134
1055
  }) => {
1135
1056
  return new three.Vector3(x, y, z);
1136
1057
  };
1058
+
1137
1059
  /**
1138
1060
  * Takes an object resembling a Quaternion and returs a Three.Quaternion
1139
1061
  * @category Math helpers
1140
1062
  */
1141
-
1142
1063
  const quat = ({
1143
1064
  x,
1144
1065
  y,
@@ -1152,11 +1073,11 @@ const quat = ({
1152
1073
  }) => {
1153
1074
  return new three.Quaternion(x, y, z, w);
1154
1075
  };
1076
+
1155
1077
  /**
1156
1078
  * Takes an object resembling an Euler and returs a Three.Euler
1157
1079
  * @category Math helpers
1158
1080
  */
1159
-
1160
1081
  const euler = ({
1161
1082
  x,
1162
1083
  y,
@@ -1169,17 +1090,17 @@ const euler = ({
1169
1090
  return new three.Euler(x, y, z);
1170
1091
  };
1171
1092
 
1093
+ // Need to catch the case where forwardedRef is a function... how to do that?
1172
1094
  const useForwardedRef = (forwardedRef, defaultValue = null) => {
1173
- const innerRef = React.useRef(defaultValue); // Update the forwarded ref when the inner ref changes
1095
+ const innerRef = React.useRef(defaultValue);
1174
1096
 
1097
+ // Update the forwarded ref when the inner ref changes
1175
1098
  if (forwardedRef && typeof forwardedRef !== "function") {
1176
1099
  if (!forwardedRef.current) {
1177
1100
  forwardedRef.current = innerRef.current;
1178
1101
  }
1179
-
1180
1102
  return forwardedRef;
1181
1103
  }
1182
-
1183
1104
  return innerRef;
1184
1105
  };
1185
1106
 
@@ -1187,7 +1108,7 @@ const useForwardedRef = (forwardedRef, defaultValue = null) => {
1187
1108
  * A collider is a shape that can be attached to a rigid body to define its physical properties.
1188
1109
  * @internal
1189
1110
  */
1190
- const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
1111
+ const AnyCollider = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((props, forwardedRef) => {
1191
1112
  const {
1192
1113
  children,
1193
1114
  position,
@@ -1203,17 +1124,16 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((prop
1203
1124
  } = useRapier();
1204
1125
  const rigidBodyContext = useRigidBodyContext();
1205
1126
  const colliderRef = useForwardedRef(forwardedRef);
1206
- const objectRef = React.useRef(null); // We spread the props out here to make sure that the ref is updated when the props change.
1127
+ const objectRef = React.useRef(null);
1207
1128
 
1129
+ // We spread the props out here to make sure that the ref is updated when the props change.
1208
1130
  const immutablePropArray = immutableColliderOptions.flatMap(key => Array.isArray(props[key]) ? [...props[key]] : props[key]);
1209
1131
  const getInstance = useImperativeInstance(() => {
1210
1132
  const worldScale = objectRef.current.getWorldScale(vec3());
1211
1133
  const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
1212
-
1213
1134
  if (typeof forwardedRef == "function") {
1214
1135
  forwardedRef(collider);
1215
1136
  }
1216
-
1217
1137
  colliderRef.current = collider;
1218
1138
  return collider;
1219
1139
  }, collider => {
@@ -1242,7 +1162,6 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((prop
1242
1162
  name: name
1243
1163
  }, children);
1244
1164
  }));
1245
-
1246
1165
  /**
1247
1166
  * A cuboid collider shape
1248
1167
  * @category Colliders
@@ -1254,7 +1173,6 @@ const CuboidCollider = /*#__PURE__*/React__default["default"].forwardRef((props,
1254
1173
  }));
1255
1174
  });
1256
1175
  CuboidCollider.displayName = "CuboidCollider";
1257
-
1258
1176
  /**
1259
1177
  * A round cuboid collider shape
1260
1178
  * @category Colliders
@@ -1264,7 +1182,6 @@ const RoundCuboidCollider = /*#__PURE__*/React__default["default"].forwardRef((p
1264
1182
  ref: ref
1265
1183
  })));
1266
1184
  RoundCuboidCollider.displayName = "RoundCuboidCollider";
1267
-
1268
1185
  /**
1269
1186
  * A ball collider shape
1270
1187
  * @category Colliders
@@ -1274,7 +1191,6 @@ const BallCollider = /*#__PURE__*/React__default["default"].forwardRef((props, r
1274
1191
  ref: ref
1275
1192
  })));
1276
1193
  BallCollider.displayName = "BallCollider";
1277
-
1278
1194
  /**
1279
1195
  * A capsule collider shape
1280
1196
  * @category Colliders
@@ -1284,7 +1200,6 @@ const CapsuleCollider = /*#__PURE__*/React__default["default"].forwardRef((props
1284
1200
  ref: ref
1285
1201
  })));
1286
1202
  CapsuleCollider.displayName = "CapsuleCollider";
1287
-
1288
1203
  /**
1289
1204
  * A heightfield collider shape
1290
1205
  * @category Colliders
@@ -1294,7 +1209,6 @@ const HeightfieldCollider = /*#__PURE__*/React__default["default"].forwardRef((p
1294
1209
  ref: ref
1295
1210
  })));
1296
1211
  HeightfieldCollider.displayName = "HeightfieldCollider";
1297
-
1298
1212
  /**
1299
1213
  * A trimesh collider shape
1300
1214
  * @category Colliders
@@ -1304,7 +1218,6 @@ const TrimeshCollider = /*#__PURE__*/React__default["default"].forwardRef((props
1304
1218
  ref: ref
1305
1219
  })));
1306
1220
  TrimeshCollider.displayName = "TrimeshCollider";
1307
-
1308
1221
  /**
1309
1222
  * A cone collider shape
1310
1223
  * @category Colliders
@@ -1314,7 +1227,6 @@ const ConeCollider = /*#__PURE__*/React__default["default"].forwardRef((props, r
1314
1227
  ref: ref
1315
1228
  })));
1316
1229
  ConeCollider.displayName = "ConeCollider";
1317
-
1318
1230
  /**
1319
1231
  * A round cylinder collider shape
1320
1232
  * @category Colliders
@@ -1324,7 +1236,6 @@ const RoundConeCollider = /*#__PURE__*/React__default["default"].forwardRef((pro
1324
1236
  ref: ref
1325
1237
  })));
1326
1238
  RoundConeCollider.displayName = "RoundConeCollider";
1327
-
1328
1239
  /**
1329
1240
  * A cylinder collider shape
1330
1241
  * @category Colliders
@@ -1334,7 +1245,6 @@ const CylinderCollider = /*#__PURE__*/React__default["default"].forwardRef((prop
1334
1245
  ref: ref
1335
1246
  })));
1336
1247
  CylinderCollider.displayName = "CylinderCollider";
1337
-
1338
1248
  /**
1339
1249
  * A round cylinder collider shape
1340
1250
  * @category Colliders
@@ -1344,7 +1254,6 @@ const RoundCylinderCollider = /*#__PURE__*/React__default["default"].forwardRef(
1344
1254
  ref: ref
1345
1255
  })));
1346
1256
  CylinderCollider.displayName = "RoundCylinderCollider";
1347
-
1348
1257
  /**
1349
1258
  * A convex hull collider shape
1350
1259
  * @category Colliders
@@ -1357,10 +1266,10 @@ ConvexHullCollider.displayName = "ConvexHullCollider";
1357
1266
 
1358
1267
  const rigidBodyDescFromOptions = options => {
1359
1268
  var _options$canSleep;
1360
-
1361
1269
  const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
1362
- const desc = new rapier3dCompat.RigidBodyDesc(type); // Apply immutable options
1270
+ const desc = new rapier3dCompat.RigidBodyDesc(type);
1363
1271
 
1272
+ // Apply immutable options
1364
1273
  desc.canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
1365
1274
  return desc;
1366
1275
  };
@@ -1392,11 +1301,9 @@ const mutableRigidBodyOptions = {
1392
1301
  gravityScale: (rb, value) => {
1393
1302
  rb.setGravityScale(value, true);
1394
1303
  },
1395
-
1396
1304
  additionalSolverIterations(rb, value) {
1397
1305
  rb.setAdditionalSolverIterations(value);
1398
1306
  },
1399
-
1400
1307
  linearDamping: (rb, value) => {
1401
1308
  rb.setLinearDamping(value);
1402
1309
  },
@@ -1435,14 +1342,15 @@ const mutableRigidBodyOptions = {
1435
1342
  ccd: (rb, value) => {
1436
1343
  rb.enableCcd(value);
1437
1344
  },
1345
+ softCcdPrediction: (rb, value) => {
1346
+ rb.setSoftCcdPrediction(value);
1347
+ },
1438
1348
  userData: (rb, value) => {
1439
1349
  rb.userData = value;
1440
1350
  },
1441
-
1442
1351
  type(rb, value) {
1443
1352
  rb.setBodyType(rigidBodyTypeFromString(value), true);
1444
1353
  },
1445
-
1446
1354
  position: () => {},
1447
1355
  rotation: () => {},
1448
1356
  quaternion: () => {},
@@ -1453,19 +1361,14 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
1453
1361
  if (!rigidBody) {
1454
1362
  return;
1455
1363
  }
1456
-
1457
1364
  const state = states.get(rigidBody.handle);
1458
-
1459
1365
  if (state) {
1460
1366
  if (updateTranslations) {
1461
1367
  state.object.updateWorldMatrix(true, false);
1462
-
1463
1368
  _matrix4.copy(state.object.matrixWorld).decompose(_position, _rotation, _scale);
1464
-
1465
1369
  rigidBody.setTranslation(_position, false);
1466
1370
  rigidBody.setRotation(_rotation, false);
1467
1371
  }
1468
-
1469
1372
  mutableRigidBodyOptionKeys.forEach(key => {
1470
1373
  if (key in options) {
1471
1374
  mutableRigidBodyOptions[key](rigidBody, options[key]);
@@ -1514,23 +1417,21 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
1514
1417
  const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
1515
1418
  const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
1516
1419
  const useRigidBodyContext = () => React.useContext(RigidBodyContext);
1517
-
1518
1420
  /**
1519
1421
  * A rigid body is a physical object that can be simulated by the physics engine.
1520
1422
  * @category Components
1521
1423
  */
1522
- const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
1424
+ const RigidBody = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((props, forwardedRef) => {
1523
1425
  const {
1524
- children,
1525
- type,
1526
- position,
1527
- rotation,
1528
- scale,
1529
- quaternion,
1530
- transformState
1531
- } = props,
1532
- objectProps = _objectWithoutProperties(props, _excluded$1);
1533
-
1426
+ children,
1427
+ type,
1428
+ position,
1429
+ rotation,
1430
+ scale,
1431
+ quaternion,
1432
+ transformState
1433
+ } = props,
1434
+ objectProps = _objectWithoutProperties(props, _excluded$1);
1534
1435
  const objectRef = React.useRef(null);
1535
1436
  const rigidBodyRef = useForwardedRef(forwardedRef);
1536
1437
  const {
@@ -1547,24 +1448,24 @@ const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props,
1547
1448
  const immutablePropArray = immutableRigidBodyOptions.flatMap(key => {
1548
1449
  return Array.isArray(mergedOptions[key]) ? [...mergedOptions[key]] : mergedOptions[key];
1549
1450
  });
1550
- const childColliderProps = useChildColliderProps(objectRef, mergedOptions); // Provide a way to eagerly create rigidbody
1451
+ const childColliderProps = useChildColliderProps(objectRef, mergedOptions);
1551
1452
 
1453
+ // Provide a way to eagerly create rigidbody
1552
1454
  const getRigidBody = useImperativeInstance(() => {
1553
1455
  const desc = rigidBodyDescFromOptions(mergedOptions);
1554
1456
  const rigidBody = world.createRigidBody(desc);
1555
-
1556
1457
  if (typeof forwardedRef === "function") {
1557
1458
  forwardedRef(rigidBody);
1558
1459
  }
1559
-
1560
1460
  rigidBodyRef.current = rigidBody;
1561
1461
  return rigidBody;
1562
1462
  }, rigidBody => {
1563
1463
  if (world.getRigidBody(rigidBody.handle)) {
1564
1464
  world.removeRigidBody(rigidBody);
1565
1465
  }
1566
- }, immutablePropArray); // Only provide a object state after the ref has been set
1466
+ }, immutablePropArray);
1567
1467
 
1468
+ // Only provide a object state after the ref has been set
1568
1469
  React.useEffect(() => {
1569
1470
  const rigidBody = getRigidBody();
1570
1471
  const state = createRigidBodyState({
@@ -1635,51 +1536,46 @@ const MeshCollider = /*#__PURE__*/React.memo(props => {
1635
1536
  MeshCollider.displayName = "MeshCollider";
1636
1537
 
1637
1538
  const _excluded = ["children", "instances", "colliderNodes", "position", "rotation", "quaternion", "scale"];
1638
- const InstancedRigidBodies = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
1539
+ const InstancedRigidBodies = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((props, forwardedRef) => {
1639
1540
  const rigidBodiesRef = useForwardedRef(forwardedRef, []);
1640
1541
  const objectRef = React.useRef(null);
1641
1542
  const instanceWrapperRef = React.useRef(null);
1642
-
1643
1543
  const {
1644
- // instanced props
1645
- children,
1646
- instances,
1647
- colliderNodes = [],
1648
- // wrapper object props
1649
- position,
1650
- rotation,
1651
- quaternion,
1652
- scale
1653
- } = props,
1654
- rigidBodyProps = _objectWithoutProperties(props, _excluded);
1655
-
1544
+ // instanced props
1545
+ children,
1546
+ instances,
1547
+ colliderNodes = [],
1548
+ // wrapper object props
1549
+ position,
1550
+ rotation,
1551
+ quaternion,
1552
+ scale
1553
+
1554
+ // rigid body specific props, and r3f-object props
1555
+ } = props,
1556
+ rigidBodyProps = _objectWithoutProperties(props, _excluded);
1656
1557
  const childColliderProps = useChildColliderProps(objectRef, _objectSpread2(_objectSpread2({}, props), {}, {
1657
1558
  children: undefined
1658
1559
  }));
1659
-
1660
1560
  const getInstancedMesh = () => {
1661
1561
  const firstChild = instanceWrapperRef.current.children[0];
1662
-
1663
1562
  if (firstChild && "isInstancedMesh" in firstChild) {
1664
1563
  return firstChild;
1665
1564
  }
1666
-
1667
1565
  return undefined;
1668
1566
  };
1669
-
1670
1567
  React.useEffect(() => {
1671
1568
  const instancedMesh = getInstancedMesh();
1672
-
1673
1569
  if (instancedMesh) {
1674
1570
  instancedMesh.instanceMatrix.setUsage(three.DynamicDrawUsage);
1675
1571
  } else {
1676
1572
  console.warn("InstancedRigidBodies expects exactly one child, which must be an InstancedMesh");
1677
1573
  }
1678
- }, []); // Update the RigidBodyStates whenever the instances change
1574
+ }, []);
1679
1575
 
1576
+ // Update the RigidBodyStates whenever the instances change
1680
1577
  const applyInstancedState = (state, index) => {
1681
1578
  const instancedMesh = getInstancedMesh();
1682
-
1683
1579
  if (instancedMesh) {
1684
1580
  return _objectSpread2(_objectSpread2({}, state), {}, {
1685
1581
  getMatrix: matrix => {
@@ -1693,10 +1589,8 @@ const InstancedRigidBodies = /*#__PURE__*/React.memo( /*#__PURE__*/React.forward
1693
1589
  meshType: "instancedMesh"
1694
1590
  });
1695
1591
  }
1696
-
1697
1592
  return state;
1698
1593
  };
1699
-
1700
1594
  return /*#__PURE__*/React__default["default"].createElement("object3D", _extends({
1701
1595
  ref: objectRef
1702
1596
  }, rigidBodyProps, {
@@ -1720,7 +1614,6 @@ InstancedRigidBodies.displayName = "InstancedRigidBodies";
1720
1614
  /**
1721
1615
  * @internal
1722
1616
  */
1723
-
1724
1617
  const useImpulseJoint = (body1, body2, params) => {
1725
1618
  const {
1726
1619
  world
@@ -1735,7 +1628,6 @@ const useImpulseJoint = (body1, body2, params) => {
1735
1628
  }, joint => {
1736
1629
  if (joint) {
1737
1630
  jointRef.current = undefined;
1738
-
1739
1631
  if (world.getImpulseJoint(joint.handle)) {
1740
1632
  world.removeImpulseJoint(joint, true);
1741
1633
  }
@@ -1743,6 +1635,7 @@ const useImpulseJoint = (body1, body2, params) => {
1743
1635
  }, []);
1744
1636
  return jointRef;
1745
1637
  };
1638
+
1746
1639
  /**
1747
1640
  * A fixed joint ensures that two rigid-bodies don't move relative to each other.
1748
1641
  * Fixed joints are characterized by one local frame (represented by an isometry) on each rigid-body.
@@ -1750,13 +1643,13 @@ const useImpulseJoint = (body1, body2, params) => {
1750
1643
  *
1751
1644
  * @category Hooks - Joints
1752
1645
  */
1753
-
1754
1646
  const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor, body2LocalFrame]) => {
1755
1647
  const {
1756
1648
  rapier
1757
1649
  } = useRapier();
1758
1650
  return useImpulseJoint(body1, body2, rapier.JointData.fixed(vector3ToRapierVector(body1Anchor), quaternionToRapierQuaternion(body1LocalFrame), vector3ToRapierVector(body2Anchor), quaternionToRapierQuaternion(body2LocalFrame)));
1759
1651
  };
1652
+
1760
1653
  /**
1761
1654
  * The spherical joint ensures that two points on the local-spaces of two rigid-bodies always coincide (it prevents any relative
1762
1655
  * translational motion at this points). This is typically used to simulate ragdolls arms, pendulums, etc.
@@ -1765,13 +1658,13 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
1765
1658
  *
1766
1659
  * @category Hooks - Joints
1767
1660
  */
1768
-
1769
1661
  const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
1770
1662
  const {
1771
1663
  rapier
1772
1664
  } = useRapier();
1773
1665
  return useImpulseJoint(body1, body2, rapier.JointData.spherical(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor)));
1774
1666
  };
1667
+
1775
1668
  /**
1776
1669
  * The revolute joint prevents any relative movement between two rigid-bodies, except for relative
1777
1670
  * rotations along one axis. This is typically used to simulate wheels, fans, etc.
@@ -1779,20 +1672,18 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
1779
1672
  *
1780
1673
  * @category Hooks - Joints
1781
1674
  */
1782
-
1783
1675
  const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]) => {
1784
1676
  const {
1785
1677
  rapier
1786
1678
  } = useRapier();
1787
1679
  const params = rapier.JointData.revolute(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor), vector3ToRapierVector(axis));
1788
-
1789
1680
  if (limits) {
1790
1681
  params.limitsEnabled = true;
1791
1682
  params.limits = limits;
1792
1683
  }
1793
-
1794
1684
  return useImpulseJoint(body1, body2, params);
1795
1685
  };
1686
+
1796
1687
  /**
1797
1688
  * The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
1798
1689
  * It is characterized by one local anchor as well as one local axis on each rigid-body. In 3D, an optional
@@ -1800,25 +1691,22 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]
1800
1691
  *
1801
1692
  * @category Hooks - Joints
1802
1693
  */
1803
-
1804
1694
  const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]) => {
1805
1695
  const {
1806
1696
  rapier
1807
1697
  } = useRapier();
1808
1698
  const params = rapier.JointData.prismatic(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor), vector3ToRapierVector(axis));
1809
-
1810
1699
  if (limits) {
1811
1700
  params.limitsEnabled = true;
1812
1701
  params.limits = limits;
1813
1702
  }
1814
-
1815
1703
  return useImpulseJoint(body1, body2, params);
1816
1704
  };
1705
+
1817
1706
  /**
1818
1707
  * The rope joint limits the max distance between two bodies.
1819
1708
  * @category Hooks - Joints
1820
1709
  */
1821
-
1822
1710
  const useRopeJoint = (body1, body2, [body1Anchor, body2Anchor, length]) => {
1823
1711
  const {
1824
1712
  rapier
@@ -1828,11 +1716,11 @@ const useRopeJoint = (body1, body2, [body1Anchor, body2Anchor, length]) => {
1828
1716
  const params = rapier.JointData.rope(length, vBody1Anchor, vBody2Anchor);
1829
1717
  return useImpulseJoint(body1, body2, params);
1830
1718
  };
1719
+
1831
1720
  /**
1832
1721
  * The spring joint applies a force proportional to the distance between two objects.
1833
1722
  * @category Hooks - Joints
1834
1723
  */
1835
-
1836
1724
  const useSpringJoint = (body1, body2, [body1Anchor, body2Anchor, restLength, stiffness, damping]) => {
1837
1725
  const {
1838
1726
  rapier
@@ -1876,7 +1764,6 @@ const useSpringJoint = (body1, body2, [body1Anchor, body2Anchor, restLength, sti
1876
1764
  * @returns An InteractionGroup bitmask.
1877
1765
  */
1878
1766
  const interactionGroups = (memberships, filters) => (bitmask(memberships) << 16) + (filters !== undefined ? bitmask(filters) : 0b1111111111111111);
1879
-
1880
1767
  const bitmask = groups => [groups].flat().reduce((acc, layer) => acc | 1 << layer, 0);
1881
1768
 
1882
1769
  Object.defineProperty(exports, 'CoefficientCombineRule', {