diff --git a/Cargo.toml b/Cargo.toml index e674879..1a8e5b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ bevy = { version = "0.9.1", features = [ "bevy_pbr" ]} wgpu-types = "0.14.1" -bevy_mod_picking = { git = "https://github.com/aevyrie/bevy_mod_picking", optional = true } +bevy_mod_picking = { version = "0.11", optional = true } [features] default = [ ] diff --git a/README.md b/README.md index 488638f..067133f 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ See [example folder](https://github.com/YoshieraHuang/bevy_outline/tree/v0.1/exa - [x] ~~the width of outliner seems not to be uniform.~~ - [x] ~~outline of built-in torus seems weird (algorithm is wrong and will be fixed in 0.8)~~ -- [ ] Pan + Orbit camera in example does not work with `main` branch +- [x] ~~Pan + Orbit camera in example does not work with `main` branch~~ # Bevy Version Support @@ -79,6 +79,7 @@ I intend to track the `main` branch of Bevy. PRs supporting this are welcome! |bevy|bevy_outline| |---|---| |0.7|0.1| +|0.9.1|0.2| # License diff --git a/examples/picking.rs b/examples/picking.rs index 4877e05..23b1b91 100644 --- a/examples/picking.rs +++ b/examples/picking.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use bevy_mod_picking::{PickableBundle, PickingCameraBundle}; // use bevy_obj::ObjPlugin; use bevy_outline::{ - picking::{DefaultPickingPlugins, HoverOutline, PressedOutline, SelectedOutline}, + picking::{DefaultPickingPlugins, HoverOutline, SelectedOutline}, OutlineMaterial, }; @@ -36,51 +36,51 @@ fn set_picking_outlines(mut commands: Commands, mut outlines: ResMut, + // asset_server: Res, // Uncomment this to spawn Monkey head mut ambient_light: ResMut, mut meshes: ResMut>, mut materials: ResMut>, ) { // Cube commands - .spawn_bundle(PbrBundle { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube::default())), material: materials.add(Color::rgb(0.2, 0.7, 0.8).into()), transform: Transform::from_xyz(2.0, 0.5, 0.0), ..default() }) - .insert_bundle(PickableBundle::default()); + .insert(PickableBundle::default()); // Sphere commands - .spawn_bundle(PbrBundle { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Icosphere::default())), material: materials.add(Color::rgb(0.3, 0.2, 0.1).into()), transform: Transform::from_xyz(-2.0, 0.5, 0.0), ..default() }) - .insert_bundle(PickableBundle::default()); + .insert(PickableBundle::default()); // Torus // The built-in torus has some mistakes which will be fixed in 0.8 commands - .spawn_bundle(PbrBundle { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Torus::default())), material: materials.add(Color::rgb(0.2, 0.2, 0.5).into()), transform: Transform::from_xyz(6.0, 0.5, 0.0), ..default() }) - .insert_bundle(PickableBundle::default()); + .insert(PickableBundle::default()); // Monkey head // commands - // .spawn_bundle(PbrBundle { + // .spawn(PbrBundle { // mesh: asset_server.load("head.obj"), // material: materials.add(Color::rgb(0.7, 0.2, 0.5).into()), // transform: Transform::from_xyz(-6.0, 0.5, 0.0), // ..default() // }) - // .insert_bundle(PickableBundle::default()); + // .insert(PickableBundle::default()); // Light ambient_light.brightness = 1.0; @@ -88,10 +88,10 @@ fn setup( // camera let camera_translation = Vec3::new(0.0, 6.0, 12.0); commands - .spawn_bundle(Camera3dBundle { + .spawn(Camera3dBundle { transform: Transform::from_translation(camera_translation) .looking_at(Vec3::ZERO, Vec3::Y), ..default() }) - .insert_bundle(PickingCameraBundle::default()); + .insert(PickingCameraBundle::default()); } diff --git a/examples/scene.rs b/examples/scene.rs index 3c9fa03..e95f1f7 100644 --- a/examples/scene.rs +++ b/examples/scene.rs @@ -44,7 +44,7 @@ fn setup( // Cube commands - .spawn_bundle(PbrBundle { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube::default())), material: materials.add(Color::rgb(0.2, 0.7, 0.8).into()), transform: Transform::from_xyz(2.0, 0.5, 0.0), @@ -54,7 +54,7 @@ fn setup( // Sphere commands - .spawn_bundle(PbrBundle { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Icosphere::default())), material: materials.add(Color::rgb(0.3, 0.2, 0.1).into()), transform: Transform::from_xyz(-2.0, 0.5, 0.0), @@ -64,7 +64,7 @@ fn setup( // Torus commands - .spawn_bundle(PbrBundle { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Torus::default())), material: materials.add(Color::rgb(0.2, 0.2, 0.5).into()), transform: Transform::from_xyz(6.0, 0.5, 0.0), @@ -89,7 +89,7 @@ fn setup( let camera_translation = Vec3::new(0.0, 6.0, 12.0); let radius = camera_translation.length(); commands - .spawn_bundle(Camera3dBundle { + .spawn(Camera3dBundle { transform: Transform::from_translation(camera_translation) .looking_at(Vec3::ZERO, Vec3::Y), ..default() @@ -125,7 +125,7 @@ fn pan_orbit_camera( mut ev_motion: EventReader, mut ev_scroll: EventReader, input_mouse: Res>, - mut query: Query<(&mut PanOrbitCamera, &mut Transform, &PerspectiveProjection)>, + mut query: Query<(&mut PanOrbitCamera, &mut Transform, &Projection)>, ) { // change input mapping for orbit and panning here let orbit_button = MouseButton::Right; @@ -182,7 +182,9 @@ fn pan_orbit_camera( any = true; // make panning distance independent of resolution and FOV, let window = get_primary_window_size(&windows); - pan *= Vec2::new(projection.fov * projection.aspect_ratio, projection.fov) / window; + if let Projection::Perspective(projection) = projection { + pan *= Vec2::new(projection.fov * projection.aspect_ratio, projection.fov) / window; + } // translate by local axes let right = transform.rotation * Vec3::X * -pan.x; let up = transform.rotation * Vec3::Y * pan.y; diff --git a/src/picking.rs b/src/picking.rs index 8e01d19..18a0b1a 100644 --- a/src/picking.rs +++ b/src/picking.rs @@ -4,8 +4,8 @@ use bevy::{ app::PluginGroupBuilder, ecs::{schedule::ShouldRun, system::EntityCommands}, prelude::{ - App, Changed, Commands, CoreStage, Deref, Entity, Handle, Or, Plugin, PluginGroup, Query, - Res, SystemSet, + App, Changed, Commands, CoreStage, Deref, Entity, Handle, IntoSystemDescriptor, Or, Plugin, + PluginGroup, Query, Res, Resource, SystemSet, }, ui::Interaction, }; @@ -21,27 +21,28 @@ use crate::{OutlineMaterial, OutlinePlugin}; /// Object get outlined instead of changing materials when hovered, clicked or selected. pub struct DefaultPickingPlugins; impl PluginGroup for DefaultPickingPlugins { - fn build(&mut self, group: &mut PluginGroupBuilder) { - group.add(PickingPlugin); - group.add(InteractablePickingPlugin); - group.add(OutlinePlugin); - group.add(OutlinePickingPlugin); + fn build(self) -> PluginGroupBuilder { + PluginGroupBuilder::start::() + .add(PickingPlugin) + .add(InteractablePickingPlugin) + .add(OutlinePlugin) + .add(OutlinePickingPlugin) } } /// `OutlineMaterial` handle resource used when object is hovered. /// If this resource does not exist in world, no outline will show. -#[derive(Deref)] +#[derive(Deref, Resource)] pub struct HoverOutline(pub Handle); /// `OutlineMaterial` handle resource used when object is selected. /// If this resource does not exist in world, no outline will show. -#[derive(Deref)] +#[derive(Deref, Resource)] pub struct SelectedOutline(pub Handle); /// `OutlineMaterial` handle resource used when object is pressed or clicked. /// If this resource does not exist in world, no outline will show. -#[derive(Deref)] +#[derive(Deref, Resource)] pub struct PressedOutline(pub Handle); /// Outline picking plugin as an alternative to `HighlightablePickingPlugin` in `bevy_mod_picking` @@ -119,7 +120,9 @@ fn mesh_highlighting( } #[inline] -fn set_outline> + Send + Sync + 'static>( +fn set_outline< + T: Deref> + Send + Sync + 'static + bevy::prelude::Resource, +>( entity_commands: &mut EntityCommands, outline: &Option>, ) {