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

added filtering of 3d and 2d cameras to allow for 3d and 2d cameras to operate simultaneously #304

Merged
merged 4 commits into from
Feb 24, 2024
Merged
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
5 changes: 4 additions & 1 deletion crates/bevy_picking_core/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,13 @@ pub mod ray {
/// Iterate over each [`Ray`] and its [`RayId`] with [`RayMap::iter`].
///
/// ```
/// # use bevy_ecs::prelude::*;
/// # use bevy_picking_core::backend::ray::RayMap;
/// # use bevy_picking_core::backend::PointerHits;
/// // My raycasting backend
/// pub fn update_hits(ray_map: Res<RayMap>, mut output_events: EventWriter<PointerHits>,) {
/// for (&ray_id, &ray) in ray_map.iter() {
/// /// Run a raycast with each ray, returning any `PointerHits` found.
/// // Run a raycast with each ray, returning any `PointerHits` found.
/// }
/// }
/// ```
Expand Down
53 changes: 51 additions & 2 deletions examples/sprite.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Demonstrates how to use the bevy_sprite picking backend. This backend simply tests the bounds of
//! a sprite.
//!
//! This also renders a 3d view in the background, to demonstrate and test that camera order is
//! respected across different backends, in this case the sprite and 3d raycasting backends.

use bevy::{prelude::*, sprite::Anchor};
use bevy_mod_picking::prelude::*;
Expand All @@ -10,7 +13,7 @@ fn main() {
DefaultPlugins.set(low_latency_window_plugin()),
DefaultPickingPlugins,
))
.add_systems(Startup, (setup, setup_atlas))
.add_systems(Startup, (setup, setup_3d, setup_atlas))
.add_systems(Update, (move_sprite, animate_sprite))
.run();
}
Expand All @@ -32,7 +35,16 @@ fn move_sprite(

/// Set up a scene that tests all sprite anchor types.
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2dBundle {
camera_2d: Camera2d {
clear_color: bevy::core_pipeline::clear_color::ClearColorConfig::None,
},
camera: Camera {
order: 1,
..default()
},
..default()
});

let len = 128.0;
let sprite_size = Some(Vec2::splat(len / 2.0));
Expand Down Expand Up @@ -138,3 +150,40 @@ fn setup_atlas(
AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
));
}

fn setup_3d(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
},
PickableBundle::default(), // Optional: adds selection, highlighting, and helper components.
));
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
PickableBundle::default(), // Optional: adds selection, highlighting, and helper components.
));
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, -4.0),
..default()
});
commands.spawn((Camera3dBundle {
transform: Transform::from_xyz(3.0, 3.0, 3.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},));
}
Loading