diff --git a/Cargo.toml b/Cargo.toml index cd1b8bc9..6078f4e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ [profile.dev] # Use slightly better optimization by default, as examples otherwise seem laggy. -opt-level = 1 +#opt-level = 1 [profile.release] codegen-units = 1 @@ -27,3 +27,4 @@ codegen-units = 1 #rapier3d = { git = "https://github.com/dimforge/rapier", branch = "character-controller" } bevy_egui = { git = "https://github.com/Vrixyz/bevy_egui", branch = "bevy_main" } bevy-inspector-egui = { git = "https://github.com/Vrixyz/bevy-inspector-egui", branch = "bevy_0.15" } +bevy_transform_interpolation = { path = "../bevy_transform_interpolation" } diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index 983e9b33..7665feb8 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -69,7 +69,7 @@ bevy-inspector-egui = "0.28.0" bevy_egui = "0.30.0" # bevy_mod_debugdump = "0.11" bevy_mod_debugdump = { git = "https://github.com/andriyDev/bevy_mod_debugdump.git", branch = "bevy-0.15" } -bevy_transform_interpolation = { git = "https://github.com/Jondolf/bevy_transform_interpolation.git" } +bevy_transform_interpolation = "*" # { git = "https://github.com/Jondolf/bevy_transform_interpolation.git" } [package.metadata.docs.rs] # Enable all the features when building the docs on docs.rs diff --git a/bevy_rapier2d/examples/interpolation2.rs b/bevy_rapier2d/examples/interpolation2.rs index 31b2184e..535b6356 100644 --- a/bevy_rapier2d/examples/interpolation2.rs +++ b/bevy_rapier2d/examples/interpolation2.rs @@ -1,9 +1,9 @@ use std::{fs::File, io::Write}; -use bevy::prelude::*; +use bevy::{color::palettes, prelude::*}; use bevy_mod_debugdump::{schedule_graph, schedule_graph_dot}; use bevy_rapier2d::prelude::*; -use bevy_transform_interpolation::{ +use bevy_transform_interpolation::prelude::{ RotationInterpolation, TransformInterpolationPlugin, TranslationInterpolation, }; @@ -19,7 +19,7 @@ fn main() { time_scale: 1f32, substeps: 10, }) - .insert_resource(Time::::from_seconds(0.4)) + .insert_resource(Time::::from_hz(5.0)) .add_plugins(( DefaultPlugins, TransformInterpolationPlugin::default(), @@ -27,6 +27,10 @@ fn main() { RapierDebugRenderPlugin::default(), )) .add_systems(Startup, (setup_graphics, setup_physics)); + app.add_systems( + PostUpdate, + debug_with_transform_info.after(TransformSystem::TransformPropagate), + ); let mut debugdump_settings = schedule_graph::Settings::default(); // Filter out some less relevant systems. debugdump_settings.include_system = @@ -50,6 +54,8 @@ fn main() { app.run(); } +#[derive(Component, Clone)] +pub struct VisualBallDebug; pub fn setup_graphics(mut commands: Commands) { commands.spawn((Camera2d::default(), Transform::from_xyz(0.0, 20.0, 0.0))); @@ -67,24 +73,44 @@ pub fn setup_physics(mut commands: Commands) { Collider::cuboid(ground_size, ground_height), )); - commands.spawn(( - Transform::from_xyz(-40.0, 200.0, 0.0), + let interpolated_ball = ( + Transform::from_xyz(-0.0, 200.0, 0.0), RigidBody::Dynamic, Collider::ball(20.0), Restitution { - coefficient: 1.0, + coefficient: 0.99, combine_rule: CoefficientCombineRule::Max, }, TranslationInterpolation, RotationInterpolation, + VisualBallDebug, + ); + commands.spawn(interpolated_ball.clone()); + commands.spawn(interpolated_ball).insert(( + ColliderDebug::NeverRender, + Transform::from_xyz(-80.0, 200.0, 0.0), )); commands.spawn(( - Transform::from_xyz(40.0, 200.0, 0.0), + Transform::from_xyz(80.0, 200.0, 0.0), RigidBody::Dynamic, Collider::ball(20.0), Restitution { - coefficient: 1.0, + coefficient: 0.99, combine_rule: CoefficientCombineRule::Max, }, + VisualBallDebug, )); } + +pub fn debug_with_transform_info( + mut gizmos: Gizmos, + entities: Query<(&Transform, &Collider), With>, +) { + for (transform, collider) in entities.iter() { + gizmos.circle( + transform.translation, + collider.as_ball().unwrap().radius(), + palettes::basic::RED, + ); + } +} diff --git a/src/render/mod.rs b/src/render/mod.rs index abdd20b4..1d6fc2b6 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -161,6 +161,20 @@ impl<'world, 'state, 'world2, 'state2, 'a, 'b, 'c, 'v, 'p> }; collider_debug == ColliderDebug::AlwaysRender } + DebugRenderObject::RigidBody(h, ..) => { + let Some(collider) = self.context.bodies.get(h) else { + return false; + }; + let entity = Entity::from_bits(collider.user_data as u64); + + let collider_debug = + if let Ok(collider_override) = self.override_visibility.get(entity) { + *collider_override + } else { + self.default_collider_debug + }; + collider_debug == ColliderDebug::AlwaysRender + } _ => true, } }