@react-three/rapier 0.13.1 → 0.13.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.
@@ -1135,12 +1135,17 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((prop
1135
1135
  const getInstance = useImperativeInstance(() => {
1136
1136
  const worldScale = ref.current.getWorldScale(vec3());
1137
1137
  const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
1138
- colliderStates.set(collider.handle, createColliderState(collider, ref.current, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.ref.current));
1139
1138
  return collider;
1140
1139
  }, collider => {
1141
- colliderStates.delete(collider.handle);
1142
1140
  world.removeCollider(collider);
1143
1141
  });
1142
+ React.useEffect(() => {
1143
+ const collider = getInstance();
1144
+ colliderStates.set(collider.handle, createColliderState(collider, ref.current, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.ref.current));
1145
+ return () => {
1146
+ colliderStates.delete(collider.handle);
1147
+ };
1148
+ }, []);
1144
1149
  React.useImperativeHandle(forwardedRef, () => getInstance());
1145
1150
  const mergedProps = React.useMemo(() => {
1146
1151
  return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
@@ -1442,21 +1447,27 @@ const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props,
1442
1447
  children: undefined
1443
1448
  });
1444
1449
  }, [physicsOptions, props]);
1445
- const childColliderProps = useChildColliderProps(ref, mergedOptions); // Create rigidbody
1450
+ const childColliderProps = useChildColliderProps(ref, mergedOptions); // Provide a way to eagerly create rigidbody
1446
1451
 
1447
1452
  const getInstance = useImperativeInstance(() => {
1448
1453
  const desc = rigidBodyDescFromOptions(mergedOptions);
1449
1454
  const rigidBody = world.createRigidBody(desc);
1455
+ return rigidBody;
1456
+ }, rigidBody => {
1457
+ world.removeRigidBody(rigidBody);
1458
+ }); // Only provide a object state after the ref has been set
1459
+
1460
+ React.useEffect(() => {
1461
+ const rigidBody = getInstance();
1450
1462
  const state = createRigidBodyState({
1451
1463
  rigidBody,
1452
1464
  object: ref.current
1453
1465
  });
1454
1466
  rigidBodyStates.set(rigidBody.handle, props.transformState ? props.transformState(state) : state);
1455
- return rigidBody;
1456
- }, rigidBody => {
1457
- world.removeRigidBody(rigidBody);
1458
- rigidBodyStates.delete(rigidBody.handle);
1459
- });
1467
+ return () => {
1468
+ rigidBodyStates.delete(rigidBody.handle);
1469
+ };
1470
+ }, []);
1460
1471
  useUpdateRigidBodyOptions(getInstance, mergedOptions, rigidBodyStates);
1461
1472
  useRigidBodyEvents(getInstance, mergedOptions, rigidBodyEvents);
1462
1473
  React.useImperativeHandle(forwardedRef, () => getInstance());
@@ -1135,12 +1135,17 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((prop
1135
1135
  const getInstance = useImperativeInstance(() => {
1136
1136
  const worldScale = ref.current.getWorldScale(vec3());
1137
1137
  const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
1138
- colliderStates.set(collider.handle, createColliderState(collider, ref.current, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.ref.current));
1139
1138
  return collider;
1140
1139
  }, collider => {
1141
- colliderStates.delete(collider.handle);
1142
1140
  world.removeCollider(collider);
1143
1141
  });
1142
+ React.useEffect(() => {
1143
+ const collider = getInstance();
1144
+ colliderStates.set(collider.handle, createColliderState(collider, ref.current, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.ref.current));
1145
+ return () => {
1146
+ colliderStates.delete(collider.handle);
1147
+ };
1148
+ }, []);
1144
1149
  React.useImperativeHandle(forwardedRef, () => getInstance());
1145
1150
  const mergedProps = React.useMemo(() => {
1146
1151
  return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
@@ -1442,21 +1447,27 @@ const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props,
1442
1447
  children: undefined
1443
1448
  });
1444
1449
  }, [physicsOptions, props]);
