diff --git a/rmf_site_editor/src/interaction/assets.rs b/rmf_site_editor/src/interaction/assets.rs index 12bb8c12..a6c452dd 100644 --- a/rmf_site_editor/src/interaction/assets.rs +++ b/rmf_site_editor/src/interaction/assets.rs @@ -82,6 +82,7 @@ impl InteractionAssets { material: material_set.passive.clone(), ..default() }) + .set_parent(parent) .id(); if let Some(for_entity) = for_entity_opt { @@ -89,7 +90,6 @@ impl InteractionAssets { .entity(child_entity) .insert(DragAxisBundle::new(for_entity, Vec3::Z).with_materials(material_set)); } - commands.entity(parent).add_child(child_entity); child_entity } @@ -126,8 +126,8 @@ impl InteractionAssets { let drag_parent = commands .spawn(SpatialBundle::default()) .insert(VisualCue::no_outline().irregular().always_xray()) + .set_parent(anchor) .id(); - commands.entity(anchor).add_child(drag_parent); let height = 0.0; let scale = 0.2; diff --git a/rmf_site_editor/src/site/lane.rs b/rmf_site_editor/src/site/lane.rs index 42aedced..aec379ea 100644 --- a/rmf_site_editor/src/site/lane.rs +++ b/rmf_site_editor/src/site/lane.rs @@ -125,29 +125,30 @@ pub fn add_lane_visuals( transform: Transform::from_xyz(0.0, 0.0, height), ..default() }) + .set_parent(e) .id(); let mut spawn_lane_mesh_and_outline = |lane_tf, lane_mesh, outline_mesh| { - let outline = commands + let mesh = commands .spawn(PbrBundle { - mesh: outline_mesh, - transform: Transform::from_translation(-0.000_5 * Vec3::Z), - visibility: Visibility { is_visible: false }, + mesh: lane_mesh, + material: lane_material.clone(), + transform: lane_tf, ..default() }) + .set_parent(layer) .id(); - let mesh = commands + let outline = commands .spawn(PbrBundle { - mesh: lane_mesh, - material: lane_material.clone(), - transform: lane_tf, + mesh: outline_mesh, + transform: Transform::from_translation(-0.000_5 * Vec3::Z), + visibility: Visibility { is_visible: false }, ..default() }) - .add_child(outline) + .set_parent(mesh) .id(); - commands.entity(layer).add_child(mesh); (mesh, outline) }; @@ -184,8 +185,7 @@ pub fn add_lane_visuals( ..default() }) .insert(Category::Lane) - .insert(EdgeLabels::StartEnd) - .add_child(layer); + .insert(EdgeLabels::StartEnd); } } diff --git a/rmf_site_editor/src/site/load.rs b/rmf_site_editor/src/site/load.rs index 3b8dc767..7523144f 100644 --- a/rmf_site_editor/src/site/load.rs +++ b/rmf_site_editor/src/site/load.rs @@ -87,104 +87,109 @@ fn generate_site_entities( let anchor_entity = commands .spawn(AnchorBundle::new(anchor.clone())) .insert(SiteID(*anchor_id)) + .set_parent(site_id) .id(); id_to_entity.insert(*anchor_id, anchor_entity); consider_id(*anchor_id); - commands.entity(site_id).add_child(anchor_entity); } for (group_id, group) in &site_data.fiducial_groups { - let group_entity = commands.spawn(group.clone()).insert(SiteID(*group_id)).id(); + let group_entity = commands + .spawn(group.clone()) + .insert(SiteID(*group_id)) + .set_parent(site_id) + .id(); id_to_entity.insert(*group_id, group_entity); consider_id(*group_id); - commands.entity(site_id).add_child(group_entity); } for (group_id, group) in &site_data.textures { - let group_entity = commands.spawn(group.clone()).insert(SiteID(*group_id)).id(); + let group_entity = commands + .spawn(group.clone()) + .insert(SiteID(*group_id)) + .set_parent(site_id) + .id(); id_to_entity.insert(*group_id, group_entity); consider_id(*group_id); - commands.entity(site_id).add_child(group_entity); } for (level_id, level_data) in &site_data.levels { - let level_entity = commands.spawn(SiteID(*level_id)).id(); + let level_entity = commands.spawn(SiteID(*level_id)).set_parent(site_id).id(); for (anchor_id, anchor) in &level_data.anchors { let anchor_entity = commands .spawn(AnchorBundle::new(anchor.clone())) .insert(SiteID(*anchor_id)) + .set_parent(level_entity) .id(); id_to_entity.insert(*anchor_id, anchor_entity); consider_id(*anchor_id); - commands.entity(level_entity).add_child(anchor_entity); } for (door_id, door) in &level_data.doors { let door_entity = commands .spawn(door.convert(&id_to_entity).for_site(site_id)?) .insert(SiteID(*door_id)) + .set_parent(level_entity) .id(); id_to_entity.insert(*door_id, door_entity); consider_id(*door_id); - commands.entity(level_entity).add_child(door_entity); } for (drawing_id, drawing) in &level_data.drawings { let drawing_entity = commands .spawn(DrawingBundle::new(drawing.properties.clone())) .insert(SiteID(*drawing_id)) + .set_parent(level_entity) .id(); for (anchor_id, anchor) in &drawing.anchors { let anchor_entity = commands .spawn(AnchorBundle::new(anchor.clone())) .insert(SiteID(*anchor_id)) + .set_parent(drawing_entity) .id(); id_to_entity.insert(*anchor_id, anchor_entity); consider_id(*anchor_id); - commands.entity(drawing_entity).add_child(anchor_entity); } for (fiducial_id, fiducial) in &drawing.fiducials { - let fiducial_entity = commands + commands .spawn(fiducial.convert(&id_to_entity).for_site(site_id)?) .insert(SiteID(*fiducial_id)) + .set_parent(drawing_entity) .id(); consider_id(*fiducial_id); - commands.entity(drawing_entity).add_child(fiducial_entity); } for (measurement_id, measurement) in &drawing.measurements { - let measurement_entity = commands + commands .spawn(measurement.convert(&id_to_entity).for_site(site_id)?) .insert(SiteID(*measurement_id)) + .set_parent(drawing_entity) .id(); consider_id(*measurement_id); - commands - .entity(drawing_entity) - .add_child(measurement_entity); } consider_id(*drawing_id); } for (floor_id, floor) in &level_data.floors { - let floor_entity = commands + commands .spawn(floor.convert(&id_to_entity).for_site(site_id)?) .insert(SiteID(*floor_id)) + .set_parent(level_entity) .id(); consider_id(*floor_id); - commands.entity(level_entity).add_child(floor_entity); } for (wall_id, wall) in &level_data.walls { - let wall_entity = commands + commands .spawn(wall.convert(&id_to_entity).for_site(site_id)?) .insert(SiteID(*wall_id)) + .set_parent(level_entity) .id(); consider_id(*wall_id); - commands.entity(level_entity).add_child(wall_entity); } commands @@ -228,11 +233,10 @@ fn generate_site_entities( ); id_to_entity.insert(*level_id, level_entity); consider_id(*level_id); - commands.entity(site_id).add_child(level_entity); } for (lift_id, lift_data) in &site_data.lifts { - let lift_entity = commands.spawn(SiteID(*lift_id)).id(); + let lift_entity = commands.spawn(SiteID(*lift_id)).set_parent(site_id).id(); commands.entity(lift_entity).with_children(|lift| { lift.spawn(SpatialBundle::default()) @@ -253,10 +257,10 @@ fn generate_site_entities( let door_entity = commands .spawn(door.convert(&id_to_entity).for_site(site_id)?) .insert(Dependents::single(lift_entity)) + .set_parent(lift_entity) .id(); id_to_entity.insert(*door_id, door_entity); consider_id(*door_id); - commands.entity(lift_entity).add_child(door_entity); } commands.entity(lift_entity).insert(Category::Lift).insert( @@ -268,17 +272,16 @@ fn generate_site_entities( id_to_entity.insert(*lift_id, lift_entity); consider_id(*lift_id); - commands.entity(site_id).add_child(lift_entity); } for (fiducial_id, fiducial) in &site_data.fiducials { let fiducial_entity = commands .spawn(fiducial.convert(&id_to_entity).for_site(site_id)?) .insert(SiteID(*fiducial_id)) + .set_parent(site_id) .id(); id_to_entity.insert(*fiducial_id, fiducial_entity); consider_id(*fiducial_id); - commands.entity(site_id).add_child(fiducial_entity); } for (nav_graph_id, nav_graph_data) in &site_data.navigation.guided.graphs { @@ -286,30 +289,30 @@ fn generate_site_entities( .spawn(SpatialBundle::default()) .insert(nav_graph_data.clone()) .insert(SiteID(*nav_graph_id)) + .set_parent(site_id) .id(); id_to_entity.insert(*nav_graph_id, nav_graph); consider_id(*nav_graph_id); - commands.entity(site_id).add_child(nav_graph); } for (lane_id, lane_data) in &site_data.navigation.guided.lanes { let lane = commands .spawn(lane_data.convert(&id_to_entity).for_site(site_id)?) .insert(SiteID(*lane_id)) + .set_parent(site_id) .id(); id_to_entity.insert(*lane_id, lane); consider_id(*lane_id); - commands.entity(site_id).add_child(lane); } for (location_id, location_data) in &site_data.navigation.guided.locations { let location = commands .spawn(location_data.convert(&id_to_entity).for_site(site_id)?) .insert(SiteID(*location_id)) + .set_parent(site_id) .id(); id_to_entity.insert(*location_id, location); consider_id(*location_id); - commands.entity(site_id).add_child(location); } let nav_graph_rankings = match RecencyRanking::::from_u32( diff --git a/rmf_site_editor/src/site/model.rs b/rmf_site_editor/src/site/model.rs index 9dd05c25..6279ded1 100644 --- a/rmf_site_editor/src/site/model.rs +++ b/rmf_site_editor/src/site/model.rs @@ -108,53 +108,58 @@ pub fn handle_model_loaded_events( .as_ref() .map(|s| s.clone()) .unwrap_or(gltf.scenes.get(0).unwrap().clone()); - let scene_id = commands - .spawn(SceneBundle { - scene, - transform: Transform::from_scale(**scale), - ..default() - }) - .id(); - commands.entity(e).add_child(scene_id); - Some(scene_id) + Some( + commands + .spawn(SceneBundle { + scene, + transform: Transform::from_scale(**scale), + ..default() + }) + .set_parent(e) + .id(), + ) } else if scenes.contains(&h.typed_weak::()) { let h_typed = h.0.clone().typed::(); - let scene_id = commands - .spawn(SceneBundle { - scene: h_typed, - transform: Transform::from_scale(**scale), - ..default() - }) - .id(); - commands.entity(e).add_child(scene_id); - Some(scene_id) + Some( + commands + .spawn(SceneBundle { + scene: h_typed, + transform: Transform::from_scale(**scale), + ..default() + }) + .set_parent(e) + .id(), + ) } else if meshes.contains(&h.typed_weak::()) { let h_typed = h.0.clone().typed::(); - let mesh_id = commands - .spawn(PbrBundle { - mesh: h_typed, - material: site_assets.default_mesh_grey_material.clone(), - transform: Transform::from_scale(**scale), - ..default() - }) - .id(); - commands.entity(e).add_child(mesh_id); - Some(mesh_id) + Some( + commands + .spawn(PbrBundle { + mesh: h_typed, + material: site_assets.default_mesh_grey_material.clone(), + transform: Transform::from_scale(**scale), + ..default() + }) + .set_parent(e) + .id(), + ) } else if let Some(urdf) = urdfs.get(&h.typed_weak::()) { - let urdf_id = commands - .spawn(SpatialBundle::VISIBLE_IDENTITY) - .insert(urdf.clone()) - .insert(Category::Workcell) - .id(); - commands.entity(e).add_child(urdf_id); - Some(urdf_id) + Some( + commands + .spawn(SpatialBundle::VISIBLE_IDENTITY) + .insert(urdf.clone()) + .insert(Category::Workcell) + .set_parent(e) + .id(), + ) } else if let Some(sdf) = sdfs.get(&h.typed_weak::()) { - let sdf_id = commands - .spawn(SpatialBundle::VISIBLE_IDENTITY) - .insert(sdf.clone()) - .id(); - commands.entity(e).add_child(sdf_id); - Some(sdf_id) + Some( + commands + .spawn(SpatialBundle::VISIBLE_IDENTITY) + .insert(sdf.clone()) + .set_parent(e) + .id(), + ) } else { None }; diff --git a/rmf_site_editor/src/site/site.rs b/rmf_site_editor/src/site/site.rs index 2ab5ddcd..0e3e9f6e 100644 --- a/rmf_site_editor/src/site/site.rs +++ b/rmf_site_editor/src/site/site.rs @@ -124,12 +124,10 @@ pub fn change_site( global_floor_visibility: default(), global_drawing_visibility: default(), }) + .set_parent(cmd.site) .id(); - commands - .entity(cmd.site) - .insert(CachedLevel(new_level)) - .add_child(new_level); + commands.entity(cmd.site).insert(CachedLevel(new_level)); current_level.0 = Some(new_level); } }