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 19 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
20 changes: 19 additions & 1 deletion 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, Model, 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 @@ -124,6 +126,22 @@ impl Cursor {
}
}

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 {
println!("Spawn model instance preview");
let e = commands.spawn(model).insert(Pending).id();
commands.entity(self.frame).push_children(&[e]);
Some(e)
} else {
None
}
}

pub fn set_workcell_model_preview(
&mut self,
commands: &mut Commands,
Expand Down
39 changes: 38 additions & 1 deletion rmf_site_editor/src/interaction/select_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ 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,
ModelInstance, NameInWorkcell, NameOfSite, Path, PixelsPerMeter, Point, Pose, Side, Wall,
WorkcellModel,
};
use std::collections::HashSet;
use std::sync::Arc;
Expand Down Expand Up @@ -1306,6 +1307,15 @@ impl SelectAnchorPointBuilder {
}
}

pub fn for_model_instance(self, model: ModelInstance<Entity>) -> SelectAnchor3D {
SelectAnchor3D {
bundle: PlaceableObject::ModelInstance(model),
parent: None,
target: self.for_element,
continuity: self.continuity,
}
}

pub fn for_visual(self, model: WorkcellModel) -> SelectAnchor3D {
SelectAnchor3D {
bundle: PlaceableObject::VisualMesh(model),
Expand Down Expand Up @@ -1687,6 +1697,7 @@ impl SelectAnchor {
#[derive(Clone)]
enum PlaceableObject {
Model(Model),
ModelInstance(ModelInstance<Entity>),
Anchor,
VisualMesh(WorkcellModel),
CollisionMesh(WorkcellModel),
Expand Down Expand Up @@ -2157,6 +2168,12 @@ pub fn handle_select_anchor_3d_mode(
.cursor
.set_model_preview(&mut params.commands, Some(m.clone()));
}
PlaceableObject::ModelInstance(ref m) => {
// Spawn the model as a child of the cursor
params
.cursor
.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
params
Expand Down Expand Up @@ -2220,6 +2237,26 @@ pub fn handle_select_anchor_3d_mode(
params.commands.spawn(model).id()
}
}
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) {
let child_id = params.commands.spawn(model).id();
params
.commands
.spawn((
AnchorBundle::new(Anchor::Pose3D(pose))
.dependents(Dependents::single(child_id)),
FrameMarker,
NameInWorkcell("model_root".to_string()),
))
.add_child(child_id)
.id()
} else {
model.pose = pose;
params.commands.spawn(model).id()
}
}
PlaceableObject::VisualMesh(ref a) => {
let mut model = a.clone();
model.pose = pose;
Expand Down
19 changes: 17 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,
RemoveModelInstance, 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, MeshConstraint, ModelMarker, 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,8 @@ 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>>,
model_instances:
Query<'w, 's, &'static Affiliation<Entity>, (With<ModelMarker>, 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 +94,7 @@ struct DeletionParams<'w, 's> {
selection: Res<'w, Selection>,
current_level: ResMut<'w, CurrentLevel>,
levels: Query<'w, 's, Entity, With<LevelElevation>>,
remove_model_instance: EventWriter<'w, RemoveModelInstance>,
select: EventWriter<'w, Select>,
log: EventWriter<'w, Log>,
issues: Query<'w, 's, (Entity, &'static mut Issue)>,
Expand Down Expand Up @@ -137,6 +142,16 @@ fn cautious_delete(element: Entity, params: &mut DeletionParams) {
}
}

if let Ok(_) = params.model_instances.get(element) {
params
.remove_model_instance
.send(RemoveModelInstance(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
4 changes: 4 additions & 0 deletions rmf_site_editor/src/site/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl Members {
pub fn iter(&self) -> impl Iterator<Item = &Entity> {
self.0.iter()
}

pub fn len(&self) -> usize {
reuben-thomas marked this conversation as resolved.
Show resolved Hide resolved
self.0.len()
}
}

#[derive(Component, Clone, Copy)]
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
47 changes: 41 additions & 6 deletions rmf_site_editor/src/site/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,6 @@ fn generate_site_entities(
consider_id(*light_id);
}

for (model_id, model) in &level_data.models {
level.spawn(model.clone()).insert(SiteID(*model_id));
consider_id(*model_id);
}

for (physical_camera_id, physical_camera) in &level_data.physical_cameras {
level
.spawn(physical_camera.clone())
Expand Down Expand Up @@ -248,6 +243,42 @@ fn generate_site_entities(
consider_id(*level_id);
}

for (model_description_id, model_description) in &site_data.model_descriptions {
let model_description = commands
.spawn(model_description.clone())
.insert(SiteID(*model_description_id))
.set_parent(site_id)
.id();
id_to_entity.insert(*model_description_id, model_description);
consider_id(*model_description_id);
}

for (model_instance_id, model_instance) in &site_data.model_instances {
let model_instance = model_instance.convert(&id_to_entity).for_site(site_id)?;
let model_instance_entity = commands
.spawn(model_instance.clone())
.insert(SiteID(*model_instance_id))
.set_parent(site_id)
.id();
id_to_entity.insert(*model_instance_id, model_instance_entity);
consider_id(*model_instance_id);
}

for (scenario_id, scenario_bundle) in &site_data.scenarios {
let parent = match scenario_bundle.scenario.parent_scenario.0 {
Some(parent_id) => *id_to_entity.get(&parent_id).unwrap_or(&site_id),
None => site_id,
};
let scenario_bundle = scenario_bundle.convert(&id_to_entity).for_site(site_id)?;
let scenario_entity = commands
.spawn(scenario_bundle.clone())
.insert(SiteID(*scenario_id))
.set_parent(parent)
.id();
id_to_entity.insert(*scenario_id, scenario_entity);
consider_id(*scenario_id);
}

for (lift_id, lift_data) in &site_data.lifts {
let lift_entity = commands.spawn(SiteID(*lift_id)).set_parent(site_id).id();

Expand Down Expand Up @@ -396,7 +427,11 @@ pub fn load_site(
}

if cmd.focus {
change_current_site.send(ChangeCurrentSite { site, level: None });
change_current_site.send(ChangeCurrentSite {
site,
level: None,
scenario: None,
});
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion rmf_site_editor/src/site/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pub use sdf::*;
pub mod save;
pub use save::*;

pub mod scenario;
pub use scenario::*;

pub mod sdf_exporter;
pub use sdf_exporter::*;

Expand All @@ -116,9 +119,10 @@ pub use util::*;

pub mod wall;
pub use wall::*;
use yaserde::ser::Config;

use crate::recency::{RecencyRank, RecencyRankingPlugin};
use crate::{clear_old_issues_on_new_validate_event, AppState, RegisterIssueType};
use crate::{AppState, RegisterIssueType};
pub use rmf_site_format::*;

use bevy::{prelude::*, render::view::visibility::VisibilitySystems, transform::TransformSystem};
Expand Down Expand Up @@ -188,6 +192,7 @@ impl Plugin for SitePlugin {
.init_resource::<FuelClient>()
.init_resource::<SiteAssets>()
.init_resource::<CurrentLevel>()
.init_resource::<CurrentScenario>()
.init_resource::<PhysicalLightToggle>()
.init_resource::<FuelCacheUpdateChannel>()
.init_resource::<FuelCacheProgressChannel>()
Expand All @@ -205,6 +210,8 @@ impl Plugin for SitePlugin {
.add_event::<LoadSite>()
.add_event::<ImportNavGraphs>()
.add_event::<ChangeCurrentSite>()
.add_event::<ChangeCurrentScenario>()
.add_event::<RemoveModelInstance>()
.add_event::<SaveSite>()
.add_event::<SaveNavGraphs>()
.add_event::<ToggleLiftDoorAvailability>()
Expand Down Expand Up @@ -264,6 +271,11 @@ impl Plugin for SitePlugin {
DrawingEditorPlugin,
SiteVisualizerPlugin,
))
.add_plugins((
ChangePlugin::<ModelProperty<AssetSource>>::default(),
ChangePlugin::<ModelProperty<Scale>>::default(),
ChangePlugin::<ModelProperty<IsStatic>>::default(),
))
.add_issue_type(&DUPLICATED_DOOR_NAME_ISSUE_UUID, "Duplicate door name")
.add_issue_type(&DUPLICATED_LIFT_NAME_ISSUE_UUID, "Duplicate lift name")
.add_issue_type(
Expand Down Expand Up @@ -360,6 +372,9 @@ impl Plugin for SitePlugin {
add_location_visuals,
add_fiducial_visuals,
update_level_visibility,
update_scenario_properties,
remove_instances,
update_current_scenario,
update_changed_lane,
update_lane_for_moved_anchor,
)
Expand Down Expand Up @@ -397,6 +412,9 @@ impl Plugin for SitePlugin {
update_measurement_for_moved_anchors,
handle_model_loaded_events,
update_model_scenes,
update_model_instances::<AssetSource>,
update_model_instances::<Scale>,
update_model_instances::<IsStatic>,
update_affiliations,
update_members_of_groups.after(update_affiliations),
update_model_scales,
Expand Down
Loading
Loading