Skip to content

Commit

Permalink
Change to set_parent when simpler
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
  • Loading branch information
luca-della-vedova committed Sep 4, 2023
1 parent 9c93a33 commit dea6af9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 86 deletions.
4 changes: 2 additions & 2 deletions rmf_site_editor/src/interaction/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ impl InteractionAssets {
material: material_set.passive.clone(),
..default()
})
.set_parent(parent)
.id();

if let Some(for_entity) = for_entity_opt {
commands
.entity(child_entity)
.insert(DragAxisBundle::new(for_entity, Vec3::Z).with_materials(material_set));
}
commands.entity(parent).add_child(child_entity);
child_entity
}

Expand Down Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions rmf_site_editor/src/site/lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand Down Expand Up @@ -184,8 +185,7 @@ pub fn add_lane_visuals(
..default()
})
.insert(Category::Lane)
.insert(EdgeLabels::StartEnd)
.add_child(layer);
.insert(EdgeLabels::StartEnd);
}
}

Expand Down
57 changes: 30 additions & 27 deletions rmf_site_editor/src/site/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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(
Expand All @@ -268,48 +272,47 @@ 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 {
let nav_graph = commands
.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::<NavGraphMarker>::from_u32(
Expand Down
87 changes: 46 additions & 41 deletions rmf_site_editor/src/site/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Scene>()) {
let h_typed = h.0.clone().typed::<Scene>();
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::<Mesh>()) {
let h_typed = h.0.clone().typed::<Mesh>();
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::<UrdfRoot>()) {
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::<SdfRoot>()) {
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
};
Expand Down
6 changes: 2 additions & 4 deletions rmf_site_editor/src/site/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit dea6af9

Please sign in to comment.