Skip to content

Commit

Permalink
Workcell editor mode (#120)
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Co-authored-by: Michael X. Grey <mxgrey@intrinsic.ai>
Co-authored-by: Arjo Chakravarty <arjoc@google.com>
  • Loading branch information
3 people authored May 12, 2023
1 parent a6eba94 commit f796e44
Show file tree
Hide file tree
Showing 73 changed files with 4,807 additions and 739 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci_web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:

- name: rust-wasm-target
run: |
rustup toolchain install nightly
rustup default nightly
rustup target add wasm32-unknown-unknown
- name: apt-deps
Expand All @@ -29,7 +27,7 @@ jobs:
- name: cargo-deps
run: |
cargo install wasm-bindgen-cli
cargo install wasm-bindgen-cli --vers =0.2.84
- uses: actions/checkout@v3

Expand Down
79 changes: 79 additions & 0 deletions assets/demo_workcells/demo.workcell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "test_workcell",
"id": 0,
"frames": {
"1": {
"parent": 0,
"Pose3D": {
"trans": [
5.0,
0.0,
0.0
],
"rot": {
"euler_xyz": [
{
"deg": 45.0
},
{
"deg": 30.0
},
{
"deg": 90.0
}
]
}
}
},
"2": {
"parent": 0,
"Pose3D": {
"trans": [
0.0,
5.0,
0.0
],
"rot": {
"euler_xyz": [
{
"deg": 45.0
},
{
"deg": 30.0
},
{
"deg": 90.0
}
]
}
}
},
"3": {
"parent": 1,
"Pose3D": {
"trans": [
1.0,
0.31817698,
0.60250926
],
"rot": {
"euler_xyz": [
{
"deg": 92.758385
},
{
"deg": -73.071754
},
{
"deg": -171.64337
}
]
}
}
}
},
"visuals": {
},
"collisions": {
}
}
3 changes: 2 additions & 1 deletion rmf_site_editor/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-Zshare-generics=off"]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold", "-Zshare-generics=off"]
20 changes: 15 additions & 5 deletions rmf_site_editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ name = "rmf_site_editor"

[dependencies]
bevy_egui = "0.19"
bevy_mod_picking = "0.10"
bevy_mod_picking = "0.11"
bevy_mod_raycast = "0.7"
bevy_mod_outline = "0.3.3"
bevy_infinite_grid = "0.6"
bevy_polyline = "0.4"
bevy_stl = "0.7.0"
bevy_obj = { git = "https://github.com/luca-della-vedova/bevy_obj", branch = "luca/scene_0.9", features = ["scene"]}
bevy_rapier3d = "0.20.0"
crossbeam-channel = "0.5.0"
smallvec = "*"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8.23"
serde_json = "1.0"
wasm-bindgen = "0.2"
# wasm-bindgen 0.2.85 introduces a compile error in stdweb
wasm-bindgen = "=0.2.84"
web-sys = { version = "0.3.56", features = ["console"] }
futures-lite = "1.12.0"
bevy = "0.9"
Expand All @@ -31,19 +38,22 @@ thiserror = "*"
rmf_site_format = { path = "../rmf_site_format", features = ["bevy"] }
itertools = "*"
bitfield = "*"
rfd = "0.11"
urdf-rs = "0.7"
# sdformat_rs = { path = "../../sdf_rust_experimental/sdformat_rs"}
sdformat_rs = { git = "https://github.com/open-rmf/sdf_rust_experimental", rev = "f86344f"}

