From 4c0b3ce271fd264a7a186f55333ff188f593b113 Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Mon, 24 Jul 2023 11:22:11 +0800 Subject: [PATCH] Get arrows to scale as well Signed-off-by: Arjo Chakravarty --- rmf_site_editor/src/interaction/assets.rs | 4 ++ rmf_site_editor/src/interaction/cursor.rs | 6 +++ rmf_site_editor/src/site/mod.rs | 5 +- .../src/site/offscreen_render_tests.rs | 48 ++++++++++++++++++- .../src/site/screenspace_selection.rs | 2 +- 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/rmf_site_editor/src/interaction/assets.rs b/rmf_site_editor/src/interaction/assets.rs index c66f3fa2..5ef88dc1 100644 --- a/rmf_site_editor/src/interaction/assets.rs +++ b/rmf_site_editor/src/interaction/assets.rs @@ -83,6 +83,10 @@ impl InteractionAssets { ..default() }); + child_entity.insert(LimitScaleFactor { + distance_to_start_scaling: 10.0, + original_scale: 0.2, + }); if let Some(for_entity) = for_entity_opt { child_entity .insert(DragAxisBundle::new(for_entity, Vec3::Z).with_materials(material_set)); diff --git a/rmf_site_editor/src/interaction/cursor.rs b/rmf_site_editor/src/interaction/cursor.rs index d57ed2ee..381272b7 100644 --- a/rmf_site_editor/src/interaction/cursor.rs +++ b/rmf_site_editor/src/interaction/cursor.rs @@ -26,6 +26,12 @@ use bevy_mod_raycast::{Intersection, Ray3d}; use rmf_site_format::{FloorMarker, Model, ModelMarker, WallMarker, WorkcellModel}; use std::collections::HashSet; +#[derive(Debug, Clone, Component)] +pub struct LimitScaleFactor { + pub distance_to_start_scaling: f32, + pub original_scale: f32, +} + /// A resource that keeps track of the unique entities that play a role in /// displaying the 3D cursor #[derive(Debug, Clone, Resource)] diff --git a/rmf_site_editor/src/site/mod.rs b/rmf_site_editor/src/site/mod.rs index 6081cfdd..a8ddf84b 100644 --- a/rmf_site_editor/src/site/mod.rs +++ b/rmf_site_editor/src/site/mod.rs @@ -104,7 +104,7 @@ pub mod camera_capture; pub use camera_capture::*; use crate::{ - interaction::{LINE_PICKING_LAYER, POINT_PICKING_LAYER}, + interaction::{LimitScaleFactor, LINE_PICKING_LAYER, POINT_PICKING_LAYER}, recency::{RecencyRank, RecencyRankingPlugin}, }; pub use rmf_site_format::*; @@ -227,7 +227,8 @@ impl Plugin for SitePlugin { .with_system(update_lift_cabin) .with_system(update_lift_edge) .with_system(update_model_tentative_formats) - .with_system(update_material_for_display_color), + .with_system(update_material_for_display_color) + .with_system(limit_size), ) .add_system_set( SystemSet::on_update(SiteState::Display) diff --git a/rmf_site_editor/src/site/offscreen_render_tests.rs b/rmf_site_editor/src/site/offscreen_render_tests.rs index 019b2768..e88671bd 100644 --- a/rmf_site_editor/src/site/offscreen_render_tests.rs +++ b/rmf_site_editor/src/site/offscreen_render_tests.rs @@ -1,9 +1,11 @@ use crate::interaction::Hover; +use crate::interaction::LimitScaleFactor; use crate::interaction::Select; use crate::interaction::LINE_PICKING_LAYER; use bevy::core_pipeline::clear_color::ClearColorConfig; use bevy::core_pipeline::fxaa::Fxaa; use bevy::core_pipeline::tonemapping::Tonemapping; +use bevy::ecs::query::WorldQuery; use bevy::prelude::*; use bevy::render::camera::RenderTarget; use bevy::render::render_resource::*; @@ -249,7 +251,7 @@ pub fn buffer_to_selection( if result.len() == 0usize { continue; - } + } if mouse_button_input.just_released(MouseButton::Left) { select_event.send(Select(Some(*entity))); @@ -265,3 +267,47 @@ pub fn buffer_to_selection( } } } + +pub fn limit_size( + item_to_limit_scale: Query<(&LimitScaleFactor, Entity)>, + camera_controls: Res, + cameras: Query<&Camera>, + transforms: Query<&GlobalTransform>, + mut editable_transforms: Query<&mut Transform>, +) { + let view_cam_entity = match camera_controls.mode() { + ProjectionMode::Perspective => camera_controls.perspective_camera_entities[0], + ProjectionMode::Orthographic => camera_controls.orthographic_camera_entities[0], + }; + + let Ok((camera)) = cameras.get(view_cam_entity) else { + println!("here1q"); + return; + }; + + let Ok(camera_transform) = transforms.get(view_cam_entity) + else { + return; + }; + + for (limits, entity) in item_to_limit_scale.iter() { + let Ok(item_to_scale_transform) = transforms.get(entity) else { + continue; + }; + + let dist = camera_transform.translation() - item_to_scale_transform.translation(); + + if dist.length() > limits.distance_to_start_scaling { + let Ok(mut item_to_scale) = editable_transforms.get_mut(entity) else { + continue; + }; + item_to_scale.scale = Vec3::splat(dist.length() / limits.distance_to_start_scaling) + * limits.original_scale; + } else { + let Ok(mut item_to_scale) = editable_transforms.get_mut(entity) else { + continue; + }; + item_to_scale.scale = Vec3::ONE * limits.original_scale; + } + } +} diff --git a/rmf_site_editor/src/site/screenspace_selection.rs b/rmf_site_editor/src/site/screenspace_selection.rs index 42d2221a..e86a00f3 100644 --- a/rmf_site_editor/src/site/screenspace_selection.rs +++ b/rmf_site_editor/src/site/screenspace_selection.rs @@ -100,7 +100,7 @@ impl ColorEntityMap { let color = Color::rgb_u8(r, g, b); let material = point_materials.add(PointsMaterial { - point_size: SCREEN_SPACE_POINT_SIZE_SELECTION, // Defines the size of the points. + point_size: SCREEN_SPACE_POINT_SIZE_SELECTION, // Defines the size of the points. perspective: false, // Specify whether points' size is attenuated by the camera depth. circle: true, use_vertex_color: false,