1445
- const childColliderProps = useChildColliderProps(ref, mergedOptions); // Create rigidbody
1450
+ const childColliderProps = useChildColliderProps(ref, mergedOptions); // Provide a way to eagerly create rigidbody
1446
1451
 
1447
1452
  const getInstance = useImperativeInstance(() => {
1448
1453
  const desc = rigidBodyDescFromOptions(mergedOptions);
1449
1454
  const rigidBody = world.createRigidBody(desc);
1455
+ return rigidBody;
1456
+ }, rigidBody => {
1457
+ world.removeRigidBody(rigidBody);
1458
+ }); // Only provide a object state after the ref has been set
1459
+
1460
+ React.useEffect(() => {
1461
+ const rigidBody = getInstance();
1450
1462
  const state = createRigidBodyState({
1451
1463
  rigidBody,
1452
1464
  object: ref.current
1453
1465
  });
1454
1466
  rigidBodyStates.set(rigidBody.handle, props.transformState ? props.transformState(state) : state);
1455
- return rigidBody;
1456
- }, rigidBody => {
1457
- world.removeRigidBody(rigidBody);
1458
- rigidBodyStates.delete(rigidBody.handle);
1459
- });
1467
+ return () => {
1468
+ rigidBodyStates.delete(rigidBody.handle);
1469
+ };
1470
+ }, []);
1460
1471
  useUpdateRigidBodyOptions(getInstance, mergedOptions, rigidBodyStates);
1461
1472
  useRigidBodyEvents(getInstance, mergedOptions, rigidBodyEvents);
1462
1473
  React.useImperativeHandle(forwardedRef, () => getInstance());
@@ -1110,12 +1110,17 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwarded
1110
1110
  const getInstance = useImperativeInstance(() => {
1111
1111
  const worldScale = ref.current.getWorldScale(vec3());
1112
1112
  const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
1113
- colliderStates.set(collider.handle, createColliderState(collider, ref.current, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.ref.current));
1114
1113
  return collider;
1115
1114
  }, collider => {
1116
- colliderStates.delete(collider.handle);
1117
1115
  world.removeCollider(collider);
1118
1116
  });
1117
+ useEffect(() => {
1118
+ const collider = getInstance();
1119
+ colliderStates.set(collider.handle, createColliderState(collider, ref.current, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.ref.current));
1120
+ return () => {
1121
+ colliderStates.delete(collider.handle);
1122
+ };
1123
+ }, []);
1119
1124
  useImperativeHandle(forwardedRef, () => getInstance());
1120
1125
  const mergedProps = useMemo(() => {
1121
1126
  return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
@@ -1417,21 +1422,27 @@ const RigidBody = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwardedRe
1417
1422
  children: undefined
1418
1423
  });
1419
1424
  }, [physicsOptions, props]);
1420
- const childColliderProps = useChildColliderProps(ref, mergedOptions); // Create rigidbody
1425
+ const childColliderProps = useChildColliderProps(ref, mergedOptions); // Provide a way to eagerly create rigidbody
1421
1426
 
1422
1427
  const getInstance = useImperativeInstance(() => {
1423
1428
  const desc = rigidBodyDescFromOptions(mergedOptions);
1424
1429
  const rigidBody = world.createRigidBody(desc);
1430
+ return rigidBody;
1431
+ }, rigidBody => {
1432
+ world.removeRigidBody(rigidBody);
1433
+ }); // Only provide a object state after the ref has been set
1434
+
1435
+ useEffect(() => {
1436
+ const rigidBody = getInstance();
1425
1437
  const state = createRigidBodyState({
1426
1438
  rigidBody,
1427
1439
  object: ref.current
1428
1440
  });
1429
1441
  rigidBodyStates.set(rigidBody.handle, props.transformState ? props.transformState(state) : state);
1430
- return rigidBody;
1431
- }, rigidBody => {
1432
- world.removeRigidBody(rigidBody);
1433
- rigidBodyStates.delete(rigidBody.handle);
1434
- });
1442
+ return () => {
1443
+ rigidBodyStates.delete(rigidBody.handle);
1444
+ };
1445
+ }, []);
1435
1446
  useUpdateRigidBodyOptions(getInstance, mergedOptions, rigidBodyStates);
