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

Update to bevy 0.14 #73

Merged
merged 1 commit into from
Jul 9, 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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_transform_gizmo"
version = "0.11.2"
version = "0.12.0"
authors = [
"Aevyrie Roessler <[email protected]>",
"Foresight Mining Software Corporation",
Expand All @@ -14,26 +14,26 @@ 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.13.1", default-features = false, features = [
bevy = { version = "0.14.0", default-features = false, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_pbr",
] }
bevy_mod_picking = { version = ">=0.18, <=0.19", default-features = false, features = [
bevy_mod_picking = { version = ">=0.18, <=0.20", default-features = false, features = [
"selection",
] }
bevy_mod_raycast = "0.17"
bevy_mod_raycast = "0.18"

[dev-dependencies]
bevy = { version = "0.13.1", default-features = false, features = [
bevy = { version = "0.14.0", default-features = false, features = [
"bevy_pbr",
"bevy_winit",
"x11",
"tonemapping_luts",
"ktx2",
"zstd",
] }
bevy_mod_picking = { version = ">=0.18, <=0.19", default-features = false, features = [
bevy_mod_picking = { version = ">=0.18, <=0.20", default-features = false, features = [
"selection",
"backend_raycast",
"highlight",
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn setup(
commands.spawn((
PbrBundle {
mesh: meshes.add(Plane3d::default()),
material: materials.add(Color::rgb(0.8, 0.8, 0.8)),
material: materials.add(Color::srgb(0.8, 0.8, 0.8)),
transform: Transform::from_scale(Vec3::splat(5.0)),
..Default::default()
},
Expand All @@ -46,7 +46,7 @@ fn setup(
commands.spawn((
PbrBundle {
mesh: meshes.add(Cuboid::from_size(Vec3::splat(1.0))),
material: materials.add(Color::rgb(0.8, 0.8, 0.8)),
material: materials.add(Color::srgb(0.8, 0.8, 0.8)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
},
Expand Down
6 changes: 3 additions & 3 deletions examples/parenting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn setup(
commands.spawn((
PbrBundle {
mesh: meshes.add(Plane3d::default()),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
material: materials.add(Color::srgb(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()
Expand All @@ -39,8 +39,8 @@ fn setup(
bevy_transform_gizmo::GizmoTransformable,
));

let tan = Color::rgb_u8(204, 178, 153);
let red = Color::rgb_u8(127, 26, 26);
let tan = Color::srgb_u8(204, 178, 153);
let red = Color::srgb_u8(127, 26, 26);

// cube
commands
Expand Down
10 changes: 6 additions & 4 deletions src/gizmo_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy::{
prelude::*,
reflect::TypePath,
render::{
mesh::MeshVertexBufferLayout,
mesh::MeshVertexBufferLayoutRef,
render_resource::{
AsBindGroup, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError,
},
Expand All @@ -15,12 +15,14 @@ pub const GIZMO_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(139538002
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
pub struct GizmoMaterial {
#[uniform(0)]
pub color: Color,
pub color: LinearRgba,
}

impl From<Color> for GizmoMaterial {
fn from(color: Color) -> Self {
GizmoMaterial { color }
GizmoMaterial {
color: color.into(),
}
}
}

Expand All @@ -40,7 +42,7 @@ impl Material for GizmoMaterial {
fn specialize(
_pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
_layout: &MeshVertexBufferLayout,
_layout: &MeshVertexBufferLayoutRef,
_key: MaterialPipelineKey<Self>,
) -> Result<(), SpecializedMeshPipelineError> {
descriptor.primitive.cull_mode = None;
Expand Down
4 changes: 2 additions & 2 deletions src/gizmo_material.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import bevy_pbr::mesh_functions::{get_model_matrix, mesh_position_local_to_clip}
#import bevy_pbr::mesh_functions::{get_world_from_local, mesh_position_local_to_clip}

struct GizmoMaterial {
color: vec4<f32>,
Expand All @@ -20,7 +20,7 @@ struct VertexOutput {
fn vertex(vertex: Vertex) -> VertexOutput {
var out: VertexOutput;
out.clip_position = mesh_position_local_to_clip(
get_model_matrix(vertex.instance_index),
get_world_from_local(vertex.instance_index),
vec4<f32>(vertex.position, 1.0),
);
return out;
Expand Down
47 changes: 28 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy_mod_picking::{
prelude::{PickingInteraction, PointerId},
selection::{NoDeselect, PickSelection},
};
use bevy_mod_raycast::prelude::{Primitive3d, RaycastSystem};
use bevy_mod_raycast::prelude::RaycastSystem;
use gizmo_material::GizmoMaterial;
use mesh::{RotationGizmo, ViewTranslateGizmo};
use normalization::*;
Expand Down Expand Up @@ -280,15 +280,15 @@ fn drag_gizmo(
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
.intersect_primitive(Primitive3d::Plane {
normal: plane_normal,
point: plane_origin,
}) {
intersection.position()
let cursor_plane_intersection = if let Some(intesect_point) = picking_camera
.get_ray()
.and_then(|ray| intersect_plane(ray, plane_normal, plane_origin))
{
intesect_point
} else {
return;
};

let cursor_vector: Vec3 = cursor_plane_intersection - plane_origin;
let cursor_projected_onto_handle = match &gizmo.drag_start {
Some(drag_start) => *drag_start,
Expand Down Expand Up @@ -321,11 +321,10 @@ fn drag_gizmo(
TransformGizmoInteraction::TranslatePlane { normal, .. } => {
let plane_origin = gizmo_origin;
let cursor_plane_intersection = if let Some(intersection) = picking_camera
.intersect_primitive(Primitive3d::Plane {
normal,
point: plane_origin,
}) {
intersection.position()
.get_ray()
.and_then(|ray| intersect_plane(ray, normal, plane_origin))
{
intersection
} else {
return;
};
Expand All @@ -351,14 +350,11 @@ fn drag_gizmo(
);
}
TransformGizmoInteraction::RotateAxis { original: _, axis } => {
let rotation_plane = Primitive3d::Plane {
normal: axis.normalize(),
point: gizmo_origin,
};
let cursor_plane_intersection = if let Some(intersection) =
picking_camera.intersect_primitive(rotation_plane)
let cursor_plane_intersection = if let Some(intersection) = picking_camera
.get_ray()
.and_then(|ray| intersect_plane(ray, axis.normalize(), gizmo_origin))
{
intersection.position()
intersection
} else {
return;
};
Expand Down Expand Up @@ -398,6 +394,19 @@ fn drag_gizmo(
}
}

fn intersect_plane(ray: Ray3d, plane_normal: Vec3, plane_origin: Vec3) -> Option<Vec3> {
// assuming vectors are all normalized
let denominator = ray.direction.dot(plane_normal);
if denominator.abs() > f32::EPSILON {
let point_to_point = plane_origin - ray.origin;
let intersect_dist = plane_normal.dot(point_to_point) / denominator;
let intersect_position = ray.direction * intersect_dist + ray.origin;
Some(intersect_position)
} else {
None
}
}

fn hover_gizmo(
gizmo_raycast_source: Query<(Entity, &GizmoPickSource)>,
mut gizmo_query: Query<(
Expand Down
Loading