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 #242

Open
wants to merge 69 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 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
42f25c2
Merge branch 'main' into scenarios
xiyuoh Oct 10, 2024
4729bef
Reduce unnecessary diff
xiyuoh Oct 11, 2024
afddc82
Remove description entity from model instances supported highlighting…
xiyuoh Oct 14, 2024
bb13ee0
Cleanup creation with place_object()
xiyuoh Oct 17, 2024
8ffcfe6
Limit model instance creation to spawn with existing model descriptio…
xiyuoh Oct 17, 2024
1d8aa7d
Avoid duplicate variable names
xiyuoh Oct 29, 2024
af5a2d5
Simplify printouts
xiyuoh Oct 29, 2024
c6eebf4
Remove unnecessary Without in deletion and minor corrections in scenario
xiyuoh Oct 29, 2024
e2b365c
Switch model instances to spawn 2d
xiyuoh Oct 30, 2024
f0fa12c
Clarify wait for units (assuming seconds)
xiyuoh Oct 30, 2024
ad5ba6e
Align delete scenario button
xiyuoh Oct 30, 2024
d331a79
Cleanup
xiyuoh Nov 4, 2024
5786bae
Do not display scenarios that do not belong to this site
xiyuoh Nov 4, 2024
7b01c91
Remove unnecessary diffs/code and duplicate variable names
xiyuoh Nov 12, 2024
d450cd7
Spawning model descriptions via fuel
xiyuoh Nov 13, 2024
83f3d85
Style
xiyuoh Nov 13, 2024
de9b60e
Tidy up inspect differential drive
xiyuoh Nov 14, 2024
90a60ba
Display Description for instance entities only instead of not-descrip…
xiyuoh Nov 14, 2024
acb39b9
Modify Task implementation
xiyuoh Nov 14, 2024
1c2cdcf
Merge branch 'main' into xiyu/scenarios
xiyuoh Nov 15, 2024
057e186
Use deletion filter for instance removal
xiyuoh Nov 15, 2024
94b54a9
Fix style - macro not derived for WaitFor task
xiyuoh Nov 15, 2024
6ad0ea7
Trigger model instance visibility update when creating new levels
xiyuoh Nov 15, 2024
8c19eed
Remove unnecessary Eq
xiyuoh Nov 15, 2024
5aed94f
Search for ignore parent entities when calculating grid
xiyuoh Dec 10, 2024
3a6ad1d
Remove unused imports
xiyuoh Dec 10, 2024
cc29375
Update wasm-bindgen dependency
xiyuoh Dec 11, 2024
01fca32
Consistent capitalization
xiyuoh Dec 11, 2024
4252c38
Save DifferentialDrive and MobileRobotMarker properties
xiyuoh Dec 19, 2024
bbc373c
Save model instance Tasks
xiyuoh Dec 19, 2024
d97232d
Cleanup todo comments
xiyuoh Dec 19, 2024
766fd62
Merge branch 'main' into xiyu/scenarios
xiyuoh Dec 19, 2024
48c94e9
Merge branch 'main' into xiyu/scenarios
xiyuoh Dec 20, 2024
347d546
Fix OptionalModelProperties and move model loading to the end of gene…
xiyuoh Dec 20, 2024
73076af
Load robot from legacy file
xiyuoh Dec 23, 2024
6663e1a
Clearer name
xiyuoh Dec 23, 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
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions assets/demo_maps/office.building.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ levels:
- [814.828, 239.25, 0, "", {is_parking_spot: [4, false]}]
- [1210.544, 365.254, 0, ""]
- [1191.442, 824.457, 0, ""]
- [1232.421, 658.567, 0, tinyRobot1_charger, {is_charger: [4, true], is_holding_point: [4, true], is_parking_spot: [4, true], spawn_robot_name: [1, tinyRobot1], spawn_robot_type: [1, TinyRobot]}]
- [1232.421, 658.567, 0, tinyRobot1_charger, {is_charger: [4, true], is_holding_point: [4, true], is_parking_spot: [4, true], spawn_robot_name: [1, tinyRobot1], spawn_robot_type: [1, Luca/TinyRobot]}]
- [1991.121, 812.872, 0, ""]
- [1990, 638.364, 0, pantry, {is_holding_point: [4, true], is_parking_spot: [4, false], pickup_dispenser: [1, coke_dispenser]}]
- [2213.636, 812, 0, "", {is_parking_spot: [4, false]}]
Expand All @@ -206,7 +206,7 @@ levels:
- [769.867, 618.148, 0, ""]
- [2016.125, 1310.955, 0, ""]
- [2468.096, 1217.693, 0, ""]
- [2412.581, 627.5, 0, tinyRobot2_charger, {is_charger: [4, true], is_holding_point: [4, true], is_parking_spot: [4, true], spawn_robot_name: [1, tinyRobot2], spawn_robot_type: [1, TinyRobot]}]
- [2412.581, 627.5, 0, tinyRobot2_charger, {is_charger: [4, true], is_holding_point: [4, true], is_parking_spot: [4, true], spawn_robot_name: [1, tinyRobot2], spawn_robot_type: [1, Luca/TinyRobot]}]
walls:
- [6, 7, {alpha: [3, 1], texture_name: [1, default]}]
- [7, 12, {alpha: [3, 1], texture_name: [1, default]}]
Expand Down
1 change: 1 addition & 0 deletions rmf_site_editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ tera = "1.19.1"
ehttp = { version = "0.4", features = ["native-async"] }
nalgebra = "0.32.5"
anyhow = "*"
strum = "*"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap = { version = "4.0.10", features = ["color", "derive", "help", "usage", "suggestions"] }
Expand Down
23 changes: 22 additions & 1 deletion rmf_site_editor/src/interaction/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
use bevy::{ecs::system::SystemParam, prelude::*, window::PrimaryWindow};
use bevy_mod_raycast::primitives::{rays::Ray3d, Primitive3d};

