From 20f343938739c2590f3edec5c3a9afff742dd8be Mon Sep 17 00:00:00 2001 From: Lethja <150316953+Lethja@users.noreply.github.com> Date: Sat, 6 Apr 2024 14:24:51 +1100 Subject: [PATCH] Bevy 0.13 (#64) * Updated Cargo.toml for Bevy 0.13 * Successfully compiled library and examples * Replaced deprecated structs * Bumped minimum Bevy version requirement to 0.13.1 (https://github.com/bevyengine/bevy/issues/12015) * Fixed plane scale * Fixed strict formatting error * Fixed strict clippy warnings * Fix shader bind group as noted in Bevy PR #10485 * Minor nits and cleanup. --------- Co-authored-by: Zach Bateman Co-authored-by: Aevyrie --- Cargo.toml | 12 ++++++------ examples/minimal.rs | 9 +++++---- examples/parenting.rs | 22 ++++++++++------------ src/gizmo_material.wgsl | 2 +- src/lib.rs | 12 ++++++------ src/mesh/cone.rs | 11 +++++++---- src/mesh/mod.rs | 30 ++++++++++++------------------ src/mesh/truncated_torus.rs | 9 ++++++--- 8 files changed, 53 insertions(+), 54 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7d48226..b3cf5ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,18 +14,18 @@ documentation = "https://docs.rs/bevy_transform_gizmo" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { version = "0.12.0", default-features = false, features = [ +bevy = { version = "0.13.1", default-features = false, features = [ "bevy_render", "bevy_core_pipeline", "bevy_pbr", ] } -bevy_mod_picking = { version = "0.17.0", default-features = false, features = [ +bevy_mod_picking = { version = "0.18", default-features = false, features = [ "selection", ] } -bevy_mod_raycast = "0.16.0" +bevy_mod_raycast = "0.17" [dev-dependencies] -bevy = { version = "0.12.0", default-features = false, features = [ +bevy = { version = "0.13.1", default-features = false, features = [ "bevy_pbr", "bevy_winit", "x11", @@ -33,9 +33,9 @@ bevy = { version = "0.12.0", default-features = false, features = [ "ktx2", "zstd", ] } -bevy_mod_picking = { version = "0.17.0", default-features = false, features = [ +bevy_mod_picking = { version = "0.18", default-features = false, features = [ "selection", "backend_raycast", "highlight", - "bevy_picking_raycast" + "bevy_picking_raycast", ] } diff --git a/examples/minimal.rs b/examples/minimal.rs index e9cb206..60def91 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -34,8 +34,9 @@ fn setup( // plane commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::rgb(0.8, 0.8, 0.8).into()), + mesh: meshes.add(Plane3d::default()), + material: materials.add(Color::rgb(0.8, 0.8, 0.8)), + transform: Transform::from_scale(Vec3::splat(5.0)), ..Default::default() }, bevy_mod_picking::PickableBundle::default(), @@ -44,8 +45,8 @@ fn setup( // cube commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.8, 0.8).into()), + mesh: meshes.add(Cuboid::from_size(Vec3::splat(1.0))), + material: materials.add(Color::rgb(0.8, 0.8, 0.8)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..Default::default() }, diff --git a/examples/parenting.rs b/examples/parenting.rs index 559da64..b315fe2 100644 --- a/examples/parenting.rs +++ b/examples/parenting.rs @@ -29,12 +29,10 @@ fn setup( // plane commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Plane { - size: 5.0, - ..default() - })), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), - transform: Transform::from_xyz(0.0, -0.5, 0.0), + mesh: meshes.add(Plane3d::default()), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), + transform: Transform::from_translation(Vec3::new(0.0, -0.5, 0.0)) + .with_scale(Vec3::splat(5.0)), ..Default::default() }, bevy_mod_picking::PickableBundle::default(), @@ -48,8 +46,8 @@ fn setup( commands .spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(red.into()), + mesh: meshes.add(Cuboid::from_size(Vec3::splat(1.0))), + material: materials.add(StandardMaterial::from(red)), transform: Transform::from_xyz(-1.0, 0.0, 0.0), ..default() }, @@ -59,8 +57,8 @@ fn setup( .with_children(|commands| { commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(tan.into()), + mesh: meshes.add(Cuboid::from_size(Vec3::splat(1.0))), + material: materials.add(StandardMaterial::from(tan)), transform: Transform::from_xyz(1.0, 0.0, 0.0), ..default() }, @@ -69,8 +67,8 @@ fn setup( )); commands.spawn(( PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(tan.into()), + mesh: meshes.add(Cuboid::from_size(Vec3::splat(1.0))), + material: materials.add(StandardMaterial::from(tan)), transform: Transform::from_xyz(1.0, 1.0, 0.0), ..default() }, diff --git a/src/gizmo_material.wgsl b/src/gizmo_material.wgsl index 2722092..0b5bbe1 100644 --- a/src/gizmo_material.wgsl +++ b/src/gizmo_material.wgsl @@ -4,7 +4,7 @@ struct GizmoMaterial { color: vec4, }; -@group(1) @binding(0) +@group(2) @binding(0) var material: GizmoMaterial; struct Vertex { diff --git a/src/lib.rs b/src/lib.rs index 83e9116..6080695 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -312,7 +312,7 @@ fn drag_gizmo( } match interaction { TransformGizmoInteraction::TranslateAxis { original: _, axis } => { - let vertical_vector = picking_ray.direction().cross(axis).normalize(); + let vertical_vector = picking_ray.direction.cross(axis).normalize(); let plane_normal = axis.cross(vertical_vector).normalize(); let plane_origin = gizmo_origin; let cursor_plane_intersection = if let Some(intersection) = picking_camera @@ -496,7 +496,7 @@ pub struct RotationOriginOffset(pub Vec3); #[allow(clippy::type_complexity, clippy::too_many_arguments)] fn grab_gizmo( mut commands: Commands, - mouse_button_input: Res>, + mouse_button_input: Res>, mut gizmo_events: EventWriter, mut gizmo_query: Query<( &mut TransformGizmo, @@ -689,12 +689,12 @@ fn adjust_view_translate_gizmo( let direction = cam_transform.local_z(); *interaction = TransformGizmoInteraction::TranslatePlane { original: Vec3::ZERO, - normal: direction, + normal: *direction, }; let rotation = Quat::from_mat3(&Mat3::from_cols( - direction.cross(cam_transform.local_y()), - direction, - cam_transform.local_y(), + direction.cross(*cam_transform.local_y()), + *direction, + *cam_transform.local_y(), )); *global_transform = Transform { rotation, diff --git a/src/mesh/cone.rs b/src/mesh/cone.rs index d99d3e7..7acc245 100644 --- a/src/mesh/cone.rs +++ b/src/mesh/cone.rs @@ -1,8 +1,8 @@ use bevy::{ prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, }; -/// A cone) shape. +/// A cone shape. #[derive(Debug, Clone, Copy)] pub struct Cone { pub radius: f32, @@ -78,8 +78,11 @@ impl From for Mesh { indices.push(left as u32); } - let mut mesh = Mesh::new(PrimitiveTopology::TriangleList); - mesh.set_indices(Some(Indices::U32(indices))); + let mut mesh = Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::default(), + ); + mesh.insert_indices(Indices::U32(indices)); mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions); mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normals); mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs); diff --git a/src/mesh/mod.rs b/src/mesh/mod.rs index 13d5d56..dcd370b 100644 --- a/src/mesh/mod.rs +++ b/src/mesh/mod.rs @@ -3,9 +3,7 @@ use crate::{ TransformGizmoInteraction, }; use bevy::{ - core_pipeline::{clear_color::ClearColorConfig, core_3d::Camera3dDepthLoadOp}, - pbr::NotShadowCaster, - prelude::*, + core_pipeline::core_3d::Camera3dDepthLoadOp, pbr::NotShadowCaster, prelude::*, render::view::RenderLayers, }; use bevy_mod_raycast::prelude::NoBackfaceCulling; @@ -30,24 +28,17 @@ pub fn build_gizmo( let plane_size = axis_length * 0.25; let plane_offset = plane_size / 2. + axis_length * 0.2; // Define gizmo meshes - let arrow_tail_mesh = meshes.add(Mesh::from(shape::Capsule { + let arrow_tail_mesh = meshes.add(Capsule3d { radius: 0.04, - depth: axis_length, - ..Default::default() - })); - let cone_mesh = meshes.add(Mesh::from(cone::Cone { + half_length: axis_length * 0.5f32, + }); + let cone_mesh = meshes.add(cone::Cone { height: 0.25, radius: 0.10, ..Default::default() - })); - let plane_mesh = meshes.add(Mesh::from(shape::Plane::from_size(plane_size))); - let sphere_mesh = meshes.add( - Mesh::try_from(shape::Icosphere { - radius: 0.2, - subdivisions: 3, - }) - .unwrap(), - ); + }); + let plane_mesh = meshes.add(Plane3d::default().mesh().size(plane_size, plane_size)); + let sphere_mesh = meshes.add(Sphere { radius: 0.2 }); let rotation_mesh = meshes.add(Mesh::from(truncated_torus::TruncatedTorus { radius: arc_radius, ring_radius: 0.04, @@ -314,10 +305,13 @@ pub fn build_gizmo( commands.spawn(( Camera3dBundle { camera_3d: Camera3d { - clear_color: ClearColorConfig::None, depth_load_op: Camera3dDepthLoadOp::Clear(0.), ..default() }, + camera: Camera { + clear_color: ClearColorConfig::None, + ..default() + }, ..Default::default() }, InternalGizmoCamera, diff --git a/src/mesh/truncated_torus.rs b/src/mesh/truncated_torus.rs index 466e34d..08bf410 100644 --- a/src/mesh/truncated_torus.rs +++ b/src/mesh/truncated_torus.rs @@ -1,6 +1,6 @@ use bevy::{ prelude::*, - render::{mesh::Indices, render_resource::PrimitiveTopology}, + render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology}, }; /// A torus (donut) shape. #[derive(Debug, Clone, Copy)] @@ -84,8 +84,11 @@ impl From for Mesh { } } - let mut mesh = Mesh::new(PrimitiveTopology::TriangleList); - mesh.set_indices(Some(Indices::U32(indices))); + let mut mesh = Mesh::new( + PrimitiveTopology::TriangleList, + RenderAssetUsages::default(), + ); + mesh.insert_indices(Indices::U32(indices)); mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions); mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normals); mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs);