Skip to content

Commit

Permalink
Merge pull request #6 from ForesightMiningSoftwareCorporation/duncan/…
Browse files Browse the repository at this point in the history
…fix-render-layers

fix: use RenderLayers to filter interactions between box frames and cameras
  • Loading branch information
bonsairobo authored Feb 23, 2024
2 parents 1c57382 + 0d9803c commit 8d390dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_fsl_box_frame"
version = "0.1.0"
version = "0.1.1"
description = "A gizmo for manipulating an OBB via 3D picking"
edition = "2021"
authors = ["Duncan Fairbanks <duncan.fairbanks@fslabs.ca>"]
Expand Down
16 changes: 12 additions & 4 deletions src/picking_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@ use crate::{ray_map::RayMap, BoxFrame};
use bevy::{
ecs::prelude::*,
prelude::{Camera, GlobalTransform},
render::view::RenderLayers,
};
use bevy_mod_picking::backend::{HitData, PointerHits};
use parry3d::{na::Isometry3, query::RayCast};

/// Generates pointer hits for the box frame's AABB and handles.
pub(crate) fn box_frame_backend(
ray_map: Res<RayMap>,
cameras: Query<&Camera>,
box_frames: Query<(Entity, &BoxFrame, &GlobalTransform)>,
cameras: Query<(&Camera, Option<&RenderLayers>)>,
box_frames: Query<(Entity, &BoxFrame, &GlobalTransform, Option<&RenderLayers>)>,
transforms: Query<&GlobalTransform>,
mut picking_out: EventWriter<PointerHits>,
) {
for (&ray_id, &ray) in ray_map.map().iter() {
let Ok(camera) = cameras.get(ray_id.camera) else {
let Ok((camera, view_mask)) = cameras.get(ray_id.camera) else {
continue;
};

let cam_view_mask = view_mask.copied().unwrap_or_default();

let ray = parry3d::query::Ray::new(ray.origin.into(), ray.direction.into());

let mut picks = Vec::new();
for (frame_entity, frame, frame_transform) in &box_frames {
for (frame_entity, frame, frame_transform, frame_view_mask) in &box_frames {
let frame_view_mask = frame_view_mask.copied().unwrap_or_default();
if !frame_view_mask.intersects(&cam_view_mask) {
continue;
}

let world_frame_center = frame_transform.transform_point(frame.center());
// Check handle intersections first, they always take priority.
let ball = frame.handle_ball();
Expand Down

0 comments on commit 8d390dc

Please # to comment.