From 1adc7c215466c639bee6da3337fe2e7edf6f0e6d Mon Sep 17 00:00:00 2001 From: Aevyrie Date: Wed, 13 Mar 2024 21:56:37 -0700 Subject: [PATCH 1/5] Bevy 0.13 update --- Cargo.toml | 10 +- examples/cad.rs | 64 ++++++----- examples/floating_origin.rs | 152 ++------------------------- examples/map.rs | 25 +++-- examples/minimal.rs | 1 + examples/ortho.rs | 1 + examples/pseudo_ortho.rs | 1 + examples/split_screen.rs | 14 +-- src/controller/component.rs | 12 +-- src/extensions/anchor_indicator.rs | 7 +- src/extensions/independent_skybox.rs | 18 ++-- src/input.rs | 2 +- 12 files changed, 95 insertions(+), 212 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b82f338..08e6ff6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,18 +9,18 @@ keywords = ["editor, camera, bevy"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { version = "0.12.1", default-features = false, features = [ +bevy = { version = "0.13", default-features = false, features = [ "bevy_render", "bevy_gizmos", "bevy_asset", "bevy_core_pipeline", ] } -bevy_picking_core = "0.17" +bevy_picking_core = "0.18" [dev-dependencies] -bevy = { version = "0.12", features = ["jpeg"] } -bevy_mod_picking = { version = "0.17", default-features = false, features = [ +bevy = { version = "0.13", features = ["jpeg"] } +bevy_mod_picking = { version = "0.18", default-features = false, features = [ "backend_raycast", ] } -big_space = "0.4" +big_space = "0.5" rand = "0.8" diff --git a/examples/cad.rs b/examples/cad.rs index 8675ad0..855087f 100644 --- a/examples/cad.rs +++ b/examples/cad.rs @@ -2,8 +2,11 @@ use std::time::Duration; use bevy::{ core_pipeline::{ - bloom::BloomSettings, experimental::taa::TemporalAntiAliasPlugin, tonemapping::Tonemapping, + bloom::BloomSettings, + experimental::taa::{TemporalAntiAliasBundle, TemporalAntiAliasPlugin}, + tonemapping::Tonemapping, }, + pbr::ScreenSpaceAmbientOcclusionBundle, prelude::*, render::primitives::Aabb, utils::Instant, @@ -20,9 +23,9 @@ fn main() { TemporalAntiAliasPlugin, )) // The camera controller works with reactive rendering: - .insert_resource(bevy::winit::WinitSettings::desktop_app()) - .insert_resource(Msaa::Sample4) - .insert_resource(ClearColor(Color::WHITE)) + // .insert_resource(bevy::winit::WinitSettings::desktop_app()) + .insert_resource(Msaa::Off) + .insert_resource(ClearColor(Color::NONE)) .insert_resource(AmbientLight { brightness: 0.0, ..default() @@ -42,33 +45,40 @@ fn setup(mut commands: Commands, asset_server: Res) { ..Default::default() }); - commands.spawn(( - Camera3dBundle { - transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y), - tonemapping: Tonemapping::AcesFitted, - ..default() - }, - BloomSettings::default(), - EnvironmentMapLight { - diffuse_map: diffuse_map.clone(), - specular_map: specular_map.clone(), - }, - EditorCam { - orbit_constraint: OrbitConstraint::Free, - last_anchor_depth: 2.0, - ..Default::default() - }, - bevy_editor_cam::extensions::independent_skybox::IndependentSkybox::new(diffuse_map), - )); + commands + .spawn(( + Camera3dBundle { + transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y), + tonemapping: Tonemapping::AcesFitted, + ..default() + }, + BloomSettings::default(), + EnvironmentMapLight { + intensity: 1000.0, + diffuse_map: diffuse_map.clone(), + specular_map: specular_map.clone(), + }, + EditorCam { + orbit_constraint: OrbitConstraint::Fixed { + up: Vec3::Y, + can_pass_tdc: false, + }, + last_anchor_depth: 2.0, + ..Default::default() + }, + bevy_editor_cam::extensions::independent_skybox::IndependentSkybox::new(diffuse_map), + )) + .insert(ScreenSpaceAmbientOcclusionBundle::default()) + .insert(TemporalAntiAliasBundle::default()); } fn toggle_projection( - keys: Res>, + keys: Res>, mut dolly: EventWriter, cam: Query>, mut toggled: Local, ) { - if keys.just_pressed(KeyCode::P) { + if keys.just_pressed(KeyCode::KeyP) { *toggled = !*toggled; let target_projection = if *toggled { Projection::Orthographic(OrthographicProjection::default()) @@ -78,7 +88,7 @@ fn toggle_projection( dolly.send(DollyZoomTrigger { target_projection, camera: cam.single(), - }) + }); } } @@ -110,7 +120,7 @@ struct StartPos(f32); #[allow(clippy::type_complexity)] fn explode( mut commands: Commands, - keys: Res>, + keys: Res>, mut toggle: Local>, mut explode_amount: Local, mut redraw: EventWriter, @@ -118,7 +128,7 @@ fn explode( mut matls: ResMut>, ) { let animation = Duration::from_millis(2000); - if keys.just_pressed(KeyCode::E) { + if keys.just_pressed(KeyCode::KeyE) { let new = if let Some((last, ..)) = *toggle { !last } else { diff --git a/examples/floating_origin.rs b/examples/floating_origin.rs index dd6b222..a6bae52 100644 --- a/examples/floating_origin.rs +++ b/examples/floating_origin.rs @@ -1,36 +1,18 @@ -//! This example demonstrates that the camera controller was designed to work with floating origin -//! systems for large worlds. Because the controller *never* relies on the `GlobalTransform` of the -//! camera, and instead only moves relative to the current position, it is compatible with arbitrary -//! transform systems. - -use bevy::{prelude::*, transform::TransformSystem}; -use bevy_editor_cam::prelude::*; -use big_space::{ - camera::{CameraController, CameraInput}, - FloatingOrigin, GridCell, -}; +use bevy::prelude::*; +use bevy_editor_cam::{controller::component::EditorCam, DefaultEditorCamPlugins}; +use big_space::{FloatingOrigin, GridCell}; fn main() { App::new() .add_plugins(( DefaultPlugins.build().disable::(), + bevy_mod_picking::DefaultPickingPlugins, + DefaultEditorCamPlugins, big_space::FloatingOriginPlugin::::default(), big_space::debug::FloatingOriginDebugPlugin::::default(), - big_space::camera::CameraControllerPlugin::::default(), - bevy_mod_picking::DefaultPickingPlugins, // Prerequisite: Use picking plugin - DefaultEditorCamPlugins, )) - .insert_resource(CameraInput { - defaults_disabled: true, - ..Default::default() - }) .insert_resource(ClearColor(Color::BLACK)) .add_systems(Startup, (setup, ui_setup)) - .add_systems(Update, ui_text_system) - .add_systems( - PostUpdate, - highlight_nearest_sphere.after(TransformSystem::TransformPropagate), - ) .run() } @@ -50,20 +32,12 @@ fn setup( }), ..default() }, - GridCell::::default(), // All spatial entities need this component - FloatingOrigin, // Important: marks the floating origin entity for rendering. - CameraController::default(), + GridCell::::default(), + FloatingOrigin, EditorCam::default(), )); - let mesh_handle = meshes.add( - shape::Icosphere { - radius: 0.5, - subdivisions: 32, - } - .try_into() - .unwrap(), - ); + let mesh_handle = meshes.add(Sphere::new(0.5).mesh().ico(32).unwrap()); let matl_handle = materials.add(StandardMaterial { base_color: Color::BLUE, perceptual_roughness: 0.8, @@ -112,7 +86,7 @@ fn ui_setup(mut commands: Commands) { ..default() }, ) - .with_text_alignment(TextAlignment::Left) + .with_text_justify(JustifyText::Left) .with_style(Style { position_type: PositionType::Absolute, top: Val::Px(10.0), @@ -138,113 +112,7 @@ fn ui_setup(mut commands: Commands) { left: Val::Px(10.0), ..default() }) - .with_text_alignment(TextAlignment::Center), + .with_text_justify(JustifyText::Center), FunFactText, )); } - -fn highlight_nearest_sphere( - cameras: Query<&CameraController>, - objects: Query<&GlobalTransform>, - mut gizmos: Gizmos, -) { - let Some((entity, _)) = cameras.single().nearest_object() else { - return; - }; - let Ok(transform) = objects.get(entity) else { - return; - }; - let (scale, rotation, translation) = transform.to_scale_rotation_translation(); - gizmos - .sphere(translation, rotation, scale.x * 0.505, Color::RED) - .circle_segments(128); -} - -fn ui_text_system( - mut debug_text: Query<&mut Text, (With, Without)>, - mut fun_text: Query<&mut Text, (With, Without)>, - time: Res