From 366adcefa3e133ee6445265830ca33c72a1ed9a2 Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 3 Aug 2023 14:05:51 +0800 Subject: [PATCH] More refactoring Signed-off-by: Arjo Chakravarty --- .../color_entity_mapping.rs | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/rmf_site_editor/src/interaction/color_based_picker/color_entity_mapping.rs b/rmf_site_editor/src/interaction/color_based_picker/color_entity_mapping.rs index 4c318452..67d20067 100644 --- a/rmf_site_editor/src/interaction/color_based_picker/color_entity_mapping.rs +++ b/rmf_site_editor/src/interaction/color_based_picker/color_entity_mapping.rs @@ -147,27 +147,23 @@ impl ColorEntityMap { /// Label items which need to be selected. #[derive(Component, Debug, Clone)] -pub struct ScreenSpaceEntity; +pub struct MarkAsDrawnToSelectionBuffer; -/// Label items which already have been marked as +/// Label entities whic are part of the selection buffer #[derive(Component, Debug, Clone)] -pub struct ScreenSpaceDrawing; +pub struct SelectionBufferDrawing; -#[derive(Component, Debug, Clone)] -pub struct ScreenSpaceShape; - -/// This system handles the mapping of entities to their colors. +/// This system handles drawing new entities in the selection pub fn new_objectcolor_entity_mapping( mut commands: Commands, screen_space_lines: Query< - (&ScreenSpaceSelection, Entity, Option<&GlobalTransform>), - Without>, + (&ScreenSpaceSelection, Entity), + Without>, >, mut polyline_materials: ResMut>, mut point_materials: ResMut>, mut polylines: ResMut>, mut color_map: ResMut, - //screen_space_entities: Query<(&ScreenSpaceEntity, Entity)>, images_to_save: Query<&ImageToSave>, point_assets: Res, ) { @@ -178,13 +174,12 @@ pub fn new_objectcolor_entity_mapping( }; // Redraw parameters. - for (screenspace_shape, entity, tf) in &screen_space_lines { + for (screenspace_shape, entity) in &screen_space_lines { match screenspace_shape { ScreenSpaceSelection::Polyline(shape) => { let thickness = shape.thickness * scale; let thickness = if thickness < 10.0 { 10.0 } else { thickness }; if Layer == LINE_PICKING_LAYER { - println!("Adding line"); commands.entity(entity).with_children(|parent| { parent.spawn(( PolylineBundle { @@ -200,19 +195,15 @@ pub fn new_objectcolor_entity_mapping( }, RenderLayers::layer(LINE_PICKING_LAYER), DontPropagateVisualCue, - ScreenSpaceDrawing, + SelectionBufferDrawing, )); }); commands .entity(entity) - .insert(ScreenSpaceEntity::); + .insert(MarkAsDrawnToSelectionBuffer::); } } ScreenSpaceSelection::Point => { - let Some(tf) = tf else { - continue; - }; - if Layer == POINT_PICKING_LAYER { commands.entity(entity).with_children(|parent| { parent.spawn(( @@ -225,24 +216,26 @@ pub fn new_objectcolor_entity_mapping( }, RenderLayers::layer(POINT_PICKING_LAYER), DontPropagateVisualCue, - ScreenSpaceDrawing, + SelectionBufferDrawing, )); }); commands .entity(entity) - .insert(ScreenSpaceEntity::); + .insert(MarkAsDrawnToSelectionBuffer::); } } } } } +/// This system synchronizes the polylines in the selection buffer +/// and the rendering system. pub fn sync_polyline_selection_buffer( screen_space_lines: Query< (&ScreenSpaceSelection, &Children), - With>, + With>, >, - polylines: Query<(&Handle, &ScreenSpaceDrawing, &RenderLayers)>, + polylines: Query<(&Handle, &SelectionBufferDrawing, &RenderLayers)>, mut polyline_assets: ResMut>, ) { for (selection, children) in screen_space_lines.iter() { @@ -254,7 +247,6 @@ pub fn sync_polyline_selection_buffer( let Ok((handle, _, layers)) = polylines.get(*child) else { continue; }; - let m: Vec<_> = layers.iter().collect(); let Some(mut polyline) = polyline_assets.get_mut(handle) else { continue; };