1436
1447
  useRigidBodyEvents(getInstance, mergedOptions, rigidBodyEvents);
1437
1448
  useImperativeHandle(forwardedRef, () => getInstance());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/rapier",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/react-three-rapier.cjs.js",
6
6
  "module": "dist/react-three-rapier.esm.js",
package/readme.md CHANGED
@@ -66,6 +66,7 @@ For full API outline and documentation, see 🧩 [API Docs](https://pmndrs.githu
66
66
  - [Collider Components](#collider-components)
67
67
  - [🖼 Collider Examples](#-collider-examples)
68
68
  - [Instanced Meshes](#instanced-meshes)
69
+ - [Debug](#debug)
69
70
  - [Moving things around, and applying forces](#moving-things-around-and-applying-forces)
70
71
  - [Collision Events](#collision-events)
71
72
  - [Configuring collision and solver groups](#configuring-collision-and-solver-groups)
@@ -255,11 +256,12 @@ const Scene = () => {
255
256
  }
256
257
 
257
258
  // You can access individual instanced by their index
258
- rigidBodies.current.at(40).applyImpulse({ x: 0, y: 10, z: 0 });
259
+ rigidBodies.current[40].applyImpulse({ x: 0, y: 10, z: 0 }, true);
260
+ rigidBodies.at(100).applyImpulse({ x: 0, y: 10, z: 0 }, true);
259
261
 
260
262
  // Or update all instances
261
263
  rigidBodies.current.forEach((api) => {
262
- api.applyImpulse({ x: 0, y: 10, z: 0 });
264
+ api.applyImpulse({ x: 0, y: 10, z: 0 }, true);
263
265
  });
264
266
  }, []);
265
267
 
@@ -328,8 +330,6 @@ const Scene = () => {
328
330
  );
329
331
  };
330
332
  ```
331
- }
332
- ```
333
333
 
334
334
  ## Debug
335
335
 
@@ -589,8 +589,6 @@ To detect when a collider enters or leaves another collider, you can use the `on
589
589
 
590
590
  🧩 See [onIntersectionEnter / onIntersectionExit docs](https://pmndrs.github.io/react-three-rapier/interfaces/RigidBodyProps.html#onIntersectionEnter) for more information.
591
591
 
592
- ```tsx
593
-
594
592
  ```tsx
595
593
  <RigidBody>
596
594
  <GoalPosts />
@@ -674,6 +672,7 @@ There are 4 different joint types available:
674
672
  - Prismatic (two bodies are connected by a sliding joint, for things like pistons or sliders)
675
673
 
676
674
  Each joint hook returns a RefObject containing the raw reference to the joint instance.
675
+
677
676
  ```tsx
678
677
  const WheelJoint = ({bodyA, bodyB}) => {
679
678
  const joint = useRevoluteJoint(bodyA, bodyB, [[0,0,0],[0,0,0],[0,0,0]])
@@ -723,8 +722,6 @@ The spherical joint ensures that two points on the local-spaces of two rigid-bod
723
722
 
724
723
  🧩 See [SphericalJoint docs](https://pmndrs.github.io/react-three-rapier/functions/useSphericalJoint.html) for available options.
725
724
 
726
- ```tsx
727
-
728
725
  ```tsx
729
726
  const JointedThing = () => {
730
727
  const joint = useSphericalJoint(
@@ -788,8 +785,6 @@ The prismatic joint prevents any relative movement between two rigid-bodies, exc
788
785
 
789
786
  🧩 See [PrismaticJoint docs](https://pmndrs.github.io/react-three-rapier/functions/usePrismaticJoint.html) for available options.
790
787
 
791
- ```tsx
792
-
793
788
  ```tsx
794
789
  const JointedThing = () => {
795
790
  const joint = usePrismaticJoint(