From e2b35dd839abbe397cb2378b60e45325754e3b2a Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Thu, 31 Aug 2023 10:43:01 +0800 Subject: [PATCH] Change outline update to use set_changed() Signed-off-by: Luca Della Vedova --- rmf_site_editor/src/interaction/mod.rs | 1 - rmf_site_editor/src/interaction/outline.rs | 22 ---------------------- rmf_site_editor/src/site/door.rs | 22 +++++++++++++++++++--- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/rmf_site_editor/src/interaction/mod.rs b/rmf_site_editor/src/interaction/mod.rs index a8905922..0c702aa5 100644 --- a/rmf_site_editor/src/interaction/mod.rs +++ b/rmf_site_editor/src/interaction/mod.rs @@ -197,7 +197,6 @@ impl Plugin for InteractionPlugin { .with_system(update_point_visual_cues.after(maintain_selected_entities)) .with_system(update_path_visual_cues.after(maintain_selected_entities)) .with_system(update_outline_visualization.after(maintain_selected_entities)) - .with_system(update_outline_for_new_meshes.after(maintain_selected_entities)) .with_system(update_highlight_visualization.after(maintain_selected_entities)) .with_system( update_cursor_hover_visualization.after(maintain_selected_entities), diff --git a/rmf_site_editor/src/interaction/outline.rs b/rmf_site_editor/src/interaction/outline.rs index 88cd79db..0f6df80a 100644 --- a/rmf_site_editor/src/interaction/outline.rs +++ b/rmf_site_editor/src/interaction/outline.rs @@ -209,25 +209,3 @@ pub fn update_outline_visualization( } } } - -pub fn update_outline_for_new_meshes( - mut commands: Commands, - new_meshes: Query>>, - outlines: Query<(&OutlineVolume, &SetOutlineDepth)>, - parents: Query<&Parent>, -) { - for e in &new_meshes { - for p in AncestorIter::new(&parents, e) { - if let Ok((outline, depth)) = outlines.get(p) { - commands - .entity(e) - .insert(OutlineBundle { - outline: outline.clone(), - ..default() - }) - .insert(depth.clone()); - break; - } - } - } -} diff --git a/rmf_site_editor/src/site/door.rs b/rmf_site_editor/src/site/door.rs index 99fb5036..1135bb5f 100644 --- a/rmf_site_editor/src/site/door.rs +++ b/rmf_site_editor/src/site/door.rs @@ -15,7 +15,11 @@ * */ -use crate::{interaction::Selectable, shapes::*, site::*}; +use crate::{ + interaction::{Hovered, Selectable}, + shapes::*, + site::*, +}; use bevy::{ prelude::*, render::mesh::{Indices, PrimitiveTopology}, @@ -393,7 +397,13 @@ fn update_door_visuals( pub fn update_changed_door( mut commands: Commands, mut doors: Query< - (Entity, &Edge, &DoorType, &mut DoorSegments), + ( + Entity, + &Edge, + &DoorType, + &mut DoorSegments, + &mut Hovered, + ), Or<(Changed>, Changed)>, >, anchors: AnchorParams, @@ -402,7 +412,8 @@ pub fn update_changed_door( mut mesh_assets: ResMut>, assets: Res, ) { - for (entity, edge, kind, mut segments) in &mut doors { + for (entity, edge, kind, mut segments, mut hovered) in &mut doors { + let old_door_count = segments.body.entities().len(); if let Some(new_body) = update_door_visuals( &mut commands, entity, @@ -416,6 +427,11 @@ pub fn update_changed_door( &assets, ) { segments.body = new_body; + if segments.body.entities().len() > old_door_count { + // A new door was spawned, trigger hovered change detection to update the outline + // for the new mesh + hovered.set_changed(); + } } } }