diff --git a/Cargo.toml b/Cargo.toml index 1d77386..35b21ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_fsl_box_frame" -version = "0.1.1" +version = "0.2.0" description = "A gizmo for manipulating an OBB via 3D picking" edition = "2021" authors = ["Duncan Fairbanks "] @@ -16,16 +16,16 @@ categories = ["3D", "game-development"] [dependencies] approx = "0.5" -bevy_polyline = "0.7" +bevy_polyline = "0.8" parry3d = "0.13" [dependencies.bevy] -version = "0.11" +version = "0.12" default-features = false features = ["bevy_asset", "bevy_pbr"] [dependencies.bevy_mod_picking] -version = "0.16" +version = "0.17" default-features = false [dependencies.nalgebra] @@ -35,4 +35,4 @@ features = ["glam024"] [[example]] name = "demo" path = "examples/demo.rs" -required-features = ["bevy/bevy_winit", "bevy/x11"] +required-features = ["bevy/bevy_winit", "bevy/x11", "bevy/tonemapping_luts"] diff --git a/src/drag_face.rs b/src/drag_face.rs index 1cf220c..22cb5d6 100644 --- a/src/drag_face.rs +++ b/src/drag_face.rs @@ -41,7 +41,7 @@ pub(crate) fn drag_face( mut handles: Query<(&mut BoxFrameHandle, &mut Transform)>, ) { // Start or stop the dragging state machine based on events. - for drag_start in drag_start_events.iter() { + for drag_start in drag_start_events.read() { let Ok((mut frame, transform)) = box_frames.get_mut(drag_start.target) else { continue; }; @@ -64,7 +64,7 @@ pub(crate) fn drag_face( }, }); } - for drag_end in drag_end_events.iter() { + for drag_end in drag_end_events.read() { let Ok(mut frame) = box_frames.get_component_mut::(drag_end.target) else { continue; }; diff --git a/src/handle_visibility.rs b/src/handle_visibility.rs index f4387b4..ee68746 100644 --- a/src/handle_visibility.rs +++ b/src/handle_visibility.rs @@ -9,9 +9,9 @@ pub fn handle_visibility( box_frames: Query<&BoxFrame>, mut visibility: Query<&mut Visibility>, ) { - let normalized_over = over_events.iter().map(|e| (e.target, Visibility::Visible)); - let normalized_move = move_events.iter().map(|e| (e.target, Visibility::Visible)); - let normalized_out = out_events.iter().map(|e| (e.target, Visibility::Hidden)); + let normalized_over = over_events.read().map(|e| (e.target, Visibility::Visible)); + let normalized_move = move_events.read().map(|e| (e.target, Visibility::Visible)); + let normalized_out = out_events.read().map(|e| (e.target, Visibility::Hidden)); for (target, set_visibility) in normalized_over.chain(normalized_move).chain(normalized_out) { let Ok(frame) = box_frames.get(target) else { diff --git a/src/highlight.rs b/src/highlight.rs index 09f719a..88da607 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -23,13 +23,13 @@ pub(crate) fn highlight_face( } let normalized_over = over_events - .iter() + .read() .map(|e| (e.target, Some(e.event.hit.clone()))); let normalized_move = move_events - .iter() + .read() .map(|e| (e.target, Some(e.event.hit.clone()))); - let normalized_out = out_events.iter().map(|e| (e.target, None)); - let normalized_drag_end = drag_end_events.iter().map(|e| (e.target, None)); + let normalized_out = out_events.read().map(|e| (e.target, None)); + let normalized_drag_end = drag_end_events.read().map(|e| (e.target, None)); // Highlight faces intersecting a pointer ray. "Out" events will clear all // highlights. @@ -63,13 +63,13 @@ pub(crate) fn highlight_handles( mut out_events: EventReader>, mut handles: Query<(&BoxFrameHandle, &mut Transform)>, ) { - for over in over_events.iter() { + for over in over_events.read() { let Ok((handle, mut tfm)) = handles.get_mut(over.target) else { continue; }; tfm.scale = Vec3::splat(handle.base_scale * handle.hover_scale); } - for out in out_events.iter() { + for out in out_events.read() { let Ok((handle, mut tfm)) = handles.get_mut(out.target) else { continue; }; diff --git a/src/lib.rs b/src/lib.rs index cc3886a..52246bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,10 @@ mod ray_map; pub use box_frame::*; pub use solid_color_material::*; -use bevy::prelude::{Assets, IntoSystemConfigs, MaterialPlugin, Plugin, PreUpdate, Shader, Update}; +use bevy::{ + asset::load_internal_asset, + prelude::{IntoSystemConfigs, MaterialPlugin, Plugin, PreUpdate, Shader, Update}, +}; use bevy_mod_picking::picking_core::PickSet; use drag_face::*; use handle_visibility::*; @@ -27,10 +30,11 @@ pub struct BoxFramePlugin; impl Plugin for BoxFramePlugin { fn build(&self, app: &mut bevy::prelude::App) { - let mut shaders = app.world.get_resource_mut::>().unwrap(); - shaders.set_untracked( + load_internal_asset!( + app, SHADER_HANDLE, - Shader::from_wgsl(include_str!("shaders/solid_color.wgsl"), file!()), + "shaders/solid_color.wgsl", + Shader::from_wgsl ); app.add_plugins(MaterialPlugin::::default()) diff --git a/src/shaders/solid_color.wgsl b/src/shaders/solid_color.wgsl index 0612c60..6ec0624 100644 --- a/src/shaders/solid_color.wgsl +++ b/src/shaders/solid_color.wgsl @@ -1,4 +1,4 @@ -#import bevy_pbr::mesh_vertex_output MeshVertexOutput +#import bevy_pbr::forward_io::VertexOutput struct SolidColorMaterial { color: vec4, @@ -9,7 +9,7 @@ var material: SolidColorMaterial; @fragment fn fragment( - _mesh: MeshVertexOutput, + _mesh: VertexOutput, ) -> @location(0) vec4 { return material.color; } diff --git a/src/solid_color_material.rs b/src/solid_color_material.rs index b79357c..c419275 100644 --- a/src/solid_color_material.rs +++ b/src/solid_color_material.rs @@ -1,15 +1,15 @@ use bevy::{ - prelude::{AlphaMode, Color, HandleUntyped, Material, Shader}, + asset::Asset, + prelude::{AlphaMode, Color, Handle, Material, Shader}, reflect::{TypePath, TypeUuid}, render::render_resource::{AsBindGroup, ShaderRef}, }; -pub(crate) const SHADER_HANDLE: HandleUntyped = - HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 7825413687727800356); +pub(crate) const SHADER_HANDLE: Handle = Handle::weak_from_u128(7825413687727800356); /// A mesh material that only outputs a single color. #[allow(missing_docs)] -#[derive(AsBindGroup, Clone, Debug, TypePath, TypeUuid)] +#[derive(Asset, AsBindGroup, Clone, Debug, TypePath, TypeUuid)] #[uuid = "f690fdae-d598-45ab-8225-97e2a3f056e0"] pub struct SolidColorMaterial { #[uniform(0)] @@ -19,7 +19,7 @@ pub struct SolidColorMaterial { impl Material for SolidColorMaterial { fn fragment_shader() -> ShaderRef { - SHADER_HANDLE.typed().into() + SHADER_HANDLE.into() } fn alpha_mode(&self) -> AlphaMode {