From 67de3158be46c0725a626cbe0c49c42c009baf29 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Thu, 10 Jul 2025 22:39:05 -0500 Subject: [PATCH 1/6] Add advanced entity outline calculations The changes add sophisticated AABB (Axis-Aligned Bounding Box) calculations for accurately drawing outlines around selected entities, handling various entity types like meshes and sprites, and properly accounting for hierarchies and transformations. --- Cargo.toml | 1 + bevy_editor_panes/bevy_3d_viewport/Cargo.toml | 1 + .../bevy_3d_viewport/src/outline_gizmo.rs | 207 +++++++++++++++++- 3 files changed, 205 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a9a5a24a..bec090f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ unused_qualifications = "warn" bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "a3d406dd497205253e34ace757ab0076d50eec14", features = [ "wayland", ] } +bevy_render = { git = "https://github.com/bevyengine/bevy.git", rev = "a3d406dd497205253e34ace757ab0076d50eec14" } bevy_derive = { git = "https://github.com/bevyengine/bevy.git", rev = "a3d406dd497205253e34ace757ab0076d50eec14" } bevy_macro_utils = { git = "https://github.com/bevyengine/bevy.git", rev = "a3d406dd497205253e34ace757ab0076d50eec14" } thiserror = "2.0" diff --git a/bevy_editor_panes/bevy_3d_viewport/Cargo.toml b/bevy_editor_panes/bevy_3d_viewport/Cargo.toml index 7bb80d70..102a1a54 100644 --- a/bevy_editor_panes/bevy_3d_viewport/Cargo.toml +++ b/bevy_editor_panes/bevy_3d_viewport/Cargo.toml @@ -10,6 +10,7 @@ bevy_editor_cam.workspace = true bevy_editor_styles.workspace = true bevy_infinite_grid.workspace = true bevy_editor_core.workspace = true +bevy_render.workspace = true [lints] workspace = true diff --git a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs index 824a55c6..8ae9d334 100644 --- a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs +++ b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs @@ -1,5 +1,6 @@ use bevy::prelude::*; use bevy_editor_core::SelectedEntity; +use bevy_render::primitives::Aabb; pub struct OutlineGizmoPlugin; impl Plugin for OutlineGizmoPlugin { @@ -18,20 +19,218 @@ pub struct ShowOutlines(pub bool); #[derive(Component)] struct GizmoToggleText; +/// Draw an outline for a world-space AABB +fn draw_world_aabb_outline(gizmos: &mut Gizmos, aabb: &Aabb) { + let min = aabb.min(); + let max = aabb.max(); + let center = (min + max) * 0.5; + let size = max - min; + + // Draw the cuboid outline at the AABB center with the AABB size + let outline_transform = Transform::from_translation(center.into()).with_scale(size.into()); + + gizmos.cuboid(outline_transform, Color::srgb(1.0, 0.5, 0.0)); // Orange outline +} + +/// Fallback outline for entities without proper bounds +fn draw_fallback_outline(gizmos: &mut Gizmos, global_transform: &GlobalTransform) { + let translation = global_transform.translation(); + let default_size = Vec3::splat(1.0); + + let outline_transform = Transform::from_translation(translation).with_scale(default_size); + + gizmos.cuboid(outline_transform, Color::srgb(0.5, 0.5, 0.5)); // Gray outline +} + pub fn outline_gizmo_system( show: Res, - query: Query<&Transform>, selected_entity: Res, mut gizmos: Gizmos, + // Comprehensive queries for different entity types + mesh_query: Query<(&GlobalTransform, &Mesh3d, Option<&Aabb>)>, + sprite_query: Query<(&GlobalTransform, &Sprite), Without>, + // Query for entities with computed AABBs (like from rendering system) + aabb_query: Query<(&GlobalTransform, &Aabb), (Without, Without)>, + // Query for entities with children that might contribute to bounds + children_query: Query<&Children>, + // Fallback query for any entity with just a transform + transform_query: Query<&GlobalTransform, (Without, Without, Without)>, + meshes: Res>, ) { if !show.0 { return; } - if let Some(entity) = selected_entity.0 { - if let Ok(transform) = query.get(entity) { - gizmos.cuboid(*transform, Color::srgb(1.0, 0.0, 0.0)); + + let Some(entity) = selected_entity.0 else { + return; + }; + + // Calculate the bounding box for the entity (including children) + if let Some(world_aabb) = calculate_world_aabb( + entity, + &mesh_query, + &sprite_query, + &aabb_query, + &children_query, + &transform_query, + &meshes, + ) { + draw_world_aabb_outline(&mut gizmos, &world_aabb); + } else { + // Fallback to simple transform-based outline + if let Ok(global_transform) = transform_query.get(entity) { + draw_fallback_outline(&mut gizmos, global_transform); + } + } +} + +/// Calculate the world-space AABB for an entity and optionally its children +fn calculate_world_aabb( + entity: Entity, + mesh_query: &Query<(&GlobalTransform, &Mesh3d, Option<&Aabb>)>, + sprite_query: &Query<(&GlobalTransform, &Sprite), Without>, + aabb_query: &Query<(&GlobalTransform, &Aabb), (Without, Without)>, + children_query: &Query<&Children>, + transform_query: &Query<&GlobalTransform, (Without, Without, Without)>, + meshes: &Assets, +) -> Option { + let mut combined_aabb: Option = None; + + // Helper function to combine AABBs + let mut combine_aabb = |new_aabb: Aabb| { + if let Some(existing) = combined_aabb { + combined_aabb = Some(combine_aabbs(&existing, &new_aabb)); + } else { + combined_aabb = Some(new_aabb); } + }; + + // Try to get AABB from the entity itself + if let Some(entity_aabb) = get_entity_aabb( + entity, + mesh_query, + sprite_query, + aabb_query, + transform_query, + meshes, + ) { + combine_aabb(entity_aabb); + } + + // Recursively include children's AABBs + if let Ok(children) = children_query.get(entity) { + for &child in children { + if let Some(child_aabb) = calculate_world_aabb( + child, + mesh_query, + sprite_query, + aabb_query, + children_query, + transform_query, + meshes, + ) { + combine_aabb(child_aabb); + } + } + } + + combined_aabb +} + +/// Combine two AABBs into a single AABB that encompasses both +fn combine_aabbs(a: &Aabb, b: &Aabb) -> Aabb { + let min = a.min().min(b.min()); + let max = a.max().max(b.max()); + Aabb::from_min_max(min.into(), max.into()) +} + +/// Get the AABB for a single entity +fn get_entity_aabb( + entity: Entity, + mesh_query: &Query<(&GlobalTransform, &Mesh3d, Option<&Aabb>)>, + sprite_query: &Query<(&GlobalTransform, &Sprite), Without>, + aabb_query: &Query<(&GlobalTransform, &Aabb), (Without, Without)>, + transform_query: &Query<&GlobalTransform, (Without, Without, Without)>, + meshes: &Assets, +) -> Option { + // Try mesh entities first + if let Ok((global_transform, mesh_handle, existing_aabb)) = mesh_query.get(entity) { + // Use existing AABB if available, otherwise compute from mesh + let local_aabb = if let Some(aabb) = existing_aabb { + *aabb + } else if let Some(_mesh) = meshes.get(&mesh_handle.0) { + // TODO: Compute AABB from mesh if possible + Aabb::from_min_max(Vec3::splat(-0.5), Vec3::splat(0.5)) + } else { + return None; + }; + + return Some(transform_aabb(&local_aabb, global_transform)); + } + + // Try sprite entities + if let Ok((global_transform, sprite)) = sprite_query.get(entity) { + let size = sprite.custom_size.unwrap_or(Vec2::new(1.0, 1.0)); + let local_aabb = Aabb::from_min_max( + Vec3::new(-size.x * 0.5, -size.y * 0.5, -0.01), + Vec3::new(size.x * 0.5, size.y * 0.5, 0.01), + ); + return Some(transform_aabb(&local_aabb, global_transform)); + } + + // Try entities with existing AABB components + if let Ok((global_transform, aabb)) = aabb_query.get(entity) { + return Some(transform_aabb(aabb, global_transform)); + } + + // Fallback for entities with just transforms + if let Ok(global_transform) = transform_query.get(entity) { + let default_size = 0.5; + let local_aabb = Aabb::from_min_max(Vec3::splat(-default_size), Vec3::splat(default_size)); + return Some(transform_aabb(&local_aabb, global_transform)); } + + None +} + +/// Transform a local AABB to world space using GlobalTransform +fn transform_aabb(local_aabb: &Aabb, global_transform: &GlobalTransform) -> Aabb { + let (scale, rotation, translation) = global_transform.to_scale_rotation_translation(); + + // Get the 8 corners of the AABB + let min = local_aabb.min(); + let max = local_aabb.max(); + let corners = [ + Vec3::new(min.x, min.y, min.z), + Vec3::new(max.x, min.y, min.z), + Vec3::new(min.x, max.y, min.z), + Vec3::new(max.x, max.y, min.z), + Vec3::new(min.x, min.y, max.z), + Vec3::new(max.x, min.y, max.z), + Vec3::new(min.x, max.y, max.z), + Vec3::new(max.x, max.y, max.z), + ]; + + // Transform all corners to world space + let transformed_corners: Vec = corners + .iter() + .map(|&corner| { + let scaled = corner * scale; + let rotated = rotation * scaled; + rotated + translation + }) + .collect(); + + // Find the min/max of transformed corners + let mut world_min = transformed_corners[0]; + let mut world_max = transformed_corners[0]; + + for &corner in &transformed_corners[1..] { + world_min = world_min.min(corner); + world_max = world_max.max(corner); + } + + Aabb::from_min_max(world_min, world_max) } pub fn spawn_gizmo_toggle_ui(mut commands: Commands) { From 4cd0dd42b8f29ba271db610b6d91ebc564fc592d Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Thu, 10 Jul 2025 22:57:44 -0500 Subject: [PATCH 2/6] minor changes --- bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs index 8ae9d334..730cdfae 100644 --- a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs +++ b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs @@ -46,12 +46,9 @@ pub fn outline_gizmo_system( show: Res, selected_entity: Res, mut gizmos: Gizmos, - // Comprehensive queries for different entity types mesh_query: Query<(&GlobalTransform, &Mesh3d, Option<&Aabb>)>, sprite_query: Query<(&GlobalTransform, &Sprite), Without>, - // Query for entities with computed AABBs (like from rendering system) aabb_query: Query<(&GlobalTransform, &Aabb), (Without, Without)>, - // Query for entities with children that might contribute to bounds children_query: Query<&Children>, // Fallback query for any entity with just a transform transform_query: Query<&GlobalTransform, (Without, Without, Without)>, From 1cf2891705f0fc6e5dbb123f58013633ae9318dd Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Thu, 10 Jul 2025 23:10:05 -0500 Subject: [PATCH 3/6] Extract outline gizmo queries into SystemParam struct The change extracts multiple queries used in the outline gizmo system into a dedicated `OutlineGizmoQueries` struct that implements `SystemParam` --- .../bevy_3d_viewport/src/outline_gizmo.rs | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs index 730cdfae..b32e76a8 100644 --- a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs +++ b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs @@ -1,6 +1,16 @@ use bevy::prelude::*; use bevy_editor_core::SelectedEntity; use bevy_render::primitives::Aabb; +use bevy::ecs::system::SystemParam; + +#[derive(SystemParam)] +pub struct OutlineGizmoQueries<'w, 's> { + pub mesh_query: Query<'w, 's, (&'static GlobalTransform, &'static Mesh3d, Option<&'static Aabb>)>, + pub sprite_query: Query<'w, 's, (&'static GlobalTransform, &'static Sprite), Without>, + pub aabb_query: Query<'w, 's, (&'static GlobalTransform, &'static Aabb), (Without, Without)>, + pub children_query: Query<'w, 's, &'static Children>, + pub transform_query: Query<'w, 's, &'static GlobalTransform, (Without, Without, Without)>, +} pub struct OutlineGizmoPlugin; impl Plugin for OutlineGizmoPlugin { @@ -46,12 +56,7 @@ pub fn outline_gizmo_system( show: Res, selected_entity: Res, mut gizmos: Gizmos, - mesh_query: Query<(&GlobalTransform, &Mesh3d, Option<&Aabb>)>, - sprite_query: Query<(&GlobalTransform, &Sprite), Without>, - aabb_query: Query<(&GlobalTransform, &Aabb), (Without, Without)>, - children_query: Query<&Children>, - // Fallback query for any entity with just a transform - transform_query: Query<&GlobalTransform, (Without, Without, Without)>, + queries: OutlineGizmoQueries, meshes: Res>, ) { if !show.0 { @@ -65,17 +70,17 @@ pub fn outline_gizmo_system( // Calculate the bounding box for the entity (including children) if let Some(world_aabb) = calculate_world_aabb( entity, - &mesh_query, - &sprite_query, - &aabb_query, - &children_query, - &transform_query, + &queries.mesh_query, + &queries.sprite_query, + &queries.aabb_query, + &queries.children_query, + &queries.transform_query, &meshes, ) { draw_world_aabb_outline(&mut gizmos, &world_aabb); } else { // Fallback to simple transform-based outline - if let Ok(global_transform) = transform_query.get(entity) { + if let Ok(global_transform) = queries.transform_query.get(entity) { draw_fallback_outline(&mut gizmos, global_transform); } } @@ -190,7 +195,7 @@ fn get_entity_aabb( None } -/// Transform a local AABB to world space using GlobalTransform +/// Transform a local AABB to world space using `GlobalTransform` fn transform_aabb(local_aabb: &Aabb, global_transform: &GlobalTransform) -> Aabb { let (scale, rotation, translation) = global_transform.to_scale_rotation_translation(); From e4cf901216ab387c5b25f437c0c29a0fa16bd6c2 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Thu, 10 Jul 2025 23:11:35 -0500 Subject: [PATCH 4/6] fmt --- .../bevy_3d_viewport/src/outline_gizmo.rs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs index b32e76a8..b2bb3e83 100644 --- a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs +++ b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs @@ -1,15 +1,29 @@ +use bevy::ecs::system::SystemParam; use bevy::prelude::*; use bevy_editor_core::SelectedEntity; use bevy_render::primitives::Aabb; -use bevy::ecs::system::SystemParam; #[derive(SystemParam)] pub struct OutlineGizmoQueries<'w, 's> { - pub mesh_query: Query<'w, 's, (&'static GlobalTransform, &'static Mesh3d, Option<&'static Aabb>)>, + pub mesh_query: Query< + 'w, + 's, + ( + &'static GlobalTransform, + &'static Mesh3d, + Option<&'static Aabb>, + ), + >, pub sprite_query: Query<'w, 's, (&'static GlobalTransform, &'static Sprite), Without>, - pub aabb_query: Query<'w, 's, (&'static GlobalTransform, &'static Aabb), (Without, Without)>, + pub aabb_query: Query< + 'w, + 's, + (&'static GlobalTransform, &'static Aabb), + (Without, Without), + >, pub children_query: Query<'w, 's, &'static Children>, - pub transform_query: Query<'w, 's, &'static GlobalTransform, (Without, Without, Without)>, + pub transform_query: + Query<'w, 's, &'static GlobalTransform, (Without, Without, Without)>, } pub struct OutlineGizmoPlugin; From 44556122e0d69df16dde11db4d653a28451df49f Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Wed, 16 Jul 2025 01:05:15 -0500 Subject: [PATCH 5/6] Rename outline gizmo plugin to selection box plugin --- bevy_editor_panes/bevy_3d_viewport/src/lib.rs | 4 ++-- bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bevy_editor_panes/bevy_3d_viewport/src/lib.rs b/bevy_editor_panes/bevy_3d_viewport/src/lib.rs index 1a9e2760..77f67894 100644 --- a/bevy_editor_panes/bevy_3d_viewport/src/lib.rs +++ b/bevy_editor_panes/bevy_3d_viewport/src/lib.rs @@ -18,7 +18,7 @@ use bevy_infinite_grid::{InfiniteGrid, InfiniteGridPlugin, InfiniteGridSettings} use bevy_pane_layout::prelude::*; use view_gizmo::{spawn_view_gizmo_target_texture, ViewGizmoPlugin}; -use crate::outline_gizmo::OutlineGizmoPlugin; +use crate::outline_gizmo::SelectionBoxPlugin; mod outline_gizmo; mod view_gizmo; @@ -47,7 +47,7 @@ impl Plugin for Viewport3dPanePlugin { app.add_plugins(InfiniteGridPlugin); } - app.add_plugins((DefaultEditorCamPlugins, ViewGizmoPlugin, OutlineGizmoPlugin)) + app.add_plugins((DefaultEditorCamPlugins, ViewGizmoPlugin, SelectionBoxPlugin)) .add_systems(Startup, setup) .add_systems( PreUpdate, diff --git a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs index b2bb3e83..3c20ef04 100644 --- a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs +++ b/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs @@ -4,7 +4,7 @@ use bevy_editor_core::SelectedEntity; use bevy_render::primitives::Aabb; #[derive(SystemParam)] -pub struct OutlineGizmoQueries<'w, 's> { +pub struct SelectionBoxQueries<'w, 's> { pub mesh_query: Query< 'w, 's, @@ -26,8 +26,8 @@ pub struct OutlineGizmoQueries<'w, 's> { Query<'w, 's, &'static GlobalTransform, (Without, Without, Without)>, } -pub struct OutlineGizmoPlugin; -impl Plugin for OutlineGizmoPlugin { +pub struct SelectionBoxPlugin; +impl Plugin for SelectionBoxPlugin { fn build(&self, app: &mut App) { app.init_resource::() .add_systems(Startup, spawn_gizmo_toggle_ui) @@ -70,7 +70,7 @@ pub fn outline_gizmo_system( show: Res, selected_entity: Res, mut gizmos: Gizmos, - queries: OutlineGizmoQueries, + queries: SelectionBoxQueries, meshes: Res>, ) { if !show.0 { From 8507ffb610785348bc5cddcc7000e9a266e6cdbb Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Wed, 16 Jul 2025 01:27:29 -0500 Subject: [PATCH 6/6] Rename outline gizmo to selection box The changes are focused on renaming the outline gizmo functionality to selection box, which includes renaming the module, component, functions and UI text for better clarity and consistency. --- bevy_editor_panes/bevy_3d_viewport/src/lib.rs | 4 +- .../{outline_gizmo.rs => selection_box.rs} | 54 +++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) rename bevy_editor_panes/bevy_3d_viewport/src/{outline_gizmo.rs => selection_box.rs} (85%) diff --git a/bevy_editor_panes/bevy_3d_viewport/src/lib.rs b/bevy_editor_panes/bevy_3d_viewport/src/lib.rs index 77f67894..e1989f8f 100644 --- a/bevy_editor_panes/bevy_3d_viewport/src/lib.rs +++ b/bevy_editor_panes/bevy_3d_viewport/src/lib.rs @@ -18,9 +18,9 @@ use bevy_infinite_grid::{InfiniteGrid, InfiniteGridPlugin, InfiniteGridSettings} use bevy_pane_layout::prelude::*; use view_gizmo::{spawn_view_gizmo_target_texture, ViewGizmoPlugin}; -use crate::outline_gizmo::SelectionBoxPlugin; +use crate::selection_box::SelectionBoxPlugin; -mod outline_gizmo; +mod selection_box; mod view_gizmo; /// The identifier for the 3D Viewport. diff --git a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs b/bevy_editor_panes/bevy_3d_viewport/src/selection_box.rs similarity index 85% rename from bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs rename to bevy_editor_panes/bevy_3d_viewport/src/selection_box.rs index 3c20ef04..bc968335 100644 --- a/bevy_editor_panes/bevy_3d_viewport/src/outline_gizmo.rs +++ b/bevy_editor_panes/bevy_3d_viewport/src/selection_box.rs @@ -29,22 +29,22 @@ pub struct SelectionBoxQueries<'w, 's> { pub struct SelectionBoxPlugin; impl Plugin for SelectionBoxPlugin { fn build(&self, app: &mut App) { - app.init_resource::() - .add_systems(Startup, spawn_gizmo_toggle_ui) - .add_systems(Update, outline_gizmo_system) - .add_systems(Update, update_gizmo_toggle_text); + app.init_resource::() + .add_systems(Startup, spawn_selection_box_toggle_ui) + .add_systems(Update, selection_box_system) + .add_systems(Update, update_selection_box_toggle_text); } } #[derive(Resource, Default)] -pub struct ShowOutlines(pub bool); +pub struct ShowSelectionBox(pub bool); // Marker for the toggle button text #[derive(Component)] -struct GizmoToggleText; +struct SelectionBoxToggleText; /// Draw an outline for a world-space AABB -fn draw_world_aabb_outline(gizmos: &mut Gizmos, aabb: &Aabb) { +fn draw_selection_box(gizmos: &mut Gizmos, aabb: &Aabb) { let min = aabb.min(); let max = aabb.max(); let center = (min + max) * 0.5; @@ -57,7 +57,7 @@ fn draw_world_aabb_outline(gizmos: &mut Gizmos, aabb: &Aabb) { } /// Fallback outline for entities without proper bounds -fn draw_fallback_outline(gizmos: &mut Gizmos, global_transform: &GlobalTransform) { +fn draw_fallback_selection_box(gizmos: &mut Gizmos, global_transform: &GlobalTransform) { let translation = global_transform.translation(); let default_size = Vec3::splat(1.0); @@ -66,8 +66,8 @@ fn draw_fallback_outline(gizmos: &mut Gizmos, global_transform: &GlobalTransform gizmos.cuboid(outline_transform, Color::srgb(0.5, 0.5, 0.5)); // Gray outline } -pub fn outline_gizmo_system( - show: Res, +pub fn selection_box_system( + show: Res, selected_entity: Res, mut gizmos: Gizmos, queries: SelectionBoxQueries, @@ -91,11 +91,11 @@ pub fn outline_gizmo_system( &queries.transform_query, &meshes, ) { - draw_world_aabb_outline(&mut gizmos, &world_aabb); + draw_selection_box(&mut gizmos, &world_aabb); } else { - // Fallback to simple transform-based outline + // Fallback to simple transform-based selection box if let Ok(global_transform) = queries.transform_query.get(entity) { - draw_fallback_outline(&mut gizmos, global_transform); + draw_fallback_selection_box(&mut gizmos, global_transform); } } } @@ -249,8 +249,8 @@ fn transform_aabb(local_aabb: &Aabb, global_transform: &GlobalTransform) -> Aabb Aabb::from_min_max(world_min, world_max) } -pub fn spawn_gizmo_toggle_ui(mut commands: Commands) { - info!("Spawning Gizmo Toggle UI"); +pub fn spawn_selection_box_toggle_ui(mut commands: Commands) { + info!("Spawning Selection Box Toggle UI"); commands .spawn(( Node { @@ -267,29 +267,29 @@ pub fn spawn_gizmo_toggle_ui(mut commands: Commands) { )) .with_children(|parent| { parent.spawn(( - Text::new("Show Outlines"), + Text::new("Show Selection Box"), TextFont::from_font_size(10.0), - GizmoToggleText, + SelectionBoxToggleText, )); }) .observe( - |_trigger: On>, mut show_outlines: ResMut| { - show_outlines.0 = !show_outlines.0; + |_trigger: On>, mut show_selection: ResMut| { + show_selection.0 = !show_selection.0; }, ); } -// System to update the button text when ShowOutlines changes -fn update_gizmo_toggle_text( - show_outlines: Res, - mut query: Query<&mut Text, With>, +// System to update the button text when ShowSelectionBox changes +fn update_selection_box_toggle_text( + show_selection: Res, + mut query: Query<&mut Text, With>, ) { - if show_outlines.is_changed() { + if show_selection.is_changed() { for mut text in &mut query { - text.0 = if show_outlines.0 { - "Hide Outlines".into() + text.0 = if show_selection.0 { + "Hide Selection Box".into() } else { - "Show Outlines".into() + "Show Selection Box".into() }; } }