aboutsummaryrefslogtreecommitdiff
path: root/examples3d/debug_serialized3.rs
diff options
context:
space:
mode:
authorGeoffrey Hayes <hayesgm@gmail.com>2022-02-24 02:41:26 -0800
committerSébastien Crozet <sebastien@crozet.re>2022-03-06 22:46:12 +0100
commit0ef55c7df7160a6178dc52502408c3293b50a503 (patch)
tree4ce92e3fcf9a920cd231370a5b4073fdce9f2a94 /examples3d/debug_serialized3.rs
parent7703333781ccb19e533c25eb53f19a01e51858f7 (diff)
downloadrapier-0ef55c7df7160a6178dc52502408c3293b50a503.tar.gz
rapier-0ef55c7df7160a6178dc52502408c3293b50a503.tar.bz2
rapier-0ef55c7df7160a6178dc52502408c3293b50a503.zip
Start to Load World State
This patch starts to load world state for debugging. The next step is to make sure that deserialization exactly matches the format of world.takeSnapshot().
Diffstat (limited to 'examples3d/debug_serialized3.rs')
-rw-r--r--examples3d/debug_serialized3.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples3d/debug_serialized3.rs b/examples3d/debug_serialized3.rs
new file mode 100644
index 0000000..76766c8
--- /dev/null
+++ b/examples3d/debug_serialized3.rs
@@ -0,0 +1,38 @@
+use rapier3d::prelude::*;
+use rapier_testbed3d::Testbed;
+
+#[derive(serde::Deserialize)]
+struct PhysicsState {
+ pub gravity: Vector<f32>,
+ pub integration_parameters: IntegrationParameters,
+ pub islands: IslandManager,
+ pub broad_phase: BroadPhase,
+ pub narrow_phase: NarrowPhase,
+ pub bodies: RigidBodySet,
+ pub colliders: ColliderSet,
+ pub impulse_joints: ImpulseJointSet,
+ pub multibody_joints: MultibodyJointSet,
+}
+
+pub fn init_world(testbed: &mut Testbed) {
+ /*
+ * Set up the testbed.
+ */
+ let bytes = std::fs::read("state.bin").unwrap();
+ let mut state: PhysicsState = bincode::deserialize(&bytes).unwrap();
+
+ testbed.set_world(
+ state.bodies,
+ state.colliders,
+ state.impulse_joints,
+ state.multibody_joints,
+ );
+ testbed.harness_mut().physics.islands = state.islands;
+ testbed.harness_mut().physics.broad_phase = state.broad_phase;
+ testbed.harness_mut().physics.narrow_phase = state.narrow_phase;
+ testbed.harness_mut().physics.integration_parameters = state.integration_parameters;
+ testbed.harness_mut().physics.gravity = state.gravity;
+
+ testbed.set_graphics_shift(vector![-541.0, -6377257.0, -61.0]);
+ testbed.look_at(point![10.0, 10.0, 10.0], point![0.0, 0.0, 0.0]);
+}