diff --git a/CHANGELOG.md b/CHANGELOG.md index 5555e54..870aefa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.19.0 + +- Changed: updated to Bevy 0.15. +- Use `Dir3` instead of `Vec3` for normalized directions in `Ray3d::new` + # 0.18.0 - Changed: updated to Bevy 0.14. diff --git a/Cargo.toml b/Cargo.toml index b5ac823..a969f4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_raycast" -version = "0.18.0" +version = "0.19.0" authors = ["Aevyrie "] edition = "2021" license = "MIT" @@ -11,23 +11,23 @@ categories = ["game-engines", "rendering"] resolver = "2" [dependencies] -bevy_app = { version = "0.14.0", default-features = false } -bevy_asset = { version = "0.14.0", default-features = false } -bevy_derive = { version = "0.14.0", default-features = false } -bevy_ecs = { version = "0.14.0", default-features = false } -bevy_gizmos = { version = "0.14.0", optional = true, default-features = false } -bevy_math = { version = "0.14.0", default-features = false } -bevy_reflect = { version = "0.14.0", default-features = false } -bevy_render = { version = "0.14.0", default-features = false } -bevy_sprite = { version = "0.14.0", optional = true, default-features = false } -bevy_transform = { version = "0.14.0", default-features = false } -bevy_utils = { version = "0.14.0", default-features = false } -bevy_window = { version = "0.14.0", default-features = false } -bevy_color = { version = "0.14.0", default-features = false } +bevy_app = { version = "0.15.0", default-features = false } +bevy_asset = { version = "0.15.0", default-features = false } +bevy_derive = { version = "0.15.0", default-features = false } +bevy_ecs = { version = "0.15.0", default-features = false } +bevy_gizmos = { version = "0.15.0", optional = true, default-features = false } +bevy_math = { version = "0.15.0", default-features = false } +bevy_reflect = { version = "0.15.0", default-features = false } +bevy_render = { version = "0.15.0", default-features = false } +bevy_sprite = { version = "0.15.0", optional = true, default-features = false } +bevy_transform = { version = "0.15.0", default-features = false } +bevy_utils = { version = "0.15.0", default-features = false } +bevy_window = { version = "0.15.0", default-features = false } +bevy_color = { version = "0.15.0", default-features = false } crossbeam-channel = "0.5" [dev-dependencies] -bevy = { version = "0.14.0", default-features = true, features = [ +bevy = { version = "0.15.0", default-features = true, features = [ "default_font", "ktx2", "tonemapping_luts", diff --git a/README.md b/README.md index 9bc2877..b3e79c2 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ I intend to track the `main` branch of Bevy. PRs supporting this are welcome! | bevy | bevy_mod_raycast | | ---- | ---------------- | +| 0.15 | 0.19 | | 0.14 | 0.18 | | 0.13 | 0.17 | | 0.12 | 0.16 | diff --git a/benches/ray_mesh_intersection.rs b/benches/ray_mesh_intersection.rs index ddbb05e..f6237ad 100644 --- a/benches/ray_mesh_intersection.rs +++ b/benches/ray_mesh_intersection.rs @@ -1,121 +1,130 @@ -use bevy::math::{Mat4, Vec3}; -use bevy_math::Ray3d; -use bevy_mod_raycast::prelude::*; -use criterion::{black_box, criterion_group, criterion_main, Criterion}; - -fn ptoxznorm(p: u32, size: u32) -> (f32, f32) { - let ij = (p / (size), p % (size)); - (ij.0 as f32 / size as f32, ij.1 as f32 / size as f32) -} - -struct SimpleMesh { - positions: Vec<[f32; 3]>, - normals: Vec<[f32; 3]>, - indices: Vec, -} - -fn mesh_creation(vertices_per_side: u32) -> SimpleMesh { - let mut positions = Vec::new(); - let mut normals = Vec::new(); - for p in 0..vertices_per_side.pow(2) { - let xz = ptoxznorm(p, vertices_per_side); - positions.push([xz.0 - 0.5, 0.0, xz.1 - 0.5]); - normals.push([0.0, 1.0, 0.0]); - } - - let mut indices = vec![]; - for p in 0..vertices_per_side.pow(2) { - if p % (vertices_per_side) != vertices_per_side - 1 - && p / (vertices_per_side) != vertices_per_side - 1 - { - indices.extend_from_slice(&[p, p + 1, p + vertices_per_side]); - indices.extend_from_slice(&[p + vertices_per_side, p + 1, p + vertices_per_side + 1]); - } - } - - SimpleMesh { - positions, - normals, - indices, - } -} - -fn ray_mesh_intersection(c: &mut Criterion) { - let mut group = c.benchmark_group("ray_mesh_intersection"); - group.warm_up_time(std::time::Duration::from_millis(500)); - - for vertices_per_side in [10_u32, 100, 1000] { - group.bench_function(format!("{}_vertices", vertices_per_side.pow(2)), |b| { - let ray = Ray3d::new(Vec3::new(0.0, 1.0, 0.0), Vec3::new(0.0, -1.0, 0.0)); - let mesh_to_world = Mat4::IDENTITY; - let mesh = mesh_creation(vertices_per_side); - - b.iter(|| { - black_box(bevy_mod_raycast::prelude::ray_mesh_intersection( - &mesh_to_world, - &mesh.positions, - Some(&mesh.normals), - ray, - Some(&mesh.indices), - Backfaces::Cull, - )); - }); - }); - } -} - -fn ray_mesh_intersection_no_cull(c: &mut Criterion) { - let mut group = c.benchmark_group("ray_mesh_intersection_no_cull"); - group.warm_up_time(std::time::Duration::from_millis(500)); - - for vertices_per_side in [10_u32, 100, 1000] { - group.bench_function(format!("{}_vertices", vertices_per_side.pow(2)), |b| { - let ray = Ray3d::new(Vec3::new(0.0, 1.0, 0.0), Vec3::new(0.0, -1.0, 0.0)); - let mesh_to_world = Mat4::IDENTITY; - let mesh = mesh_creation(vertices_per_side); - - b.iter(|| { - black_box(bevy_mod_raycast::prelude::ray_mesh_intersection( - &mesh_to_world, - &mesh.positions, - Some(&mesh.normals), - ray, - Some(&mesh.indices), - Backfaces::Include, - )); - }); - }); - } -} - -fn ray_mesh_intersection_no_intersection(c: &mut Criterion) { - let mut group = c.benchmark_group("ray_mesh_intersection_no_intersection"); - group.warm_up_time(std::time::Duration::from_millis(500)); - - for vertices_per_side in [10_u32, 100, 1000] { - group.bench_function(format!("{}_vertices", (vertices_per_side).pow(2)), |b| { - let ray = Ray3d::new(Vec3::new(0.0, 1.0, 0.0), Vec3::new(1.0, 0.0, 0.0)); - let mesh_to_world = Mat4::IDENTITY; - let mesh = mesh_creation(vertices_per_side); - - b.iter(|| { - black_box(bevy_mod_raycast::prelude::ray_mesh_intersection( - &mesh_to_world, - &mesh.positions, - Some(&mesh.normals), - ray, - Some(&mesh.indices), - Backfaces::Cull, - )); - }); - }); - } -} - -criterion_group!( - benches, - ray_mesh_intersection, - ray_mesh_intersection_no_cull, - ray_mesh_intersection_no_intersection -); -criterion_main!(benches); +use bevy::math::{Mat4, Vec3}; +use bevy_math::{Dir3, Ray3d}; +use bevy_mod_raycast::prelude::*; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +fn ptoxznorm(p: u32, size: u32) -> (f32, f32) { + let ij = (p / (size), p % (size)); + (ij.0 as f32 / size as f32, ij.1 as f32 / size as f32) +} + +struct SimpleMesh { + positions: Vec<[f32; 3]>, + normals: Vec<[f32; 3]>, + indices: Vec, +} + +fn mesh_creation(vertices_per_side: u32) -> SimpleMesh { + let mut positions = Vec::new(); + let mut normals = Vec::new(); + for p in 0..vertices_per_side.pow(2) { + let xz = ptoxznorm(p, vertices_per_side); + positions.push([xz.0 - 0.5, 0.0, xz.1 - 0.5]); + normals.push([0.0, 1.0, 0.0]); + } + + let mut indices = vec![]; + for p in 0..vertices_per_side.pow(2) { + if p % (vertices_per_side) != vertices_per_side - 1 + && p / (vertices_per_side) != vertices_per_side - 1 + { + indices.extend_from_slice(&[p, p + 1, p + vertices_per_side]); + indices.extend_from_slice(&[p + vertices_per_side, p + 1, p + vertices_per_side + 1]); + } + } + + SimpleMesh { + positions, + normals, + indices, + } +} + +fn ray_mesh_intersection(c: &mut Criterion) { + let mut group = c.benchmark_group("ray_mesh_intersection"); + group.warm_up_time(std::time::Duration::from_millis(500)); + + for vertices_per_side in [10_u32, 100, 1000] { + group.bench_function(format!("{}_vertices", vertices_per_side.pow(2)), |b| { + let ray = Ray3d::new( + Vec3::new(0.0, 1.0, 0.0), + Dir3::from_xyz_unchecked(0.0, -1.0, 0.0), + ); + let mesh_to_world = Mat4::IDENTITY; + let mesh = mesh_creation(vertices_per_side); + + b.iter(|| { + black_box(bevy_mod_raycast::prelude::ray_mesh_intersection( + &mesh_to_world, + &mesh.positions, + Some(&mesh.normals), + ray, + Some(&mesh.indices), + Backfaces::Cull, + )); + }); + }); + } +} + +fn ray_mesh_intersection_no_cull(c: &mut Criterion) { + let mut group = c.benchmark_group("ray_mesh_intersection_no_cull"); + group.warm_up_time(std::time::Duration::from_millis(500)); + + for vertices_per_side in [10_u32, 100, 1000] { + group.bench_function(format!("{}_vertices", vertices_per_side.pow(2)), |b| { + let ray = Ray3d::new( + Vec3::new(0.0, 1.0, 0.0), + Dir3::from_xyz_unchecked(0.0, -1.0, 0.0), + ); + let mesh_to_world = Mat4::IDENTITY; + let mesh = mesh_creation(vertices_per_side); + + b.iter(|| { + black_box(bevy_mod_raycast::prelude::ray_mesh_intersection( + &mesh_to_world, + &mesh.positions, + Some(&mesh.normals), + ray, + Some(&mesh.indices), + Backfaces::Include, + )); + }); + }); + } +} + +fn ray_mesh_intersection_no_intersection(c: &mut Criterion) { + let mut group = c.benchmark_group("ray_mesh_intersection_no_intersection"); + group.warm_up_time(std::time::Duration::from_millis(500)); + + for vertices_per_side in [10_u32, 100, 1000] { + group.bench_function(format!("{}_vertices", (vertices_per_side).pow(2)), |b| { + let ray = Ray3d::new( + Vec3::new(0.0, 1.0, 0.0), + Dir3::from_xyz_unchecked(1.0, 0.0, 0.0), + ); + let mesh_to_world = Mat4::IDENTITY; + let mesh = mesh_creation(vertices_per_side); + + b.iter(|| { + black_box(bevy_mod_raycast::prelude::ray_mesh_intersection( + &mesh_to_world, + &mesh.positions, + Some(&mesh.normals), + ray, + Some(&mesh.indices), + Backfaces::Cull, + )); + }); + }); + } +} + +criterion_group!( + benches, + ray_mesh_intersection, + ray_mesh_intersection_no_cull, + ray_mesh_intersection_no_intersection +); +criterion_main!(benches); diff --git a/examples/minimal.rs b/examples/minimal.rs index 861027f..ba57255 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -16,9 +16,9 @@ fn main() { const RAY_DIST: Vec3 = Vec3::new(0.0, 0.0, -7.0); fn raycast(mut raycast: Raycast, mut gizmos: Gizmos, time: Res