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 rc #115

Merged
merged 3 commits into from
Jun 11, 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
27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ categories = ["game-engines", "rendering"]
resolver = "2"

[dependencies]
bevy_app = { version = "0.13", default-features = false }
bevy_asset = { version = "0.13", default-features = false }
bevy_derive = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_gizmos = { version = "0.13", optional = true, default-features = false }
bevy_math = { version = "0.13", default-features = false }
bevy_reflect = { version = "0.13", default-features = false }
bevy_render = { version = "0.13", default-features = false }
bevy_sprite = { version = "0.13", optional = true, default-features = false }
bevy_transform = { version = "0.13", default-features = false }
bevy_utils = { version = "0.13", default-features = false }
bevy_window = { version = "0.13", default-features = false }
bevy_app = { version = "0.14.0-rc.2", default-features = false }
bevy_asset = { version = "0.14.0-rc.2", default-features = false }
bevy_derive = { version = "0.14.0-rc.2", default-features = false }
bevy_ecs = { version = "0.14.0-rc.2", default-features = false }
bevy_gizmos = { version = "0.14.0-rc.2", optional = true, default-features = false }
bevy_math = { version = "0.14.0-rc.2", default-features = false }
bevy_reflect = { version = "0.14.0-rc.2", default-features = false }
bevy_render = { version = "0.14.0-rc.2", default-features = false }
bevy_sprite = { version = "0.14.0-rc.2", optional = true, default-features = false }
bevy_transform = { version = "0.14.0-rc.2", default-features = false }
bevy_utils = { version = "0.14.0-rc.2", default-features = false }
bevy_window = { version = "0.14.0-rc.2", default-features = false }
bevy_color = { version = "0.14.0-rc.2", default-features = false }
crossbeam-channel = "0.5"