use rmf_site_format::{FloorMarker, Model, WallMarker};
use rmf_site_format::{FloorMarker, Model, ModelInstance, WallMarker};
use std::collections::HashSet;

/// A resource that keeps track of the unique entities that play a role in
Expand Down Expand Up @@ -120,6 +120,27 @@ impl Cursor {
}
}

// TODO(luca) reduce duplication here
pub fn set_model_instance_preview(
&mut self,
commands: &mut Commands,
model_loader: &mut ModelLoader,
model_instance: Option<ModelInstance<Entity>>,
) {
self.remove_preview(commands);
self.preview_model = if let Some(model_instance) = model_instance {
if let Some(mut spawn_instance) =
model_loader.spawn_model_instance(self.frame, model_instance.clone(), None)
{
Some(spawn_instance.insert(Pending).id())
} else {
None
}
} else {
None
};
}

pub fn set_model_preview(
&mut self,
commands: &mut Commands,
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 @@ -55,6 +55,9 @@ pub use lift::*;
pub mod light;
pub use light::*;

pub mod model;
pub use model::*;

pub mod model_preview;
pub use model_preview::*;

Expand Down Expand Up @@ -197,6 +200,7 @@ impl Plugin for InteractionPlugin {
.add_systems(
Update,
(
update_model_instance_visual_cues.after(SelectionServiceStages::Select),
update_lane_visual_cues.after(SelectionServiceStages::Select),
update_edge_visual_cues.after(SelectionServiceStages::Select),
update_point_visual_cues.after(SelectionServiceStages::Select),
Expand Down
98 changes: 98 additions & 0 deletions rmf_site_editor/src/interaction/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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>)>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current setup, we iterate over &mut model_instances which does not have this filter, meaning it will include all model instances in the world every update cycle. Moreover, this query will only include model descriptions whose Hovered or Selected status has changed during the latest cycle, so this line will not fetch anything if neither of these components changed for the model description.

I have a feeling this filter was meant to go on model_instances, not on model_descriptions.

),
>,
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
{
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
.remove(&description_entity);
}
if description_hovered.cue() {
instance_hovered.support_hovering.insert(description_entity);
} else {
instance_hovered
.support_hovering
.remove(&description_entity);
}
}
}

// 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the use of support selected. It may also be worth doing support_hovering, which works similarly but with the Hovered component instead of Selected.

} 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);
}
}
}
4 changes: 2 additions & 2 deletions rmf_site_editor/src/interaction/select/place_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

use crate::{interaction::select::*, site::Model};
use crate::{interaction::select::*, site::ModelInstance};
use bevy::ecs::system::SystemParam;

#[derive(Default)]
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct ObjectPlacement<'w, 's> {
}

