Skip to content

Commit

Permalink
Update model names, cleanup logic
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <[email protected]>
  • Loading branch information
luca-della-vedova committed Jun 28, 2023
1 parent 479ba05 commit f60ae2f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
59 changes: 29 additions & 30 deletions rmf_site_editor/src/site/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn add_robot_to_spawn_location(
Changed<LocationTags>,
>,
levels: Query<(), With<LevelProperties>>,
mut models: Query<&mut AssetSource, With<ModelMarker>>,
mut models: Query<(&mut NameInSite, &mut AssetSource), With<ModelMarker>>,
anchors: AnchorParams,
parents: Query<&Parent>,
) {
Expand All @@ -112,38 +112,37 @@ pub fn add_robot_to_spawn_location(

let parent = AncestorIter::new(&parents, point.0).find(|p| levels.get(*p).is_ok());

let mut found_robot = false;
if let Some(parent) = parent {
for location_tag in location_tags.iter() {
if let LocationTag::SpawnRobot(m) = location_tag {
if let Some(location_model) = location_model {
// Update existing model
if let Ok(mut source) = models.get_mut(location_model.0) {
*source = m.source.clone();
}
} else {
// Spawn new model
let mut model = m.clone();
model.pose = Pose {
trans: position.into(),
..default()
};
// TODO(luca) there should be a marker component to denote this is a robot
// as well as set it non static
// Robots should probably be made non deletable, since their spawning is
// controlled by the location property
let child = commands.spawn(model).id();
commands.entity(parent).push_children(&[child]);
commands.entity(e).insert(LocationRobotModel(child));
if let Some(m) = location_tags.iter().find_map(|l| match l {
LocationTag::SpawnRobot(m) => Some(m),
_ => None,
}) {
if let Some(location_model) = location_model {
// Update existing model
if let Ok((mut name, mut source)) = models.get_mut(location_model.0) {
*name = m.name.clone();
*source = m.source.clone();
}
found_robot = true;
} else {
// Spawn new model
let mut model = m.clone();
model.pose = Pose {
trans: position.into(),
..default()
};
// TODO(luca) there should be a marker component to denote this is a robot
// as well as set it non static
// Robots should probably be made non deletable, since their spawning is
// controlled by the location property
let child = commands.spawn(model).id();
commands.entity(parent).push_children(&[child]);
commands.entity(e).insert(LocationRobotModel(child));
}
} else {
if let Some(location_model) = location_model {
commands.entity(location_model.0).despawn_recursive();
commands.entity(e).remove::<LocationRobotModel>();
}
}
}
if !found_robot {
if let Some(location_model) = location_model {
commands.entity(location_model.0).despawn_recursive();
commands.entity(e).remove::<LocationRobotModel>();
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions rmf_site_editor/src/site/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ pub fn update_model_scenes(

pub fn update_model_tentative_formats(
mut commands: Commands,
changed_models: Query<Entity, (Changed<AssetSource>, With<ModelMarker>)>,
changed_models: Query<
(Entity, &AssetSource, Option<&ModelScene>),
(Changed<AssetSource>, With<ModelMarker>),
>,
mut loading_models: Query<
(
Entity,
Expand All @@ -272,9 +275,11 @@ pub fn update_model_tentative_formats(
>,
asset_server: Res<AssetServer>,
) {
for e in changed_models.iter() {
for (e, source, scene) in changed_models.iter() {
// Reset to the first format
commands.entity(e).insert(TentativeModelFormat::default());
if !scene.is_some_and(|r| &r.source == source) {
commands.entity(e).insert(TentativeModelFormat::default());
}
}
// Check from the asset server if any format failed, if it did try the next
for (e, mut tentative_format, h, source) in loading_models.iter_mut() {
Expand Down

0 comments on commit f60ae2f

Please sign in to comment.