Skip to content

Commit

Permalink
Update to bevy 0.13 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry authored Jul 9, 2024
1 parent 7a2d5d5 commit 5a43b2d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 131 deletions.
30 changes: 16 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_fsl_box_frame"
version = "0.2.0"
version = "0.3.0"
description = "A gizmo for manipulating an OBB via 3D picking"
edition = "2021"
authors = ["Duncan Fairbanks <[email protected]>"]
Expand All @@ -16,21 +16,23 @@ categories = ["3D", "game-development"]

[dependencies]
approx = "0.5"
bevy_polyline = "0.8"
bevy_polyline = "0.9"
parry3d = "0.13"
bevy = { version = "0.13", default-features = false, features = [
"bevy_asset",
"bevy_pbr",
] }
bevy_mod_picking = { version = "0.19", default_features = false }
nalgebra = { version = "0.32", features = ["glam025"] }

[dependencies.bevy]
version = "0.12"
default-features = false
features = ["bevy_asset", "bevy_pbr"]

[dependencies.bevy_mod_picking]
version = "0.17"
default-features = false

[dependencies.nalgebra]
version = "0.32"
features = ["glam024"]
[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = [
"bevy_asset",
"bevy_pbr",
"bevy_winit",
"x11",
"tonemapping_luts",
] }

[[example]]
name = "demo"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
profile = "default"
channel = "1.74"
channel = "1.76"
8 changes: 4 additions & 4 deletions src/box_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ impl BoxFrameVisuals {
..default()
}),

handle_mesh: meshes.add(shape::Icosphere::default().try_into().unwrap()),
handle_material: materials.add(Color::RED.into()),
handle_mesh: meshes.add(Sphere::new(1.0).mesh()),
handle_material: materials.add(Color::RED),
handle_scale: |e| 0.05 * median3(e),
handle_hover_scale: 1.2,
}
Expand Down Expand Up @@ -136,7 +136,7 @@ impl BoxFrame {
},
Pickable {
should_block_lower: false,
should_emit_events: true,
is_hoverable: true,
},
))
.id();
Expand All @@ -157,7 +157,7 @@ impl BoxFrame {
},
Pickable {
should_block_lower: false,
should_emit_events: true,
is_hoverable: true,
},
));
}
Expand Down
23 changes: 10 additions & 13 deletions src/drag_face.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::{
face_index_from_world_normal, face_sign,
ray_map::{RayId, RayMap},
BoxFrame, BoxFrameHandle, FaceIndex,
};
use crate::{face_index_from_world_normal, face_sign, BoxFrame, BoxFrameHandle, FaceIndex};
use approx::relative_eq;
use bevy::prelude::*;
use bevy_mod_picking::{
backend::ray::{RayId, RayMap},
events::Pointer,
prelude::{DragEnd, DragStart},
};
Expand All @@ -21,7 +18,7 @@ pub(crate) struct Dragging {
initial_coord: f32,
// The ray along which the face is translated during dragging. In world
// coordinates.
drag_ray: Ray,
drag_ray: Ray3d,
}

