diff --git a/examples/3d_scene.rs b/examples/3d_scene.rs index 138b9cbc..d2db57e9 100644 --- a/examples/3d_scene.rs +++ b/examples/3d_scene.rs @@ -1,6 +1,9 @@ -use bevy::render::camera::PerspectiveProjection; -use bevy::{prelude::*, render::camera::Camera}; -use bevy_mod_picking; // Import all the picking goodies! +use bevy::{prelude::*, ui::FocusPolicy}; +use bevy_mod_picking::{ + DebugCursorPickingPlugin, DebugEventsPickingPlugin, HighlightablePickingPlugin, + InteractablePickingPlugin, NoDeselect, PickableBundle, PickableButton, PickableMesh, + PickingCameraBundle, PickingPlugin, +}; fn main() { App::build() @@ -29,32 +32,34 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, ) { - // add entities to the world + // plane commands - // plane - .spawn(PbrBundle { + .spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), ..Default::default() }) - .with_bundle(PickableBundle::default()) - // cube - .spawn(PbrBundle { + .insert_bundle(PickableBundle::default()); + + // cube + commands + .spawn_bundle(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::default() }) - .with_bundle(PickableBundle::default()) - // light - .spawn(LightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), - ..Default::default() - }) - // camera - .spawn(PerspectiveCameraBundle { + .insert_bundle(PickableBundle::default()); + // light + commands.spawn_bundle(LightBundle { + transform: Transform::from_xyz(4.0, 8.0, 4.0), + ..Default::default() + }); + // camera + commands + .spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..Default::default() }) - .with_bundle(PickingCameraBundle::default()); + .insert_bundle(PickingCameraBundle::default()); } diff --git a/examples/deselection.rs b/examples/deselection.rs index 84d16673..9b05775c 100644 --- a/examples/deselection.rs +++ b/examples/deselection.rs @@ -29,44 +29,47 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, ) { - // add entities to the world + // plane commands - // plane - .spawn(PbrBundle { + .spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), ..Default::default() }) - .with_bundle(PickableBundle::default()) - // cube - .spawn(PbrBundle { + .insert_bundle(PickableBundle::default()); + + // cube + commands + .spawn_bundle(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::default() }) - .with_bundle(PickableBundle::default()) - // cube with NoDeselect - .spawn(PbrBundle { + .insert_bundle(PickableBundle::default()); + // cube with NoDeselect + commands + .spawn_bundle(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(1.5, 0.5, 0.0), ..Default::default() }) - .with(PickableMesh::default()) - .with(Interaction::default()) - .with(PickableButton::default()) - .with(FocusPolicy::default()) - .with(NoDeselect) - // light - .spawn(LightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), - ..Default::default() - }) - // camera - .spawn(PerspectiveCameraBundle { + .insert(PickableMesh::default()) + .insert(Interaction::default()) + .insert(PickableButton::default()) + .insert(FocusPolicy::default()) + .insert(NoDeselect); + // light + commands.spawn_bundle(LightBundle { + transform: Transform::from_xyz(4.0, 8.0, 4.0), + ..Default::default() + }); + // camera + commands + .spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..Default::default() }) - .with_bundle(PickingCameraBundle::default()); + .insert_bundle(PickingCameraBundle::default()); } diff --git a/examples/events.rs b/examples/events.rs index 2a3813fe..f3d0c593 100644 --- a/examples/events.rs +++ b/examples/events.rs @@ -29,7 +29,7 @@ fn setup( // add entities to the world commands // camera - .spawn(PerspectiveCameraBundle { + .spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_matrix(Mat4::face_toward( Vec3::new(-3.0, 5.0, 8.0), Vec3::new(0.0, 0.0, 0.0), @@ -37,25 +37,27 @@ fn setup( )), ..Default::default() }) - .with_bundle(PickingCameraBundle::default()) - //plane - .spawn(PbrBundle { + .insert_bundle(PickingCameraBundle::default()); + //plane + commands + .spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 10.0 })), material: materials.add(Color::rgb(1.0, 1.0, 1.0).into()), ..Default::default() }) - .with_bundle(PickableBundle::default()) - // cube - .spawn(PbrBundle { + .insert_bundle(PickableBundle::default()); + // cube + commands + .spawn_bundle(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(1.0, 1.0, 1.0).into()), transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)), ..Default::default() }) - .with_bundle(PickableBundle::default()) - // light - .spawn(LightBundle { - transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), - ..Default::default() - }); + .insert_bundle(PickableBundle::default()); + // light + commands.spawn_bundle(LightBundle { + transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), + ..Default::default() + }); } diff --git a/examples/stress_test.rs b/examples/stress_test.rs index 19cd8f6f..eeba27fe 100644 --- a/examples/stress_test.rs +++ b/examples/stress_test.rs @@ -36,7 +36,7 @@ fn setup( // camera commands - .spawn(PerspectiveCameraBundle { + .spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_matrix(Mat4::face_toward( Vec3::new( f32::from(edge_length) * -0.55, @@ -52,14 +52,14 @@ fn setup( )), ..Default::default() }) - .with_bundle(PickingCameraBundle::default()); + .insert_bundle(PickingCameraBundle::default()); let _scenes: Vec = asset_server.load_folder("models").unwrap(); let mesh_handle = asset_server.get_handle("models/monkey/Monkey.gltf#Mesh0/Primitive0"); for i in 0..edge_length.pow(3) { let f_edge_length = edge_length as f32; commands - .spawn(PbrBundle { + .spawn_bundle(PbrBundle { mesh: mesh_handle.clone(), material: materials.add(StandardMaterial { base_color: Color::rgb(1.0, 1.0, 1.0), @@ -76,11 +76,11 @@ fn setup( )) * Transform::from_scale(Vec3::from([0.25, 0.25, 0.25])), ..Default::default() }) - .with_bundle(PickableBundle::default()) - .with(BoundVol::default()); + .insert_bundle(PickableBundle::default()) + .insert(BoundVol::default()); } - commands.spawn(LightBundle { + commands.spawn_bundle(LightBundle { transform: Transform::from_matrix(Mat4::face_toward( Vec3::new( f32::from(edge_length) * -0.8,