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

Remove add_children uses #178

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 13 additions & 13 deletions rmf_site_editor/src/interaction/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ pub fn add_anchor_visual_cues(
_ => site_assets.site_anchor_mesh.clone(),
};

let mut entity_commands = commands.entity(e);
let body = entity_commands.add_children(|parent| {
let mut body = parent.spawn(PbrBundle {
let body = commands
.spawn(PbrBundle {
mesh: body_mesh,
material: site_assets.passive_anchor_material.clone(),
..default()
});
body.insert(Selectable::new(e));
if subordinate.is_none() {
body.insert(DragPlaneBundle::new(e, Vec3::Z));
}
let body = body.id();

body
});
})
.insert(Selectable::new(e))
.id();
if subordinate.is_none() {
commands
.entity(body)
.insert(DragPlaneBundle::new(e, Vec3::Z));
}

let mut entity_commands = commands.entity(e);
entity_commands
.insert(AnchorVisualization { body, drag: None })
.insert(OutlineVisualization::Anchor { body });
.insert(OutlineVisualization::Anchor { body })
.add_child(body);

// 3D anchors should always be visible with arrow cue meshes
if anchor.is_3D() {
Expand Down
46 changes: 23 additions & 23 deletions rmf_site_editor/src/interaction/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl InteractionAssets {

pub fn make_axis(
&self,
command: &mut Commands,
commands: &mut Commands,
// What entity will be moved when this gizmo is dragged
for_entity_opt: Option<Entity>,
// What entity should be the parent frame of this gizmo
Expand All @@ -73,22 +73,24 @@ impl InteractionAssets {
rotation: Quat,
scale: f32,
) -> Entity {
return command.entity(parent).add_children(|parent| {
let mut child_entity = parent.spawn(PbrBundle {
let child_entity = commands
.spawn(PbrBundle {
transform: Transform::from_rotation(rotation)
.with_translation(offset)
.with_scale(Vec3::splat(scale)),
mesh: self.arrow_mesh.clone(),
material: material_set.passive.clone(),
..default()
});
})
.set_parent(parent)
.id();

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

pub fn make_draggable_axis(
Expand Down Expand Up @@ -121,12 +123,11 @@ impl InteractionAssets {
anchor: Entity,
cue: &mut AnchorVisualization,
) {
let drag_parent = commands.entity(anchor).add_children(|parent| {
parent
.spawn(SpatialBundle::default())
.insert(VisualCue::no_outline().irregular().always_xray())
.id()
});
let drag_parent = commands
.spawn(SpatialBundle::default())
.insert(VisualCue::no_outline().irregular().always_xray())
.set_parent(anchor)
.id();

let height = 0.0;
let scale = 0.2;
Expand Down Expand Up @@ -167,12 +168,11 @@ impl InteractionAssets {
cue: &mut AnchorVisualization,
draggable: bool,
) {
let drag_parent = commands.entity(anchor).add_children(|parent| {
parent
.spawn(SpatialBundle::default())
.insert(VisualCue::no_outline().irregular().always_xray())
.id()
});
let drag_parent = commands
.spawn(SpatialBundle::default())
.insert(VisualCue::no_outline().irregular().always_xray())
.id();
commands.entity(anchor).add_child(drag_parent);

let for_entity = if draggable { Some(anchor) } else { None };
let scale = 0.2;
Expand All @@ -197,7 +197,7 @@ impl InteractionAssets {
self.make_axis(commands, for_entity, drag_parent, m, p, r, scale);
}

commands.entity(drag_parent).add_children(|parent| {
commands.entity(drag_parent).with_children(|parent| {
for (polyline, material) in &self.centimeter_finite_grid {
parent.spawn(PolylineBundle {
polyline: polyline.clone(),
Expand Down
171 changes: 84 additions & 87 deletions rmf_site_editor/src/interaction/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,98 +65,95 @@ pub fn add_physical_light_visual_cues(
headlight_toggle.0 = false;
}

let bodies = commands
.entity(e)
.insert(light_material.clone())
.add_children(|parent| {
let point = parent
.spawn(SpatialBundle {
visibility: Visibility {
is_visible: kind.is_point(),
},
..default()
})
.with_children(|point| {
point
.spawn(PbrBundle {
mesh: assets.point_light_socket_mesh.clone(),
material: assets.physical_light_cover_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());

point
.spawn(PbrBundle {
mesh: assets.point_light_shine_mesh.clone(),
material: light_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());
})
.id();

let spot = parent
.spawn(SpatialBundle {
visibility: Visibility {
is_visible: kind.is_spot(),
},
let point = commands
.spawn(SpatialBundle {
visibility: Visibility {
is_visible: kind.is_point(),
},
..default()
})
.with_children(|point| {
point
.spawn(PbrBundle {
mesh: assets.point_light_socket_mesh.clone(),
material: assets.physical_light_cover_material.clone(),
..default()
})
.with_children(|spot| {
spot.spawn(PbrBundle {
mesh: assets.spot_light_cover_mesh.clone(),
material: assets.physical_light_cover_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());

spot.spawn(PbrBundle {
mesh: assets.spot_light_shine_mesh.clone(),
material: light_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());
})
.id();
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());

let directional = parent
.spawn(SpatialBundle {
visibility: Visibility {
is_visible: kind.is_directional(),
},
point
.spawn(PbrBundle {
mesh: assets.point_light_shine_mesh.clone(),
material: light_material.clone(),
..default()
})
.with_children(|dir| {
dir.spawn(PbrBundle {
mesh: assets.directional_light_cover_mesh.clone(),
material: assets.direction_light_cover_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());

dir.spawn(PbrBundle {
mesh: assets.directional_light_shine_mesh.clone(),
material: light_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());
})
.id();

return LightBodies {
point,
spot,
directional,
};
});

commands.entity(e).insert(bodies);
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());
})
.id();

let spot = commands
.spawn(SpatialBundle {
visibility: Visibility {
is_visible: kind.is_spot(),
},
..default()
})
.with_children(|spot| {
spot.spawn(PbrBundle {
mesh: assets.spot_light_cover_mesh.clone(),
material: assets.physical_light_cover_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());

spot.spawn(PbrBundle {
mesh: assets.spot_light_shine_mesh.clone(),
material: light_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());
})
.id();

let directional = commands
.spawn(SpatialBundle {
visibility: Visibility {
is_visible: kind.is_directional(),
},
..default()
})
.with_children(|dir| {
dir.spawn(PbrBundle {
mesh: assets.directional_light_cover_mesh.clone(),
material: assets.direction_light_cover_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());

dir.spawn(PbrBundle {
mesh: assets.directional_light_shine_mesh.clone(),
material: light_material.clone(),
..default()
})
.insert(Selectable::new(e))
.insert(DragPlaneBundle::new(e, Vec3::Z).globally());
})
.id();

commands
.entity(e)
.insert(light_material.clone())
.insert(LightBodies {
point,
spot,
directional,
})
.push_children(&[point, spot, directional]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/occupancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn calculate_grid(
);
}

commands.entity(level).add_children(|level| {
commands.entity(level).with_children(|level| {
level
.spawn(PbrBundle {
mesh: meshes.add(mesh.into()),
Expand Down
Loading