impl Dragging {
Expand Down Expand Up @@ -58,14 +55,14 @@ pub(crate) fn drag_face(
ray_id: RayId::new(hit_data.camera, drag_start.pointer_id),
face,
initial_coord: frame.faces()[face],
drag_ray: Ray {
drag_ray: Ray3d {
origin: world_position,
direction: world_normal,
direction: Direction3d::new(world_normal).unwrap(),
},
});
}
for drag_end in drag_end_events.read() {
let Ok(mut frame) = box_frames.get_component_mut::<BoxFrame>(drag_end.target) else {
let Ok((mut frame, _)) = box_frames.get_mut(drag_end.target) else {
continue;
};
frame.on_drag_end(&mut line_handles, &mut polylines);
Expand Down Expand Up @@ -105,9 +102,9 @@ pub(crate) fn drag_face(
/// Find the closest pair of points `(p1, p2)` where `p1` is on ray `r1` and
/// `p2` is on ray `r2`. Returns `(t1, t2)` such that `p_n =
/// r_n.get_point(t_n)`.
fn closest_points_on_two_rays(r1: &Ray, r2: &Ray) -> Option<(f32, f32)> {
fn closest_points_on_two_rays(r1: &Ray3d, r2: &Ray3d) -> Option<(f32, f32)> {
// If the rays are parallel, then there are infinitely many solutions.
if vectors_are_parallel(r1.direction, r2.direction) {
if vectors_are_parallel(*r1.direction, *r2.direction) {
return None;
}

Expand All @@ -117,9 +114,9 @@ fn closest_points_on_two_rays(r1: &Ray, r2: &Ray) -> Option<(f32, f32)> {
// t1 * V1 - t2 * V2 + t3 * (V1 x V2) = P2 - P1
let col1 = r1.direction;
let col2 = -r2.direction;
let col3 = r1.direction.cross(r2.direction);
let col3 = r1.direction.cross(*r2.direction);
let rhs = r2.origin - r1.origin;
let mat = Mat3::from_cols(col1, col2, col3);
let mat = Mat3::from_cols(*col1, *col2, col3);
let t = mat.inverse() * rhs;

Some((t.x, t.y))
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ mod highlight;
mod picking_backend;
mod solid_color_material;

// TODO: remove this for bevy_mod_picking 0.17.1
mod ray_map;

pub use box_frame::*;
pub use solid_color_material::*;

Expand All @@ -23,7 +20,6 @@ use drag_face::*;
use handle_visibility::*;
use highlight::*;
use picking_backend::box_frame_backend;
use ray_map::RayMap;

/// Enables pointer interactions for [`BoxFrame`] entities.
pub struct BoxFramePlugin;
Expand All @@ -38,8 +34,6 @@ impl Plugin for BoxFramePlugin {
);

app.add_plugins(MaterialPlugin::<SolidColorMaterial>::default())
.init_resource::<RayMap>()
.add_systems(PreUpdate, RayMap::repopulate.in_set(PickSet::ProcessInput))
.add_systems(PreUpdate, box_frame_backend.in_set(PickSet::Backend))
.add_systems(Update, (handle_visibility, highlight_handles))
// Correct highlighting updates depend on the state of dragging.
Expand Down
7 changes: 4 additions & 3 deletions src/picking_backend.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{ray_map::RayMap, BoxFrame};
use crate::BoxFrame;
use bevy::{
ecs::prelude::*,
math::Vec3Swizzles,
prelude::{Camera, GlobalTransform},
render::view::RenderLayers,
};
use bevy_mod_picking::backend::{HitData, PointerHits};
use bevy_mod_picking::backend::{ray::RayMap, HitData, PointerHits};
use parry3d::{na::Isometry3, query::RayCast};

/// Generates pointer hits for the box frame's AABB and handles.
Expand All @@ -22,7 +23,7 @@ pub(crate) fn box_frame_backend(

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

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

let mut picks = Vec::new();
for (frame_entity, frame, frame_transform, frame_view_mask) in &box_frames {
Expand Down
86 changes: 0 additions & 86 deletions src/ray_map.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/shaders/solid_color.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct SolidColorMaterial {
color: vec4<f32>,
};

@group(1) @binding(0)
@group(2) @binding(0)
var<uniform> material: SolidColorMaterial;

@fragment
Expand Down
5 changes: 2 additions & 3 deletions src/solid_color_material.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use bevy::{
asset::Asset,
prelude::{AlphaMode, Color, Handle, Material, Shader},
reflect::{TypePath, TypeUuid},
reflect::TypePath,
render::render_resource::{AsBindGroup, ShaderRef},
};

pub(crate) const SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(7825413687727800356);

/// A mesh material that only outputs a single color.
#[allow(missing_docs)]
#[derive(Asset, AsBindGroup, Clone, Debug, TypePath, TypeUuid)]
#[uuid = "f690fdae-d598-45ab-8225-97e2a3f056e0"]
#[derive(Asset, AsBindGroup, Clone, Debug, TypePath)]
pub struct SolidColorMaterial {
#[uniform(0)]
pub color: Color,
Expand Down

0 comments on commit 5a43b2d

Please sign in to comment.