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

Bevy 0.13 #314

Merged
merged 41 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
7d8bab1
Bump bevy to 0.13
StrikeForceZero Feb 18, 2024
0abfb1d
Explicitly discard returns
StrikeForceZero Feb 18, 2024
e2c3f91
Replace deprecated Query::for_each_mut usage
StrikeForceZero Feb 18, 2024
85e98da
Add remaining patterns for MouseButton
StrikeForceZero Feb 18, 2024
9e75c0f
Replace WorldQuery with QueryData
StrikeForceZero Feb 18, 2024
53acd94
Replace bevy_input::Input usage with ButtonInput
StrikeForceZero Feb 18, 2024
85f5c54
Replace UICameraConfig Query with (Node, Visibility)
StrikeForceZero Feb 18, 2024
7686829
Replace TextureAtlasSprite usage with TextureAtlasLayout
StrikeForceZero Feb 18, 2024
a9774f7
Remove into() calls failing to infer types
StrikeForceZero Feb 18, 2024
13d1784
Add dependency bevy_hierarchy@^0.13 for backend/bevy_picking_ui
StrikeForceZero Feb 18, 2024
369bc62
Update ui_picking
StrikeForceZero Feb 18, 2024
85f58f6
Bump dependencies bevy_eventlistener@^0.7, bevy_egui@^0.25, bevy_rapi…
StrikeForceZero Feb 19, 2024
2500474
WIP: Bump dependency bevy_mod_raycast@^0.16
StrikeForceZero Feb 19, 2024
3539124
Add default to LogPlugin
StrikeForceZero Feb 19, 2024
e8befeb
Replace Color + Vec4 usages with Color + Color:rgba
StrikeForceZero Feb 19, 2024
ad249bb
Update ClearColorConfig usages
StrikeForceZero Feb 19, 2024
2e520e0
Update generic parameters for EntityCommands implementation
StrikeForceZero Feb 19, 2024
80e02a6
Replace App.add_state usage with App.init_state
StrikeForceZero Feb 19, 2024
5d6fb64
Replace Ray3d::from_screenspace usage with ray_from_screenspace
StrikeForceZero Feb 19, 2024
56f3aab
Dereference ray.direction before passing to cast_ray_and_get_normal
StrikeForceZero Feb 19, 2024
c0e6b89
Add can_bubble attribute to Pointer
StrikeForceZero Feb 21, 2024
3cb0d06
chore(update): flatten system params
RobWalt Feb 21, 2024
27760f3
chore(update): use InheritedVisibility instead of Visibility
RobWalt Feb 21, 2024
664a883
chore(update): add sorting based on `IsDefaultUiCamera` marker
RobWalt Feb 21, 2024
0693b60
chore(update): remove `let _ = ` and just ignore event sends
RobWalt Feb 21, 2024
a5672ee
Bump dependency bevy_mod_raycast@^0.17
StrikeForceZero Feb 23, 2024
81e3774
Remove into() calls failing to infer types
StrikeForceZero Feb 23, 2024
042c58a
chore: apply rustfmt to satisfy linter
StrikeForceZero Feb 23, 2024
5764e17
Remove unnecessary cast
StrikeForceZero Feb 23, 2024
10995a3
Remove unused imports in examples
StrikeForceZero Feb 23, 2024
a1cc453
Replace deprecated Query::for_each_mut usage
StrikeForceZero Feb 23, 2024
7362341
Merge remote-tracking branch 'origin/main' into pr/StrikeForceZero/314
aevyrie Feb 24, 2024
6401681
Fix clippy
aevyrie Feb 24, 2024
bb71a32
Formatting and documentation
aevyrie Feb 24, 2024
faf3f57
Fix lighting intensity
aevyrie Feb 24, 2024
1f9e2f4
Fix clipper error behind feature flag
aevyrie Feb 24, 2024
3e76611
Fix sprite backend using sprite atlas extents instead of sprite
aevyrie Feb 24, 2024
d91aa4c
Match plane to previous size in examples
aevyrie Feb 24, 2024
7fb5c3c
Fix bevy ui backend and debug overlay
aevyrie Feb 26, 2024
989e89f
Clean up debug for 0.13
aevyrie Mar 3, 2024
2a262bb
Update examples to have debugging on by default
aevyrie Mar 3, 2024
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# UNRELEASED