[dev-dependencies]
bevy = { version = "0.13", default-features = true, features = [
bevy = { version = "0.14.0-rc.2", default-features = true, features = [
"default_font",
"ktx2",
"tonemapping_luts",
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn setup(
commands.spawn(PointLightBundle::default());
commands.spawn(PbrBundle {
mesh: meshes.add(Capsule3d::default()),
material: materials.add(Color::rgb(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
transform: Transform::from_translation(RAY_DIST),
..default()
});
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal_deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn setup(
commands.spawn((
PbrBundle {
mesh: meshes.add(Capsule3d::default()),
material: materials.add(Color::rgb(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
transform: Transform::from_translation(RAY_DIST),
..default()
},
Expand Down
4 changes: 2 additions & 2 deletions examples/mouse_picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! scene, intersect a mesh, and mark the intersection with the built in debug cursor. If you are
//! looking for a more fully-featured mouse picking plugin, try out bevy_mod_picking.

use bevy::prelude::*;
use bevy::{color::palettes::css, prelude::*};
use bevy_mod_raycast::prelude::*;

fn main() {
Expand All @@ -29,7 +29,7 @@ fn setup(
commands.spawn(PointLightBundle::default());
commands.spawn(PbrBundle {
mesh: meshes.add(Sphere::default()),
material: materials.add(Color::GRAY),
material: materials.add(Color::from(css::GRAY)),
transform: Transform::from_xyz(0.0, 0.0, -5.0),
..default()
});
Expand Down
4 changes: 2 additions & 2 deletions examples/mouse_picking_2d.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
use bevy::{color::palettes::css, prelude::*, sprite::MaterialMesh2dBundle};
use bevy_mod_raycast::prelude::*;

fn main() {
Expand All @@ -23,7 +23,7 @@ fn setup(
MaterialMesh2dBundle {
mesh: meshes.add(Circle::default()).into(),
transform: Transform::default().with_scale(Vec3::splat(128.)),
material: materials.add(ColorMaterial::from(Color::PURPLE)),
material: materials.add(ColorMaterial::from(Color::from(css::PURPLE))),
..default()
},
RaycastMesh::<()>::default(), // Make this mesh ray cast-able;
Expand Down
4 changes: 2 additions & 2 deletions examples/mouse_picking_deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! parameter. By contrast this example instead uses the deferred API, where raycasts are declared
//! using components, and the plugin handles the raycasting. Note we use `()` as the raycasting set.

use bevy::prelude::*;
use bevy::{color::palettes::css, prelude::*};
use bevy_mod_raycast::prelude::*;

fn main() {
Expand All @@ -29,7 +29,7 @@ fn setup(
commands.spawn((
PbrBundle {
mesh: meshes.add(Sphere::default()),
material: materials.add(Color::GRAY),
material: materials.add(Color::from(css::GRAY)),
transform: Transform::from_xyz(0.0, 0.0, -5.0),
..default()
},
Expand Down
26 changes: 18 additions & 8 deletions examples/reflecting_laser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::f32::consts::{FRAC_PI_2, PI};

use bevy::{core_pipeline::bloom::BloomSettings, math::vec3, prelude::*};
use bevy::{color::palettes::css, core_pipeline::bloom::BloomSettings, math::vec3, prelude::*};
use bevy_mod_raycast::prelude::*;

fn main() {
Expand Down Expand Up @@ -35,26 +35,36 @@ fn bouncing_raycast(
let ray_dir = (-ray_pos).normalize();
let ray = Ray3d::new(ray_pos, ray_dir);
gizmos.sphere(ray_pos, Quat::IDENTITY, 0.1, Color::WHITE);
bounce_ray(ray, &mut raycast, &mut gizmos, Color::RED);
bounce_ray(ray, &mut raycast, &mut gizmos, Color::from(css::RED));

if let Some(cursor_ray) = **cursor_ray {
bounce_ray(cursor_ray, &mut raycast, &mut gizmos, Color::GREEN)
bounce_ray(
cursor_ray,
&mut raycast,
&mut gizmos,
Color::from(css::GREEN),
)
}
}

fn bounce_ray(mut ray: Ray3d, raycast: &mut Raycast, gizmos: &mut Gizmos, color: Color) {
let mut intersections = Vec::with_capacity(MAX_BOUNCES + 1);
intersections.push((ray.origin, Color::rgb(30.0, 0.0, 0.0)));
intersections.push((ray.origin, Color::srgb(30.0, 0.0, 0.0)));

for i in 0..MAX_BOUNCES {
if let Some((_, hit)) = raycast.cast_ray(ray, &RaycastSettings::default()).first() {
let bright = 1.0 + 10.0 * (1.0 - i as f32 / MAX_BOUNCES as f32);
intersections.push((hit.position(), color * bright));
gizmos.sphere(hit.position(), Quat::IDENTITY, 0.005, color * bright * 2.0);
intersections.push((hit.position(), Color::BLACK.mix(&color, bright)));
gizmos.sphere(
hit.position(),
Quat::IDENTITY,
0.005,
Color::BLACK.mix(&color, bright * 2.0),
);
let ray_dir = ray.direction;
// reflect the ray
let proj = (ray_dir.dot(hit.normal()) / hit.normal().dot(hit.normal())) * hit.normal();
ray.direction = Direction3d::new(*ray_dir - 2.0 * proj).unwrap();
ray.direction = Dir3::new(*ray_dir - 2.0 * proj).unwrap();
ray.origin = hit.position() + ray.direction * 1e-6;
} else {
break;
Expand Down Expand Up @@ -88,7 +98,7 @@ fn setup_scene(
// Make a box of planes facing inward so the laser gets trapped inside:
let plane = PbrBundle {
mesh: meshes.add(Plane3d::default()),
material: materials.add(Color::GRAY.with_a(0.01)),
material: materials.add(Color::from(css::GRAY).with_alpha(0.01)),
..default()
};
let pbr_bundle = move |translation, rotation| PbrBundle {
Expand Down
9 changes: 5 additions & 4 deletions examples/simplified_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! intersection with the mesh.

use bevy::{
color::palettes::css,
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
prelude::*,
};
Expand Down Expand Up @@ -37,7 +38,7 @@ fn setup_scene(
PbrBundle {
// This is a very complex mesh that will be hard to raycast on
mesh: meshes.add(Sphere::default().mesh().uv(1000, 1000)),
material: materials.add(Color::rgb(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, -5.0)),
..default()
},
Expand Down Expand Up @@ -105,7 +106,7 @@ fn setup_ui(mut commands: Commands) {
value: "ON".to_string(),
style: TextStyle {
font_size: 30.0,
color: Color::GREEN,
color: css::GREEN.into(),
..default()
},
},
Expand Down Expand Up @@ -140,11 +141,11 @@ fn manage_simplified_mesh(
mesh: meshes.add(Sphere::default()),
});
text.sections[1].value = "ON".to_string();
text.sections[1].style.color = Color::GREEN;
text.sections[1].style.color = css::GREEN.into();
} else {
commands.entity(entity).remove::<SimplifiedMesh>();
text.sections[1].value = "OFF".to_string();
text.sections[1].style.color = Color::RED;
text.sections[1].style.color = css::RED.into();
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions examples/stress_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ops::Sub;

use bevy::{
color::palettes::css,
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
math::Vec3A,
prelude::*,
Expand Down Expand Up @@ -144,10 +145,10 @@ fn update_status(
let bool_to_text = |is_enabled: bool, text: &mut Text| {
if is_enabled {
text.sections[1].value = "ON".to_string();
text.sections[1].style.color = Color::GREEN;
text.sections[1].style.color = css::GREEN.into();
} else {
text.sections[1].value = "OFF".to_string();
text.sections[1].style.color = Color::RED;
text.sections[1].style.color = css::RED.into();
}
};

Expand Down
14 changes: 7 additions & 7 deletions src/deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,11 @@ pub fn update_target_intersections<T: TypePath + Send + Sync>(
pub mod debug {
#![allow(unused)]

use bevy_color::palettes::css;
use bevy_ecs::system::{Commands, Query};
use bevy_gizmos::gizmos::Gizmos;
use bevy_math::{primitives::Direction3d, Quat, Vec3};
use bevy_math::{Dir3, Quat, Vec3};
use bevy_reflect::TypePath;
use bevy_render::color::Color;
use bevy_utils::tracing::info;
use std::marker::PhantomData;

Expand All @@ -523,8 +523,8 @@ pub mod debug {
) {
for ray in sources.iter().filter_map(|s| s.ray) {
let orientation = Quat::from_rotation_arc(Vec3::NEG_Z, *ray.direction);
gizmos.ray(ray.origin, *ray.direction, Color::BLUE);
gizmos.sphere(ray.origin, orientation, 0.1, Color::BLUE);
gizmos.ray(ray.origin, *ray.direction, css::BLUE);
gizmos.sphere(ray.origin, orientation, 0.1, css::BLUE);
}

for (is_first, intersection) in sources.iter().flat_map(|m| {
Expand All @@ -535,13 +535,13 @@ pub mod debug {
.map(|(i, hit)| (i == 0, hit))
}) {
let color = match is_first {
true => Color::GREEN,
false => Color::PINK,
true => css::GREEN,
false => css::PINK,
};
gizmos.ray(intersection.position(), intersection.normal(), color);
gizmos.circle(
intersection.position(),
Direction3d::new_unchecked(intersection.normal().normalize()),
Dir3::new_unchecked(intersection.normal().normalize()),
0.1,
color,
);
Expand Down
17 changes: 9 additions & 8 deletions src/immediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

use bevy_asset::{Assets, Handle};
use bevy_ecs::{prelude::*, system::lifetimeless::Read, system::SystemParam};
use bevy_math::Ray3d;
use bevy_math::{FloatOrd, Ray3d};
use bevy_reflect::Reflect;
use bevy_render::{prelude::*, primitives::Aabb};
use bevy_transform::components::GlobalTransform;
use bevy_utils::{tracing::*, FloatOrd};
use bevy_utils::tracing::*;

#[cfg(feature = "debug")]
use {
Expand Down Expand Up @@ -196,11 +196,12 @@ impl<'w, 's> Raycast<'w, 's> {
settings: &RaycastSettings,
gizmos: &mut Gizmos,
) -> &[(Entity, IntersectionData)] {
use bevy_math::primitives::Direction3d;
use bevy_color::palettes::css;
use bevy_math::Dir3;

let orientation = Quat::from_rotation_arc(Vec3::NEG_Z, *ray.direction);
gizmos.ray(ray.origin, *ray.direction, Color::BLUE);
gizmos.sphere(ray.origin, orientation, 0.1, Color::BLUE);
gizmos.ray(ray.origin, *ray.direction, css::BLUE);
gizmos.sphere(ray.origin, orientation, 0.1, css::BLUE);

let hits = self.cast_ray(ray, settings);

Expand All @@ -211,13 +212,13 @@ impl<'w, 's> Raycast<'w, 's> {
.map(|(i, hit)| (i == 0, hit))
{
let color = match is_first {
true => Color::GREEN,
false => Color::PINK,
true => css::GREEN,
false => css::PINK,
};
gizmos.ray(intersection.position(), intersection.normal(), color);
gizmos.circle(
intersection.position(),
Direction3d::new_unchecked(intersection.normal().normalize()),
Dir3::new_unchecked(intersection.normal().normalize()),
0.1,
color,
);
Expand Down
Loading