Skip to content

Commit

Permalink
reorganize folders to separate picking backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Dec 9, 2024
1 parent 7fc9907 commit b418dc1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
4 changes: 4 additions & 0 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ bevy_egui = "0.31"
[[example]]
name = "picking3"
required-features = ["picking-backend"]

[[example]]
name = "testbed3"
required-features = ["picking-backend"]
22 changes: 11 additions & 11 deletions bevy_rapier3d/examples/picking3.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! A simple scene to demonstrate picking events for rapier [`Collider`] entities.
use bevy::prelude::*;
use bevy_rapier3d::plugin::picking_backend::{RapierPickingPlugin, RapierPickingSettings};
use bevy_rapier3d::prelude::*;
use picking_backend::RapierPickable;

fn main() {
App::new()
Expand All @@ -22,11 +20,20 @@ fn main() {
require_markers: true,
..Default::default()
})
.add_systems(Startup, setup_scene)
.add_systems(Startup, (setup_graphics, setup_physics))
.run();
}

fn setup_scene(mut commands: Commands) {
pub fn setup_graphics(mut commands: Commands) {
// Camera
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
RapierPickable,
));
}

pub fn setup_physics(mut commands: Commands) {
commands
.spawn((
Text::new("Click Me to get a box\nDrag cubes to rotate"),
Expand Down Expand Up @@ -58,13 +65,6 @@ fn setup_scene(mut commands: Commands) {
Collider::cuboid(ground_size, ground_height, ground_size),
ColliderDebugColor(Hsla::BLACK),
));

// Camera
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
RapierPickable,
));
}

fn on_click_spawn_cube(
Expand Down
11 changes: 11 additions & 0 deletions bevy_rapier3d/examples/testbed3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod joints3;
mod joints_despawn3;
mod locked_rotations3;
mod multiple_colliders3;
mod picking3;
mod ray_casting3;
mod static_trimesh3;

Expand All @@ -28,6 +29,7 @@ pub enum Examples {
JointsDespawn3,
LockedRotations3,
MultipleColliders3,
Picking3,
Raycasting3,
StaticTrimesh3,
}
Expand Down Expand Up @@ -64,6 +66,7 @@ fn main() {
RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(),
WorldInspectorPlugin::new(),
RapierPickingPlugin::default(),
))
.register_type::<Examples>()
.register_type::<ExamplesRes>()
Expand All @@ -78,6 +81,7 @@ fn main() {
(Examples::JointsDespawn3, "JointsDespawn3").into(),
(Examples::LockedRotations3, "LockedRotations3").into(),
(Examples::MultipleColliders3, "MultipleColliders3").into(),
(Examples::Picking3, "Picking3").into(),
(Examples::Raycasting3, "Raycasting3").into(),
(Examples::StaticTrimesh3, "StaticTrimesh3").into(),
]))
Expand Down Expand Up @@ -173,6 +177,13 @@ fn main() {
)
.add_systems(OnExit(Examples::MultipleColliders3), cleanup)
//
// picking
.add_systems(
OnEnter(Examples::Picking3),
(picking3::setup_graphics, picking3::setup_physics),
)
.add_systems(OnExit(Examples::Picking3), cleanup)
//
// raycasting
.add_systems(
OnEnter(Examples::Raycasting3),
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ pub mod pipeline;
/// The physics plugin and systems.
pub mod plugin;

#[cfg(feature = "picking-backend")]
/// The bevy_picking rapier backend plugin and systems.
pub mod picking_backend;

/// Components related to character control.
pub mod control;
/// The debug-renderer.
Expand All @@ -71,6 +75,8 @@ pub mod prelude {
pub use crate::dynamics::*;
pub use crate::geometry::*;
pub use crate::math::*;
#[cfg(feature = "picking-backend")]
pub use crate::picking_backend::*;
pub use crate::pipeline::*;
pub use crate::plugin::*;
#[cfg(any(feature = "debug-render-3d", feature = "debug-render-2d"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bevy::picking::{
use bevy::reflect::prelude::*;
use bevy::render::{prelude::*, view::RenderLayers};

use super::RapierContext;
use crate::prelude::RapierContext;

/// How a ray cast should handle [`Visibility`].
#[derive(Clone, Copy, Reflect)]
Expand Down
3 changes: 0 additions & 3 deletions src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ pub use narrow_phase::{ContactManifoldView, ContactPairView, ContactView, Solver
#[allow(clippy::too_many_arguments)]
pub mod systems;

#[cfg(feature = "picking-backend")]
pub mod picking_backend;

mod configuration;
mod context;
mod narrow_phase;
Expand Down

0 comments on commit b418dc1

Please sign in to comment.