From 1b27619cc5c44d4e939e63345cddc1954e4123db Mon Sep 17 00:00:00 2001 From: d28n <183181773+d28n@users.noreply.github.com> Date: Mon, 16 Dec 2024 21:11:41 +0200 Subject: [PATCH] Update to 0.15 (#70) --- Cargo.toml | 5 ++-- examples/render_layers.rs | 47 +++++++++++++++----------------- examples/simple.rs | 56 +++++++++++++++++---------------------- rust-toolchain.toml | 2 +- src/lib.rs | 14 +++++++--- src/render.rs | 21 ++++++++------- 6 files changed, 72 insertions(+), 73 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9ba075d..c6b97d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ keywords = ["bevy"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { version = "0.14.0", default-features = false, features = [ +bevy = { version = "0.15.0", default-features = false, features = [ "bevy_render", "bevy_core_pipeline", "bevy_pbr", @@ -23,8 +23,9 @@ bevy = { version = "0.14.0", default-features = false, features = [ ] } [dev-dependencies] -bevy = { version = "0.14.0", default-features = false, features = [ +bevy = { version = "0.15.0", default-features = false, features = [ "bevy_winit", + "bevy_window", "x11", "tonemapping_luts", "ktx2", diff --git a/examples/render_layers.rs b/examples/render_layers.rs index b1a76b5..877e224 100644 --- a/examples/render_layers.rs +++ b/examples/render_layers.rs @@ -17,39 +17,36 @@ fn setup_system( commands.spawn((InfiniteGridBundle::default(), RenderLayers::layer(1))); commands.spawn(( - Camera3dBundle { - transform: Transform::from_xyz(0.0, 4.37, 14.77), + Camera3d::default(), + Camera { + hdr: true, ..default() }, + Transform::from_xyz(0.0, 4.37, 14.77), RenderLayers::layer(1), )); - commands.spawn(DirectionalLightBundle { - transform: Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.) - .looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); - - let mat = standard_materials.add(StandardMaterial::default()); + commands.spawn(( + DirectionalLight { + ..default() + }, + Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.).looking_at(Vec3::ZERO, Vec3::Y), + )); // cube - commands.spawn(PbrBundle { - material: mat.clone(), - mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()), - transform: Transform { - translation: Vec3::new(3., 4., 0.), - rotation: Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()), - scale: Vec3::splat(1.5), - }, - ..default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), + MeshMaterial3d(standard_materials.add(StandardMaterial::default())), + Transform::from_xyz(3.0, 4.0, 0.0) + .with_rotation(Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize())) + .with_scale(Vec3::splat(1.5)), + )); - commands.spawn(PbrBundle { - material: mat.clone(), - mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()), - transform: Transform::from_xyz(0.0, 2.0, 0.0), - ..default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), + MeshMaterial3d(standard_materials.add(StandardMaterial::default())), + Transform::from_xyz(0.0, 2.0, 0.0), + )); } fn toggle_layers(mut q: Query<&mut RenderLayers, With>, input: Res>) { diff --git a/examples/simple.rs b/examples/simple.rs index b01713d..494783a 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -17,43 +17,37 @@ fn setup_system( commands.spawn(InfiniteGridBundle::default()); commands.spawn(( - Camera3dBundle { - transform: Transform::from_xyz(0.0, 4.37, 14.77), - camera: Camera { - hdr: true, - ..default() - }, + Camera3d::default(), + Camera { + hdr: true, ..default() }, + Transform::from_xyz(0.0, 4.37, 14.77), CameraController::default(), )); + + commands.spawn(( + DirectionalLight { + ..default() + }, + Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.).looking_at(Vec3::ZERO, Vec3::Y), + )); - commands.spawn(DirectionalLightBundle { - transform: Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.) - .looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); + // cube + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), + MeshMaterial3d(standard_materials.add(StandardMaterial::default())), + Transform::from_xyz(3.0, 4.0, 0.0) + .with_rotation(Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize())) + .with_scale(Vec3::splat(1.5)), + )); - let mat = standard_materials.add(StandardMaterial::default()); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), + MeshMaterial3d(standard_materials.add(StandardMaterial::default())), + Transform::from_xyz(0.0, 2.0, 0.0), + )); - // cube - commands.spawn(PbrBundle { - material: mat.clone(), - mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()), - transform: Transform { - translation: Vec3::new(3., 4., 0.), - rotation: Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()), - scale: Vec3::splat(1.5), - }, - ..default() - }); - - commands.spawn(PbrBundle { - material: mat.clone(), - mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()), - transform: Transform::from_xyz(0.0, 2.0, 0.0), - ..default() - }); } // This is a simplified version of the camera controller used in bevy examples @@ -96,7 +90,7 @@ mod camera_controller { key_input: Res>, mut query: Query<(&mut Transform, &mut CameraController), With>, ) { - let dt = time.delta_seconds(); + let dt = time.delta_secs(); if let Ok((mut transform, mut state)) = query.get_single_mut() { // Handle key input diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d5ed441..06bea96 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] profile = "default" -channel = "1.79" +channel = "1.82" diff --git a/src/lib.rs b/src/lib.rs index 488af82..5e11db4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,12 @@ mod render; -use bevy::prelude::*; -use bevy::render::view::{check_visibility, NoFrustumCulling, VisibleEntities}; +use bevy::{ + prelude::*, + render::{ + view::{check_visibility, NoFrustumCulling, RenderVisibleEntities}, + sync_world::SyncToRenderWorld, + } +}; pub struct InfiniteGridPlugin; @@ -52,6 +57,7 @@ pub struct InfiniteGridBundle { pub visibility: Visibility, pub view_visibility: ViewVisibility, pub inherited_visibility: InheritedVisibility, - pub shadow_casters: VisibleEntities, + pub shadow_casters: RenderVisibleEntities, pub no_frustum_culling: NoFrustumCulling, -} + pub sync_to_render_world: SyncToRenderWorld +} \ No newline at end of file diff --git a/src/render.rs b/src/render.rs index 4a41aa1..0e1ee6b 100644 --- a/src/render.rs +++ b/src/render.rs @@ -27,10 +27,11 @@ use bevy::{ StencilFaceState, StencilState, TextureFormat, VertexState, }, renderer::{RenderDevice, RenderQueue}, - texture::BevyDefault, - view::{ExtractedView, ViewTarget, VisibleEntities}, + view::{ExtractedView, ViewTarget, RenderVisibleEntities}, Extract, ExtractSchedule, Render, RenderApp, RenderSet, + sync_world::RenderEntity, }, + image::BevyDefault, }; use crate::InfiniteGridSettings; @@ -196,7 +197,7 @@ impl RenderCommand

for SetInfiniteGridBindGroup ) -> RenderCommandResult { let Some(base_offsets) = base_offsets else { warn!("PerCameraSettingsUniformOffset missing"); - return RenderCommandResult::Failure; + return RenderCommandResult::Skip; }; pass.set_bind_group( I, @@ -285,10 +286,10 @@ fn extract_infinite_grids( mut commands: Commands, grids: Extract< Query<( - Entity, + RenderEntity, &InfiniteGridSettings, &GlobalTransform, - &VisibleEntities, + &RenderVisibleEntities, )>, >, ) { @@ -312,7 +313,7 @@ fn extract_infinite_grids( fn extract_per_camera_settings( mut commands: Commands, - cameras: Extract>>, + cameras: Extract>>, ) { let extracted: Vec<_> = cameras .iter() @@ -400,15 +401,14 @@ fn queue_infinite_grids( mut pipelines: ResMut>, infinite_grids: Query<&ExtractedInfiniteGrid>, mut transparent_render_phases: ResMut>, - mut views: Query<(Entity, &VisibleEntities, &ExtractedView)>, - msaa: Res, + mut views: Query<(Entity, &RenderVisibleEntities, &ExtractedView, &Msaa), With>, ) { let draw_function_id = transparent_draw_functions .read() .get_id::() .unwrap(); - for (view_entity, entities, view) in views.iter_mut() { + for (view_entity, entities, view, msaa) in views.iter_mut() { let Some(phase) = transparent_render_phases.get_mut(&view_entity) else { continue; }; @@ -424,7 +424,7 @@ fn queue_infinite_grids( ); for &entity in entities.iter::>() { if !infinite_grids - .get(entity) + .get(entity.0) .map(|grid| plane_check(&grid.transform, view.world_from_view.translation())) .unwrap_or(false) { @@ -553,6 +553,7 @@ impl SpecializedRenderPipeline for InfiniteGridPipeline { write_mask: ColorWrites::ALL, })], }), + zero_initialize_workgroup_memory: false, } } }