Skip to content

Commit

Permalink
clean comments + rename some code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Nov 28, 2024
1 parent de8dcce commit 66bab9a
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/plugin/picking_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
//! By default, all colliders are pickable. Picking can be disabled for individual entities
//! by adding [`PickingBehavior::IGNORE`].
//!
//! To make mesh picking entirely opt-in, set [`RapierPickingSettings::require_markers`]
//! To make rapier picking entirely opt-in, set [`RapierPickingSettings::require_markers`]
//! to `true` and add a [`RapierPickable`] component to the desired camera and target entities.
//!
//! To manually perform mesh ray casts independent of picking, use [`QueryPipeline`].
use bevy::app::prelude::*;
use bevy::ecs::prelude::*;
Expand Down Expand Up @@ -36,10 +34,10 @@ pub struct RapierPickingSettings {
/// [`RapierPickable`]. `false` by default.
///
/// This setting is provided to give you fine-grained control over which cameras and entities
/// should be used by the mesh picking backend at runtime.
/// should be used by the rapier picking backend at runtime.
pub require_markers: bool,

/// Determines how mesh picking should consider [`Visibility`]. When set to [`RapierCastVisibility::Any`],
/// Determines how rapier picking should consider [`Visibility`]. When set to [`RapierCastVisibility::Any`],
/// ray casts can be performed against both visible and hidden entities.
///
/// Defaults to [`RapierCastVisibility::Visible`], only performing picking against entities with [`InheritedVisibility`] set to `true`.
Expand Down Expand Up @@ -73,27 +71,23 @@ impl Plugin for RapierPickingPlugin {
}
}

/// Casts rays into the scene using [`MeshPickingSettings`] and sends [`PointerHits`] events.
/// Casts rays into the scene using [`RapierPickingSettings`] and sends [`PointerHits`] events.
#[allow(clippy::too_many_arguments)]
pub fn update_hits(
backend_settings: Res<RapierPickingSettings>,
ray_map: Res<RayMap>,
picking_cameras: Query<(&Camera, Option<&RapierPickable>, Option<&RenderLayers>)>,
pickables: Query<&PickingBehavior>,
marked_targets: Query<&RapierPickable>,
culling_query: Query<(Option<&InheritedVisibility>, Option<&ViewVisibility>)>,
layers: Query<&RenderLayers>,
rapier_context: Query<&RapierContext>,
mut output: EventWriter<PointerHits>,
) {
dbg!("update_hits");
for (&ray_id, &ray) in ray_map.map().iter() {
let Ok((camera, cam_pickable, cam_layers)) = picking_cameras.get(ray_id.camera) else {
dbg!("No camera found for ray_id");
continue;
};
if backend_settings.require_markers && cam_pickable.is_none() {
dbg!("Camera not marked as pickable");
continue;
}
let order = camera.order as f32;
Expand Down Expand Up @@ -166,8 +160,6 @@ pub fn update_hits(
},
);

// TODO: Sort picks by depth and check picking behavior ; or use raycast rather than intersections
dbg!(&picks);
if !picks.is_empty() {
output.send(PointerHits::new(ray_id.pointer, picks, order));
}
Expand Down

0 comments on commit 66bab9a

Please sign in to comment.