Skip to content

Commit

Permalink
Bevy 0.13 (#64)
Browse files Browse the repository at this point in the history
* Updated Cargo.toml for Bevy 0.13

* Successfully compiled library and examples

* Replaced deprecated structs

* Bumped minimum Bevy version requirement to 0.13.1 (bevyengine/bevy#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 <zkbateman@gmail.com>
Co-authored-by: Aevyrie <aevyrie@gmail.com>
  • Loading branch information
3 people authored and NicoleKai committed Apr 29, 2024
1 parent cbd2e13 commit 20f3439
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 54 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ 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",
"tonemapping_luts",
"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",
] }
9 changes: 5 additions & 4 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()
},
Expand Down
22 changes: 10 additions & 12 deletions examples/parenting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()
},
Expand All @@ -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()
},
Expand All @@ -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()
},
Expand Down
2 changes: 1 addition & 1 deletion src/gizmo_material.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct GizmoMaterial {
color: vec4<f32>,
};

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

struct Vertex {
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Input<MouseButton>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
mut gizmo_events: EventWriter<TransformGizmoEvent>,
mut gizmo_query: Query<(
&mut TransformGizmo,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions src/mesh/cone.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -78,8 +78,11 @@ impl From<Cone> 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);
Expand Down
30 changes: 12 additions & 18 deletions src/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions src/mesh/truncated_torus.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -84,8 +84,11 @@ impl From<TruncatedTorus> 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);
Expand Down

0 comments on commit 20f3439

Please sign in to comment.