diff options
| author | Sébastien Crozet <developer@crozet.re> | 2023-11-04 18:32:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-04 18:32:55 +0100 |
| commit | e9ea2ca10b3058a6ac2d7f4b79d351ef18ad3c06 (patch) | |
| tree | 8a64ad550e9b99158bdbb26a260e9ab27ffd4be6 /src_testbed/testbed.rs | |
| parent | dbc540d788a3c46d85e07d47e7028d67aab04dbf (diff) | |
| parent | 1886c6f362139d780596baa6a0d6208a2c49212f (diff) | |
| download | rapier-e9ea2ca10b3058a6ac2d7f4b79d351ef18ad3c06.tar.gz rapier-e9ea2ca10b3058a6ac2d7f4b79d351ef18ad3c06.tar.bz2 rapier-e9ea2ca10b3058a6ac2d7f4b79d351ef18ad3c06.zip | |
Merge pull request #540 from johnny-smitherson/bevy-0.11
update bevy 0.11 - fix compile errors
Diffstat (limited to 'src_testbed/testbed.rs')
| -rw-r--r-- | src_testbed/testbed.rs | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index 6a3ab7a..9b08e90 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -3,9 +3,10 @@ use std::mem; use bevy::prelude::*; +use crate::debug_render::{DebugRenderPipelineResource, RapierDebugRenderPlugin}; use crate::physics::{PhysicsEvents, PhysicsSnapshot, PhysicsState}; use crate::plugin::TestbedPlugin; -use crate::{debug_render, ui}; +use crate::ui; use crate::{graphics::GraphicsManager, harness::RunState}; use na::{self, Point2, Point3, Vector3}; @@ -27,9 +28,11 @@ use crate::box2d_backend::Box2dWorld; use crate::harness::Harness; #[cfg(all(feature = "dim3", feature = "other-backends"))] use crate::physx_backend::PhysxWorld; -use bevy::pbr::wireframe::WireframePlugin; use bevy::render::camera::Camera; -use bevy_egui::EguiContext; +use bevy_core_pipeline::prelude::ClearColor; +use bevy_egui::EguiContexts; +use bevy_pbr::wireframe::WireframePlugin; +use bevy_pbr::AmbientLight; #[cfg(feature = "dim2")] use crate::camera2d::{OrbitCamera, OrbitCameraPlugin}; @@ -372,25 +375,25 @@ impl TestbedApp { }; let window_plugin = WindowPlugin { - window: WindowDescriptor { + primary_window: Some(Window { title, ..Default::default() - }, + }), ..Default::default() }; let mut app = App::new(); app.insert_resource(ClearColor(Color::rgb(0.15, 0.15, 0.15))) - .insert_resource(Msaa { samples: 4 }) + .insert_resource(Msaa::Sample4) .insert_resource(AmbientLight { brightness: 0.3, ..Default::default() }) .add_plugins(DefaultPlugins.set(window_plugin)) - .add_plugin(OrbitCameraPlugin) - .add_plugin(WireframePlugin) - .add_plugin(bevy_egui::EguiPlugin) - .add_plugin(debug_render::RapierDebugRenderPlugin::default()); + .add_plugins(OrbitCameraPlugin) + .add_plugins(WireframePlugin) + .add_plugins(RapierDebugRenderPlugin::default()) + .add_plugins(bevy_egui::EguiPlugin); #[cfg(target_arch = "wasm32")] app.add_plugin(bevy_webgl2::WebGL2Plugin); @@ -398,15 +401,14 @@ impl TestbedApp { #[cfg(feature = "other-backends")] app.insert_non_send_resource(self.other_backends); - app.add_startup_system(setup_graphics_environment) + app.add_systems(Startup, setup_graphics_environment) .insert_non_send_resource(self.graphics) .insert_resource(self.state) .insert_non_send_resource(self.harness) .insert_resource(self.builders) .insert_non_send_resource(self.plugins) - .add_stage_before(CoreStage::Update, "physics", SystemStage::single_threaded()) - .add_system_to_stage("physics", update_testbed) - .add_system(egui_focus); + .add_systems(Update, update_testbed) + .add_systems(Update, egui_focus); init(&mut app); app.run(); } @@ -709,10 +711,10 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> { KeyCode::Space => { desired_movement += Vector::y() * 2.0; } - KeyCode::RControl => { + KeyCode::ControlRight => { desired_movement -= Vector::y(); } - KeyCode::RShift => { + KeyCode::ShiftRight => { speed /= 10.0; } _ => {} @@ -750,10 +752,10 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> { KeyCode::Space => { desired_movement += Vector::y() * 2.0; } - KeyCode::RControl => { + KeyCode::ControlRight => { desired_movement -= Vector::y(); } - KeyCode::RShift => { + KeyCode::ShiftLeft => { speed /= 10.0; } _ => {} @@ -998,21 +1000,9 @@ fn draw_contacts(_nf: &NarrowPhase, _colliders: &ColliderSet) { #[cfg(feature = "dim3")] fn setup_graphics_environment(mut commands: Commands) { - const HALF_SIZE: f32 = 100.0; - commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { illuminance: 10000.0, - // Configure the projection to better fit the scene - shadow_projection: OrthographicProjection { - left: -HALF_SIZE, - right: HALF_SIZE, - bottom: -HALF_SIZE, - top: HALF_SIZE, - near: -10.0 * HALF_SIZE, - far: 100.0 * HALF_SIZE, - ..Default::default() - }, shadows_enabled: true, ..Default::default() }, @@ -1073,7 +1063,7 @@ fn setup_graphics_environment(mut commands: Commands) { }); } -fn egui_focus(mut ui_context: ResMut<EguiContext>, mut cameras: Query<&mut OrbitCamera>) { +fn egui_focus(mut ui_context: EguiContexts, mut cameras: Query<&mut OrbitCamera>) { let mut camera_enabled = true; if ui_context.ctx_mut().wants_pointer_input() { camera_enabled = false; @@ -1083,19 +1073,22 @@ fn egui_focus(mut ui_context: ResMut<EguiContext>, mut cameras: Query<&mut Orbit } } +use bevy::window::PrimaryWindow; + fn update_testbed( mut commands: Commands, - windows: Res<Windows>, + windows: Query<&Window, With<PrimaryWindow>>, // mut pipelines: ResMut<Assets<RenderPipelineDescriptor>>, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<BevyMaterial>>, - builders: NonSendMut<SceneBuilders>, + builders: ResMut<SceneBuilders>, mut graphics: NonSendMut<GraphicsManager>, mut state: ResMut<TestbedState>, + mut debug_render: ResMut<DebugRenderPipelineResource>, mut harness: NonSendMut<Harness>, #[cfg(feature = "other-backends")] mut other_backends: NonSendMut<OtherBackends>, mut plugins: NonSendMut<Plugins>, - mut ui_context: ResMut<EguiContext>, + mut ui_context: EguiContexts, mut gfx_components: Query<(&mut Transform,)>, mut cameras: Query<(&Camera, &GlobalTransform, &mut OrbitCamera)>, keys: Res<Input<KeyCode>>, @@ -1136,7 +1129,7 @@ fn update_testbed( // Update UI { let harness = &mut *harness; - ui::update_ui(&mut ui_context, &mut state, harness); + ui::update_ui(&mut ui_context, &mut state, harness, &mut debug_render); for plugin in &mut plugins.0 { plugin.update_ui( @@ -1407,7 +1400,7 @@ fn update_testbed( } } - if let Some(window) = windows.get_primary() { + if let Ok(window) = windows.get_single() { for (camera, camera_pos, _) in cameras.iter_mut() { highlight_hovered_body( &mut *materials, @@ -1419,7 +1412,7 @@ fn update_testbed( camera_pos, ); } - } + }; graphics.draw( &harness.physics.bodies, @@ -1494,7 +1487,10 @@ fn highlight_hovered_body( } if let Some(cursor) = window.cursor_position() { - let ndc_cursor = (cursor / Vec2::new(window.width(), window.height()) * 2.0) - Vec2::ONE; + let ndc_cursor = Vec2::new( + cursor.x / window.width() * 2.0 - 1.0, + 1.0 - cursor.y / window.height() * 2.0, + ); let ndc_to_world = camera_transform.compute_matrix() * camera.projection_matrix().inverse(); let ray_pt1 = ndc_to_world.project_point3(Vec3::new(ndc_cursor.x, ndc_cursor.y, -1.0)); let ray_pt2 = ndc_to_world.project_point3(Vec3::new(ndc_cursor.x, ndc_cursor.y, 1.0)); |
