From 0ef55c7df7160a6178dc52502408c3293b50a503 Mon Sep 17 00:00:00 2001 From: Geoffrey Hayes Date: Thu, 24 Feb 2022 02:41:26 -0800 Subject: [PATCH] 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(). --- examples3d/Cargo.toml | 2 ++ examples3d/all_examples3.rs | 5 +++++ examples3d/debug_serialized3.rs | 38 ++++++++++++++++++++++++++++++++ state.bin | Bin 0 -> 16369 bytes 4 files changed, 45 insertions(+) create mode 100644 examples3d/debug_serialized3.rs create mode 100644 state.bin diff --git a/examples3d/Cargo.toml b/examples3d/Cargo.toml index bbab27e..c50dc95 100644 --- a/examples3d/Cargo.toml +++ b/examples3d/Cargo.toml @@ -18,6 +18,8 @@ getrandom = { version = "0.2", features = [ "js" ] } Inflector = "0.11" wasm-bindgen = "0.2" obj-rs = { version = "0.6", default-features = false } +serde = "1" +bincode = "1" [dependencies.rapier_testbed3d] path = "../crates/rapier_testbed3d" diff --git a/examples3d/all_examples3.rs b/examples3d/all_examples3.rs index 0aad4c2..2b51a7f 100644 --- a/examples3d/all_examples3.rs +++ b/examples3d/all_examples3.rs @@ -25,6 +25,7 @@ mod debug_friction3; mod debug_infinite_fall3; mod debug_prismatic3; mod debug_rollback3; +mod debug_serialized3; mod debug_shape_modification3; mod debug_triangle3; mod debug_trimesh3; @@ -122,6 +123,10 @@ pub fn main() { "(Debug) shape modification", debug_shape_modification3::init_world, ), + ( + "A serialized", + debug_serialized3::init_world, + ), ]; // Lexicographic sort, with stress tests moved at the end of the list. 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, + 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]); +} diff --git a/state.bin b/state.bin new file mode 100644 index 0000000000000000000000000000000000000000..beb406a27b8aab034c50e780763fc4310aca467b GIT binary patch literal 16369 zcmeHOd2Ccg7=PPxiCh-J3L>km6$L7|6cD>_-v$K_h!RjRMuQp_)QB;H7!&CR42mL$ zC4tt1YQzJOH1U9NwBQvh#o!SGiD13{0gOgPM2YqL=6%1nyY1SUg%T#wN#6e6oB3wm zZ@zDiZ|2SBJE`#Ak@I%qDfV9J6^@gP?QWb9BXsXCSUBeXg8VBxh(H&?5HN`wK@(`E zU?SJHOiL=Dn3*dX%MT(vs*(!zxyU-H0vzY?q|H$-V%qkis}SF`yJ;*glY*s;dgSM_ zaB(?4N5{cEBV>`rm@ST?*=}i-PUXlhpHxaYJZZG+z^JJ#X?HCXcQ-b={@a4zG-=!- zmtHSUy_DnSBAZnS6mX( z)vD1Ue`|!Afvt>_*E)|A*gF@!>5qfoxXeG&iqt(Grhd zKQ6jtRJSN&E(Ie$mxYVV;5T#NG8s7zviyvYEv~J!?DBrk88+_QIPzvk^ca-V$~X|n z$d1TNz4-6EeE8GFD9z6l_NXVfm~+~e%`i^)*+09LbMs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