Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to bevy 0.12 #4

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 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.1.1"
version = "0.2.0"
description = "A gizmo for manipulating an OBB via 3D picking"
edition = "2021"
authors = ["Duncan Fairbanks <duncan.fairbanks@fslabs.ca>"]
Expand All @@ -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]
Expand All @@ -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"]
4 changes: 2 additions & 2 deletions src/drag_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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::<BoxFrame>(drag_end.target) else {
continue;
};
Expand Down
6 changes: 3 additions & 3 deletions src/handle_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -63,13 +63,13 @@ pub(crate) fn highlight_handles(
mut out_events: EventReader<Pointer<Out>>,
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;
};
Expand Down
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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::<Assets<Shader>>().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::<SolidColorMaterial>::default())
Expand Down
4 changes: 2 additions & 2 deletions src/shaders/solid_color.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import bevy_pbr::mesh_vertex_output MeshVertexOutput
#import bevy_pbr::forward_io::VertexOutput

struct SolidColorMaterial {
color: vec4<f32>,
Expand All @@ -9,7 +9,7 @@ var<uniform> material: SolidColorMaterial;

@fragment
fn fragment(
_mesh: MeshVertexOutput,
_mesh: VertexOutput,
) -> @location(0) vec4<f32> {
return material.color;
}
10 changes: 5 additions & 5 deletions src/solid_color_material.rs
Original file line number Diff line number Diff line change
@@ -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<Shader> = 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)]
Expand All @@ -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 {
Expand Down