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().
This commit is contained in:
committed by
Sébastien Crozet
parent
7703333781
commit
0ef55c7df7
@@ -18,6 +18,8 @@ getrandom = { version = "0.2", features = [ "js" ] }
|
|||||||
Inflector = "0.11"
|
Inflector = "0.11"
|
||||||
wasm-bindgen = "0.2"
|
wasm-bindgen = "0.2"
|
||||||
obj-rs = { version = "0.6", default-features = false }
|
obj-rs = { version = "0.6", default-features = false }
|
||||||
|
serde = "1"
|
||||||
|
bincode = "1"
|
||||||
|
|
||||||
[dependencies.rapier_testbed3d]
|
[dependencies.rapier_testbed3d]
|
||||||
path = "../crates/rapier_testbed3d"
|
path = "../crates/rapier_testbed3d"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ mod debug_friction3;
|
|||||||
mod debug_infinite_fall3;
|
mod debug_infinite_fall3;
|
||||||
mod debug_prismatic3;
|
mod debug_prismatic3;
|
||||||
mod debug_rollback3;
|
mod debug_rollback3;
|
||||||
|
mod debug_serialized3;
|
||||||
mod debug_shape_modification3;
|
mod debug_shape_modification3;
|
||||||
mod debug_triangle3;
|
mod debug_triangle3;
|
||||||
mod debug_trimesh3;
|
mod debug_trimesh3;
|
||||||
@@ -122,6 +123,10 @@ pub fn main() {
|
|||||||
"(Debug) shape modification",
|
"(Debug) shape modification",
|
||||||
debug_shape_modification3::init_world,
|
debug_shape_modification3::init_world,
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"A serialized",
|
||||||
|
debug_serialized3::init_world,
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Lexicographic sort, with stress tests moved at the end of the list.
|
// Lexicographic sort, with stress tests moved at the end of the list.
|
||||||
|
|||||||
38
examples3d/debug_serialized3.rs
Normal file
38
examples3d/debug_serialized3.rs
Normal file
@@ -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]);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user