Files
rapier/examples3d/debug_serialized3.rs
Geoffrey Hayes 0ef55c7df7 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().
2022-03-06 22:46:12 +01:00

39 lines
1.3 KiB
Rust

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]);
}