# only enable the 'dynamic' feature if we're not building for web or windows
[target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "windows")))'.dependencies]
bevy = { version = "0.9", features = ["dynamic"] }
bevy = { version = "0.9", features = ["dynamic", "jpeg", "tga"] }
surf = { version = "2.3" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
rfd = "0.8.2"
clap = { version = "4.0.10", features = ["color", "derive", "help", "usage", "suggestions"] }

# windows doesnt work well with dynamic feature yet
[target.'cfg(target_os = "windows")'.dependencies]
bevy = "0.9"
bevy = { version = "0.9", features = ["jpeg", "tga"] }
surf = { version = "2.3" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly"
channel = "stable"
12 changes: 10 additions & 2 deletions rmf_site_editor/src/demo_world.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
pub fn demo_office() -> String {
return include_str!("../../assets/demo_maps/office.building.yaml").to_string();
pub fn demo_office() -> Vec<u8> {
return include_str!("../../assets/demo_maps/office.building.yaml")
.as_bytes()
.to_vec();
}

pub fn demo_workcell() -> Vec<u8> {
return include_str!("../../assets/demo_workcells/demo.workcell.json")
.as_bytes()
.to_vec();
}
80 changes: 59 additions & 21 deletions rmf_site_editor/src/interaction/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ pub struct AnchorVisualization {

pub fn add_anchor_visual_cues(
mut commands: Commands,
new_anchors: Query<(Entity, &Parent, Option<&Subordinate>), (Added<Anchor>, Without<Preview>)>,
new_anchors: Query<
(Entity, &Parent, Option<&Subordinate>, &Anchor),
(Added<Anchor>, Without<Preview>),
>,
categories: Query<&Category>,
site_assets: Res<SiteAssets>,
interaction_assets: Res<InteractionAssets>,
) {
for (e, parent, subordinate) in &new_anchors {
for (e, parent, subordinate, anchor) in &new_anchors {
let body_mesh = match categories.get(parent.get()).unwrap() {
Category::Level => site_assets.level_anchor_mesh.clone(),
Category::Lift => site_assets.lift_anchor_mesh.clone(),
_ => site_assets.site_anchor_mesh.clone(),
};

let mut commands = commands.entity(e);
let body = commands.add_children(|parent| {
let mut entity_commands = commands.entity(e);
let body = entity_commands.add_children(|parent| {
let mut body = parent.spawn(PbrBundle {
mesh: body_mesh,
material: site_assets.passive_anchor_material.clone(),
Expand All @@ -60,10 +63,16 @@ pub fn add_anchor_visual_cues(
body
});

commands
entity_commands
.insert(AnchorVisualization { body, drag: None })
.insert(OutlineVisualization::Anchor)
.insert(VisualCue::outline().irregular());
.insert(OutlineVisualization::Anchor { body });

// 3D anchors should always be visible with arrow cue meshes
if anchor.is_3D() {
entity_commands.insert(VisualCue::outline());
} else {
entity_commands.insert(VisualCue::outline().irregular());
}
}
}

Expand Down Expand Up @@ -166,15 +175,17 @@ pub fn update_anchor_cues_for_mode(
}

pub fn update_anchor_visual_cues(
mut command: Commands,
mut commands: Commands,
mut anchors: Query<
(
Entity,
&Anchor,
&Hovered,
&Selected,
&mut AnchorVisualization,
&mut VisualCue,
Option<&Subordinate>,
ChangeTrackers<Hovered>,
ChangeTrackers<Selected>,
),
Or<(Changed<Hovered>, Changed<Selected>, Changed<Dependents>)>,
Expand All @@ -187,7 +198,18 @@ pub fn update_anchor_visual_cues(
interaction_assets: Res<InteractionAssets>,
debug_mode: Option<Res<DebugMode>>,
) {
for (a, hovered, selected, mut shapes, mut cue, subordinate, select_tracker) in &mut anchors {
for (
a,
anchor,
hovered,
selected,
mut shapes,
mut cue,
subordinate,
hover_tracker,
select_tracker,
) in &mut anchors
{
if debug_mode.as_ref().filter(|d| d.0).is_some() {
// NOTE(MXG): I have witnessed a scenario where a lane is deleted
// and then the anchors that supported it are permanently stuck as
Expand Down Expand Up @@ -247,20 +269,36 @@ pub fn update_anchor_visual_cues(
);
}

if select_tracker.is_changed() {
if selected.cue() {
if shapes.drag.is_none() && subordinate.is_none() {
interaction_assets.add_anchor_draggable_arrows(
&mut command,
a,
shapes.as_mut(),
);
if anchor.is_3D() {
if select_tracker.is_changed() || hover_tracker.is_changed() {
if selected.cue() || hovered.cue() {
if shapes.drag.is_none() {
interaction_assets.add_anchor_gizmos_3D(
&mut commands,
a,
shapes.as_mut(),
subordinate.is_none(),
);
}
} else {
if let Some(drag) = shapes.drag {
commands.entity(drag).despawn_recursive();
}
shapes.drag = None;
}
} else {
if let Some(drag) = shapes.drag {
command.entity(drag).despawn_recursive();
}
} else {
if select_tracker.is_changed() {
if selected.cue() {
if shapes.drag.is_none() && subordinate.is_none() {
interaction_assets.add_anchor_gizmos_2D(&mut commands, a, shapes.as_mut());
}
} else {
if let Some(drag) = shapes.drag {
commands.entity(drag).despawn_recursive();
}
shapes.drag = None;
}
shapes.drag = None;
}
}
}
Expand Down
Loading

0 comments on commit f796e44

Please sign in to comment.