From 780ba4a216aa9ef68d7f10db4a2b67b866699f43 Mon Sep 17 00:00:00 2001 From: johnny-smitherson <127537716+johnny-smitherson@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:21:07 +0000 Subject: update bevy 0.11 - fix compile errors --- src_testbed/camera2d.rs | 6 ++-- src_testbed/camera3d.rs | 6 ++-- src_testbed/debug_render.rs | 5 ++- src_testbed/graphics.rs | 2 ++ src_testbed/lines/mod.rs | 32 +++++++++++------- src_testbed/lines/render_dim.rs | 37 +++++++++++---------- src_testbed/objects/node.rs | 13 +++++--- src_testbed/plugin.rs | 4 +-- src_testbed/testbed.rs | 73 ++++++++++++++++++++++++----------------- src_testbed/ui.rs | 4 +-- 10 files changed, 105 insertions(+), 77 deletions(-) (limited to 'src_testbed') diff --git a/src_testbed/camera2d.rs b/src_testbed/camera2d.rs index ddac1ed..2f4de67 100644 --- a/src_testbed/camera2d.rs +++ b/src_testbed/camera2d.rs @@ -87,8 +87,8 @@ impl OrbitCameraPlugin { } impl Plugin for OrbitCameraPlugin { fn build(&self, app: &mut App) { - app.add_system(Self::mouse_motion_system) - .add_system(Self::zoom_system) - .add_system(Self::update_transform_system); + app.add_systems(Update, Self::mouse_motion_system) + .add_systems(Update, Self::zoom_system) + .add_systems(Update, Self::update_transform_system); } } diff --git a/src_testbed/camera3d.rs b/src_testbed/camera3d.rs index 12ee508..7621c50 100644 --- a/src_testbed/camera3d.rs +++ b/src_testbed/camera3d.rs @@ -113,8 +113,8 @@ impl OrbitCameraPlugin { } impl Plugin for OrbitCameraPlugin { fn build(&self, app: &mut App) { - app.add_system(Self::mouse_motion_system) - .add_system(Self::zoom_system) - .add_system(Self::update_transform_system); + app.add_systems(Update, Self::mouse_motion_system) + .add_systems(Update, Self::zoom_system) + .add_systems(Update, Self::update_transform_system); } } diff --git a/src_testbed/debug_render.rs b/src_testbed/debug_render.rs index 928b8ba..979d8ec 100644 --- a/src_testbed/debug_render.rs +++ b/src_testbed/debug_render.rs @@ -20,17 +20,16 @@ impl Default for RapierDebugRenderPlugin { } } } - impl Plugin for RapierDebugRenderPlugin { fn build(&self, app: &mut App) { - app.add_plugin(crate::lines::DebugLinesPlugin::with_depth_test( + app.add_plugins(crate::lines::DebugLinesPlugin::with_depth_test( self.depth_test, )) .insert_resource(DebugRenderPipelineResource(DebugRenderPipeline::new( Default::default(), !DebugRenderMode::RIGID_BODY_AXES & !DebugRenderMode::COLLIDER_AABBS, ))) - .add_system_to_stage(CoreStage::Update, debug_render_scene); + .add_systems(Update, debug_render_scene); } } diff --git a/src_testbed/graphics.rs b/src_testbed/graphics.rs index 847258d..7c356c8 100644 --- a/src_testbed/graphics.rs +++ b/src_testbed/graphics.rs @@ -13,6 +13,8 @@ use rapier::math::{Isometry, Real, Vector}; //#[cfg(feature = "dim2")] //use crate::objects::polyline::Polyline; // use crate::objects::mesh::Mesh; +use bevy_pbr::StandardMaterial; +use bevy_sprite::ColorMaterial; use rand::{Rng, SeedableRng}; use rand_pcg::Pcg32; use std::collections::HashMap; diff --git a/src_testbed/lines/mod.rs b/src_testbed/lines/mod.rs index 60d8098..c68b86e 100644 --- a/src_testbed/lines/mod.rs +++ b/src_testbed/lines/mod.rs @@ -19,7 +19,6 @@ use bevy::render::MainWorld; */ use bevy::{ asset::{Assets, HandleUntyped}, - pbr::{NotShadowCaster, NotShadowReceiver}, prelude::*, reflect::TypeUuid, render::{ @@ -27,8 +26,10 @@ use bevy::{ render_phase::AddRenderCommand, render_resource::PrimitiveTopology, render_resource::Shader, + RenderSet, }, }; +use bevy_pbr::{NotShadowCaster, NotShadowReceiver}; mod render_dim; @@ -38,8 +39,8 @@ mod render_dim; #[cfg(feature = "dim3")] mod dim { pub(crate) use super::render_dim::r3d::{queue, DebugLinePipeline, DrawDebugLines}; - pub(crate) use bevy::core_pipeline::core_3d::Opaque3d as Phase; use bevy::{asset::Handle, render::mesh::Mesh}; + pub(crate) use bevy_core_pipeline::core_3d::Opaque3d as Phase; pub(crate) type MeshHandle = Handle; pub(crate) fn from_handle(from: &MeshHandle) -> &Handle { @@ -54,8 +55,9 @@ mod dim { #[cfg(feature = "dim2")] mod dim { pub(crate) use super::render_dim::r2d::{queue, DebugLinePipeline, DrawDebugLines}; - pub(crate) use bevy::core_pipeline::core_2d::Transparent2d as Phase; - use bevy::{asset::Handle, render::mesh::Mesh, sprite::Mesh2dHandle}; + use bevy::{asset::Handle, render::mesh::Mesh}; + pub(crate) use bevy_core_pipeline::core_2d::Transparent2d as Phase; + use bevy_sprite::Mesh2dHandle; pub(crate) type MeshHandle = Mesh2dHandle; pub(crate) fn from_handle(from: &MeshHandle) -> &Handle { @@ -120,27 +122,33 @@ impl DebugLinesPlugin { Self { depth_test: val } } } - +use bevy::render::render_phase::DrawFunctions; +use bevy::render::Render; impl Plugin for DebugLinesPlugin { fn build(&self, app: &mut App) { - use bevy::render::{render_resource::SpecializedMeshPipelines, RenderApp, RenderStage}; + use bevy::render::{render_resource::SpecializedMeshPipelines, RenderApp}; let mut shaders = app.world.get_resource_mut::>().unwrap(); shaders.set_untracked( DEBUG_LINES_SHADER_HANDLE, - Shader::from_wgsl(dim::SHADER_FILE), + Shader::from_wgsl(dim::SHADER_FILE, file!()), ); app.init_resource::(); - app.add_startup_system(setup) - .add_system_to_stage(CoreStage::PostUpdate, update.label("draw_lines")); + + app.init_resource::>(); + + app.add_systems(Startup, setup) + .add_systems(PostUpdate, update); + app.sub_app_mut(RenderApp) + .init_resource::>() .add_render_command::() .insert_resource(DebugLinesConfig { depth_test: self.depth_test, }) .init_resource::() .init_resource::>() - .add_system_to_stage(RenderStage::Extract, extract) - .add_system_to_stage(RenderStage::Queue, dim::queue); + .add_systems(Render, extract.in_set(RenderSet::ExtractCommands)) + .add_systems(Render, dim::queue.in_set(RenderSet::Queue)); info!("Loaded {} debug lines plugin.", dim::DIMMENSION); } @@ -176,7 +184,7 @@ fn setup(mut cmds: Commands, mut meshes: ResMut>) { // https://github.com/Toqozz/bevy_debug_lines/issues/16 //mesh.set_indices(Some(Indices::U16(Vec::with_capacity(MAX_POINTS_PER_MESH)))); - cmds.spawn_bundle(( + cmds.spawn(( dim::into_handle(meshes.add(mesh)), NotShadowCaster, NotShadowReceiver, diff --git a/src_testbed/lines/render_dim.rs b/src_testbed/lines/render_dim.rs index 718cce0..f339cdb 100644 --- a/src_testbed/lines/render_dim.rs +++ b/src_testbed/lines/render_dim.rs @@ -1,10 +1,11 @@ pub mod r3d { + use bevy_core_pipeline::core_3d::Opaque3d; + use bevy_pbr::{ + DrawMesh, MeshPipeline, MeshPipelineKey, MeshUniform, SetMeshBindGroup, + SetMeshViewBindGroup, + }; + use bevy::{ - core_pipeline::core_3d::Opaque3d, - pbr::{ - DrawMesh, MeshPipeline, MeshPipelineKey, MeshUniform, SetMeshBindGroup, - SetMeshViewBindGroup, - }, prelude::*, render::{ mesh::MeshVertexBufferLayout, @@ -54,9 +55,9 @@ pub mod r3d { //use VertexFormat::{Float32x3, Float32x4}; let mut shader_defs = Vec::new(); - shader_defs.push("LINES_3D".to_string()); + shader_defs.push("LINES_3D".to_string().into()); if depth_test { - shader_defs.push("DEPTH_TEST_ENABLED".to_string()); + shader_defs.push("DEPTH_TEST_ENABLED".to_string().into()); } let vertex_buffer_layout = layout.get_layout(&[ @@ -64,7 +65,7 @@ pub mod r3d { Mesh::ATTRIBUTE_COLOR.at_shader_location(1), ])?; let (label, blend, depth_write_enabled); - if key.contains(MeshPipelineKey::TRANSPARENT_MAIN_PASS) { + if key.contains(MeshPipelineKey::BLEND_ALPHA) { label = "transparent_mesh_pipeline".into(); blend = Some(BlendState::ALPHA_BLENDING); // For the transparent pass, fragments that are closer will be alpha @@ -96,7 +97,7 @@ pub mod r3d { write_mask: ColorWrites::ALL, })], }), - layout: Some(vec![self.mesh_pipeline.view_layout.clone()]), + layout: vec![self.mesh_pipeline.view_layout.clone()], primitive: PrimitiveState { front_face: FrontFace::Ccw, cull_mode: None, @@ -128,6 +129,7 @@ pub mod r3d { alpha_to_coverage_enabled: false, }, label: Some(label), + push_constant_ranges: vec![], }) } } @@ -147,7 +149,7 @@ pub mod r3d { .read() .get_id::() .unwrap(); - let key = MeshPipelineKey::from_msaa_samples(msaa.samples); + let key = MeshPipelineKey::from_msaa_samples(msaa.samples()); for (view, mut transparent_phase) in views.iter_mut() { let view_matrix = view.transform.compute_matrix(); let view_row_2 = view_matrix.row(2); @@ -183,7 +185,6 @@ pub mod r3d { pub mod r2d { use bevy::{ asset::Handle, - core_pipeline::core_2d::Transparent2d, prelude::*, render::{ mesh::MeshVertexBufferLayout, @@ -200,12 +201,13 @@ pub mod r2d { texture::BevyDefault, view::{Msaa, VisibleEntities}, }, - sprite::{ - DrawMesh2d, Mesh2dHandle, Mesh2dPipeline, Mesh2dPipelineKey, Mesh2dUniform, - SetMesh2dBindGroup, SetMesh2dViewBindGroup, - }, utils::FloatOrd, }; + use bevy_core_pipeline::core_2d::Transparent2d; + use bevy_sprite::{ + DrawMesh2d, Mesh2dHandle, Mesh2dPipeline, Mesh2dPipelineKey, Mesh2dUniform, + SetMesh2dBindGroup, SetMesh2dViewBindGroup, + }; use crate::lines::{RenderDebugLinesMesh, DEBUG_LINES_SHADER_HANDLE}; @@ -264,7 +266,7 @@ pub mod r2d { write_mask: ColorWrites::ALL, })], }), - layout: Some(vec![self.mesh_pipeline.view_layout.clone()]), + layout: vec![self.mesh_pipeline.view_layout.clone()], primitive: PrimitiveState { front_face: FrontFace::Ccw, cull_mode: None, @@ -281,6 +283,7 @@ pub mod r2d { alpha_to_coverage_enabled: false, }, label: None, + push_constant_ranges: vec![], }) } } @@ -297,7 +300,7 @@ pub mod r2d { ) { for (view, mut phase) in views.iter_mut() { let draw_mesh2d = draw2d_functions.read().get_id::().unwrap(); - let msaa_key = Mesh2dPipelineKey::from_msaa_samples(msaa.samples); + let msaa_key = Mesh2dPipelineKey::from_msaa_samples(msaa.samples()); for visible_entity in &view.entities { if let Ok((uniform, mesh_handle)) = material_meshes.get(*visible_entity) { diff --git a/src_testbed/objects/node.rs b/src_testbed/objects/node.rs index f4b9015..3214a0f 100644 --- a/src_testbed/objects/node.rs +++ b/src_testbed/objects/node.rs @@ -5,9 +5,13 @@ use bevy::render::mesh::{Indices, VertexAttributeValues}; use na::{point, Point3, Vector3}; use std::collections::HashMap; -use bevy::pbr::wireframe::Wireframe; use bevy::render::render_resource::PrimitiveTopology; +use bevy_pbr::wireframe::Wireframe; +use bevy_pbr::PbrBundle; +use bevy_pbr::StandardMaterial; +use bevy_sprite::ColorMaterial; use rapier::geometry::{ColliderHandle, ColliderSet, Shape, ShapeType}; + #[cfg(feature = "dim3")] use rapier::geometry::{Cone, Cylinder}; use rapier::math::{Isometry, Real, Vector}; @@ -15,7 +19,7 @@ use rapier::math::{Isometry, Real, Vector}; use crate::graphics::BevyMaterial; #[cfg(feature = "dim2")] use { - bevy::sprite::MaterialMesh2dBundle, + bevy_sprite::MaterialMesh2dBundle, na::{Point2, Vector2}, rapier::geometry::{Ball, Cuboid}, }; @@ -235,10 +239,11 @@ impl EntityWithGraphics { // // Ball mesh // - let ball = Mesh::from(shape::Icosphere { + let ball = Mesh::try_from(shape::Icosphere { subdivisions: 2, radius: 1.0, - }); + }) + .unwrap(); out.insert(ShapeType::Ball, meshes.add(ball)); // diff --git a/src_testbed/plugin.rs b/src_testbed/plugin.rs index 6eaf09e..7f19aa9 100644 --- a/src_testbed/plugin.rs +++ b/src_testbed/plugin.rs @@ -4,7 +4,7 @@ use crate::physics::PhysicsState; use crate::GraphicsManager; use bevy::prelude::*; // use bevy::render::render_resource::RenderPipelineDescriptor; -use bevy_egui::EguiContext; +use bevy_egui::EguiContexts; pub trait TestbedPlugin { fn init_plugin(&mut self); @@ -31,7 +31,7 @@ pub trait TestbedPlugin { ); fn update_ui( &mut self, - ui_context: &EguiContext, + ui_context: &EguiContexts, harness: &mut Harness, graphics: &mut GraphicsManager, commands: &mut Commands, diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index 6a3ab7a..9ddec5f 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -27,9 +27,15 @@ 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::Camera2dBundle; +use bevy_core_pipeline::prelude::Camera3dBundle; +use bevy_core_pipeline::prelude::ClearColor; +use bevy_egui::EguiContexts; +use bevy_pbr::wireframe::WireframePlugin; +use bevy_pbr::AmbientLight; +use bevy_pbr::DirectionalLight; +use bevy_pbr::DirectionalLightBundle; #[cfg(feature = "dim2")] use crate::camera2d::{OrbitCamera, OrbitCameraPlugin}; @@ -372,25 +378,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(bevy_egui::EguiPlugin); + // .add_plugins(debug_render::RapierDebugRenderPlugin::default()); #[cfg(target_arch = "wasm32")] app.add_plugin(bevy_webgl2::WebGL2Plugin); @@ -398,15 +404,16 @@ 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_stage_before(CoreStage::Update, "physics", SystemStage::single_threaded()) + // .add_system_to_stage("physics", update_testbed) + .add_systems(PreUpdate, update_testbed) + .add_systems(Update, egui_focus); init(&mut app); app.run(); } @@ -709,10 +716,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 +757,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; } _ => {} @@ -1004,15 +1011,17 @@ fn setup_graphics_environment(mut commands: Commands) { 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() - }, + // shadow_projection: OrthographicProjection { + // area: Rect::new( + // -HALF_SIZE, + // HALF_SIZE, + // -HALF_SIZE, + // HALF_SIZE, + // ), + // near: -10.0 * HALF_SIZE, + // far: 100.0 * HALF_SIZE, + // ..Default::default() + // }, shadows_enabled: true, ..Default::default() }, @@ -1073,7 +1082,7 @@ fn setup_graphics_environment(mut commands: Commands) { }); } -fn egui_focus(mut ui_context: ResMut, 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,9 +1092,11 @@ fn egui_focus(mut ui_context: ResMut, mut cameras: Query<&mut Orbit } } +use bevy::window::PrimaryWindow; + fn update_testbed( mut commands: Commands, - windows: Res, + windows: Query<&Window, With>, // mut pipelines: ResMut>, mut meshes: ResMut>, mut materials: ResMut>, @@ -1095,7 +1106,7 @@ fn update_testbed( mut harness: NonSendMut, #[cfg(feature = "other-backends")] mut other_backends: NonSendMut, mut plugins: NonSendMut, - mut ui_context: ResMut, + mut ui_context: EguiContexts, mut gfx_components: Query<(&mut Transform,)>, mut cameras: Query<(&Camera, &GlobalTransform, &mut OrbitCamera)>, keys: Res>, @@ -1407,7 +1418,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 +1430,7 @@ fn update_testbed( camera_pos, ); } - } + }; graphics.draw( &harness.physics.bodies, diff --git a/src_testbed/ui.rs b/src_testbed/ui.rs index 9829b28..3983934 100644 --- a/src_testbed/ui.rs +++ b/src_testbed/ui.rs @@ -9,9 +9,9 @@ use crate::testbed::{ use crate::PhysicsState; use bevy_egui::egui::Slider; -use bevy_egui::{egui, EguiContext}; +use bevy_egui::{egui, EguiContexts}; -pub fn update_ui(ui_context: &mut EguiContext, state: &mut TestbedState, harness: &mut Harness) { +pub fn update_ui(ui_context: &mut EguiContexts, state: &mut TestbedState, harness: &mut Harness) { egui::Window::new("Parameters").show(ui_context.ctx_mut(), |ui| { if state.backend_names.len() > 1 && !state.example_names.is_empty() { let mut changed = false; -- cgit From 23a7ed5beba12161d67184cdf7e63caa86be45eb Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 29 Oct 2023 18:59:47 +0100 Subject: Fix crashes on MacOS --- src_testbed/debug_render.rs | 19 +- src_testbed/lib.rs | 2 +- src_testbed/lines/debuglines.wgsl | 53 ----- src_testbed/lines/debuglines2d.wgsl | 32 --- src_testbed/lines/mod.rs | 389 ------------------------------------ src_testbed/lines/render_dim.rs | 340 ------------------------------- src_testbed/testbed.rs | 6 +- 7 files changed, 11 insertions(+), 830 deletions(-) delete mode 100644 src_testbed/lines/debuglines.wgsl delete mode 100644 src_testbed/lines/debuglines2d.wgsl delete mode 100644 src_testbed/lines/mod.rs delete mode 100644 src_testbed/lines/render_dim.rs (limited to 'src_testbed') diff --git a/src_testbed/debug_render.rs b/src_testbed/debug_render.rs index 979d8ec..8e588db 100644 --- a/src_testbed/debug_render.rs +++ b/src_testbed/debug_render.rs @@ -1,5 +1,5 @@ use crate::harness::Harness; -use crate::lines::DebugLines; +use bevy::gizmos::gizmos::Gizmos; use bevy::prelude::*; use rapier::math::{Point, Real}; use rapier::pipeline::{ @@ -22,10 +22,7 @@ impl Default for RapierDebugRenderPlugin { } impl Plugin for RapierDebugRenderPlugin { fn build(&self, app: &mut App) { - app.add_plugins(crate::lines::DebugLinesPlugin::with_depth_test( - self.depth_test, - )) - .insert_resource(DebugRenderPipelineResource(DebugRenderPipeline::new( + app.insert_resource(DebugRenderPipelineResource(DebugRenderPipeline::new( Default::default(), !DebugRenderMode::RIGID_BODY_AXES & !DebugRenderMode::COLLIDER_AABBS, ))) @@ -34,25 +31,23 @@ impl Plugin for RapierDebugRenderPlugin { } struct BevyLinesRenderBackend<'a> { - lines: &'a mut DebugLines, + gizmos: Gizmos<'a>, } impl<'a> DebugRenderBackend for BevyLinesRenderBackend<'a> { #[cfg(feature = "dim2")] fn draw_line(&mut self, _: DebugRenderObject, a: Point, b: Point, color: [f32; 4]) { - self.lines.line_colored( + self.gizmos.line( [a.x as f32, a.y as f32, 1.0e-8 as f32].into(), [b.x as f32, b.y as f32, 1.0e-8 as f32].into(), - 0.0, Color::hsla(color[0], color[1], color[2], color[3]), ) } #[cfg(feature = "dim3")] fn draw_line(&mut self, _: DebugRenderObject, a: Point, b: Point, color: [f32; 4]) { - self.lines.line_colored( + self.gizmos.line( [a.x as f32, a.y as f32, a.z as f32].into(), [b.x as f32, b.y as f32, b.z as f32].into(), - 0.0, Color::hsla(color[0], color[1], color[2], color[3]), ) } @@ -61,9 +56,9 @@ impl<'a> DebugRenderBackend for BevyLinesRenderBackend<'a> { fn debug_render_scene( mut pipeline: ResMut, harness: NonSend, - mut lines: ResMut, + gizmos: Gizmos, ) { - let mut backend = BevyLinesRenderBackend { lines: &mut *lines }; + let mut backend = BevyLinesRenderBackend { gizmos }; pipeline.0.render( &mut backend, &harness.physics.bodies, diff --git a/src_testbed/lib.rs b/src_testbed/lib.rs index 3c87453..3702866 100644 --- a/src_testbed/lib.rs +++ b/src_testbed/lib.rs @@ -22,7 +22,7 @@ mod camera3d; mod debug_render; mod graphics; pub mod harness; -mod lines; +// mod lines; pub mod objects; pub mod physics; #[cfg(all(feature = "dim3", feature = "other-backends"))] diff --git a/src_testbed/lines/debuglines.wgsl b/src_testbed/lines/debuglines.wgsl deleted file mode 100644 index 364d9ac..0000000 --- a/src_testbed/lines/debuglines.wgsl +++ /dev/null @@ -1,53 +0,0 @@ -// This should work, but it's bugged right now so we have to use 2 shaders: https://github.com/bevyengine/bevy/issues/4011 -#ifdef LINES_3D - #import bevy_pbr::mesh_view_bind_group - //#import bevy_pbr::mesh_struct -#else - //#import bevy_sprite::mesh2d_view_bind_group -#endif - -struct Vertex { - [[location(0)]] pos: vec3; - [[location(1)]] color: u32; -}; - -struct VertexOutput { - [[builtin(position)]] clip_position: vec4; - [[location(0)]] color: vec4; -}; - -struct FragmentOutput { - [[builtin(frag_depth)]] depth: f32; - [[location(0)]] color: vec4; -}; - -[[stage(vertex)]] -fn vertex(vertex: Vertex) -> VertexOutput { - var out: VertexOutput; - out.clip_position = view.view_proj * vec4(vertex.pos, 1.0); - // https://github.com/bevyengine/bevy/blob/328c26d02c50de0bc77f0d24a376f43ba89517b1/examples/2d/mesh2d_manual.rs#L234 - // ... except the above doesn't seem to work in 3d. Not sure what's going on there. - var r = f32(vertex.color & 255u) / 255.0; - var g = f32(vertex.color >> 8u & 255u) / 255.0; - var b = f32(vertex.color >> 16u & 255u) / 255.0; - var a = f32(vertex.color >> 24u & 255u) / 255.0; - out.color = vec4(r, g, b, a); - - return out; -} - -[[stage(fragment)]] -fn fragment(in: VertexOutput) -> FragmentOutput { - var out: FragmentOutput; - -// This should be #ifdef DEPTH_TEST_ENABLED && LINES_3D, but the -// preprocessor doesn't support that yet. -// Luckily, DEPTH_TEST_ENABLED isn't set in 2d anyway. -#ifdef DEPTH_TEST_ENABLED - out.depth = in.clip_position.z; -#else - out.depth = 1.0; -#endif - out.color = in.color; - return out; -} diff --git a/src_testbed/lines/debuglines2d.wgsl b/src_testbed/lines/debuglines2d.wgsl deleted file mode 100644 index b722d8a..0000000 --- a/src_testbed/lines/debuglines2d.wgsl +++ /dev/null @@ -1,32 +0,0 @@ -#import bevy_sprite::mesh2d_view_bind_group -[[group(0), binding(0)]] -var view: View; - -struct Vertex { - //[[location(0)]] color: vec4; - [[location(0)]] place: vec3; - [[location(1)]] color: u32; -}; - -struct VertexOutput { - [[builtin(position)]] clip_position: vec4; - [[location(0)]] color: vec4; -}; - -[[stage(vertex)]] -fn vertex(vertex: Vertex) -> VertexOutput { - var out: VertexOutput; - out.clip_position = view.view_proj * vec4(vertex.place, 1.0); - var r = f32(vertex.color & 255u) / 255.0; - var g = f32(vertex.color >> 8u & 255u) / 255.0; - var b = f32(vertex.color >> 16u & 255u) / 255.0; - var a = f32(vertex.color >> 24u & 255u) / 255.0; - out.color = vec4(r, g, b, a); - - return out; -} - -[[stage(fragment)]] -fn fragment(in: VertexOutput) -> [[location(0)]] vec4 { - return in.color; -} diff --git a/src_testbed/lines/mod.rs b/src_testbed/lines/mod.rs deleted file mode 100644 index c68b86e..0000000 --- a/src_testbed/lines/mod.rs +++ /dev/null @@ -1,389 +0,0 @@ -#![allow(warnings)] -use bevy::render::mesh::MeshVertexAttribute; -use bevy::render::render_resource::VertexFormat; -use bevy::render::view::NoFrustumCulling; -use bevy::render::MainWorld; -/** - * - * NOTE: this module and its submodules are only temporary. It is a copy-paste of the bevy-debug-lines - * crate: https://github.com/Toqozz/bevy_debug_lines (MIT license) - * It has been partially updated to work with bevy 0.7, but hasn’t been released yet. - * So, in the mean time, we are keeping a version here that we will replace by the - * upstream dependency once: - * 1. The version compatible with bevy 0.7 is released to crates.io. - * 2. We find a way to make the 2D version work with our examples. The problem - * only happens when running our own examples because cargo’s unification of - * features will enable the `3d` feature of `bevy_debug_lines` when running - * a `2d` example. - * - */ -use bevy::{ - asset::{Assets, HandleUntyped}, - prelude::*, - reflect::TypeUuid, - render::{ - mesh::{/*Indices,*/ Mesh, VertexAttributeValues}, - render_phase::AddRenderCommand, - render_resource::PrimitiveTopology, - render_resource::Shader, - RenderSet, - }, -}; -use bevy_pbr::{NotShadowCaster, NotShadowReceiver}; - -mod render_dim; - -// This module exists to "isolate" the `#[cfg]` attributes to this part of the -// code. Otherwise, we would pollute the code with a lot of feature -// gates-specific code. -#[cfg(feature = "dim3")] -mod dim { - pub(crate) use super::render_dim::r3d::{queue, DebugLinePipeline, DrawDebugLines}; - use bevy::{asset::Handle, render::mesh::Mesh}; - pub(crate) use bevy_core_pipeline::core_3d::Opaque3d as Phase; - - pub(crate) type MeshHandle = Handle; - pub(crate) fn from_handle(from: &MeshHandle) -> &Handle { - from - } - pub(crate) fn into_handle(from: Handle) -> MeshHandle { - from - } - pub(crate) const SHADER_FILE: &str = include_str!("debuglines.wgsl"); - pub(crate) const DIMMENSION: &str = "3d"; -} -#[cfg(feature = "dim2")] -mod dim { - pub(crate) use super::render_dim::r2d::{queue, DebugLinePipeline, DrawDebugLines}; - use bevy::{asset::Handle, render::mesh::Mesh}; - pub(crate) use bevy_core_pipeline::core_2d::Transparent2d as Phase; - use bevy_sprite::Mesh2dHandle; - - pub(crate) type MeshHandle = Mesh2dHandle; - pub(crate) fn from_handle(from: &MeshHandle) -> &Handle { - &from.0 - } - pub(crate) fn into_handle(from: Handle) -> MeshHandle { - Mesh2dHandle(from) - } - pub(crate) const SHADER_FILE: &str = include_str!("debuglines2d.wgsl"); - pub(crate) const DIMMENSION: &str = "2d"; -} - -// See debuglines.wgsl for explanation on 2 shaders. -//pub(crate) const SHADER_FILE: &str = include_str!("debuglines.wgsl"); -pub(crate) const DEBUG_LINES_SHADER_HANDLE: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 17477439189930443325); - -#[derive(Resource)] -pub(crate) struct DebugLinesConfig { - depth_test: bool, -} - -/// Bevy plugin, for initializing stuff. -/// -/// # Usage -/// -/// ```.ignore -/// use bevy::prelude::*; -/// use bevy_prototype_debug_lines::*; -/// -/// App::new() -/// .add_plugins(DefaultPlugins) -/// .add_plugin(DebugLinesPlugin::default()) -/// .run(); -/// ``` -/// -/// Alternatively, you can initialize the plugin with depth testing, so that -/// debug lines cut through geometry. To do this, use [`DebugLinesPlugin::with_depth_test(true)`]. -/// ```.ignore -/// use bevy::prelude::*; -/// use bevy_prototype_debug_lines::*; -/// -/// App::new() -/// .add_plugins(DefaultPlugins) -/// .add_plugin(DebugLinesPlugin::with_depth_test(true)) -/// .run(); -/// ``` -#[derive(Debug, Default, Clone)] -pub struct DebugLinesPlugin { - depth_test: bool, -} - -impl DebugLinesPlugin { - /// Controls whether debug lines should be drawn with depth testing enabled - /// or disabled. - /// - /// # Arguments - /// - /// * `val` - True if lines should intersect with other geometry, or false - /// if lines should always draw on top be drawn on top (the default). - pub fn with_depth_test(val: bool) -> Self { - Self { depth_test: val } - } -} -use bevy::render::render_phase::DrawFunctions; -use bevy::render::Render; -impl Plugin for DebugLinesPlugin { - fn build(&self, app: &mut App) { - use bevy::render::{render_resource::SpecializedMeshPipelines, RenderApp}; - let mut shaders = app.world.get_resource_mut::>().unwrap(); - shaders.set_untracked( - DEBUG_LINES_SHADER_HANDLE, - Shader::from_wgsl(dim::SHADER_FILE, file!()), - ); - app.init_resource::(); - - app.init_resource::>(); - - app.add_systems(Startup, setup) - .add_systems(PostUpdate, update); - - app.sub_app_mut(RenderApp) - .init_resource::>() - .add_render_command::() - .insert_resource(DebugLinesConfig { - depth_test: self.depth_test, - }) - .init_resource::() - .init_resource::>() - .add_systems(Render, extract.in_set(RenderSet::ExtractCommands)) - .add_systems(Render, dim::queue.in_set(RenderSet::Queue)); - - info!("Loaded {} debug lines plugin.", dim::DIMMENSION); - } -} - -// Number of meshes to separate line buffers into. -// We don't really do culling currently but this is a gateway to that. -const MESH_COUNT: usize = 4; -// Maximum number of points for each individual mesh. -const MAX_POINTS_PER_MESH: usize = 2_usize.pow(16); -const _MAX_LINES_PER_MESH: usize = MAX_POINTS_PER_MESH / 2; -/// Maximum number of points. -pub const MAX_POINTS: usize = MAX_POINTS_PER_MESH * MESH_COUNT; -/// Maximum number of unique lines to draw at once. -pub const MAX_LINES: usize = MAX_POINTS / 2; - -const ATTRIBUTE_COLOR: MeshVertexAttribute = - MeshVertexAttribute::new("Vertex_Color", 1, VertexFormat::Uint32); - -fn setup(mut cmds: Commands, mut meshes: ResMut>) { - // Spawn a bunch of meshes to use for lines. - for i in 0..MESH_COUNT { - // Create a new mesh with the number of vertices we need. - let mut mesh = Mesh::new(PrimitiveTopology::LineList); - mesh.insert_attribute( - Mesh::ATTRIBUTE_POSITION, - VertexAttributeValues::Float32x3(Vec::with_capacity(MAX_POINTS_PER_MESH)), - ); - mesh.insert_attribute( - ATTRIBUTE_COLOR, - VertexAttributeValues::Uint32(Vec::with_capacity(MAX_POINTS_PER_MESH)), - ); - // https://github.com/Toqozz/bevy_debug_lines/issues/16 - //mesh.set_indices(Some(Indices::U16(Vec::with_capacity(MAX_POINTS_PER_MESH)))); - - cmds.spawn(( - dim::into_handle(meshes.add(mesh)), - NotShadowCaster, - NotShadowReceiver, - NoFrustumCulling, - Transform::default(), - GlobalTransform::default(), - Visibility::default(), - ComputedVisibility::default(), - DebugLinesMesh(i), - )); - } -} - -fn update( - debug_line_meshes: Query<(&dim::MeshHandle, &DebugLinesMesh)>, - time: Res