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 4 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
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
21 changes: 11 additions & 10 deletions rmf_site_editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ 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_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 All @@ -55,6 +53,9 @@ nalgebra = "0.32.5"

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

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.7"
# Disable the manage_clipboard feature, depends on nightly web features
bevy_egui = { version = "0.27", features = ["open_url", "default_fonts", "render"] }
Copy link
Member Author

Choose a reason for hiding this comment

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

Ref mvlabat/bevy_egui#270, manage_clipboard only works on nightly web APIs

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
55 changes: 43 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 @@ -61,6 +59,22 @@ pub const XRAY_RENDER_LAYER: u8 = 5;
/// models in the engine without having them being visible to general cameras
pub const MODEL_PREVIEW_LAYER: u8 = 6;

// Creates all the layers visible in the main camera view (excluding, for example
// the model preview which is on a separate view). The main lights will affect these.
pub fn main_view_render_layers() -> RenderLayers {
RenderLayers::from_layers(&[
GENERAL_RENDER_LAYER,
PHYSICAL_RENDER_LAYER,
VISUAL_CUE_RENDER_LAYER,
SELECTED_OUTLINE_LAYER,
HOVERED_OUTLINE_LAYER,
XRAY_RENDER_LAYER,
])
}

/// Camera exposure, adjusted for indoor lighting, in ev100 units
pub const DEFAULT_CAMERA_EV100: f32 = 3.5;

/// Camera limits
pub const MIN_FOV: f32 = 5.0;
pub const MAX_FOV: f32 = 120.0;
Expand Down Expand Up @@ -257,11 +271,12 @@ impl FromWorld for CameraControls {
.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
shadows_enabled: false,
illuminance: 20000.,
illuminance: 50.,
..default()
},
..default()
})
.insert(main_view_render_layers())
.id();

let perspective_child_cameras = [
Expand All @@ -273,12 +288,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: DEFAULT_CAMERA_EV100,
},
..default()
})
.insert(VisibilityBundle {
Expand All @@ -293,6 +311,9 @@ impl FromWorld for CameraControls {
.spawn(Camera3dBundle {
transform: Transform::from_xyz(-10., -10., 10.).looking_at(Vec3::ZERO, Vec3::Z),
projection: Projection::Perspective(Default::default()),
exposure: Exposure {
ev100: DEFAULT_CAMERA_EV100,
},
tonemapping: Tonemapping::ReinhardLuminance,
..default()
})
Expand All @@ -316,11 +337,12 @@ impl FromWorld for CameraControls {
)),
directional_light: DirectionalLight {
shadows_enabled: false,
illuminance: 20000.,
illuminance: 50.,
..default()
},
..default()
})
.insert(main_view_render_layers())
.id();

let ortho_projection = OrthographicProjection {
Expand All @@ -341,13 +363,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: DEFAULT_CAMERA_EV100,
},
tonemapping: Tonemapping::ReinhardLuminance,
..default()
})
Expand All @@ -367,6 +389,9 @@ impl FromWorld for CameraControls {
},
transform: Transform::from_xyz(0., 0., 20.).looking_at(Vec3::ZERO, Vec3::Y),
projection: Projection::Orthographic(ortho_projection),
exposure: Exposure {
ev100: DEFAULT_CAMERA_EV100,
},
tonemapping: Tonemapping::ReinhardLuminance,
..default()
})
Expand All @@ -382,6 +407,12 @@ impl FromWorld for CameraControls {
.push_children(&orthographic_child_cameras)
.id();

let mut ambient_light = world
.get_resource_mut::<AmbientLight>()
.expect("Make sure bevy's PbrPlugin is initialized before the cameras");

ambient_light.brightness = 2.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.

Since we made everything a lot darker than default bevy, I also had to reduce the ambient light otherwise its effect would be overwhelming the rendering and everything would look washed out.


CameraControls {
mode: ProjectionMode::Perspective,
perspective_camera_entities: [
Expand Down Expand Up @@ -463,7 +494,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
Loading
Loading