@react-three/rapier 1.2.0 → 1.2.1
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.
@@ -78,7 +78,36 @@ export interface RapierContext {
|
|
78
78
|
*/
|
79
79
|
world: World;
|
80
80
|
/**
|
81
|
-
*
|
81
|
+
* Can be used to overwrite the current World. Useful when working with snapshots.
|
82
|
+
*
|
83
|
+
* @example
|
84
|
+
* ```tsx
|
85
|
+
* import { useRapier } from '@react-three/rapier';
|
86
|
+
*
|
87
|
+
* const SnapshottingComponent = () => {
|
88
|
+
* const { world, setWorld, rapier } = useRapier();
|
89
|
+
* const worldSnapshot = useRef<Uint8Array>();
|
90
|
+
*
|
91
|
+
* // Store the snapshot
|
92
|
+
* const takeSnapshot = () => {
|
93
|
+
* const snapshot = world.takeSnapshot()
|
94
|
+
* worldSnapshot.current = snapshot
|
95
|
+
* }
|
96
|
+
*
|
97
|
+
* // Create a new World from the snapshot, and replace the current one
|
98
|
+
* const restoreSnapshot = () => {
|
99
|
+
* setWorld(rapier.World.restoreSnapshot(worldSnapshot.current))
|
100
|
+
* }
|
101
|
+
*
|
102
|
+
* return <>
|
103
|
+
* <Rigidbody>...</RigidBody>
|
104
|
+
* <Rigidbody>...</RigidBody>
|
105
|
+
* <Rigidbody>...</RigidBody>
|
106
|
+
* <Rigidbody>...</RigidBody>
|
107
|
+
* <Rigidbody>...</RigidBody>
|
108
|
+
* </>
|
109
|
+
* }
|
110
|
+
* ```
|
82
111
|
*/
|
83
112
|
setWorld: (world: World) => void;
|
84
113
|
/**
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -82,6 +82,7 @@ For full API outline and documentation, see 🧩 [API Docs](https://pmndrs.githu
|
|
82
82
|
- [Advanced hooks usage](#advanced-hooks-usage)
|
83
83
|
- [Manual stepping](#manual-stepping)
|
84
84
|
- [On-demand rendering](#on-demand-rendering)
|
85
|
+
- [Snapshots](#snapshots)
|
85
86
|
|
86
87
|
---
|
87
88
|
|
@@ -813,7 +814,7 @@ Setting `<Physics updateLoop="independent" />` will make the physics simulation
|
|
813
814
|
</Canvas>
|
814
815
|
```
|
815
816
|
|
816
|
-
|
817
|
+
## Snapshots
|
817
818
|
The `world` can be serialized as a `Uint8Array` using `world.takeSnapshot()`, see Rapier's docs on [Serialization](https://rapier.rs/docs/user_guides/javascript/serialization/) for more info.
|
818
819
|
|
819
820
|
The snapshot can be used to construct a new world. In `r3/rapier`, you need to replace the world with this snapshot.
|