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

Fixed problems of 0.2 version #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [ ]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
24 changes: 12 additions & 12 deletions examples/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -36,62 +36,62 @@ fn set_picking_outlines(mut commands: Commands, mut outlines: ResMut<Assets<Outl

fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
// asset_server: Res<AssetServer>, // Uncomment this to spawn Monkey head
mut ambient_light: ResMut<AmbientLight>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// 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;

// 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());
}
14 changes: 8 additions & 6 deletions examples/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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()
Expand Down Expand Up @@ -125,7 +125,7 @@ fn pan_orbit_camera(
mut ev_motion: EventReader<MouseMotion>,
mut ev_scroll: EventReader<MouseWheel>,
input_mouse: Res<Input<MouseButton>>,
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;
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 14 additions & 11 deletions src/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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::<Self>()
.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>);

/// `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>);

/// `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<OutlineMaterial>);

/// Outline picking plugin as an alternative to `HighlightablePickingPlugin` in `bevy_mod_picking`
Expand Down Expand Up @@ -119,7 +120,9 @@ fn mesh_highlighting(
}

#[inline]
fn set_outline<T: Deref<Target = Handle<OutlineMaterial>> + Send + Sync + 'static>(
fn set_outline<
T: Deref<Target = Handle<OutlineMaterial>> + Send + Sync + 'static + bevy::prelude::Resource,
>(
entity_commands: &mut EntityCommands,
outline: &Option<Res<T>>,
) {
Expand Down