diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index 6535ff7f..e9b89891 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -66,6 +66,8 @@ rapier2d = { version = "0.21", features = ["serde-serialize"] } serde_json = "1.0" bevy-inspector-egui = "0.25.1" bevy_egui = "0.28.0" +rapier2d = { version = "0.22", features = ["serde-serialize"] } +serde_json = "1.0" [package.metadata.docs.rs] # Enable all the features when building the docs on docs.rs diff --git a/bevy_rapier2d/examples/serialization.rs b/bevy_rapier2d/examples/serialization.rs new file mode 100644 index 00000000..0162c37d --- /dev/null +++ b/bevy_rapier2d/examples/serialization.rs @@ -0,0 +1,36 @@ +//! Example for RapierContext serialization, run with `--features serde-serialize`. + +use bevy::prelude::*; +use bevy_rapier2d::prelude::*; + +/// Note: This will end up in duplication for testbed, but that's more simple. +mod joints2; + +fn main() { + App::new() + .insert_resource(ClearColor(Color::srgb( + 0xF9 as f32 / 255.0, + 0xF9 as f32 / 255.0, + 0xFF as f32 / 255.0, + ))) + .add_plugins(( + DefaultPlugins, + RapierPhysicsPlugin::::pixels_per_meter(100.0), + RapierDebugRenderPlugin::default(), + )) + .add_systems(Startup, (joints2::setup_graphics, joints2::setup_physics)) + .add_systems(PostUpdate, print_physics) + .add_systems(Last, quit) + .run(); +} + +pub fn print_physics(context: Res) { + println!( + "{}", + serde_json::to_string_pretty(&(*context)).expect("Unable to serialize `RapierContext`") + ); +} + +fn quit(mut exit_event: EventWriter) { + exit_event.send(AppExit::Success); +} diff --git a/src/plugin/context.rs b/src/plugin/context.rs index ce8bda56..d4436912 100644 --- a/src/plugin/context.rs +++ b/src/plugin/context.rs @@ -32,6 +32,8 @@ pub struct RapierContext { /// The island manager, which detects what object is sleeping /// (not moving much) to reduce computations. pub islands: IslandManager, + // FIXME: This shoulnd not be skipped. + #[cfg_attr(feature = "serde-serialize", serde(skip))] /// The broad-phase, which detects potential contact pairs. pub broad_phase: DefaultBroadPhase, /// The narrow-phase, which computes contact points, tests intersections,