From 1bf2e57a5261c3160f248f9a95a6228e121276af Mon Sep 17 00:00:00 2001 From: ActuallyHappening <105958073+ActuallyHappening@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:49:10 +1000 Subject: [PATCH 01/14] wip: basic example works but a bit buggy --- Cargo.toml | 15 +- crates/bevy_editor_pls/Cargo.toml | 2 +- crates/bevy_editor_pls/examples/basic.rs | 4 +- crates/bevy_editor_pls/src/controls.rs | 6 +- crates/bevy_editor_pls/src/lib.rs | 5 + .../Cargo.toml | 2 +- .../src/cameras/mod.rs | 15 +- .../src/gizmos.rs | 182 ++++++++++++------ 8 files changed, 154 insertions(+), 77 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8752c13..87539cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,14 +11,15 @@ description = "In-App editor tools for bevy apps" readme = "README.md" [workspace.dependencies] -bevy_editor_pls = { version = "0.8.0", path = "crates/bevy_editor_pls" } -bevy_editor_pls_core = { version = "0.8.0", path = "crates/bevy_editor_pls_core" } -bevy_editor_pls_default_windows = { version = "0.8.0", path = "crates/bevy_editor_pls_default_windows" } +bevy_editor_pls = { version = "0.8.1", path = "crates/bevy_editor_pls" } +bevy_editor_pls_core = { version = "0.8.1", path = "crates/bevy_editor_pls_core" } +bevy_editor_pls_default_windows = { version = "0.8.1", path = "crates/bevy_editor_pls_default_windows" } -bevy-inspector-egui = "0.23.0" -egui = "0.26" -egui_dock = "0.11" -egui-gizmo = "0.16" +bevy-inspector-egui = "0.24.0" +egui = "0.27" +egui_dock = "0.12" +# used to be egui-gizmo 0.16 +transform-gizmo-bevy = "0.2" [profile.dev.package."*"] opt-level = 2 diff --git a/crates/bevy_editor_pls/Cargo.toml b/crates/bevy_editor_pls/Cargo.toml index 3655b2e..3b32f21 100644 --- a/crates/bevy_editor_pls/Cargo.toml +++ b/crates/bevy_editor_pls/Cargo.toml @@ -24,7 +24,7 @@ bevy_editor_pls_core.workspace = true bevy_editor_pls_default_windows = { workspace = true, optional = true } bevy = { version = "0.13", default-features = false, features = ["x11"] } egui.workspace = true -egui-gizmo.workspace = true +transform-gizmo-bevy.workspace = true # bevy_framepace = { version = "0.12", default-features = false } [dev-dependencies] diff --git a/crates/bevy_editor_pls/examples/basic.rs b/crates/bevy_editor_pls/examples/basic.rs index 31d161d..22e0598 100644 --- a/crates/bevy_editor_pls/examples/basic.rs +++ b/crates/bevy_editor_pls/examples/basic.rs @@ -47,7 +47,7 @@ fn setup( material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..Default::default() - }); + }).insert(transform_gizmo_bevy::GizmoTarget::default()); // light commands.spawn(PointLightBundle { transform: Transform::from_xyz(4.0, 8.0, 4.0), @@ -61,5 +61,5 @@ fn setup( commands.spawn(Camera3dBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..Default::default() - }); + }).insert(transform_gizmo_bevy::GizmoCamera); } diff --git a/crates/bevy_editor_pls/src/controls.rs b/crates/bevy_editor_pls/src/controls.rs index 78e0f74..c8ed55c 100644 --- a/crates/bevy_editor_pls/src/controls.rs +++ b/crates/bevy_editor_pls/src/controls.rs @@ -240,7 +240,7 @@ pub fn editor_controls_system( editor .window_state_mut::() .unwrap() - .gizmo_mode = egui_gizmo::GizmoMode::Translate; + .gizmo_mode = transform_gizmo_bevy::GizmoMode::all_translate(); } if controls.just_pressed( Action::SetGizmoModeRotate, @@ -251,7 +251,7 @@ pub fn editor_controls_system( editor .window_state_mut::() .unwrap() - .gizmo_mode = egui_gizmo::GizmoMode::Rotate; + .gizmo_mode = transform_gizmo_bevy::GizmoMode::all_rotate(); } if controls.just_pressed( Action::SetGizmoModeScale, @@ -262,7 +262,7 @@ pub fn editor_controls_system( editor .window_state_mut::() .unwrap() - .gizmo_mode = egui_gizmo::GizmoMode::Scale; + .gizmo_mode = transform_gizmo_bevy::GizmoMode::all_scale(); } } } diff --git a/crates/bevy_editor_pls/src/lib.rs b/crates/bevy_editor_pls/src/lib.rs index f479693..ef599a7 100644 --- a/crates/bevy_editor_pls/src/lib.rs +++ b/crates/bevy_editor_pls/src/lib.rs @@ -128,6 +128,11 @@ impl Plugin for EditorPlugin { app.add_plugins(bevy::pbr::wireframe::WireframePlugin); + // required for the GizmoWindow + if !app.is_plugin_added::() { + app.add_plugins(transform_gizmo_bevy::TransformGizmoPlugin); + } + app.insert_resource(controls::EditorControls::default_bindings()) .add_systems(Update, controls::editor_controls_system); diff --git a/crates/bevy_editor_pls_default_windows/Cargo.toml b/crates/bevy_editor_pls_default_windows/Cargo.toml index 203cb72..18c0095 100644 --- a/crates/bevy_editor_pls_default_windows/Cargo.toml +++ b/crates/bevy_editor_pls_default_windows/Cargo.toml @@ -31,4 +31,4 @@ indexmap = "2" pretty-type-name = "1.0" bevy_mod_debugdump = "0.10" opener = "0.6.0" -egui-gizmo.workspace = true +transform-gizmo-bevy.workspace = true diff --git a/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs b/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs index 56894ec..25731fa 100644 --- a/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs +++ b/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs @@ -13,6 +13,7 @@ use bevy_editor_pls_core::{ Editor, EditorEvent, }; use bevy_inspector_egui::egui; +use transform_gizmo_bevy::GizmoCamera; // use bevy_mod_picking::prelude::PickRaycastSource; use crate::hierarchy::{HideInEditor, HierarchyWindow}; @@ -28,6 +29,9 @@ pub struct EditorCamera; // Present only one the one currently active camera #[derive(Component)] pub struct ActiveEditorCamera; +// /// Changed to a type alias to guarentee being in sync with the GizmoCamera component, +// /// this should be considered a 'hack' that maybe should be fixed down the line +// pub type ActiveEditorCamera = transform_gizmo_bevy::GizmoCamera; // Marker component for the 3d free camera #[derive(Component)] @@ -168,7 +172,7 @@ fn set_active_editor_camera_marker(world: &mut World, editor_cam: EditorCamKind) state.iter(world).next().unwrap() } }; - world.entity_mut(entity).insert(ActiveEditorCamera); + world.entity_mut(entity).insert(ActiveEditorCamera {}); } fn cameras_ui(ui: &mut egui::Ui, world: &mut World) { @@ -232,6 +236,7 @@ fn spawn_editor_cameras(mut commands: Commands, editor: Res) { HideInEditor, Name::new("Editor Camera 3D Free"), NotInScene, + GizmoCamera, render_layers, )); @@ -254,6 +259,7 @@ fn spawn_editor_cameras(mut commands: Commands, editor: Res) { HideInEditor, Name::new("Editor Camera 3D Pan/Orbit"), NotInScene, + GizmoCamera, render_layers, )); @@ -275,6 +281,7 @@ fn spawn_editor_cameras(mut commands: Commands, editor: Res) { HideInEditor, Name::new("Editor Camera 2D Pan/Zoom"), NotInScene, + GizmoCamera, render_layers, )); } @@ -496,21 +503,21 @@ fn initial_camera_setup( camera_state.editor_cam = EditorCamKind::D2PanZoom; commands .entity(cameras.p0().single().0) - .insert(ActiveEditorCamera); + .insert(ActiveEditorCamera {}); *has_decided_initial_cam = true; } (false, true) => { camera_state.editor_cam = EditorCamKind::D3PanOrbit; commands .entity(cameras.p2().single().0) - .insert(ActiveEditorCamera); + .insert(ActiveEditorCamera {}); *has_decided_initial_cam = true; } (true, true) => { camera_state.editor_cam = EditorCamKind::D3PanOrbit; commands .entity(cameras.p2().single().0) - .insert(ActiveEditorCamera); + .insert(ActiveEditorCamera {}); *has_decided_initial_cam = true; } (false, false) => return, diff --git a/crates/bevy_editor_pls_default_windows/src/gizmos.rs b/crates/bevy_editor_pls_default_windows/src/gizmos.rs index 1f5482f..2771302 100644 --- a/crates/bevy_editor_pls_default_windows/src/gizmos.rs +++ b/crates/bevy_editor_pls_default_windows/src/gizmos.rs @@ -1,12 +1,13 @@ use bevy::{ - ecs::query::QueryFilter, + ecs::{query::QueryFilter, system::RunSystemOnce}, prelude::*, render::{camera::CameraProjection, view::RenderLayers}, }; use bevy_editor_pls_core::editor_window::{EditorWindow, EditorWindowContext}; use bevy_inspector_egui::{bevy_inspector::hierarchy::SelectedEntities, egui}; -use egui_gizmo::GizmoMode; +use transform_gizmo_bevy::{EnumSet, GizmoMode}; +use transform_gizmo_bevy::GizmoTarget; use crate::{ cameras::{ActiveEditorCamera, CameraWindow, EditorCamera, EDITOR_RENDER_LAYER}, @@ -15,14 +16,15 @@ use crate::{ pub struct GizmoState { pub camera_gizmo_active: bool, - pub gizmo_mode: GizmoMode, + /// TODO: Take these settings into account + pub gizmo_mode: EnumSet, } impl Default for GizmoState { fn default() -> Self { Self { camera_gizmo_active: true, - gizmo_mode: GizmoMode::Translate, + gizmo_mode: GizmoMode::all_translate(), } } } @@ -42,10 +44,62 @@ impl EditorWindow for GizmoWindow { let gizmo_state = cx.state::().unwrap(); if gizmo_state.camera_gizmo_active { - if let (Some(hierarchy_state), Some(_camera_state)) = - (cx.state::(), cx.state::()) - { - draw_gizmo(ui, world, &hierarchy_state.selected, gizmo_state.gizmo_mode); + // if let (Some(hierarchy_state), Some(_camera_state)) = + // (cx.state::(), cx.state::()) + // { + // draw_gizmo(ui, world, &hierarchy_state.selected, gizmo_state.gizmo_mode); + // } + + /// Before [hydrate_gizmos] and [deconstruct_gizmos] are run, this system resets the state of all entities that have a [EntityShouldShowGizmo] component. + /// Then, according to selection logic some entities are marked as focussed, and [hydrate_gizmos] and [deconstruct_gizmos] is run to sync the gizmo state with the selection state. + fn reset_gizmos_selected_state( + mut commands: Commands, + entities: Query>, + ) { + for entity in entities.iter() { + commands.entity(entity).remove::(); + } + } + + /// Takes all entities marked with [EntityShouldShowGizmo] and adds the [GizmoTarget] component to them. + fn hydrate_gizmos( + mut commands: Commands, + entities: Query, Without)>, + ) { + for entity in entities.iter() { + trace!("Hydrating a gizmo on entity {:?} because it is selected", entity); + // TODO: Maybe change the exact gizmo target instance instead of using default? should this load from some config? + commands.entity(entity).insert(GizmoTarget::default()); + } + } + + /// Takes all entities that should have their [GizmoTarget] removed because they are no longer selected. + fn deconstruct_gizmos( + mut commands: Commands, + entities: Query, Without)>, + ) { + for entity in entities.iter() { + commands.entity(entity).remove::(); + debug!( + "Removing GizmoTarget from entity {:?} because it has lost focus", + entity + ); + } + } + + if let Some(hierarchy_state) = cx.state::() { + // here should assign the `EntityShouldShowGizmo` component, which is later synced + // with the actual gizmo ui system + + world.run_system_once(reset_gizmos_selected_state); + + let selected_entities = hierarchy_state.selected.iter(); + for entity in selected_entities { + world.entity_mut(entity).insert(EntityShouldShowGizmo); + } + + world.run_system_once(hydrate_gizmos); + world.run_system_once(deconstruct_gizmos); } } } @@ -93,9 +147,15 @@ struct GizmoMarkerConfig { camera_material: Handle, } +/// can somebody document what this does? is it a duplicate of [EntityShouldShowGizmo]? #[derive(Component)] struct HasGizmoMarker; +/// When on an entity, this entity should be controllable using some sort of user gizmo. +/// Currently uses [transform_gizmo_bevy], and puts the [GizmoTarget] on the entity. +#[derive(Component)] +struct EntityShouldShowGizmo; + type GizmoMarkerQuery<'w, 's, T, F = ()> = Query<'w, 's, Entity, (With, Without, F)>; @@ -166,55 +226,59 @@ fn add_gizmo_markers( } } -fn draw_gizmo( - ui: &mut egui::Ui, - world: &mut World, - selected_entities: &SelectedEntities, - gizmo_mode: GizmoMode, -) { - let Ok((cam_transform, projection)) = world - .query_filtered::<(&GlobalTransform, &Projection), With>() - .get_single(world) - else { - return; - }; - let view_matrix = Mat4::from(cam_transform.affine().inverse()); - let projection_matrix = projection.get_projection_matrix(); - - if selected_entities.len() != 1 { - return; - } +// fn draw_gizmo( +// ui: &mut egui::Ui, +// world: &mut World, +// selected_entities: &SelectedEntities, +// gizmo_mode: GizmoMode, +// ) { +// for entity in selected_entities.iter() { +// world.entity_mut(entity).insert(transform_gizmo_bevy::GizmoTarget::default()); +// info!("Inserted GizmoTarget to entity: {:?}", entity); +// } +// // let Ok((cam_transform, projection)) = world +// // .query_filtered::<(&GlobalTransform, &Projection), With>() +// // .get_single(world) +// // else { +// // return; +// // }; +// // let view_matrix = Mat4::from(cam_transform.affine().inverse()); +// // let projection_matrix = projection.get_projection_matrix(); - for selected in selected_entities.iter() { - let Some(global_transform) = world.get::(selected) else { - continue; - }; - let model_matrix = global_transform.compute_matrix(); - - let Some(result) = egui_gizmo::Gizmo::new(selected) - .model_matrix(model_matrix.into()) - .view_matrix(view_matrix.into()) - .projection_matrix(projection_matrix.into()) - .orientation(egui_gizmo::GizmoOrientation::Local) - .mode(gizmo_mode) - .interact(ui) - else { - continue; - }; - - let global_affine = global_transform.affine(); - - let mut transform = world.get_mut::(selected).unwrap(); - - let parent_affine = global_affine * transform.compute_affine().inverse(); - let inverse_parent_transform = GlobalTransform::from(parent_affine.inverse()); - - let global_transform = Transform { - translation: result.translation.into(), - rotation: result.rotation.into(), - scale: result.scale.into(), - }; - - *transform = (inverse_parent_transform * global_transform).into(); - } -} +// // if selected_entities.len() != 1 { +// // return; +// // } + +// // for selected in selected_entities.iter() { +// // // let Some(global_transform) = world.get::(selected) else { +// // // continue; +// // // }; +// // // let model_matrix = global_transform.compute_matrix(); + +// // // let Some(result) = transform_gizmo_bevy::Gizmo::new(selected) +// // // .model_matrix(model_matrix.into()) +// // // .view_matrix(view_matrix.into()) +// // // .projection_matrix(projection_matrix.into()) +// // // .orientation(transform_gizmo_bevy::GizmoOrientation::Local) +// // // .mode(gizmo_mode) +// // // .interact(ui) +// // // else { +// // // continue; +// // // }; + +// // // let global_affine = global_transform.affine(); + +// // // let mut transform = world.get_mut::(selected).unwrap(); + +// // // let parent_affine = global_affine * transform.compute_affine().inverse(); +// // // let inverse_parent_transform = GlobalTransform::from(parent_affine.inverse()); + +// // // let global_transform = Transform { +// // // translation: result.translation.into(), +// // // rotation: result.rotation.into(), +// // // scale: result.scale.into(), +// // // }; + +// // // *transform = (inverse_parent_transform * global_transform).into(); +// // } +// } From 58997923c24445720a4cbf914aa7e897c8d08104 Mon Sep 17 00:00:00 2001 From: ActuallyHappening <105958073+ActuallyHappening@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:55:38 +1000 Subject: [PATCH 02/14] revert: basic example accidentally committed changes --- crates/bevy_editor_pls/examples/basic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_editor_pls/examples/basic.rs b/crates/bevy_editor_pls/examples/basic.rs index 22e0598..31d161d 100644 --- a/crates/bevy_editor_pls/examples/basic.rs +++ b/crates/bevy_editor_pls/examples/basic.rs @@ -47,7 +47,7 @@ fn setup( material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..Default::default() - }).insert(transform_gizmo_bevy::GizmoTarget::default()); + }); // light commands.spawn(PointLightBundle { transform: Transform::from_xyz(4.0, 8.0, 4.0), @@ -61,5 +61,5 @@ fn setup( commands.spawn(Camera3dBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..Default::default() - }).insert(transform_gizmo_bevy::GizmoCamera); + }); } From cb4e8b3ad71fa4fdf0278e5dddfb1720a5b13955 Mon Sep 17 00:00:00 2001 From: ActuallyHappening <105958073+ActuallyHappening@users.noreply.github.com> Date: Mon, 10 Jun 2024 20:30:17 +1000 Subject: [PATCH 03/14] feat: gizmos are completely integrated --- crates/bevy_editor_pls/src/controls.rs | 6 +++--- crates/bevy_editor_pls/src/lib.rs | 2 +- .../bevy_editor_pls_core/src/editor_window.rs | 1 + .../src/gizmos.rs | 19 ++++++++++--------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/bevy_editor_pls/src/controls.rs b/crates/bevy_editor_pls/src/controls.rs index c8ed55c..2ff8436 100644 --- a/crates/bevy_editor_pls/src/controls.rs +++ b/crates/bevy_editor_pls/src/controls.rs @@ -240,7 +240,7 @@ pub fn editor_controls_system( editor .window_state_mut::() .unwrap() - .gizmo_mode = transform_gizmo_bevy::GizmoMode::all_translate(); + .gizmo_modes = transform_gizmo_bevy::GizmoMode::all_translate(); } if controls.just_pressed( Action::SetGizmoModeRotate, @@ -251,7 +251,7 @@ pub fn editor_controls_system( editor .window_state_mut::() .unwrap() - .gizmo_mode = transform_gizmo_bevy::GizmoMode::all_rotate(); + .gizmo_modes = transform_gizmo_bevy::GizmoMode::all_rotate(); } if controls.just_pressed( Action::SetGizmoModeScale, @@ -262,7 +262,7 @@ pub fn editor_controls_system( editor .window_state_mut::() .unwrap() - .gizmo_mode = transform_gizmo_bevy::GizmoMode::all_scale(); + .gizmo_modes = transform_gizmo_bevy::GizmoMode::all_scale(); } } } diff --git a/crates/bevy_editor_pls/src/lib.rs b/crates/bevy_editor_pls/src/lib.rs index ef599a7..13c3db7 100644 --- a/crates/bevy_editor_pls/src/lib.rs +++ b/crates/bevy_editor_pls/src/lib.rs @@ -128,7 +128,7 @@ impl Plugin for EditorPlugin { app.add_plugins(bevy::pbr::wireframe::WireframePlugin); - // required for the GizmoWindow + // required for the GizmoWindow if !app.is_plugin_added::() { app.add_plugins(transform_gizmo_bevy::TransformGizmoPlugin); } diff --git a/crates/bevy_editor_pls_core/src/editor_window.rs b/crates/bevy_editor_pls_core/src/editor_window.rs index 89dde47..aac990e 100644 --- a/crates/bevy_editor_pls_core/src/editor_window.rs +++ b/crates/bevy_editor_pls_core/src/editor_window.rs @@ -13,6 +13,7 @@ pub trait EditorWindow: 'static { const DEFAULT_SIZE: (f32, f32) = (0.0, 0.0); fn ui(world: &mut World, cx: EditorWindowContext, ui: &mut egui::Ui); + /// Ui shown in the `Open Window` menu item. By default opens the window as a floating window. fn menu_ui(world: &mut World, mut cx: EditorWindowContext, ui: &mut egui::Ui) { let _ = world; diff --git a/crates/bevy_editor_pls_default_windows/src/gizmos.rs b/crates/bevy_editor_pls_default_windows/src/gizmos.rs index 2771302..73f1564 100644 --- a/crates/bevy_editor_pls_default_windows/src/gizmos.rs +++ b/crates/bevy_editor_pls_default_windows/src/gizmos.rs @@ -17,14 +17,14 @@ use crate::{ pub struct GizmoState { pub camera_gizmo_active: bool, /// TODO: Take these settings into account - pub gizmo_mode: EnumSet, + pub gizmo_modes: EnumSet, } impl Default for GizmoState { fn default() -> Self { Self { camera_gizmo_active: true, - gizmo_mode: GizmoMode::all_translate(), + gizmo_modes: GizmoMode::all_translate(), } } } @@ -38,18 +38,19 @@ impl EditorWindow for GizmoWindow { fn ui(_world: &mut World, _cx: EditorWindowContext, ui: &mut egui::Ui) { ui.label("Gizmos can currently not be configured"); + // could definitely change some settings here in the future } - fn viewport_toolbar_ui(world: &mut World, cx: EditorWindowContext, ui: &mut egui::Ui) { + /// Called every frame (hopefully), could this invariant (namely being called every frame) be documented, + /// ideally in the [EditorWindow] trait? + fn viewport_toolbar_ui(world: &mut World, cx: EditorWindowContext, _ui: &mut egui::Ui) { let gizmo_state = cx.state::().unwrap(); - if gizmo_state.camera_gizmo_active { - // if let (Some(hierarchy_state), Some(_camera_state)) = - // (cx.state::(), cx.state::()) - // { - // draw_gizmo(ui, world, &hierarchy_state.selected, gizmo_state.gizmo_mode); - // } + // syncs the [GizmoOptions] resource with the current state of the gizmo window + let mut gizmo_options = world.resource_mut::(); + gizmo_options.gizmo_modes = gizmo_state.gizmo_modes; + if gizmo_state.camera_gizmo_active { /// Before [hydrate_gizmos] and [deconstruct_gizmos] are run, this system resets the state of all entities that have a [EntityShouldShowGizmo] component. /// Then, according to selection logic some entities are marked as focussed, and [hydrate_gizmos] and [deconstruct_gizmos] is run to sync the gizmo state with the selection state. fn reset_gizmos_selected_state( From fd3f4c7960484ad9ba31988b8aaafc2c6e03a97c Mon Sep 17 00:00:00 2001 From: ActuallyHappening <105958073+ActuallyHappening@users.noreply.github.com> Date: Mon, 10 Jun 2024 20:35:21 +1000 Subject: [PATCH 04/14] fmt: Fixed formatting and added documentation here and there --- crates/bevy_editor_pls/src/controls.rs | 2 ++ .../src/gizmos.rs | 31 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/bevy_editor_pls/src/controls.rs b/crates/bevy_editor_pls/src/controls.rs index 2ff8436..01f9429 100644 --- a/crates/bevy_editor_pls/src/controls.rs +++ b/crates/bevy_editor_pls/src/controls.rs @@ -136,6 +136,8 @@ pub enum Action { PauseUnpauseTime, FocusSelected, + // maybe investigate [GizmoOptions].hotkeys + // https://docs.rs/transform-gizmo-bevy/latest/transform_gizmo_bevy/struct.GizmoHotkeys.html #[cfg(feature = "default_windows")] SetGizmoModeTranslate, #[cfg(feature = "default_windows")] diff --git a/crates/bevy_editor_pls_default_windows/src/gizmos.rs b/crates/bevy_editor_pls_default_windows/src/gizmos.rs index 73f1564..49a4339 100644 --- a/crates/bevy_editor_pls_default_windows/src/gizmos.rs +++ b/crates/bevy_editor_pls_default_windows/src/gizmos.rs @@ -1,22 +1,23 @@ use bevy::{ ecs::{query::QueryFilter, system::RunSystemOnce}, prelude::*, - render::{camera::CameraProjection, view::RenderLayers}, + render::view::RenderLayers, }; use bevy_editor_pls_core::editor_window::{EditorWindow, EditorWindowContext}; -use bevy_inspector_egui::{bevy_inspector::hierarchy::SelectedEntities, egui}; -use transform_gizmo_bevy::{EnumSet, GizmoMode}; +use bevy_inspector_egui::egui; use transform_gizmo_bevy::GizmoTarget; +use transform_gizmo_bevy::{EnumSet, GizmoMode}; use crate::{ - cameras::{ActiveEditorCamera, CameraWindow, EditorCamera, EDITOR_RENDER_LAYER}, + cameras::{EditorCamera, EDITOR_RENDER_LAYER}, hierarchy::HierarchyWindow, }; pub struct GizmoState { + /// If [false], doesn't show any gizmos pub camera_gizmo_active: bool, - /// TODO: Take these settings into account + /// Synced with the [transform_gizmo_bevy::GizmoOptions] resource pub gizmo_modes: EnumSet, } @@ -38,17 +39,17 @@ impl EditorWindow for GizmoWindow { fn ui(_world: &mut World, _cx: EditorWindowContext, ui: &mut egui::Ui) { ui.label("Gizmos can currently not be configured"); - // could definitely change some settings here in the future + // could definitely change some settings here in the future } - /// Called every frame (hopefully), could this invariant (namely being called every frame) be documented, - /// ideally in the [EditorWindow] trait? + /// Called every frame (hopefully), could this invariant (namely being called every frame) be documented, + /// ideally in the [EditorWindow] trait? fn viewport_toolbar_ui(world: &mut World, cx: EditorWindowContext, _ui: &mut egui::Ui) { let gizmo_state = cx.state::().unwrap(); - // syncs the [GizmoOptions] resource with the current state of the gizmo window - let mut gizmo_options = world.resource_mut::(); - gizmo_options.gizmo_modes = gizmo_state.gizmo_modes; + // syncs the [GizmoOptions] resource with the current state of the gizmo window + let mut gizmo_options = world.resource_mut::(); + gizmo_options.gizmo_modes = gizmo_state.gizmo_modes; if gizmo_state.camera_gizmo_active { /// Before [hydrate_gizmos] and [deconstruct_gizmos] are run, this system resets the state of all entities that have a [EntityShouldShowGizmo] component. @@ -68,8 +69,12 @@ impl EditorWindow for GizmoWindow { entities: Query, Without)>, ) { for entity in entities.iter() { - trace!("Hydrating a gizmo on entity {:?} because it is selected", entity); - // TODO: Maybe change the exact gizmo target instance instead of using default? should this load from some config? + trace!( + "Hydrating a gizmo on entity {:?} because it is selected", + entity + ); + // implicitly assumes it is the only gizmo system in the world, + // otherwise setting [GizmoTarget].is_focussed may be necessary commands.entity(entity).insert(GizmoTarget::default()); } } From f9c500eea07fe5ffdf0e46eff71e26667a028bef Mon Sep 17 00:00:00 2001 From: ActuallyHappening <105958073+ActuallyHappening@users.noreply.github.com> Date: Mon, 10 Jun 2024 20:46:51 +1000 Subject: [PATCH 05/14] clean: remove unnecessary code --- .../src/cameras/mod.rs | 11 ++-- .../src/gizmos.rs | 59 +------------------ 2 files changed, 5 insertions(+), 65 deletions(-) diff --git a/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs b/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs index 25731fa..3d61b05 100644 --- a/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs +++ b/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs @@ -29,9 +29,6 @@ pub struct EditorCamera; // Present only one the one currently active camera #[derive(Component)] pub struct ActiveEditorCamera; -// /// Changed to a type alias to guarentee being in sync with the GizmoCamera component, -// /// this should be considered a 'hack' that maybe should be fixed down the line -// pub type ActiveEditorCamera = transform_gizmo_bevy::GizmoCamera; // Marker component for the 3d free camera #[derive(Component)] @@ -172,7 +169,7 @@ fn set_active_editor_camera_marker(world: &mut World, editor_cam: EditorCamKind) state.iter(world).next().unwrap() } }; - world.entity_mut(entity).insert(ActiveEditorCamera {}); + world.entity_mut(entity).insert(ActiveEditorCamera); } fn cameras_ui(ui: &mut egui::Ui, world: &mut World) { @@ -503,21 +500,21 @@ fn initial_camera_setup( camera_state.editor_cam = EditorCamKind::D2PanZoom; commands .entity(cameras.p0().single().0) - .insert(ActiveEditorCamera {}); + .insert(ActiveEditorCamera); *has_decided_initial_cam = true; } (false, true) => { camera_state.editor_cam = EditorCamKind::D3PanOrbit; commands .entity(cameras.p2().single().0) - .insert(ActiveEditorCamera {}); + .insert(ActiveEditorCamera); *has_decided_initial_cam = true; } (true, true) => { camera_state.editor_cam = EditorCamKind::D3PanOrbit; commands .entity(cameras.p2().single().0) - .insert(ActiveEditorCamera {}); + .insert(ActiveEditorCamera); *has_decided_initial_cam = true; } (false, false) => return, diff --git a/crates/bevy_editor_pls_default_windows/src/gizmos.rs b/crates/bevy_editor_pls_default_windows/src/gizmos.rs index 49a4339..71428dd 100644 --- a/crates/bevy_editor_pls_default_windows/src/gizmos.rs +++ b/crates/bevy_editor_pls_default_windows/src/gizmos.rs @@ -230,61 +230,4 @@ fn add_gizmo_markers( )); }); } -} - -// fn draw_gizmo( -// ui: &mut egui::Ui, -// world: &mut World, -// selected_entities: &SelectedEntities, -// gizmo_mode: GizmoMode, -// ) { -// for entity in selected_entities.iter() { -// world.entity_mut(entity).insert(transform_gizmo_bevy::GizmoTarget::default()); -// info!("Inserted GizmoTarget to entity: {:?}", entity); -// } -// // let Ok((cam_transform, projection)) = world -// // .query_filtered::<(&GlobalTransform, &Projection), With>() -// // .get_single(world) -// // else { -// // return; -// // }; -// // let view_matrix = Mat4::from(cam_transform.affine().inverse()); -// // let projection_matrix = projection.get_projection_matrix(); - -// // if selected_entities.len() != 1 { -// // return; -// // } - -// // for selected in selected_entities.iter() { -// // // let Some(global_transform) = world.get::(selected) else { -// // // continue; -// // // }; -// // // let model_matrix = global_transform.compute_matrix(); - -// // // let Some(result) = transform_gizmo_bevy::Gizmo::new(selected) -// // // .model_matrix(model_matrix.into()) -// // // .view_matrix(view_matrix.into()) -// // // .projection_matrix(projection_matrix.into()) -// // // .orientation(transform_gizmo_bevy::GizmoOrientation::Local) -// // // .mode(gizmo_mode) -// // // .interact(ui) -// // // else { -// // // continue; -// // // }; - -// // // let global_affine = global_transform.affine(); - -// // // let mut transform = world.get_mut::(selected).unwrap(); - -// // // let parent_affine = global_affine * transform.compute_affine().inverse(); -// // // let inverse_parent_transform = GlobalTransform::from(parent_affine.inverse()); - -// // // let global_transform = Transform { -// // // translation: result.translation.into(), -// // // rotation: result.rotation.into(), -// // // scale: result.scale.into(), -// // // }; - -// // // *transform = (inverse_parent_transform * global_transform).into(); -// // } -// } +} \ No newline at end of file From 0027011644562a4c000c079ed767cc7c6ca0b09c Mon Sep 17 00:00:00 2001 From: ActuallyHappening <105958073+ActuallyHappening@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:06:53 +1000 Subject: [PATCH 06/14] fix: More defensive programming to avoid panics --- .../src/cameras/mod.rs | 6 ++--- .../src/gizmos.rs | 26 ++++++++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs b/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs index 3d61b05..5982018 100644 --- a/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs +++ b/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs @@ -604,7 +604,7 @@ fn set_main_pass_viewport( } }); - cameras.iter_mut().for_each(|mut cam| { - cam.viewport = viewport.clone(); - }); + cameras + .iter_mut() + .for_each(|mut cam| cam.viewport.clone_from(&viewport)); } diff --git a/crates/bevy_editor_pls_default_windows/src/gizmos.rs b/crates/bevy_editor_pls_default_windows/src/gizmos.rs index 71428dd..2938b14 100644 --- a/crates/bevy_editor_pls_default_windows/src/gizmos.rs +++ b/crates/bevy_editor_pls_default_windows/src/gizmos.rs @@ -69,13 +69,15 @@ impl EditorWindow for GizmoWindow { entities: Query, Without)>, ) { for entity in entities.iter() { + if let Some(mut entity) = commands.get_entity(entity) { trace!( "Hydrating a gizmo on entity {:?} because it is selected", - entity + entity.id() ); - // implicitly assumes it is the only gizmo system in the world, + // implicitly assumes it is the only gizmo target in the world, // otherwise setting [GizmoTarget].is_focussed may be necessary - commands.entity(entity).insert(GizmoTarget::default()); + entity.insert(GizmoTarget::default()); + } } } @@ -85,11 +87,13 @@ impl EditorWindow for GizmoWindow { entities: Query, Without)>, ) { for entity in entities.iter() { - commands.entity(entity).remove::(); - debug!( - "Removing GizmoTarget from entity {:?} because it has lost focus", - entity - ); + if let Some(mut entity) = commands.get_entity(entity) { + entity.remove::(); + debug!( + "Removing GizmoTarget from entity {:?} because it has lost focus", + entity.id() + ); + } } } @@ -101,7 +105,9 @@ impl EditorWindow for GizmoWindow { let selected_entities = hierarchy_state.selected.iter(); for entity in selected_entities { - world.entity_mut(entity).insert(EntityShouldShowGizmo); + if let Some(mut entity) = world.get_entity_mut(entity) { + entity.insert(EntityShouldShowGizmo); + } } world.run_system_once(hydrate_gizmos); @@ -230,4 +236,4 @@ fn add_gizmo_markers( )); }); } -} \ No newline at end of file +} From df9dfc2e46fa78a5ae5208176a5f5e0eb77d6c24 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Mon, 24 Jun 2024 15:40:17 +0200 Subject: [PATCH 07/14] Change bevy dependencies to 0.14.0-rc in Cargo.toml --- crates/bevy_editor_pls/Cargo.toml | 4 ++-- crates/bevy_editor_pls_core/Cargo.toml | 2 +- crates/bevy_editor_pls_default_windows/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_editor_pls/Cargo.toml b/crates/bevy_editor_pls/Cargo.toml index 3b32f21..bb3b625 100644 --- a/crates/bevy_editor_pls/Cargo.toml +++ b/crates/bevy_editor_pls/Cargo.toml @@ -22,13 +22,13 @@ default = ["default_windows"] [dependencies] bevy_editor_pls_core.workspace = true bevy_editor_pls_default_windows = { workspace = true, optional = true } -bevy = { version = "0.13", default-features = false, features = ["x11"] } +bevy = { version = "0.14.0-rc", default-features = false, features = ["x11"] } egui.workspace = true transform-gizmo-bevy.workspace = true # bevy_framepace = { version = "0.12", default-features = false } [dev-dependencies] -bevy = { version = "0.13", default-features = false, features = [ +bevy = { version = "0.14.0-rc", default-features = false, features = [ "bevy_winit", "bevy_core_pipeline", "x11", diff --git a/crates/bevy_editor_pls_core/Cargo.toml b/crates/bevy_editor_pls_core/Cargo.toml index a39a774..88c845c 100644 --- a/crates/bevy_editor_pls_core/Cargo.toml +++ b/crates/bevy_editor_pls_core/Cargo.toml @@ -8,7 +8,7 @@ description.workspace = true readme.workspace = true [dependencies] -bevy = { version = "0.13", default-features = false } +bevy = { version = "0.14.0-rc", default-features = false } bevy-inspector-egui.workspace = true indexmap = "2" egui_dock.workspace = true diff --git a/crates/bevy_editor_pls_default_windows/Cargo.toml b/crates/bevy_editor_pls_default_windows/Cargo.toml index 18c0095..c32b1f2 100644 --- a/crates/bevy_editor_pls_default_windows/Cargo.toml +++ b/crates/bevy_editor_pls_default_windows/Cargo.toml @@ -11,7 +11,7 @@ readme.workspace = true highlight_changes = ["bevy-inspector-egui/highlight_changes"] [dependencies] -bevy = { version = "0.13", default-features = false, features = [ +bevy = { version = "0.14.0-rc", default-features = false, features = [ "bevy_scene", "bevy_text", "bevy_ui", From 73257a1d718efc537c5ac7ada0e48890173ebc31 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Mon, 24 Jun 2024 17:51:10 +0200 Subject: [PATCH 08/14] Use app.world_mut() or .world() instead of .world Addresses Bevy [9202](https://github.com/bevyengine/bevy/pull/9202) --- crates/bevy_editor_pls/src/lib.rs | 4 ++-- crates/bevy_editor_pls_core/src/lib.rs | 6 +++--- .../src/debug_settings/debugdump.rs | 10 +++++----- crates/bevy_editor_pls_default_windows/src/gizmos.rs | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/bevy_editor_pls/src/lib.rs b/crates/bevy_editor_pls/src/lib.rs index 13c3db7..aeaddb9 100644 --- a/crates/bevy_editor_pls/src/lib.rs +++ b/crates/bevy_editor_pls/src/lib.rs @@ -85,7 +85,7 @@ impl Plugin for EditorPlugin { if window.title == "Bevy App" { window.title = "bevy_editor_pls".into(); } - let entity = app.world.spawn(window); + let entity = app.world_mut().spawn(window); WindowRef::Entity(entity.id()) } EditorWindowPlacement::Window(entity) => WindowRef::Entity(entity), @@ -136,7 +136,7 @@ impl Plugin for EditorPlugin { app.insert_resource(controls::EditorControls::default_bindings()) .add_systems(Update, controls::editor_controls_system); - let mut internal_state = app.world.resource_mut::(); + let mut internal_state = app.world_mut().resource_mut::(); let [game, _inspector] = internal_state.split_right::(egui_dock::NodeIndex::root(), 0.75); diff --git a/crates/bevy_editor_pls_core/src/lib.rs b/crates/bevy_editor_pls_core/src/lib.rs index 4b91e5a..755026c 100644 --- a/crates/bevy_editor_pls_core/src/lib.rs +++ b/crates/bevy_editor_pls_core/src/lib.rs @@ -39,7 +39,7 @@ impl Plugin for WindowSetupPlugin { impl AddEditorWindow for App { fn add_editor_window(&mut self) -> &mut Self { - let mut editor = self.world.get_resource_mut::().expect("Editor resource missing. Make sure to add the `EditorPlugin` before calling `app.add_editor_window`."); + let mut editor = self.world_mut().get_resource_mut::().expect("Editor resource missing. Make sure to add the `EditorPlugin` before calling `app.add_editor_window`."); editor.add_window::(); self.add_plugins(WindowSetupPlugin::(PhantomData)); @@ -69,9 +69,9 @@ impl Plugin for EditorPlugin { let (window_entity, always_active) = match self.window { WindowRef::Primary => { let entity = app - .world + .world_mut() .query_filtered::>() - .single(&app.world); + .single(&app.world()); (entity, false) } WindowRef::Entity(entity) => (entity, true), diff --git a/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs b/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs index 509999d..a870dd1 100644 --- a/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs +++ b/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs @@ -24,7 +24,7 @@ pub fn setup(app: &mut App) { return; } }; - let render_graph = render_app.world.get_resource::().unwrap(); + let render_graph = render_app.world().get_resource::().unwrap(); let schedule_settings = schedule_graph::settings::Settings { include_system: Some(Box::new(|system| { @@ -35,18 +35,18 @@ pub fn setup(app: &mut App) { let rendergraph_settings = render_graph::settings::Settings::default(); let update_schedule = app.get_schedule(Update).map(|schedule| { - schedule_graph::schedule_graph_dot(schedule, &app.world, &schedule_settings) + schedule_graph::schedule_graph_dot(schedule, &app.world(), &schedule_settings) }); let fixed_update_schedule = app.get_schedule(FixedUpdate).map(|schedule| { - schedule_graph::schedule_graph_dot(schedule, &app.world, &schedule_settings) + schedule_graph::schedule_graph_dot(schedule, &app.world(), &schedule_settings) }); let render_main_schedule = render_app.get_schedule(Render).map(|schedule| { - schedule_graph::schedule_graph_dot(schedule, &app.world, &schedule_settings) + schedule_graph::schedule_graph_dot(schedule, &app.world(), &schedule_settings) }); let render_extract_schedule = render_app.get_schedule(ExtractSchedule).map(|schedule| { - schedule_graph::schedule_graph_dot(schedule, &app.world, &schedule_settings) + schedule_graph::schedule_graph_dot(schedule, &app.world(), &schedule_settings) }); let render_graph = render_graph::render_graph_dot(render_graph, &rendergraph_settings); diff --git a/crates/bevy_editor_pls_default_windows/src/gizmos.rs b/crates/bevy_editor_pls_default_windows/src/gizmos.rs index 2938b14..3943d3c 100644 --- a/crates/bevy_editor_pls_default_windows/src/gizmos.rs +++ b/crates/bevy_editor_pls_default_windows/src/gizmos.rs @@ -117,7 +117,7 @@ impl EditorWindow for GizmoWindow { } fn app_setup(app: &mut App) { - let mut materials = app.world.resource_mut::>(); + let mut materials = app.world_mut().resource_mut::>(); let material_light = materials.add(StandardMaterial { base_color: Color::rgba_u8(222, 208, 103, 255), unlit: true, @@ -133,10 +133,10 @@ impl EditorWindow for GizmoWindow { ..default() }); - let mut meshes = app.world.resource_mut::>(); + let mut meshes = app.world_mut().resource_mut::>(); let sphere = meshes.add(Sphere { radius: 0.3 }); - app.world.insert_resource(GizmoMarkerConfig { + app.world_mut().insert_resource(GizmoMarkerConfig { point_light_mesh: sphere.clone(), point_light_material: material_light.clone(), directional_light_mesh: sphere.clone(), From 5dc8c40d08b707190e2da6a2b7315cb373b8bda9 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Mon, 24 Jun 2024 18:04:39 +0200 Subject: [PATCH 09/14] Clone RenderLayers when necessary & change underlying type to usize Addresses Bevy [13317](https://github.com/bevyengine/bevy/pull/13317) --- crates/bevy_editor_pls_default_windows/src/cameras/mod.rs | 6 +++--- crates/bevy_editor_pls_default_windows/src/gizmos.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs b/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs index 5982018..42601d5 100644 --- a/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs +++ b/crates/bevy_editor_pls_default_windows/src/cameras/mod.rs @@ -20,7 +20,7 @@ use crate::hierarchy::{HideInEditor, HierarchyWindow}; use self::camera_3d_panorbit::PanOrbitCamera; -pub const EDITOR_RENDER_LAYER: u8 = 19; +pub const EDITOR_RENDER_LAYER: usize = 19; // Present on all editor cameras #[derive(Component)] @@ -234,7 +234,7 @@ fn spawn_editor_cameras(mut commands: Commands, editor: Res) { Name::new("Editor Camera 3D Free"), NotInScene, GizmoCamera, - render_layers, + render_layers.clone(), )); commands.spawn(( @@ -257,7 +257,7 @@ fn spawn_editor_cameras(mut commands: Commands, editor: Res) { Name::new("Editor Camera 3D Pan/Orbit"), NotInScene, GizmoCamera, - render_layers, + render_layers.clone(), )); commands.spawn(( diff --git a/crates/bevy_editor_pls_default_windows/src/gizmos.rs b/crates/bevy_editor_pls_default_windows/src/gizmos.rs index 3943d3c..ff61621 100644 --- a/crates/bevy_editor_pls_default_windows/src/gizmos.rs +++ b/crates/bevy_editor_pls_default_windows/src/gizmos.rs @@ -191,7 +191,7 @@ fn add_gizmo_markers( .entity(entity) .insert(HasGizmoMarker) .with_children(|commands| { - commands.spawn((f(), render_layers, Name::new(name))); + commands.spawn((f(), render_layers.clone(), Name::new(name))); }); } } @@ -231,7 +231,7 @@ fn add_gizmo_markers( material: gizmo_marker_meshes.camera_material.clone_weak(), ..default() }, - render_layers, + render_layers.clone(), Name::new("Camera Gizmo"), )); }); From be6eab0a184abc8a4df10f01827debed35c88e03 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Mon, 24 Jun 2024 18:05:47 +0200 Subject: [PATCH 10/14] Match app.get_sub_app as Option instead of Result Addresses Bevy[9202](https://github.com/bevyengine/bevy/pull/9202) --- .../src/debug_settings/debugdump.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs b/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs index a870dd1..05b31bc 100644 --- a/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs +++ b/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs @@ -19,8 +19,8 @@ pub struct DotGraphs { pub fn setup(app: &mut App) { let render_app = match app.get_sub_app(RenderApp) { - Ok(render_app) => render_app, - Err(_label) => { + Some(render_app) => render_app, + None => { return; } }; From 76f6f9e013bef2505404f759f353f04fb4098f07 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Mon, 24 Jun 2024 18:07:20 +0200 Subject: [PATCH 11/14] Use Color::srgb* instead of Color::rgb* Addresses Bevy [12163](https://github.com/bevyengine/bevy/pull/12163) --- crates/bevy_editor_pls_default_windows/src/gizmos.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_editor_pls_default_windows/src/gizmos.rs b/crates/bevy_editor_pls_default_windows/src/gizmos.rs index ff61621..46dfa02 100644 --- a/crates/bevy_editor_pls_default_windows/src/gizmos.rs +++ b/crates/bevy_editor_pls_default_windows/src/gizmos.rs @@ -119,14 +119,14 @@ impl EditorWindow for GizmoWindow { fn app_setup(app: &mut App) { let mut materials = app.world_mut().resource_mut::>(); let material_light = materials.add(StandardMaterial { - base_color: Color::rgba_u8(222, 208, 103, 255), + base_color: Color::srgba_u8(222, 208, 103, 255), unlit: true, fog_enabled: false, alpha_mode: AlphaMode::Add, ..default() }); let material_camera = materials.add(StandardMaterial { - base_color: Color::rgb(1.0, 1.0, 1.0), + base_color: Color::srgb(1.0, 1.0, 1.0), unlit: true, fog_enabled: false, alpha_mode: AlphaMode::Multiply, From ba608668bbb29b3392444c9a1268dd6db46a7784 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Mon, 24 Jun 2024 18:08:03 +0200 Subject: [PATCH 12/14] Change to DynamicScene::serialize(&TypeRegistry) Addresses Bevy [12715](https://github.com/bevyengine/bevy/pull/12715) --- crates/bevy_editor_pls_default_windows/src/scenes.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bevy_editor_pls_default_windows/src/scenes.rs b/crates/bevy_editor_pls_default_windows/src/scenes.rs index bba31ea..faabbda 100644 --- a/crates/bevy_editor_pls_default_windows/src/scenes.rs +++ b/crates/bevy_editor_pls_default_windows/src/scenes.rs @@ -64,12 +64,13 @@ fn save_world( name: &str, entities: std::collections::HashSet, ) -> Result<(), Box> { - let type_registry = world.get_resource::().unwrap(); + let type_registry_arc = world.get_resource::().unwrap(); + let type_registry = type_registry_arc.read(); let mut scene_builder = DynamicSceneBuilder::from_world(world); scene_builder = scene_builder.extract_entities(entities.into_iter()); let scene = scene_builder.build(); - let ron = scene.serialize_ron(type_registry)?; + let ron = scene.serialize(&type_registry)?; std::fs::write(name, ron)?; Ok(()) } From 8a71420427a68b0d5169b2de97089907b1972432 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Tue, 25 Jun 2024 17:04:42 +0200 Subject: [PATCH 13/14] Temporarily patch dependencies to forks that support bevy 0.14.0-rc too --- Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 87539cd..74b631e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,12 @@ repository = "https://github.com/jakobhellermann/bevy_editor_pls" description = "In-App editor tools for bevy apps" readme = "README.md" +[patch.crates-io] +bevy_egui = { git = "https://github.com/zhaop/bevy_egui.git", branch = "bevy-0.14" } +bevy-inspector-egui = { git = "https://github.com/kristoff3r/bevy-inspector-egui.git", branch = "main", package = "bevy-inspector-egui" } +bevy_mod_debugdump = { git = "https://github.com/Vrixyz/bevy_mod_debugdump.git", branch = "bevy_0.14" } +transform-gizmo-bevy = { git = "https://github.com/zhaop/transform-gizmo.git", branch = "bevy-0.14.0-rc", package = "transform-gizmo-bevy" } + [workspace.dependencies] bevy_editor_pls = { version = "0.8.1", path = "crates/bevy_editor_pls" } bevy_editor_pls_core = { version = "0.8.1", path = "crates/bevy_editor_pls_core" } From a9e1867a707b94612958c54d80a8ca86731f96c5 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Tue, 25 Jun 2024 17:19:10 +0200 Subject: [PATCH 14/14] Update colors in examples from rgb* -> srgb* Addresses Bevy [12163](https://github.com/bevyengine/bevy/pull/12163) --- crates/bevy_editor_pls/examples/ui.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/bevy_editor_pls/examples/ui.rs b/crates/bevy_editor_pls/examples/ui.rs index 70e9aa0..2b55009 100644 --- a/crates/bevy_editor_pls/examples/ui.rs +++ b/crates/bevy_editor_pls/examples/ui.rs @@ -43,7 +43,7 @@ fn setup(mut commands: Commands, asset_server: Res) { border: UiRect::all(Val::Px(2.0)), ..default() }, - background_color: Color::rgb(0.65, 0.65, 0.65).into(), + background_color: Color::srgb(0.65, 0.65, 0.65).into(), ..default() }) .with_children(|parent| { @@ -55,7 +55,7 @@ fn setup(mut commands: Commands, asset_server: Res) { height: Val::Percent(100.0), ..default() }, - background_color: Color::rgb(0.15, 0.15, 0.15).into(), + background_color: Color::srgb(0.15, 0.15, 0.15).into(), ..default() }) .with_children(|parent| { @@ -86,7 +86,7 @@ fn setup(mut commands: Commands, asset_server: Res) { height: Val::Percent(100.0), ..default() }, - background_color: Color::rgb(0.15, 0.15, 0.15).into(), + background_color: Color::srgb(0.15, 0.15, 0.15).into(), ..default() }) .with_children(|parent| { @@ -122,7 +122,7 @@ fn setup(mut commands: Commands, asset_server: Res) { overflow: Overflow::clip(), ..default() }, - background_color: Color::rgb(0.10, 0.10, 0.10).into(), + background_color: Color::srgb(0.10, 0.10, 0.10).into(), ..default() }) .with_children(|parent| { @@ -178,7 +178,7 @@ fn setup(mut commands: Commands, asset_server: Res) { border: UiRect::all(Val::Px(20.0)), ..default() }, - background_color: Color::rgb(0.4, 0.4, 1.0).into(), + background_color: Color::srgb(0.4, 0.4, 1.0).into(), ..default() }) .with_children(|parent| { @@ -188,7 +188,7 @@ fn setup(mut commands: Commands, asset_server: Res) { height: Val::Percent(100.0), ..default() }, - background_color: Color::rgb(0.8, 0.8, 1.0).into(), + background_color: Color::srgb(0.8, 0.8, 1.0).into(), ..default() }); }); @@ -213,7 +213,7 @@ fn setup(mut commands: Commands, asset_server: Res) { height: Val::Px(100.0), ..default() }, - background_color: Color::rgb(1.0, 0.0, 0.0).into(), + background_color: Color::srgb(1.0, 0.0, 0.0).into(), ..default() }) .with_children(|parent| { @@ -226,7 +226,7 @@ fn setup(mut commands: Commands, asset_server: Res) { bottom: Val::Px(20.0), ..default() }, - background_color: Color::rgb(1.0, 0.3, 0.3).into(), + background_color: Color::srgb(1.0, 0.3, 0.3).into(), ..default() }); parent.spawn(NodeBundle { @@ -238,7 +238,7 @@ fn setup(mut commands: Commands, asset_server: Res) { bottom: Val::Px(40.0), ..default() }, - background_color: Color::rgb(1.0, 0.5, 0.5).into(), + background_color: Color::srgb(1.0, 0.5, 0.5).into(), ..default() }); parent.spawn(NodeBundle { @@ -250,7 +250,7 @@ fn setup(mut commands: Commands, asset_server: Res) { bottom: Val::Px(60.0), ..default() }, - background_color: Color::rgb(1.0, 0.7, 0.7).into(), + background_color: Color::srgb(1.0, 0.7, 0.7).into(), ..default() }); // alpha test @@ -263,7 +263,7 @@ fn setup(mut commands: Commands, asset_server: Res) { bottom: Val::Px(80.0), ..default() }, - background_color: Color::rgba(1.0, 0.9, 0.9, 0.4).into(), + background_color: Color::srgba(1.0, 0.9, 0.9, 0.4).into(), ..default() }); });