impl<'w, 's> ObjectPlacement<'w, 's> {
pub fn place_object_2d(&mut self, object: Model, level: Entity) {
pub fn place_object_2d(&mut self, object: ModelInstance<Entity>, level: Entity) {
let state = self
.commands
.spawn(SelectorInput(PlaceObject2d { object, level }))
Expand Down
14 changes: 8 additions & 6 deletions rmf_site_editor/src/interaction/select/place_object_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::{
interaction::select::*,
site::{Model, ModelLoader},
site::{ModelInstance, ModelLoader},
};
use bevy::prelude::Input as UserInput;

Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn build_place_object_2d_workflow(
}

pub struct PlaceObject2d {
pub object: Model,
pub object: ModelInstance<Entity>,
pub level: Entity,
}

Expand All @@ -121,7 +121,7 @@ pub fn place_object_2d_setup(
let mut access = access.get_mut(&key).or_broken_buffer()?;
let state = access.newest_mut().or_broken_buffer()?;

cursor.set_model_preview(&mut commands, &mut model_loader, Some(state.object.clone()));
cursor.set_model_instance_preview(&mut commands, &mut model_loader, Some(state.object.clone()));
set_visibility(cursor.dagger, &mut visibility, false);
set_visibility(cursor.halo, &mut visibility, false);

Expand Down Expand Up @@ -205,9 +205,11 @@ pub fn on_placement_chosen_2d(
let mut state = access.pull().or_broken_state()?;

state.object.pose = placement.into();
model_loader
.spawn_model(state.level, state.object)
.insert(Category::Model);
if let Some(mut model_instance) =
model_loader.spawn_model_instance(state.level, state.object, None)
{
model_instance.insert(Category::Model);
}

Ok(())
}
38 changes: 28 additions & 10 deletions rmf_site_editor/src/interaction/select/place_object_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use crate::{
interaction::select::*,
site::{
Anchor, AnchorBundle, Dependents, FrameMarker, Model, ModelLoader, NameInWorkcell, Pending,
SiteID,
Anchor, AnchorBundle, AssetSource, Dependents, FrameMarker, Group, Model, ModelInstance,
ModelLoader, ModelMarker, NameInWorkcell, Pending, SiteID,
},
widgets::canvas_tooltips::CanvasTooltips,
workcell::flatten_loaded_model_hierarchy,
Expand Down Expand Up @@ -152,7 +152,7 @@ pub struct PlaceObject3d {

#[derive(Clone, Debug)]
pub enum PlaceableObject {
Model(Model),
ModelInstance(ModelInstance<Entity>),
Anchor,
VisualMesh(Model),
CollisionMesh(Model),
Expand All @@ -179,9 +179,13 @@ pub fn place_object_3d_setup(
set_visibility(cursor.dagger, &mut visibility, true);
set_visibility(cursor.halo, &mut visibility, true);
}
PlaceableObject::Model(m)
| PlaceableObject::VisualMesh(m)
| PlaceableObject::CollisionMesh(m) => {
PlaceableObject::ModelInstance(m) => {
// Spawn the model as a child of the cursor
cursor.set_model_instance_preview(&mut commands, &mut model_loader, Some(m.clone()));
set_visibility(cursor.dagger, &mut visibility, false);
set_visibility(cursor.halo, &mut visibility, false);
}
PlaceableObject::VisualMesh(m) | PlaceableObject::CollisionMesh(m) => {
// Spawn the model as a child of the cursor
cursor.set_model_preview(&mut commands, &mut model_loader, Some(m.clone()));
set_visibility(cursor.dagger, &mut visibility, false);
Expand Down Expand Up @@ -438,6 +442,7 @@ pub fn on_placement_chosen_3d(
parents: Query<&Parent>,
frames: Query<(), With<FrameMarker>>,
mut model_loader: ModelLoader,
model_descriptions: Query<&AssetSource, (With<ModelMarker>, With<Group>)>,
) -> SelectionNodeResult {
let mut access = access.get_mut(&key).or_broken_buffer()?;
let state = access.pull().or_broken_state()?;
Expand Down Expand Up @@ -472,12 +477,25 @@ pub fn on_placement_chosen_3d(
NameInWorkcell("Unnamed".to_string()),
))
.id(),
PlaceableObject::Model(object) => {
PlaceableObject::ModelInstance(object) => {
let model_id = commands.spawn(VisualCue::outline()).id();
let source = object.source.clone();
add_model_components(object, commands.entity(model_id));
let source = object
.description
.0
.map(|e| {
model_descriptions
.get(e)
.ok()
.map(|property| property.clone())
})
.flatten()
.unwrap();
commands
.entity(model_id)
.insert(NameInWorkcell(object.name.0))
.insert(object.pose);
model_loader
.update_asset_source_impulse(model_id, source)
.update_asset_source_impulse(model_id, source.clone())
.then(flatten_models)
.detach();
// Create a parent anchor to contain the new model in
Expand Down
Loading
Loading