- Changed: simplified debug settings and examples. Debug settings can be changed with the
`DebugPickingMode` resource.
- Fixed: replaced uses of `.insert` with `.try_insert`, where they could potentially panic.
- Fixed: replace all `.single` calls with matched `.get_single` calls to avoid crashing in
environments where there is no window available
Expand Down
33 changes: 17 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@ all-features = true
members = ["crates/*", "backends/*"]

[dependencies]
bevy_app = { version = "0.12", default-features = false }
bevy_core = { version = "0.12", default-features = false }
bevy_ecs = { version = "0.12", default-features = false }
bevy_math = { version = "0.12", default-features = false }
bevy_reflect = { version = "0.12", default-features = false }
bevy_render = { version = "0.12", default-features = false }
bevy_text = { version = "0.12", optional = true, default-features = false, features = [
bevy_app = { version = "0.13", default-features = false }
bevy_core = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_math = { version = "0.13", default-features = false }
bevy_reflect = { version = "0.13", default-features = false }
bevy_render = { version = "0.13", default-features = false }
bevy_core_pipeline = { version = "0.13", optional = true, default-features = false }
bevy_text = { version = "0.13", optional = true, default-features = false, features = [
"default_font",
] }
bevy_ui = { version = "0.12", optional = true, default-features = false }
bevy_utils = { version = "0.12", default-features = false }
bevy_window = { version = "0.12", default-features = false }
bevy_ui = { version = "0.13", optional = true, default-features = false }
bevy_utils = { version = "0.13", default-features = false }
bevy_window = { version = "0.13", default-features = false }

bevy_eventlistener = "0.6"
bevy_egui = { optional = true, version = "0.23" }
bevy_rapier3d = { optional = true, version = "0.23" }
bevy_eventlistener = "0.7"
bevy_egui = { optional = true, version = "0.25" }
bevy_rapier3d = { optional = true, version = "0.25" }

# Local
bevy_picking_core = { path = "crates/bevy_picking_core", version = "0.17" }
Expand All @@ -48,7 +49,7 @@ bevy_picking_sprite = { optional = true, path = "backends/bevy_picking_sprite",
bevy_picking_egui = { optional = true, path = "backends/bevy_picking_egui", version = "0.17" }

[dev-dependencies]
bevy = { version = "0.12", default-features = false, features = [
bevy = { version = "0.13", default-features = false, features = [
"bevy_winit",
"x11",
"bevy_gltf",
Expand Down Expand Up @@ -87,7 +88,7 @@ selection = [
"bevy_picking_highlight/selection",
]
highlight = ["bevy_picking_highlight/pbr"]
debug = ["bevy_text", "bevy_ui/bevy_text"]
debug = ["bevy_text", "bevy_ui/bevy_text", "bevy_core_pipeline"]
backend_raycast = ["bevy_picking_raycast"]
backend_rapier = ["bevy_picking_rapier", "bevy_rapier3d"]
backend_sprite = ["bevy_picking_sprite", "bevy_picking_highlight/sprite"]
Expand All @@ -112,7 +113,7 @@ required-features = ["backend_egui"]
[[example]]
name = "multiple_windows"
path = "examples/multiple_windows.rs"
required-features = ["backend_egui"]
# required-features = ["backend_egui"]

[[example]]
name = "virtual_pointer"
Expand Down
10 changes: 5 additions & 5 deletions backends/bevy_picking_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_app = { version = "0.12", default-features = false }
bevy_ecs = { version = "0.12", default-features = false }
bevy_reflect = { version = "0.12", default-features = false }
bevy_render = { version = "0.12", default-features = false }
bevy_app = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_reflect = { version = "0.13", default-features = false }
bevy_render = { version = "0.13", default-features = false }

bevy_egui = "0.23"
bevy_egui = "0.25"
# Local
bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" }
bevy_picking_selection = { path = "../../crates/bevy_picking_selection", optional = true, version = "0.17" }
Expand Down
2 changes: 1 addition & 1 deletion backends/bevy_picking_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn egui_picking(
if ctx.get_mut().wants_pointer_input() {
let entry = (entity, HitData::new(entity, 0.0, None, None));
let order = 1_000_000f32; // Assume egui should be on top of everything else.
output.send(PointerHits::new(*pointer, Vec::from([entry]), order))
output.send(PointerHits::new(*pointer, Vec::from([entry]), order));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions backends/bevy_picking_rapier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_app = { version = "0.12", default-features = false }
bevy_ecs = { version = "0.12", default-features = false }
bevy_reflect = { version = "0.12", default-features = false }
bevy_render = { version = "0.12", default-features = false }
bevy_transform = { version = "0.12", default-features = false }
bevy_window = { version = "0.12", default-features = false }
bevy_app = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_reflect = { version = "0.13", default-features = false }
bevy_render = { version = "0.13", default-features = false }
bevy_transform = { version = "0.13", default-features = false }
bevy_window = { version = "0.13", default-features = false }

bevy_rapier3d = "0.23"
bevy_rapier3d = "0.25"
# Local
bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" }
2 changes: 1 addition & 1 deletion backends/bevy_picking_rapier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn update_hits(
if let Some((entity, hit_data)) = rapier_context
.cast_ray_and_get_normal(
ray.origin,
ray.direction,
*ray.direction,
f32::MAX,
true,
QueryFilter::new().predicate(&predicate),
Expand Down
14 changes: 7 additions & 7 deletions backends/bevy_picking_raycast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_app = { version = "0.12", default-features = false }
bevy_ecs = { version = "0.12", default-features = false }
bevy_reflect = { version = "0.12", default-features = false }
bevy_render = { version = "0.12", default-features = false }
bevy_transform = { version = "0.12", default-features = false }
bevy_window = { version = "0.12", default-features = false }
bevy_app = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_reflect = { version = "0.13", default-features = false }
bevy_render = { version = "0.13", default-features = false }
bevy_transform = { version = "0.13", default-features = false }
bevy_window = { version = "0.13", default-features = false }

bevy_mod_raycast = "0.16"
bevy_mod_raycast = { version = "0.17.0" }
# Local
bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" }
2 changes: 1 addition & 1 deletion backends/bevy_picking_raycast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn update_hits(
},
};
let picks = raycast
.cast_ray(ray.into(), &settings)
.cast_ray(ray, &settings)
.iter()
.map(|(entity, hit)| {
let hit_data = HitData::new(
Expand Down
16 changes: 8 additions & 8 deletions backends/bevy_picking_sprite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_app = { version = "0.12", default-features = false }
bevy_asset = { version = "0.12", default-features = false }
bevy_ecs = { version = "0.12", default-features = false }
bevy_math = { version = "0.12", default-features = false }
bevy_render = { version = "0.12", default-features = false }
bevy_sprite = { version = "0.12", default-features = false }
bevy_transform = { version = "0.12", default-features = false }
bevy_window = { version = "0.12", default-features = false }
bevy_app = { version = "0.13", default-features = false }
bevy_asset = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_math = { version = "0.13", default-features = false }
bevy_render = { version = "0.13", default-features = false }
bevy_sprite = { version = "0.13", default-features = false }
bevy_transform = { version = "0.13", default-features = false }
bevy_window = { version = "0.13", default-features = false }
# Local
bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" }
104 changes: 54 additions & 50 deletions backends/bevy_picking_sprite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bevy_asset::prelude::*;
use bevy_ecs::prelude::*;
use bevy_math::prelude::*;
use bevy_render::prelude::*;
use bevy_sprite::{Sprite, TextureAtlas, TextureAtlasSprite};
use bevy_sprite::{Sprite, TextureAtlas, TextureAtlasLayout};
use bevy_transform::prelude::*;
use bevy_window::PrimaryWindow;

Expand All @@ -38,24 +38,25 @@ pub fn sprite_picking(
cameras: Query<(Entity, &Camera, &GlobalTransform, &OrthographicProjection)>,
primary_window: Query<Entity, With<PrimaryWindow>>,
images: Res<Assets<Image>>,
texture_atlas: Res<Assets<TextureAtlas>>,
texture_atlas_layout: Res<Assets<TextureAtlasLayout>>,
sprite_query: Query<
(
Entity,
(Option<&Sprite>, Option<&TextureAtlasSprite>),
(Option<&Handle<Image>>, Option<&Handle<TextureAtlas>>),
Option<&Sprite>,
Option<&TextureAtlas>,
Option<&Handle<Image>>,
&GlobalTransform,
Option<&Pickable>,
&ViewVisibility,
),
Or<(With<Sprite>, With<TextureAtlasSprite>)>,
Or<(With<Sprite>, With<TextureAtlas>)>,
>,
mut output: EventWriter<PointerHits>,
) {
let mut sorted_sprites: Vec<_> = sprite_query.iter().collect();
sorted_sprites.sort_by(|a, b| {
(b.3.translation().z)
.partial_cmp(&a.3.translation().z)
(b.4.translation().z)
.partial_cmp(&a.4.translation().z)
.unwrap_or(Ordering::Equal)
});

Expand Down Expand Up @@ -89,51 +90,54 @@ pub fn sprite_picking(
.iter()
.copied()
.filter(|(.., visibility)| visibility.get())
.filter_map(|(entity, sprite, image, sprite_transform, pickable, ..)| {
if blocked {
return None;
}

// Hit box in sprite coordinate system
let (extents, anchor) = if let Some((sprite, image)) = sprite.0.zip(image.0) {
let extents = sprite
.custom_size
.or_else(|| images.get(image).map(|f| f.size().as_vec2()))?;
let anchor = sprite.anchor.as_vec();
(extents, anchor)
} else if let Some((sprite, atlas)) = sprite.1.zip(image.1) {
let extents = sprite.custom_size.or_else(|| {
texture_atlas
.get(atlas)
.map(|f| f.textures[sprite.index].size())
})?;
let anchor = sprite.anchor.as_vec();
(extents, anchor)
} else {
return None;
};

let center = -anchor * extents;
let rect = Rect::from_center_half_size(center, extents / 2.0);

// Transform cursor pos to sprite coordinate system
let cursor_pos_sprite = sprite_transform
.affine()
.inverse()
.transform_point3((cursor_pos_world, 0.0).into());

let is_cursor_in_sprite = rect.contains(cursor_pos_sprite.truncate());
blocked =
is_cursor_in_sprite && pickable.map(|p| p.should_block_lower) != Some(false);

// HitData requires a depth as calculated from the camera's near clipping plane
let depth = -cam_ortho.near - sprite_transform.translation().z;

is_cursor_in_sprite.then_some((entity, HitData::new(cam_entity, depth, None, None)))
})
.filter_map(
|(entity, sprite, atlas, image, sprite_transform, pickable, ..)| {
if blocked {
return None;
}

// Hit box in sprite coordinate system
let (extents, anchor) = if let Some((sprite, atlas)) = sprite.zip(atlas) {
let extents = sprite.custom_size.or_else(|| {
texture_atlas_layout
.get(&atlas.layout)
.map(|f| f.textures[atlas.index].size())
})?;
let anchor = sprite.anchor.as_vec();
(extents, anchor)
} else if let Some((sprite, image)) = sprite.zip(image) {
let extents = sprite
.custom_size
.or_else(|| images.get(image).map(|f| f.size().as_vec2()))?;
let anchor = sprite.anchor.as_vec();
(extents, anchor)
} else {
return None;
};

let center = -anchor * extents;
let rect = Rect::from_center_half_size(center, extents / 2.0);

// Transform cursor pos to sprite coordinate system
let cursor_pos_sprite = sprite_transform
.affine()
.inverse()
.transform_point3((cursor_pos_world, 0.0).into());

let is_cursor_in_sprite = rect.contains(cursor_pos_sprite.truncate());
blocked = is_cursor_in_sprite
&& pickable.map(|p| p.should_block_lower) != Some(false);

// HitData requires a depth as calculated from the camera's near clipping plane
let depth = -cam_ortho.near - sprite_transform.translation().z;

is_cursor_in_sprite
.then_some((entity, HitData::new(cam_entity, depth, None, None)))
},
)
.collect();

let order = camera.order as f32;
output.send(PointerHits::new(*pointer, picks, order))
output.send(PointerHits::new(*pointer, picks, order));
}
}
16 changes: 10 additions & 6 deletions backends/bevy_picking_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_app = { version = "0.12", default-features = false }
bevy_ecs = { version = "0.12", default-features = false }
bevy_render = { version = "0.12", default-features = false }
bevy_transform = { version = "0.12", default-features = false }
bevy_window = { version = "0.12", default-features = false }
bevy_ui = { version = "0.12", default-features = false }
bevy_app = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_hierarchy = { version = "0.13", default-features = false }
bevy_render = { version = "0.13", default-features = false }
bevy_transform = { version = "0.13", default-features = false }
bevy_window = { version = "0.13", default-features = false }
bevy_ui = { version = "0.13", default-features = false }
bevy_utils = { version = "0.13", default-features = false }
bevy_math = { version = "0.13", default-features = false }

# Local
bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" }
Loading
Loading