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

Texture groups #165

Merged
merged 22 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 16 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
Binary file modified assets/textures/alignment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions assets/textures/alignment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions assets/textures/alpha.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/textures/attribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [`empty.png`](https://thenounproject.com/icon/empty-194055/)
* [`add.png`](https://thenounproject.com/icon/plus-1809810/)
* [`search.png`](https://thenounproject.com/icon/search-3743008/)
* [`merge.png`](https://thenounproject.com/icon/merge-3402180/)
* `trash.png`: @mxgrey
* `selected.png`: @mxgrey
* `alignment.png`: @mxgrey
Binary file added assets/textures/merge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 55 additions & 3 deletions rmf_site_editor/src/interaction/select_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
interaction::*,
site::{
drawing_editor::CurrentEditDrawing, Anchor, AnchorBundle, Category, Dependents,
DrawingMarker, Original, PathBehavior, Pending,
DrawingMarker, Original, PathBehavior, Pending, TextureNeedsAssignment,
},
CurrentWorkspace,
};
Expand Down Expand Up @@ -377,6 +377,25 @@ impl EdgePlacement {
})
}

fn with_extra<F>(self: Arc<Self>, f: F) -> Arc<Self>
where
F: Fn(&mut SelectAnchorPlacementParams, Entity) + Send + Sync + 'static,
{
let mut result = match Arc::try_unwrap(self) {
Ok(r) => r,
Err(r) => (*r).clone(),
};
let base = result.create;
result.create = Arc::new(
move |params: &mut SelectAnchorPlacementParams, edge: Edge<Entity>| {
let entity = base(params, edge);
f(params, entity);
entity
},
);
Arc::new(result)
}

fn update_dependencies(
mut anchor_selection: Option<&mut AnchorSelection>,
target: Entity,
Expand Down Expand Up @@ -812,6 +831,25 @@ impl PathPlacement {
})
}

fn with_extra<F>(self: Arc<Self>, f: F) -> Arc<Self>
where
F: Fn(&mut SelectAnchorPlacementParams, Entity) + Send + Sync + 'static,
{
let mut result = match Arc::try_unwrap(self) {
Ok(r) => r,
Err(r) => (*r).clone(),
};
let base = result.create;
result.create = Arc::new(
move |params: &mut SelectAnchorPlacementParams, path: Path<Entity>| {
let entity = base(params, path);
f(params, entity);
entity
},
);
Arc::new(result)
}

