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

Update to Bevy 0.13 #232

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1,272 changes: 744 additions & 528 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/demo_maps/office.building.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ levels:
lights:
- {pose: {trans: [1672, 783, 2.6], rot: {euler_xyz: [{deg: 30}, {deg: 0}, {deg: 0}]}}, kind: {type: spot}}
- {pose: {trans: [1273, 783, 2.6]}, kind: {type: point, enable_shadows: false}}
- {pose: {trans: [1973, 633, 2.6]}, kind: {type: point, color: [0.5, 0.5, 1.0, 1.0]}}
- {pose: {trans: [1973, 633, 2.6]}, kind: {type: point, color: [0.5, 0.5, 1.0]}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lights in the bevy renderer itself don't use the alpha channel (and it's unclear what alpha even means for a light color), hence changed them to be RGB

vertices:
- [80.27, 1024.974, 0, ""]
- [580.795, 43.396, 0, ""]
Expand Down
19 changes: 9 additions & 10 deletions rmf_site_editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ name = "extending_site_editor"
path = "examples/extending_menu.rs"

[dependencies]
bevy_egui = "0.23"
bevy_mod_raycast = "0.16"
bevy_mod_outline = "0.6"
# PR merged after 0.10 but not released yet, bump to 0.10.1 once merged
bevy_infinite_grid = { git = "https://github.com/ForesightMiningSoftwareCorporation/bevy_infinite_grid", rev = "86018dd" }
bevy_gltf_export = { git = "https://github.com/luca-della-vedova/bevy_gltf_export", branch = "luca/transform_api"}
bevy_polyline = "0.8.1"
bevy_stl = "0.12"
bevy_obj = { version = "0.12.1", features = ["scene"] }
bevy_egui = "0.27"
bevy_mod_raycast = "0.17"
bevy_mod_outline = "0.7"
bevy_infinite_grid = "0.12"
bevy_gltf_export = { git = "https://github.com/luca-della-vedova/bevy_gltf_export", branch = "bevy_0.13"}
bevy_polyline = { git = "https://github.com/luca-della-vedova/bevy_polyline", branch = "luca/bevy_0.13_panic" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bevy_polyline in 0.13 panics, this is fixed in their 0.14 release but was not backported, once we update we won't need a custom branch anymore.

bevy_stl = "0.13"
bevy_obj = { version = "0.13", features = ["scene"] }
smallvec = "*"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8.23"
serde_json = "1.0"
wasm-bindgen = "0.2.87"
futures-lite = "1.12.0"
bevy = { version = "0.12", features = ["pnm", "jpeg", "tga"] }
bevy = { version = "0.13", features = ["pnm", "jpeg", "tga"] }
dirs = "5.0"
thread_local = "*"
geo = "0.27"
Expand Down
4 changes: 2 additions & 2 deletions rmf_site_editor/examples/extending_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl FromWorld for MyMenuHandler {
/// an event that is of the same type as the one we are supposed to
/// handle.
fn watch_unique_export_click(mut reader: EventReader<MenuEvent>, menu_handle: Res<MyMenuHandler>) {
for event in reader.iter() {
for event in reader.read() {
if event.clicked() && event.source() == menu_handle.unique_export {
println!("Doing our epic export");
}
Expand All @@ -67,7 +67,7 @@ fn watch_unique_export_click(mut reader: EventReader<MenuEvent>, menu_handle: Re
/// an event that is of the same type as the one we are supposed to
/// handle.
fn watch_submenu_click(mut reader: EventReader<MenuEvent>, menu_handle: Res<MyMenuHandler>) {
for event in reader.iter() {
for event in reader.read() {
if event.clicked() && event.source() == menu_handle.custom_nested_menu {
println!("Submenu clicked");
}
Expand Down
42 changes: 18 additions & 24 deletions rmf_site_editor/src/interaction/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use bevy_polyline::{
material::PolylineMaterial,
polyline::{Polyline, PolylineBundle},
};
use shape::UVSphere;

#[derive(Clone, Debug, Resource)]
pub struct InteractionAssets {
Expand Down Expand Up @@ -228,47 +227,42 @@ impl FromWorld for InteractionAssets {
let mut meshes = world.get_resource_mut::<Assets<Mesh>>().unwrap();
let dagger_mesh = meshes.add(make_dagger_mesh());
let halo_mesh = meshes.add(make_halo_mesh());
let camera_control_mesh = meshes.add(Mesh::from(UVSphere {
let camera_control_mesh = meshes.add(Mesh::from(Sphere {
radius: 0.02,
..Default::default()
}));
let arrow_mesh = meshes.add(make_cylinder_arrow_mesh());
let point_light_socket_mesh = meshes.add(
make_cylinder(0.06, 0.02)
.transform_by(Affine3A::from_translation(0.04 * Vec3::Z))
.into(),
make_cylinder(0.06, 0.02).transform_by(Affine3A::from_translation(0.04 * Vec3::Z)),
);
let point_light_shine_mesh = meshes.add(Mesh::from(shape::UVSphere {
let point_light_shine_mesh = meshes.add(Mesh::from(Sphere {
radius: 0.05,
..Default::default()
}));
let spot_light_cover_mesh = meshes.add(
make_smooth_wrap(
[
Circle {
radius: 0.05,
height: 0.0,
},
Circle {
radius: 0.01,
height: 0.04,
},
],
32,
)
.into(),
);
let spot_light_cover_mesh = meshes.add(make_smooth_wrap(
[
OffsetCircle {
radius: 0.05,
height: 0.0,
},
OffsetCircle {
radius: 0.01,
height: 0.04,
},
],
32,
));
let spot_light_shine_mesh = meshes.add(
Mesh::from(
make_bottom_circle(
Circle {
OffsetCircle {
Comment on lines -267 to +261
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle cannot be used anymore since it was added to the prelude as part of the primitive shape support effort.
I renamed this OffsetCircle since it's a circle with a Z offset but any other solution is also OK.

radius: 0.05,
height: 0.0,
},
32,
)
.merge_with(make_top_circle(
Circle {
OffsetCircle {
radius: 0.01,
height: 0.04,
},
Expand Down
16 changes: 8 additions & 8 deletions rmf_site_editor/src/interaction/camera_controls/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ pub fn update_cursor_command(
mut camera_controls: ResMut<CameraControls>,
mut cursor_command: ResMut<CursorCommand>,
mut mouse_wheel: EventReader<MouseWheel>,
mouse_input: Res<Input<MouseButton>>,
keyboard_input: Res<Input<KeyCode>>,
mouse_input: Res<ButtonInput<MouseButton>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
raycast_sources: Query<&RaycastSource<SiteRaycastSet>>,
cameras: Query<(&Projection, &Transform, &GlobalTransform)>,
primary_windows: Query<&Window, With<PrimaryWindow>>,
Expand Down Expand Up @@ -137,7 +137,7 @@ pub fn update_cursor_command(
Some(selection) => selection,
None => cursor_selection_new,
};
let cursor_direction = cursor_ray.direction().normalize();
let cursor_direction = cursor_ray.direction.normalize();
let cursor_direction_camera_frame = camera_transform.rotation.inverse() * cursor_direction;
let cursor_direction_camera_frame_prev = cursor_command
.cursor_direction_camera_frame
Expand Down Expand Up @@ -380,16 +380,16 @@ fn get_cursor_selected_point(
match cursor_raycast_source.get_nearest_intersection() {
Some((_, intersection)) => intersection.position(),
None => get_groundplane_else_default_selection(
cursor_ray.origin(),
cursor_ray.direction(),
camera_transform.forward(),
cursor_ray.origin,
*cursor_ray.direction,
*camera_transform.forward(),
),
}
}

fn get_command_type(
keyboard_input: &Res<Input<KeyCode>>,
mouse_input: &Res<Input<MouseButton>>,
keyboard_input: &Res<ButtonInput<KeyCode>>,
mouse_input: &Res<ButtonInput<MouseButton>>,
scroll_motion: &f32,
projection_mode: ProjectionMode,
) -> CameraCommandType {
Expand Down
10 changes: 5 additions & 5 deletions rmf_site_editor/src/interaction/camera_controls/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl KeyboardCommand {
pub fn update_keyboard_command(
mut camera_controls: ResMut<CameraControls>,
mut keyboard_command: ResMut<KeyboardCommand>,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
cameras: Query<(&Camera, &Projection, &Transform, &GlobalTransform)>,
immediate_raycast: Raycast,
time: Res<Time>,
Expand All @@ -92,16 +92,16 @@ pub fn update_keyboard_command(
let is_shifting = keyboard_input.pressed(KeyCode::ShiftLeft)
|| keyboard_input.pressed(KeyCode::ShiftRight);
let mut target_keyboard_motion = Vec2::ZERO;
if keyboard_input.pressed(KeyCode::Up) {
if keyboard_input.pressed(KeyCode::ArrowUp) {
target_keyboard_motion.y += 1.0;
}
if keyboard_input.pressed(KeyCode::Left) {
if keyboard_input.pressed(KeyCode::ArrowLeft) {
target_keyboard_motion.x += -1.0;
}
if keyboard_input.pressed(KeyCode::Down) {
if keyboard_input.pressed(KeyCode::ArrowDown) {
target_keyboard_motion.y += -1.0;
}
if keyboard_input.pressed(KeyCode::Right) {
if keyboard_input.pressed(KeyCode::ArrowRight) {
target_keyboard_motion.x += 1.0;
}
if target_keyboard_motion.length() > 0.0 {
Expand Down
27 changes: 15 additions & 12 deletions rmf_site_editor/src/interaction/camera_controls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
*/
use crate::interaction::{InteractionAssets, PickingBlockers};
use bevy::{
core_pipeline::{
clear_color::ClearColorConfig, core_3d::Camera3dBundle, tonemapping::Tonemapping,
},
core_pipeline::{core_3d::Camera3dBundle, tonemapping::Tonemapping},
prelude::*,
render::{
camera::{Camera, Projection, ScalingMode},
camera::{Camera, Exposure, Projection, ScalingMode},
view::RenderLayers,
},
};
Expand Down Expand Up @@ -257,11 +255,12 @@ impl FromWorld for CameraControls {
.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
shadows_enabled: false,
illuminance: 20000.,
illuminance: 5000.,
..default()
},
..default()
})
.insert(RenderLayers::all())
.id();

let perspective_child_cameras = [
Expand All @@ -273,12 +272,15 @@ impl FromWorld for CameraControls {
world
.spawn(Camera3dBundle {
projection: Projection::Perspective(Default::default()),
camera: Camera { order, ..default() },
camera_3d: Camera3d {
camera: Camera {
order,
clear_color: ClearColorConfig::None,
..default()
},
tonemapping: Tonemapping::ReinhardLuminance,
exposure: Exposure {
ev100: Exposure::EV100_INDOOR,
},
..default()
})
.insert(VisibilityBundle {
Expand Down Expand Up @@ -316,11 +318,12 @@ impl FromWorld for CameraControls {
)),
directional_light: DirectionalLight {
shadows_enabled: false,
illuminance: 20000.,
illuminance: 5000.,
..default()
},
..default()
})
.insert(RenderLayers::all())
.id();

let ortho_projection = OrthographicProjection {
Expand All @@ -341,13 +344,13 @@ impl FromWorld for CameraControls {
camera: Camera {
is_active: false,
order,
..default()
},
camera_3d: Camera3d {
clear_color: ClearColorConfig::None,
..default()
},
projection: Projection::Orthographic(ortho_projection.clone()),
exposure: Exposure {
ev100: Exposure::EV100_INDOOR,
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of the work on lighting and cameras, a new component was added for exposure. I'm defaulting it to indoor exposure and changing the light default accordingly.

tonemapping: Tonemapping::ReinhardLuminance,
..default()
})
Expand Down Expand Up @@ -463,7 +466,7 @@ fn camera_controls(

// Ensure upright
let forward = persp_transform.forward();
persp_transform.look_to(forward, Vec3::Z);
persp_transform.look_to(*forward, Vec3::Z);
}

let proj = persp_proj.clone();
Expand Down
13 changes: 5 additions & 8 deletions rmf_site_editor/src/interaction/camera_controls/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/

use bevy::prelude::*;
use bevy_mod_raycast::{
immediate::{Raycast, RaycastSettings, RaycastVisibility},
primitives::Ray3d,
};
use bevy_mod_raycast::immediate::{Raycast, RaycastSettings, RaycastVisibility};

use super::{MAX_PITCH, MAX_SELECTION_DIST, MIN_SELECTION_DIST};
use crate::UserCameraDisplay;
Expand Down Expand Up @@ -80,7 +77,7 @@ pub fn get_camera_selected_point(
let camera_ray = camera
.viewport_to_world(camera_global_transform, available_viewport_center)
.expect("Active camera does not have a valid ray from center of its viewport");
let camera_ray = Ray3d::new(camera_ray.origin, camera_ray.direction);
let camera_ray = Ray3d::new(camera_ray.origin, *camera_ray.direction);
let raycast_setting = RaycastSettings::default()
.always_early_exit()
.with_visibility(RaycastVisibility::MustBeVisible);
Expand All @@ -92,9 +89,9 @@ pub fn get_camera_selected_point(
return intersection_data.position();
} else {
return get_groundplane_else_default_selection(
camera_ray.origin(),
camera_ray.direction(),
camera_ray.direction(),
camera_ray.origin,
*camera_ray.direction,
*camera_ray.direction,
);
}
}
Expand Down
30 changes: 17 additions & 13 deletions rmf_site_editor/src/interaction/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ use crate::{
site::{AnchorBundle, Pending, SiteAssets, Trashcan},
};
use bevy::{ecs::system::SystemParam, prelude::*, window::PrimaryWindow};
use bevy_mod_raycast::{deferred::RaycastMesh, deferred::RaycastSource, primitives::rays::Ray3d};
use bevy_mod_raycast::{
deferred::RaycastMesh,
deferred::RaycastSource,
primitives::rays::{ray_from_screenspace, to_aligned_transform},
};
use rmf_site_format::{FloorMarker, Model, ModelMarker, PrimitiveShape, WallMarker, WorkcellModel};
use std::collections::HashSet;

Expand Down Expand Up @@ -290,17 +294,16 @@ impl<'w, 's> IntersectGroundPlaneParams<'w, 's> {
let active_camera = self.cameras.get(e_active_camera).ok()?;
let camera_tf = self.global_transforms.get(e_active_camera).ok()?;
let primary_window = self.primary_window.get_single().ok()?;
let ray =
Ray3d::from_screenspace(cursor_position, active_camera, camera_tf, primary_window)?;
let ray = ray_from_screenspace(cursor_position, active_camera, camera_tf, primary_window)?;
let n_p = Vec3::Z;
let n_r = ray.direction();
let denom = n_p.dot(n_r);
let n_r = ray.direction;
let denom = n_p.dot(*n_r);
if denom.abs() < 1e-3 {
// Too close to parallel
return None;
}

Some(ray.origin() - n_r * ray.origin().dot(n_p) / denom)
Some(ray.origin - n_r * ray.origin.dot(n_p) / denom)
}
}

Expand Down Expand Up @@ -336,7 +339,7 @@ pub fn update_cursor_transform(

let ray = Ray3d::new(intersection.position(), intersection.normal());

*transform = Transform::from_matrix(ray.to_aligned_transform([0., 0., 1.].into()));
*transform = Transform::from_matrix(to_aligned_transform(ray, [0., 0., 1.].into()));
}
InteractionMode::SelectAnchor(_) => {
let intersection = match intersect_ground_params.ground_plane_intersection() {
Expand Down Expand Up @@ -383,10 +386,10 @@ pub fn update_cursor_transform(
// to area, then populate a MeshConstraint component to be used by downstream
// spawning methods
// TODO(luca) there must be a better way to find a minimum given predicate in Rust
let triangle_vecs = vec![triangle.v1, triangle.v2];
let triangle_vecs = vec![triangle[1], triangle[2]];
let position = intersection.position();
let mut closest_vertex = triangle.v0;
let mut closest_dist = position.distance(triangle.v0.into());
let mut closest_vertex = triangle[0];
let mut closest_dist = position.distance(triangle[0].into());
for v in triangle_vecs {
let dist = position.distance(v.into());
if dist < closest_dist {
Expand All @@ -396,9 +399,10 @@ pub fn update_cursor_transform(
}
//closest_vertex = *triangle_vecs.iter().min_by(|position, ver| position.distance(**ver).cmp(closest_dist)).unwrap();
let ray = Ray3d::new(closest_vertex.into(), intersection.normal());
*transform = Transform::from_matrix(
ray.to_aligned_transform([0., 0., 1.].into()),
);
*transform = Transform::from_matrix(to_aligned_transform(
ray,
[0., 0., 1.].into(),
));
set_visibility(cursor.frame, &mut visibility, true);
} else {
// Hide the cursor
Expand Down
Loading
Loading