Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing model descriptions and instances #230

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ce017cb
Scenarios V2
reuben-thomas Jun 27, 2024
f00141d
Use groups
reuben-thomas Jul 1, 2024
6167ec1
Add scale and static to instances
reuben-thomas Jul 1, 2024
03cace2
fix description names
reuben-thomas Jul 2, 2024
0010b9f
Added convert function for model instance
reuben-thomas Jul 2, 2024
243b2b4
Merge remote-tracking branch 'upstream/main' into scenarios
reuben-thomas Jul 2, 2024
8386209
add from group list
reuben-thomas Jul 8, 2024
9f30004
redefine description, instances, scenarios
reuben-thomas Jul 10, 2024
1215fa9
scenario panel prototype
reuben-thomas Jul 11, 2024
1c25265
senario menu
reuben-thomas Jul 12, 2024
7adb5c6
improve scenario selector ui
reuben-thomas Jul 16, 2024
ce9f345
functional scenario switching
reuben-thomas Jul 17, 2024
97f8dbf
additions
reuben-thomas Jul 17, 2024
537ff76
Description inspector prototype
reuben-thomas Jul 18, 2024
b3f232d
organize instance and group properties
reuben-thomas Jul 19, 2024
c284a64
model description inspector plugin
reuben-thomas Jul 23, 2024
8cf25e7
Add differential drive
reuben-thomas Jul 23, 2024
9c96e32
deletions
reuben-thomas Jul 24, 2024
f6124a2
remove task view
reuben-thomas Jul 24, 2024
e84dc58
edit scenarios
reuben-thomas Jul 25, 2024
6d0a7e8
fix description deletions, instances without parent
reuben-thomas Jul 25, 2024
63fb8b9
scenarios: fix undos, allow for different instance types
reuben-thomas Jul 26, 2024
443a3fe
fix misplaced cfg(feature)
reuben-thomas Jul 26, 2024
ecb9bb7
fix base tasks
reuben-thomas Jul 27, 2024
5a8ef05
fix styling
reuben-thomas Jul 27, 2024
c896ea8
move all scenario viewer from mapf
reuben-thomas Jul 29, 2024
f7a24be
fixes, address comment
reuben-thomas Jul 31, 2024
69ea1df
Add instances to creation
reuben-thomas Jul 31, 2024
9963a8f
model selection
reuben-thomas Jul 31, 2024
a944432
add collision radius
reuben-thomas Jul 31, 2024
94ccc5c
allow ignore for occupancy calculation
reuben-thomas Jul 31, 2024
4b413a2
delete scenarios
reuben-thomas Aug 1, 2024
d95be3b
add saving
reuben-thomas Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rmf_site_editor/src/interaction/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl InteractionAssets {
// The arrows should originate in the mesh origin
let pos = Vec3::splat(0.0);
let rot_x = Quat::from_rotation_y(90_f32.to_radians());
let rot_y = Quat::from_rotation_x(-90_f32.to_radians());
let rot_y = Quat::from_rotation_x((-90_f32).to_radians());
let rot_z = Quat::default();
let x_mat = self.x_axis_materials.clone();
let y_mat = self.y_axis_materials.clone();
Expand Down Expand Up @@ -145,12 +145,12 @@ impl InteractionAssets {
(
self.x_axis_materials.clone(),
Vec3::new(-offset, 0., height),
Quat::from_rotation_y(-90_f32.to_radians()),
Quat::from_rotation_y(-(90_f32).to_radians()),
),
(
self.y_axis_materials.clone(),
Vec3::new(0., offset, height),
Quat::from_rotation_x(-90_f32.to_radians()),
Quat::from_rotation_x(-(90_f32).to_radians()),
),
(
self.y_axis_materials.clone(),
Expand Down Expand Up @@ -190,7 +190,7 @@ impl InteractionAssets {
(
self.y_axis_materials.clone(),
Vec3::new(0., offset, 0.),
Quat::from_rotation_x(-90_f32.to_radians()),
Quat::from_rotation_x(-(90_f32).to_radians()),
),
(
self.z_axis_materials.clone(),
Expand Down
10 changes: 8 additions & 2 deletions rmf_site_editor/src/interaction/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use crate::{
};
use bevy::{ecs::system::SystemParam, prelude::*, window::PrimaryWindow};
use bevy_mod_raycast::{deferred::RaycastMesh, deferred::RaycastSource, primitives::rays::Ray3d};
use rmf_site_format::{FloorMarker, Model, ModelMarker, PrimitiveShape, WallMarker, WorkcellModel};
use rmf_site_format::{
FloorMarker, ModelInstance, ModelMarker, PrimitiveShape, WallMarker, WorkcellModel,
};
use std::collections::HashSet;

/// A resource that keeps track of the unique entities that play a role in
Expand Down Expand Up @@ -113,7 +115,11 @@ impl Cursor {
}

// TODO(luca) reduce duplication here
pub fn set_model_preview(&mut self, commands: &mut Commands, model: Option<Model>) {
pub fn set_model_instance_preview(
&mut self,
commands: &mut Commands,
model: Option<ModelInstance<Entity>>,
) {
self.remove_preview(commands);
self.preview_model = if let Some(model) = model {
let e = commands.spawn(model).insert(Pending).id();
Expand Down
4 changes: 4 additions & 0 deletions rmf_site_editor/src/interaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub use light::*;
pub mod mode;
pub use mode::*;

pub mod model;
pub use model::*;

pub mod model_preview;
pub use model_preview::*;

Expand Down Expand Up @@ -215,6 +218,7 @@ impl Plugin for InteractionPlugin {
Update,
(
make_model_previews_not_selectable,
update_model_instance_visual_cues.after(maintain_hovered_entities),
update_lane_visual_cues.after(maintain_selected_entities),
update_edge_visual_cues.after(maintain_selected_entities),
update_point_visual_cues.after(maintain_selected_entities),
Expand Down
96 changes: 96 additions & 0 deletions rmf_site_editor/src/interaction/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2024 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

use crate::{interaction::*, site::*};
use bevy::prelude::*;

pub fn update_model_instance_visual_cues(
model_descriptions: Query<
(Entity, &Selected, &Hovered),
(
With<ModelMarker>,
With<Group>,
Or<(Changed<Hovered>, Changed<Selected>)>,
),
>,
mut model_instances: Query<
(
Entity,
&mut Selected,
&mut Hovered,
&mut Affiliation<Entity>,
Option<Ref<Tasks<Entity>>>,
),
(With<ModelMarker>, Without<Group>),
>,
mut locations: Query<&mut Selected, (With<LocationTags>, Without<ModelMarker>)>,
mut removed_components: RemovedComponents<Tasks<Entity>>,
) {
for (instance_entity, mut instance_selected, mut instance_hovered, affiliation, tasks) in
&mut model_instances
{
// By clearing instance supports for selected / hovered, we assume instances will never
// be supporting select / hovering for anything else
let mut is_description_selected = false;
if let Some(description_entity) = affiliation.0 {
if let Ok((_, description_selected, description_hovered)) =
model_descriptions.get(description_entity)
{
if description_selected.cue() {
instance_selected
.support_selected
.insert(description_entity);
is_description_selected = true;
} else {
instance_selected.support_selected.clear();
}
if description_hovered.cue() {
instance_hovered.support_hovering.insert(description_entity);
} else {
instance_hovered.support_hovering.clear();
}
}
}

// When an instance is selected, select all locations supporting it
if let Some(tasks) = tasks {
// When tasks for an instance have changed, reset all locations from supporting this instance
if tasks.is_changed() {
for mut location_selected in locations.iter_mut() {
location_selected.support_selected.remove(&instance_entity);
}
}

if let Some(task_location) = tasks.0.first().and_then(|t| t.location()) {
if let Ok(mut location_selected) = locations.get_mut(task_location.0) {
if instance_selected.cue() && !is_description_selected {
location_selected.support_selected.insert(instance_entity);
} else {
location_selected.support_selected.remove(&instance_entity);
}
}
}
}
}

// When instances are removed, prevent any location from supporting them
for removed in removed_components.read() {
for mut location_selected in locations.iter_mut() {
location_selected.support_selected.remove(&removed);
}
}
}
20 changes: 11 additions & 9 deletions rmf_site_editor/src/interaction/select_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ use crate::{
};
use bevy::{ecs::system::SystemParam, prelude::*};
use rmf_site_format::{
Door, Edge, Fiducial, Floor, FrameMarker, Lane, LiftProperties, Location, Measurement, Model,
NameInWorkcell, NameOfSite, Path, PixelsPerMeter, Point, Pose, Side, Wall, WorkcellModel,
Door, Edge, Fiducial, Floor, FrameMarker, Lane, LiftProperties, Location, Measurement,
ModelInstance, NameInWorkcell, NameOfSite, Path, PixelsPerMeter, Point, Pose, Side, Wall,
WorkcellModel,
};
use std::collections::HashSet;
use std::sync::Arc;
Expand Down Expand Up @@ -1186,7 +1187,8 @@ impl<'w, 's> SelectAnchorPlacementParams<'w, 's> {
false,
);
set_visibility(self.cursor.frame_placement, &mut self.visibility, false);
self.cursor.set_model_preview(&mut self.commands, None);
self.cursor
.set_model_instance_preview(&mut self.commands, None);
for e in self.hidden_entities.drawing_anchors.drain() {
set_visibility(e, &mut self.visibility, true);
}
Expand Down Expand Up @@ -1297,9 +1299,9 @@ impl SelectAnchorPointBuilder {
}
}

pub fn for_model(self, model: Model) -> SelectAnchor3D {
pub fn for_model_instance(self, model: ModelInstance<Entity>) -> SelectAnchor3D {
SelectAnchor3D {
bundle: PlaceableObject::Model(model),
bundle: PlaceableObject::ModelInstance(model),
parent: None,
target: self.for_element,
continuity: self.continuity,
Expand Down Expand Up @@ -1686,7 +1688,7 @@ impl SelectAnchor {

#[derive(Clone)]
enum PlaceableObject {
Model(Model),
ModelInstance(ModelInstance<Entity>),
Anchor,
VisualMesh(WorkcellModel),
CollisionMesh(WorkcellModel),
Expand Down Expand Up @@ -2151,11 +2153,11 @@ pub fn handle_select_anchor_3d_mode(
PlaceableObject::Anchor => {
set_visibility(params.cursor.frame_placement, &mut params.visibility, true);
}
PlaceableObject::Model(ref m) => {
PlaceableObject::ModelInstance(ref m) => {
// Spawn the model as a child of the cursor
params
.cursor
.set_model_preview(&mut params.commands, Some(m.clone()));
.set_model_instance_preview(&mut params.commands, Some(m.clone()));
}
PlaceableObject::VisualMesh(ref m) | PlaceableObject::CollisionMesh(ref m) => {
// Spawn the model as a child of the cursor
Expand Down Expand Up @@ -2200,7 +2202,7 @@ pub fn handle_select_anchor_3d_mode(
NameInWorkcell("Unnamed".to_string()),
))
.id(),
PlaceableObject::Model(ref a) => {
PlaceableObject::ModelInstance(ref a) => {
let mut model = a.clone();
// If we are in workcell mode, add a "base link" frame to the model
if matches!(**app_state, AppState::WorkcellEditor) {
Expand Down
10 changes: 10 additions & 0 deletions rmf_site_editor/src/occupancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ pub struct CalculateGrid {
pub floor: f32,
/// Ignore meshes above this height
pub ceiling: f32,
// Ignore these entities
pub ignore: Option<HashSet<Entity>>,
}

enum Group {
Expand Down Expand Up @@ -180,6 +182,14 @@ fn calculate_grid(
let physical_entities = collect_physical_entities(&bodies, &meta);
info!("Checking {:?} physical entities", physical_entities.len());
for e in &physical_entities {
if request
.ignore
.as_ref()
.is_some_and(|ignored_set| ignored_set.contains(e))
{
continue;
}

let (_, mesh, aabb, tf) = match bodies.get(*e) {
Ok(body) => body,
Err(_) => continue,
Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ pub(crate) fn make_physical_camera_mesh() -> Mesh {
)
.transform_by(
Affine3A::from_translation([lens_hood_protrusion * scale, 0., 0.].into())
* Affine3A::from_rotation_y(-90_f32.to_radians())
* Affine3A::from_rotation_y(-(90_f32).to_radians())
* Affine3A::from_rotation_z(45_f32.to_radians()),
)
.merge_into(&mut mesh);
Expand Down
16 changes: 14 additions & 2 deletions rmf_site_editor/src/site/deletion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ use crate::{
log::Log,
site::{
Category, CurrentLevel, Dependents, LevelElevation, LevelProperties, NameInSite,
SiteUpdateSet,
RemoveInstance, SiteUpdateSet,
},
AppState, Issue,
};
use bevy::{ecs::system::SystemParam, prelude::*};
use rmf_site_format::{ConstraintDependents, Edge, MeshConstraint, Path, Point};
use rmf_site_format::{
Affiliation, ConstraintDependents, Edge, Group, InstanceMarker, MeshConstraint, Path, Point,
};
use std::collections::HashSet;

// TODO(MXG): Use this module to implement the deletion buffer. The role of the
Expand Down Expand Up @@ -82,6 +84,7 @@ struct DeletionParams<'w, 's> {
edges: Query<'w, 's, &'static Edge<Entity>>,
points: Query<'w, 's, &'static Point<Entity>>,
paths: Query<'w, 's, &'static Path<Entity>>,
instances: Query<'w, 's, &'static Affiliation<Entity>, (With<InstanceMarker>, Without<Group>)>,
parents: Query<'w, 's, &'static mut Parent>,
dependents: Query<'w, 's, &'static mut Dependents>,
constraint_dependents: Query<'w, 's, &'static mut ConstraintDependents>,
Expand All @@ -90,6 +93,7 @@ struct DeletionParams<'w, 's> {
selection: Res<'w, Selection>,
current_level: ResMut<'w, CurrentLevel>,
levels: Query<'w, 's, Entity, With<LevelElevation>>,
remove_instance: EventWriter<'w, RemoveInstance>,
select: EventWriter<'w, Select>,
log: EventWriter<'w, Log>,
issues: Query<'w, 's, (Entity, &'static mut Issue)>,
Expand Down Expand Up @@ -137,6 +141,14 @@ fn cautious_delete(element: Entity, params: &mut DeletionParams) {
}
}

if let Ok(_) = params.instances.get(element) {
params.remove_instance.send(RemoveInstance(element));
if **params.selection == Some(element) {
params.select.send(Select(None));
}
return;
}

for descendent in &all_descendents {
if let Ok(prevent) = params.preventions.get(*descendent) {
if *descendent == element {
Expand Down
8 changes: 1 addition & 7 deletions rmf_site_editor/src/site/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ pub struct MergeGroups {
pub into_group: Entity,
}

#[derive(Component, Deref)]
#[derive(Component, Deref, DerefMut)]
pub struct Members(Vec<Entity>);

impl Members {
pub fn iter(&self) -> impl Iterator<Item = &Entity> {
self.0.iter()
}
}

#[derive(Component, Clone, Copy)]
struct LastAffiliation(Option<Entity>);

Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/site/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

use crate::site::*;
use crate::{interaction::CameraControls, CurrentWorkspace};
use crate::CurrentWorkspace;
use bevy::prelude::*;

pub fn update_level_visibility(
Expand Down
Loading
Loading