fn at_index(&self, index: usize) -> Arc<Self> {
Arc::new(Self {
index: Some(index),
Expand Down Expand Up @@ -1188,7 +1226,14 @@ impl SelectAnchorEdgeBuilder {
pub fn for_wall(self) -> SelectAnchor {
SelectAnchor {
target: self.for_element,
placement: EdgePlacement::new::<Wall<Entity>>(self.placement),
placement: EdgePlacement::new::<Wall<Entity>>(self.placement).with_extra(
|params, entity| {
params
.commands
.entity(entity)
.insert(TextureNeedsAssignment);
},
),
continuity: self.continuity,
scope: Scope::General,
}
Expand Down Expand Up @@ -1304,7 +1349,14 @@ impl SelectAnchorPathBuilder {
pub fn for_floor(self) -> SelectAnchor {
SelectAnchor {
target: self.for_element,
placement: PathPlacement::new::<Floor<Entity>>(self.placement),
placement: PathPlacement::new::<Floor<Entity>>(self.placement).with_extra(
|params, entity| {
params
.commands
.entity(entity)
.insert(TextureNeedsAssignment);
},
),
continuity: self.continuity,
scope: Scope::General,
}
Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Default for LogHistory {
{
let fmt_layer = tracing_subscriber::fmt::Layer::default();
let subscriber = subscriber.with(fmt_layer);
tracing::subscriber::set_global_default(subscriber);
tracing::subscriber::set_global_default(subscriber).ok();
}
#[cfg(target_arch = "wasm32")]
{
Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn dispatch_save_events(
if let Some(file) = default_files.get(ws_root).ok().map(|f| f.0.clone()) {
file
} else {
let Some(file) = FileDialog::new().save_file() else {
let Some(file) = FileDialog::new().save_file() else {
continue;
};
file
Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/sdf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn load_model<'a, 'b>(
match root {
Ok(root) => {
if let Some(model) = root.model {
let path = load_context.path().clone().to_str().unwrap().to_string();
let path = load_context.path().to_str().unwrap().to_string();
let sdf_root = SdfRoot { model, path };
load_context.set_default_asset(LoadedAsset::new(sdf_root));
Ok(())
Expand Down
18 changes: 8 additions & 10 deletions rmf_site_editor/src/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,14 +1111,8 @@ pub(crate) fn make_closed_path_outline(mut initial_positions: Vec<[f32; 3]>) ->
let p0 = Vec3::new(p0[0], p0[1], 0.0);
let p1 = Vec3::new(p1[0], p1[1], 0.0);
let p2 = Vec3::new(p2[0], p2[1], 0.0);
let v0 = match (p1 - p0).try_normalize() {
Some(v) => v,
None => continue,
};
let v1 = match (p2 - p1).try_normalize() {
Some(v) => v,
None => continue,
};
let v0 = (p1 - p0).normalize_or_zero();
let v1 = (p2 - p1).normalize_or_zero();

// n: normal
let n = Vec3::Z;
Expand Down Expand Up @@ -1279,7 +1273,9 @@ pub(crate) fn make_finite_grid(

let mut polylines: HashMap<u32, Polyline> = HashMap::new();
let mut result = {
let Some(width) = weights.values().last().copied() else { return Vec::new() };
let Some(width) = weights.values().last().copied() else {
return Vec::new();
};
let mut axes: Vec<(Polyline, PolylineMaterial)> = Vec::new();

for (sign, x_axis_color, y_axis_color) in [
Expand Down Expand Up @@ -1308,7 +1304,9 @@ pub(crate) fn make_finite_grid(
for n in 1..=count {
let d = n as f32 * scale;
let polylines = {
let Some(weight_key) = weights.keys().rev().find(|k| n % **k == 0) else { continue };
let Some(weight_key) = weights.keys().rev().find(|k| n % **k == 0) else {
continue;
};
polylines.entry(*weight_key).or_default()
};

Expand Down
36 changes: 27 additions & 9 deletions rmf_site_editor/src/site/drawing_editor/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@ pub fn align_site_drawings(
) {
for AlignSiteDrawings(site) in events.iter() {
let mut site_variables = SiteVariables::<Entity>::default();
let Ok(children) = sites.get(*site) else { continue };
let Ok(children) = sites.get(*site) else {
continue;
};
for child in children {
let Ok((group, point)) = params.fiducials.get(*child) else { continue };
let Ok(anchor) = params.anchors.get(point.0) else { continue };
let Ok((group, point)) = params.fiducials.get(*child) else {
continue;
};
let Ok(anchor) = params.anchors.get(point.0) else {
continue;
};
let Some(group) = group.0 else { continue };
let p = anchor.translation_for_category(Category::Fiducial);
site_variables.fiducials.push(FiducialVariables {
Expand All @@ -72,17 +78,23 @@ pub fn align_site_drawings(
}

for child in children {
let Ok(level_children) = levels.get(*child) else { continue };
let Ok(level_children) = levels.get(*child) else {
continue;
};
for level_child in level_children {
let Ok((drawing_children, pose, ppm)) = params.drawings.get(*level_child) else { continue };
let Ok((drawing_children, pose, ppm)) = params.drawings.get(*level_child) else {
continue;
};
let mut drawing_variables = DrawingVariables::<Entity>::new(
Vec2::from_slice(&pose.trans).as_dvec2(),
pose.rot.yaw().radians() as f64,
(1.0 / ppm.0) as f64,
);
for child in drawing_children {
if let Ok((group, point)) = params.fiducials.get(*child) {
let Ok(anchor) = params.anchors.get(point.0) else { continue };
let Ok(anchor) = params.anchors.get(point.0) else {
continue;
};
let Some(group) = group.0 else { continue };
let p = anchor.translation_for_category(Category::Fiducial);
drawing_variables.fiducials.push(FiducialVariables {
Expand All @@ -92,8 +104,12 @@ pub fn align_site_drawings(
}

if let Ok((edge, distance)) = params.measurements.get(*child) {
let Ok([anchor0, anchor1]) = params.anchors.get_many(edge.array()) else { continue };
let Some(in_meters) = distance.0 else { continue };
let Ok([anchor0, anchor1]) = params.anchors.get_many(edge.array()) else {
continue;
};
let Some(in_meters) = distance.0 else {
continue;
};
let in_meters = in_meters as f64;
let p0 =
Vec2::from_slice(anchor0.translation_for_category(Category::Fiducial));
Expand All @@ -117,7 +133,9 @@ pub fn align_site_drawings(
// undo operation for this set of changes.
let alignments = align_site(&site_variables);
for (e, alignment) in alignments {
let Ok((_, mut pose, mut ppm)) = params.drawings.get_mut(e) else { continue };
let Ok((_, mut pose, mut ppm)) = params.drawings.get_mut(e) else {
continue;
};
pose.trans[0] = alignment.translation.x as f32;
pose.trans[1] = alignment.translation.y as f32;
pose.rot =
Expand Down
33 changes: 26 additions & 7 deletions rmf_site_editor/src/site/fiducial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,26 @@ pub fn update_fiducial_usage_tracker(
.iter()
.chain(changed_fiducial.iter().map(|p| p.get()))
{
let Ok((_, mut tracker)) = unused_fiducial_trackers.get_mut(e) else { continue };
let Ok((_, mut tracker)) = unused_fiducial_trackers.get_mut(e) else {
continue;
};
reset_fiducial_usage(e, &mut tracker, &fiducials, &fiducial_groups, &children);
}

for changed_group in &changed_fiducial_groups {
let Ok((_, name, site)) = fiducial_groups.get(changed_group) else { continue };
let Ok((_, name, site)) = fiducial_groups.get(changed_group) else {
continue;
};
for (e, mut tracker) in &mut unused_fiducial_trackers {
if tracker.site == site.get() {
tracker.unused.insert(changed_group, name.0.clone());
let Ok(scope_children) = children.get(e) else { continue };
let Ok(scope_children) = children.get(e) else {
continue;
};
for child in scope_children {
let Ok(affiliation) = fiducials.get(*child) else { continue };
let Ok(affiliation) = fiducials.get(*child) else {
continue;
};
if let Some(group) = affiliation.0 {
if changed_group == group {
tracker.unused.remove(&changed_group);
Expand All @@ -132,7 +140,9 @@ pub fn update_fiducial_usage_tracker(
}

for (changed_fiducial, parent) in &changed_fiducials {
let Ok((e, mut tracker)) = unused_fiducial_trackers.get_mut(parent.get()) else { continue };
let Ok((e, mut tracker)) = unused_fiducial_trackers.get_mut(parent.get()) else {
continue;
};
reset_fiducial_usage(e, &mut tracker, &fiducials, &fiducial_groups, &children);
}

Expand Down Expand Up @@ -177,9 +187,13 @@ fn reset_fiducial_usage(
}
}

let Ok(scope_children) = children.get(entity) else { return };
let Ok(scope_children) = children.get(entity) else {
return;
};
for child in scope_children {
let Ok(affiliation) = fiducials.get(*child) else { continue };
let Ok(affiliation) = fiducials.get(*child) else {
continue;
};
if let Some(group) = affiliation.0 {
tracker.unused.remove(&group);
if let Ok((_, name, _)) = fiducial_groups.get(group) {
Expand All @@ -192,6 +206,7 @@ fn reset_fiducial_usage(
pub fn add_fiducial_visuals(
mut commands: Commands,
fiducials: Query<(Entity, &Point<Entity>, Option<&Transform>), Added<FiducialMarker>>,
fiducial_groups: Query<Entity, (Added<FiducialMarker>, With<Group>)>,
mut dependents: Query<&mut Dependents, With<Anchor>>,
assets: Res<SiteAssets>,
) {
Expand All @@ -213,6 +228,10 @@ pub fn add_fiducial_visuals(
.insert(Category::Fiducial)
.insert(VisualCue::outline());
}

for e in &fiducial_groups {
commands.entity(e).insert(Category::FiducialGroup);
}
}

pub fn assign_orphan_fiducials_to_parent(
Expand Down
Loading