Skip to content

Commit

Permalink
Get arrows to scale as well
Browse files Browse the repository at this point in the history
Signed-off-by: Arjo Chakravarty <[email protected]>
  • Loading branch information
arjo129 committed Jul 24, 2023
1 parent 77198bd commit 4c0b3ce
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
4 changes: 4 additions & 0 deletions rmf_site_editor/src/interaction/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions rmf_site_editor/src/interaction/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 3 additions & 2 deletions rmf_site_editor/src/site/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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)
Expand Down
48 changes: 47 additions & 1 deletion rmf_site_editor/src/site/offscreen_render_tests.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -249,7 +251,7 @@ pub fn buffer_to_selection<const Layer: u8>(
if result.len() == 0usize {
continue;
}
}
if mouse_button_input.just_released(MouseButton::Left) {
select_event.send(Select(Some(*entity)));
Expand All @@ -265,3 +267,47 @@ pub fn buffer_to_selection<const Layer: u8>(
}
}
}

pub fn limit_size(
item_to_limit_scale: Query<(&LimitScaleFactor, Entity)>,
camera_controls: Res<CameraControls>,
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;
}
}
}
2 changes: 1 addition & 1 deletion rmf_site_editor/src/site/screenspace_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4c0b3ce

Please sign in to comment.