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

Updated to bevy 0.7 #43

Merged
merged 3 commits into from
Apr 17, 2022
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_raycast"
version = "0.3.9"
version = "0.4.0"
authors = ["Aevyrie <aevyrie@gmail.com>"]
edition = "2021"
license = "MIT"
Expand All @@ -14,11 +14,11 @@ resolver = "2"
#bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", default-features = false, features = [
# "render",
#] }
bevy = { version = "0.6", default-features = false, features = ["render"] }
bevy = { version = "0.7", default-features = false, features = ["render"] }

[dev-dependencies]
#bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", default-features = false, features = [
bevy = { version = "0.6", default-features = false, features = [
bevy = { version = "0.7", default-features = false, features = [
"bevy_winit",
"x11",
] }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ I intend to track the `main` branch of Bevy. PRs supporting this are welcome!

|bevy|bevy_mod_raycast|
|---|---|
|0.7|0.4|
|0.6|0.3|
|0.5|0.2|
|0.4|0.1|
Expand Down
6 changes: 4 additions & 2 deletions examples/bounding_volume.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use bevy::{
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
math::Vec3A,
prelude::*,
render::primitives::Aabb,
window::PresentMode,
};
use bevy_mod_raycast::{
DefaultPluginState, DefaultRaycastingPlugin, RayCastMesh, RayCastMethod, RayCastSource,
Expand All @@ -15,7 +17,7 @@ use bevy_mod_raycast::{
fn main() {
App::new()
.insert_resource(WindowDescriptor {
vsync: false, // We'll turn off vsync for this example, as it's a source of input lag.
present_mode: PresentMode::Immediate, // We'll turn off vsync for this example, as it's a source of input lag.
..Default::default()
})
.add_plugins(DefaultPlugins)
Expand Down Expand Up @@ -201,7 +203,7 @@ fn manage_aabb(
if enabled.0 {
commands.entity(entity).remove::<Aabb>();
} else {
aabb.half_extents = Vec3::ONE * f32::MAX;
aabb.half_extents = Vec3A::ONE * f32::MAX;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/mouse_picking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{prelude::*, window::PresentMode};
use bevy_mod_raycast::{
DefaultPluginState, DefaultRaycastingPlugin, RayCastMesh, RayCastMethod, RayCastSource,
RaycastSystem,
Expand All @@ -11,7 +11,7 @@ use bevy_mod_raycast::{
fn main() {
App::new()
.insert_resource(WindowDescriptor {
vsync: false, // We'll turn off vsync for this example, as it's a source of input lag.
present_mode: PresentMode::Immediate, // We'll turn off vsync for this example, as it's a source of input lag.
..Default::default()
})
.add_plugins(DefaultPlugins)
Expand Down
4 changes: 2 additions & 2 deletions examples/ray_intersection_over_mesh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::f32::consts::FRAC_PI_2;

use bevy::prelude::*;
use bevy::{prelude::*, window::PresentMode};
use bevy_mod_raycast::{
ray_intersection_over_mesh, DefaultPluginState, DefaultRaycastingPlugin, Ray3d, RayCastMesh,
RayCastMethod, RayCastSource, RaycastSystem,
Expand All @@ -15,7 +15,7 @@ use bevy_mod_raycast::{
fn main() {
App::new()
.insert_resource(WindowDescriptor {
vsync: false, // Disabled for this demo to remove vsync as a source of input latency
present_mode: PresentMode::Immediate, // Disabled for this demo to remove vsync as a source of input latency
..Default::default()
})
.add_plugins(DefaultPlugins)
Expand Down
3 changes: 2 additions & 1 deletion examples/simplified_mesh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy::{
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
prelude::*,
window::PresentMode,
};
use bevy_mod_raycast::{
DefaultPluginState, DefaultRaycastingPlugin, RayCastMesh, RayCastMethod, RayCastSource,
Expand All @@ -14,7 +15,7 @@ use bevy_mod_raycast::{
fn main() {
App::new()
.insert_resource(WindowDescriptor {
vsync: false, // We'll turn off vsync for this example, as it's a source of input lag.
present_mode: PresentMode::Immediate, // We'll turn off vsync for this example, as it's a source of input lag.
..Default::default()
})
.add_plugins(DefaultPlugins)
Expand Down
22 changes: 19 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,19 @@ impl<T> RayCastSource<T> {
&self,
cursor_pos_screen: Vec2,
windows: &Res<Windows>,
images: &Res<Assets<Image>>,
camera: &Camera,
camera_transform: &GlobalTransform,
) -> Self {
RayCastSource {
cast_method: RayCastMethod::Screenspace(cursor_pos_screen),
ray: Ray3d::from_screenspace(cursor_pos_screen, windows, camera, camera_transform),
ray: Ray3d::from_screenspace(
cursor_pos_screen,
windows,
images,
camera,
camera_transform,
),
intersections: self.intersections.clone(),
_marker: self._marker,
}
Expand All @@ -180,12 +187,14 @@ impl<T> RayCastSource<T> {
pub fn new_screenspace(
cursor_pos_screen: Vec2,
windows: &Res<Windows>,
images: &Res<Assets<Image>>,
camera: &Camera,
camera_transform: &GlobalTransform,
) -> Self {
RayCastSource::new().with_ray_screenspace(
cursor_pos_screen,
windows,
images,
camera,
camera_transform,
)
Expand Down Expand Up @@ -279,6 +288,7 @@ pub enum RayCastMethod {
#[allow(clippy::type_complexity)]
pub fn build_rays<T: 'static + Send + Sync>(
windows: Res<Windows>,
images: Res<Assets<Image>>,
mut pick_source_query: Query<(
&mut RayCastSource<T>,
Option<&GlobalTransform>,
Expand Down Expand Up @@ -307,7 +317,13 @@ pub fn build_rays<T: 'static + Send + Sync>(
return;
}
};
Ray3d::from_screenspace(*cursor_pos_screen, &windows, camera, camera_transform)
Ray3d::from_screenspace(
*cursor_pos_screen,
&windows,
&images,
camera,
camera_transform,
)
}
// Use the specified transform as the origin and direction of the ray
RayCastMethod::Transform => {
Expand Down Expand Up @@ -445,7 +461,7 @@ pub fn ray_intersection_over_mesh(
None => panic!("Mesh does not contain vertex positions"),
Some(vertex_values) => match &vertex_values {
VertexAttributeValues::Float32x3(positions) => positions,
_ => panic!("Unexpected types in {}", Mesh::ATTRIBUTE_POSITION),
_ => panic!("Unexpected types in {:?}", Mesh::ATTRIBUTE_POSITION),
},
};
let vertex_normals: Option<&[[f32; 3]]> =
Expand Down
15 changes: 9 additions & 6 deletions src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,21 @@ pub mod rays {
pub fn from_screenspace(
cursor_pos_screen: Vec2,
windows: &Res<Windows>,
images: &Res<Assets<Image>>,
camera: &Camera,
camera_transform: &GlobalTransform,
) -> Option<Self> {
let view = camera_transform.compute_matrix();
let window = match windows.get(camera.window) {
Some(window) => window,
let screen_size = match camera.target.get_logical_size(windows, images) {
Some(s) => s,
None => {
error!("WindowId {} does not exist", camera.window);
error!(
"Unable to get screen size for RenderTarget {:?}",
camera.target
);
return None;
}
};
let screen_size = Vec2::from([window.width() as f32, window.height() as f32]);
let projection = camera.projection_matrix;

// 2D Normalized device coordinate cursor position from (-1, -1) to (1, 1)
Expand Down Expand Up @@ -150,8 +153,8 @@ pub mod rays {
// Check if the ray intersects the mesh's AABB. It's useful to work in model space because
// we can do an AABB intersection test, instead of an OBB intersection test.

let t_0: Vec3A = (Vec3A::from(aabb.min()) - ray_origin) / ray_dir;
let t_1: Vec3A = (Vec3A::from(aabb.max()) - ray_origin) / ray_dir;
let t_0: Vec3A = (aabb.min() - ray_origin) / ray_dir;
let t_1: Vec3A = (aabb.max() - ray_origin) / ray_dir;
let t_min: Vec3A = t_0.min(t_1);
let t_max: Vec3A = t_0.max(t_1);

Expand Down